Skip to content

Commit

Permalink
chore: Size logging and force deleting folders (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
dalkia authored Oct 8, 2024
1 parent 26005f9 commit a83d74e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
21 changes: 13 additions & 8 deletions DCL_PiXYZ/PXZClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions DCL_PiXYZ/PXZEntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ 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)
{
Console.Error.WriteLine(errorMessage);
Environment.Exit(1);
}



}
Expand Down
23 changes: 22 additions & 1 deletion DCL_PiXYZ/Utils/FileWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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);
}



}
}

0 comments on commit a83d74e

Please sign in to comment.