project64/Source/Project64/UserInterface/Settings/SettingsPage-Directories.cpp

389 lines
12 KiB
C++
Raw Normal View History

2016-01-27 09:11:59 +00:00
#include "stdafx.h"
#include "SettingsPage.h"
COptionsDirectoriesPage::COptionsDirectoriesPage(HWND hParent, const RECT & rcDispay) :
2022-09-21 05:16:07 +00:00
m_InUpdateSettings(false)
2016-01-27 09:11:59 +00:00
{
Create(hParent);
2021-04-12 11:35:39 +00:00
if (m_hWnd == nullptr)
2016-01-27 09:11:59 +00:00
{
return;
}
SetWindowPos(HWND_TOP, &rcDispay, SWP_HIDEWINDOW);
m_PluginGroup.Attach(GetDlgItem(IDC_DIR_FRAME1));
m_AutoSaveGroup.Attach(GetDlgItem(IDC_DIR_FRAME3));
m_InstantSaveGroup.Attach(GetDlgItem(IDC_DIR_FRAME4));
m_ScreenShotGroup.Attach(GetDlgItem(IDC_DIR_FRAME5));
m_TextureGroup.Attach(GetDlgItem(IDC_DIR_TEXTURE_FRAME));
m_PluginDir.Attach(GetDlgItem(IDC_PLUGIN_DIR));
m_AutoSaveDir.Attach(GetDlgItem(IDC_AUTO_DIR));
m_InstantSaveDir.Attach(GetDlgItem(IDC_INSTANT_DIR));
m_ScreenShotDir.Attach(GetDlgItem(IDC_SNAP_DIR));
m_TextureDir.Attach(GetDlgItem(IDC_TEXTURE_DIR));
m_PluginDefault.Attach(GetDlgItem(IDC_PLUGIN_DEFAULT));
m_PluginSelected.Attach(GetDlgItem(IDC_PLUGIN_OTHER));
m_AutoSaveDefault.Attach(GetDlgItem(IDC_AUTO_DEFAULT));
m_AutoSaveSelected.Attach(GetDlgItem(IDC_AUTO_OTHER));
m_InstantDefault.Attach(GetDlgItem(IDC_INSTANT_DEFAULT));
m_InstantSelected.Attach(GetDlgItem(IDC_INSTANT_OTHER));
m_ScreenShotDefault.Attach(GetDlgItem(IDC_SNAP_DEFAULT));
m_ScreenShotSelected.Attach(GetDlgItem(IDC_SNAP_OTHER));
m_TextureDefault.Attach(GetDlgItem(IDC_TEXTURE_DEFAULT));
m_TextureSelected.Attach(GetDlgItem(IDC_TEXTURE_OTHER));
// Set text language for the dialog box
::SetWindowText(m_PluginGroup.m_hWnd, wGS(DIR_PLUGIN).c_str());
::SetWindowText(m_AutoSaveGroup.m_hWnd, wGS(DIR_AUTO_SAVE).c_str());
::SetWindowText(m_InstantSaveGroup.m_hWnd, wGS(DIR_INSTANT_SAVE).c_str());
::SetWindowText(m_ScreenShotGroup.m_hWnd, wGS(DIR_SCREEN_SHOT).c_str());
::SetWindowText(m_TextureGroup.m_hWnd, wGS(DIR_TEXTURE).c_str());
2016-01-27 09:11:59 +00:00
UpdatePageSettings();
}
int CALLBACK COptionsDirectoriesPage::SelectDirCallBack(HWND hwnd, DWORD uMsg, DWORD /*lp*/, DWORD lpData)
{
switch (uMsg)
{
case BFFM_INITIALIZED:
// WParam is true since you are passing a path
// It would be false if you were passing a PIDL
2016-01-27 09:11:59 +00:00
if (lpData)
{
SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData);
}
break;
}
return 0;
}
void COptionsDirectoriesPage::SelectDirectory(LanguageStringID Title, CModifiedEditBox & EditBox, CModifiedButton & Default, CModifiedButton & selected)
{
wchar_t Buffer[MAX_PATH], Directory[MAX_PATH];
LPITEMIDLIST pidl;
BROWSEINFO bi;
2016-01-27 09:11:59 +00:00
std::string InitialDir = GetCWindowText(EditBox);
2016-01-27 09:11:59 +00:00
std::wstring wTitle = wGS(Title);
bi.hwndOwner = m_hWnd;
2021-04-12 11:35:39 +00:00
bi.pidlRoot = nullptr;
2016-01-27 09:11:59 +00:00
bi.pszDisplayName = Buffer;
bi.lpszTitle = wTitle.c_str();
bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
bi.lpfn = (BFFCALLBACK)SelectDirCallBack;
bi.lParam = (DWORD)InitialDir.c_str();
2021-04-12 11:35:39 +00:00
if ((pidl = SHBrowseForFolder(&bi)) != nullptr)
2016-01-27 09:11:59 +00:00
{
if (SHGetPathFromIDList(pidl, Directory))
2016-01-27 09:11:59 +00:00
{
stdstr path;
CPath SelectedDir(path.FromUTF16(Directory), "");
EditBox.SetChanged(true);
2020-05-12 12:19:05 +00:00
EditBox.SetWindowText(stdstr((const char *)SelectedDir).ToUTF16().c_str());
2016-01-27 09:11:59 +00:00
Default.SetChanged(true);
Default.SetCheck(BST_UNCHECKED);
selected.SetCheck(BM_SETCHECK);
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
}
}
}
void COptionsDirectoriesPage::PluginDirChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{
2022-09-21 05:16:07 +00:00
if (m_InUpdateSettings)
{
return;
}
2016-01-27 09:11:59 +00:00
m_PluginDir.SetChanged(true);
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
}
void COptionsDirectoriesPage::AutoSaveDirChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{
2022-09-21 05:16:07 +00:00
if (m_InUpdateSettings)
{
return;
}
2016-01-27 09:11:59 +00:00
m_AutoSaveDir.SetChanged(true);
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
}
void COptionsDirectoriesPage::InstantSaveDirChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{
2022-09-21 05:16:07 +00:00
if (m_InUpdateSettings)
{
return;
}
2016-01-27 09:11:59 +00:00
m_InstantSaveDir.SetChanged(true);
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
}
void COptionsDirectoriesPage::SnapShotDirChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{
2022-09-21 05:16:07 +00:00
if (m_InUpdateSettings)
{
return;
}
2016-01-27 09:11:59 +00:00
m_ScreenShotDir.SetChanged(true);
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
}
void COptionsDirectoriesPage::TextureDirChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{
2022-09-21 05:16:07 +00:00
if (m_InUpdateSettings)
{
return;
}
2016-01-27 09:11:59 +00:00
m_TextureDir.SetChanged(true);
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
}
void COptionsDirectoriesPage::SelectPluginDir(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{
SelectDirectory(DIR_SELECT_PLUGIN, m_PluginDir, m_PluginDefault, m_PluginSelected);
}
void COptionsDirectoriesPage::SelectAutoDir(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{
SelectDirectory(DIR_SELECT_AUTO, m_AutoSaveDir, m_AutoSaveDefault, m_AutoSaveSelected);
}
void COptionsDirectoriesPage::SelectInstantDir(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{
SelectDirectory(DIR_SELECT_INSTANT, m_InstantSaveDir, m_InstantDefault, m_InstantSelected);
}
void COptionsDirectoriesPage::SelectSnapShotDir(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{
SelectDirectory(DIR_SELECT_SCREEN, m_ScreenShotDir, m_ScreenShotDefault, m_ScreenShotSelected);
}
void COptionsDirectoriesPage::SelectTextureDir(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{
SelectDirectory(DIR_SELECT_TEXTURE, m_TextureDir, m_TextureDefault, m_TextureSelected);
}
void COptionsDirectoriesPage::UpdatePageSettings()
{
stdstr Directory;
m_InUpdateSettings = true;
m_PluginDir.SetChanged(g_Settings->LoadStringVal(Directory_PluginSelected, Directory));
2020-05-12 12:19:05 +00:00
m_PluginDir.SetWindowText(Directory.ToUTF16().c_str());
2016-01-27 09:11:59 +00:00
m_AutoSaveDir.SetChanged(g_Settings->LoadStringVal(Directory_NativeSaveSelected, Directory));
2020-05-12 12:19:05 +00:00
m_AutoSaveDir.SetWindowText(Directory.ToUTF16().c_str());
2016-01-27 09:11:59 +00:00
m_InstantSaveDir.SetChanged(g_Settings->LoadStringVal(Directory_InstantSaveSelected, Directory));
2020-05-12 12:19:05 +00:00
m_InstantSaveDir.SetWindowText(Directory.ToUTF16().c_str());
2016-01-27 09:11:59 +00:00
m_ScreenShotDir.SetChanged(g_Settings->LoadStringVal(Directory_SnapShotSelected, Directory));
2020-05-12 12:19:05 +00:00
m_ScreenShotDir.SetWindowText(Directory.ToUTF16().c_str());
2016-01-27 09:11:59 +00:00
m_TextureDir.SetChanged(g_Settings->LoadStringVal(Directory_TextureSelected, Directory));
2020-05-12 12:19:05 +00:00
m_TextureDir.SetWindowText(Directory.ToUTF16().c_str());
2016-01-27 09:11:59 +00:00
bool UseSelected;
m_PluginDefault.SetChanged(g_Settings->LoadBool(Directory_PluginUseSelected, UseSelected));
m_PluginDefault.SetCheck(!UseSelected);
m_PluginSelected.SetCheck(UseSelected);
m_AutoSaveDefault.SetChanged(g_Settings->LoadBool(Directory_NativeSaveUseSelected, UseSelected));
m_AutoSaveDefault.SetCheck(!UseSelected);
m_AutoSaveSelected.SetCheck(UseSelected);
m_InstantDefault.SetChanged(g_Settings->LoadBool(Directory_InstantSaveUseSelected, UseSelected));
m_InstantDefault.SetCheck(!UseSelected);
m_InstantSelected.SetCheck(UseSelected);
m_ScreenShotDefault.SetChanged(g_Settings->LoadBool(Directory_SnapShotUseSelected, UseSelected));
m_ScreenShotDefault.SetCheck(!UseSelected);
m_ScreenShotSelected.SetCheck(UseSelected);
m_TextureDefault.SetChanged(g_Settings->LoadBool(Directory_TextureUseSelected, UseSelected));
m_TextureDefault.SetCheck(!UseSelected);
m_TextureSelected.SetCheck(UseSelected);
m_InUpdateSettings = false;
}
void COptionsDirectoriesPage::UseSelectedClicked(UINT /*Code*/, int id, HWND /*ctl*/)
{
2021-04-12 11:35:39 +00:00
CModifiedButton * Button = nullptr;
2016-01-27 09:11:59 +00:00
switch (id)
{
case IDC_PLUGIN_DEFAULT: Button = &m_PluginDefault; break;
case IDC_PLUGIN_OTHER: Button = &m_PluginDefault; break;
case IDC_AUTO_DEFAULT: Button = &m_AutoSaveDefault; break;
case IDC_AUTO_OTHER: Button = &m_AutoSaveDefault; break;
case IDC_INSTANT_DEFAULT: Button = &m_InstantDefault; break;
case IDC_INSTANT_OTHER: Button = &m_InstantDefault; break;
case IDC_SNAP_DEFAULT: Button = &m_ScreenShotDefault; break;
case IDC_SNAP_OTHER: Button = &m_ScreenShotDefault; break;
case IDC_TEXTURE_DEFAULT: Button = &m_TextureDefault; break;
case IDC_TEXTURE_OTHER: Button = &m_TextureDefault; break;
}
2021-04-12 11:35:39 +00:00
if (Button == nullptr)
2016-01-27 09:11:59 +00:00
{
return;
}
if (!Button->IsChanged() || Button->IsReset())
{
if ((int)Button->GetMenu() == id)
{
return;
}
}
Button->SetChanged(true);
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
}
void COptionsDirectoriesPage::HidePage()
{
ShowWindow(SW_HIDE);
}
void COptionsDirectoriesPage::ShowPage()
{
ShowWindow(SW_SHOW);
}
void COptionsDirectoriesPage::ResetDirectory(CModifiedEditBox & EditBox, SettingID Type)
{
if (!EditBox.IsChanged())
{
return;
}
stdstr dir;
g_Settings->LoadDefaultString(Type, dir);
2020-05-12 12:19:05 +00:00
EditBox.SetWindowText(dir.ToUTF16().c_str());
2016-01-27 09:11:59 +00:00
EditBox.SetReset(true);
}
void COptionsDirectoriesPage::ResetDefaultSelected(CModifiedButton & ButtonDefault, CModifiedButton & ButtonSelected, SettingID Type)
{
if (!ButtonDefault.IsChanged())
{
return;
}
bool UseSelected;
g_Settings->LoadDefaultBool(Type, UseSelected);
ButtonDefault.SetCheck(!UseSelected);
ButtonSelected.SetCheck(UseSelected);
ButtonDefault.SetReset(true);
}
void COptionsDirectoriesPage::UpdateDirectory(CModifiedEditBox & EditBox, SettingID Type)
{
if (EditBox.IsChanged())
{
g_Settings->SaveString(Type, GetCWindowText(EditBox).c_str());
2016-01-27 09:11:59 +00:00
}
if (EditBox.IsReset())
{
g_Settings->DeleteSetting(Type);
}
}
void COptionsDirectoriesPage::UpdateDefaultSelected(CModifiedButton & Button, SettingID Type)
{
if (Button.IsChanged())
{
bool bUseSelected = (Button.GetCheck() & BST_CHECKED) == 0;
g_Settings->SaveBool(Type, bUseSelected);
if (Type == Directory_TextureUseSelected && !bUseSelected)
{
g_Settings->DeleteSetting(Directory_TextureSelected);
}
}
if (Button.IsReset())
{
g_Settings->DeleteSetting(Type);
}
}
void COptionsDirectoriesPage::ApplySettings(bool UpdateScreen)
{
UpdateDirectory(m_PluginDir, Directory_PluginSelected);
UpdateDirectory(m_AutoSaveDir, Directory_NativeSaveSelected);
UpdateDirectory(m_InstantSaveDir, Directory_InstantSaveSelected);
UpdateDirectory(m_ScreenShotDir, Directory_SnapShotSelected);
UpdateDirectory(m_TextureDir, Directory_TextureSelected);
UpdateDefaultSelected(m_PluginDefault, Directory_PluginUseSelected);
UpdateDefaultSelected(m_AutoSaveDefault, Directory_NativeSaveUseSelected);
UpdateDefaultSelected(m_InstantDefault, Directory_InstantSaveUseSelected);
UpdateDefaultSelected(m_ScreenShotDefault, Directory_SnapShotUseSelected);
UpdateDefaultSelected(m_TextureDefault, Directory_TextureUseSelected);
if (UpdateScreen)
{
UpdatePageSettings();
}
}
bool COptionsDirectoriesPage::EnableReset(void)
{
2022-09-21 05:16:07 +00:00
if (m_PluginDir.IsChanged())
{
return true;
}
if (m_AutoSaveDir.IsChanged())
{
return true;
}
if (m_InstantSaveDir.IsChanged())
{
return true;
}
if (m_ScreenShotDir.IsChanged())
{
return true;
}
if (m_TextureDir.IsChanged())
{
return true;
}
if (m_PluginDefault.IsChanged())
{
return true;
}
if (m_AutoSaveDefault.IsChanged())
{
return true;
}
if (m_InstantDefault.IsChanged())
{
return true;
}
if (m_ScreenShotDefault.IsChanged())
{
return true;
}
if (m_TextureDefault.IsChanged())
{
return true;
}
2016-01-27 09:11:59 +00:00
return false;
}
void COptionsDirectoriesPage::ResetPage()
{
ResetDirectory(m_PluginDir, Directory_PluginSelected);
ResetDirectory(m_AutoSaveDir, Directory_NativeSaveSelected);
ResetDirectory(m_InstantSaveDir, Directory_InstantSaveSelected);
ResetDirectory(m_ScreenShotDir, Directory_SnapShotSelected);
ResetDirectory(m_TextureDir, Directory_TextureSelected);
ResetDefaultSelected(m_PluginDefault, m_PluginSelected, Directory_PluginUseSelected);
ResetDefaultSelected(m_AutoSaveDefault, m_AutoSaveSelected, Directory_NativeSaveUseSelected);
ResetDefaultSelected(m_InstantDefault, m_InstantSelected, Directory_InstantSaveUseSelected);
ResetDefaultSelected(m_ScreenShotDefault, m_ScreenShotSelected, Directory_SnapShotUseSelected);
ResetDefaultSelected(m_TextureDefault, m_TextureSelected, Directory_TextureUseSelected);
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
}