Skip to content

Commit

Permalink
Autoupdater.NET
Browse files Browse the repository at this point in the history
Pptimized estimation prediction
Fixed bug with source selection availability
Fixed parsing raw output regex bug
Partial raw output localization
light UI improvements
  • Loading branch information
uom42 committed Dec 4, 2023
1 parent a59b784 commit fcd5f73
Show file tree
Hide file tree
Showing 30 changed files with 1,600 additions and 355 deletions.
48 changes: 48 additions & 0 deletions SDeleteGUI/Core/ListBoxEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ public ListBoxEx() : base()
this.SetStyle(ControlStyles.EnableNotifyMessage, true);
}


protected override CreateParams CreateParams
{
get
{
const int WS_EX_COMPOSITED = 0x02000000;
CreateParams cp = base.CreateParams;
//cp.ExStyle |= WS_EX_COMPOSITED;
return cp;
}
}


protected override void OnNotifyMessage(Message m)
{
//Filter out the WM_ERASEBKGND message
Expand All @@ -39,5 +52,40 @@ protected override void OnPaintBackground(PaintEventArgs pevent)
}



private void LockWindow(Control ctl)
{
// DIALOG SEND ghDlg, %WM_SETREDRAW,%FALSE,0 'do not allow messages
uom.WinAPI.Windows.SendMessage(ctl.Handle, uom.WinAPI.Windows.WindowMessages.WM_SETREDRAW, (int)0, 0);
ClearBuffers();
}

private void UnlockWindow(Control ctl)
{
ClearBuffers();//do not use DIALOG ENABLE or DIALOG DISABLE
uom.WinAPI.Windows.SendMessage(ctl.Handle, uom.WinAPI.Windows.WindowMessages.WM_SETREDRAW, (int)-1, 0);
/*
DIALOG SEND ghDlg, % WM_SETREDRAW,% TRUE,0 'allow messages
DIALOG REDRAW ghDlg 'required for scrollbars to refresh
*/

//RedrawWindow(hWnd, NULL, NULL, RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN) для перерисовки списка.
}

private void ClearBuffers()
{
//http://stackoverflow.com/questions/2400332/how-to-clear-mouse-click-buffer


//call just before exit sub/function to prevent re-entry by stray input
/*
LOCAL SystemMsg AS TagMsg
WHILE PeekMessage(SystemMsg,% NULL,% WM_KEYFIRST,% WM_KEYLAST, % PM_REMOVE OR % PM_NOYIELD):WEND
WHILE PeekMessage(SystemMsg,% NULL,% WM_MOUSEFIRST,% WM_MOUSELAST, % PM_REMOVE OR % PM_NOYIELD) :WEND
*/
}


}
}
107 changes: 107 additions & 0 deletions SDeleteGUI/Core/SDelete/DataReceivedEventArgsEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#nullable enable


namespace SDeleteGUI.Core.SDelete
{

internal class DataReceivedEventArgsEx : System.EventArgs
{

#region OutputLocalization


private const string C_METHOD_TryParse = "TryParse";
//Get all classes from 'SDeleteGUI.Core.SDelete.OutputLocalization' namespace which have static|public TryParse() method
private static Lazy<MethodInfo[]> _localizedOutputParsers = new(() =>
Assembly
.GetExecutingAssembly()
.GetTypes()
.Where(
t =>
t.Namespace == typeof(OutputLocalization.Progress_BaseEventArgs).Namespace
&& !t.IsAbstract
&& t.GetMember(C_METHOD_TryParse, BindingFlags.Static | BindingFlags.Public).Any()
)
.Select(t => (System.Reflection.MethodInfo)t.GetMember(C_METHOD_TryParse, BindingFlags.Static | BindingFlags.Public).First())
.ToArray());

#endregion


public DateTime Timestamp { get; private set; } = DateTime.Now;
public readonly string RAWData = string.Empty;


public DataReceivedEventArgsEx(string data) : base()
{
this.RAWData = data;
}


public void UpdateTimestamp(DateTime newTimestamp)
{
Timestamp = newTimestamp;
RecalculateEstimation();
}


protected virtual void RecalculateEstimation() { }


public override string ToString() => RAWData;


public static DataReceivedEventArgsEx Parse(DataReceivedEventArgs e)
{
string rawDada = e.Data;

#if DEBUG
Debug.Write($"Parsing RAW '{rawDada}'... ");
#endif
DataReceivedEventArgsEx? dreax = null;
try
{

var lop = _localizedOutputParsers.Value;
foreach (var miTryParse in lop)
{
var input = new object[] { rawDada, null };
if ((bool)miTryParse.Invoke(null, input))
{
dreax = (DataReceivedEventArgsEx)input[1];
break;
}
}

/* OLD
if (OutputLocalization.Header_CleaningPhyDiskEventArgs.TryParse(rawDada, out var hdr_pd))
dreax = hdr_pd;
else if (OutputLocalization.Header_PassInfoEventArgs.TryParse(rawDada, out var hdr_pi))
dreax = hdr_pi;
else if (OutputLocalization.Progress_VolumeFreeSpace_ZeroingFreeSpace.TryParse(rawDada, out var vol_pi))
dreax = vol_pi;
else if (OutputLocalization.Progress_PhyDisk_ProgressEventArgs.TryParse(rawDada, out var pri))
dreax = pri;
*/

}
catch (Exception ex)
{
#if DEBUG
Debug.WriteLine($"*** ERROR DataReceivedEventArgsEx.Parse: {ex}");
#endif
}

dreax ??= new DataReceivedEventArgsEx(rawDada);
#if DEBUG
Debug.WriteLine(dreax.ToString());
#endif
return dreax!;
}
}





}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#nullable enable

