From 34e28d60ae788e9efb86d93ccd3fb496675c7dfe Mon Sep 17 00:00:00 2001 From: DaNike Date: Thu, 7 Feb 2019 23:17:03 -0600 Subject: [PATCH] Tweaked updater to no longer reference SelfPlugin when updating --- IPA.Loader/Loader/PluginLoader.cs | 10 +++++--- IPA.Loader/Updating/ModSaber/Updater.cs | 33 +++++++++++-------------- IPA.Loader/Utilities/Extensions.cs | 7 ++++++ 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/IPA.Loader/Loader/PluginLoader.cs b/IPA.Loader/Loader/PluginLoader.cs index 62baf403..cb281187 100644 --- a/IPA.Loader/Loader/PluginLoader.cs +++ b/IPA.Loader/Loader/PluginLoader.cs @@ -67,7 +67,9 @@ namespace IPA.Loader /// public IReadOnlyList Features => InternalFeatures; - internal List InternalFeatures = new List(); + internal readonly List InternalFeatures = new List(); + + internal bool IsSelf; private PluginManifest manifest; @@ -112,7 +114,8 @@ namespace IPA.Loader { Assembly = Assembly.GetExecutingAssembly(), File = new FileInfo(Path.Combine(BeatSaber.InstallPath, "IPA.exe")), - PluginType = null + PluginType = null, + IsSelf = true }; string manifest; @@ -138,7 +141,8 @@ namespace IPA.Loader { var metadata = new PluginMetadata { - File = new FileInfo(Path.Combine(BeatSaber.PluginsPath, plugin)) + File = new FileInfo(Path.Combine(BeatSaber.PluginsPath, plugin)), + IsSelf = false }; var pluginModule = AssemblyDefinition.ReadAssembly(plugin, new ReaderParameters diff --git a/IPA.Loader/Updating/ModSaber/Updater.cs b/IPA.Loader/Updating/ModSaber/Updater.cs index 6a026494..64536ff4 100644 --- a/IPA.Loader/Updating/ModSaber/Updater.cs +++ b/IPA.Loader/Updating/ModSaber/Updater.cs @@ -56,13 +56,13 @@ namespace IPA.Updating.ModSaber public Version Version { get; set; } public Version ResolvedVersion { get; set; } public Range Requirement { get; set; } - public Range Conflicts { get; set; } + public Range Conflicts { get; set; } // a range of versions that are not allowed to be downloaded public bool Resolved { get; set; } public bool Has { get; set; } public HashSet Consumers { get; set; } = new HashSet(); public bool MetaRequestFailed { get; set; } - + public PluginLoader.PluginInfo LocalPluginMeta { get; set; } public override string ToString() @@ -205,10 +205,8 @@ namespace IPA.Updating.ModSaber var dep = list.Value[i]; var mod = new Ref(null); - - #region TEMPORARY get latest // SHOULD BE GREATEST OF VERSION // not going to happen because of disagreements with ModSaber + yield return GetModInfo(dep.Name, "", mod); - #endregion try { mod.Verify(); } catch (Exception e) @@ -278,10 +276,12 @@ namespace IPA.Updating.ModSaber continue; } - var ver = modsMatching.Value.Where(nullCheck => nullCheck != null) - .Where(versionCheck => versionCheck.GameVersion.Version == BeatSaber.GameVersion && versionCheck.Approval.Status) - .Where(conflictsCheck => dep.Conflicts == null || !dep.Conflicts.IsSatisfied(conflictsCheck.Version)) - .Select(mod => mod.Version).Max(); // (2.1) + var ver = modsMatching.Value + .Where(nullCheck => nullCheck != null) // entry is not null + .Where(versionCheck => versionCheck.GameVersion.Version == BeatSaber.GameVersion) // game version matches + .Where(approvalCheck => approvalCheck.Approval.Status) // version approved + .Where(conflictsCheck => dep.Conflicts == null || !dep.Conflicts.IsSatisfied(conflictsCheck.Version)) // not a conflicting version + .Select(mod => mod.Version).Max(); // (2.1) get the max version // ReSharper disable once AssignmentInConditionalExpression if (dep.Resolved = ver != null) dep.ResolvedVersion = ver; // (2.2) dep.Has = dep.Version == dep.ResolvedVersion && dep.Resolved; // dep.Version is only not null if its already installed @@ -311,11 +311,6 @@ namespace IPA.Updating.ModSaber Logger.updater.Debug($"To Download {string.Join(", ", toDl.Select(d => $"{d.Name}@{d.ResolvedVersion}"))}"); - string tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + Path.GetRandomFileName()); - Directory.CreateDirectory(tempDirectory); - - Logger.updater.Debug($"Temp directory: {tempDirectory}"); - foreach (var item in toDl) StartCoroutine(UpdateModCoroutine(item)); } @@ -475,7 +470,7 @@ namespace IPA.Updating.ModSaber try { - bool shouldDeleteOldFile = !(item.LocalPluginMeta?.Plugin is SelfPlugin); + bool shouldDeleteOldFile = !(item.LocalPluginMeta?.Metadata.IsSelf).Unwrap(); using (var zipFile = ZipFile.Read(stream)) { @@ -543,13 +538,15 @@ namespace IPA.Updating.ModSaber throw; } - if (item.LocalPluginMeta?.Plugin is SelfPlugin) + if ((item.LocalPluginMeta?.Metadata.IsSelf).Unwrap()) { // currently updating self, so copy to working dir and update Utils.CopyAll(new DirectoryInfo(targetDir), new DirectoryInfo(BeatSaber.InstallPath)); - if (File.Exists(Path.Combine(BeatSaber.InstallPath, SpecialDeletionsFile))) File.Delete(Path.Combine(BeatSaber.InstallPath, SpecialDeletionsFile)); + var deleteFile = Path.Combine(BeatSaber.InstallPath, SpecialDeletionsFile); + if (File.Exists(deleteFile)) File.Delete(deleteFile); Process.Start(new ProcessStartInfo { - FileName = item.LocalPluginMeta?.Metadata.File.FullName, + // will never actually be null + FileName = item.LocalPluginMeta?.Metadata.File.FullName ?? throw new InvalidOperationException(), Arguments = $"-nw={Process.GetCurrentProcess().Id}", UseShellExecute = false }); diff --git a/IPA.Loader/Utilities/Extensions.cs b/IPA.Loader/Utilities/Extensions.cs index 4cd6b762..cfcfcb29 100644 --- a/IPA.Loader/Utilities/Extensions.cs +++ b/IPA.Loader/Utilities/Extensions.cs @@ -16,5 +16,12 @@ namespace IPA.Utilities { return type.IsValueType ? Activator.CreateInstance(type) : null; } + + /// + /// Unwraps a where T is such that if the value is null, it gives . + /// + /// the bool? to unwrap + /// the unwrapped value, or if it was + public static bool Unwrap(this bool? self) => self != null && self.Value; } }