[chronojump] Error window shows when Chronojump is going to be opened two times



commit 5c18a7b2a1fc9a1bea3cb951bb7b689db31c6b10
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Jun 19 16:12:42 2017 +0200

    Error window shows when Chronojump is going to be opened two times

 src/chronojump.cs |   74 ++++++++++++++++++++++++++++++++++------------------
 1 files changed, 48 insertions(+), 26 deletions(-)
---
diff --git a/src/chronojump.cs b/src/chronojump.cs
index bcf0610..084d5b1 100644
--- a/src/chronojump.cs
+++ b/src/chronojump.cs
@@ -235,15 +235,20 @@ public class ChronoJump
        bool allSQLCallsDoneOnSqliteThingsThread;
 
        //used when Chronojump is being running two or more times (quadriple-click on start)
-       bool quitNow = false;   
+       bool quitNowCjTwoTimes = false;
 
        protected void sqliteThings () {
-               bool crashedBefore = checkIfChronojumpExitAbnormally();
-               if(crashedBefore) {
-                       if(chronojumpIsExecutingNTimes()) {
-                               quitNow = true;
+               bool badExit = checkIfChronojumpExitAbnormally();
+               if(badExit) {
+                       if(chronojumpIsExecutingNTimes())
+                       {
+                               messageToShowOnBoot += Catalog.GetString("Chronojump is already running") + 
"\n\n" +
+                                       Catalog.GetString("Chronojump will exit now.");
+
+                               chronojumpHasToExit = true;
+                               quitNowCjTwoTimes = true;
                                LogB.Error("Chronojump is already running.");
-                               Application.Quit();
+
                                return;
                        }
                        else
@@ -466,7 +471,7 @@ public class ChronoJump
 
 
                //if chronojump chrashed before
-               if(crashedBefore) {
+               if(badExit) {
                        if( versionAvailableKnown.Length > 0 && new Version(versionAvailableKnown) > new 
Version(progVersion) ) 
                                messageToShowOnBoot += "\n" + Catalog.GetString("Chronojump crashed before.") 
+ "\n" +
                                       Catalog.GetString("Please, update to new version: ") + 
versionAvailableKnown + "\n";
@@ -539,15 +544,23 @@ public class ChronoJump
                //pingEnd = true;
        }
 
-       protected void readMessageToStart() {
-               if(messageToShowOnBoot.Length > 0) {
+       protected void readMessageToStart()
+       {
+               if(messageToShowOnBoot.Length > 0)
+               {
                        ErrorWindow errorWin;
-                       if(chronojumpHasToExit) {
-                               messageToShowOnBoot += "\n<b>" + string.Format(Catalog.GetString("Chronojump 
will exit now.")) + "</b>\n";
-
-                               errorWin = ErrorWindow.Show(messageToShowOnBoot);
-                               errorWin.Show_button_open_database_folder();
-                               errorWin.Button_accept.Clicked += new 
EventHandler(on_message_boot_accepted_quit);
+                       if(chronojumpHasToExit)
+                       {
+                               if(quitNowCjTwoTimes) {
+                                       errorWin = ErrorWindow.Show(messageToShowOnBoot);
+                                       errorWin.Button_accept.Clicked += new 
EventHandler(on_message_boot_accepted_quit_not_deleting_runningfilename);
+                               } else {
+                                       messageToShowOnBoot += "\n<b>" + 
string.Format(Catalog.GetString("Chronojump will exit now.")) + "</b>\n";
+
+                                       errorWin = ErrorWindow.Show(messageToShowOnBoot);
+                                       errorWin.Show_button_open_database_folder();
+                                       errorWin.Button_accept.Clicked += new 
EventHandler(on_message_boot_accepted_quit_nice);
+                               }
                        } else { 
                                errorWin = ErrorWindow.Show(messageToShowOnBoot);
                                errorWin.Show_send_log();
@@ -564,17 +577,31 @@ public class ChronoJump
                startChronojump();
        }
 
-       private void on_message_boot_accepted_quit (object o, EventArgs args) {
-               try {
-                       File.Delete(runningFileName);
-               } catch {
-                       //done because if database dir is moved in a chronojump conversion (eg from before 
installer to installjammer) maybe it will not find this runningFileName
+       private void on_message_boot_accepted_quit_nice (object o, EventArgs args)
+       {
+               quitChronojump(true);
+       }
+       private void on_message_boot_accepted_quit_not_deleting_runningfilename (object o, EventArgs args)
+       {
+               quitChronojump(false);
+       }
+       private void quitChronojump(bool deleteRunningFileName)
+       {
+               if(deleteRunningFileName)
+               {
+                       try {
+                               File.Delete(runningFileName);
+                       } catch {
+                               //done because if database dir is moved in a chronojump conversion
+                               //(eg from before installer to installjammer) maybe it will not find this 
runningFileName
+                       }
                }
                Log.End();
                //Log.Delete();
                Application.Quit();
        }
 
+
        private void startChronojump() {
 
                //wait until all sql calls are done in other thread
@@ -623,12 +650,7 @@ public class ChronoJump
        
        protected bool PulseGTK ()
        {
-               if(quitNow) 
-                       return false;
-
-               //if( ( needEndSplashWin && pingEnd ) 
-               //              || ! thread.IsAlive) {
-               if( needEndSplashWin || ! thread.IsAlive ) {
+               if( quitNowCjTwoTimes || needEndSplashWin || ! thread.IsAlive ) {
                        LogB.ThreadEnding();
                        fakeSplashButton.Click();
 


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