-
Notifications
You must be signed in to change notification settings - Fork 13
/
git_windows.c
117 lines (101 loc) · 2.76 KB
/
git_windows.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Startup code for Windows Git
#ifdef _MSC_VER // For Visual C++, get rand_s()
#define _CRT_RAND_S
#endif
#include "glk.h"
#include "WinGlk.h"
#include "git.h"
const char* gFilename = NULL;
char gExePath[_MAX_PATH];
int winglk_startup_code(const char* cmdline)
{
char* sep;
int i;
winglk_set_gui(100);
winglk_app_set_name("Git");
winglk_set_menu_name("&Git");
winglk_window_set_title("Windows Git");
winglk_set_about_text("Windows Git "GIT_VERSION_STR);
winglk_show_game_dialog();
if (GetModuleFileName(0,gExePath,sizeof gExePath) == 0)
return 0;
sep = strrchr(gExePath,'.');
if (sep != 0)
{
strcpy_s(sep,(sizeof gExePath)-(sep-gExePath),".chm");
winglk_set_help_file(gExePath);
}
if (GetModuleFileName(0,gExePath,sizeof gExePath) == 0)
return 0;
sep = strrchr(gExePath,'.');
if (sep != 0)
{
static char* exts[] = { ".blb",".blorb",".glb",".gblorb",".ulx" };
for (i = 0; i < sizeof exts / sizeof exts[0]; i++)
{
strcpy_s(sep,(sizeof gExePath)-(sep-gExePath),exts[i]);
if (GetFileAttributes(gExePath) != INVALID_FILE_ATTRIBUTES)
{
gFilename = gExePath;
break;
}
}
}
if (gFilename == NULL)
{
gFilename = (char*)winglk_get_initial_filename(cmdline,
"Select a Glulx game to run",
"Glulx Files (.ulx;.blb;.blorb;.glb;.gblorb)|*.ulx;*.blb;*.blorb;*.glb;*.gblorb|"
"All Files (*.*)|*.*||");
}
if (gFilename == NULL)
return 0;
winglk_load_config_file(gFilename);
return 1;
}
#define CACHE_SIZE (256 * 1024)
#define UNDO_SIZE (2 * 1024 * 1024)
void fatalError(const char* s)
{
MessageBox(0,s,"Git Fatal Error",MB_OK|MB_ICONERROR);
exit(1);
}
void glk_main()
{
void* file = INVALID_HANDLE_VALUE;
void* mapping = NULL;
void* ptr = NULL;
size_t size = 0;
// Memory-map the gamefile
file = CreateFile(gFilename,GENERIC_READ,FILE_SHARE_READ,0,
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if (file != INVALID_HANDLE_VALUE)
{
size = GetFileSize(file,0);
mapping = CreateFileMapping(file,0,PAGE_READONLY,0,0,0);
}
if (mapping)
ptr = MapViewOfFile(mapping,FILE_MAP_READ,0,0,0);
// Pass the gamefile to git
if (ptr)
git(ptr,size,CACHE_SIZE,UNDO_SIZE);
else
fatalError("Can't open gamefile");
// Close the gamefile
if (ptr)
UnmapViewOfFile(ptr);
if (mapping)
CloseHandle(mapping);
if (file != INVALID_HANDLE_VALUE)
CloseHandle(file);
}
glui32 native_random()
{
#ifdef _MSC_VER
unsigned int value;
rand_s(&value);
return value;
#else
return xo_random();
#endif
}