ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/RenegadeMapSelector/RenegadeMapSelector.cpp
Revision: 68
Committed: 2003-03-11T17:16:41-08:00 (22 years, 3 months ago) by douglas
File size: 3586 byte(s)
Log Message:
Did some more stuff.

File Contents

# User Rev Content
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 68 string error;
77 douglas 67 string file = "svrcfg_cnc.ini";
78    
79 douglas 66 program = fix(argv[0]);
80 douglas 63
81     for (int index = 1; index < argc; index++)
82     {
83 douglas 66 string arg = fix(argv[index]);
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 douglas 68 if (!config->load())
111     {
112     error = "Could not open " + file + ".";
113 douglas 67
114 douglas 68 MessageBox(NULL, error.c_str(), "Bad File", MB_ICONERROR);
115     return 1;
116     }
117    
118 douglas 63 DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAP_SELECTOR), NULL, selector);
119    
120 douglas 67 delete config;
121    
122 douglas 68 if (debug) cin.get();
123    
124 douglas 63 return 0;
125     }
126    
127     int CALLBACK selector(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
128     {
129     switch (uMsg)
130     {
131     case WM_INITDIALOG:
132     {
133     RECT rc, rcDlg, rcDesktop;
134    
135     GetWindowRect(GetDesktopWindow(), &rcDesktop);
136     GetWindowRect(hwndDlg, &rcDlg);
137     CopyRect(&rc, &rcDesktop);
138    
139     OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top);
140     OffsetRect(&rc, -rc.left, -rc.top);
141     OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom);
142    
143     SetWindowPos(hwndDlg, HWND_TOP, rcDesktop.left + (rc.right / 2),
144     rcDesktop.top + (rc.bottom / 2), 0, 0, SWP_NOSIZE);
145     }
146     {
147     char* directory = new char[MAX_PATH + 1];
148     GetCurrentDirectory(MAX_PATH + 1, directory);
149 douglas 66 if (debug) cerr << "directory = " << directory << "\n";
150 douglas 63
151     char* data = new char[MAX_PATH + 1];
152     sprintf(data, "%s\\data\\*.mix", directory);
153     delete [] directory;
154 douglas 66 if (debug) cerr << "data = " << data << "\n";
155 douglas 63
156     DlgDirList(hwndDlg, data, IDC_AVAILABLE, 0, DDL_ARCHIVE);
157 douglas 68 SetCurrentDirectory("..");
158 douglas 63
159     delete [] data;
160     }
161     break;
162     case WM_COMMAND:
163     switch (LOWORD(wParam))
164     {
165     case IDOK:
166 douglas 67 config->save();
167 douglas 63 case IDCANCEL:
168     EndDialog(hwndDlg, wParam);
169     return true;
170     }
171     break;
172     }
173    
174     return false;
175     }