Skip to content

Commit

Permalink
Move function
Browse files Browse the repository at this point in the history
Move function into correct file
  • Loading branch information
bfourk committed Feb 24, 2024
1 parent 2a5a2d9 commit 9827322
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
25 changes: 3 additions & 22 deletions FileDiff/FileDiff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,6 @@ namespace FileDiff;
public class FDiff
{
private const int Threads = 16; // Can change to whatever you want
private static void RecreateDirectoryTree(string GarbagePath, string? path)
{
string? DirName = Path.GetDirectoryName(path);
if (DirName == null)
return;
string[] WithoutFile = DirName.Split("/");
string CurrentPath = "";
foreach (string str in WithoutFile)
{
if (str == "")
continue;
CurrentPath += string.Format("{0}/",str);
if (!CurrentPath.Contains(".DiffTrash"))
continue;
int index = CurrentPath.IndexOf(".DiffTrash");
Console.WriteLine(CurrentPath.Substring(index + 11));
Directory.CreateDirectory(Path.Join(GarbagePath,CurrentPath.Substring(index + 11)));
}
}
public static void Main(string[] args)
{
Stopwatch sw = new Stopwatch(); // For calculating the total time
Expand Down Expand Up @@ -254,7 +235,7 @@ public static void Main(string[] args)
string NewPath = Path.Join(GarbagePath, del);

// Re-create directory path in trash folder
RecreateDirectoryTree(GarbagePath, NewPath);
Util.RecreateDirectoryTree(GarbagePath, NewPath);
if (File.Exists(NewPath))
{
Console.WriteLine("Warn: File with similar name already exists in trash, adding number to beginning");
Expand All @@ -276,7 +257,7 @@ public static void Main(string[] args)
{
string DirPath = Path.Join(SyncDirectory, del);
string NewPath = Path.Join(GarbagePath, del);
RecreateDirectoryTree(GarbagePath, NewPath);
Util.RecreateDirectoryTree(GarbagePath, NewPath);
if (Directory.Exists(NewPath))
{
Console.WriteLine("Warn: File with similar name already exists in trash, adding number to beginning");
Expand All @@ -293,4 +274,4 @@ public static void Main(string[] args)
}
Console.WriteLine("Finished");
}
}
}
18 changes: 18 additions & 0 deletions FileDiff/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ public static bool CompareFiles(string path1, string path2)
}
return CompareHash(Hash1, Hash2);
}
public static void RecreateDirectoryTree(string GarbagePath, string? path)
{
string? DirName = Path.GetDirectoryName(path);
if (DirName == null)
return;
string[] WithoutFile = DirName.Split("/");
string CurrentPath = "";
foreach (string str in WithoutFile)
{
if (str == "")
continue;
CurrentPath += string.Format("{0}/",str);
if (!CurrentPath.Contains(".DiffTrash"))
continue;
int index = CurrentPath.IndexOf(".DiffTrash");
Directory.CreateDirectory(Path.Join(GarbagePath,CurrentPath.Substring(index + 11)));
}
}

//
// Misc. Functions
Expand Down

0 comments on commit 9827322

Please sign in to comment.