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