Esempio n. 1
0
 public Scanner()
 {
     InitializeComponent();
     Icon          = Properties.Resources.full;
     PtbLogo.Image = Icon.ToBitmap();
     LblIntro.Text = string.Format(LblIntro.Text, Preferences.SelectedDrive.Name);
     HandlerThread = new Thread(new ThreadStart(() => {
         Preferences.CleanupHandlers = new List <CleanupHandler>();
         using (RegistryKey rKey = Registry.LocalMachine.OpenSubKey(Api.VolumeCacheStoreKey, false))
         {
             string[] subKeyNames = rKey.GetSubKeyNames();
             // Adjust progress bar maximum to discovered handler count
             Invoke((MethodInvoker) delegate
             {
                 PrgScan.Maximum = subKeyNames.Length;
             });
             // Set up a dummy callback because COM stuff goes haywire for particular handlers if we supply none
             EmptyVolumeCacheCallBacks callBacks = new EmptyVolumeCacheCallBacks();
             for (int i = 0; i < subKeyNames.Length; i++)
             {
                 CleanupHandler evp = Api.InitializeHandler(subKeyNames[i], Preferences.SelectedDrive.Letter);
                 if (evp != null)
                 {
                     if (LblHandler.IsHandleCreated)
                     {
                         Invoke((MethodInvoker) delegate {
                             LblHandler.Text = evp.DisplayName;
                             PrgScan.Value   = i + 1;
                         });
                     }
                     int spaceResult = evp.Instance.GetSpaceUsed(out long spaceUsed, callBacks);
                     if (spaceResult < 0 || (spaceUsed == 0 &&
                                             ((evp.Flags & HandlerFlags.DontShowIfZero) == HandlerFlags.DontShowIfZero ||
                                              (evp.DataDrivenFlags & DDCFlags.DontShowIfZero) == DDCFlags.DontShowIfZero)))
                     {
                         try { evp.Instance.Deactivate(out uint dummy); } catch { }
                         Marshal.FinalReleaseComObject(evp.Instance);
                     }
                     else
                     {
                         evp.BytesUsed = spaceUsed;
                         Preferences.CleanupHandlers.Add(evp);
                     }
                 }
             }
         }
         Api.DeactivateHandlers(Preferences.CleanupHandlers);
         // Sort handlers by priority, making sure they'll run in correct order
         Preferences.CleanupHandlers.Sort((x, y) => y.Priority.CompareTo(x.Priority));
         // A (stupid?) way to close the form once we are done cleaning
         Invoke((MethodInvoker) delegate {
             Close();
         });
     }));
     HandlerThread.SetApartmentState(ApartmentState.STA);
     HandlerThread.Start();
 }
Esempio n. 2
0
 public Cleaner()
 {
     InitializeComponent();
     Icon            = Properties.Resources._1;
     PtbLogo.Image   = Icon.ToBitmap();
     LblIntro.Text   = string.Format(LblIntro.Text, Preferences.SelectedDrive.Name);
     LblHandler.Text = Preferences.CleanupHandlers[0].DisplayName;
     HandlerThread   = new Thread(new ThreadStart(() => {
         Api.ReinstateHandlers(Preferences.CleanupHandlers, Preferences.SelectedDrive.Letter);
         // Set up a callbacks for progress reporting
         EmptyVolumeCacheCallBacks callBacks = new EmptyVolumeCacheCallBacks();
         callBacks.PurgeProgressChanged     += CallBacks_PurgeProgressChanged;
         TotalBytesDeleted = 0;
         for (int i = 0; i < Preferences.CleanupHandlers.Count; i++)
         {
             CleanupHandler oHandler = Preferences.CleanupHandlers[i];
             if (oHandler.PreProcHint != null)
             {
                 RunProcHint(oHandler.PreProcHint);
             }
             if (LblHandler.IsHandleCreated)
             {
                 Invoke((MethodInvoker) delegate {
                     LblHandler.Text = oHandler.DisplayName;
                 });
             }
             try
             {
                 int purgeResult = oHandler.Instance.Purge(oHandler.BytesUsed, callBacks);
                 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);
                 }
                 try { oHandler.Instance.Deactivate(out uint dummy); } catch { }
                 Marshal.FinalReleaseComObject(oHandler.Instance);
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.ToString(), oHandler.DisplayName, MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         // A (stupid?) way to close the form once we are done cleaning
         Invoke((MethodInvoker) delegate {
             Close();
         });
     }));
     HandlerThread.SetApartmentState(ApartmentState.STA);
     HandlerThread.Start();
 }
Esempio n. 3
0
        private void Run()
        {
            lblCurrentHandler.Text = Resources.Label_Preparing.Format(Preferences.CleanupHandlers[0].DisplayName);

            _thread = new Thread(new ThreadStart(() =>
            {
                CleanupApi.ReinstateHandlers(Preferences.CleanupHandlers, Preferences.SelectedDrive.Letter);
                // Set up a callback for progress reporting
                _callBacks = new EmptyVolumeCacheCallBacks();
                _callBacks.PurgeProgressChanged += CallBacks_PurgeProgressChanged;
                _totalBytesDeleted  = 0;
                _processingHandlers = true;
                for (int i = 0; i < Preferences.CleanupHandlers.Count; i++)
                {
                    _currentHandler = Preferences.CleanupHandlers[i];
                    if (_currentHandler.PreProcHint != null)
                    {
                        RunProcHint(_currentHandler.PreProcHint);
                    }
                    _lastHandlerPercent = 0;
                    if (i > 0 && lblCurrentHandler.IsHandleCreated)
                    {
                        Invoke((MethodInvoker) delegate
                        {
                            lblCurrentHandler.Text = Resources.Label_Preparing.Format(_currentHandler.DisplayName);
                        });
                    }
                    int spaceResult = _currentHandler.Instance.GetSpaceUsed(out long newSpaceUsed, _callBacks);
                    if (spaceResult >= 0)
                    {
                        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 " + _currentHandler.DisplayName + " failed with error 0x" + purgeResult.ToString("x8"), Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        if (_currentHandler.PostProcHint != null)
                        {
                            RunProcHint(_currentHandler.PostProcHint);
                        }
                    }
                    try { _currentHandler.Instance.Deactivate(out uint dummy); } catch { }
                    Marshal.FinalReleaseComObject(_currentHandler.Instance);
                    if (spaceResult < 0)
                    {
                        break;
                    }
                }
                _processingHandlers = false;
                CleanupApi.DeactivateHandlers(Preferences.CleanupHandlers);
                // A (stupid?) way to close the form once we are done cleaning
                Invoke((MethodInvoker) delegate
                {
                    Close();
                });
            }));

            _thread.SetApartmentState(ApartmentState.STA);
            _thread.Start();
        }
