view src/win32/Directories.cpp @ 6:458a4f18f3cd

working on lua generation
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:48:33 -0600
parents f9f4f1b99eed
children
line wrap: on
line source
1 // Directories.cpp : implementation file
2 //
4 #include "stdafx.h"
5 #include <shlobj.h>
6 #include "resource.h"
7 #include "Directories.h"
8 #include "Reg.h"
9 #include "WinMiscUtil.h"
10 #include "WinResUtil.h"
12 /////////////////////////////////////////////////////////////////////////////
13 // Directories dialog
15 static int CALLBACK browseCallbackProc(HWND hWnd, UINT msg,
16 LPARAM l, LPARAM data)
17 {
18 char *buffer = (char *)data;
19 switch (msg)
20 {
21 case BFFM_INITIALIZED:
22 if (buffer[0])
23 SendMessage(hWnd, BFFM_SETSELECTION, TRUE, (LPARAM)buffer);
24 break;
25 default:
26 break;
27 }
28 return 0;
29 }
31 Directories::Directories(CWnd*pParent /*=NULL*/)
32 : CDialog(Directories::IDD, pParent)
33 {
34 //{{AFX_DATA_INIT(Directories)
35 // NOTE: the ClassWizard will add member initialization here
36 //}}AFX_DATA_INIT
37 }
39 void Directories::DoDataExchange(CDataExchange*pDX)
40 {
41 CDialog::DoDataExchange(pDX);
42 //{{AFX_DATA_MAP(Directories)
43 DDX_Control(pDX, IDC_ROM_PATH, m_romPath);
44 DDX_Control(pDX, IDC_GBXROM_PATH, m_gbxromPath);
45 DDX_Control(pDX, IDC_BATTERY_PATH, m_batteryPath);
46 DDX_Control(pDX, IDC_SAVE_PATH, m_savePath);
47 DDX_Control(pDX, IDC_MOVIE_PATH, m_moviePath);
48 DDX_Control(pDX, IDC_CHEAT_PATH, m_cheatPath);
49 DDX_Control(pDX, IDC_IPS_PATH, m_ipsPath);
50 DDX_Control(pDX, IDC_LUA_PATH, m_luaPath);
51 DDX_Control(pDX, IDC_AVI_PATH, m_aviPath);
52 DDX_Control(pDX, IDC_WAV_PATH, m_wavPath);
53 DDX_Control(pDX, IDC_CAPTURE_PATH, m_capturePath);
54 DDX_Control(pDX, IDC_WATCH_PATH, m_watchPath);
55 //}}AFX_DATA_MAP
56 }
58 BEGIN_MESSAGE_MAP(Directories, CDialog)
59 //{{AFX_MSG_MAP(Directories)
60 ON_BN_CLICKED(IDC_ROM_DIR, OnRomDir)
61 ON_BN_CLICKED(IDC_ROM_DIR_RESET, OnRomDirReset)
62 ON_BN_CLICKED(IDC_GBXROM_DIR, OnGBxRomDir)
63 ON_BN_CLICKED(IDC_GBXROM_DIR_RESET, OnGBxRomDirReset)
64 ON_BN_CLICKED(IDC_BATTERY_DIR, OnBatteryDir)
65 ON_BN_CLICKED(IDC_BATTERY_DIR_RESET, OnBatteryDirReset)
66 ON_BN_CLICKED(IDC_SAVE_DIR, OnSaveDir)
67 ON_BN_CLICKED(IDC_SAVE_DIR_RESET, OnSaveDirReset)
68 ON_BN_CLICKED(IDC_MOVIE_DIR, OnMovieDir)
69 ON_BN_CLICKED(IDC_MOVIE_DIR_RESET, OnMovieDirReset)
70 ON_BN_CLICKED(IDC_CHEAT_DIR, OnCheatDir)
71 ON_BN_CLICKED(IDC_CHEAT_DIR_RESET, OnCheatDirReset)
72 ON_BN_CLICKED(IDC_IPS_DIR, OnIpsDir)
73 ON_BN_CLICKED(IDC_IPS_DIR_RESET, OnIpsDirReset)
74 ON_BN_CLICKED(IDC_LUA_DIR, OnLuaDir)
75 ON_BN_CLICKED(IDC_LUA_DIR_RESET, OnLuaDirReset)
76 ON_BN_CLICKED(IDC_AVI_DIR, OnAviDir)
77 ON_BN_CLICKED(IDC_AVI_DIR_RESET, OnAviDirReset)
78 ON_BN_CLICKED(IDC_WAV_DIR, OnWavDir)
79 ON_BN_CLICKED(IDC_WAV_DIR_RESET, OnWavDirReset)
80 ON_BN_CLICKED(IDC_CAPTURE_DIR, OnCaptureDir)
81 ON_BN_CLICKED(IDC_CAPTURE_DIR_RESET, OnCaptureDirReset)
82 ON_BN_CLICKED(IDC_WATCH_DIR, OnWatchDir)
83 ON_BN_CLICKED(IDC_WATCH_DIR_RESET, OnWatchDirReset)
84 //}}AFX_MSG_MAP
85 END_MESSAGE_MAP()
87 /////////////////////////////////////////////////////////////////////////////
88 // Directories message handlers
90 BOOL Directories::OnInitDialog()
91 {
92 CDialog::OnInitDialog();
94 CString p = regQueryStringValue(IDS_ROM_DIR, NULL);
95 if (!p.IsEmpty())
96 GetDlgItem(IDC_ROM_PATH)->SetWindowText(p);
98 p = regQueryStringValue(IDS_GBXROM_DIR, NULL);
99 if (!p.IsEmpty())
100 GetDlgItem(IDC_GBXROM_PATH)->SetWindowText(p);
102 p = regQueryStringValue(IDS_BATTERY_DIR, NULL);
103 if (!p.IsEmpty())
104 GetDlgItem(IDC_BATTERY_PATH)->SetWindowText(p);
106 p = regQueryStringValue(IDS_SAVE_DIR, NULL);
107 if (!p.IsEmpty())
108 GetDlgItem(IDC_SAVE_PATH)->SetWindowText(p);
110 p = regQueryStringValue(IDS_MOVIE_DIR, NULL);
111 if (!p.IsEmpty())
112 GetDlgItem(IDC_MOVIE_PATH)->SetWindowText(p);
114 p = regQueryStringValue(IDS_CHEAT_DIR, NULL);
115 if (!p.IsEmpty())
116 GetDlgItem(IDC_CHEAT_PATH)->SetWindowText(p);
118 p = regQueryStringValue(IDS_IPS_DIR, NULL);
119 if (!p.IsEmpty())
120 GetDlgItem(IDC_IPS_PATH)->SetWindowText(p);
122 p = regQueryStringValue(IDS_LUA_DIR, NULL);
123 if (!p.IsEmpty())
124 GetDlgItem(IDC_LUA_PATH)->SetWindowText(p);
126 p = regQueryStringValue(IDS_AVI_DIR, NULL);
127 if (!p.IsEmpty())
128 GetDlgItem(IDC_AVI_PATH)->SetWindowText(p);
130 p = regQueryStringValue(IDS_WAV_DIR, NULL);
131 if (!p.IsEmpty())
132 GetDlgItem(IDC_WAV_PATH)->SetWindowText(p);
134 p = regQueryStringValue(IDS_CAPTURE_DIR, NULL);
135 if (!p.IsEmpty())
136 GetDlgItem(IDC_CAPTURE_PATH)->SetWindowText(p);
138 p = regQueryStringValue(IDS_WATCH_DIR, NULL);
139 if (!p.IsEmpty())
140 GetDlgItem(IDC_WATCH_PATH)->SetWindowText(p);
142 CenterWindow();
144 return TRUE; // return TRUE unless you set the focus to a control
145 // EXCEPTION: OCX Property Pages should return FALSE
146 }
148 void Directories::OnRomDir()
149 {
150 m_romPath.GetWindowText(initialFolderDir);
151 CString p = browseForDir(winResLoadString(IDS_SELECT_ROM_DIR));
152 if (!p.IsEmpty())
153 m_romPath.SetWindowText(p);
154 }
156 void Directories::OnRomDirReset()
157 {
158 m_romPath.SetWindowText("");
159 }
161 void Directories::OnGBxRomDir()
162 {
163 m_gbxromPath.GetWindowText(initialFolderDir);
164 CString p = browseForDir(winResLoadString(IDS_SELECT_GBXROM_DIR));
165 if (!p.IsEmpty())
166 m_gbxromPath.SetWindowText(p);
167 }
169 void Directories::OnGBxRomDirReset()
170 {
171 m_gbxromPath.SetWindowText("");
172 }
174 void Directories::OnBatteryDir()
175 {
176 m_batteryPath.GetWindowText(initialFolderDir);
177 CString p = browseForDir(winResLoadString(IDS_SELECT_BATTERY_DIR));
178 if (!p.IsEmpty())
179 m_batteryPath.SetWindowText(p);
180 }
182 void Directories::OnBatteryDirReset()
183 {
184 m_batteryPath.SetWindowText("");
185 }
187 void Directories::OnSaveDir()
188 {
189 m_savePath.GetWindowText(initialFolderDir);
190 CString p = browseForDir(winResLoadString(IDS_SELECT_SAVE_DIR));
191 if (!p.IsEmpty())
192 m_savePath.SetWindowText(p);
193 }
195 void Directories::OnSaveDirReset()
196 {
197 m_savePath.SetWindowText("");
198 }
200 void Directories::OnMovieDir()
201 {
202 m_moviePath.GetWindowText(initialFolderDir);
203 CString p = browseForDir(winResLoadString(IDS_SELECT_MOVIE_DIR));
204 if (!p.IsEmpty())
205 m_moviePath.SetWindowText(p);
206 }
208 void Directories::OnMovieDirReset()
209 {
210 m_moviePath.SetWindowText("");
211 }
213 void Directories::OnCheatDir()
214 {
215 m_cheatPath.GetWindowText(initialFolderDir);
216 CString p = browseForDir(winResLoadString(IDS_SELECT_CHEAT_DIR));
217 if (!p.IsEmpty())
218 m_cheatPath.SetWindowText(p);
219 }
221 void Directories::OnCheatDirReset()
222 {
223 m_cheatPath.SetWindowText("");
224 }
226 void Directories::OnLuaDir()
227 {
228 m_luaPath.GetWindowText(initialFolderDir);
229 CString p = browseForDir(winResLoadString(IDS_SELECT_LUA_DIR));
230 if (!p.IsEmpty())
231 m_luaPath.SetWindowText(p);
232 }
234 void Directories::OnLuaDirReset()
235 {
236 m_luaPath.SetWindowText("");
237 }
239 void Directories::OnAviDir()
240 {
241 m_aviPath.GetWindowText(initialFolderDir);
242 CString p = browseForDir(winResLoadString(IDS_SELECT_AVI_DIR));
243 if (!p.IsEmpty())
244 m_aviPath.SetWindowText(p);
245 }
247 void Directories::OnAviDirReset()
248 {
249 m_aviPath.SetWindowText("");
250 }
252 void Directories::OnWavDir()
253 {
254 m_wavPath.GetWindowText(initialFolderDir);
255 CString p = browseForDir(winResLoadString(IDS_SELECT_WAV_DIR));
256 if (!p.IsEmpty())
257 m_wavPath.SetWindowText(p);
258 }
260 void Directories::OnWavDirReset()
261 {
262 m_wavPath.SetWindowText("");
263 }
265 void Directories::OnCaptureDir()
266 {
267 m_capturePath.GetWindowText(initialFolderDir);
268 CString p = browseForDir(winResLoadString(IDS_SELECT_CAPTURE_DIR));
269 if (!p.IsEmpty())
270 m_capturePath.SetWindowText(p);
271 }
273 void Directories::OnCaptureDirReset()
274 {
275 m_capturePath.SetWindowText("");
276 }
278 void Directories::OnIpsDir()
279 {
280 m_ipsPath.GetWindowText(initialFolderDir);
281 CString p = browseForDir(winResLoadString(IDS_SELECT_IPS_DIR));
282 if (!p.IsEmpty())
283 m_ipsPath.SetWindowText(p);
284 }
286 void Directories::OnIpsDirReset()
287 {
288 m_ipsPath.SetWindowText("");
289 }
291 void Directories::OnWatchDir()
292 {
293 m_watchPath.GetWindowText(initialFolderDir);
294 CString p = browseForDir(winResLoadString(IDS_SELECT_WATCH_DIR));
295 if(!p.IsEmpty())
296 m_watchPath.SetWindowText(p);
297 }
299 void Directories::OnWatchDirReset()
300 {
301 m_watchPath.SetWindowText("");
302 }
304 void Directories::OnCancel()
305 {
306 EndDialog(FALSE);
307 }
309 void Directories::OnOK()
310 {
311 CString buffer;
313 m_romPath.GetWindowText(buffer);
314 if (!buffer.IsEmpty())
315 regSetStringValue(IDS_ROM_DIR, buffer);
316 else
317 regDeleteValue(IDS_ROM_DIR);
319 m_gbxromPath.GetWindowText(buffer);
320 if (!buffer.IsEmpty())
321 regSetStringValue(IDS_GBXROM_DIR, buffer);
322 else
323 regDeleteValue(IDS_GBXROM_DIR);
325 m_batteryPath.GetWindowText(buffer);
326 if (!buffer.IsEmpty())
327 regSetStringValue(IDS_BATTERY_DIR, buffer);
328 else
329 regDeleteValue(IDS_BATTERY_DIR);
331 m_savePath.GetWindowText(buffer);
332 if (!buffer.IsEmpty())
333 regSetStringValue(IDS_SAVE_DIR, buffer);
334 else
335 regDeleteValue(IDS_SAVE_DIR);
337 m_moviePath.GetWindowText(buffer);
338 if (!buffer.IsEmpty())
339 regSetStringValue(IDS_MOVIE_DIR, buffer);
340 else
341 regDeleteValue(IDS_MOVIE_DIR);
343 m_cheatPath.GetWindowText(buffer);
344 if (!buffer.IsEmpty())
345 regSetStringValue(IDS_CHEAT_DIR, buffer);
346 else
347 regDeleteValue(IDS_CHEAT_DIR);
349 m_ipsPath.GetWindowText(buffer);
350 if (!buffer.IsEmpty())
351 regSetStringValue(IDS_IPS_DIR, buffer);
352 else
353 regDeleteValue(IDS_IPS_DIR);
355 m_luaPath.GetWindowText(buffer);
356 if (!buffer.IsEmpty())
357 regSetStringValue(IDS_LUA_DIR, buffer);
358 else
359 regDeleteValue(IDS_LUA_DIR);
361 m_aviPath.GetWindowText(buffer);
362 if (!buffer.IsEmpty())
363 regSetStringValue(IDS_AVI_DIR, buffer);
364 else
365 regDeleteValue(IDS_AVI_DIR);
367 m_wavPath.GetWindowText(buffer);
368 if (!buffer.IsEmpty())
369 regSetStringValue(IDS_WAV_DIR, buffer);
370 else
371 regDeleteValue(IDS_WAV_DIR);
373 m_capturePath.GetWindowText(buffer);
374 if (!buffer.IsEmpty())
375 regSetStringValue(IDS_CAPTURE_DIR, buffer);
376 else
377 regDeleteValue(IDS_CAPTURE_DIR);
379 m_watchPath.GetWindowText(buffer);
380 if (!buffer.IsEmpty())
381 regSetStringValue(IDS_WATCH_DIR, buffer);
382 else
383 regDeleteValue(IDS_WATCH_DIR);
385 EndDialog(TRUE);
386 }
388 CString Directories::browseForDir(CString title)
389 {
390 static char buffer[1024];
391 LPMALLOC pMalloc;
392 LPITEMIDLIST pidl;
394 CString res;
396 if (SUCCEEDED(SHGetMalloc(&pMalloc)))
397 {
398 BROWSEINFO bi;
399 ZeroMemory(&bi, sizeof(bi));
400 bi.hwndOwner = m_hWnd;
401 bi.lpszTitle = title;
402 bi.pidlRoot = 0;
403 bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI; // will fail if COINIT_MULTITHREADED
404 bi.lpfn = browseCallbackProc;
405 bi.lParam = (LPARAM)(LPCTSTR)initialFolderDir;
407 pidl = SHBrowseForFolder(&bi);
409 if (pidl)
410 {
411 if (SHGetPathFromIDList(pidl, buffer))
412 {
413 res = buffer;
414 }
415 pMalloc->Free(pidl);
416 pMalloc->Release();
417 }
418 }
419 return res;
420 }