11#region Copyright (C)
2- // <copyright file="ConfigFileHelper .cs" company="Smurf-IV">
2+ // <copyright file="RunControl .cs" company="Smurf-IV">
33//
4- // Copyright (C) 2018-2019 Smurf-IV & BlueBlock
4+ // Copyright (C) 2018-2020 Smurf-IV & BlueBlock 2018
55//
66// This program is free software: you can redistribute it and/or modify
77// it under the terms of the GNU General Public License as published by
2727using System . ComponentModel ;
2828using System . Diagnostics ;
2929using System . Drawing ;
30- using System . Linq ;
3130using System . Text ;
3231using System . Threading ;
3332using System . Windows . Forms ;
33+
3434using ComponentFactory . Krypton . Toolkit ;
35+
3536using Elucidate . wyDay . Controls ;
3637
3738using NLog ;
3839
3940namespace Elucidate . Controls
4041{
41- public partial class LiveRunLogControl : UserControl
42+ public partial class RunControl : UserControl
4243 {
4344 private static readonly Logger Log = LogManager . GetCurrentClassLogger ( ) ;
4445
@@ -55,22 +56,16 @@ public partial class LiveRunLogControl : UserControl
5556 private readonly ManualResetEvent mreErrorDone = new ManualResetEvent ( false ) ;
5657 private ProcessPriorityClass requested = ProcessPriorityClass . Normal ;
5758 private string lastError ;
58- private List < string > batchPaths ;
59- private static ListBoxLog ListBoxLog ;
59+ private Stack < string > batchPaths ;
6060
61- public bool IsRunning { get ; set ; }
61+ public bool IsRunning { get ; private set ; }
6262
63- private CommandType CommandTypeRunning { get ; set ; }
63+ public CommandType CommandTypeRunning { get ; private set ; }
6464
65- public LiveRunLogControl ( )
65+ public RunControl ( )
6666 {
6767 InitializeComponent ( ) ;
6868
69- if ( ListBoxLog == null )
70- {
71- ListBoxLog = new ListBoxLog ( rtbLiveLog ) ;
72- }
73-
7469 AddThreadingCallbacks ( ) ;
7570
7671 toolStripStatusLabel1 . Text = DateTime . Now . ToString ( "u" ) ;
@@ -113,8 +108,7 @@ public enum CommandType
113108 Scrub ,
114109 Fix ,
115110 Dup ,
116- QuickCheck ,
117- RecoverCheck ,
111+ CheckForMissing ,
118112 RecoverFix ,
119113 ForceFullSync
120114 }
@@ -123,28 +117,23 @@ private void LiveRunLogControl_Load(object sender, EventArgs e)
123117 {
124118 }
125119
126- public void HideAdditionalCommands ( )
127- {
128- tableLayoutPanelAdditionalCommands . Visible = false ;
129- }
130-
131- public readonly BackgroundWorker ActionWorker = new BackgroundWorker
120+ private readonly BackgroundWorker actionWorker = new BackgroundWorker
132121 {
133122 WorkerReportsProgress = true ,
134- WorkerSupportsCancellation = true ,
123+ WorkerSupportsCancellation = true
135124 } ;
136125
137126 private void AddThreadingCallbacks ( )
138127 {
139128 // Add threading callbacks
140- ActionWorker . DoWork += actionWorker_DoWork ;
141- ActionWorker . ProgressChanged += actionWorker_ProgressChanged ;
142- ActionWorker . RunWorkerCompleted += actionWorker_RunWorkerCompleted ;
129+ actionWorker . DoWork += actionWorker_DoWork ;
130+ actionWorker . ProgressChanged += actionWorker_ProgressChanged ;
131+ actionWorker . RunWorkerCompleted += actionWorker_RunWorkerCompleted ;
143132 comboBoxProcessStatus . Text = @"Stopped" ;
144133 comboBoxProcessStatus . Enabled = false ;
145134 }
146135
147- internal void StartSnapRaidProcess ( CommandType commandToRun , List < string > paths = null )
136+ internal void StartSnapRaidProcess ( CommandType commandToRun , Stack < string > paths = null )
148137 {
149138 if ( IsRunning )
150139 {
@@ -165,13 +154,13 @@ internal void StartSnapRaidProcess(CommandType commandToRun, List<string> paths
165154 case CommandType . Diff :
166155 command . Append ( @"diff" ) ;
167156 break ;
168- case CommandType . QuickCheck :
157+ case CommandType . CheckForMissing :
169158 command . Append ( @"check" ) ;
170- defaultOption = @" -a " ;
159+ defaultOption = @" -m " ;
171160 break ;
172161 case CommandType . Check :
173- case CommandType . RecoverCheck :
174162 command . Append ( @"check" ) ;
163+ defaultOption = @" -a" ;
175164 break ;
176165 case CommandType . Sync :
177166 command . Append ( @"sync" ) ;
@@ -225,7 +214,7 @@ internal void StartSnapRaidProcess(CommandType commandToRun, List<string> paths
225214
226215 requested = ProcessPriorityClass . Normal ;
227216
228- ActionWorker . RunWorkerAsync ( command . ToString ( ) ) ;
217+ actionWorker . RunWorkerAsync ( command . ToString ( ) ) ;
229218
230219 toolStripProgressBar1 . DisplayText = "Running..." ;
231220
@@ -243,10 +232,6 @@ private void actionWorker_DoWork(object sender, DoWorkEventArgs e)
243232 {
244233 try
245234 {
246- IsRunning = true ;
247-
248- OnTaskStarted ( e ) ;
249-
250235 BackgroundWorker worker = sender as BackgroundWorker ;
251236
252237 string command = e . Argument as string ;
@@ -273,6 +258,10 @@ private void actionWorker_DoWork(object sender, DoWorkEventArgs e)
273258
274259 string args = Util . FormatSnapRaidCommandArgs ( command , out string appPath ) ;
275260
261+ IsRunning = true ;
262+
263+ OnTaskStarted ( e ) ;
264+
276265 RunSnapRaid ( e , args , appPath , worker ) ;
277266 }
278267 catch ( Exception ex )
@@ -294,9 +283,11 @@ private void RunSnapRaid(DoWorkEventArgs e, string args, string appPath, Backgro
294283
295284 do
296285 {
297- sbPaths . Append ( $ "-f \" { batchPaths [ batchPaths . Count - 1 ] } \" ") ;
298- batchPaths . RemoveAt ( batchPaths . Count - 1 ) ;
299- } while ( sbPaths . Length < MAX_COMMAND_ARG_LENGTH && batchPaths . Any ( ) ) ;
286+ var restore = batchPaths . Pop ( ) ;
287+ sbPaths . Append ( " -f \" " ) . Append ( restore ) . Append ( "\" " ) ;
288+ } while ( ( sbPaths . Length < MAX_COMMAND_ARG_LENGTH )
289+ && ( batchPaths . Count > 0 )
290+ ) ;
300291
301292 args += sbPaths . ToString ( ) ;
302293 }
@@ -427,9 +418,8 @@ private void actionWorker_ProgressChanged(object sender, ProgressChangedEventArg
427418 private void actionWorker_RunWorkerCompleted ( object sender , RunWorkerCompletedEventArgs e )
428419 {
429420 IsRunning = false ;
430-
431421 // continue running additional times if there is more work to be done
432- if ( CommandTypeRunning == CommandType . RecoverFix && batchPaths . Any ( ) )
422+ if ( CommandTypeRunning == CommandType . RecoverFix && ( batchPaths . Count > 0 ) )
433423 {
434424 StartSnapRaidProcess ( CommandType . RecoverFix ) ;
435425 return ;
@@ -468,7 +458,10 @@ private void actionWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEv
468458 comboBoxProcessStatus . Text = @"Stopped" ;
469459 }
470460
471- if ( CommandTypeRunning == CommandType . RecoverCheck || CommandTypeRunning == CommandType . RecoverFix )
461+ if ( CommandTypeRunning == CommandType . Check
462+ || CommandTypeRunning == CommandType . CheckForMissing
463+ || CommandTypeRunning == CommandType . RecoverFix
464+ )
472465 {
473466 toolStripProgressBar1 . State = ProgressBarState . Normal ;
474467 toolStripProgressBar1 . DisplayText = "Completed" ;
@@ -543,8 +536,7 @@ private void ReadStandardOutput(ThreadObject threadObject)
543536 // SnapRaid dumps a null length when drawing graphs etc. So need to check if still running..
544537 mreProcessExit . WaitOne ( 100 ) ;
545538 }
546- } while ( ! mreProcessExit . WaitOne ( 0 ) // If millisecondsTimeout is zero, the method does not block. It tests the state of the wait handle and returns immediately.
547- ) ;
539+ } while ( ! mreProcessExit . WaitOne ( 0 ) ) ; // If millisecondsTimeout is zero, the method does not block. It tests the state of the wait handle and returns immediately.
548540 }
549541 catch ( Exception ex )
550542 {
@@ -598,13 +590,13 @@ private void comboBoxProcessStatus_SelectedIndexChanged(object sender, EventArgs
598590 switch ( strSelected )
599591 {
600592 case "Stopped" :
601- if ( ActionWorker . IsBusy )
593+ if ( actionWorker . IsBusy )
602594 {
603595 comboBoxProcessStatus . SelectedIndex = comboBoxProcessStatus . FindStringExact ( "Running" ) ;
604596 }
605597 break ;
606598 case "Abort" :
607- ActionWorker . CancelAsync ( ) ;
599+ actionWorker . CancelAsync ( ) ;
608600 Log . Info ( "Cancelling the running process..." ) ;
609601 break ;
610602 }
@@ -614,13 +606,5 @@ private void LiveRunLogControl_Resize(object sender, EventArgs e)
614606 {
615607 toolStripProgressBar1 . Width = 100 ;
616608 }
617-
618-
619- // ReSharper disable UnusedMember.Global
620- // This is used by the logging to force all to the output window
621- public static void LogMethod ( string levelUppercase , string message )
622- {
623- ListBoxLog ? . LogMethod ( levelUppercase , message ) ;
624- }
625609 }
626610}
0 commit comments