1 |
douglas |
63 |
// Renegade Map Selector |
2 |
|
|
// |
3 |
|
|
// Douglas Thrift |
4 |
|
|
// |
5 |
|
|
// RenegadeMapSelector.cpp |
6 |
|
|
|
7 |
douglas |
66 |
#ifdef _WIN32 |
8 |
|
|
#include <io.h> |
9 |
|
|
#include <fcntl.h> |
10 |
douglas |
67 |
#include "resource.h" |
11 |
douglas |
66 |
#endif |
12 |
|
|
|
13 |
douglas |
63 |
#include "RenegadeMapSelector.h" |
14 |
douglas |
67 |
#include "RenegadeConfig.h" |
15 |
douglas |
63 |
|
16 |
|
|
bool debug = false; |
17 |
|
|
string program; |
18 |
douglas |
67 |
RenegadeConfig* config; |
19 |
douglas |
63 |
|
20 |
douglas |
66 |
#ifndef _WIN32 |
21 |
|
|
inline string fix(const string& ansi) { return ansi; } |
22 |
douglas |
67 |
inline void munge(void) { return; } |
23 |
douglas |
66 |
#else |
24 |
|
|
inline string fix(const wstring& wide) |
25 |
douglas |
63 |
{ |
26 |
|
|
char* buffer = new char[wide.length() + 1]; |
27 |
|
|
|
28 |
|
|
WideCharToMultiByte(CP_ACP, 0, wide.c_str(), -1, buffer, wide.length() + 1, |
29 |
|
|
NULL, NULL); |
30 |
|
|
|
31 |
|
|
string ansi = buffer; |
32 |
|
|
delete [] buffer; |
33 |
|
|
|
34 |
|
|
return ansi; |
35 |
|
|
} |
36 |
|
|
|
37 |
douglas |
67 |
inline void munge(void) |
38 |
douglas |
66 |
{ |
39 |
douglas |
67 |
if (debug) return; |
40 |
|
|
|
41 |
douglas |
66 |
AllocConsole(); |
42 |
|
|
SetConsoleTitle("Renegade Map Selector"); |
43 |
|
|
|
44 |
|
|
int hin = _open_osfhandle(long(GetStdHandle(STD_INPUT_HANDLE)), _O_TEXT); |
45 |
|
|
int hout = _open_osfhandle(long(GetStdHandle(STD_OUTPUT_HANDLE)), _O_TEXT); |
46 |
|
|
int herr = _open_osfhandle(long(GetStdHandle(STD_ERROR_HANDLE)), _O_TEXT); |
47 |
|
|
|
48 |
|
|
FILE* fin = _fdopen(hin, "r"); |
49 |
|
|
FILE* fout = _fdopen(hout, "w"); |
50 |
|
|
FILE* ferr = _fdopen(herr, "w"); |
51 |
|
|
|
52 |
|
|
*stdin = *fin; |
53 |
|
|
*stdout = *fout; |
54 |
|
|
*stderr = *ferr; |
55 |
|
|
|
56 |
|
|
setvbuf(stdin, NULL, _IONBF, 0); |
57 |
|
|
setvbuf(stdout, NULL, _IONBF, 0); |
58 |
|
|
setvbuf(stderr, NULL, _IONBF, 0); |
59 |
|
|
|
60 |
|
|
cin.sync_with_stdio(); |
61 |
|
|
cout.sync_with_stdio(); |
62 |
|
|
cerr.sync_with_stdio(); |
63 |
douglas |
67 |
|
64 |
|
|
debug = true; |
65 |
douglas |
66 |
} |
66 |
|
|
#endif |
67 |
|
|
|
68 |
douglas |
63 |
int CALLBACK selector(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); |
69 |
|
|
|
70 |
|
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR |
71 |
|
|
lpCmdLine, int nShowCmd) |
72 |
|
|
{ |
73 |
|
|
int argc; |
74 |
|
|
unsigned short** argv = CommandLineToArgvW(GetCommandLineW(), &argc); |
75 |
|
|
|
76 |
douglas |
67 |
string file = "svrcfg_cnc.ini"; |
77 |
|
|
|
78 |
douglas |
66 |
program = fix(argv[0]); |
79 |
douglas |
63 |
|
80 |
|
|
for (int index = 1; index < argc; index++) |
81 |
|
|
{ |
82 |
douglas |
66 |
string arg = fix(argv[index]); |
83 |
douglas |
67 |
string error; |
84 |
douglas |
63 |
|
85 |
|
|
if (arg == "-D") |
86 |
|
|
{ |
87 |
douglas |
67 |
munge(); |
88 |
douglas |
63 |
} |
89 |
douglas |
67 |
else if (arg == "-file") |
90 |
|
|
{ |
91 |
|
|
if (++index < argc) |
92 |
|
|
{ |
93 |
|
|
file = fix(argv[index]); |
94 |
|
|
} |
95 |
|
|
else |
96 |
|
|
{ |
97 |
|
|
error = "The argument -file must be followed by a filename."; |
98 |
|
|
|
99 |
|
|
MessageBox(NULL, error.c_str(), "Bad Arguments", MB_ICONERROR); |
100 |
|
|
return 1; |
101 |
|
|
} |
102 |
|
|
} |
103 |
douglas |
63 |
} |
104 |
|
|
|
105 |
douglas |
67 |
GlobalFree(argv); |
106 |
douglas |
63 |
|
107 |
douglas |
67 |
if (debug) cerr << "file = " << file << "\n"; |
108 |
|
|
|
109 |
|
|
config = new RenegadeConfig(file); |
110 |
|
|
config->load(); |
111 |
|
|
|
112 |
douglas |
63 |
DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAP_SELECTOR), NULL, selector); |
113 |
|
|
|
114 |
douglas |
67 |
delete config; |
115 |
|
|
|
116 |
douglas |
63 |
return 0; |
117 |
|
|
} |
118 |
|
|
|
119 |
|
|
int CALLBACK selector(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) |
120 |
|
|
{ |
121 |
|
|
switch (uMsg) |
122 |
|
|
{ |
123 |
|
|
case WM_INITDIALOG: |
124 |
|
|
{ |
125 |
|
|
RECT rc, rcDlg, rcDesktop; |
126 |
|
|
|
127 |
|
|
GetWindowRect(GetDesktopWindow(), &rcDesktop); |
128 |
|
|
GetWindowRect(hwndDlg, &rcDlg); |
129 |
|
|
CopyRect(&rc, &rcDesktop); |
130 |
|
|
|
131 |
|
|
OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top); |
132 |
|
|
OffsetRect(&rc, -rc.left, -rc.top); |
133 |
|
|
OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom); |
134 |
|
|
|
135 |
|
|
SetWindowPos(hwndDlg, HWND_TOP, rcDesktop.left + (rc.right / 2), |
136 |
|
|
rcDesktop.top + (rc.bottom / 2), 0, 0, SWP_NOSIZE); |
137 |
|
|
} |
138 |
|
|
{ |
139 |
|
|
char* directory = new char[MAX_PATH + 1]; |
140 |
|
|
GetCurrentDirectory(MAX_PATH + 1, directory); |
141 |
douglas |
66 |
if (debug) cerr << "directory = " << directory << "\n"; |
142 |
douglas |
63 |
|
143 |
|
|
char* data = new char[MAX_PATH + 1]; |
144 |
|
|
sprintf(data, "%s\\data\\*.mix", directory); |
145 |
|
|
delete [] directory; |
146 |
douglas |
66 |
if (debug) cerr << "data = " << data << "\n"; |
147 |
douglas |
63 |
|
148 |
|
|
DlgDirList(hwndDlg, data, IDC_AVAILABLE, 0, DDL_ARCHIVE); |
149 |
|
|
|
150 |
|
|
delete [] data; |
151 |
|
|
} |
152 |
|
|
break; |
153 |
|
|
case WM_COMMAND: |
154 |
|
|
switch (LOWORD(wParam)) |
155 |
|
|
{ |
156 |
|
|
case IDOK: |
157 |
douglas |
67 |
config->save(); |
158 |
douglas |
63 |
case IDCANCEL: |
159 |
|
|
EndDialog(hwndDlg, wParam); |
160 |
|
|
return true; |
161 |
|
|
} |
162 |
|
|
break; |
163 |
|
|
} |
164 |
|
|
|
165 |
|
|
return false; |
166 |
|
|
} |