Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split file tree logs #170

Merged
merged 3 commits into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion QModManager/Patching/Patcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ internal static void Patch()

try
{
Logger.Info($"Folder structure:{IOUtilities.GetFolderStructureAsTree()}");
Logger.Info("Folder structure:");
IOUtilities.LogFolderStructureAsTree();
}
catch (Exception e)
{
Expand Down
32 changes: 14 additions & 18 deletions QModManager/Utility/IOUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,77 +22,73 @@ internal static class IOUtilities
"steam_shader_cache",
};

internal static string GetFolderStructureAsTree(string directory = null)
internal static void LogFolderStructureAsTree(string directory = null)
{
try
{
directory ??= Environment.CurrentDirectory;

return GenerateFolderStructure(directory);
WriteFolderStructure(directory);
}
catch (Exception e)
{
throw e;
}
}

internal static string GenerateFolderStructure(string directory)
internal static void WriteFolderStructure(string directory)
{
var builder = new StringBuilder();
try
{
builder.AppendLine();
builder.AppendLine($"+ {new DirectoryInfo(directory).Name}");
Console.WriteLine();
Console.WriteLine($"+ {new DirectoryInfo(directory).Name}");

foreach (string dir in Directory.GetDirectories(directory))
{
GetFolderStructureRecursively(builder, dir, 0);
WriteFolderStructureRecursively(dir, 0);
}

string[] files = Directory.GetFiles(directory);
for (int i = 1; i <= files.Length; i++)
{
FileInfo fileinfo = new FileInfo(files[i - 1]);
if (i != files.Length)
builder.AppendLine($"{GenerateSpaces(0)}|---- {fileinfo.Name} ({ParseSize(fileinfo.Length)})");
Console.WriteLine($"{GenerateSpaces(0)}|---- {fileinfo.Name} ({ParseSize(fileinfo.Length)})");
else
builder.AppendLine($"{GenerateSpaces(0)}|---- {fileinfo.Name} ({ParseSize(fileinfo.Length)})");
Console.WriteLine($"{GenerateSpaces(0)}|---- {fileinfo.Name} ({ParseSize(fileinfo.Length)})");
}

builder.AppendLine();
return builder.ToString();
}
catch (Exception e)
{
throw e;
}
}
internal static void GetFolderStructureRecursively(StringBuilder builder, string directory, int spaces = 0)
internal static void WriteFolderStructureRecursively(string directory, int spaces = 0)
{
try
{
DirectoryInfo dirInfo = new DirectoryInfo(directory);
builder.AppendLine($"{GenerateSpaces(spaces)}|---+ {dirInfo.Name}");
Console.WriteLine($"{GenerateSpaces(spaces)}|---+ {dirInfo.Name}");

if (BannedFolders.Contains(dirInfo.Name) || BannedFolders.Contains($"{dirInfo.Parent.Name}/{dirInfo.Name}"))
{
builder.AppendLine($"{GenerateSpaces(spaces + 4)}`---- (Folder content not shown)");
Console.WriteLine($"{GenerateSpaces(spaces + 4)}`---- (Folder content not shown)");
return;
}

foreach (string dir in Directory.GetDirectories(directory))
{
GetFolderStructureRecursively(builder, dir, spaces + 4);
WriteFolderStructureRecursively(dir, spaces + 4);
}

string[] files = Directory.GetFiles(directory);
for (int i = 1; i <= files.Length; i++)
{
FileInfo fileinfo = new FileInfo(files[i - 1]);
if (i != files.Length)
builder.AppendLine($"{GenerateSpaces(spaces + 4)}|---- {fileinfo.Name} ({ParseSize(fileinfo.Length)})");
Console.WriteLine($"{GenerateSpaces(spaces + 4)}|---- {fileinfo.Name} ({ParseSize(fileinfo.Length)})");
else
builder.AppendLine($"{GenerateSpaces(spaces + 4)}`---- {fileinfo.Name} ({ParseSize(fileinfo.Length)})");
Console.WriteLine($"{GenerateSpaces(spaces + 4)}`---- {fileinfo.Name} ({ParseSize(fileinfo.Length)})");
}
}
catch (Exception e)
Expand Down