namespace SDeleteGUI.Core.SDelete.OutputLocalization
{
internal class Header_CleaningPhyDiskEventArgs : DataReceivedEventArgsEx
{

private const string C_PREFIX = "Cleaning disk ";

//Cleaning disk 6:
private static readonly Regex _rx = new(@"Cleaning \s disk \s (?<DiskNumber>\d+)\:",
RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline);


public readonly uint DiskNumber;


internal Header_CleaningPhyDiskEventArgs(string raw, uint passCount) : base(raw) => DiskNumber = passCount;


public static bool TryParse(string raw, out Header_CleaningPhyDiskEventArgs? piea)
{
piea = null;

if (!raw.StartsWith(C_PREFIX, StringComparison.InvariantCultureIgnoreCase)) return false;

Match? mx = _rx.Match(raw.Trim());
if (!mx?.Success ?? false) return false;

GroupCollection rGroups = mx!.Groups;
piea = new(raw, uint.Parse(rGroups["DiskNumber"].Value));
return true;
}


public override string ToString()
{
string localizedFormat = Localization.Strings.M_OUTPUT_LOCALIZATION_PHY_DISK_NO;

return localizedFormat.e_IsNullOrWhiteSpace()
? RAWData
: localizedFormat.e_Format(DiskNumber);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#nullable enable

namespace SDeleteGUI.Core.SDelete.OutputLocalization
{
internal class Header_PassInfoEventArgs : DataReceivedEventArgsEx
{

private const string C_PREFIX = "SDelete is set for ";

//SDelete is set for 1 pass.
private static readonly Regex _rx = new(@".+ set \s for \s (?<PassCount>\d+) \s pass",
RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline);


public readonly uint PassCount;


internal Header_PassInfoEventArgs(string raw, uint passCount) : base(raw) => PassCount = passCount;


public static bool TryParse(string raw, out Header_PassInfoEventArgs? piea)
{
piea = null;

if (!raw.StartsWith(C_PREFIX, StringComparison.InvariantCultureIgnoreCase)) return false;

Match? mx = _rx.Match(raw.Trim());
if (!mx?.Success ?? false) return false;

GroupCollection rGroups = mx!.Groups;
piea = new(raw, uint.Parse(rGroups["PassCount"].Value));
return true;
}


public override string ToString()
{
string localizedFormat = Localization.Strings.M_OUTPUT_LOCALIZATION_PASS_COUNT;

return localizedFormat.e_IsNullOrWhiteSpace()
? RAWData
: localizedFormat.e_Format(PassCount);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#nullable enable

namespace SDeleteGUI.Core.SDelete.OutputLocalization
{
internal abstract class Progress_BaseEventArgs : DataReceivedEventArgsEx
{
public readonly uint CurrentOperationProgressPercent;

internal Progress_BaseEventArgs(string raw, uint currentOperationProgressPercent) : base(raw)
=> CurrentOperationProgressPercent = currentOperationProgressPercent;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#nullable enable

namespace SDeleteGUI.Core.SDelete.OutputLocalization
{

/*
T:\file.txt...deleted.
T:\folder...deleted.
*/
internal class Progress_DirOrFile_Deleted : DataReceivedEventArgsEx
{
private const string C_SUFFIX = "...deleted.";

public readonly string FileSystemObject;


internal Progress_DirOrFile_Deleted(string raw, string fileSystemObject) : base(raw)
=> FileSystemObject = fileSystemObject;


public static bool TryParse(string raw, out Progress_DirOrFile_Deleted? piea)
{
piea = null;

if (!(raw.EndsWith(C_SUFFIX, StringComparison.InvariantCultureIgnoreCase) && (raw.Length >= C_SUFFIX.Length))) return false;
string fileSystemObject = raw.Substring(0, raw.Length - C_SUFFIX.Length);

piea = new(raw, fileSystemObject);
return true;
}


public override string ToString()
{
string localizedFormat = Localization.Strings.M_OUTPUT_LOCALIZATION_FSO_DELETED;

return localizedFormat.e_IsNullOrWhiteSpace()
? RAWData
: localizedFormat.e_Format(FileSystemObject);
}
}
}
Loading

0 comments on commit fcd5f73

Please sign in to comment.