From 26d3877bcfb24b67cee5ba4c41101c2d9cfc0597 Mon Sep 17 00:00:00 2001
From: Niels Martin Hansen <nielsm@aegisub.org>
Date: Tue, 14 Jul 2009 04:51:35 +0000
Subject: [PATCH] More cleanup of local config:  * Remove option from Options
 dialogue, it's an install-time thing really  * Don't try to do file
 associations at startup if we're portable  * General clean up of config
 handling code; properly make ?user point to ?data and then everything
 magically follows, makes a lot of handling cleaner

Originally committed to SVN as r3131.
---
 aegisub/src/dialog_options.cpp | 11 +---------
 aegisub/src/main.cpp           | 37 +++++++++++++++++-----------------
 2 files changed, 20 insertions(+), 28 deletions(-)

diff --git a/aegisub/src/dialog_options.cpp b/aegisub/src/dialog_options.cpp
index b7cd69546..ee5bba40b 100644
--- a/aegisub/src/dialog_options.cpp
+++ b/aegisub/src/dialog_options.cpp
@@ -114,7 +114,6 @@ DialogOptions::DialogOptions(wxWindow *parent)
 		AddCheckBox(generalPage,genSizer4,_("Show Splash Screen"),_T("Show splash"));
 #ifdef __WXMSW__
 		AddCheckBox(generalPage,genSizer4,_("Auto Check for Updates"),_T("Auto check for updates"));
-		AddCheckBox(generalPage,genSizer4,_("Save config.dat locally"),_T("Local config"));
 #endif
 		genSizer4->AddGrowableCol(0,1);
 
@@ -904,15 +903,7 @@ void DialogOptions::WriteToOptions(bool justApply) {
 	}
 
 	// Save options
-#ifdef __WXMSW__
-	if (Options.AsBool(_T("Local config"))) Options.SetFile(StandardPaths::DecodePath(_T("?data/config.dat")));
-	else {
-#endif
-		Options.SetFile(StandardPaths::DecodePath(_T("?user/config.dat")));
-#ifdef __WXMSW__
-		wxRemoveFile(StandardPaths::DecodePath(_T("?data/config.dat")));
-	}
-#endif
+	Options.SetFile(StandardPaths::DecodePath(_T("?user/config.dat")));
 	Options.Save();
 
 	// Need restart?
diff --git a/aegisub/src/main.cpp b/aegisub/src/main.cpp
index 75556b2f6..ef86dbee6 100644
--- a/aegisub/src/main.cpp
+++ b/aegisub/src/main.cpp
@@ -147,27 +147,27 @@ bool AegisubApp::OnInit() {
 		StartupLog(_T("Load configuration"));
 		Options.LoadDefaults();
 #ifdef __WXMSW__
-		// TODO: Display a messagebox about permission being needed to write to local config once the string freeze is over with
-		if (wxFileName::IsFileWritable(StandardPaths::DecodePath(_T("?data/config.dat"))))
+		// Try loading configuration from the install dir if one exists there
+		if (wxFileName::FileExists(StandardPaths::DecodePath(_T("?data/config.dat")))) {
 			Options.SetFile(StandardPaths::DecodePath(_T("?data/config.dat")));
-		else 
-			Options.SetFile(StandardPaths::DecodePath(_T("?user/config.dat")));
-		Options.Load();
-		if (!Options.AsBool(_T("Local config")) && Options.GetFile() != StandardPaths::DecodePath(_T("?user/config.dat")))
-#endif
-		{
-			Options.SetFile(StandardPaths::DecodePath(_T("?user/config.dat")));
 			Options.Load();
-#ifdef __WXMSW__
-			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")));
+
+			if (Options.AsBool(_T("Local config"))) {
+				// Local config, make ?user mean ?data so all user settings are placed in install dir
+				StandardPaths::SetPathValue(_T("?user"), StandardPaths::DecodePath(_T("?data")));
+			}
+			else {
+				// Not local config, we don't want that config.dat file here any more
+				// It might be a leftover from a really old install
+				wxRemoveFile(StandardPaths::DecodePath(_T("?data/config.dat")));
+			}
 		}
 #endif
+		// TODO: Check if we can write to config.dat and warn the user if we can't
+		// If we had local config, ?user now means ?data so this will still be loaded from the correct location
+		Options.SetFile(StandardPaths::DecodePath(_T("?user/config.dat")));
+		Options.Load();
+
 		StartupLog(_T("Store options back"));
 		Options.SetInt(_T("Last Version"),GetSVNRevision());
 		Options.LoadDefaults(false,true);	// Override options based on version number
@@ -207,7 +207,8 @@ bool AegisubApp::OnInit() {
 		// Set association
 #ifndef _DEBUG
 		StartupLog(_T("Install file type associations"));
-		RegistryAssociate();
+		if (!Options.AsBool(_T("Local config")))
+			RegistryAssociate();
 #endif
 
 		// Get parameter subs
-- 
GitLab