annotate src/win32/Directories.cpp @ 2:3549bbe597ed

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