From 712a751bd7df1136ae37dd011a24a7e21c3d4ef2 Mon Sep 17 00:00:00 2001 From: Yoshi Askharoun Date: Sun, 30 May 2021 23:48:48 -0500 Subject: [PATCH] Prevented overwriting of backups when reapplying mod --- ZuneModCore/Mods/VideoSyncMod.cs | 7 +++++-- ZuneModCore/Mods/WebservicesMod.cs | 8 ++++++-- ZuneModCore/ZuneModCore.csproj | 2 +- ZuneModdingHelper/ZuneModdingHelper.csproj | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ZuneModCore/Mods/VideoSyncMod.cs b/ZuneModCore/Mods/VideoSyncMod.cs index 6ce177f..f304d4d 100644 --- a/ZuneModCore/Mods/VideoSyncMod.cs +++ b/ZuneModCore/Mods/VideoSyncMod.cs @@ -1,6 +1,7 @@ using OwlCore.AbstractUI.Models; using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Security.AccessControl; using System.Security.Principal; @@ -27,8 +28,10 @@ namespace ZuneModCore.Mods #pragma warning disable CA1416 // Validate platform compatibility public override Task Apply() { - // Make a backup of the file - File.Copy(WMVCORE_PATH, Path.Combine(StorageDirectory, "WMVCORE.original.dll"), true); + // Make a backup of the original file + FileVersionInfo wmvDllVersionInfo = FileVersionInfo.GetVersionInfo(WMVCORE_PATH); + if (Version.Parse(wmvDllVersionInfo.ProductVersion!) <= new Version(12, 0, 10586, 0)) + File.Copy(WMVCORE_PATH, Path.Combine(StorageDirectory, "WMVCORE.original.dll"), true); // Get the working WMVCORE.dll string sourcePath = Path.Combine( diff --git a/ZuneModCore/Mods/WebservicesMod.cs b/ZuneModCore/Mods/WebservicesMod.cs index c0cbf93..632c7cd 100644 --- a/ZuneModCore/Mods/WebservicesMod.cs +++ b/ZuneModCore/Mods/WebservicesMod.cs @@ -34,8 +34,12 @@ namespace ZuneModCore.Mods return Task.FromResult($"The file '{zsDllInfo.FullName}' does not exist."); } - // Make a backup of the file - File.Copy(zsDllInfo.FullName, Path.Combine(StorageDirectory, "ZuneService.original.dll"), true); + // Make a backup if it doesn't already exist + FileInfo zsDllBackupInfo = new(Path.Combine(StorageDirectory, "ZuneService.original.dll")); + if (zsDllBackupInfo.Exists) + { + File.Copy(zsDllInfo.FullName, zsDllBackupInfo.FullName, true); + } try { diff --git a/ZuneModCore/ZuneModCore.csproj b/ZuneModCore/ZuneModCore.csproj index 1d530bf..ceaa925 100644 --- a/ZuneModCore/ZuneModCore.csproj +++ b/ZuneModCore/ZuneModCore.csproj @@ -8,7 +8,7 @@ - + diff --git a/ZuneModdingHelper/ZuneModdingHelper.csproj b/ZuneModdingHelper/ZuneModdingHelper.csproj index cd13d64..b0ba108 100644 --- a/ZuneModdingHelper/ZuneModdingHelper.csproj +++ b/ZuneModdingHelper/ZuneModdingHelper.csproj @@ -21,7 +21,7 @@ - +