mirror of
https://github.com/isledecomp/LEGOIslandRebuilder.git
synced 2025-03-23 19:19:40 -04:00
implemented config loading
This commit is contained in:
parent
8eb36e84ca
commit
04578b19b4
6 changed files with 106 additions and 18 deletions
|
@ -1 +1 @@
|
|||
Subproject commit 937145d0f2a0bc43d8e69927fff1b166fb93ce69
|
||||
Subproject commit 7f40af32bc7f121078d3c2b90a2656146d65cb3a
|
|
@ -145,8 +145,7 @@ LONG WINAPI InterceptRegQueryValueExA(HKEY hKey, LPCSTR lpValueName, LPDWORD lpR
|
|||
|
||||
} else if (!strcmp(lpValueName, "Full Screen")) {
|
||||
|
||||
//ReturnRegistryYESNOFromBool(lpData, config.GetInt(_T("FullScreen"), 1));
|
||||
ReturnRegistryYESNOFromBool(lpData, FALSE);
|
||||
ReturnRegistryYESNOFromBool(lpData, config.GetInt(_T("FullScreen"), 1));
|
||||
return ERROR_SUCCESS;
|
||||
|
||||
} else if (!strcmp(lpValueName, "Draw Cursor")) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "patchgrid.h"
|
||||
|
||||
#include <SHLWAPI.H>
|
||||
#include <SSTREAM>
|
||||
|
||||
#include "../cmn/path.h"
|
||||
|
@ -142,6 +143,61 @@ std::string toString(const T &value)
|
|||
return oss.str();
|
||||
}
|
||||
|
||||
void PatchGrid::LoadConfiguration(LPCTSTR filename)
|
||||
{
|
||||
for (std::map<std::string, HITEM>::const_iterator it=m_mPatchItems.begin(); it!=m_mPatchItems.end(); it++) {
|
||||
CItem *item = FindItem(it->second);
|
||||
|
||||
std::string value;
|
||||
value.resize(1024);
|
||||
|
||||
char buf[1024];
|
||||
|
||||
DWORD sz = GetPrivateProfileString(appName, it->first.c_str(), NULL, &value[0], value.size(), filename);
|
||||
|
||||
// If this entry wasn't in the profile, skip it
|
||||
if (!sz) {
|
||||
continue;
|
||||
}
|
||||
|
||||
value.resize(sz);
|
||||
|
||||
// Convert value to string
|
||||
switch (item->m_type) {
|
||||
case IT_STRING:
|
||||
case IT_TEXT:
|
||||
case IT_FILE:
|
||||
case IT_FOLDER:
|
||||
case IT_COMBO:
|
||||
SetItemValue(it->second, value);
|
||||
break;
|
||||
case IT_BOOLEAN:
|
||||
SetItemValue(it->second, (bool)StrToIntA(value.c_str()));
|
||||
break;
|
||||
case IT_INTEGER:
|
||||
SetItemValue(it->second, StrToIntA(value.c_str()));
|
||||
break;
|
||||
case IT_DOUBLE:
|
||||
SetItemValue(it->second, atof(value.c_str()));
|
||||
break;
|
||||
case IT_COLOR:
|
||||
SetItemValue(it->second, (COLORREF) StrToIntA(value.c_str()));
|
||||
break;
|
||||
case IT_CUSTOM:
|
||||
case IT_DATE:
|
||||
case IT_DATETIME:
|
||||
case IT_FONT:
|
||||
{
|
||||
// Report inability to serialize
|
||||
TCHAR buf[200];
|
||||
sprintf(buf, "Failed to serialize %s from string.", it->first.c_str());
|
||||
MessageBox(buf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOL PatchGrid::SaveConfiguration(LPCTSTR filename)
|
||||
{
|
||||
for (std::map<std::string, HITEM>::const_iterator it=m_mPatchItems.begin(); it!=m_mPatchItems.end(); it++) {
|
||||
|
@ -156,19 +212,29 @@ BOOL PatchGrid::SaveConfiguration(LPCTSTR filename)
|
|||
case IT_FILE:
|
||||
case IT_FOLDER:
|
||||
case IT_COMBO:
|
||||
value = item->m_strValue;
|
||||
GetItemValue(it->second, value);
|
||||
break;
|
||||
case IT_BOOLEAN:
|
||||
value = toString(item->m_bValue);
|
||||
{
|
||||
bool b;
|
||||
GetItemValue(it->second, b);
|
||||
value = toString(b);
|
||||
break;
|
||||
}
|
||||
case IT_INTEGER:
|
||||
value = toString(item->m_nValue);
|
||||
int i;
|
||||
GetItemValue(it->second, i);
|
||||
value = toString(i);
|
||||
break;
|
||||
case IT_DOUBLE:
|
||||
value = toString(item->m_dValue);
|
||||
double d;
|
||||
GetItemValue(it->second, d);
|
||||
value = toString(d);
|
||||
break;
|
||||
case IT_COLOR:
|
||||
value = toString(item->m_clrValue);
|
||||
COLORREF c;
|
||||
GetItemValue(it->second, c);
|
||||
value = toString(c);
|
||||
break;
|
||||
case IT_CUSTOM:
|
||||
case IT_DATE:
|
||||
|
@ -183,7 +249,6 @@ BOOL PatchGrid::SaveConfiguration(LPCTSTR filename)
|
|||
}
|
||||
}
|
||||
|
||||
this->GetItemValue(it->second, value);
|
||||
if (!WritePrivateProfileString(appName, it->first.c_str(), value.c_str(), filename)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ class PatchGrid : public CPropertyGrid
|
|||
public:
|
||||
PatchGrid();
|
||||
|
||||
void LoadConfiguration(LPCTSTR filename);
|
||||
BOOL SaveConfiguration(LPCTSTR filename);
|
||||
|
||||
private:
|
||||
|
|
|
@ -78,6 +78,16 @@ CRebuilderWindow::CRebuilderWindow()
|
|||
RECT patchGridClientRect;
|
||||
m_cPatchGrid.GetClientRect(&patchGridClientRect);
|
||||
m_cPatchGrid.SetGutterWidth((patchGridClientRect.right - patchGridClientRect.left) / 2);
|
||||
|
||||
TCHAR configPath[MAX_PATH];
|
||||
if (GetConfigFilename(configPath)) {
|
||||
m_cPatchGrid.LoadConfiguration(configPath);
|
||||
}
|
||||
}
|
||||
|
||||
CRebuilderWindow::~CRebuilderWindow()
|
||||
{
|
||||
TrySaving();
|
||||
}
|
||||
|
||||
DWORD WINAPI WaitForProcessToClose(HANDLE hProcess)
|
||||
|
@ -88,26 +98,35 @@ DWORD WINAPI WaitForProcessToClose(HANDLE hProcess)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void CRebuilderWindow::OnRunClick()
|
||||
BOOL CRebuilderWindow::TrySaving()
|
||||
{
|
||||
TCHAR configPath[MAX_PATH];
|
||||
|
||||
if (GetConfigFilename(configPath)) {
|
||||
if (m_cPatchGrid.SaveConfiguration(configPath)) {
|
||||
if (HANDLE proc = Launcher::Launch(this->GetSafeHwnd())) {
|
||||
m_lProcesses.push_back(proc);
|
||||
SwitchButtonMode(TRUE);
|
||||
|
||||
// Register callback when process exits
|
||||
DWORD threadId; // We don't use this, but Windows 95 will fail without it
|
||||
CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)WaitForProcessToClose, proc, 0, &threadId));
|
||||
}
|
||||
return TRUE;
|
||||
} else {
|
||||
MessageBox(_T("Failed to save configuration file."));
|
||||
}
|
||||
} else {
|
||||
MessageBox(_T("Failed to determine configuration path."));
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void CRebuilderWindow::OnRunClick()
|
||||
{
|
||||
if (TrySaving()) {
|
||||
if (HANDLE proc = Launcher::Launch(this->GetSafeHwnd())) {
|
||||
m_lProcesses.push_back(proc);
|
||||
SwitchButtonMode(TRUE);
|
||||
|
||||
// Register callback when process exits
|
||||
DWORD threadId; // We don't use this, but Windows 95 will fail without it
|
||||
CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)WaitForProcessToClose, proc, 0, &threadId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CRebuilderWindow::OnKillClick()
|
||||
|
|
|
@ -13,6 +13,8 @@ class CRebuilderWindow : public CFrameWnd
|
|||
public:
|
||||
CRebuilderWindow();
|
||||
|
||||
~CRebuilderWindow();
|
||||
|
||||
afx_msg void OnRunClick();
|
||||
|
||||
afx_msg void OnKillClick();
|
||||
|
@ -34,6 +36,8 @@ private:
|
|||
|
||||
void SwitchButtonMode(BOOL running);
|
||||
|
||||
BOOL TrySaving();
|
||||
|
||||
enum {
|
||||
ID_RUN = 1000,
|
||||
ID_KILL,
|
||||
|
|
Loading…
Add table
Reference in a new issue