-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathperkedel-start.c
87 lines (72 loc) · 3.05 KB
/
perkedel-start.c
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
77
78
79
80
81
82
83
84
85
86
87
/*
perkedel-start.c
- Used in Perkedel compilers/interpreters bundle for Windows
- Author: Noprianto <nopri.anto@icloud.com>, 2020
- Website: nopri.github.io
- License: public domain
- Compile: gcc perkedel-start.c -mwindows -Os -s -o perkedel-start.exe
*/
#include<stdio.h>
#include<windows.h>
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
DWORD version = 0;
DWORD major = 0;
DWORD minor = 0;
DWORD build = 0;
char versions[32];
char *drive;
char error[255];
char errors[255];
char path[16];
char confirm[255];
char extract[64];
char run[64];
char dir[16];
STARTUPINFO startup_info;
PROCESS_INFORMATION process_info;
version = GetVersion();
major = (DWORD)(LOBYTE(LOWORD(version)));
minor = (DWORD)(HIBYTE(LOWORD(version)));
if (version < 0x80000000) build = (DWORD)(HIWORD(version));
sprintf(versions, "%d.%d.%d", major, minor, build);
drive = getenv("SystemDrive");
sprintf(path, "%s\\perkedel", drive);
sprintf(error, "Perkedel was tested only on Windows 7 or later. This system runs Windows 95/98/Me/2000/XP/Server 2003 (%s).", versions);
sprintf(errors, "Perkedel was tested only on Windows 7 or later. This system runs Windows Vista (%s).", versions);
sprintf(confirm, "Do you want to copy Perkedel to %s? If no is selected, perkedel will be run in a temporary directory.", path);
if (major < 6) {
MessageBox(NULL, error, "Perkedel", MB_OK);
} else {
if (minor < 1) {
MessageBox(NULL, errors, "Perkedel", MB_OK);
} else {
int res = MessageBox(NULL, confirm, "Perkedel", MB_YESNO);
if (res == IDYES) {
sprintf(extract, "perkedel-bundle.exe -o\"%s\" -y", path);
sprintf(run, "%s\\perkedel.exe", path);
sprintf(dir, "%s\\", path);
} else {
sprintf(extract, "perkedel-bundle.exe -o . -y");
sprintf(run, "perkedel.exe", path);
sprintf(dir, ".");
}
ZeroMemory(&startup_info, sizeof(startup_info));
startup_info.cb = sizeof(startup_info);
ZeroMemory(&process_info, sizeof(process_info));
GetStartupInfo (&startup_info);
if (CreateProcess(NULL, extract, NULL, NULL, FALSE, 0, NULL, NULL, &startup_info, &process_info)) {
WaitForSingleObject(process_info.hProcess, INFINITE);
}
SetCurrentDirectory(dir);
ZeroMemory(&startup_info, sizeof(startup_info));
startup_info.cb = sizeof(startup_info);
ZeroMemory(&process_info, sizeof(process_info));
GetStartupInfo (&startup_info);
if (CreateProcess(NULL, run, NULL, NULL, FALSE, 0, NULL, NULL, &startup_info, &process_info)) {
WaitForSingleObject(process_info.hProcess, INFINITE);
}
}
}
return 0;
}