ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/RenegadeMapSelector/RenegadeMapSelector.cpp
(Generate patch)

Comparing trunk/RenegadeMapSelector/RenegadeMapSelector.cpp (file contents):
Revision 66 by douglas, 2003-03-11T14:43:01-08:00 vs.
Revision 69 by douglas, 2003-03-11T18:39:01-08:00

# Line 7 | Line 7
7   #ifdef _WIN32
8   #include <io.h>
9   #include <fcntl.h>
10 + #include "resource.h"
11   #endif
12  
13   #include "RenegadeMapSelector.h"
14 < #include "resource.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   {
# Line 31 | Line 34 | inline string fix(const wstring& wide)
34          return ansi;
35   }
36  
37 < inline munge(void)
37 > inline void munge(void)
38   {
39 +        if (debug) return;
40 +
41          AllocConsole();
42          SetConsoleTitle("Renegade Map Selector");
43  
# Line 55 | Line 60 | inline munge(void)
60          cin.sync_with_stdio();
61          cout.sync_with_stdio();
62          cerr.sync_with_stdio();
63 +
64 +        debug = true;
65   }
66   #endif
67  
# Line 66 | Line 73 | int WINAPI WinMain(HINSTANCE hInstance,
73          int argc;
74          unsigned short** argv = CommandLineToArgvW(GetCommandLineW(), &argc);
75  
76 +        string error;
77 +        string file = "svrcfg_cnc.ini";
78 +
79          program = fix(argv[0]);
80  
81          for (int index = 1; index < argc; index++)
# Line 74 | Line 84 | int WINAPI WinMain(HINSTANCE hInstance,
84  
85                  if (arg == "-D")
86                  {
87 <                        debug = true;
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 <        if (debug) munge();
105 >        GlobalFree(argv);
106 >
107 >        if (debug) cerr << "file = " << file << "\n";
108 >
109 >        config = new RenegadeConfig(file);
110 >        if (!config->load())
111 >        {
112 >                error = "Could not open " + file + ".";
113 >
114 >                MessageBox(NULL, error.c_str(), "Bad File", MB_ICONERROR);
115 >                return 1;
116 >        }
117  
118          DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAP_SELECTOR), NULL, selector);
119  
120 <        if (debug) FreeConsole();
121 <        GlobalFree(argv);
120 >        delete config;
121 >
122 >        if (debug) cin.get();
123 >
124          return 0;
125   }
126  
# Line 117 | Line 154 | int CALLBACK selector(HWND hwndDlg, UINT
154                          if (debug) cerr << "data = " << data << "\n";
155  
156                          DlgDirList(hwndDlg, data, IDC_AVAILABLE, 0, DDL_ARCHIVE);
157 +                        SetCurrentDirectory("..");
158  
159                          delete [] data;
160                  }
161 +                {
162 +                        vector<string> maps = config->getMaps();
163 +
164 +                        for (unsigned index = 0; index < maps.size(); index++)
165 +                        {
166 +                                SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_ADDSTRING, 0,
167 +                                        long(maps[index].c_str()));
168 +                        }
169 +                }
170                  break;
171          case WM_COMMAND:
172                  switch (LOWORD(wParam))
173                  {
174                  case IDOK:
175 <                        //
175 >                        if (GetListBoxInfo(GetDlgItem(hwndDlg, IDC_SELECTED)) == 0)
176 >                        {
177 >                                MessageBox(hwndDlg, "You need at least one map.", "No Maps",
178 >                                        MB_ICONEXCLAMATION);
179 >
180 >                                return false;
181 >                        }
182 >                        else
183 >                        {
184 >                                vector<string> maps;
185 >
186 >                                for (unsigned index = 0; index < GetListBoxInfo(GetDlgItem(
187 >                                        hwndDlg, IDC_SELECTED)); index++)
188 >                                {
189 >                                        char* name = new char[SendMessage(GetDlgItem(hwndDlg,
190 >                                                IDC_SELECTED), LB_GETTEXTLEN, index, 0) + 1];
191 >
192 >                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETTEXT,
193 >                                                index, long(name));
194 >                                        maps.push_back(name);
195 >
196 >                                        delete [] name;
197 >                                }
198 >
199 >                                config->setMaps(maps);
200 >                        }
201 >                        config->save();
202                  case IDCANCEL:
203                          EndDialog(hwndDlg, wParam);
204                          return true;
205 +                case IDC_ADD_MAP:
206 +                        break;
207 +                case IDC_REMOVE_MAP:
208 +                        break;
209 +                case IDC_UP_MAP:
210 +                        break;
211 +                case IDC_DOWN_MAP:
212 +                        break;
213 +                case IDC_AVAILABLE:
214 +                        switch (HIWORD(wParam))
215 +                        {
216 +                        case LBN_SELCHANGE:
217 +                                if (SendMessage(GetDlgItem(hwndDlg, IDC_AVAILABLE),
218 +                                        LB_GETSELCOUNT, 0, 0) > 0)
219 +                                {
220 +                                        EnableWindow(GetDlgItem(hwndDlg, IDC_ADD_MAP), true);
221 +                                }
222 +                                else
223 +                                {
224 +                                        EnableWindow(GetDlgItem(hwndDlg, IDC_ADD_MAP), false);
225 +                                }
226 +                                break;
227 +                        }
228 +                        break;
229 +                case IDC_SELECTED:
230 +                        switch (HIWORD(wParam))
231 +                        {
232 +                        case LBN_SELCHANGE:
233 +                                if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
234 +                                        LB_GETSELCOUNT, 0, 0) > 0)
235 +                                {
236 +                                        EnableWindow(GetDlgItem(hwndDlg, IDC_REMOVE_MAP), true);
237 +                                        
238 +                                        if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
239 +                                                LB_GETSEL, 0, 0) == 0)
240 +                                        {
241 +                                                EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), true);
242 +                                        }
243 +                                        else
244 +                                        {
245 +                                                EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), false);
246 +                                        }
247 +
248 +                                        if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
249 +                                                LB_GETSEL, SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED
250 +                                                ), LB_GETCOUNT, 0, 0) - 1, 0) == 0)
251 +                                        {
252 +                                                EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), true);
253 +                                        }
254 +                                        else
255 +                                        {
256 +                                                EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), false);
257 +                                        }
258 +                                }
259 +                                else
260 +                                {
261 +                                        EnableWindow(GetDlgItem(hwndDlg, IDC_REMOVE_MAP), false);
262 +                                        EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), false);
263 +                                        EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), false);
264 +                                }
265 +                                break;
266 +                        }
267 +                        break;
268                  }
269                  break;
270          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines