Aggiunte parti di codice per supportare SQLite in GlobalConfig,

Leonardo Robol [2010-02-02 22:40]
Aggiunte parti di codice per supportare SQLite in GlobalConfig,
anche se non è ancora funzionante. Correzioni (grezze) per far
chiudere l'applicazione.
Filename
GlobalConfig.cs
MainWindow.cs
Protocol.cs
diff --git a/GlobalConfig.cs b/GlobalConfig.cs
index 7eeb156..cf201ed 100644
--- a/GlobalConfig.cs
+++ b/GlobalConfig.cs
@@ -1,5 +1,6 @@

 using System;
+using System.Data.SQLite;

 namespace Dizzy
 {
@@ -8,9 +9,57 @@ namespace Dizzy
 	public class GlobalConfig
 	{
 		public string user, password;
+		private SQLiteConnection conn;

 		public GlobalConfig ()
 		{
+			conn = new SQLiteConnection ("Data Source=" + DataBaseName () + ";Version=3;");
+			// Controlliamo che il database sia correttamente
+			// inizializzato.
+			Init ();
+		}
+
+		protected void Init ()
+		{
+			SQLiteCommand sqlCmd;
+			this.conn.Open ();
+			sqlCmd = this.conn.CreateCommand ();
+
+			sqlCmd.CommandText = "SELECT * from sqlite_master WHERE type='table';";
+			SQLiteDataReader reader = sqlCmd.ExecuteReader ();
+
+			if(!reader.HasRows)
+				InitialSetup ();
+		}
+
+		protected void InitialSetup ()
+		{
+
+		}
+
+		protected string DataBaseName ()
+		{
+			string dir = "";
+			if (System.Environment.OSVersion.ToString ().Contains("Windows"))
+			{
+
+				System.Reflection.Assembly a = System.Reflection.Assembly.GetEntryAssembly ();
+				dir = System.IO.Path.GetDirectoryName (a.Location);
+
+			}
+			else // Assumiamo qualcosa di Unix-like
+			{
+				dir = System.Environment.GetEnvironmentVariable("HOME");
+				dir += System.IO.Path.DirectorySeparatorChar + ".dizzy";
+			}
+			if (!System.IO.Directory.Exists(dir))
+				System.IO.Directory.CreateDirectory (dir);
+
+			string db = dir + System.IO.Path.DirectorySeparatorChar + "list.sqlite";
+			if (!System.IO.File.Exists (db))
+				System.IO.File.Create (db);
+			return db;
 		}
 	}
+
 }
diff --git a/MainWindow.cs b/MainWindow.cs
index fc085f8..7d55d6d 100644
--- a/MainWindow.cs
+++ b/MainWindow.cs
@@ -14,6 +14,7 @@ public partial class MainWindow : Gtk.Window

 		Build ();

+
 		// Inizializziamo la vista dei file.
 		files = new Dizzy.FileTreeView (filelist);

@@ -28,6 +29,10 @@ public partial class MainWindow : Gtk.Window
 	{
 		protocol.Disconnect ();
 		Application.Quit ();
+
+		// Questo è molto grezzo ma è effettivamente l'unico metodo per uscire
+		// per il momento.
+		this.Destroy ();
 		a.RetVal = true;
 	}

diff --git a/Protocol.cs b/Protocol.cs
index adddd1c..38ad533 100644
--- a/Protocol.cs
+++ b/Protocol.cs
@@ -114,6 +114,7 @@ namespace Dizzy

 		public void Download(File f, ref TaskTreeView tasks, string downloadFolder)
 		{
+			// Preparo gli argomento da passare alla funzione.
 			ArrayList args = new ArrayList ();
 			args.Add (f);
 			args.Add (tasks);
@@ -240,16 +241,16 @@ namespace Dizzy
 		public void Download(File f, string downloadFolder)
 		{
 			Console.WriteLine (" => Getting {0}", f.name);
-			try
-			{
+			// try
+			// {
 				Console.WriteLine (f.path);
 				this.sftp.Get (f.path, downloadFolder + Path.DirectorySeparatorChar +  f.name);
-			}
-			catch(Exception e)
+			// }
+			/* catch()
 			{
 				Console.WriteLine("Error in Get... ");
 				Console.WriteLine(e.Message);
-			}
+			} */
 		}

 		public void Disconnect ()
ViewGit