Skip to content

Commit

Permalink
Final changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hxseven committed Mar 11, 2012
1 parent 81a1baf commit 689a1e7
Show file tree
Hide file tree
Showing 11 changed files with 384 additions and 379 deletions.
2 changes: 1 addition & 1 deletion RED2/Lib/Core.cs
Expand Up @@ -195,7 +195,7 @@ void deletionWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArg
}
else
{
// Todo: Use separate class here?
// TODO: Use separate class here?
int deletedCount = this.deletionWorker.DeletedCount;
int failedCount = this.deletionWorker.FailedCount;

Expand Down
6 changes: 3 additions & 3 deletions RED2/Lib/DeletionWorker.cs
Expand Up @@ -56,7 +56,7 @@ protected override void OnDoWork(DoWorkEventArgs e)
var folder = this.Data.EmptyFolderList[this.ListPos];
var status = DirectoryDeletionStatusTypes.Ignored;

// Do not delete protected folders: TODO check if // passt
// Do not delete one time protected folders
if (!this.Data.ProtectedFolderList.ContainsKey(folder))
{
try
Expand Down Expand Up @@ -108,7 +108,7 @@ private void secureDelete(string path)
{
var emptyDirectory = new DirectoryInfo(path);

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

// Cleanup folder
Expand All @@ -122,7 +122,7 @@ private void secureDelete(string path)
// loop trough files and cancel if containsFiles == true
for (int f = 0; f < Files.Length; f++)
{
FileInfo file = Files[f];
var file = Files[f];

string delPattern = "";
bool deleteTrashFile = SystemFunctions.MatchesIgnorePattern(file, (int)file.Length, this.Data.IgnoreEmptyFiles, ignoreFileList, out delPattern);
Expand Down
11 changes: 8 additions & 3 deletions RED2/Lib/RuntimeData.cs
Expand Up @@ -29,9 +29,8 @@ public class RuntimeData
public int MaxDepth { get; set; }
public int InfiniteLoopDetectionCount { get; set; }

public StringBuilder LogMessages = new StringBuilder();
public Dictionary<String, bool> ProtectedFolderList = new Dictionary<string, bool>();
//public List<DirectoryInfo> EmptyFolderList { get; set; } TODO
public StringBuilder LogMessages = null;
public Dictionary<string, bool> ProtectedFolderList = new Dictionary<string, bool>();
public List<string> EmptyFolderList { get; set; }

public RuntimeData()
Expand All @@ -55,5 +54,11 @@ public void AddLogMessage(string msg)
{
this.LogMessages.AppendLine(DateTime.Now.ToString("r") + "\t" + msg);
}

internal void AddLogSpacer()
{
if (this.LogMessages.Length > 0)
this.LogMessages.Append(Environment.NewLine);
}
}
}
25 changes: 11 additions & 14 deletions RED2/Lib/SystemFunctions.cs
Expand Up @@ -45,25 +45,22 @@ public static bool MatchesIgnorePattern(FileInfo file, int filesize, bool Ignore
}
else if (pattern.ToLower() == file.Name.ToLower())
{
// Direct match - ignore case
delPattern = pattern;
matches_pattern = true;
}
else if (pattern.Contains("*"))
else if (pattern.Contains("*") || (pattern.StartsWith("/") && pattern.EndsWith("/")))
{
pattern = Regex.Escape(pattern);
pattern = pattern.Replace("\\*", ".*");

regexPattern = new Regex("^" + pattern + "$");

if (regexPattern.IsMatch(file.Name))
// Pattern is a regex
if (pattern.StartsWith("/") && pattern.EndsWith("/"))
{
delPattern = pattern;
matches_pattern = true;
regexPattern = new Regex(pattern.Substring(1, pattern.Length - 2));
}
else
{
pattern = Regex.Escape(pattern).Replace("\\*", ".*");
regexPattern = new Regex("^" + pattern + "$");
}
}
else if (pattern.StartsWith("/") && pattern.EndsWith("/"))
{
regexPattern = new Regex(pattern.Substring(1, pattern.Length - 2));

if (regexPattern.IsMatch(file.Name))
{
Expand Down Expand Up @@ -104,7 +101,7 @@ public static void SecureDeleteFile(FileInfo file, DeleteModes deleteMode)
if (deleteMode == DeleteModes.Simulate) return;

if (deleteMode == DeleteModes.RecycleBin) FileSystem.DeleteFile(file.FullName, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin, UICancelOption.ThrowException);
else if (deleteMode == DeleteModes.RecycleBinWithQuestion) FileSystem.DeleteDirectory(file.FullName, UIOption.AllDialogs, RecycleOption.SendToRecycleBin, UICancelOption.ThrowException);
else if (deleteMode == DeleteModes.RecycleBinWithQuestion) FileSystem.DeleteFile(file.FullName, UIOption.AllDialogs, RecycleOption.SendToRecycleBin, UICancelOption.ThrowException);
else if (deleteMode == DeleteModes.Direct)
{
//if (SystemFunctions.random.NextDouble() > 0.5) throw new Exception("Test error");
Expand Down
3 changes: 2 additions & 1 deletion RED2/Lib/TreeManager.cs
Expand Up @@ -86,14 +86,15 @@ internal void UpdateItemIcon(string path, DirectoryIcons iconKey)
treeNode.EnsureVisible();
}

// TODO: Find better code structure for the following two routines
private TreeNode findOrCreateDirectoryNodeByPath(string path)
{
if (path == null) return null;

if (directoryToTreeNodeMapping.ContainsKey(path))
return directoryToTreeNodeMapping[path];
else
return AddOrUpdateDirectoryNode(path, DirectorySearchStatusTypes.NotEmpty, ""); // TODO: OK?
return AddOrUpdateDirectoryNode(path, DirectorySearchStatusTypes.NotEmpty, "");
}

public TreeNode AddOrUpdateDirectoryNode(string path, DirectorySearchStatusTypes statusType, string optionalErrorMsg)
Expand Down
2 changes: 1 addition & 1 deletion RED2/Lib/UIHelpers.cs
Expand Up @@ -51,7 +51,7 @@ public override string ToString()
case DeleteModes.Simulate:
return "Simulate deletion (Don't delete anything)";

// TODO: Move files instead of deleting?
// TODO: Idea -> Move files instead of deleting?

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

0 comments on commit 689a1e7

Please sign in to comment.