Skip to content

Commit

Permalink
- Update to the latest NuGet Packages
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
Smurf-IV committed Jul 4, 2020
1 parent 91273f6 commit bb675c1
Show file tree
Hide file tree
Showing 35 changed files with 1,151 additions and 824 deletions.
6 changes: 3 additions & 3 deletions Elucidate/Elucidate/Controls/ListBoxLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,10 @@ private void timer1_Tick(object sender, EventArgs e)
return;
}

alreadyDequing = true;
// Now lock in case the timer is overlapping !
listBoxInt.BeginInvoke((MethodInvoker)delegate
alreadyDequing = true;

listBoxInt.BeginInvoke((MethodInvoker) delegate
{
//some stuffs for best performance
listBoxInt.BeginUpdate();
Expand All @@ -254,7 +255,6 @@ private void timer1_Tick(object sender, EventArgs e)
}

listBoxInt.EndUpdate();
//}
alreadyDequing = false;
}
);
Expand Down
91 changes: 38 additions & 53 deletions Elucidate/Elucidate/Controls/LiveRunLogControl.Designer.cs

Large diffs are not rendered by default.

90 changes: 37 additions & 53 deletions Elucidate/Elucidate/Controls/LiveRunLogControl.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#region Copyright (C)
// <copyright file="ConfigFileHelper.cs" company="Smurf-IV">
// <copyright file="RunControl.cs" company="Smurf-IV">
//
// Copyright (C) 2018-2019 Smurf-IV & BlueBlock
// Copyright (C) 2018-2020 Smurf-IV & BlueBlock 2018
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand All @@ -27,18 +27,19 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;

using ComponentFactory.Krypton.Toolkit;

using Elucidate.wyDay.Controls;

using NLog;

