From: <sag...@us...> - 2015-06-04 11:15:54
|
Revision: 5246 http://sourceforge.net/p/modplug/code/5246 Author: saga-games Date: 2015-06-04 11:15:48 +0000 (Thu, 04 Jun 2015) Log Message: ----------- [Mod] The working directory is now set to "My Documents" on startup rather than the executable directory. This is done since the tree view and, possibly, open/save file dialogs (if never used before) may use the working directory as a default directory. [Ref] Combine mpt::PathString::HasTrailingSlash + slash addition into mpt::PathString::EnsureTrailingSlash Modified Paths: -------------- trunk/OpenMPT/common/mptPathString.h trunk/OpenMPT/mptrack/FolderScanner.cpp trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/PathConfigDlg.cpp trunk/OpenMPT/mptrack/TrackerSettings.cpp trunk/OpenMPT/mptrack/View_tre.cpp Modified: trunk/OpenMPT/common/mptPathString.h =================================================================== --- trunk/OpenMPT/common/mptPathString.h 2015-06-03 23:13:38 UTC (rev 5245) +++ trunk/OpenMPT/common/mptPathString.h 2015-06-04 11:15:48 UTC (rev 5246) @@ -129,6 +129,18 @@ return (c == '/'); #endif } + mpt::PathString &EnsureTrailingSlash() + { + if(!path.empty() && !HasTrailingSlash()) + { +#if MPT_OS_WINDOWS + path += L'\\'; +#else + path += '/'; +#endif + } + return *this; + } // Relative / absolute paths conversion mpt::PathString AbsolutePathToRelative(const mpt::PathString &relativeTo) const; Modified: trunk/OpenMPT/mptrack/FolderScanner.cpp =================================================================== --- trunk/OpenMPT/mptrack/FolderScanner.cpp 2015-06-03 23:13:38 UTC (rev 5245) +++ trunk/OpenMPT/mptrack/FolderScanner.cpp 2015-06-04 11:15:48 UTC (rev 5246) @@ -43,7 +43,7 @@ currentPath = paths.back(); paths.pop_back(); - if(!currentPath.HasTrailingSlash()) currentPath += MPT_PATHSTRING("\\"); + currentPath.EnsureTrailingSlash(); hFind = FindFirstFileW((currentPath + MPT_PATHSTRING("*.*")).AsNative().c_str(), &wfd); } Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2015-06-03 23:13:38 UTC (rev 5245) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2015-06-04 11:15:48 UTC (rev 5246) @@ -71,7 +71,7 @@ { CDocument *pDoc = nullptr; mpt::PathString path = filename; - if(!path.HasTrailingSlash()) path += MPT_PATHSTRING("\\"); + path.EnsureTrailingSlash(); HANDLE hFind; WIN32_FIND_DATAW wfd; MemsetZero(wfd); @@ -456,10 +456,7 @@ if(!UltraSndPath.empty()) { tmp = UltraSndPath; - if(!tmp.HasTrailingSlash()) - { - tmp += MPT_PATHSTRING("\\"); - } + tmp.EnsureTrailingSlash(); } tmp += filename; tmp += MPT_PATHSTRING(".pat"); @@ -790,25 +787,24 @@ void CTrackApp::SetupPaths(bool overridePortable) //----------------------------------------------- { + // Set current directory to My Documents. If no sample / mod / etc. paths are set up by the user, this will be the default location for browsing files. + WCHAR dir[MAX_PATH] = { 0 }; + if(SHGetFolderPathW(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, dir) == S_OK) + { + SetCurrentDirectoryW(dir); + } - // change to exe directory - - SetCurrentDirectoryW(mpt::GetAppPath().AsNative().c_str()); - - // Determine paths, portable mode, first run. Do not yet update any state. mpt::PathString configPathApp = mpt::GetAppPath(); // config path in portable mode mpt::PathString configPathGlobal; // config path in default non-portable mode { // Try to find a nice directory where we should store our settings (default: %APPDATA%) - WCHAR tempConfigDirectory[MAX_PATH]; - MemsetZero(tempConfigDirectory); - if((SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, tempConfigDirectory) == S_OK) - || (SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, tempConfigDirectory) == S_OK)) + if((SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, dir) == S_OK) + || (SHGetFolderPathW(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, dir) == S_OK)) { - // Store our app settings in %APPDATA% or "My Files" - configPathGlobal = mpt::PathString::FromNative(tempConfigDirectory) + MPT_PATHSTRING("\\OpenMPT\\"); + // Store our app settings in %APPDATA% or "My Documents" + configPathGlobal = mpt::PathString::FromNative(dir) + MPT_PATHSTRING("\\OpenMPT\\"); } } Modified: trunk/OpenMPT/mptrack/PathConfigDlg.cpp =================================================================== --- trunk/OpenMPT/mptrack/PathConfigDlg.cpp 2015-06-03 23:13:38 UTC (rev 5245) +++ trunk/OpenMPT/mptrack/PathConfigDlg.cpp 2015-06-04 11:15:48 UTC (rev 5246) @@ -106,11 +106,7 @@ m_AutoSaver.SetSaveInterval(GetDlgItemInt(IDC_AUTOSAVE_INTERVAL)); m_AutoSaver.SetUseOriginalPath(IsDlgButtonChecked(IDC_AUTOSAVE_USEORIGDIR) == BST_CHECKED); ::GetDlgItemTextW(m_hWnd, IDC_AUTOSAVE_PATH, tempPath, CountOf(tempPath)); - mpt::PathString path = mpt::PathString::FromNative(tempPath); - if(!path.empty() && !path.HasTrailingSlash()) - { - path += MPT_PATHSTRING("\\"); - } + mpt::PathString path = mpt::PathString::FromNative(tempPath).EnsureTrailingSlash(); m_AutoSaver.SetPath(path); CPropertyPage::OnOK(); Modified: trunk/OpenMPT/mptrack/TrackerSettings.cpp =================================================================== --- trunk/OpenMPT/mptrack/TrackerSettings.cpp 2015-06-03 23:13:38 UTC (rev 5245) +++ trunk/OpenMPT/mptrack/TrackerSettings.cpp 2015-06-04 11:15:48 UTC (rev 5246) @@ -1107,10 +1107,7 @@ //-------------------------------------------------------------------------------------------------------------------------- { mpt::PathString newPath = (stripFilename ? filenameFrom.GetPath() : filenameFrom); - if(!newPath.empty() && !newPath.HasTrailingSlash()) - { - newPath += MPT_PATHSTRING("\\"); - } + newPath.EnsureTrailingSlash(); mpt::PathString oldPath = dest; dest = newPath; return newPath != oldPath; Modified: trunk/OpenMPT/mptrack/View_tre.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_tre.cpp 2015-06-03 23:13:38 UTC (rev 5245) +++ trunk/OpenMPT/mptrack/View_tre.cpp 2015-06-04 11:15:48 UTC (rev 5246) @@ -201,27 +201,21 @@ if(!IsSampleBrowser()) { - const mpt::PathString dirs[] = { + WCHAR curDir[MAX_PATH]; + GetCurrentDirectoryW(CountOf(curDir), curDir); + const mpt::PathString dirs[] = + { TrackerSettings::Instance().PathSamples.GetDefaultDir(), TrackerSettings::Instance().PathInstruments.GetDefaultDir(), - TrackerSettings::Instance().PathSongs.GetDefaultDir() + TrackerSettings::Instance().PathSongs.GetDefaultDir(), + mpt::PathString::FromNative(curDir) }; for(int i = 0; i < CountOf(dirs); i++) { m_InstrLibPath = dirs[i]; - if(!m_InstrLibPath.empty()) - { - break; - } else if(i == CountOf(dirs) - 1) - { - // Resort to current directory. - WCHAR curDir[MAX_PATH]; - GetCurrentDirectoryW(CountOf(curDir), curDir); - m_InstrLibPath = mpt::PathString::FromNative(curDir); - } + if(!m_InstrLibPath.empty()) break; } - if(!m_InstrLibPath.HasTrailingSlash()) - m_InstrLibPath += MPT_PATHSTRING("\\"); + m_InstrLibPath.EnsureTrailingSlash(); m_pDataTree->InsLibSetFullPath(m_InstrLibPath, mpt::PathString()); } @@ -355,7 +349,7 @@ //---------------------------------------------------------------- { mpt::PathString fullPath = m_InstrLibPath; - if(!fullPath.HasTrailingSlash()) fullPath += MPT_PATHSTRING("\\"); + fullPath.EnsureTrailingSlash(); return fullPath + mpt::PathString::FromCStringW(GetItemTextW(hItem)); } @@ -1358,8 +1352,7 @@ if(dlg.Show()) { mpt::PathString dir = dlg.GetDirectory(); - if(!dir.HasTrailingSlash()) - dir += MPT_PATHSTRING("\\"); + dir.EnsureTrailingSlash(); CMainFrame::GetMainFrame()->GetUpperTreeview()->InstrumentLibraryChDir(dir, false); } } @@ -2025,7 +2018,10 @@ { // Drives are formatted like "E:\", folders are just folder name without slash. if(!dir.HasTrailingSlash()) - dir = m_InstrLibPath + dir + MPT_PATHSTRING("\\"); + { + dir = m_InstrLibPath + dir; + dir.EnsureTrailingSlash(); + } m_InstrLibHighlightPath = MPT_PATHSTRING(".."); // Highlight first entry } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |