Skip to content

Commit

Permalink
Fix startup crashes if mem not available. Add support for InstallerSu…
Browse files Browse the repository at this point in the history
…pportPacakge.zip
  • Loading branch information
Mgamerz committed Nov 5, 2020
1 parent c40a87c commit afc6d4a
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 49 deletions.
8 changes: 6 additions & 2 deletions ALOTInstallerCore/Helpers/Locations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@ public static void OverrideMEMPath(string forcedPath)
forcedMemPath = forcedPath;
}
#if WINDOWS
public static string MEMPath() => forcedMemPath ?? Path.Combine(AppDataFolder(), @"MassEffectModderNoGui.exe");
public static string MEMPath(bool forceCached = false) => !forceCached ?
forcedMemPath ?? Path.Combine(AppDataFolder(), @"MassEffectModderNoGui.exe") :
Path.Combine(AppDataFolder(), @"MassEffectModderNoGui.exe");
#elif LINUX
public static string MEMPath() => forcedMemPath ?? Path.Combine(AppDataFolder(), @"MassEffectModderNoGui");
public static string MEMPath(bool forceCached = false) => !forceCached ?
forcedMemPath ?? Path.Combine(AppDataFolder(), @"MassEffectModderNoGui.exe") :
Path.Combine(AppDataFolder(), @"MassEffectModderNoGui");
#endif

public static GameTarget ME1Target { get; set; }
Expand Down
28 changes: 28 additions & 0 deletions ALOTInstallerCore/Helpers/MEMIPCHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ALOTInstallerCore.Helpers.AppSettings;
using ALOTInstallerCore.Objects;
using CliWrap;
Expand Down Expand Up @@ -88,6 +89,22 @@ public static void KillAllActiveMEMInstances()
}
}

/// <summary>
/// Tests if MEM is working and available
/// </summary>
/// <returns></returns>
public static bool TestWorkingMEM()
{
try
{
var version = MEMIPCHandler.GetMemVersion(true);
return version > 421;
}
catch (Exception e)
{
return false;
}
}

