Skip to content

Commit

Permalink
Version 2019.5.1.1000, better cleanup percentage details, return valu…
Browse files Browse the repository at this point in the history
…e handling fixes
  • Loading branch information
thebookisclosed committed May 1, 2019
1 parent 456db6f commit 97287bd
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 34 deletions.
4 changes: 2 additions & 2 deletions Comet/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2019.4.19.1001")]
[assembly: AssemblyFileVersion("2019.4.19.1001")]
[assembly: AssemblyVersion("2019.5.1.1000")]
[assembly: AssemblyFileVersion("2019.5.1.1000")]
91 changes: 60 additions & 31 deletions Comet/UI/Cleaner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ public partial class Cleaner : Form
{
private Thread HandlerThread;
private long TotalBytesDeleted;
private int LastPercent;
private int LastTotalPercent;
private EmptyVolumeCacheCallBacks CallBacks;
private bool ProcessingHandlers;
private int LastHandlerPercent;
private CleanupHandler CurrentHandler;

public Cleaner()
{
InitializeComponent();
Icon = Properties.Resources.full;
PtbLogo.Image = Icon.ToBitmap();
LblClnUp.Text += Preferences.SelectedDrive.Name;
LblHandler.Text = Preferences.CleanupHandlers[0].DisplayName;
LblHandler.Text = $"{Preferences.CleanupHandlers[0].DisplayName} (Preparing...)";
HandlerThread = new Thread(new ThreadStart(() => {
Api.ReinstateHandlers(Preferences.CleanupHandlers, Preferences.SelectedDrive.Letter);
// Set up a callback for progress reporting
Expand All @@ -31,29 +33,32 @@ public Cleaner()
ProcessingHandlers = true;
for (int i = 0; i < Preferences.CleanupHandlers.Count; i++)
{
CleanupHandler oHandler = Preferences.CleanupHandlers[i];
if (oHandler.PreProcHint != null)
RunProcHint(oHandler.PreProcHint);
if (LblHandler.IsHandleCreated)
CurrentHandler = Preferences.CleanupHandlers[i];
if (CurrentHandler.PreProcHint != null)
RunProcHint(CurrentHandler.PreProcHint);
LastHandlerPercent = 0;
if (i > 0 && LblHandler.IsHandleCreated)
Invoke((MethodInvoker)delegate {
LblHandler.Text = oHandler.DisplayName;
LblHandler.Text = $"{CurrentHandler.DisplayName} (Preparing...)";
});
int spaceResult = oHandler.Instance.GetSpaceUsed(out long newSpaceUsed, CallBacks);
if (spaceResult == -2147467260) // -2147467260 = 0x80004004 = E_ABORT
break;
else if (spaceResult == 0)
int spaceResult = CurrentHandler.Instance.GetSpaceUsed(out long newSpaceUsed, CallBacks);
if (spaceResult >= 0)
{
Preferences.CurrentSelectionSavings = Preferences.CurrentSelectionSavings - oHandler.BytesUsed + newSpaceUsed;
int purgeResult = oHandler.Instance.Purge(newSpaceUsed, CallBacks);
Preferences.CurrentSelectionSavings = Preferences.CurrentSelectionSavings - CurrentHandler.BytesUsed + newSpaceUsed;
CurrentHandler.BytesUsed = newSpaceUsed;
ReportLastHandlerPercent();
int purgeResult = CurrentHandler.Instance.Purge(CurrentHandler.BytesUsed, CallBacks);
if (purgeResult == -2147467260) // -2147467260 = 0x80004004 = E_ABORT
break;
if (purgeResult != 0 && purgeResult != -2147287022) // -2147287022 == 0x80030012 == STG_E_NOMOREFILES
MessageBox.Show("Purging " + oHandler.DisplayName + " failed with error 0x" + purgeResult.ToString("x8"), Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
if (oHandler.PostProcHint != null)
RunProcHint(oHandler.PostProcHint);
if (purgeResult < 0 && purgeResult != -2147287022) // -2147287022 == 0x80030012 == STG_E_NOMOREFILES
MessageBox.Show("Purging " + CurrentHandler.DisplayName + " failed with error 0x" + purgeResult.ToString("x8"), Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
if (CurrentHandler.PostProcHint != null)
RunProcHint(CurrentHandler.PostProcHint);
}
try { oHandler.Instance.Deactivate(out uint dummy); } catch { }
Marshal.FinalReleaseComObject(oHandler.Instance);
try { CurrentHandler.Instance.Deactivate(out uint dummy); } catch { }
Marshal.FinalReleaseComObject(CurrentHandler.Instance);
if (spaceResult < 0)
break;
}
ProcessingHandlers = false;
Api.DeactivateHandlers(Preferences.CleanupHandlers);
Expand All @@ -68,26 +73,50 @@ public Cleaner()

private void CallBacks_PurgeProgressChanged(object sender, PurgeProgressChangedEventArgs e)
{
int cPerc = (int)((double)(TotalBytesDeleted + e.SpaceFreed) / Preferences.CurrentSelectionSavings * 100);
if (cPerc != LastPercent)
if (Preferences.CurrentSelectionSavings > 0)
{
LastPercent = cPerc;
int ctPerc = (int)((double)(TotalBytesDeleted + e.SpaceFreed) / Preferences.CurrentSelectionSavings * 100);
if (ctPerc != LastTotalPercent)
{
LastTotalPercent = ctPerc;
ReportLastTotalPercent();
}
if (CurrentHandler.BytesUsed > 0)
{
int hPerc = Preferences.CleanupHandlers.Count == 1 ? ctPerc : (int)((double)e.SpaceFreed / CurrentHandler.BytesUsed * 100);
if (hPerc != LastHandlerPercent)
{
LastHandlerPercent = hPerc;
ReportLastHandlerPercent();
}
}
if (e.Flags == CallbackFlags.LastNotification)
{
TotalBytesDeleted += CurrentHandler.BytesUsed;
LastTotalPercent = (int)((double)TotalBytesDeleted / Preferences.CurrentSelectionSavings * 100);
ReportLastTotalPercent();
}
}
}

private void ReportLastHandlerPercent()
{
if (LblHandler.IsHandleCreated)
Invoke((MethodInvoker)delegate {
PrgClean.Value = cPerc;
LblHandler.Text = $"{CurrentHandler.DisplayName} ({LastHandlerPercent}%)";
});
}
if (e.Flags == CallbackFlags.LastNotification)
{
TotalBytesDeleted += e.SpaceToFree;
LastPercent = (int)((double)TotalBytesDeleted / Preferences.CurrentSelectionSavings * 100);
}

private void ReportLastTotalPercent()
{
if (PrgClean.IsHandleCreated)
Invoke((MethodInvoker)delegate {
PrgClean.Value = LastPercent;
PrgClean.Value = LastTotalPercent;
});
}
}

// Get effective filename of process to run for pre/post cleanup actions
private static string GetFirstParam(string line)
private string GetFirstParam(string line)
{
char prevChar = '\0';
char nextChar = '\0';
Expand Down
2 changes: 1 addition & 1 deletion Comet/UI/Scanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Scanner()
PrgScan.Value = i + 1;
});
int spaceResult = evp.Instance.GetSpaceUsed(out long spaceUsed, callBacks);
if (spaceResult != 0 || (spaceUsed == 0 &&
if (spaceResult < 0 || (spaceUsed == 0 &&
((evp.Flags & HandlerFlags.DontShowIfZero) == HandlerFlags.DontShowIfZero ||
(evp.DataDrivenFlags & DDCFlags.DontShowIfZero) == DDCFlags.DontShowIfZero)))
{
Expand Down

0 comments on commit 97287bd

Please sign in to comment.