Skip to content

Commit bb675c1

Browse files
committed
- Update to the latest NuGet Packages
- Update the (c) year - Move logging into a seperate window - Implement methods to populate the Recovery tree - Fix #68: Implement recovery of listed files (If possible and taking into -a option)
1 parent 91273f6 commit bb675c1

35 files changed

Lines changed: 1151 additions & 824 deletions

Elucidate/Elucidate/Controls/ListBoxLog.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,10 @@ private void timer1_Tick(object sender, EventArgs e)
230230
return;
231231
}
232232

233-
alreadyDequing = true;
234233
// Now lock in case the timer is overlapping !
235-
listBoxInt.BeginInvoke((MethodInvoker)delegate
234+
alreadyDequing = true;
235+
236+
listBoxInt.BeginInvoke((MethodInvoker) delegate
236237
{
237238
//some stuffs for best performance
238239
listBoxInt.BeginUpdate();
@@ -254,7 +255,6 @@ private void timer1_Tick(object sender, EventArgs e)
254255
}
255256

256257
listBoxInt.EndUpdate();
257-
//}
258258
alreadyDequing = false;
259259
}
260260
);

Elucidate/Elucidate/Controls/LiveRunLogControl.Designer.cs

Lines changed: 38 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Elucidate/Elucidate/Controls/LiveRunLogControl.cs

Lines changed: 37 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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
@@ -27,18 +27,19 @@
2727
using System.ComponentModel;
2828
using System.Diagnostics;
2929
using System.Drawing;
30-
using System.Linq;
3130
using System.Text;
3231
using System.Threading;
3332
using System.Windows.Forms;
33+
3434
using ComponentFactory.Krypton.Toolkit;
35+
3536
using Elucidate.wyDay.Controls;
3637

3738
using NLog;
3839

3940
namespace 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
}

Elucidate/Elucidate/TabPages/LogsViewerControl.Designer.cs renamed to Elucidate/Elucidate/Controls/LogsViewerControl.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Elucidate/Elucidate/TabPages/LogsViewerControl.cs renamed to Elucidate/Elucidate/Controls/LogsViewerControl.cs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// ---------------------------------------------------------------------------------------------------------------
33
// <copyright file="LogsViewerControl.cs" company="Smurf-IV">
44
//
5-
// Copyright (C) 2018-2019 Simon Coghlan (Aka Smurf-IV) & BlueBlock 2018
5+
// Copyright (C) 2018-2020 Simon Coghlan (Aka Smurf-IV) & BlueBlock 2018
66
//
77
// This program is free software: you can redistribute it and/or modify
88
// it under the terms of the GNU General Public License as published by
@@ -26,14 +26,15 @@
2626

2727
using System;
2828
using System.Collections.Generic;
29+
using System.Diagnostics;
2930
using System.IO;
3031
using System.Linq;
3132
using System.Windows.Forms;
3233

3334
using NLog;
3435
using NLog.Targets;
3536

36-
namespace Elucidate.TabPages
37+
namespace Elucidate.Controls
3738
{
3839
public partial class LogsViewerControl : UserControl
3940
{
@@ -239,5 +240,44 @@ private void checkedFilesWithWarn_CheckedChanged(object sender, EventArgs e)
239240
listBoxViewLogFiles.BeginInvoke((MethodInvoker)delegate { UpdateLogFileList(comboBoxLogType.SelectedItem.ToString()); });
240241
}
241242

243+
private void logViewToolStripMenuItem_Click(object sender, EventArgs e)
244+
{
245+
// if (_liveRunLogControl.ActionWorker.IsBusy) { return; }
246+
247+
string userAppData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"Elucidate");
248+
249+
OpenFileDialog openFileDialog = new OpenFileDialog
250+
{
251+
InitialDirectory = Path.Combine(userAppData, @"Logs"),
252+
Filter = @"Log files (*.log)|*.log|Archive logs (*.*)|*.*",
253+
FileName = "*.log",
254+
FilterIndex = 2,
255+
Title = @"Select name to view contents"
256+
};
257+
258+
if (openFileDialog.ShowDialog() != DialogResult.OK)
259+
{
260+
return;
261+
}
262+
263+
if (Properties.Settings.Default.UseWindowsSettings)
264+
{
265+
Process word = Process.Start("Wordpad.exe", '"' + openFileDialog.FileName + '"');
266+
if (word == null)
267+
{
268+
return;
269+
}
270+
271+
word.WaitForInputIdle();
272+
SendKeys.SendWait("^{END}");
273+
}
274+
else
275+
{
276+
// Launch whatever "Knows" how to view log files
277+
Process.Start('"' + openFileDialog.FileName + '"');
278+
}
279+
}
280+
281+
242282
}
243283
}
File renamed without changes.

Elucidate/Elucidate/Controls/ProtectedDrivesDisplay.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
1-
using System;
1+
#region Copyright (C)
2+
// <copyright file="ProtectedDrivesDisplay.cs" company="Smurf-IV">
3+
//
4+
// Copyright (C) 2019-2020 Smurf-IV
5+
//
6+
// This program is free software: you can redistribute it and/or modify
7+
// it under the terms of the GNU General Public License as published by
8+
// the Free Software Foundation, either version 2 of the License, or
9+
// any later version.
10+
//
11+
// This program is distributed in the hope that it will be useful,
12+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
// GNU General Public License for more details.
15+
//
16+
// You should have received a copy of the GNU General Public License
17+
// along with this program. If not, see http://www.gnu.org/licenses/.
18+
// </copyright>
19+
// <summary>
20+
// Url: https://github.com/Smurf-IV/Elucidate
21+
// Email: https://github.com/Smurf-IV
22+
// </summary>
23+
#endregion Copyright (C)
24+
25+
using System;
226
using System.Collections.Generic;
327
using System.Linq;
428
using System.Threading;
@@ -24,8 +48,8 @@ internal partial class ProtectedDrivesDisplay : UserControl
2448

2549
internal ProtectedDrivesDisplay()
2650
{
27-
cancelTokenSrc = new CancellationTokenSource();
2851
InitializeComponent();
52+
cancelTokenSrc = new CancellationTokenSource();
2953
}
3054

3155
internal void StopProcessing()

0 commit comments

Comments
 (0)