From: <sv...@op...> - 2024-11-29 23:10:43
|
Author: sagamusix Date: Sat Nov 30 00:10:35 2024 New Revision: 22351 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=22351 Log: [Imp] Autosave directory is now created when it's missing. [Mod] Autosave no longer defaults to saving in the song's original folder. Besides annoying some users, this also had the problem that trying to edit a module on readonly media could cause Autosave to become disabled permanently (because saving the autosave file would fail). By default, autosave now saves files in %localappdata%\OpenMPT\Autosave, and for portable installations, in the Autosave sub folder within the portable installation (https://bugs.openmpt.org/view.php?id=1837). Modified: trunk/OpenMPT/mptrack/AutoSaver.cpp trunk/OpenMPT/mptrack/PathConfigDlg.cpp trunk/OpenMPT/mptrack/PathConfigDlg.h trunk/OpenMPT/mptrack/TrackerSettings.cpp trunk/OpenMPT/mptrack/TrackerSettings.h Modified: trunk/OpenMPT/mptrack/AutoSaver.cpp ============================================================================== --- trunk/OpenMPT/mptrack/AutoSaver.cpp Fri Nov 29 23:37:35 2024 (r22350) +++ trunk/OpenMPT/mptrack/AutoSaver.cpp Sat Nov 30 00:10:35 2024 (r22351) @@ -22,6 +22,7 @@ #include "mpt/fs/fs.hpp" #include <algorithm> +#include <filesystem> OPENMPT_NAMESPACE_BEGIN @@ -123,17 +124,19 @@ path = path.GetDirectoryWithDrive(); } else { - // if it doesn't, put it in settings dir - path = theApp.GetConfigPath() + P_("Autosave\\"); - if(createPath && !CreateDirectory(path.AsNative().c_str(), nullptr) && GetLastError() == ERROR_PATH_NOT_FOUND) - path = theApp.GetConfigPath(); - else if(!createPath && !mpt::native_fs{}.is_directory(path)) - path = theApp.GetConfigPath(); + // If it doesn't, fall back to default + path = TrackerSettings::GetDefaultAutosavePath(); } } else { path = GetPath(); } + std::error_code ec; + if(createPath) + std::filesystem::create_directories(mpt::support_long_path(path.AsNative()), ec); + if(!mpt::native_fs{}.is_directory(path)) + path = theApp.GetConfigPath(); + return path.WithTrailingSlash(); } @@ -160,7 +163,7 @@ // We are actually not going to show the log for autosaved files. ScopedLogCapturer logcapturer(modDoc, _T(""), nullptr, false); - return modDoc.SaveFile(BuildFileName(modDoc), GetUseOriginalPath()); + return modDoc.SaveFile(fileName, GetUseOriginalPath()); } Modified: trunk/OpenMPT/mptrack/PathConfigDlg.cpp ============================================================================== --- trunk/OpenMPT/mptrack/PathConfigDlg.cpp Fri Nov 29 23:37:35 2024 (r22350) +++ trunk/OpenMPT/mptrack/PathConfigDlg.cpp Sat Nov 30 00:10:35 2024 (r22351) @@ -222,20 +222,6 @@ } -BOOL PathConfigDlg::OnKillActive() -{ - mpt::PathString path = GetPath(IDC_AUTOSAVE_PATH); - - if (!mpt::native_fs{}.is_directory(path) && IsDlgButtonChecked(IDC_AUTOSAVE_ENABLE) && !IsDlgButtonChecked(IDC_AUTOSAVE_USEORIGDIR)) - { - Reporting::Error("Backup path does not exist."); - GetDlgItem(IDC_AUTOSAVE_PATH)->SetFocus(); - return 0; - } - - return CPropertyPage::OnKillActive(); -} - void PathConfigDlg::OnBrowseAutosavePath() { BrowseFolder(IDC_AUTOSAVE_PATH); } void PathConfigDlg::OnBrowseSongs() { BrowseFolder(IDC_OPTIONS_DIR_MODS); } void PathConfigDlg::OnBrowseSamples() { BrowseFolder(IDC_OPTIONS_DIR_SAMPS); } Modified: trunk/OpenMPT/mptrack/PathConfigDlg.h ============================================================================== --- trunk/OpenMPT/mptrack/PathConfigDlg.h Fri Nov 29 23:37:35 2024 (r22350) +++ trunk/OpenMPT/mptrack/PathConfigDlg.h Sat Nov 30 00:10:35 2024 (r22351) @@ -27,7 +27,6 @@ void OnOK() override; BOOL OnInitDialog() override; - BOOL OnKillActive() override; afx_msg void OnAutosaveEnable(); afx_msg void OnAutosaveUseOrigDir(); Modified: trunk/OpenMPT/mptrack/TrackerSettings.cpp ============================================================================== --- trunk/OpenMPT/mptrack/TrackerSettings.cpp Fri Nov 29 23:37:35 2024 (r22350) +++ trunk/OpenMPT/mptrack/TrackerSettings.cpp Sat Nov 30 00:10:35 2024 (r22351) @@ -319,9 +319,9 @@ , AutosaveIntervalMinutes(conf, UL_("AutoSave"), UL_("IntervalMinutes"), 10) , AutosaveHistoryDepth(conf, UL_("AutoSave"), UL_("BackupHistory"), 3) , AutosaveRetentionTimeDays(conf, UL_("AutoSave"), UL_("RetentionTimeDays"), 30) - , AutosaveUseOriginalPath(conf, UL_("AutoSave"), UL_("UseOriginalPath"), true) + , AutosaveUseOriginalPath(conf, UL_("AutoSave"), UL_("UseOriginalPath"), false) , AutosaveDeletePermanently(conf, UL_("AutoSave"), UL_("DeletePermanently"), false) - , AutosavePath(conf, UL_("AutoSave"), UL_("Path"), mpt::common_directories::get_temp_directory()) + , AutosavePath(conf, UL_("AutoSave"), UL_("Path"), GetDefaultAutosavePath()) // Paths , PathSongs(conf, UL_("Paths"), UL_("Songs_Directory"), mpt::PathString()) , PathSamples(conf, UL_("Paths"), UL_("Samples_Directory"), mpt::PathString()) @@ -1417,6 +1417,31 @@ } +mpt::PathString TrackerSettings::GetDefaultAutosavePath() +{ + mpt::PathString path; + if(theApp.IsPortableMode()) + { + return theApp.GetInstallPath().WithTrailingSlash(); + } else + { + // Try to find non-roaming (local) app data first, fall back to other directory + TCHAR dir[MAX_PATH] = {0}; + if((SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, dir) == S_OK) + || (SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, dir) == S_OK) + || (SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, dir) == S_OK)) + { + path = mpt::PathString::FromNative(dir); + } else + { + path = mpt::common_directories::get_temp_directory(); + } + path = path.WithTrailingSlash() + P_("OpenMPT\\"); + } + return path + P_("Autosave"); +} + + //////////////////////////////////////////////////////////////////////////////// // Chords Modified: trunk/OpenMPT/mptrack/TrackerSettings.h ============================================================================== --- trunk/OpenMPT/mptrack/TrackerSettings.h Fri Nov 29 23:37:35 2024 (r22350) +++ trunk/OpenMPT/mptrack/TrackerSettings.h Sat Nov 30 00:10:35 2024 (r22351) @@ -995,6 +995,8 @@ void SetMIDIDevice(UINT id); UINT GetCurrentMIDIDevice(); + static mpt::PathString GetDefaultAutosavePath(); + protected: static std::vector<uint32> GetDefaultSampleRates(); |