Skip to content

Commit

Permalink
Last fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hxseven committed Mar 11, 2012
1 parent e8a0f25 commit 81a1baf
Show file tree
Hide file tree
Showing 19 changed files with 607 additions and 689 deletions.
8 changes: 4 additions & 4 deletions RED2/DeletionError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ private void DeletionError_Load(object sender, EventArgs e)

}

internal void SetPath(string p)
internal void SetPath(string path)
{
this.tbPath.Text = p;
this.tbPath.Text = path;
}

internal void SetErrorMessage(string p)
internal void SetErrorMessage(string msg)
{
this.tbErrorMessage.Text = p;
this.tbErrorMessage.Text = msg;
}
}
}
21 changes: 3 additions & 18 deletions RED2/Lib/ConfigurationManger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class ConfigurationManger
private string Command = "Folder\\shell\\{0}\\command";

public event EventHandler OnSettingsSaved;
public int DeletedFolderCount { get; set; }

public int DeletedFolderCount { get; set; }
public ConfigurationManger(string configPath)
{
// Settings object:
Expand All @@ -40,7 +40,7 @@ public void LoadOptions()

if (key == "registry_explorer_integration") ((CheckBox)c).Checked = SystemFunctions.IsRegKeyIntegratedIntoWindowsExplorer(MenuName);
else if (c is CheckBox) ((CheckBox)c).Checked = this.settings.Read(key, Boolean.Parse(this.defaultValues[key]));
else if (c is TextBox) ((TextBox)c).Text = this.settings.Read(key, Helpers_FixText(this.defaultValues[key]));
else if (c is TextBox) ((TextBox)c).Text = this.settings.Read(key, SystemFunctions.FixLineBreaks(this.defaultValues[key]));
else if (c is NumericUpDown) ((NumericUpDown)c).Value = (int)this.settings.Read(key, Int32.Parse(this.defaultValues[key]));
else if (c is ComboBox) ((ComboBox)c).SelectedIndex = (int)this.settings.Read(key, Int32.Parse(this.defaultValues[key]));
else if (c is Label) {
Expand All @@ -64,15 +64,8 @@ public void LoadOptions()
}
}

public static string Helpers_FixText(string _str)
{
return _str.Replace(@"\r\n", "\r\n").Replace(@"\n", "\n");
}

private void Options_CheckedChanged(object sender, EventArgs e)
{
//var cb = (CheckBox)sender;

this.Save();
}

Expand All @@ -95,14 +88,6 @@ internal void Save()
throw new Exception("Unknown control type: " + c.GetType().ToString());
}

//if (!this.cbKeepSystemFolders.Checked)
//{
// if (MessageBox.Show(this, Helpers_FixText(RED2.Properties.Resources.warning_really_delete), RED2.Properties.Resources.warning, MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.Cancel)
// this.cbKeepSystemFolders.Checked = true;
//}

//this.settings.Write("keep_system_folders", this.cbKeepSystemFolders.Checked);

if (OnSettingsSaved != null)
this.OnSettingsSaved(this, new EventArgs());

Expand Down
28 changes: 5 additions & 23 deletions RED2/Lib/Core.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;

namespace RED2
{
Expand Down Expand Up @@ -55,23 +50,8 @@ public void SearchingForEmptyDirectories()
searchEmptyFoldersWorker.ProgressChanged += new ProgressChangedEventHandler(FFWorker_ProgressChanged);
searchEmptyFoldersWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(FFWorker_RunWorkerCompleted);

//TODO

//if (!searchEmptyFoldersWorker.SetIgnoreFiles(this.data.IgnoreFiles))
//{
// showErrorMsg(RED2.Properties.Resources.error_ignore_settings);
// return;
//}

//if (!searchEmptyFoldersWorker.SetIgnoreFolders(this.data.IgnoreFolders))
//{
// showErrorMsg(RED2.Properties.Resources.error_ignore_settings);
// return;
//}

// Start worker
searchEmptyFoldersWorker.RunWorkerAsync(this.Data.StartFolder);

}

/// <summary>
Expand Down Expand Up @@ -136,7 +116,7 @@ void FFWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
else
{
int FolderCount = this.searchEmptyFoldersWorker.FolderCount;

this.searchEmptyFoldersWorker.Dispose(); this.searchEmptyFoldersWorker = null;

if (this.OnFinishedScanForEmptyDirs != null)
Expand Down Expand Up @@ -238,7 +218,10 @@ internal void RemoveProtected(string FolderFullName)
this.Data.ProtectedFolderList.Remove(FolderFullName);
}

