diff options
author | Alex Marsev <alex.marsev@gmail.com> | 2013-10-13 23:20:39 +0400 |
---|---|---|
committer | Alex Marsev <alex.marsev@gmail.com> | 2013-10-13 23:59:34 +0400 |
commit | bc1d1c28c8f60b1b68276c413f04054894a3fa51 (patch) | |
tree | 475ff4ec43ac7b8229e94ed731f043e5c81efb9e /src | |
parent | 7c1645f7033081b14e8935ffd58317cb747e0797 (diff) |
Fixes to reset settings option
- Reset .ini now doesn't write ExePath to the registry
- Reset .ini is now achieved through file write not delete
Fixes #3591
Diffstat (limited to 'src')
-rw-r--r-- | src/mpc-hc/mplayerc.cpp | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/src/mpc-hc/mplayerc.cpp b/src/mpc-hc/mplayerc.cpp index fc2db7fcc..421b491dc 100644 --- a/src/mpc-hc/mplayerc.cpp +++ b/src/mpc-hc/mplayerc.cpp @@ -1248,17 +1248,30 @@ BOOL CMPlayerCApp::InitInstance() // Remove the settings
if (IsIniValid()) {
- CFile::Remove(GetIniPath());
+ FILE* fp;
+ do { // Open mpc-hc.ini, retry if it is already being used by another process
+ fp = _tfsopen(m_pszProfileName, _T("w"), _SH_SECURE);
+ if (fp || (GetLastError() != ERROR_SHARING_VIOLATION)) {
+ break;
+ }
+ Sleep(100);
+ } while (true);
+ if (fp) {
+ // Close without writing anything, it should produce empty file
+ VERIFY(fclose(fp) == 0);
+ } else {
+ ASSERT(FALSE);
+ }
} else {
- HKEY reg = GetAppRegistryKey();
- SHDeleteKey(reg, _T(""));
- RegCloseKey(reg);
- }
-
- // Restore the ExePath value to prevent settings migration
- CRegKey key;
- if (ERROR_SUCCESS == key.Create(HKEY_CURRENT_USER, _T("Software\\MPC-HC\\MPC-HC"))) {
- key.SetStringValue(_T("ExePath"), GetProgramPath(true));
+ CRegKey key;
+ // Clear settings
+ key.Attach(GetAppRegistryKey());
+ VERIFY(key.RecurseDeleteKey(_T("")) == ERROR_SUCCESS);
+ VERIFY(key.Close() == ERROR_SUCCESS);
+ // Set ExePath value to prevent settings migration
+ key.Attach(GetAppRegistryKey());
+ VERIFY(key.SetStringValue(_T("ExePath"), GetProgramPath(true)) == ERROR_SUCCESS);
+ VERIFY(key.Close() == ERROR_SUCCESS);
}
// Remove the current playlist if it exists
|