summaryrefslogtreecommitdiff
path: root/src/SMAPI.Installer/Program.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2018-11-19 13:48:19 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2018-11-19 13:48:19 -0500
commit593723b7940ba72a786fc4c7366c56f9813d977b (patch)
tree4d23fbef5bc5a20115f10ca04ae3379df78cc8e1 /src/SMAPI.Installer/Program.cs
parent4f28ea33bd7cc65485402c5e85259083e86b49e1 (diff)
parent3dc27a5681dcfc4ae30e95570d9966f2e14a4dd7 (diff)
downloadSMAPI-593723b7940ba72a786fc4c7366c56f9813d977b.tar.gz
SMAPI-593723b7940ba72a786fc4c7366c56f9813d977b.tar.bz2
SMAPI-593723b7940ba72a786fc4c7366c56f9813d977b.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI.Installer/Program.cs')
-rw-r--r--src/SMAPI.Installer/Program.cs69
1 files changed, 67 insertions, 2 deletions
diff --git a/src/SMAPI.Installer/Program.cs b/src/SMAPI.Installer/Program.cs
index 8f328ecf..0ca5aea0 100644
--- a/src/SMAPI.Installer/Program.cs
+++ b/src/SMAPI.Installer/Program.cs
@@ -1,17 +1,82 @@
-namespace StardewModdingApi.Installer
+using System;
+using System.Diagnostics.CodeAnalysis;
+using System.IO;
+using System.IO.Compression;
+using System.Reflection;
+using StardewModdingAPI.Internal;
+using StardewModdingAPI.Toolkit.Utilities;
+
+namespace StardewModdingApi.Installer
{
/// <summary>The entry point for SMAPI's install and uninstall console app.</summary>
internal class Program
{
/*********
+ ** Properties
+ *********/
+ /// <summary>The absolute path of the installer folder.</summary>
+ [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute", Justification = "The assembly location is never null in this context.")]
+ private static readonly string InstallerPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
+
+ /// <summary>The absolute path of the folder containing the unzipped installer files.</summary>
+ private static readonly string ExtractedBundlePath = Path.Combine(Path.GetTempPath(), $"SMAPI-installer-{Guid.NewGuid():N}");
+
+ /// <summary>The absolute path for referenced assemblies.</summary>
+ private static readonly string InternalFilesPath = Path.Combine(Program.ExtractedBundlePath, "smapi-internal");
+
+ /*********
** Public methods
*********/
/// <summary>Run the install or uninstall script.</summary>
/// <param name="args">The command line arguments.</param>
public static void Main(string[] args)
{
- var installer = new InteractiveInstaller();
+ // find install bundle
+ PlatformID platform = Environment.OSVersion.Platform;
+ FileInfo zipFile = new FileInfo(Path.Combine(Program.InstallerPath, $"{(platform == PlatformID.Win32NT ? "windows" : "unix")}-install.dat"));
+ if (!zipFile.Exists)
+ {
+ Console.WriteLine($"Oops! Some of the installer files are missing; try redownloading the installer. (Missing file: {zipFile.FullName})");
+ Console.ReadLine();
+ return;
+ }
+
+ // unzip bundle into temp folder
+ DirectoryInfo bundleDir = new DirectoryInfo(Program.ExtractedBundlePath);
+ Console.WriteLine("Extracting install files...");
+ ZipFile.ExtractToDirectory(zipFile.FullName, bundleDir.FullName);
+
+ // set up assembly resolution
+ AppDomain.CurrentDomain.AssemblyResolve += Program.CurrentDomain_AssemblyResolve;
+
+ // launch installer
+ var installer = new InteractiveInstaller(bundleDir.FullName);
installer.Run(args);
}
+
+ /*********
+ ** Private methods
+ *********/
+ /// <summary>Method called when assembly resolution fails, which may return a manually resolved assembly.</summary>
+ /// <param name="sender">The event sender.</param>
+ /// <param name="e">The event arguments.</param>
+ private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs e)
+ {
+ try
+ {
+ AssemblyName name = new AssemblyName(e.Name);
+ foreach (FileInfo dll in new DirectoryInfo(Program.InternalFilesPath).EnumerateFiles("*.dll"))
+ {
+ if (name.Name.Equals(AssemblyName.GetAssemblyName(dll.FullName).Name, StringComparison.InvariantCultureIgnoreCase))
+ return Assembly.LoadFrom(dll.FullName);
+ }
+ return null;
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"Error resolving assembly: {ex}");
+ return null;
+ }
+ }
}
}