From 626d21d38005ab03f867f6402c3d555e40232c1d Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Tue, 2 Feb 2010 23:40:56 +0100 Subject: [PATCH] =?UTF-8?q?Aggiunte=20parti=20di=20codice=20per=20supporta?= =?UTF-8?q?re=20SQLite=20in=20GlobalConfig,=20anche=20se=20non=20=C3=A8=20?= =?UTF-8?q?ancora=20funzionante.=20Correzioni=20(grezze)=20per=20far=20chi?= =?UTF-8?q?udere=20l'applicazione.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GlobalConfig.cs | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ MainWindow.cs | 5 +++++ Protocol.cs | 11 ++++++----- 3 files changed, 60 insertions(+), 5 deletions(-) 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 () -- 2.1.4