From 81515f024f9c2ebdb2fbcc6896d212ba35dd4a57 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Tue, 14 Jul 2009 03:02:17 +0000 Subject: [PATCH] Properly fix "local config" option, previously it only made config.dat local and kept everything else in %APPDATA% still. Now fixed, along with a load of other problematic uses of relative paths. Still a lot more to go. This also makes a bit of sense of the default options for various paths that previously were implicitly relative to ?user or ?data but never explicitly specified in options. Originally committed to SVN as r3130. --- aegisub/src/browse_button.cpp | 4 ++-- aegisub/src/frame_main.cpp | 2 +- aegisub/src/frame_main_events.cpp | 2 +- aegisub/src/help_button.cpp | 2 +- aegisub/src/main.cpp | 10 ++++++++-- aegisub/src/options.cpp | 8 ++++---- aegisub/src/spellchecker_hunspell.cpp | 4 ++-- aegisub/src/standard_paths.cpp | 14 ++++++++++++-- aegisub/src/standard_paths.h | 11 ++++++----- aegisub/src/thesaurus_myspell.cpp | 4 ++-- 10 files changed, 39 insertions(+), 22 deletions(-) diff --git a/aegisub/src/browse_button.cpp b/aegisub/src/browse_button.cpp index cc04c325c..5e35bd5b1 100644 --- a/aegisub/src/browse_button.cpp +++ b/aegisub/src/browse_button.cpp @@ -72,10 +72,10 @@ void BrowseButton::OnPressed(wxCommandEvent &event) { if (type == BROWSE_FOLDER) { // For some reason I can't make this work on Mac... -jfs #ifndef __WXMAC__ - wxString def = DecodeRelativePath(ctrl[0]->GetValue(),StandardPaths::DecodePath(_T("?user/"))); + wxString def = StandardPaths::DecodePathMaybeRelative(ctrl[0]->GetValue(), _T("?user/")); wxDirDialog dlg(0, _("Please choose the folder:"), def); if (dlg.ShowModal() == wxID_OK) { - wxString dir = MakeRelativePath(dlg.GetPath(),StandardPaths::DecodePath(_T("?user/"))); + wxString dir = StandardPaths::EncodePath(dlg.GetPath()); if (dir != _T("")) ctrl[0]->SetValue(dir); } #endif diff --git a/aegisub/src/frame_main.cpp b/aegisub/src/frame_main.cpp index 437580890..fc104474a 100644 --- a/aegisub/src/frame_main.cpp +++ b/aegisub/src/frame_main.cpp @@ -718,7 +718,7 @@ void FrameMain::LoadSubtitles (wxString filename,wxString charset) { wxString path = Options.AsText(_T("Auto backup path")); if (path.IsEmpty()) path = origfile.GetPath(); wxFileName dstpath(path); - if (!dstpath.IsAbsolute()) path = StandardPaths::DecodePath(_T("?user/") + path); + if (!dstpath.IsAbsolute()) path = StandardPaths::DecodePathMaybeRelative(path, _T("?user/")); path += _T("/"); dstpath.Assign(path); if (!dstpath.DirExists()) wxMkdir(path); diff --git a/aegisub/src/frame_main_events.cpp b/aegisub/src/frame_main_events.cpp index 0cb9cba1d..f672df3ce 100644 --- a/aegisub/src/frame_main_events.cpp +++ b/aegisub/src/frame_main_events.cpp @@ -1519,7 +1519,7 @@ void FrameMain::OnAutoSave(wxTimerEvent &event) { wxString path = Options.AsText(_T("Auto save path")); if (path.IsEmpty()) path = origfile.GetPath(); wxFileName dstpath(path); - if (!dstpath.IsAbsolute()) path = StandardPaths::DecodePath(_T("?user/") + path); + if (!dstpath.IsAbsolute()) path = StandardPaths::DecodePathMaybeRelative(path, _T("?user/")); path += _T("/"); dstpath.Assign(path); if (!dstpath.DirExists()) wxMkdir(path); diff --git a/aegisub/src/help_button.cpp b/aegisub/src/help_button.cpp index 12e58fda8..8a01f526e 100644 --- a/aegisub/src/help_button.cpp +++ b/aegisub/src/help_button.cpp @@ -88,7 +88,7 @@ void HelpButton::OpenPage(const wxString pageID) { docsPath.Replace(_T("\\"),_T("/")); docsPath = _T("/") + docsPath; #endif - wxString path = StandardPaths::DecodePath(wxString::Format(_T("file://%s/%s.html"),docsPath.c_str(),page.c_str())); + wxString path = wxString::Format(_T("file://%s/%s.html"),docsPath.c_str(),page.c_str()); wxLaunchDefaultBrowser(path); } } diff --git a/aegisub/src/main.cpp b/aegisub/src/main.cpp index 10175b4ed..75556b2f6 100644 --- a/aegisub/src/main.cpp +++ b/aegisub/src/main.cpp @@ -162,6 +162,12 @@ bool AegisubApp::OnInit() { wxRemoveFile(StandardPaths::DecodePath(_T("?data/config.dat"))); #endif } +#ifdef __WXMSW__ + // Change ?user to point to ?data if we have local config + if (Options.AsBool(_T("Local config"))) { + StandardPaths::SetPathValue(_T("?user"), StandardPaths::DecodePath(_T("?data"))); + } +#endif StartupLog(_T("Store options back")); Options.SetInt(_T("Last Version"),GetSVNRevision()); Options.LoadDefaults(false,true); // Override options based on version number @@ -260,7 +266,7 @@ void AegisubApp::OnUnhandledException() { wxString path = Options.AsText(_T("Auto recovery path")); if (path.IsEmpty()) path = StandardPaths::DecodePath(_T("?user/")); wxFileName dstpath(path); - if (!dstpath.IsAbsolute()) path = StandardPaths::DecodePath(_T("?user/")) + path; + if (!dstpath.IsAbsolute()) path = StandardPaths::DecodePathMaybeRelative(path, _T("?user/")); path += _T("/"); dstpath.Assign(path); if (!dstpath.DirExists()) wxMkdir(path); @@ -280,7 +286,7 @@ void AegisubApp::OnFatalException() { wxString path = Options.AsText(_T("Auto recovery path")); if (path.IsEmpty()) path = StandardPaths::DecodePath(_T("?user/")); wxFileName dstpath(path); - if (!dstpath.IsAbsolute()) path = StandardPaths::DecodePath(_T("?user/")) + path; + if (!dstpath.IsAbsolute()) path = StandardPaths::DecodePathMaybeRelative(path, _T("?user/")); path += _T("/"); dstpath.Assign(path); if (!dstpath.DirExists()) wxMkdir(path); diff --git a/aegisub/src/options.cpp b/aegisub/src/options.cpp index 15e156d4c..f03093c38 100644 --- a/aegisub/src/options.cpp +++ b/aegisub/src/options.cpp @@ -106,10 +106,10 @@ void OptionsManager::LoadDefaults(bool onlyDefaults,bool doOverride) { SetModificationType(MOD_RESTART); SetInt(_T("Auto save every seconds"),60); // FIXME: this shouldn't need to require a restart SetModificationType(MOD_AUTOMATIC); - SetText(_T("Auto save path"),_T("autosave")); // what does this mean on linux? actually this should be under $HOME on any OS + SetText(_T("Auto save path"),_T("?user/autosave")); SetBool(_T("Auto backup"),true); - SetText(_T("Auto backup path"),_T("autoback")); - SetText(_T("Auto recovery path"),_T("recovered")); + SetText(_T("Auto backup path"),_T("?user/autoback")); + SetText(_T("Auto recovery path"),_T("?user/recovered")); SetInt(_T("Autoload linked files"),2); SetText(_T("Text actor separator"),_T(":")); SetText(_T("Text comment starter"),_T("#")); @@ -119,7 +119,7 @@ void OptionsManager::LoadDefaults(bool onlyDefaults,bool doOverride) { // Edit Box SetModificationType(MOD_RESTART); - SetText(_T("Dictionaries path"),_T("dictionaries")); + SetText(_T("Dictionaries path"),_T("?data/dictionaries")); SetText(_T("Spell Checker"),_T("hunspell")); SetModificationType(MOD_AUTOMATIC); SetBool(_T("Link time boxes commit"),true); diff --git a/aegisub/src/spellchecker_hunspell.cpp b/aegisub/src/spellchecker_hunspell.cpp index 163fe3438..acecf88c7 100644 --- a/aegisub/src/spellchecker_hunspell.cpp +++ b/aegisub/src/spellchecker_hunspell.cpp @@ -202,7 +202,7 @@ wxArrayString HunspellSpellChecker::GetSuggestions(wxString word) { // Get list of available dictionaries wxArrayString HunspellSpellChecker::GetLanguageList() { // Get dir name - wxString path = DecodeRelativePath(Options.AsText(_T("Dictionaries path")),StandardPaths::DecodePath(_T("?data/"))) + _T("/"); + wxString path = StandardPaths::DecodePathMaybeRelative(Options.AsText(_T("Dictionaries path")), _T("?data")) + _T("/"); wxArrayString list; wxFileName folder(path); if (!folder.DirExists()) return list; @@ -240,7 +240,7 @@ void HunspellSpellChecker::SetLanguage(wxString language) { // Get dir name //FIXME: this should use ?user instead of ?data; however, since it apparently works already on win32, I'm not gonna mess with it right now :p - wxString path = DecodeRelativePath(Options.AsText(_T("Dictionaries path")),StandardPaths::DecodePath(_T("?data/"))) + _T("/"); + wxString path = StandardPaths::DecodePathMaybeRelative(Options.AsText(_T("Dictionaries path")), _T("?data")) + _T("/"); wxString userPath = StandardPaths::DecodePath(_T("?user/dictionaries/user_")); // Get affix and dictionary paths diff --git a/aegisub/src/standard_paths.cpp b/aegisub/src/standard_paths.cpp index 934edf7c1..11c23a766 100644 --- a/aegisub/src/standard_paths.cpp +++ b/aegisub/src/standard_paths.cpp @@ -119,7 +119,7 @@ wxString StandardPaths::DoDecodePath(wxString path) { /////////////// // Encode path -wxString StandardPaths::DoEncodePath(wxString path) { +wxString StandardPaths::DoEncodePath(const wxString &path) { // TODO return path; } @@ -127,6 +127,16 @@ wxString StandardPaths::DoEncodePath(wxString path) { ///////////////////////// // Set value of a ? path -void StandardPaths::DoSetPathValue(wxString path,wxString value) { +void StandardPaths::DoSetPathValue(const wxString &path, const wxString &value) { paths[path] = value; } + + +/////////////////////////////////////////////////////////////////////////// +// Decode a path that for legacy reasons might be relative to another path +wxString StandardPaths::DecodePathMaybeRelative(const wxString &path, const wxString &relativeTo) { + wxFileName res(DecodePath(path)); + if (res.IsRelative()) + res.Assign(DecodePath(relativeTo + _T("/") + path)); + return res.GetFullPath(); +} diff --git a/aegisub/src/standard_paths.h b/aegisub/src/standard_paths.h index 8438c154d..5cfd39f4d 100644 --- a/aegisub/src/standard_paths.h +++ b/aegisub/src/standard_paths.h @@ -56,11 +56,12 @@ private: StandardPaths& operator=(StandardPaths const&); wxString DoDecodePath(wxString path); - wxString DoEncodePath(wxString path); - void DoSetPathValue(wxString path,wxString value); + wxString DoEncodePath(const wxString &path); + void DoSetPathValue(const wxString &path, const wxString &value); public: - static wxString DecodePath(wxString path) { return GetInstance().DoDecodePath(path); } - static wxString EncodePath(wxString path) { return GetInstance().DoEncodePath(path); } - static void SetPathValue(wxString path,wxString value) { GetInstance().DoSetPathValue(path,value); } + static wxString DecodePath(const wxString &path) { return GetInstance().DoDecodePath(path); } + static wxString DecodePathMaybeRelative(const wxString &path, const wxString &relativeTo); + static wxString EncodePath(const wxString &path) { return GetInstance().DoEncodePath(path); } + static void SetPathValue(const wxString &path, const wxString &value) { GetInstance().DoSetPathValue(path,value); } }; diff --git a/aegisub/src/thesaurus_myspell.cpp b/aegisub/src/thesaurus_myspell.cpp index 59ea17e8c..32bc6fc56 100644 --- a/aegisub/src/thesaurus_myspell.cpp +++ b/aegisub/src/thesaurus_myspell.cpp @@ -96,7 +96,7 @@ void MySpellThesaurus::Lookup(wxString word,ThesaurusEntryArray &result) { // Get language list wxArrayString MySpellThesaurus::GetLanguageList() { // Get dir name - wxString path = DecodeRelativePath(Options.AsText(_T("Dictionaries path")),StandardPaths::DecodePath(_T("?data/"))) + _T("/"); + wxString path = StandardPaths::DecodePathMaybeRelative(Options.AsText(_T("Dictionaries path")), _T("?data")) + _T("/"); wxArrayString list; wxFileName folder(path); if (!folder.DirExists()) return list; @@ -140,7 +140,7 @@ void MySpellThesaurus::SetLanguage(wxString language) { if (language.IsEmpty()) return; // Get dir name - wxString path = DecodeRelativePath(Options.AsText(_T("Dictionaries path")),StandardPaths::DecodePath(_T("?data/"))) + _T("/"); + wxString path = StandardPaths::DecodePathMaybeRelative(Options.AsText(_T("Dictionaries path")), _T("?data")) + _T("/"); // Get affix and dictionary paths wxString idxpath = path + _T("th_") + language + _T(".idx");