diff src/win32/Directories.cpp @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/win32/Directories.cpp	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,420 @@
     1.4 +// Directories.cpp : implementation file
     1.5 +//
     1.6 +
     1.7 +#include "stdafx.h"
     1.8 +#include <shlobj.h>
     1.9 +#include "resource.h"
    1.10 +#include "Directories.h"
    1.11 +#include "Reg.h"
    1.12 +#include "WinMiscUtil.h"
    1.13 +#include "WinResUtil.h"
    1.14 +
    1.15 +/////////////////////////////////////////////////////////////////////////////
    1.16 +// Directories dialog
    1.17 +
    1.18 +static int CALLBACK browseCallbackProc(HWND hWnd, UINT msg,
    1.19 +                                       LPARAM l, LPARAM data)
    1.20 +{
    1.21 +	char *buffer = (char *)data;
    1.22 +	switch (msg)
    1.23 +	{
    1.24 +	case BFFM_INITIALIZED:
    1.25 +		if (buffer[0])
    1.26 +			SendMessage(hWnd, BFFM_SETSELECTION, TRUE, (LPARAM)buffer);
    1.27 +		break;
    1.28 +	default:
    1.29 +		break;
    1.30 +	}
    1.31 +	return 0;
    1.32 +}
    1.33 +
    1.34 +Directories::Directories(CWnd*pParent /*=NULL*/)
    1.35 +	: CDialog(Directories::IDD, pParent)
    1.36 +{
    1.37 +	//{{AFX_DATA_INIT(Directories)
    1.38 +	// NOTE: the ClassWizard will add member initialization here
    1.39 +	//}}AFX_DATA_INIT
    1.40 +}
    1.41 +
    1.42 +void Directories::DoDataExchange(CDataExchange*pDX)
    1.43 +{
    1.44 +	CDialog::DoDataExchange(pDX);
    1.45 +	//{{AFX_DATA_MAP(Directories)
    1.46 +	DDX_Control(pDX, IDC_ROM_PATH, m_romPath);
    1.47 +	DDX_Control(pDX, IDC_GBXROM_PATH, m_gbxromPath);
    1.48 +	DDX_Control(pDX, IDC_BATTERY_PATH, m_batteryPath);
    1.49 +	DDX_Control(pDX, IDC_SAVE_PATH, m_savePath);
    1.50 +	DDX_Control(pDX, IDC_MOVIE_PATH, m_moviePath);
    1.51 +	DDX_Control(pDX, IDC_CHEAT_PATH, m_cheatPath);
    1.52 +	DDX_Control(pDX, IDC_IPS_PATH, m_ipsPath);
    1.53 +	DDX_Control(pDX, IDC_LUA_PATH, m_luaPath);
    1.54 +	DDX_Control(pDX, IDC_AVI_PATH, m_aviPath);
    1.55 +	DDX_Control(pDX, IDC_WAV_PATH, m_wavPath);
    1.56 +	DDX_Control(pDX, IDC_CAPTURE_PATH, m_capturePath);
    1.57 +	DDX_Control(pDX, IDC_WATCH_PATH, m_watchPath);
    1.58 +	//}}AFX_DATA_MAP
    1.59 +}
    1.60 +
    1.61 +BEGIN_MESSAGE_MAP(Directories, CDialog)
    1.62 +//{{AFX_MSG_MAP(Directories)
    1.63 +ON_BN_CLICKED(IDC_ROM_DIR, OnRomDir)
    1.64 +ON_BN_CLICKED(IDC_ROM_DIR_RESET, OnRomDirReset)
    1.65 +ON_BN_CLICKED(IDC_GBXROM_DIR, OnGBxRomDir)
    1.66 +ON_BN_CLICKED(IDC_GBXROM_DIR_RESET, OnGBxRomDirReset)
    1.67 +ON_BN_CLICKED(IDC_BATTERY_DIR, OnBatteryDir)
    1.68 +ON_BN_CLICKED(IDC_BATTERY_DIR_RESET, OnBatteryDirReset)
    1.69 +ON_BN_CLICKED(IDC_SAVE_DIR, OnSaveDir)
    1.70 +ON_BN_CLICKED(IDC_SAVE_DIR_RESET, OnSaveDirReset)
    1.71 +ON_BN_CLICKED(IDC_MOVIE_DIR, OnMovieDir)
    1.72 +ON_BN_CLICKED(IDC_MOVIE_DIR_RESET, OnMovieDirReset)
    1.73 +ON_BN_CLICKED(IDC_CHEAT_DIR, OnCheatDir)
    1.74 +ON_BN_CLICKED(IDC_CHEAT_DIR_RESET, OnCheatDirReset)
    1.75 +ON_BN_CLICKED(IDC_IPS_DIR, OnIpsDir)
    1.76 +ON_BN_CLICKED(IDC_IPS_DIR_RESET, OnIpsDirReset)
    1.77 +ON_BN_CLICKED(IDC_LUA_DIR, OnLuaDir)
    1.78 +ON_BN_CLICKED(IDC_LUA_DIR_RESET, OnLuaDirReset)
    1.79 +ON_BN_CLICKED(IDC_AVI_DIR, OnAviDir)
    1.80 +ON_BN_CLICKED(IDC_AVI_DIR_RESET, OnAviDirReset)
    1.81 +ON_BN_CLICKED(IDC_WAV_DIR, OnWavDir)
    1.82 +ON_BN_CLICKED(IDC_WAV_DIR_RESET, OnWavDirReset)
    1.83 +ON_BN_CLICKED(IDC_CAPTURE_DIR, OnCaptureDir)
    1.84 +ON_BN_CLICKED(IDC_CAPTURE_DIR_RESET, OnCaptureDirReset)
    1.85 +ON_BN_CLICKED(IDC_WATCH_DIR, OnWatchDir)
    1.86 +ON_BN_CLICKED(IDC_WATCH_DIR_RESET, OnWatchDirReset)
    1.87 +//}}AFX_MSG_MAP
    1.88 +END_MESSAGE_MAP()
    1.89 +
    1.90 +/////////////////////////////////////////////////////////////////////////////
    1.91 +// Directories message handlers
    1.92 +
    1.93 +BOOL Directories::OnInitDialog()
    1.94 +{
    1.95 +	CDialog::OnInitDialog();
    1.96 +
    1.97 +	CString p = regQueryStringValue(IDS_ROM_DIR, NULL);
    1.98 +	if (!p.IsEmpty())
    1.99 +		GetDlgItem(IDC_ROM_PATH)->SetWindowText(p);
   1.100 +
   1.101 +	p = regQueryStringValue(IDS_GBXROM_DIR, NULL);
   1.102 +	if (!p.IsEmpty())
   1.103 +		GetDlgItem(IDC_GBXROM_PATH)->SetWindowText(p);
   1.104 +
   1.105 +	p = regQueryStringValue(IDS_BATTERY_DIR, NULL);
   1.106 +	if (!p.IsEmpty())
   1.107 +		GetDlgItem(IDC_BATTERY_PATH)->SetWindowText(p);
   1.108 +
   1.109 +	p = regQueryStringValue(IDS_SAVE_DIR, NULL);
   1.110 +	if (!p.IsEmpty())
   1.111 +		GetDlgItem(IDC_SAVE_PATH)->SetWindowText(p);
   1.112 +
   1.113 +	p = regQueryStringValue(IDS_MOVIE_DIR, NULL);
   1.114 +	if (!p.IsEmpty())
   1.115 +		GetDlgItem(IDC_MOVIE_PATH)->SetWindowText(p);
   1.116 +
   1.117 +	p = regQueryStringValue(IDS_CHEAT_DIR, NULL);
   1.118 +	if (!p.IsEmpty())
   1.119 +		GetDlgItem(IDC_CHEAT_PATH)->SetWindowText(p);
   1.120 +
   1.121 +	p = regQueryStringValue(IDS_IPS_DIR, NULL);
   1.122 +	if (!p.IsEmpty())
   1.123 +		GetDlgItem(IDC_IPS_PATH)->SetWindowText(p);
   1.124 +
   1.125 +	p = regQueryStringValue(IDS_LUA_DIR, NULL);
   1.126 +	if (!p.IsEmpty())
   1.127 +		GetDlgItem(IDC_LUA_PATH)->SetWindowText(p);
   1.128 +
   1.129 +	p = regQueryStringValue(IDS_AVI_DIR, NULL);
   1.130 +	if (!p.IsEmpty())
   1.131 +		GetDlgItem(IDC_AVI_PATH)->SetWindowText(p);
   1.132 +
   1.133 +	p = regQueryStringValue(IDS_WAV_DIR, NULL);
   1.134 +	if (!p.IsEmpty())
   1.135 +		GetDlgItem(IDC_WAV_PATH)->SetWindowText(p);
   1.136 +
   1.137 +	p = regQueryStringValue(IDS_CAPTURE_DIR, NULL);
   1.138 +	if (!p.IsEmpty())
   1.139 +		GetDlgItem(IDC_CAPTURE_PATH)->SetWindowText(p);
   1.140 +
   1.141 +	p = regQueryStringValue(IDS_WATCH_DIR, NULL);
   1.142 +	if (!p.IsEmpty())
   1.143 +		GetDlgItem(IDC_WATCH_PATH)->SetWindowText(p);
   1.144 +
   1.145 +	CenterWindow();
   1.146 +
   1.147 +	return TRUE; // return TRUE unless you set the focus to a control
   1.148 +	             // EXCEPTION: OCX Property Pages should return FALSE
   1.149 +}
   1.150 +
   1.151 +void Directories::OnRomDir()
   1.152 +{
   1.153 +	m_romPath.GetWindowText(initialFolderDir);
   1.154 +	CString p = browseForDir(winResLoadString(IDS_SELECT_ROM_DIR));
   1.155 +	if (!p.IsEmpty())
   1.156 +		m_romPath.SetWindowText(p);
   1.157 +}
   1.158 +
   1.159 +void Directories::OnRomDirReset()
   1.160 +{
   1.161 +	m_romPath.SetWindowText("");
   1.162 +}
   1.163 +
   1.164 +void Directories::OnGBxRomDir()
   1.165 +{
   1.166 +	m_gbxromPath.GetWindowText(initialFolderDir);
   1.167 +	CString p = browseForDir(winResLoadString(IDS_SELECT_GBXROM_DIR));
   1.168 +	if (!p.IsEmpty())
   1.169 +		m_gbxromPath.SetWindowText(p);
   1.170 +}
   1.171 +
   1.172 +void Directories::OnGBxRomDirReset()
   1.173 +{
   1.174 +	m_gbxromPath.SetWindowText("");
   1.175 +}
   1.176 +
   1.177 +void Directories::OnBatteryDir()
   1.178 +{
   1.179 +	m_batteryPath.GetWindowText(initialFolderDir);
   1.180 +	CString p = browseForDir(winResLoadString(IDS_SELECT_BATTERY_DIR));
   1.181 +	if (!p.IsEmpty())
   1.182 +		m_batteryPath.SetWindowText(p);
   1.183 +}
   1.184 +
   1.185 +void Directories::OnBatteryDirReset()
   1.186 +{
   1.187 +	m_batteryPath.SetWindowText("");
   1.188 +}
   1.189 +
   1.190 +void Directories::OnSaveDir()
   1.191 +{
   1.192 +	m_savePath.GetWindowText(initialFolderDir);
   1.193 +	CString p = browseForDir(winResLoadString(IDS_SELECT_SAVE_DIR));
   1.194 +	if (!p.IsEmpty())
   1.195 +		m_savePath.SetWindowText(p);
   1.196 +}
   1.197 +
   1.198 +void Directories::OnSaveDirReset()
   1.199 +{
   1.200 +	m_savePath.SetWindowText("");
   1.201 +}
   1.202 +
   1.203 +void Directories::OnMovieDir()
   1.204 +{
   1.205 +	m_moviePath.GetWindowText(initialFolderDir);
   1.206 +	CString p = browseForDir(winResLoadString(IDS_SELECT_MOVIE_DIR));
   1.207 +	if (!p.IsEmpty())
   1.208 +		m_moviePath.SetWindowText(p);
   1.209 +}
   1.210 +
   1.211 +void Directories::OnMovieDirReset()
   1.212 +{
   1.213 +	m_moviePath.SetWindowText("");
   1.214 +}
   1.215 +
   1.216 +void Directories::OnCheatDir()
   1.217 +{
   1.218 +	m_cheatPath.GetWindowText(initialFolderDir);
   1.219 +	CString p = browseForDir(winResLoadString(IDS_SELECT_CHEAT_DIR));
   1.220 +	if (!p.IsEmpty())
   1.221 +		m_cheatPath.SetWindowText(p);
   1.222 +}
   1.223 +
   1.224 +void Directories::OnCheatDirReset()
   1.225 +{
   1.226 +	m_cheatPath.SetWindowText("");
   1.227 +}
   1.228 +
   1.229 +void Directories::OnLuaDir()
   1.230 +{
   1.231 +	m_luaPath.GetWindowText(initialFolderDir);
   1.232 +	CString p = browseForDir(winResLoadString(IDS_SELECT_LUA_DIR));
   1.233 +	if (!p.IsEmpty())
   1.234 +		m_luaPath.SetWindowText(p);
   1.235 +}
   1.236 +
   1.237 +void Directories::OnLuaDirReset()
   1.238 +{
   1.239 +	m_luaPath.SetWindowText("");
   1.240 +}
   1.241 +
   1.242 +void Directories::OnAviDir()
   1.243 +{
   1.244 +	m_aviPath.GetWindowText(initialFolderDir);
   1.245 +	CString p = browseForDir(winResLoadString(IDS_SELECT_AVI_DIR));
   1.246 +	if (!p.IsEmpty())
   1.247 +		m_aviPath.SetWindowText(p);
   1.248 +}
   1.249 +
   1.250 +void Directories::OnAviDirReset()
   1.251 +{
   1.252 +	m_aviPath.SetWindowText("");
   1.253 +}
   1.254 +
   1.255 +void Directories::OnWavDir()
   1.256 +{
   1.257 +	m_wavPath.GetWindowText(initialFolderDir);
   1.258 +	CString p = browseForDir(winResLoadString(IDS_SELECT_WAV_DIR));
   1.259 +	if (!p.IsEmpty())
   1.260 +		m_wavPath.SetWindowText(p);
   1.261 +}
   1.262 +
   1.263 +void Directories::OnWavDirReset()
   1.264 +{
   1.265 +	m_wavPath.SetWindowText("");
   1.266 +}
   1.267 +
   1.268 +void Directories::OnCaptureDir()
   1.269 +{
   1.270 +	m_capturePath.GetWindowText(initialFolderDir);
   1.271 +	CString p = browseForDir(winResLoadString(IDS_SELECT_CAPTURE_DIR));
   1.272 +	if (!p.IsEmpty())
   1.273 +		m_capturePath.SetWindowText(p);
   1.274 +}
   1.275 +
   1.276 +void Directories::OnCaptureDirReset()
   1.277 +{
   1.278 +	m_capturePath.SetWindowText("");
   1.279 +}
   1.280 +
   1.281 +void Directories::OnIpsDir()
   1.282 +{
   1.283 +	m_ipsPath.GetWindowText(initialFolderDir);
   1.284 +	CString p = browseForDir(winResLoadString(IDS_SELECT_IPS_DIR));
   1.285 +	if (!p.IsEmpty())
   1.286 +		m_ipsPath.SetWindowText(p);
   1.287 +}
   1.288 +
   1.289 +void Directories::OnIpsDirReset()
   1.290 +{
   1.291 +	m_ipsPath.SetWindowText("");
   1.292 +}
   1.293 +
   1.294 +void Directories::OnWatchDir()
   1.295 +{
   1.296 +	m_watchPath.GetWindowText(initialFolderDir);
   1.297 +	CString p = browseForDir(winResLoadString(IDS_SELECT_WATCH_DIR));
   1.298 +	if(!p.IsEmpty())
   1.299 +		m_watchPath.SetWindowText(p);
   1.300 +}
   1.301 +
   1.302 +void Directories::OnWatchDirReset()
   1.303 +{
   1.304 +	m_watchPath.SetWindowText("");
   1.305 +}
   1.306 +
   1.307 +void Directories::OnCancel()
   1.308 +{
   1.309 +	EndDialog(FALSE);
   1.310 +}
   1.311 +
   1.312 +void Directories::OnOK()
   1.313 +{
   1.314 +	CString buffer;
   1.315 +
   1.316 +	m_romPath.GetWindowText(buffer);
   1.317 +	if (!buffer.IsEmpty())
   1.318 +		regSetStringValue(IDS_ROM_DIR, buffer);
   1.319 +	else
   1.320 +		regDeleteValue(IDS_ROM_DIR);
   1.321 +
   1.322 +	m_gbxromPath.GetWindowText(buffer);
   1.323 +	if (!buffer.IsEmpty())
   1.324 +		regSetStringValue(IDS_GBXROM_DIR, buffer);
   1.325 +	else
   1.326 +		regDeleteValue(IDS_GBXROM_DIR);
   1.327 +
   1.328 +	m_batteryPath.GetWindowText(buffer);
   1.329 +	if (!buffer.IsEmpty())
   1.330 +		regSetStringValue(IDS_BATTERY_DIR, buffer);
   1.331 +	else
   1.332 +		regDeleteValue(IDS_BATTERY_DIR);
   1.333 +
   1.334 +	m_savePath.GetWindowText(buffer);
   1.335 +	if (!buffer.IsEmpty())
   1.336 +		regSetStringValue(IDS_SAVE_DIR, buffer);
   1.337 +	else
   1.338 +		regDeleteValue(IDS_SAVE_DIR);
   1.339 +
   1.340 +	m_moviePath.GetWindowText(buffer);
   1.341 +	if (!buffer.IsEmpty())
   1.342 +		regSetStringValue(IDS_MOVIE_DIR, buffer);
   1.343 +	else
   1.344 +		regDeleteValue(IDS_MOVIE_DIR);
   1.345 +
   1.346 +	m_cheatPath.GetWindowText(buffer);
   1.347 +	if (!buffer.IsEmpty())
   1.348 +		regSetStringValue(IDS_CHEAT_DIR, buffer);
   1.349 +	else
   1.350 +		regDeleteValue(IDS_CHEAT_DIR);
   1.351 +
   1.352 +	m_ipsPath.GetWindowText(buffer);
   1.353 +	if (!buffer.IsEmpty())
   1.354 +		regSetStringValue(IDS_IPS_DIR, buffer);
   1.355 +	else
   1.356 +		regDeleteValue(IDS_IPS_DIR);
   1.357 +
   1.358 +	m_luaPath.GetWindowText(buffer);
   1.359 +	if (!buffer.IsEmpty())
   1.360 +		regSetStringValue(IDS_LUA_DIR, buffer);
   1.361 +	else
   1.362 +		regDeleteValue(IDS_LUA_DIR);
   1.363 +
   1.364 +	m_aviPath.GetWindowText(buffer);
   1.365 +	if (!buffer.IsEmpty())
   1.366 +		regSetStringValue(IDS_AVI_DIR, buffer);
   1.367 +	else
   1.368 +		regDeleteValue(IDS_AVI_DIR);
   1.369 +
   1.370 +	m_wavPath.GetWindowText(buffer);
   1.371 +	if (!buffer.IsEmpty())
   1.372 +		regSetStringValue(IDS_WAV_DIR, buffer);
   1.373 +	else
   1.374 +		regDeleteValue(IDS_WAV_DIR);
   1.375 +
   1.376 +	m_capturePath.GetWindowText(buffer);
   1.377 +	if (!buffer.IsEmpty())
   1.378 +		regSetStringValue(IDS_CAPTURE_DIR, buffer);
   1.379 +	else
   1.380 +		regDeleteValue(IDS_CAPTURE_DIR);
   1.381 +
   1.382 +	m_watchPath.GetWindowText(buffer);
   1.383 +	if (!buffer.IsEmpty())
   1.384 +		regSetStringValue(IDS_WATCH_DIR, buffer);
   1.385 +	else
   1.386 +		regDeleteValue(IDS_WATCH_DIR);
   1.387 +
   1.388 +	EndDialog(TRUE);
   1.389 +}
   1.390 +
   1.391 +CString Directories::browseForDir(CString title)
   1.392 +{
   1.393 +	static char  buffer[1024];
   1.394 +	LPMALLOC     pMalloc;
   1.395 +	LPITEMIDLIST pidl;
   1.396 +
   1.397 +	CString res;
   1.398 +
   1.399 +	if (SUCCEEDED(SHGetMalloc(&pMalloc)))
   1.400 +	{
   1.401 +		BROWSEINFO bi;
   1.402 +		ZeroMemory(&bi, sizeof(bi));
   1.403 +		bi.hwndOwner = m_hWnd;
   1.404 +		bi.lpszTitle = title;
   1.405 +		bi.pidlRoot  = 0;
   1.406 +		bi.ulFlags   = BIF_RETURNONLYFSDIRS | BIF_USENEWUI;	// will fail if COINIT_MULTITHREADED
   1.407 +		bi.lpfn      = browseCallbackProc;
   1.408 +		bi.lParam    = (LPARAM)(LPCTSTR)initialFolderDir;
   1.409 +
   1.410 +		pidl = SHBrowseForFolder(&bi);
   1.411 +
   1.412 +		if (pidl)
   1.413 +		{
   1.414 +			if (SHGetPathFromIDList(pidl, buffer))
   1.415 +			{
   1.416 +				res = buffer;
   1.417 +			}
   1.418 +			pMalloc->Free(pidl);
   1.419 +			pMalloc->Release();
   1.420 +		}
   1.421 +	}
   1.422 +	return res;
   1.423 +}