Esempio n. 4
0
        // Methods

        private void Run()
        {
            _thread = new Thread(new ThreadStart(() =>
            {
                Preferences.CleanupHandlers = new List <CleanupHandler>();
                using (var registryKey = Registry.LocalMachine.OpenSubKey(CleanupApi.VolumeCacheStoreKey, false))
                {
                    var subKeyNames = registryKey.GetSubKeyNames();

                    // Adjust progress bar maximum to discovered handler count
                    Invoke((MethodInvoker) delegate
                    {
                        pgrScanning.Maximum = subKeyNames.Length;
                    });

                    // Set up a dummy callback because COM stuff goes haywire for particular handlers if we supply none
                    var callBacks = new EmptyVolumeCacheCallBacks();

                    for (var i = 0; i < subKeyNames.Length; i++)
                    {
                        var cleanupHandler = CleanupApi.InitializeHandler(subKeyNames[i], Preferences.SelectedDrive.Letter);
                        if (cleanupHandler != null)
                        {
                            if (lblCurrentHandler.IsHandleCreated)
                            {
                                Invoke((MethodInvoker) delegate
                                {
                                    lblCurrentHandler.Text = cleanupHandler.DisplayName;
                                    pgrScanning.Value      = i + 1;
                                });
                            }

                            var spaceResult = cleanupHandler.Instance.GetSpaceUsed(out long spaceUsed, callBacks);
                            if (spaceResult < 0 || (spaceUsed == 0 &&
                                                    ((cleanupHandler.Flags & HandlerFlags.DontShowIfZero) == HandlerFlags.DontShowIfZero ||
                                                     (cleanupHandler.DataDrivenFlags & DDCFlags.DontShowIfZero) == DDCFlags.DontShowIfZero)))
                            {
                                try { cleanupHandler.Instance.Deactivate(out uint dummy); } catch { }
                                Marshal.FinalReleaseComObject(cleanupHandler.Instance);
                            }
                            else
                            {
                                cleanupHandler.BytesUsed = spaceUsed;
                                Preferences.CleanupHandlers.Add(cleanupHandler);
                            }
                        }
                    }
                }

                CleanupApi.DeactivateHandlers(Preferences.CleanupHandlers);

                // Sort handlers by priority, making sure they'll run in correct order
                Preferences.CleanupHandlers.Sort((x, y) => y.Priority.CompareTo(x.Priority));


                // A (stupid?) way to close the form once we are done cleaning

                Invoke((MethodInvoker) delegate
                {
                    Close();
                });
            }));

            _thread.SetApartmentState(ApartmentState.STA);
            _thread.Start();
        }
Esempio n. 5
0
 public Cleaner()
 {
     InitializeComponent();
     Icon            = Properties.Resources.full;
     PtbLogo.Image   = Icon.ToBitmap();
     LblClnUp.Text  += Preferences.SelectedDrive.Name;
     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
         CallBacks = new EmptyVolumeCacheCallBacks();
         CallBacks.PurgeProgressChanged += CallBacks_PurgeProgressChanged;
         TotalBytesDeleted  = 0;
         ProcessingHandlers = true;
         for (int i = 0; i < Preferences.CleanupHandlers.Count; i++)
         {
             CurrentHandler = Preferences.CleanupHandlers[i];
             if (CurrentHandler.PreProcHint != null)
             {
                 RunProcHint(CurrentHandler.PreProcHint);
             }
             LastHandlerPercent = 0;
             if (i > 0 && LblHandler.IsHandleCreated)
             {
                 Invoke((MethodInvoker) delegate {
                     LblHandler.Text = $"{CurrentHandler.DisplayName} (Preparing...)";
                 });
             }
             int spaceResult = CurrentHandler.Instance.GetSpaceUsed(out long newSpaceUsed, CallBacks);
             if (spaceResult >= 0)
             {
                 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 " + CurrentHandler.DisplayName + " failed with error 0x" + purgeResult.ToString("x8"), Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
                 if (CurrentHandler.PostProcHint != null)
                 {
                     RunProcHint(CurrentHandler.PostProcHint);
                 }
             }
             try { CurrentHandler.Instance.Deactivate(out uint dummy); } catch { }
             Marshal.FinalReleaseComObject(CurrentHandler.Instance);
             if (spaceResult < 0)
             {
                 break;
             }
         }
         ProcessingHandlers = false;
         Api.DeactivateHandlers(Preferences.CleanupHandlers);
         // A (stupid?) way to close the form once we are done cleaning
         Invoke((MethodInvoker) delegate {
             Close();
         });
     }));
     HandlerThread.SetApartmentState(ApartmentState.STA);
     HandlerThread.Start();
 }