public string GetLog() { return this.Data.LogMessages.ToString(); }
public string GetLog()
{
return this.Data.LogMessages.ToString();
}

private void showErrorMsg(string errorMessage)
{
Expand All @@ -258,7 +241,6 @@ internal void AbortDeletion()

internal void ContinueDeleteProcess()
{
// Continue
this.CurrentProcessStep = WorkflowSteps.DeleteProcessRunning;
this.deletionWorker.RunWorkerAsync();
}
Expand Down
26 changes: 13 additions & 13 deletions RED2/Lib/DeletionWorker.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.ComponentModel;
using System;
using System.ComponentModel;
using System.IO;
using System;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Threading;

namespace RED2
Expand Down Expand Up @@ -58,15 +56,15 @@ protected override void OnDoWork(DoWorkEventArgs e)
var folder = this.Data.EmptyFolderList[this.ListPos];
var status = DirectoryDeletionStatusTypes.Ignored;

// Do not delete protected folders:
if (!this.Data.ProtectedFolderList.ContainsKey(folder.FullName))
// Do not delete protected folders: TODO check if // passt
if (!this.Data.ProtectedFolderList.ContainsKey(folder))
{
try
{
// Try to delete the directory
this.secureDelete(folder);

this.Data.AddLogMessage(String.Format("Successfully deleted dir \"{0}\"", folder.FullName));
this.Data.AddLogMessage(String.Format("Successfully deleted dir \"{0}\"", folder));

status = DirectoryDeletionStatusTypes.Deleted;
this.DeletedCount++;
Expand All @@ -76,7 +74,7 @@ protected override void OnDoWork(DoWorkEventArgs e)
errorMessage = ex.Message;
stopNow = (!this.Data.IgnoreAllErrors);

this.Data.AddLogMessage(String.Format("Failed to delete dir \"{0}\" - Error message: \"{1}\"", folder.FullName, errorMessage));
this.Data.AddLogMessage(String.Format("Failed to delete dir \"{0}\" - Error message: \"{1}\"", folder, errorMessage));

status = DirectoryDeletionStatusTypes.Warning;
this.FailedCount++;
Expand All @@ -98,16 +96,18 @@ protected override void OnDoWork(DoWorkEventArgs e)
if (errorMessage == "") errorMessage = "Unknown error";

e.Cancel = true;
this.ErrorInfo = new DeletionErrorEventArgs(folder.FullName, errorMessage);
this.ErrorInfo = new DeletionErrorEventArgs(folder, errorMessage);
return;
}
}

e.Result = count;
}

private void secureDelete(DirectoryInfo emptyDirectory)
private void secureDelete(string path)
{
var emptyDirectory = new DirectoryInfo(path);

if (!Directory.Exists(emptyDirectory.FullName))
throw new Exception("Could not delete the directory \""+emptyDirectory.FullName+"\" because it does not exist anymore.");

Expand All @@ -125,7 +125,7 @@ private void secureDelete(DirectoryInfo emptyDirectory)
FileInfo file = Files[f];

string delPattern = "";
bool deleteTrashFile = SystemFunctions.MatchesIgnorePattern(file, (int)file.Length, this.Data.Ignore0kbFiles, ignoreFileList, out delPattern);
bool deleteTrashFile = SystemFunctions.MatchesIgnorePattern(file, (int)file.Length, this.Data.IgnoreEmptyFiles, ignoreFileList, out delPattern);

// If only one file is good, then stop.
if (deleteTrashFile)
Expand All @@ -147,9 +147,9 @@ private void secureDelete(DirectoryInfo emptyDirectory)

// End cleanup

SystemFunctions.SecureDeleteDirectory(emptyDirectory, this.Data.DeleteMode);
// This function will ensure that the directory is really empty before it gets deleted
SystemFunctions.SecureDeleteDirectory(emptyDirectory.FullName, this.Data.DeleteMode);

}

}
}
68 changes: 10 additions & 58 deletions RED2/Lib/Enums.cs
Original file line number Diff line number Diff line change
@@ -1,81 +1,33 @@
using System;

