From: <man...@us...> - 2014-06-01 10:12:35
|
Revision: 4078 http://sourceforge.net/p/modplug/code/4078 Author: manxorist Date: 2014-06-01 10:12:23 +0000 (Sun, 01 Jun 2014) Log Message: ----------- [Ref] Implement a generic mpt::GetAppPath in misc_util.cpp (exactly the same implementation as in CTrackApp::SetupPaths before). Thereby avoid back-dependency from common/ on mptrack/ . [Ref] Make m_szExePath non-global. Modified Paths: -------------- trunk/OpenMPT/common/misc_util.cpp trunk/OpenMPT/common/misc_util.h trunk/OpenMPT/mptrack/MPTrackUtil.cpp trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/Mptrack.h Modified: trunk/OpenMPT/common/misc_util.cpp =================================================================== --- trunk/OpenMPT/common/misc_util.cpp 2014-06-01 08:48:22 UTC (rev 4077) +++ trunk/OpenMPT/common/misc_util.cpp 2014-06-01 10:12:23 UTC (rev 4078) @@ -751,23 +751,46 @@ #endif -#if !defined(MODPLUG_TRACKER) -// For OpenMPT, this is defined in mptrack/MPTrackUtil.cpp . mpt::PathString GetAppPath() { +#if defined(MODPLUG_TRACKER) + WCHAR exeFileName[MAX_PATH+1]; + MemsetZero(exeFileName); + if(!GetModuleFileNameW(NULL, exeFileName, MAX_PATH)) + { + return mpt::PathString(); + } + return mpt::GetAbsolutePath(mpt::PathString::FromNative(exeFileName).GetDrive() + mpt::PathString::FromNative(exeFileName).GetDir()); +#else return mpt::PathString(); // dummy +#endif } -#endif + mpt::PathString GetSystemPath() { WCHAR path[MAX_PATH+1]; MemsetZero(path); - GetSystemDirectoryW(path, MAX_PATH); + if(!GetSystemDirectoryW(path, MAX_PATH)) + { + return mpt::PathString(); + } return mpt::PathString::FromNative(path) + MPT_PATHSTRING("\\"); } +mpt::PathString GetAbsolutePath(const mpt::PathString &path) +{ + WCHAR fullPathName[MAX_PATH+1]; + MemsetZero(fullPathName); + if(!GetFullPathNameW(path.AsNative().c_str(), MAX_PATH, fullPathName, NULL)) + { + return path; + } + return mpt::PathString::FromNative(fullPathName); +} + + class LibraryHandle { Modified: trunk/OpenMPT/common/misc_util.h =================================================================== --- trunk/OpenMPT/common/misc_util.h 2014-06-01 08:48:22 UTC (rev 4077) +++ trunk/OpenMPT/common/misc_util.h 2014-06-01 10:12:23 UTC (rev 4078) @@ -742,6 +742,9 @@ // Returns the system directory path, e.g. "C:\Windows\System32\" mpt::PathString GetSystemPath(); +// Returns the absolute path for a potentially relative path and removes ".." or "." components. (same as GetFullPathNameW) +mpt::PathString GetAbsolutePath(const mpt::PathString &path); + #endif // MPT_OS_WINDOWS Modified: trunk/OpenMPT/mptrack/MPTrackUtil.cpp =================================================================== --- trunk/OpenMPT/mptrack/MPTrackUtil.cpp 2014-06-01 08:48:22 UTC (rev 4077) +++ trunk/OpenMPT/mptrack/MPTrackUtil.cpp 2014-06-01 10:12:23 UTC (rev 4078) @@ -19,22 +19,6 @@ OPENMPT_NAMESPACE_BEGIN - -namespace mpt -{ - - -// declared in misc_util.h -mpt::PathString GetAppPath() -//-------------------------- -{ - return theApp.GetAppDirPath(); -} - - -} // namespace mpt - - /* * Loads resource. * [in] lpName and lpType: parameters passed to FindResource(). Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2014-06-01 08:48:22 UTC (rev 4077) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2014-06-01 10:12:23 UTC (rev 4078) @@ -2677,11 +2677,11 @@ for(size_t i = 0; i < 2; i++) // 0: app items, 1: user items { // To avoid duplicates, check whether app path and config path are the same. - if (i == 1 && mpt::PathString::CompareNoCase(CTrackApp::GetAppDirPath(), theApp.GetConfigPath()) == 0) + if (i == 1 && mpt::PathString::CompareNoCase(theApp.GetAppDirPath(), theApp.GetConfigPath()) == 0) break; mpt::PathString basePath; - basePath = (i == 0) ? CTrackApp::GetAppDirPath() : theApp.GetConfigPath(); + basePath = (i == 0) ? theApp.GetAppDirPath() : theApp.GetConfigPath(); basePath += pszFolderName; if (Util::sdOs::IsPathFileAvailable(basePath, Util::sdOs::FileModeExists) == false) continue; Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2014-06-01 08:48:22 UTC (rev 4077) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2014-06-01 10:12:23 UTC (rev 4078) @@ -294,8 +294,6 @@ } -mpt::PathString CTrackApp::m_szExePath; - ///////////////////////////////////////////////////////////////////////////// // MPTRACK Command Line options @@ -700,7 +698,7 @@ // copy a config file from the exe directory to the new config dirs mpt::PathString sOldPath; mpt::PathString sNewPath; - sOldPath = m_szExePath; + sOldPath = GetAppDirPath(); sOldPath += sSubDir; sOldPath += sFileName; @@ -727,19 +725,9 @@ void CTrackApp::SetupPaths(bool overridePortable) //----------------------------------------------- { - WCHAR tempExePath[MAX_PATH]; - if(GetModuleFileNameW(NULL, tempExePath, CountOf(tempExePath))) - { - mpt::String::SetNullTerminator(tempExePath); - m_szExePath = mpt::PathString::FromNative(tempExePath).GetDrive(); - m_szExePath += mpt::PathString::FromNative(tempExePath).GetDir(); + m_szExePath = mpt::GetAppPath(); + SetCurrentDirectoryW(m_szExePath.AsNative().c_str()); - WCHAR wcsDir[MAX_PATH]; - GetFullPathNameW(m_szExePath.AsNative().c_str(), CountOf(wcsDir), wcsDir, NULL); - m_szExePath = mpt::PathString::FromNative(wcsDir); - SetCurrentDirectoryW(wcsDir); - } - m_szConfigDirectory = mpt::PathString(); // Try to find a nice directory where we should store our settings (default: %APPDATA%) bool bIsAppDir = overridePortable; @@ -755,7 +743,7 @@ m_szConfigDirectory = mpt::PathString::FromNative(tempConfigDirectory); // Check if the user prefers to use the app's directory - m_szConfigFileName = m_szExePath; // config file + m_szConfigFileName = GetAppDirPath(); // config file m_szConfigFileName += MPT_PATHSTRING("mptrack.ini"); if(GetPrivateProfileIntW(L"Paths", L"UseAppDataDirectory", 1, m_szConfigFileName.AsNative().c_str()) == 0) { @@ -780,7 +768,7 @@ #endif // WIN32 Legacy Stuff } else { - m_szConfigDirectory = m_szExePath; + m_szConfigDirectory = GetAppDirPath(); } // Create tunings dir @@ -796,7 +784,7 @@ { // Import old tunings mpt::PathString sOldTunings; - sOldTunings = m_szExePath; + sOldTunings = GetAppDirPath(); sOldTunings += MPT_PATHSTRING("tunings\\"); if(PathIsDirectoryW(sOldTunings.AsNative().c_str()) != 0) Modified: trunk/OpenMPT/mptrack/Mptrack.h =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.h 2014-06-01 08:48:22 UTC (rev 4077) +++ trunk/OpenMPT/mptrack/Mptrack.h 2014-06-01 10:12:23 UTC (rev 4078) @@ -205,7 +205,7 @@ DWORD m_dwTimeStarted, m_dwLastPluginIdleCall; // Default macro configuration MIDIMacroConfig m_MidiCfg; - static mpt::PathString m_szExePath; + mpt::PathString m_szExePath; mpt::PathString m_szConfigDirectory; mpt::PathString m_szConfigFileName; mpt::PathString m_szPluginCacheFileName; @@ -222,7 +222,7 @@ static VOID SetAsProject(BOOL n) { m_nProject = n; } // -! NEW_FEATURE#0023 - static mpt::PathString GetAppDirPath() {return m_szExePath;} // Returns '\'-ended executable directory path. + mpt::PathString GetAppDirPath() {return m_szExePath;} // Returns '\'-ended executable directory path. static MODTYPE GetDefaultDocType() { return m_nDefaultDocType; } static void SetDefaultDocType(MODTYPE n) { m_nDefaultDocType = n; } static MIDILIBSTRUCT &GetMidiLibrary() { return midiLibrary; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |