4 |
|
// |
5 |
|
// RenegadeMapSelector.cpp |
6 |
|
|
7 |
+ |
#ifdef _WIN32 |
8 |
+ |
#include <io.h> |
9 |
+ |
#include <fcntl.h> |
10 |
+ |
#endif |
11 |
+ |
|
12 |
|
#include "RenegadeMapSelector.h" |
13 |
|
#include "resource.h" |
14 |
|
|
15 |
|
bool debug = false; |
16 |
|
string program; |
17 |
|
|
18 |
< |
inline string widetoansi(const wstring& wide) |
18 |
> |
#ifndef _WIN32 |
19 |
> |
inline string fix(const string& ansi) { return ansi; } |
20 |
> |
#else |
21 |
> |
inline string fix(const wstring& wide) |
22 |
|
{ |
23 |
|
char* buffer = new char[wide.length() + 1]; |
24 |
|
|
31 |
|
return ansi; |
32 |
|
} |
33 |
|
|
34 |
+ |
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 |
|
int CALLBACK selector(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); |
62 |
|
|
63 |
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR |
66 |
|
int argc; |
67 |
|
unsigned short** argv = CommandLineToArgvW(GetCommandLineW(), &argc); |
68 |
|
|
69 |
< |
program = widetoansi(argv[0]); |
69 |
> |
program = fix(argv[0]); |
70 |
|
|
71 |
|
for (int index = 1; index < argc; index++) |
72 |
|
{ |
73 |
< |
string arg = widetoansi(argv[index]); |
73 |
> |
string arg = fix(argv[index]); |
74 |
|
|
75 |
|
if (arg == "-D") |
76 |
|
{ |
78 |
|
} |
79 |
|
} |
80 |
|
|
81 |
< |
if (debug) MessageBox(NULL, program.c_str(), "Program", 0); |
81 |
> |
if (debug) munge(); |
82 |
|
|
83 |
|
DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAP_SELECTOR), NULL, selector); |
84 |
|
|
85 |
+ |
if (debug) FreeConsole(); |
86 |
|
GlobalFree(argv); |
87 |
|
return 0; |
88 |
|
} |
109 |
|
{ |
110 |
|
char* directory = new char[MAX_PATH + 1]; |
111 |
|
GetCurrentDirectory(MAX_PATH + 1, directory); |
112 |
< |
if (debug) MessageBox(hwndDlg, directory, "Directory", 0); |
112 |
> |
if (debug) cerr << "directory = " << directory << "\n"; |
113 |
|
|
114 |
|
char* data = new char[MAX_PATH + 1]; |
115 |
|
sprintf(data, "%s\\data\\*.mix", directory); |
116 |
|
delete [] directory; |
117 |
< |
if (debug) MessageBox(hwndDlg, data, "Data", 0); |
117 |
> |
if (debug) cerr << "data = " << data << "\n"; |
118 |
|
|
119 |
|
DlgDirList(hwndDlg, data, IDC_AVAILABLE, 0, DDL_ARCHIVE); |
120 |
|
|