From a83d74ea576dfe4f7ba7eafb2c99e42c9802051b Mon Sep 17 00:00:00 2001 From: Juan Ignacio Molteni Date: Tue, 8 Oct 2024 11:30:45 -0300 Subject: [PATCH] chore: Size logging and force deleting folders (#150) --- DCL_PiXYZ/PXZClient.cs | 21 +++++++++++++-------- DCL_PiXYZ/PXZEntryPoint.cs | 4 ++++ DCL_PiXYZ/Utils/FileWriter.cs | 23 ++++++++++++++++++++++- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/DCL_PiXYZ/PXZClient.cs b/DCL_PiXYZ/PXZClient.cs index ece84936..ee0186e1 100644 --- a/DCL_PiXYZ/PXZClient.cs +++ b/DCL_PiXYZ/PXZClient.cs @@ -76,23 +76,28 @@ public async Task RunLODBuilder(PXZEntryArgs args) FileWriter.WriteToConsole("END SCENE CONVERSION FOR " + currentScene); UpdateConvertedScenesFile(convertedScenes); } - //TODO (Juani): Clear resources folder DoManifestCleanup(args.DebugMode, pathHandler); + ClearResourcesFolder(args.DebugMode, pathHandler); pxz.Core.ResetSession(); } - private void DoManifestCleanup(bool isDebug, SceneConversionPathHandler pathHandler) + private void ClearResourcesFolder(bool isDebug, SceneConversionPathHandler pathHandler) { - if (!isDebug) + if (isDebug) return; - if (string.IsNullOrEmpty(pathHandler.ManifestOutputJsonDirectory) - || Directory.Exists(pathHandler.ManifestOutputJsonDirectory)) return; + if (Directory.Exists(PXZConstants.RESOURCES_DIRECTORY)) + Directory.Delete(PXZConstants.RESOURCES_DIRECTORY, true); - var dir = new DirectoryInfo(pathHandler.ManifestOutputJsonDirectory); + } - foreach (var fi in dir.GetFiles()) - fi.Delete(); + private void DoManifestCleanup(bool isDebug, SceneConversionPathHandler pathHandler) + { + if (isDebug) + return; + + if (Directory.Exists(pathHandler.ManifestOutputJsonDirectory)) + Directory.Delete(pathHandler.ManifestOutputJsonDirectory, true); } private async Task DoConversion(PXZConversionParams pxzParams, SceneConversionInfo sceneConversionInfo, string scene, SceneConversionPathHandler pathHandler) diff --git a/DCL_PiXYZ/PXZEntryPoint.cs b/DCL_PiXYZ/PXZEntryPoint.cs index 9152ae20..e4fbfc76 100644 --- a/DCL_PiXYZ/PXZEntryPoint.cs +++ b/DCL_PiXYZ/PXZEntryPoint.cs @@ -16,7 +16,10 @@ static async Task Main(string[] args) private static async Task RunLODGeneration(PXZEntryArgs obj) { PXZClient pxzClient = new PXZClient(); + FileWriter.currentScene = obj.SceneToConvert; + FileWriter.PrintDriveSize("ON START PROCESS"); await pxzClient.RunLODBuilder(obj); + FileWriter.PrintDriveSize("ON END PROCESS"); } public static void CloseApplication(string errorMessage) @@ -24,6 +27,7 @@ public static void CloseApplication(string errorMessage) Console.Error.WriteLine(errorMessage); Environment.Exit(1); } + } diff --git a/DCL_PiXYZ/Utils/FileWriter.cs b/DCL_PiXYZ/Utils/FileWriter.cs index 532560ea..2fea1084 100644 --- a/DCL_PiXYZ/Utils/FileWriter.cs +++ b/DCL_PiXYZ/Utils/FileWriter.cs @@ -5,6 +5,8 @@ namespace DCL_PiXYZ.Utils { public class FileWriter { + public static string currentScene; + public static void WriteToFile(string message, string fileName) { using (StreamWriter file = new StreamWriter(fileName, true)) @@ -14,7 +16,26 @@ public static void WriteToFile(string message, string fileName) public static void WriteToConsole(string message) { string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); - Console.WriteLine($"[{timestamp}] {message}"); + Console.WriteLine($"[{timestamp}] {currentScene} {message}"); + } + + + public static void PrintDriveSize(string message) + { + DriveInfo[] allDrives = DriveInfo.GetDrives(); + foreach (DriveInfo d in allDrives) + { + if(d.IsReady) + WriteToConsole($"{message} Drive {d.Name} - Total: {ConvertToGB(d.TotalSize)} GB, Available: {ConvertToGB(d.AvailableFreeSpace)} GB, Free: {ConvertToGB(d.TotalFreeSpace)} GB"); + } } + + private static double ConvertToGB(long bytes) + { + return Math.Round(bytes / (double)(1024 * 1024 * 1024), 2); + } + + + } } \ No newline at end of file