/// <summary>
/// Returns the version number for MEM, or -1 if it couldn't be retrieved. The result is cached into the variable MassEffectModderNoGuiVerison
Expand Down Expand Up @@ -194,6 +211,17 @@ void memCrashLogOutput(string str)
private static async void RunMEMIPC(string arguments, Action<int> applicationStarted = null, Action<string, string> ipcCallback = null, Action<string> applicationStdErr = null, Action<int> applicationExited = null, Action<string> memCrashLine = null, CancellationToken cancellationToken = default)
{
if (SuppressFurtherMEMLaunches) return;
if (!File.Exists(Locations.MEMPath()))
{
Task.Run(() =>
{
// this is so the locks still work
Thread.Sleep(500);
applicationExited?.Invoke(-1);
});
Log.Error(@"[AICORE] Can't run MassEffectModderNoGui: It doesn't exist! You may need to install the support package since it didn't seem to auto download");
return; //Can't run if it doesn't exist!
}
bool exceptionOcurred = false;
DateTime lastCacheoutput = DateTime.Now;
void internalHandleIPC(string command, string parm)
Expand Down
42 changes: 37 additions & 5 deletions ALOTInstallerWPF/BuilderUI/FileSelectionUIController.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Windows;
Expand All @@ -25,6 +26,7 @@
using Notifications.Wpf.Core;
using Serilog;
using Application = System.Windows.Application;
using ZipFile = System.IO.Compression.ZipFile;

namespace ALOTInstallerWPF.BuilderUI
{
Expand Down Expand Up @@ -193,16 +195,13 @@ public FileSelectionUIController()

}

private async void startPostStartup()
private void startPostStartup()
{


NamedBackgroundWorker nbw = new NamedBackgroundWorker("PostStartup");
nbw.DoWork += async (sender, args) =>
{
try
{
if (ManifestHandler.MasterManifest == null || ManifestHandler.MasterManifest.MusicPackMirrors.Count == 0)
{
// Nothing wae can do.
Expand Down Expand Up @@ -617,7 +616,12 @@ protected override void OnDrop(DragEventArgs e)
else
{
// It's a file
if (TextureLibrary.ImportableFileTypes.Contains(Path.GetExtension(f), StringComparer.InvariantCultureIgnoreCase))

if (Path.GetFileName(f) == "InstallerSupportPackage.zip")
{
IngestSupportPackage(f);
}
else if (TextureLibrary.ImportableFileTypes.Contains(Path.GetExtension(f), StringComparer.InvariantCultureIgnoreCase))
{
// Not supported.
e.Effects = DragDropEffects.None;
Expand All @@ -629,6 +633,34 @@ protected override void OnDrop(DragEventArgs e)
}
}

/// <summary>
/// Installs an archive of supporting files that are typically downloaded
/// </summary>
/// <param name="packagePath"></param>
private async void IngestSupportPackage(string packagePath)
{
Log.Information(@"[AIWPF] Installing support package for the installer");
using ZipArchive za = ZipFile.OpenRead(packagePath);
za.ExtractToDirectory(Locations.AppDataFolder(), true);
if (Application.Current.MainWindow is MainWindow mw)
{
await mw.ShowMessageAsync("Support package installed",
"The support package has been installed. The installer should be restarted.");
}
//// MEM, manifest
//za.Entries.FirstOrDefault(x => x.Name == "MassEffectModderNoGui.exe").ExtractToFile(Locations.MEMPath());
//za.Entries.FirstOrDefault(x => x.Name == "manifest.xml").ExtractToFile(Locations.GetCachedManifestPath());

//// Music pack
//var me1Mp3Entry = za.Entries.FirstOrDefault(x => x.Name == "me1.mp3");
//var me2Mp3Entry = za.Entries.FirstOrDefault(x => x.Name == "me2.mp3");
//var me3Mp3Entry = za.Entries.FirstOrDefault(x => x.Name == "me3.mp3");
//me1Mp3Entry?.ExtractToFile(Path.Combine(Locations.MusicDirectory, "me1.mp3"));
//me2Mp3Entry?.ExtractToFile(Path.Combine(Locations.MusicDirectory, "me2.mp3"));
//me3Mp3Entry?.ExtractToFile(Path.Combine(Locations.MusicDirectory, "me3.mp3"));

}

private void attemptImportFolder(string folderPath)
{
if (Application.Current.MainWindow is MainWindow mw)
Expand Down
97 changes: 55 additions & 42 deletions ALOTInstallerWPF/BuilderUI/StartupUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,70 +226,77 @@ void downloadProgressChanged(long bytes, long total)
void errorUpdating(Exception e)
{
Log.Error($@"[AIWPF] Error updating MEM: {e.Message}");
// ?? What do we do here.
}
pd.SetMessage("Checking for MassEffectModderNoGui updates");
MEMUpdater.UpdateMEM(downloadProgressChanged, errorUpdating, setStatus);
pd.SetMessage("Loading installer framework");
handleM3Passthrough();
ALOTInstallerCoreLib.PostCriticalStartup(x => pd.SetMessage(x), RunOnUIThread);
BackupService.RefreshBackupStatus(Locations.GetAllAvailableTargets(), false);
pd.SetMessage("Loading installer manifests");
var alotManifestModePackage = ManifestHandler.LoadMasterManifest(x => pd.SetMessage(x));
void setStatus(string message)
{
pd.SetIndeterminate();
pd.SetMessage(message);
}
b.Result = alotManifestModePackage;
pd.SetMessage("Checking for MassEffectModderNoGui updates");
MEMUpdater.UpdateMEM(downloadProgressChanged, errorUpdating, setStatus);
if (ManifestHandler.MasterManifest != null)
try
{
ManifestHandler.SetCurrentMode(ManifestHandler.GetDefaultMode());
pd.SetMessage("Preparing texture library");
foreach (var v in ManifestHandler.MasterManifest.ManifestModePackageMappping)
pd.SetMessage("Loading installer framework");
handleM3Passthrough();
ALOTInstallerCoreLib.PostCriticalStartup(x => pd.SetMessage(x), RunOnUIThread);
BackupService.RefreshBackupStatus(Locations.GetAllAvailableTargets(), false);
pd.SetMessage("Loading installer manifests");
var alotManifestModePackage = ManifestHandler.LoadMasterManifest(x => pd.SetMessage(x));
b.Result = alotManifestModePackage;
if (ManifestHandler.MasterManifest != null)
{
TextureLibrary.ResetAllReadyStatuses(ManifestHandler.GetManifestFilesForMode(v.Key));
ManifestHandler.SetCurrentMode(ManifestHandler.GetDefaultMode());
pd.SetMessage("Preparing texture library");
foreach (var v in ManifestHandler.MasterManifest.ManifestModePackageMappping)
{
TextureLibrary.ResetAllReadyStatuses(ManifestHandler.GetManifestFilesForMode(v.Key));
}
}
else
{
// This shouldn't happen...
}
}
else
{
// This shouldn't happen...
}
pd.SetMessage("Performing startup checks");
StartupCheck.PerformStartupCheck((title, message) =>
{
object o = new object();
Application.Current.Dispatcher.Invoke(async () =>
pd.SetMessage("Performing startup checks");
StartupCheck.PerformStartupCheck((title, message) =>
{
if (Application.Current.MainWindow is MainWindow mw)
object o = new object();
Application.Current.Dispatcher.Invoke(async () =>
{
await mw.ShowMessageAsync(title, message, ContentWidthPercent: 75);
lock (o)
if (Application.Current.MainWindow is MainWindow mw)
{
Monitor.Pulse(o);
await mw.ShowMessageAsync(title, message, ContentWidthPercent: 75);
lock (o)
{
Monitor.Pulse(o);
}
}
});
lock (o)
{
Monitor.Wait(o);
}
});
lock (o)
{
Monitor.Wait(o);
}
}, x => pd.SetMessage(x));
}, x => pd.SetMessage(x));
}
catch (Exception e)
{
Log.Error(@"[AIWPF] There was an error starting up the installer!");
e.WriteToLog("[AIWPF] ");
}
pd.SetMessage("Preparing interface");
var hasWorkingMEM = MEMIPCHandler.TestWorkingMEM();
Thread.Sleep(250); // This will allow this message to show up for moment so user can see it.
Application.Current.Dispatcher.Invoke(() =>
Application.Current.Dispatcher.Invoke(async () =>
{
if (Application.Current.MainWindow is MainWindow mw)
{
Expand All @@ -299,6 +306,12 @@ void setStatus(string message)
mw.DiagnosticsFlyoutControl.Content = new DiagnosticsFlyout();
mw.FileImporterFlyoutContent = new FileImporterFlyout();
mw.LODSwitcherFlyout.Content = mw.LODSwitcherFlyoutContent = new LODSwitcherFlyout();
if (!hasWorkingMEM)
{
await mw.ShowMessageAsync("Required components are not available",
"Some components for installation are not available, likely due to network issues (blocking, no internet, etc). To install these components, download the 'Installer Support Package' from the ALOT page on NexusMods. Drag the downloaded zip file onto this window once you have closed this dialog.",
ContentWidthPercent: 75);
}
}
});
};
Expand Down

0 comments on commit afc6d4a

Please sign in to comment.