Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
Rewrote search system, and now it actually works.
Browse files Browse the repository at this point in the history
  • Loading branch information
NovoCore committed Jun 1, 2024
1 parent 94c1e32 commit 1b3d2eb
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions NanoCoreRemover/FileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void CheckAndScan()
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
Path.GetTempPath()
};

int totalFiles = directories.Sum(dir => CountFiles(dir));
progressBar1.Invoke(new Action(() =>
{
Expand All @@ -54,11 +54,13 @@ public void CheckAndScan()
{
try
{
var files = Directory.EnumerateFiles(folder, "*.*", SearchOption.AllDirectories);
Console.WriteLine($"Scanning folder: {folder}");
var files = GetFiles(folder, "*.*");
foreach (string file in files)
{
try
{
Console.WriteLine($"Processing file: {file}");
if (IsNanoCoreAssembly(file))
{
listView1.Invoke(new Action(() =>
Expand Down Expand Up @@ -119,21 +121,29 @@ private string AsmName(string filePath)
private List<string> GetFiles(string path, string pattern)
{
var files = new List<string>();
var directories = new string[] { };
var stack = new Stack<string>();
stack.Push(path);

try
while (stack.Count > 0)
{
files.AddRange(Directory.GetFiles(path, pattern, SearchOption.TopDirectoryOnly));
directories = Directory.GetDirectories(path);
}
catch (UnauthorizedAccessException) { }

foreach (var directory in directories)
var currentDir = stack.Pop();
try
{
files.AddRange(GetFiles(directory, pattern));
files.AddRange(Directory.GetFiles(currentDir, pattern));
foreach (var dir in Directory.GetDirectories(currentDir))
{
stack.Push(dir);
}
}
catch (UnauthorizedAccessException ex)
{
Console.WriteLine($"Access denied to folder {currentDir}: {ex.Message}");
}
catch (UnauthorizedAccessException) { }
catch (Exception ex)
{
Console.WriteLine($"Error accessing folder {currentDir}: {ex.Message}");
}
}

return files;
}
Expand All @@ -143,13 +153,16 @@ private int CountFiles(string directory)
int count = 0;
try
{
count = GetFiles(directory, "*.*").Count;
var files = GetFiles(directory, "*.*");
count = files.Count;
}
catch (UnauthorizedAccessException ex)
{
Console.WriteLine($"Access denied to folder {directory}: {ex.Message}");
}
catch (Exception ex)
{

Console.WriteLine($"Error counting files in {directory}: {ex.Message}");

}
return count;
}
Expand Down

0 comments on commit 1b3d2eb

Please sign in to comment.