sparkles: Lazy Configuration Singleton on app startup

This commit is contained in:
Jonathan Haines 2017-04-18 22:30:42 +10:00
parent 909be12c1e
commit 5b34d2ff29
6 changed files with 21 additions and 16 deletions

View file

@ -194,18 +194,9 @@ namespace SparkleShare {
bool lost_folders_path = false;
public BaseController ()
public BaseController (Configuration config)
{
string app_data_path = Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData);
if (InstallationInfo.OperatingSystem != OS.Windows && InstallationInfo.OperatingSystem != OS.Mac)
app_data_path = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Personal), ".config");
string config_path = Path.Combine (app_data_path, "org.sparkleshare.SparkleShare");
Config = new Configuration (config_path, "projects.xml");
Configuration.DefaultConfiguration = Config;
Config = config;
FoldersPath = Config.FoldersPath;
}

View file

@ -62,7 +62,7 @@ namespace SparkleShare {
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
Controller = new Controller ();
Controller = new Controller (Configuration.DefaultConfiguration);
Controller.Initialize ();
UI = new UserInterface ();

View file

@ -28,7 +28,8 @@ namespace SparkleShare {
public class Controller : BaseController {
public Controller ()
public Controller (Configuration config)
: base (config)
{
}

View file

@ -39,7 +39,8 @@ namespace SparkleShare {
}
public Controller ()
public Controller (Configuration config)
: base (config)
{
NSApplication.Init ();

View file

@ -31,7 +31,8 @@ namespace SparkleShare {
public class Controller : BaseController {
public Controller ()
public Controller (Configuration config)
: base (config)
{
}

View file

@ -24,7 +24,18 @@ namespace Sparkles {
public class Configuration : XmlDocument {
public static Configuration DefaultConfiguration;
private static Lazy<Configuration> ConfigLazy = new Lazy<Configuration> (() => {
string app_data_path = Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData);
if (InstallationInfo.OperatingSystem != OS.Windows && InstallationInfo.OperatingSystem != OS.Mac)
app_data_path = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Personal), ".config");
string config_path = Path.Combine (app_data_path, "org.sparkleshare.SparkleShare");
return new Configuration (config_path, "projects.xml");
});
public static Configuration DefaultConfiguration { get { return ConfigLazy.Value; } }
public static bool DebugMode = true;
public readonly string DirectoryPath;