namespace RED2
namespace RED2
{
/// <summary>
/// RED workflow steps
/// </summary>
public enum WorkflowSteps
{
Idle,
StartSearchingForEmptyDirs,
DeleteProcessRunning,
}


/// <summary>
/// Result status types of the scan
/// </summary>
public enum DirectorySearchStatusTypes
{
//Unknown,
Empty,
Error,
NotEmpty
}

/// <summary>
/// Result types of the deletion process
/// </summary>
public enum DirectoryDeletionStatusTypes
{
Deleted,
Warning,
Ignored,
Protected
}

// Warning: Entries are case sensitive
public enum DirectoryIcons
{
home,
deleted,
protected_icon,
folder_warning
}

public class DeleteModeItem
{
public DeleteModes DeleteMode { get; set; }

public DeleteModeItem(DeleteModes Mode)
{
this.DeleteMode = Mode;
}

public static DeleteModes[] GetList()
{
return new DeleteModes[] {
DeleteModes.RecycleBin,
DeleteModes.RecycleBinWithQuestion,
DeleteModes.Direct,
DeleteModes.Simulate
};
}

public override string ToString()
{
switch (this.DeleteMode)
{
case DeleteModes.RecycleBin:
return "Delete to recycle bin (Default)";

case DeleteModes.RecycleBinWithQuestion:
return "Delete to recycle bin and ask before every deletion (Can be annoying)";

case DeleteModes.Direct:
return "Delete directly and don't ask any questions (No turning back)";

case DeleteModes.Simulate:
return "Simulate deletion (Don't delete anything)";

// Idee Move all files?

default:
throw new Exception("Unknown delete mode");
}
}
}

}
46 changes: 28 additions & 18 deletions RED2/Lib/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ public ErrorEventArgs(string msg)
}
}

//public class FoundDirEventArgs : EventArgs
//{
// public DirectoryInfo Directory { get; set; }

// public FoundDirEventArgs(DirectoryInfo dir)
// {
// this.Directory = dir;
// }
//}

public class FinishedScanForEmptyDirsEventArgs : EventArgs
{
public int EmptyFolderCount { get; set; }
Expand All @@ -48,16 +38,16 @@ public FinishedScanForEmptyDirsEventArgs(int EmptyFolderCount, int FolderCount)
public class DeleteProcessUpdateEventArgs : EventArgs
{
public int ProgressStatus { get; set; }
public DirectoryInfo Folder { get; set; }
public string Path { get; set; }
public DirectoryDeletionStatusTypes Status { get; set; }
public int FolderCount { get; set; }

public DeleteProcessUpdateEventArgs(int ProgressStatus, DirectoryInfo Folder, DirectoryDeletionStatusTypes Status, int FolderCount)
public DeleteProcessUpdateEventArgs(int progressStatus, string path, DirectoryDeletionStatusTypes status, int folderCount)
{
this.ProgressStatus = ProgressStatus;
this.Folder = Folder;
this.Status = Status;
this.FolderCount = FolderCount;
this.ProgressStatus = progressStatus;
this.Path = path;
this.Status = status;
this.FolderCount = folderCount;
}
}

Expand Down Expand Up @@ -87,9 +77,9 @@ public ProtectionStatusChangedEventArgs(string Path, bool Protected)

public class DeleteRequestFromTreeEventArgs : EventArgs
{
public DirectoryInfo Directory { get; set; }
public string Directory { get; set; }

public DeleteRequestFromTreeEventArgs(DirectoryInfo Directory)
public DeleteRequestFromTreeEventArgs(string Directory)
{
this.Directory = Directory;
}
Expand All @@ -106,4 +96,24 @@ public DeletionErrorEventArgs(string Path, string ErrorMessage)
this.ErrorMessage = ErrorMessage;
}
}

public class FoundEmptyDirInfoEventArgs : EventArgs
{
public string Directory { get; set; }
public DirectorySearchStatusTypes Type { get; set; }
public string ErrorMessage { get; set; }

public FoundEmptyDirInfoEventArgs(string Directory, DirectorySearchStatusTypes type)
{
this.Directory = Directory;
this.Type = type;
}

public FoundEmptyDirInfoEventArgs(string Directory, DirectorySearchStatusTypes type, string ErrorMessage)
{
this.Directory = Directory;
this.Type = type;
this.ErrorMessage = ErrorMessage;
}
}
}
Loading

0 comments on commit 81a1baf

Please sign in to comment.