| 1 |
|
| 2 |
|
| 3 |
#ifdef _MSC_VER |
| 4 |
#define _CRT_RAND_S |
| 5 |
#endif |
| 6 |
|
| 7 |
#include "glk.h" |
| 8 |
#include "WinGlk.h" |
| 9 |
#include "git.h" |
| 10 |
|
| 11 |
const char* gFilename = NULL; |
| 12 |
char gExePath[_MAX_PATH]; |
| 13 |
|
| 14 |
int winglk_startup_code(const char* cmdline) |
| 15 |
{ |
| 16 |
char* sep; |
| 17 |
int i; |
| 18 |
|
| 19 |
winglk_set_gui(100); |
| 20 |
winglk_app_set_name("Git"); |
| 21 |
winglk_set_menu_name("&Git"); |
| 22 |
winglk_window_set_title("Windows Git"); |
| 23 |
winglk_set_about_text("Windows Git "GIT_VERSION_STR); |
| 24 |
winglk_show_game_dialog(); |
| 25 |
|
| 26 |
if (GetModuleFileName(0,gExePath,sizeof gExePath) == 0) |
| 27 |
return 0; |
| 28 |
sep = strrchr(gExePath,'.'); |
| 29 |
if (sep != 0) |
| 30 |
{ |
| 31 |
strcpy_s(sep,(sizeof gExePath)-(sep-gExePath),".chm"); |
| 32 |
winglk_set_help_file(gExePath); |
| 33 |
} |
| 34 |
|
| 35 |
if (GetModuleFileName(0,gExePath,sizeof gExePath) == 0) |
| 36 |
return 0; |
| 37 |
sep = strrchr(gExePath,'.'); |
| 38 |
if (sep != 0) |
| 39 |
{ |
| 40 |
static char* exts[] = { ".blb",".blorb",".glb",".gblorb",".ulx" }; |
| 41 |
for (i = 0; i < sizeof exts / sizeof exts[0]; i++) |
| 42 |
{ |
| 43 |
strcpy_s(sep,(sizeof gExePath)-(sep-gExePath),exts[i]); |
| 44 |
if (GetFileAttributes(gExePath) != INVALID_FILE_ATTRIBUTES) |
| 45 |
{ |
| 46 |
gFilename = gExePath; |
| 47 |
break; |
| 48 |
} |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
if (gFilename == NULL) |
| 53 |
{ |
| 54 |
gFilename = (char*)winglk_get_initial_filename(cmdline, |
| 55 |
"Select a Glulx game to run", |
| 56 |
"Glulx Files (.ulx;.blb;.blorb;.glb;.gblorb)|*.ulx;*.blb;*.blorb;*.glb;*.gblorb|" |
| 57 |
"All Files (*.*)|*.*||"); |
| 58 |
} |
| 59 |
|
| 60 |
if (gFilename == NULL) |
| 61 |
return 0; |
| 62 |
winglk_load_config_file(gFilename); |
| 63 |
return 1; |
| 64 |
} |
| 65 |
|
| 66 |
#define CACHE_SIZE (256 * 1024) |
| 67 |
#define UNDO_SIZE (2 * 1024 * 1024) |
| 68 |
|
| 69 |
void fatalError(const char* s) |
| 70 |
{ |
| 71 |
MessageBox(0,s,"Git Fatal Error",MB_OK|MB_ICONERROR); |
| 72 |
exit(1); |
| 73 |
} |
| 74 |
|
| 75 |
void glk_main() |
| 76 |
{ |
| 77 |
void* file = INVALID_HANDLE_VALUE; |
| 78 |
void* mapping = NULL; |
| 79 |
void* ptr = NULL; |
| 80 |
size_t size = 0; |
| 81 |
|
| 82 |
|
| 83 |
file = CreateFile(gFilename,GENERIC_READ,FILE_SHARE_READ,0, |
| 84 |
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0); |
| 85 |
if (file != INVALID_HANDLE_VALUE) |
| 86 |
{ |
| 87 |
size = GetFileSize(file,0); |
| 88 |
mapping = CreateFileMapping(file,0,PAGE_READONLY,0,0,0); |
| 89 |
} |
| 90 |
if (mapping) |
| 91 |
ptr = MapViewOfFile(mapping,FILE_MAP_READ,0,0,0); |
| 92 |
|
| 93 |
|
| 94 |
if (ptr) |
| 95 |
git(ptr,size,CACHE_SIZE,UNDO_SIZE); |
| 96 |
else |
| 97 |
fatalError("Can't open gamefile"); |
| 98 |
|
| 99 |
|
| 100 |
if (ptr) |
| 101 |
UnmapViewOfFile(ptr); |
| 102 |
if (mapping) |
| 103 |
CloseHandle(mapping); |
| 104 |
if (file != INVALID_HANDLE_VALUE) |
| 105 |
CloseHandle(file); |
| 106 |
} |
| 107 |
|
| 108 |
glui32 native_random() |
| 109 |
{ |
| 110 |
#ifdef _MSC_VER |
| 111 |
unsigned int value; |
| 112 |
rand_s(&value); |
| 113 |
return value; |
| 114 |
#else |
| 115 |
return xo_random(); |
| 116 |
#endif |
| 117 |
} |