namespace Elucidate.Controls
{
public partial class LiveRunLogControl : UserControl
public partial class RunControl : UserControl
{
private static readonly Logger Log = LogManager.GetCurrentClassLogger();

Expand All @@ -55,22 +56,16 @@ public partial class LiveRunLogControl : UserControl
private readonly ManualResetEvent mreErrorDone = new ManualResetEvent(false);
private ProcessPriorityClass requested = ProcessPriorityClass.Normal;
private string lastError;
private List<string> batchPaths;
private static ListBoxLog ListBoxLog;
private Stack<string> batchPaths;

public bool IsRunning { get; set; }
public bool IsRunning { get; private set; }

private CommandType CommandTypeRunning { get; set; }
public CommandType CommandTypeRunning { get; private set; }

public LiveRunLogControl()
public RunControl()
{
InitializeComponent();

if (ListBoxLog == null)
{
ListBoxLog = new ListBoxLog(rtbLiveLog);
}

AddThreadingCallbacks();

toolStripStatusLabel1.Text = DateTime.Now.ToString("u");
Expand Down Expand Up @@ -113,8 +108,7 @@ public enum CommandType
Scrub,
Fix,
Dup,
QuickCheck,
RecoverCheck,
CheckForMissing,
RecoverFix,
ForceFullSync
}
Expand All @@ -123,28 +117,23 @@ private void LiveRunLogControl_Load(object sender, EventArgs e)
{
}

public void HideAdditionalCommands()
{
tableLayoutPanelAdditionalCommands.Visible = false;
}

public readonly BackgroundWorker ActionWorker = new BackgroundWorker
private readonly BackgroundWorker actionWorker = new BackgroundWorker
{
WorkerReportsProgress = true,
WorkerSupportsCancellation = true,
WorkerSupportsCancellation = true
};

private void AddThreadingCallbacks()
{
// Add threading callbacks
ActionWorker.DoWork += actionWorker_DoWork;
ActionWorker.ProgressChanged += actionWorker_ProgressChanged;
ActionWorker.RunWorkerCompleted += actionWorker_RunWorkerCompleted;
actionWorker.DoWork += actionWorker_DoWork;
actionWorker.ProgressChanged += actionWorker_ProgressChanged;
actionWorker.RunWorkerCompleted += actionWorker_RunWorkerCompleted;
comboBoxProcessStatus.Text = @"Stopped";
comboBoxProcessStatus.Enabled = false;
}

internal void StartSnapRaidProcess(CommandType commandToRun, List<string> paths = null)
internal void StartSnapRaidProcess(CommandType commandToRun, Stack<string> paths = null)
{
if (IsRunning)
{
Expand All @@ -165,13 +154,13 @@ internal void StartSnapRaidProcess(CommandType commandToRun, List<string> paths
case CommandType.Diff:
command.Append(@"diff");
break;
case CommandType.QuickCheck:
case CommandType.CheckForMissing:
command.Append(@"check");
defaultOption = @" -a";
defaultOption = @" -m";
break;
case CommandType.Check:
case CommandType.RecoverCheck:
command.Append(@"check");
defaultOption = @" -a";
break;
case CommandType.Sync:
command.Append(@"sync");
Expand Down Expand Up @@ -225,7 +214,7 @@ internal void StartSnapRaidProcess(CommandType commandToRun, List<string> paths

requested = ProcessPriorityClass.Normal;

ActionWorker.RunWorkerAsync(command.ToString());
actionWorker.RunWorkerAsync(command.ToString());

toolStripProgressBar1.DisplayText = "Running...";

Expand All @@ -243,10 +232,6 @@ private void actionWorker_DoWork(object sender, DoWorkEventArgs e)
{
try
{
IsRunning = true;

OnTaskStarted(e);

BackgroundWorker worker = sender as BackgroundWorker;

string command = e.Argument as string;
Expand All @@ -273,6 +258,10 @@ private void actionWorker_DoWork(object sender, DoWorkEventArgs e)

string args = Util.FormatSnapRaidCommandArgs( command, out string appPath);

IsRunning = true;

OnTaskStarted(e);

RunSnapRaid(e, args, appPath, worker);
}
catch (Exception ex)
Expand All @@ -294,9 +283,11 @@ private void RunSnapRaid(DoWorkEventArgs e, string args, string appPath, Backgro

do
{
sbPaths.Append($"-f \"{batchPaths[batchPaths.Count - 1]}\" ");
batchPaths.RemoveAt(batchPaths.Count - 1);
} while (sbPaths.Length < MAX_COMMAND_ARG_LENGTH && batchPaths.Any());
var restore = batchPaths.Pop();
sbPaths.Append(" -f \"").Append(restore).Append("\"");
} while ((sbPaths.Length < MAX_COMMAND_ARG_LENGTH)
&& (batchPaths.Count > 0)
);

args += sbPaths.ToString();
}
Expand Down Expand Up @@ -427,9 +418,8 @@ private void actionWorker_ProgressChanged(object sender, ProgressChangedEventArg
private void actionWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
IsRunning = false;

// continue running additional times if there is more work to be done
if (CommandTypeRunning == CommandType.RecoverFix && batchPaths.Any())
if (CommandTypeRunning == CommandType.RecoverFix && (batchPaths.Count > 0))
{
StartSnapRaidProcess(CommandType.RecoverFix);
return;
Expand Down Expand Up @@ -468,7 +458,10 @@ private void actionWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEv
comboBoxProcessStatus.Text = @"Stopped";
}

if (CommandTypeRunning == CommandType.RecoverCheck || CommandTypeRunning == CommandType.RecoverFix)
if (CommandTypeRunning == CommandType.Check
|| CommandTypeRunning == CommandType.CheckForMissing
|| CommandTypeRunning == CommandType.RecoverFix
)
{
toolStripProgressBar1.State = ProgressBarState.Normal;
toolStripProgressBar1.DisplayText = "Completed";
Expand Down Expand Up @@ -543,8 +536,7 @@ private void ReadStandardOutput(ThreadObject threadObject)
// SnapRaid dumps a null length when drawing graphs etc. So need to check if still running..
mreProcessExit.WaitOne(100);
}
} while (!mreProcessExit.WaitOne(0) // If millisecondsTimeout is zero, the method does not block. It tests the state of the wait handle and returns immediately.
);
} while (!mreProcessExit.WaitOne(0)); // If millisecondsTimeout is zero, the method does not block. It tests the state of the wait handle and returns immediately.
}
catch (Exception ex)
{
Expand Down Expand Up @@ -598,13 +590,13 @@ private void comboBoxProcessStatus_SelectedIndexChanged(object sender, EventArgs
switch (strSelected)
{
case "Stopped":
if (ActionWorker.IsBusy)
if (actionWorker.IsBusy)
{
comboBoxProcessStatus.SelectedIndex = comboBoxProcessStatus.FindStringExact("Running");
}
break;
case "Abort":
ActionWorker.CancelAsync();
actionWorker.CancelAsync();
Log.Info("Cancelling the running process...");
break;
}
Expand All @@ -614,13 +606,5 @@ private void LiveRunLogControl_Resize(object sender, EventArgs e)
{
toolStripProgressBar1.Width = 100;
}


// ReSharper disable UnusedMember.Global
// This is used by the logging to force all to the output window
public static void LogMethod(string levelUppercase, string message)
{
ListBoxLog?.LogMethod(levelUppercase, message);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ---------------------------------------------------------------------------------------------------------------
// <copyright file="LogsViewerControl.cs" company="Smurf-IV">
//
// Copyright (C) 2018-2019 Simon Coghlan (Aka Smurf-IV) & BlueBlock 2018
// Copyright (C) 2018-2020 Simon Coghlan (Aka Smurf-IV) & BlueBlock 2018
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand All @@ -26,14 +26,15 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;

using NLog;
using NLog.Targets;

namespace Elucidate.TabPages
namespace Elucidate.Controls
{
public partial class LogsViewerControl : UserControl
{
Expand Down Expand Up @@ -239,5 +240,44 @@ private void checkedFilesWithWarn_CheckedChanged(object sender, EventArgs e)
listBoxViewLogFiles.BeginInvoke((MethodInvoker)delegate { UpdateLogFileList(comboBoxLogType.SelectedItem.ToString()); });
}

private void logViewToolStripMenuItem_Click(object sender, EventArgs e)
{
// if (_liveRunLogControl.ActionWorker.IsBusy) { return; }

string userAppData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"Elucidate");

OpenFileDialog openFileDialog = new OpenFileDialog
{
InitialDirectory = Path.Combine(userAppData, @"Logs"),
Filter = @"Log files (*.log)|*.log|Archive logs (*.*)|*.*",
FileName = "*.log",
FilterIndex = 2,
Title = @"Select name to view contents"
};

if (openFileDialog.ShowDialog() != DialogResult.OK)
{
return;
}

if (Properties.Settings.Default.UseWindowsSettings)
{
Process word = Process.Start("Wordpad.exe", '"' + openFileDialog.FileName + '"');
if (word == null)
{
return;
}

word.WaitForInputIdle();
SendKeys.SendWait("^{END}");
}
else
{
// Launch whatever "Knows" how to view log files
Process.Start('"' + openFileDialog.FileName + '"');
}
}


}
}
28 changes: 26 additions & 2 deletions Elucidate/Elucidate/Controls/ProtectedDrivesDisplay.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
using System;
#region Copyright (C)
// <copyright file="ProtectedDrivesDisplay.cs" company="Smurf-IV">
//
// Copyright (C) 2019-2020 Smurf-IV
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
// </copyright>
// <summary>
// Url: https://github.com/Smurf-IV/Elucidate
// Email: https://github.com/Smurf-IV
// </summary>
#endregion Copyright (C)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
Expand All @@ -24,8 +48,8 @@ internal partial class ProtectedDrivesDisplay : UserControl

internal ProtectedDrivesDisplay()
{
cancelTokenSrc = new CancellationTokenSource();
InitializeComponent();
cancelTokenSrc = new CancellationTokenSource();
}

internal void StopProcessing()
Expand Down
Loading

0 comments on commit bb675c1

Please sign in to comment.