// filetime.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include "stdafx.h"
#include <windows.h>

int _tmain(int argc, _TCHAR* argv[])
{
	FILETIME ft;
	SYSTEMTIME st;

	ft.dwLowDateTime = ft.dwHighDateTime = 0;

	GetSystemTime(&st);

	switch (argc) {
		case 9:
			st.wMilliseconds = _ttoi(argv[8]);
		case 8:
			st.wSecond = _ttoi(argv[7]);
		case 7:
			st.wMinute = _ttoi(argv[6]);
		case 6:
			st.wHour = _ttoi(argv[5]);
		case 5:
			st.wDay = _ttoi(argv[4]);
		case 4:
			st.wMonth = _ttoi(argv[3]);
		case 3:
			if (_tcsncmp(argv[2], _T("0x"), 2) == 0) {
				unsigned __int64 t;
				t = _tcstoui64(argv[2] + 2, NULL, 16);
				memcpy(&ft, &t, sizeof(ft));
			} else {
				st.wYear = _ttoi(argv[2]);
			}
			break;
		default:
			;
	}

	if (ft.dwHighDateTime == 0 && ft.dwLowDateTime == 0) {
		printf("%d\n", SystemTimeToFileTime(&st, &ft));
	}
	


	HANDLE hFile = CreateFile(argv[1], GENERIC_WRITE,
		FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0,
		NULL);

	if (hFile != INVALID_HANDLE_VALUE) {
		printf("%d\n", SetFileTime(hFile, &ft, &ft, &ft));
	}

	return 0;
}

