[longomatch] Add a common init function for the config



commit 4c64a1aba19ace3dc5036f45e22529a6cc9bc6e7
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Tue Nov 18 18:50:21 2014 +0100

    Add a common init function for the config

 LongoMatch.Core/Config.cs                    |   34 +++++++++++++++++++++++++
 LongoMatch.Services/Services/CoreServices.cs |   35 +-------------------------
 2 files changed, 35 insertions(+), 34 deletions(-)
---
diff --git a/LongoMatch.Core/Config.cs b/LongoMatch.Core/Config.cs
index e2a0293..caf2e5b 100644
--- a/LongoMatch.Core/Config.cs
+++ b/LongoMatch.Core/Config.cs
@@ -50,6 +50,40 @@ namespace LongoMatch
                public static StyleConf Style;
 
                static ConfigState state;
+
+               public static void Init () {
+                       string home;
+
+                       if (Environment.GetEnvironmentVariable ("LGM_UNINSTALLED") != null) {
+                               Config.baseDirectory = Path.GetFullPath (".");
+                               Config.dataDir = "../data";
+                       } else {
+                               Config.baseDirectory = Path.Combine (AppDomain.CurrentDomain.BaseDirectory, 
"../");
+                               if (!Directory.Exists (Path.Combine (Config.baseDirectory, "share",
+                                                                    Constants.SOFTWARE_NAME))) {
+                                       Config.baseDirectory = Path.Combine (Config.baseDirectory, "../");
+                               }
+                               if (!Directory.Exists (Path.Combine (Config.baseDirectory, "share",
+                                                                    Constants.SOFTWARE_NAME)))
+                                       Log.Warning ("Prefix directory not found");
+                               Config.dataDir = Path.Combine (Config.baseDirectory, "share",
+                                                              Constants.SOFTWARE_NAME.ToLower ());
+                       }
+                       
+                       /* Check for the magic file PORTABLE to check if it's a portable version
+                        * and the config goes in the same folder as the binaries */
+                       if (File.Exists (Path.Combine (Config.baseDirectory, Constants.PORTABLE_FILE)))
+                               home = Config.baseDirectory;
+                       else
+                               home = System.Environment.GetFolderPath (Environment.SpecialFolder.Personal);
+                       
+                       Config.homeDirectory = System.IO.Path.Combine (home, Constants.SOFTWARE_NAME);
+                       if (Environment.OSVersion.Platform == PlatformID.Win32NT)
+                               Config.configDirectory = Config.homeDirectory;
+                       else
+                               Config.configDirectory = System.IO.Path.Combine (home, "." +
+                                       Constants.SOFTWARE_NAME.ToLower ());
+               }
                
                public static void Load () {
                        if (File.Exists(Config.ConfigFile)) {
diff --git a/LongoMatch.Services/Services/CoreServices.cs b/LongoMatch.Services/Services/CoreServices.cs
index d3dd277..85951cc 100644
--- a/LongoMatch.Services/Services/CoreServices.cs
+++ b/LongoMatch.Services/Services/CoreServices.cs
@@ -54,7 +54,7 @@ namespace LongoMatch.Services
                        Log.Debugging = Debugging;
                        Log.Information ("Starting " + Constants.SOFTWARE_NAME);
 
-                       SetupBaseDir ();
+                       Config.Init ();
 
                        /* Check default folders */
                        CheckDirs ();
@@ -131,39 +131,6 @@ namespace LongoMatch.Services
                                System.IO.Directory.CreateDirectory (Config.TempVideosDir);
                }
 
-               static void SetupBaseDir ()
-               {
-                       string home;
-
-                       if (Environment.GetEnvironmentVariable ("LGM_UNINSTALLED") != null) {
-                               Config.baseDirectory = Path.GetFullPath (".");
-                               Config.dataDir = "../data";
-                       } else {
-                               Config.baseDirectory = System.IO.Path.Combine 
(System.AppDomain.CurrentDomain.BaseDirectory, "../");
-                               if (!System.IO.Directory.Exists (System.IO.Path.Combine 
(Config.baseDirectory, "share", Constants.SOFTWARE_NAME))) {
-                                       Config.baseDirectory = System.IO.Path.Combine (Config.baseDirectory, 
"../");
-                               }
-                               if (!System.IO.Directory.Exists (System.IO.Path.Combine 
(Config.baseDirectory, "share", Constants.SOFTWARE_NAME)))
-                                       Log.Warning ("Prefix directory not found");
-                               Config.dataDir = Path.Combine (Config.baseDirectory, "share",
-                                                              Constants.SOFTWARE_NAME.ToLower ());
-                       }
-                       
-                       /* Check for the magic file PORTABLE to check if it's a portable version
-                        * and the config goes in the same folder as the binaries */
-                       if (File.Exists (System.IO.Path.Combine (Config.baseDirectory, 
Constants.PORTABLE_FILE)))
-                               home = Config.baseDirectory;
-                       else
-                               home = System.Environment.GetFolderPath (Environment.SpecialFolder.Personal);
-                       
-                       Config.homeDirectory = System.IO.Path.Combine (home, Constants.SOFTWARE_NAME);
-                       if (Environment.OSVersion.Platform == PlatformID.Win32NT)
-                               Config.configDirectory = Config.homeDirectory;
-                       else
-                               Config.configDirectory = System.IO.Path.Combine (home, "." +
-                                       Constants.SOFTWARE_NAME.ToLower ());
-               }
-
                static bool? debugging = null;
 
                public static bool Debugging {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]