win32: Ask about registry keys on first start. Also...

add a command-line option to remove these keys.
This commit is contained in:
BearOso 2023-03-08 14:31:55 -06:00
parent 879134ca5a
commit 036fa5a951
3 changed files with 49 additions and 6 deletions

View File

@ -40,7 +40,11 @@ extern TCHAR multiRomB[MAX_PATH];
void S9xParseArg (char **argv, int &i, int argc)
{
if (strcasecmp (argv [i], "-restore") == 0)
if (strcasecmp (argv [i], "-removeregistrykeys"))
{
S9xWinRemoveRegistryKeys();
}
else if (strcasecmp (argv [i], "-restore") == 0)
{
WinDeleteRegistryEntries ();
WinSetDefaultValues ();
@ -814,7 +818,7 @@ void WinRegisterConfigItems()
AddUIntC("RewindGranularity", GUI.rewindGranularity, 1, "rewind granularity - rewind takes a snapshot each x frames");
AddBoolC("PauseWhenInactive", GUI.InactivePause, TRUE, "true to pause Snes9x when it is not the active window");
AddBoolC("CustomRomOpenDialog", GUI.CustomRomOpen, false, "false to use standard Windows open dialog for the ROM open dialog");
AddBoolC("AddToRegistry", GUI.AddToRegistry, false, "true to add entries to registry for file type associations");
AddBoolC("AddToRegistry", GUI.AddToRegistry, true, "true to ask to add entries to registry for file type associations");
AddBoolC("AVIHiRes", GUI.AVIHiRes, false, "true to record AVI in Hi-Res scale");
AddBoolC("ConfirmSaveLoad", GUI.ConfirmSaveLoad, false, "true to ask for confirmation when saving/loading");
// AddUIntC("Language", GUI.Language, 0, "0=English, 1=Nederlands"); // NYI

View File

@ -2721,6 +2721,7 @@ void S9xExtraUsage ()
S9xMessage(S9X_INFO, S9X_USAGE, "-fullscreen Start in fullscreen mode");
S9xMessage(S9X_INFO, S9X_USAGE, "-hidemenu Initially hide the GUI menu");
S9xMessage(S9X_INFO, S9X_USAGE, "-restore Reset all settings to default");
S9xMessage(S9X_INFO, S9X_USAGE, "-removeregistrykeys Remove registry keys");
S9xMessage(S9X_INFO, S9X_USAGE, "-cartb <filename> Specify the second cart for multicart, also triggers multicart");
MessageBox(NULL, _T("Snes9x command line options have been written to stdout.txt in the same folder as snes9x.exe"), _T("Command line options"), MB_OK | MB_ICONINFORMATION);
}
@ -3240,8 +3241,6 @@ int WINAPI WinMain(
DWORD wSoundTimerRes;
LoadExts();
WinRegisterConfigItems ();
ConfigFile::SetAlphaSort(false);
@ -3251,6 +3250,8 @@ int WINAPI WinMain(
WinSaveConfigFile ();
WinLockConfigFile ();
LoadExts();
ControllerOptionsFromControllers();
ChangeInputDevice();
@ -7015,6 +7016,32 @@ void SetInfoDlgColor(unsigned char r, unsigned char g, unsigned char b)
return false;\
}
void S9xWinRemoveRegistryKeys() {
TCHAR szRegKey[4096] = {};
_stprintf_s(szRegKey, 4095, TEXT("Software\\Classes\\%s"), SNES9XWPROGID);
SHDeleteKey(HKEY_CURRENT_USER, szRegKey);
_stprintf_s(szRegKey, 4095, TEXT("Software\\RegisteredApplications\\%s"), SNES9XWPROGID);
SHDeleteKey(HKEY_CURRENT_USER, szRegKey);
_stprintf_s(szRegKey, 4095, TEXT("Software\\Snes9x"), SNES9XWPROGID);
SHDeleteKey(HKEY_CURRENT_USER, szRegKey);
const TCHAR* szExeNames[] = { TEXT("snes9x.exe"), TEXT("snes9x-debug.exe"), TEXT("snes9x-x64.exe"), TEXT("snes9x-debug-x64.exe") };
for (auto& szExeName : szExeNames)
{
_stprintf_s(szRegKey, 4095, TEXT("Software\\Classes\\Applications\\%s"), szExeName);
SHDeleteKey(HKEY_CURRENT_USER, szRegKey);
ExtList* curr = valid_ext;
while (curr->next != NULL) {
auto ext = curr->extension;
_stprintf(szRegKey, TEXT("Software\\Classes\\.%s\\OpenWithList\\%s"), ext, szExeName);
SHDeleteKey(HKEY_CURRENT_USER, szRegKey);
curr = curr->next;
}
}
}
bool RegisterProgid() {
LONG regResult;
TCHAR szRegKey[PATH_MAX];
@ -7190,10 +7217,21 @@ void LoadExts(void)
delete curr;
if (GUI.AddToRegistry)
{
auto result = MessageBox(
GUI.hWnd,
TEXT("Snes9x would like to add entries to the Windows registry to set file associations and configure the jump list. Is this okay?"),
TEXT("Snes9x"),
MB_YESNO | MB_ICONQUESTION);
if (result == IDYES)
{
RegisterProgid();
RegisterExts();
}
GUI.AddToRegistry = false;
}
}
void MakeExtFile(void)

View File

@ -464,5 +464,6 @@ void FreezeUnfreezeDialog(bool8 freeze);
void FreezeUnfreezeDialogPreview(bool8 freeze);
void FreezeUnfreeze(const char *filename, bool8 freeze);
bool UnfreezeScreenshotSlot(int slot, uint16 **image_buffer, int &width, int &height);
void S9xWinRemoveRegistryKeys();
#endif // !defined(SNES9X_H_INCLUDED)