[longomatch] Add support for a portable version that don't require installation



commit 38d7968c7188fc63870102cd76a739e379a02471
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Sun Apr 10 23:44:00 2011 +0200

    Add support for a portable version that don't require installation

 LongoMatch/Common/Constants.cs |    2 +
 LongoMatch/Main.cs             |   49 +++++++++++++++++----------------------
 2 files changed, 23 insertions(+), 28 deletions(-)
---
diff --git a/LongoMatch/Common/Constants.cs b/LongoMatch/Common/Constants.cs
index 6535fcd..416235c 100644
--- a/LongoMatch/Common/Constants.cs
+++ b/LongoMatch/Common/Constants.cs
@@ -32,6 +32,8 @@ namespace LongoMatch.Common
 		
 		public const string FAKE_PROJECT = "@Fake Project@";
 		
+		public const string PORTABLE_FILE = "longomatch.portable";
+		
 		public const string LICENSE =
 @"This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
diff --git a/LongoMatch/Main.cs b/LongoMatch/Main.cs
index 78ddef6..4781ace 100644
--- a/LongoMatch/Main.cs
+++ b/LongoMatch/Main.cs
@@ -45,15 +45,7 @@ namespace LongoMatch
 
 		public static void Main(string[] args)
 		{
-			//Configuramos el directorio base de la ejecucuión y el directorio HOME
-			baseDirectory = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory,"../../");
-			homeDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal);
-			configDirectory = System.IO.Path.Combine(homeDirectory,".longomatch");
-			homeDirectory = System.IO.Path.Combine(homeDirectory,Constants.SOFTWARE_NAME);
-
-			if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
-				SetUpWin32Config();
-			}
+			SetupBaseDir();
 
 			//Iniciamos la internalización
 			Catalog.Init(Constants.SOFTWARE_NAME.ToLower(),RelativeToPrefix("share/locale"));
@@ -180,26 +172,27 @@ namespace LongoMatch
 				return db;
 			}
 		}
-
-		private static void SetUpWin32Config() {
-			Environment.SetEnvironmentVariable("GST_PLUGIN_PATH",RelativeToPrefix("lib\\gstreamer-0.10"));
-			baseDirectory = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory,"../");
-
-			try {
-				StreamReader reader = new StreamReader(System.IO.Path.Combine(homeDirectory,WIN32_CONFIG_FILE));
-				homeDirectory = reader.ReadLine();
+		
+		private static void SetupBaseDir() {
+			string home;
+			
+			if (Environment.OSVersion.Platform == PlatformID.Win32NT)
+				baseDirectory = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory,"../");
+			else
+				baseDirectory = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory,"../../");
+			
+			/* 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(Constants.PROJECT_NAME))
+				home = baseDirectory;
+			else
+				home = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal);
+			
+			homeDirectory = System.IO.Path.Combine(homeDirectory,Constants.SOFTWARE_NAME);
+			if (Environment.OSVersion.Platform == PlatformID.Win32NT)
 				configDirectory = homeDirectory;
-				if (!System.IO.Directory.Exists(homeDirectory))
-					System.IO.Directory.CreateDirectory(homeDirectory);
-				reader.Close();
-			}
-			//No config file exists, use default
-			catch {
-				//Vista permissions doesn't allow to use the 'etc' dir
-				//in the installation path. Use the default homeDirectory
-				//and let the user change it by hand
-				configDirectory=homeDirectory;
-			}
+			else
+				configDirectory = System.IO.Path.Combine(home,".longomatch");
 		}
 
 		private static void OnException(GLib.UnhandledExceptionArgs args) {



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