Skip to content

Commit

Permalink
Merge pull request DaXcess#50 from bontebok/copyresourcefile
Browse files Browse the repository at this point in the history
Added new method CopyResourceFile to prevent copying each mod startup
  • Loading branch information
DaXcess authored Jan 10, 2024
2 parents f2b523c + bd4f4e4 commit 100cb84
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions LCVR/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,28 @@ private bool StartDisplay()
return true;
}

/// <summary>
/// Helper function for SetupRuntimeAssets() to copy resource files and return false if the source does not exist
/// </summary>
private bool CopyResourceFile(string sourceFile, string destinationFile)
{
if (!File.Exists(sourceFile))
return false;

if (File.Exists(destinationFile))
{
var sourceHash = SHA256.Create().ComputeHash(File.ReadAllBytes(sourceFile));
var destHash = SHA256.Create().ComputeHash(File.ReadAllBytes(destinationFile));

if (sourceHash.SequenceEqual(destHash))
return true;
}

File.Copy(sourceFile, destinationFile, true);

return true;
}

/// <summary>
/// Place required runtime libraries and configuration in the game files to allow VR to be started
/// </summary>
Expand Down Expand Up @@ -320,14 +342,10 @@ private bool SetupRuntimeAssets()
var uoxr = Path.Combine(current, "RuntimeDeps/UnityOpenXR.dll");
var oxrLoader = Path.Combine(current, "RuntimeDeps/openxr_loader.dll");

if (File.Exists(uoxr))
File.Copy(uoxr, uoxrTarget, true);
else
if (!CopyResourceFile(uoxr, uoxrTarget))
Logger.LogWarning("Could not find UnityOpenXR.dll to copy to the game, VR might not work!");

if (File.Exists(oxrLoader))
File.Copy(oxrLoader, oxrLoaderTarget, true);
else
if (!CopyResourceFile(oxrLoader, oxrLoaderTarget))
Logger.LogWarning("Could not find openxr_loader.dll to copy to the game, VR might not work!");

return mustRestart;
Expand Down

0 comments on commit 100cb84

Please sign in to comment.