[chronojump] Better management of runningFileName



commit f34ec1fe343e48e348046f2c6bd1759f737fc31e
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Sep 16 13:59:40 2009 +0200

    Better management of runningFileName
    -Added try catch on delete
    -Fixed bug: on running 0.8.9.8 for the first time if there was a runningFileName of a previous version (without it's PID inside)

 src/chronojump.cs     |   35 ++++++++++++++++++++++-------------
 src/gui/chronojump.cs |   18 ++++++++++++++----
 2 files changed, 36 insertions(+), 17 deletions(-)
---
diff --git a/src/chronojump.cs b/src/chronojump.cs
index 63af58e..21a9b18 100644
--- a/src/chronojump.cs
+++ b/src/chronojump.cs
@@ -193,7 +193,6 @@ public class ChronoJump
 
 
 
-			//File.Create(runningFileName);
 			createRunningFileName(runningFileName);
 			Sqlite.CreateTables(false); //not server
 			creatingDB = false;
@@ -248,7 +247,6 @@ Log.WriteLine("doing backup");
 			//check for bad Rjs (activate if program crashes and you use it in the same db before v.0.41)
 			//SqliteJump.FindBadRjs();
 		
-			//File.Create(runningFileName);
 			createRunningFileName(runningFileName);
 		}
 		
@@ -619,18 +617,29 @@ Console.WriteLine("--6--");
 	}
 
 	private bool chronojumpIsExecutingNTimes() {
-		StreamReader reader = File.OpenText(runningFileName);
-		string pid = reader.ReadToEnd();
-		reader.Close();
+		try {
+			StreamReader reader = File.OpenText(runningFileName);
+			string pid = reader.ReadToEnd();
+			reader.Close();
 
-		//delete the '\n' that ReaderToEnd() has put
-		pid = pid.TrimEnd(new char[1] {'\n'});
-		
-		Process [] pids = Process.GetProcessesByName("Chronojump");
-		foreach (Process myPid in pids)
-			if (myPid.Id == Convert.ToInt32(pid))
-				return true;
-		return false;
+			//delete the '\n' that ReaderToEnd() has put
+			pid = pid.TrimEnd(new char[1] {'\n'});
+
+			Process [] pids = Process.GetProcessesByName("Chronojump");
+			foreach (Process myPid in pids)
+				if (myPid.Id == Convert.ToInt32(pid))
+					return true;
+			return false;
+		} catch {
+			/*
+			   if we a chronojump older that 0.8.9.8 has crashed, and now we install 0.8.9.8
+			   it will try to read the pid
+			   but there will be no pid because old chronojumps have nothing written on that file
+			   A -not perfect- solution is if there are problems here, return false: (is not executing n times)
+			   */
+
+			return false;
+		}
 	}
 
 
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index a1bdd8b..a71bd27 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -1942,8 +1942,13 @@ public class ChronoJumpWindow
 		if(simulated == false) {
 			serialPortsClose();
 		}
-		
-		File.Delete(runningFileName);
+	
+		try {	
+			File.Delete(runningFileName);
+		} catch {
+			new DialogMessage(Constants.MessageTypes.WARNING, 
+					string.Format(Catalog.GetString("Could not delete file:\n{0}"), runningFileName));
+		}
 
 		if(File.Exists(Util.GetDatabaseTempDir() + Path.DirectorySeparatorChar + "chronojump.db"))
 			File.Move(Util.GetDatabaseTempDir() + Path.DirectorySeparatorChar + "chronojump.db",
@@ -1964,8 +1969,13 @@ public class ChronoJumpWindow
 		if(simulated == false) {
 			serialPortsClose();
 		}
-		
-		File.Delete(runningFileName);
+	
+		try {	
+			File.Delete(runningFileName);
+		} catch {
+			new DialogMessage(Constants.MessageTypes.WARNING, 
+					string.Format(Catalog.GetString("Could not delete file:\n{0}"), runningFileName));
+		}
 		
 		if(File.Exists(Util.GetDatabaseTempDir() + Path.DirectorySeparatorChar + "chronojump.db"))
 			File.Move(Util.GetDatabaseTempDir() + Path.DirectorySeparatorChar + "chronojump.db",



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