-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
76 lines (65 loc) · 2.18 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <windows.h>
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPTSTR lpCmd, int nShow)
{
wchar_t msg[1024];
HANDLE file;
DWORD fileSize;
DWORD readSize;
DWORD err;
TCHAR errStr[32];
void* buf;
file = CreateFile(L"\\NAND\\version.txt", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (file == INVALID_HANDLE_VALUE)
{
err = GetLastError();
switch (err)
{
case 2:
case 3:
swprintf(errStr, L"File not found");
break;
default:
swprintf(errStr, L"Yabai error sorry");
break;
}
swprintf(msg, L"Failed to open version.txt\n%#010x: %s", err, errStr);
MessageBox(NULL, msg, L"(X_X) < OMG", MB_ICONWARNING);
return 1;
}
fileSize = GetFileSize(file, NULL);
buf = LocalAlloc(LPTR, fileSize+1);
if (buf == NULL)
{
MessageBox(NULL, L"Failed to allocate memory", L"(X_X) < OMG", MB_ICONWARNING);
goto disaster;
}
if (!ReadFile(file, buf, fileSize, &readSize, NULL))
{
MessageBox(NULL, L"Failed to read version.txt", L"(X_X) < OMG", MB_ICONWARNING);
goto disaster;
}
CloseHandle(file);
((char *)buf)[fileSize] = '\0';
mbstowcs(msg, (char *)buf, fileSize);
MessageBox(NULL, msg, L"(>_O)b < My version.txt is...", MB_ICONINFORMATION);
file = CreateFile(L"\\Storage Card\\version.txt", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (file == INVALID_HANDLE_VALUE)
{
file = CreateFile(L"\\NAND3\\version.txt", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (file == INVALID_HANDLE_VALUE)
{
MessageBox(NULL, L"Failed to create \\Storage Card\\version.txt and \\NAND3\\version.txt", L"(X_X) < OMG", MB_ICONWARNING);
return 1;
}
}
if (!WriteFile(file, buf, fileSize, NULL, NULL))
{
MessageBox(NULL, L"Failed to write \\Storage Card\\version.txt", L"(X_X) < OMG", MB_ICONWARNING);
goto disaster;
}
CloseHandle(file);
return 0;
disaster:
CloseHandle(file);
return 1;
}