Skip to content

Commit

Permalink
Add Conditional DEBUG file load/save logging
Browse files Browse the repository at this point in the history
  • Loading branch information
MidoriKami committed Apr 3, 2023
1 parent 62162d4 commit cbf3608
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions DailyDuty/System/FileController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ public static unsafe class FileController
{
public static object LoadFile(string filePath, object targetObject)
{
DebugPrint($"[FileController] Loading {filePath}");

if (LoadFile(filePath, targetObject.GetType(), out var loadedData))
{
return loadedData;
}


DebugPrint($"[FileController] File Doesn't Exist, creating: {filePath}");

SaveFile(filePath, targetObject.GetType(), targetObject);
return targetObject;
}
Expand All @@ -38,7 +42,7 @@ private static bool LoadFile(string fileName, Type fileType, [NotNullWhen(true)]
}
catch (Exception exception)
{
PluginLog.Error(exception, $"Failed to load file: {fileName}");
PluginLog.Error(exception, $"[FileController] Failed to load file: {fileName}");

loadedData = null;
return false;
Expand All @@ -47,6 +51,8 @@ private static bool LoadFile(string fileName, Type fileType, [NotNullWhen(true)]

public static void SaveFile(string fileName, Type fileType, object objectData)
{
DebugPrint($"[FileController] Saving {fileName}");

try
{
var fileInfo = GetFileInfo(fileName);
Expand All @@ -56,7 +62,7 @@ public static void SaveFile(string fileName, Type fileType, object objectData)
}
catch (Exception exception)
{
PluginLog.Error(exception, $"Failed to save file: {fileName}");
PluginLog.Error(exception, $"[FileController] Failed to save file: {fileName}");
}
}

Expand All @@ -79,4 +85,11 @@ private static DirectoryInfo GetCharacterDirectory(ulong contentId)

return directoryInfo;
}

private static void DebugPrint(string message)
{
#if DEBUG
PluginLog.Debug(message);
#endif
}
}

0 comments on commit cbf3608

Please sign in to comment.