diff options
author | Underground78 <underground78@users.sourceforge.net> | 2012-04-07 12:17:34 +0400 |
---|---|---|
committer | Underground78 <underground78@users.sourceforge.net> | 2012-04-07 12:17:34 +0400 |
commit | 70f3eeeeb1064092857ac492ac8947d50b743f38 (patch) | |
tree | 4f0ca288e7717154eb8fe66604c6c79b2509c9a8 /src | |
parent | 6b891ccb350b1fa61d07f901fc6282300a27ebad (diff) |
A Unicode encoding will now be used for the ini file. Old ASCII ini files will be automatically converted to Unicode. Favorites with Unicode filenames are now correctly handled when using an ini file.
This commit fixes ticket #734.
git-svn-id: https://mpc-hc.svn.sourceforge.net/svnroot/mpc-hc/trunk@4274 10f7b99b-c216-0410-bff0-8a66a9350fd8
Diffstat (limited to 'src')
-rw-r--r-- | src/apps/mplayerc/mplayerc.cpp | 38 | ||||
-rw-r--r-- | src/apps/mplayerc/mplayerc.h | 1 |
2 files changed, 30 insertions, 9 deletions
diff --git a/src/apps/mplayerc/mplayerc.cpp b/src/apps/mplayerc/mplayerc.cpp index 3e63f8372..f2e249484 100644 --- a/src/apps/mplayerc/mplayerc.cpp +++ b/src/apps/mplayerc/mplayerc.cpp @@ -430,13 +430,9 @@ bool CMPlayerCApp::StoreSettingsToIni() // We can only use UTF16-LE for unicode ini files in windows. UTF8/UTF16-BE do not work.
// So to ensure we have correct encoding for ini files, create a file with right BOM first,
// then add some comments in first line to make sure it's not empty.
-
- // If you want to try unicode ini, uncomment following code block.
- /*
- if (!::PathFileExists(m_pszProfileName)) // don't overwrite existing ini file
- {
+ if (!::PathFileExists(m_pszProfileName)) { // don't overwrite existing ini file
LPTSTR pszComments = _T("; Media Player Classic - Home Cinema");
- WORD wBOM = 0xFEFF;// UTF16-LE BOM(FFFE)
+ WORD wBOM = 0xFEFF; // UTF16-LE BOM (FFFE)
DWORD nBytes;
HANDLE hFile = ::CreateFile(m_pszProfileName, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
@@ -447,15 +443,12 @@ bool CMPlayerCApp::StoreSettingsToIni() ::CloseHandle(hFile);
}
}
- */
return true;
}
bool CMPlayerCApp::StoreSettingsToRegistry()
{
- _tremove(GetIniPath());
-
free((void*)m_pszRegistryKey);
m_pszRegistryKey = NULL;
@@ -479,6 +472,22 @@ bool CMPlayerCApp::IsIniValid() const return !!CFile::GetStatus(GetIniPath(), fs);
}
+bool CMPlayerCApp::IsIniUTF16LE() const
+{
+ bool isUTF16LE = false;
+
+ CFile f(GetIniPath(), CFile::modeRead);
+
+ if (f) {
+ WORD bom;
+ if (f.Read(&bom, sizeof(bom)) == sizeof(bom)) {
+ isUTF16LE = (bom == 0xFEFF);
+ }
+ }
+
+ return isUTF16LE;
+}
+
bool CMPlayerCApp::GetAppSavePath(CString& path)
{
path.Empty();
@@ -511,12 +520,18 @@ bool CMPlayerCApp::ChangeSettingsLocation(bool useIni) AfxGetAppSettings().GetFav(FAV_DVD, DVDsFav);
AfxGetAppSettings().GetFav(FAV_DEVICE, devicesFav);
+ // In case an ini file is present, we remove it so that it will be recreated
+ _tremove(GetIniPath());
+
if (useIni) {
success = StoreSettingsToIni();
} else {
success = StoreSettingsToRegistry();
}
+ // Write settings immediately
+ m_s.UpdateData(true);
+
// Save favorites to the new location
AfxGetAppSettings().SetFav(FAV_FILE, filesFav);
AfxGetAppSettings().SetFav(FAV_DVD, DVDsFav);
@@ -1142,6 +1157,11 @@ BOOL CMPlayerCApp::InitInstance() m_s.UpdateData(false); // read settings
+ // If we use an ASCII ini file, let's recreate it to switch to UTF-16LE
+ if (IsIniValid() && !IsIniUTF16LE()) {
+ ChangeSettingsLocation(true);
+ }
+
AfxGetMyApp()->m_AudioRendererDisplayName_CL = _T("");
if (!__super::InitInstance()) {
diff --git a/src/apps/mplayerc/mplayerc.h b/src/apps/mplayerc/mplayerc.h index 88f55ddec..61c5685e9 100644 --- a/src/apps/mplayerc/mplayerc.h +++ b/src/apps/mplayerc/mplayerc.h @@ -132,6 +132,7 @@ public: bool StoreSettingsToRegistry();
CString GetIniPath() const;
bool IsIniValid() const;
+ bool IsIniUTF16LE() const;
bool ChangeSettingsLocation(bool useIni);
void ExportSettings();
|