Browse Source

Tweaked updater to no longer reference SelfPlugin when updating

pull/1/head
DaNike 5 years ago
parent
commit
a271350b4f
3 changed files with 29 additions and 21 deletions
  1. +7
    -3
      IPA.Loader/Loader/PluginLoader.cs
  2. +15
    -18
      IPA.Loader/Updating/ModSaber/Updater.cs
  3. +7
    -0
      IPA.Loader/Utilities/Extensions.cs

+ 7
- 3
IPA.Loader/Loader/PluginLoader.cs View File

@ -67,7 +67,9 @@ namespace IPA.Loader
/// </summary> /// </summary>
public IReadOnlyList<Feature> Features => InternalFeatures; public IReadOnlyList<Feature> Features => InternalFeatures;
internal List<Feature> InternalFeatures = new List<Feature>();
internal readonly List<Feature> InternalFeatures = new List<Feature>();
internal bool IsSelf;
private PluginManifest manifest; private PluginManifest manifest;
@ -112,7 +114,8 @@ namespace IPA.Loader
{ {
Assembly = Assembly.GetExecutingAssembly(), Assembly = Assembly.GetExecutingAssembly(),
File = new FileInfo(Path.Combine(BeatSaber.InstallPath, "IPA.exe")), File = new FileInfo(Path.Combine(BeatSaber.InstallPath, "IPA.exe")),
PluginType = null
PluginType = null,
IsSelf = true
}; };
string manifest; string manifest;
@ -138,7 +141,8 @@ namespace IPA.Loader
{ {
var metadata = new PluginMetadata 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 var pluginModule = AssemblyDefinition.ReadAssembly(plugin, new ReaderParameters


+ 15
- 18
IPA.Loader/Updating/ModSaber/Updater.cs View File

@ -56,13 +56,13 @@ namespace IPA.Updating.ModSaber
public Version Version { get; set; } public Version Version { get; set; }
public Version ResolvedVersion { get; set; } public Version ResolvedVersion { get; set; }
public Range Requirement { 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 Resolved { get; set; }
public bool Has { get; set; } public bool Has { get; set; }
public HashSet<string> Consumers { get; set; } = new HashSet<string>(); public HashSet<string> Consumers { get; set; } = new HashSet<string>();
public bool MetaRequestFailed { get; set; } public bool MetaRequestFailed { get; set; }
public PluginLoader.PluginInfo LocalPluginMeta { get; set; } public PluginLoader.PluginInfo LocalPluginMeta { get; set; }
public override string ToString() public override string ToString()
@ -205,10 +205,8 @@ namespace IPA.Updating.ModSaber
var dep = list.Value[i]; var dep = list.Value[i];
var mod = new Ref<ApiEndpoint.Mod>(null); var mod = new Ref<ApiEndpoint.Mod>(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); yield return GetModInfo(dep.Name, "", mod);
#endregion
try { mod.Verify(); } try { mod.Verify(); }
catch (Exception e) catch (Exception e)
@ -278,10 +276,12 @@ namespace IPA.Updating.ModSaber
continue; 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 // ReSharper disable once AssignmentInConditionalExpression
if (dep.Resolved = ver != null) dep.ResolvedVersion = ver; // (2.2) 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 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}"))}"); 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) foreach (var item in toDl)
StartCoroutine(UpdateModCoroutine(item)); StartCoroutine(UpdateModCoroutine(item));
} }
@ -475,7 +470,7 @@ namespace IPA.Updating.ModSaber
try try
{ {
bool shouldDeleteOldFile = !(item.LocalPluginMeta?.Plugin is SelfPlugin);
bool shouldDeleteOldFile = !(item.LocalPluginMeta?.Metadata.IsSelf).Unwrap();
using (var zipFile = ZipFile.Read(stream)) using (var zipFile = ZipFile.Read(stream))
{ {
@ -543,13 +538,15 @@ namespace IPA.Updating.ModSaber
throw; throw;
} }
if (item.LocalPluginMeta?.Plugin is SelfPlugin)
if ((item.LocalPluginMeta?.Metadata.IsSelf).Unwrap())
{ // currently updating self, so copy to working dir and update { // currently updating self, so copy to working dir and update
Utils.CopyAll(new DirectoryInfo(targetDir), new DirectoryInfo(BeatSaber.InstallPath)); 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 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}", Arguments = $"-nw={Process.GetCurrentProcess().Id}",
UseShellExecute = false UseShellExecute = false
}); });


+ 7
- 0
IPA.Loader/Utilities/Extensions.cs View File

@ -16,5 +16,12 @@ namespace IPA.Utilities
{ {
return type.IsValueType ? Activator.CreateInstance(type) : null; return type.IsValueType ? Activator.CreateInstance(type) : null;
} }
/// <summary>
/// Unwraps a <see cref="Nullable{T}"/> where T is <see cref="bool"/> such that if the value is null, it gives <see langword="false"/>.
/// </summary>
/// <param name="self">the bool? to unwrap</param>
/// <returns>the unwrapped value, or <see langword="false"/> if it was <see langword="null"/></returns>
public static bool Unwrap(this bool? self) => self != null && self.Value;
} }
} }

Loading…
Cancel
Save