From efcb7dc603fca4b4f0eb93d83de09615d337cef8 Mon Sep 17 00:00:00 2001
From: regeszter <regeszter@freemail.hu>
Date: Thu, 17 Oct 2013 18:56:45 +0200
Subject: [PATCH] Save last used directory in watchdog

---
 mediaportal/WatchDog/MPWatchDog.Designer.cs | 14 +++++++++++
 mediaportal/WatchDog/MPWatchDog.cs          | 38 +++++++++++++++++++++++++++--
 mediaportal/WatchDog/Utils.cs               | 17 +++++++++++++
 3 files changed, 67 insertions(+), 2 deletions(-)

diff --git a/mediaportal/WatchDog/MPWatchDog.Designer.cs b/mediaportal/WatchDog/MPWatchDog.Designer.cs
index 4a42022..282ba23 100644
--- a/mediaportal/WatchDog/MPWatchDog.Designer.cs
+++ b/mediaportal/WatchDog/MPWatchDog.Designer.cs
@@ -30,6 +30,7 @@ namespace WatchDog
     {
       this.components = new System.ComponentModel.Container();
       this.settingsGroup = new System.Windows.Forms.GroupBox();
+      this.button1 = new System.Windows.Forms.Button();
       this.btnZipFile = new System.Windows.Forms.Button();
       this.tbZipFile = new System.Windows.Forms.TextBox();
       this.logDirLabel = new System.Windows.Forms.Label();
@@ -71,6 +72,7 @@ namespace WatchDog
       // 
       this.settingsGroup.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
             | System.Windows.Forms.AnchorStyles.Right)));
+      this.settingsGroup.Controls.Add(this.button1);
       this.settingsGroup.Controls.Add(this.btnZipFile);
       this.settingsGroup.Controls.Add(this.tbZipFile);
       this.settingsGroup.Controls.Add(this.logDirLabel);
@@ -81,6 +83,16 @@ namespace WatchDog
       this.settingsGroup.TabStop = false;
       this.settingsGroup.Text = "Settings";
       // 
+      // button1
+      // 
+      this.button1.Location = new System.Drawing.Point(333, 57);
+      this.button1.Name = "button1";
+      this.button1.Size = new System.Drawing.Size(64, 23);
+      this.button1.TabIndex = 4;
+      this.button1.Text = "Reset";
+      this.button1.UseVisualStyleBackColor = true;
+      this.button1.Click += new System.EventHandler(this.button1_Click);
+      // 
       // btnZipFile
       // 
       this.btnZipFile.Location = new System.Drawing.Point(333, 32);
@@ -96,6 +108,7 @@ namespace WatchDog
       this.tbZipFile.Name = "tbZipFile";
       this.tbZipFile.Size = new System.Drawing.Size(321, 20);
       this.tbZipFile.TabIndex = 2;
+      this.tbZipFile.TextChanged += new System.EventHandler(this.tbZipFile_TextChanged);
       // 
       // logDirLabel
       // 
@@ -412,5 +425,6 @@ namespace WatchDog
     private System.Windows.Forms.MenuItem menuItem17;
     private System.Windows.Forms.MenuItem menuItem18;
     private System.Windows.Forms.MenuItem menuItem19;
+    private System.Windows.Forms.Button button1;
   }
 }
\ No newline at end of file
diff --git a/mediaportal/WatchDog/MPWatchDog.cs b/mediaportal/WatchDog/MPWatchDog.cs
index 0a13926..af09353 100644
--- a/mediaportal/WatchDog/MPWatchDog.cs
+++ b/mediaportal/WatchDog/MPWatchDog.cs
@@ -62,6 +62,8 @@ namespace WatchDog
     private readonly List<string> _knownPids = new List<string>();
     private bool _safeMode;
     private int GraphsCreated { get; set; }
+    private string _watchdogtargetDir = "";
+    private string _watchdogAppDir = "";
 
     #endregion
 
@@ -176,6 +178,13 @@ namespace WatchDog
 
     public MPWatchDog()
     {
+      _watchdogAppDir = Directory.GetCurrentDirectory() + "\\watchdog.xml";
+
+      using (Settings xmlreader = new Settings(_watchdogAppDir, false))
+      {
+        _watchdogtargetDir = xmlreader.GetValueAsString("general", "watchdogTargetDir", "");
+      }
+     
       GraphsCreated = 0;
       Thread.CurrentThread.Name = "MPWatchDog";
       InitializeComponent();
@@ -185,8 +194,17 @@ namespace WatchDog
         _tempDir += "\\";
       }
       _tempDir += "MPTemp";
-      _zipFile = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) +
-                 "\\MediaPortal-Logs\\MediaPortalLogs_[date]__[time].zip";
+      
+      if (_watchdogtargetDir == string.Empty)
+      {
+        _zipFile = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) 
+          + "\\MediaPortal-Logs\\MediaPortalLogs_[date]__[time].zip";
+      }
+      else
+      {
+        _zipFile = _watchdogtargetDir + "\\MediaPortalLogs_[date]__[time].zip";
+      }
+      
       if (!ParseCommandLine())
       {
         Application.Exit();
@@ -681,5 +699,21 @@ namespace WatchDog
     {
 
     }
+
+    private void tbZipFile_TextChanged(object sender, EventArgs e)
+    {
+      using (var xmlwriter = new Settings(_watchdogAppDir, false))
+      {
+        xmlwriter.SetValue("general", "watchdogTargetDir", Utils.GetDirectoryName(tbZipFile.Text));
+      }
+    }
+
+    private void button1_Click(object sender, EventArgs e)
+    {
+      _zipFile = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
+         + "\\MediaPortal-Logs\\MediaPortalLogs_[date]__[time].zip";
+      tbZipFile.Text = _zipFile;
+      //MessageBox.Show(_zipFile, "MediaPortal WatchDog -- Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+    }
   }
 }
diff --git a/mediaportal/WatchDog/Utils.cs b/mediaportal/WatchDog/Utils.cs
index 8e39b3b..4866b14 100644
--- a/mediaportal/WatchDog/Utils.cs
+++ b/mediaportal/WatchDog/Utils.cs
@@ -43,5 +43,22 @@ namespace WatchDog
         Application.DoEvents();
       }
     }
+
+    public static string GetDirectoryName(string f)
+    {
+      try
+      {
+        int posOfDirSep = f.LastIndexOf("\\");
+        if (posOfDirSep >= 0)
+          return f.Substring(0, posOfDirSep);
+        else return string.Empty;
+      }
+      catch (Exception)
+      {
+        return string.Empty;
+      }
+    }
+
+
   }
 }
\ No newline at end of file
-- 
1.8.1.msysgit.1

