1 |
// Renegade Map Selector |
2 |
// |
3 |
// Douglas Thrift |
4 |
// |
5 |
// RenegadeMapSelector.cpp |
6 |
|
7 |
#ifdef _WIN32 |
8 |
#include <io.h> |
9 |
#include <fcntl.h> |
10 |
#include "resource.h" |
11 |
#endif |
12 |
|
13 |
#include "RenegadeMapSelector.h" |
14 |
#include "RenegadeConfig.h" |
15 |
|
16 |
bool debug = false; |
17 |
string program; |
18 |
RenegadeConfig* config; |
19 |
|
20 |
#ifndef _WIN32 |
21 |
inline string fix(const string& ansi) { return ansi; } |
22 |
inline void munge(void) { return; } |
23 |
#else |
24 |
inline string fix(const wstring& wide) |
25 |
{ |
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 |
inline void munge(void) |
38 |
{ |
39 |
if (debug) return; |
40 |
|
41 |
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 |
|
64 |
debug = true; |
65 |
} |
66 |
#endif |
67 |
|
68 |
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 |
string file = "svrcfg_cnc.ini"; |
77 |
|
78 |
program = fix(argv[0]); |
79 |
|
80 |
for (int index = 1; index < argc; index++) |
81 |
{ |
82 |
string arg = fix(argv[index]); |
83 |
string error; |
84 |
|
85 |
if (arg == "-D") |
86 |
{ |
87 |
munge(); |
88 |
} |
89 |
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 |
} |
104 |
|
105 |
GlobalFree(argv); |
106 |
|
107 |
if (debug) cerr << "file = " << file << "\n"; |
108 |
|
109 |
config = new RenegadeConfig(file); |
110 |
config->load(); |
111 |
|
112 |
DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAP_SELECTOR), NULL, selector); |
113 |
|
114 |
delete config; |
115 |
|
116 |
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 |
if (debug) cerr << "directory = " << directory << "\n"; |
142 |
|
143 |
char* data = new char[MAX_PATH + 1]; |
144 |
sprintf(data, "%s\\data\\*.mix", directory); |
145 |
delete [] directory; |
146 |
if (debug) cerr << "data = " << data << "\n"; |
147 |
|
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 |
config->save(); |
158 |
case IDCANCEL: |
159 |
EndDialog(hwndDlg, wParam); |
160 |
return true; |
161 |
} |
162 |
break; |
163 |
} |
164 |
|
165 |
return false; |
166 |
} |