From: <sag...@us...> - 2009-09-20 13:44:31
|
Revision: 372 http://modplug.svn.sourceforge.net/modplug/?rev=372&view=rev Author: saga-games Date: 2009-09-20 13:44:24 +0000 (Sun, 20 Sep 2009) Log Message: ----------- [Mod] Store configuration and tuning files in %APPDATA% if possible. Can be disabled by adding UseAppDataDirectory=0 to [Paths] in mptrack.ini. Modified Paths: -------------- trunk/OpenMPT/mptrack/AutoSaver.cpp trunk/OpenMPT/mptrack/InputHandler.cpp trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Mainfrm.h trunk/OpenMPT/mptrack/Moptions.cpp trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/Mptrack.h trunk/OpenMPT/soundlib/Sndfile.cpp Modified: trunk/OpenMPT/mptrack/AutoSaver.cpp =================================================================== --- trunk/OpenMPT/mptrack/AutoSaver.cpp 2009-09-20 13:09:10 UTC (rev 371) +++ trunk/OpenMPT/mptrack/AutoSaver.cpp 2009-09-20 13:44:24 UTC (rev 372) @@ -191,8 +191,8 @@ if (m_bUseOriginalPath) { if (pModDoc->m_bHasValidPath) { // Check that the file has a user-chosen path name = pModDoc->GetPathName(); - } else { // if it doesnt, put it in executable dir - name = CMainFrame::m_csExecutableDirectoryPath + pModDoc->GetTitle(); + } else { // if it doesnt, put it in settings dir + name = theApp.GetConfigPath() + pModDoc->GetTitle(); } } else { @@ -271,7 +271,7 @@ CString fullPath = pModDoc->GetPathName(); path = fullPath.Left(fullPath.GetLength()-pModDoc->GetTitle().GetLength()); //remove file name if necessary } else { - path = CMainFrame::m_csExecutableDirectoryPath; + path = theApp.GetConfigPath(); } } else { path = m_csPath; Modified: trunk/OpenMPT/mptrack/InputHandler.cpp =================================================================== --- trunk/OpenMPT/mptrack/InputHandler.cpp 2009-09-20 13:09:10 UTC (rev 371) +++ trunk/OpenMPT/mptrack/InputHandler.cpp 2009-09-20 13:44:24 UTC (rev 372) @@ -23,7 +23,7 @@ activeCommandSet = new CCommandSet(); CCommandSet::s_bShowErrorOnUnknownKeybinding = (CMainFrame::GetMainFrame()->GetPrivateProfileLong("Misc", "ShowErrorOnUnknownKeybinding", 1, theApp.GetConfigFileName()) != 0); - CString sDefaultPath = CMainFrame::m_csExecutableDirectoryPath + TEXT("Keybindings.mkb"); + CString sDefaultPath = CString(theApp.GetConfigPath()) + TEXT("Keybindings.mkb"); if (sDefaultPath.GetLength() > MAX_PATH - 1) sDefaultPath = ""; Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2009-09-20 13:09:10 UTC (rev 371) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2009-09-20 13:44:24 UTC (rev 372) @@ -267,8 +267,6 @@ CAutoSaver *CMainFrame::m_pAutoSaver = NULL; //rewbs.autosave CPerformanceCounter *CMainFrame::m_pPerfCounter = NULL; -CString CMainFrame::m_csExecutableDirectoryPath = ""; - static UINT indicators[] = { ID_SEPARATOR, // status line indicator @@ -285,17 +283,6 @@ CMainFrame::CMainFrame() //---------------------- { - { - char path[_MAX_PATH]; - char exedrive[_MAX_DRIVE]; - char exedir[_MAX_DIR]; - GetModuleFileName(NULL, path, MAX_PATH); - _splitpath(path, exedrive, exedir, NULL, NULL); - memset(path, 0, sizeof(path)); - _makepath(path, exedrive, exedir, NULL, NULL); - m_csExecutableDirectoryPath = path; //path should end with \ - } - m_bModTreeHasFocus = false; //rewbs.customKeys m_pNoteMapHasFocus = NULL; //rewbs.customKeys m_bOptionsLocked = false; //rewbs.customKeys Modified: trunk/OpenMPT/mptrack/Mainfrm.h =================================================================== --- trunk/OpenMPT/mptrack/Mainfrm.h 2009-09-20 13:09:10 UTC (rev 371) +++ trunk/OpenMPT/mptrack/Mainfrm.h 2009-09-20 13:44:24 UTC (rev 372) @@ -383,7 +383,6 @@ CString m_csRegExt; CString m_csRegSettings; CString m_csRegWindow; - static CString m_csExecutableDirectoryPath; //To contain path of executable directory // Globals static UINT m_nLastOptionsPage, m_nFilterIndex; static BOOL gbMdiMaximize; Modified: trunk/OpenMPT/mptrack/Moptions.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moptions.cpp 2009-09-20 13:09:10 UTC (rev 371) +++ trunk/OpenMPT/mptrack/Moptions.cpp 2009-09-20 13:44:24 UTC (rev 372) @@ -562,7 +562,7 @@ "OpenMPT Color Schemes|*.mptcolor|" "All Files (*.*)|*.*||", this); - dlg.m_ofn.lpstrInitialDir = CMainFrame::m_csExecutableDirectoryPath; + dlg.m_ofn.lpstrInitialDir = theApp.GetConfigPath(); if (dlg.DoModal() != IDOK) return; TCHAR sFilename[MAX_PATH]; @@ -584,7 +584,7 @@ OFN_HIDEREADONLY| OFN_ENABLESIZING | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_NOREADONLYRETURN, "OpenMPT Color Schemes|*.mptcolor|", this); - dlg.m_ofn.lpstrInitialDir = CMainFrame::m_csExecutableDirectoryPath; + dlg.m_ofn.lpstrInitialDir = theApp.GetConfigPath(); if (dlg.DoModal() != IDOK) return; TCHAR sFilename[MAX_PATH]; Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2009-09-20 13:09:10 UTC (rev 371) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2009-09-20 13:44:24 UTC (rev 372) @@ -407,11 +407,11 @@ wsprintf(s, "Midi%d", iMidi); else wsprintf(s, "Perc%d", iMidi & 0x7F); - if ((glpMidiLibrary->MidiMap[iMidi][1] == ':') && (lpszConfigFile[1] == ':') + /*if ((glpMidiLibrary->MidiMap[iMidi][1] == ':') && (lpszConfigFile[1] == ':') && ((glpMidiLibrary->MidiMap[iMidi][0]|0x20) == (lpszConfigFile[0]|0x20))) { strcpy(szFileName, glpMidiLibrary->MidiMap[iMidi]+2); - } else + } else*/ { strcpy(szFileName, glpMidiLibrary->MidiMap[iMidi]); } @@ -669,6 +669,129 @@ exit(-1); } +void CTrackApp::MoveConfigFile(TCHAR sFileName[_MAX_PATH], TCHAR sSubDir[_MAX_PATH], TCHAR sNewFileName[_MAX_PATH]) +//----------------------------------------------------------------------------------------------------------------- +{ + // copy a config file from the exe directory to the new config dirs + TCHAR sOldPath[_MAX_PATH], sNewPath[_MAX_PATH]; + strcpy(sOldPath, m_szExePath); + if(sSubDir[0]) + strcat(sOldPath, sSubDir); + strcat(sOldPath, sFileName); + + strcpy(sNewPath, m_szConfigDirectory); + if(sSubDir[0]) + strcat(sNewPath, sSubDir); + if(sNewFileName[0]) + strcat(sNewPath, sNewFileName); + else + strcat(sNewPath, sFileName); + + if(PathFileExists(sNewPath) == 0 && PathFileExists(sOldPath) != 0) + { + MoveFile(sOldPath, sNewPath); + } +} + + +void CTrackApp::SetupPaths() +//-------------------------- +{ + if(GetModuleFileName(NULL, m_szExePath, _MAX_PATH)) + { + TCHAR szDrive[_MAX_DRIVE] = "", szDir[_MAX_PATH] = ""; + _splitpath(m_szExePath, szDrive, szDir, NULL, NULL); + strcpy(m_szExePath, szDrive); + strcat(m_szExePath, szDir); + } + + m_szConfigDirectory[0] = 0; + // Try to find a nice directory where we should store our settings (default: %APPDATA%) + bool bIsAppDir = false; + if(!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, m_szConfigDirectory))) + { + if(!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, m_szConfigDirectory))) + { + strcpy(m_szConfigDirectory, m_szExePath); + bIsAppDir = true; + } + } + + // Check if the user prefers to use the app's directory + strcpy(m_szConfigFileName, m_szExePath); // config file + strcat(m_szConfigFileName, "mptrack.ini"); + if(GetPrivateProfileInt("Paths", "UseAppDataDirectory", 1, m_szConfigFileName) == 0) + { + strcpy(m_szConfigDirectory, m_szExePath); + bIsAppDir = true; + } + + if(!bIsAppDir) + { + // Store our app settings in %APPDATA% or "My Files" + strcat(m_szConfigDirectory, "\\OpenMPT\\"); + + // Path doesn't exist yet, so it has to be created + if(PathIsDirectory(m_szConfigDirectory) == 0) + { + CreateDirectory(m_szConfigDirectory, 0); + } + + // Move files if necessary. + MoveConfigFile("mptrack.ini"); + MoveConfigFile("plugin.cache"); + MoveConfigFile("mpt_intl.ini"); + MoveConfigFile("default.mkb", "", "Keybindings.mkb"); + } + + // Create tunings dir + strcpy(m_szTuningsDirectory, m_szConfigDirectory); + strcat(m_szTuningsDirectory, "tunings\\"); + + if(PathIsDirectory(m_szTuningsDirectory) == 0) + { + CreateDirectory(m_szTuningsDirectory, 0); + } + + if(!bIsAppDir) + { + // Import old tunings + TCHAR sOldTunings[_MAX_PATH]; + strcpy(sOldTunings, m_szExePath); + strcat(sOldTunings, "tunings\\"); + + if(PathIsDirectory(sOldTunings) != 0) + { + TCHAR sSearchPattern[_MAX_PATH]; + strcpy(sSearchPattern, sOldTunings); + strcat(sSearchPattern, "*.*"); + WIN32_FIND_DATA FindFileData; + HANDLE hFind; + hFind = FindFirstFile(sSearchPattern, &FindFileData); + if(hFind != INVALID_HANDLE_VALUE) + { + do + { + MoveConfigFile(FindFileData.cFileName, "tunings\\"); + } while(FindNextFile(hFind, &FindFileData) != 0); + } + FindClose(hFind); + RemoveDirectory(sOldTunings); + } + } + + // Set up default file locations + strcpy(m_szConfigFileName, m_szConfigDirectory); // config file + strcat(m_szConfigFileName, "mptrack.ini"); + + strcpy(m_szStringsFileName, m_szConfigDirectory); // I18N file + strcat(m_szStringsFileName, "mpt_intl.ini"); + + strcpy(m_szPluginCacheFileName, m_szConfigDirectory); // plugin cache + strcat(m_szPluginCacheFileName, "plugin.cache"); + +} + BOOL CTrackApp::InitInstance() //---------------------------- { @@ -711,35 +834,9 @@ // Disabled by rewbs for smoothVST. Might cause minor perf issues due to increased cache misses? #endif - m_szConfigFileName[0] = 0; - m_szStringsFileName[0] = 0; + // Set up paths to store configuration in + SetupPaths(); - if (GetModuleFileName(NULL, m_szConfigFileName, sizeof(m_szConfigFileName))) - { - CHAR szDrive[_MAX_DRIVE]="", szDir[_MAX_PATH]=""; - _splitpath(m_szConfigFileName, szDrive, szDir, NULL, NULL); - m_szConfigFileName[0] = 0; - lstrcpyn(m_szConfigFileName, szDrive, sizeof(m_szConfigFileName)); - strncat(m_szConfigFileName, szDir, sizeof(m_szConfigFileName)); - m_szConfigFileName[sizeof(m_szConfigFileName)-1] = 0; - strncat(m_szConfigFileName, "mptrack.ini", sizeof(m_szConfigFileName)); - m_szConfigFileName[sizeof(m_szConfigFileName)-1] = 0; - - m_szPluginCacheFileName[0] = 0; - lstrcpyn(m_szPluginCacheFileName, szDrive, sizeof(m_szPluginCacheFileName)); - strncat(m_szPluginCacheFileName, szDir, sizeof(m_szPluginCacheFileName)); - m_szPluginCacheFileName[sizeof(m_szPluginCacheFileName)-1] = 0; - strncat(m_szPluginCacheFileName, "plugin.cache", sizeof(m_szPluginCacheFileName)); - m_szPluginCacheFileName[sizeof(m_szPluginCacheFileName)-1] = 0; - - m_szStringsFileName[0] = 0; - lstrcpyn(m_szStringsFileName, szDrive, sizeof(m_szStringsFileName)); - strncat(m_szStringsFileName, szDir, sizeof(m_szStringsFileName)); - m_szStringsFileName[sizeof(m_szStringsFileName)-1] = 0; - strncat(m_szStringsFileName, "mpt_intl.ini", sizeof(m_szStringsFileName)); - m_szStringsFileName[sizeof(m_szStringsFileName)-1] = 0; - } - //Force use of custom ini file rather than windowsDir\executableName.ini if (m_pszProfileName) { free((void *)m_pszProfileName); Modified: trunk/OpenMPT/mptrack/Mptrack.h =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.h 2009-09-20 13:09:10 UTC (rev 371) +++ trunk/OpenMPT/mptrack/Mptrack.h 2009-09-20 13:44:24 UTC (rev 372) @@ -140,9 +140,12 @@ HANDLE m_hAlternateResourceHandle; // Default macro configuration MODMIDICFG m_MidiCfg; - CHAR m_szConfigFileName[_MAX_PATH]; - CHAR m_szPluginCacheFileName[_MAX_PATH]; - CHAR m_szStringsFileName[_MAX_PATH]; + TCHAR m_szExePath[_MAX_PATH]; + TCHAR m_szConfigDirectory[_MAX_PATH]; + TCHAR m_szTuningsDirectory[_MAX_PATH]; + TCHAR m_szConfigFileName[_MAX_PATH]; + TCHAR m_szPluginCacheFileName[_MAX_PATH]; + TCHAR m_szStringsFileName[_MAX_PATH]; #ifdef UPDATECHECKENABLED // Internet request context @@ -184,6 +187,8 @@ BOOL IsDebug() const { return m_bDebugMode; } LPCSTR GetConfigFileName() const { return m_szConfigFileName; } LPCSTR GetPluginCacheFileName() const { return m_szPluginCacheFileName; } + LPCSTR GetConfigPath() const { return m_szConfigDirectory; } + void SetupPaths(); // Splash Screen protected: @@ -261,6 +266,8 @@ private: static void LoadRegistryDLS(); + + void MoveConfigFile(TCHAR sFileName[_MAX_PATH], TCHAR sSubDir[_MAX_PATH] = "", TCHAR sNewFileName[_MAX_PATH] = ""); }; Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2009-09-20 13:09:10 UTC (rev 371) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2009-09-20 13:44:24 UTC (rev 372) @@ -2896,7 +2896,7 @@ } // Load local tunings. - s_pTuningsSharedLocal->SetSavefilePath(std::string(CMainFrame::m_csExecutableDirectoryPath + "tunings\\local_tunings" + CTuningCollection::s_FileExtension.c_str())); + s_pTuningsSharedLocal->SetSavefilePath(std::string(std::string(theApp.GetConfigPath()) + "tunings\\local_tunings" + CTuningCollection::s_FileExtension.c_str())); s_pTuningsSharedLocal->Deserialize(); // Enabling adding/removing of tunings for standard collection This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |