diff --git a/Wabbajack/App.xaml b/Wabbajack/App.xaml index 9dd43ac8..245efda8 100644 --- a/Wabbajack/App.xaml +++ b/Wabbajack/App.xaml @@ -2,7 +2,8 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Wabbajack" - StartupUri="MainWindow.xaml"> + StartupUri="ModeSelectionWindow.xaml" + ShutdownMode="OnExplicitShutdown"> diff --git a/Wabbajack/AppState.cs b/Wabbajack/AppState.cs index ea1f9449..208a5ba1 100644 --- a/Wabbajack/AppState.cs +++ b/Wabbajack/AppState.cs @@ -116,28 +116,6 @@ namespace Wabbajack } } - public bool IgnoreMissingFiles - { - get => _ignoreMissingFiles; - set - { - if (value) - { - if (MessageBox.Show( - "Setting this value could result in broken installations. \n Are you sure you want to continue?", - "Ignore Missing Files?", MessageBoxButton.OKCancel, MessageBoxImage.Warning) - == MessageBoxResult.OK) - _ignoreMissingFiles = value; - } - else - { - _ignoreMissingFiles = value; - } - - OnPropertyChanged("IgnoreMissingFiles"); - } - } - public string ModListName { get => _modListName; @@ -360,7 +338,7 @@ namespace Wabbajack private void UpdateLoop() { - while (true) + while (Running) { if (Dirty) lock (InternalStatus) @@ -399,6 +377,8 @@ namespace Wabbajack } } + public bool Running { get; set; } = true; + internal void ConfigureForInstall(ModList modlist) { _modList = modlist; @@ -503,7 +483,6 @@ namespace Wabbajack { var installer = new Installer(_modList, Location); - installer.IgnoreMissingFiles = IgnoreMissingFiles; installer.DownloadFolder = DownloadLocation; var th = new Thread(() => { @@ -530,7 +509,6 @@ namespace Wabbajack else if (_mo2Folder != null) { var compiler = new Compiler(_mo2Folder); - compiler.IgnoreMissingFiles = IgnoreMissingFiles; compiler.MO2Profile = ModListName; var th = new Thread(() => { diff --git a/Wabbajack/Compiler.cs b/Wabbajack/Compiler.cs index c2d808c7..3c62ef23 100644 --- a/Wabbajack/Compiler.cs +++ b/Wabbajack/Compiler.cs @@ -246,16 +246,34 @@ namespace Wabbajack }; GenerateReport(); - PatchExecutable(); + ExportModlist(); ResetMembers(); ShowReport(); - Info("Done Building Modpack"); + Info("Done Building Modlist"); return true; } + private void ExportModlist() + { + var out_path = MO2Profile + ".modlist"; + + Utils.Log($"Exporting Modlist to : {out_path}"); + + using (var os = File.OpenWrite(out_path)) + using (var bw = new BinaryWriter(os)) + { + var formatter = new BinaryFormatter(); + using (var compressed = LZ4Stream.Encode(bw.BaseStream, + new LZ4EncoderSettings { CompressionLevel = LZ4Level.L10_OPT }, true)) + { + formatter.Serialize(compressed, ModList); + } + } + } + private void ShowReport() { if (!ShowReportWhenFinished) return; @@ -1141,15 +1159,6 @@ namespace Wabbajack { var orig_pos = os.Length; os.Position = os.Length; - //using (var compressor = new BZip2OutputStream(bw.BaseStream)) - /*using (var sw = new StreamWriter(compressor)) - using (var writer = new JsonTextWriter(sw)) - { - var serializer = new JsonSerializer(); - serializer.TypeNameHandling = TypeNameHandling.Auto; - serializer.Serialize(writer, ModList); - }*/ - //bw.Write(data); var formatter = new BinaryFormatter(); using (var compressed = LZ4Stream.Encode(bw.BaseStream, diff --git a/Wabbajack/Installer.cs b/Wabbajack/Installer.cs index bcc7bf5a..41a362a4 100644 --- a/Wabbajack/Installer.cs +++ b/Wabbajack/Installer.cs @@ -357,7 +357,10 @@ namespace Wabbajack vfiles.DoIndexed((idx, file) => { Utils.Status("Installing files", idx * 100 / vfiles.Count); - File.Copy(file.FromFile.StagedPath, Path.Combine(Outputfolder, file.To)); + var dest = Path.Combine(Outputfolder, file.To); + if (File.Exists(dest)) + File.Delete(dest); + File.Copy(file.FromFile.StagedPath, dest); }); Status("Unstaging files"); @@ -578,7 +581,7 @@ namespace Wabbajack { var read = webs.Read(buffer, 0, buffer_size); if (read == 0) break; - Status("Downloading {archive.Name}", (int)(total_read * 100 / content_size)); + Status($"Downloading {archive.Name}", (int)(total_read * 100 / content_size)); fs.Write(buffer, 0, read); total_read += read; @@ -618,33 +621,30 @@ namespace Wabbajack return HashArchive(e); } - public static ModList CheckForModList() + public static ModList LoadModlist(string file) { - Utils.Log("Looking for attached modlist"); - using (var s = File.OpenRead(Assembly.GetExecutingAssembly().Location)) + Utils.Log("Reading Modlist, this may take a moment"); + try { - var magic_bytes = Encoding.ASCII.GetBytes(Consts.ModListMagic); - s.Position = s.Length - magic_bytes.Length; - using (var br = new BinaryReader(s)) + using (var s = File.OpenRead(file)) { - var bytes = br.ReadBytes(magic_bytes.Length); - var magic = Encoding.ASCII.GetString(bytes); - - if (magic != Consts.ModListMagic) return null; - - s.Position = s.Length - magic_bytes.Length - 8; - var start_pos = br.ReadInt64(); - s.Position = start_pos; - Utils.Log("Modlist found, loading..."); - using (var dc = LZ4Stream.Decode(br.BaseStream, leaveOpen: true)) + using (var br = new BinaryReader(s)) { - IFormatter formatter = new BinaryFormatter(); - var list = formatter.Deserialize(dc); - Utils.Log("Modlist loaded."); - return (ModList) list; + using (var dc = LZ4Stream.Decode(br.BaseStream, leaveOpen: true)) + { + IFormatter formatter = new BinaryFormatter(); + var list = formatter.Deserialize(dc); + Utils.Log("Modlist loaded."); + return (ModList) list; + } } } } + catch (Exception) + { + Utils.Log("Error Loading modlist"); + return null; + } } } } diff --git a/Wabbajack/MainWindow.xaml b/Wabbajack/MainWindow.xaml index 613b8084..22b0407f 100644 --- a/Wabbajack/MainWindow.xaml +++ b/Wabbajack/MainWindow.xaml @@ -115,6 +115,5 @@ + + + diff --git a/Wabbajack/ModeSelectionWindow.xaml.cs b/Wabbajack/ModeSelectionWindow.xaml.cs new file mode 100644 index 00000000..844773ab --- /dev/null +++ b/Wabbajack/ModeSelectionWindow.xaml.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; +using static Wabbajack.MainWindow; + +namespace Wabbajack +{ + /// + /// Interaction logic for ModeSelectionWindow.xaml + /// + public partial class ModeSelectionWindow : Window + { + public ModeSelectionWindow() + { + InitializeComponent(); + var img = UIUtils.BitmapImageFromResource("Wabbajack.banner_small.png"); + Banner.Source = img; + } + + private void CreateModlist_Click(object sender, RoutedEventArgs e) + { + var file = UIUtils.OpenFileDialog("MO2 Modlist(modlist.txt)|modlist.txt"); + if (file != null) + { + ShutdownOnClose = false; + new MainWindow(RunMode.Compile, file).Show(); + Close(); + } + } + + private void InstallModlist_Click(object sender, RoutedEventArgs e) + { + var file = UIUtils.OpenFileDialog("Wabbajack Modlist (*.modlist)|*.modlist"); + if (file != null) + { + ShutdownOnClose = false; + new MainWindow(RunMode.Install, file).Show(); + Close(); + } + } + + + + public void Close_Window(object sender, CancelEventArgs e) + { + if (ShutdownOnClose) + Application.Current.Shutdown(); + } + + public bool ShutdownOnClose { get; set; } = true; + } +} diff --git a/Wabbajack/UIUtils.cs b/Wabbajack/UIUtils.cs index 1b4652d7..bcc9c10e 100644 --- a/Wabbajack/UIUtils.cs +++ b/Wabbajack/UIUtils.cs @@ -6,6 +6,8 @@ using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading; using System.Threading.Tasks; +using System.Windows.Forms; +using System.Windows.Media.Imaging; using System.Windows.Threading; using Microsoft.WindowsAPICodePack.Dialogs; using Wabbajack.Common; @@ -62,6 +64,24 @@ namespace Wabbajack return null; } + public static BitmapImage BitmapImageFromResource(string name) + { + var img = new BitmapImage(); + img.BeginInit(); + img.StreamSource = Assembly.GetExecutingAssembly().GetManifestResourceStream(name); + img.EndInit(); + return img; + } + + public static string OpenFileDialog(string filter) + { + OpenFileDialog ofd = new OpenFileDialog(); + ofd.Filter = filter; + if (ofd.ShowDialog() == DialogResult.OK) + return ofd.FileName; + return null; + } + public static Dispatcher Dispatcher { get; set; } } } diff --git a/Wabbajack/Wabbajack.csproj b/Wabbajack/Wabbajack.csproj index 3d4e89a7..23c7b7a8 100644 --- a/Wabbajack/Wabbajack.csproj +++ b/Wabbajack/Wabbajack.csproj @@ -182,6 +182,9 @@ + + ModeSelectionWindow.xaml + @@ -203,6 +206,10 @@ MainWindow.xaml Code + + Designer + MSBuild:Compile + MSBuild:Compile Designer @@ -274,6 +281,9 @@ + + + diff --git a/Wabbajack/banner_small.png b/Wabbajack/banner_small.png new file mode 100644 index 00000000..e1b067e0 Binary files /dev/null and b/Wabbajack/banner_small.png differ diff --git a/logos/banner_small.png b/logos/banner_small.png new file mode 100644 index 00000000..e1b067e0 Binary files /dev/null and b/logos/banner_small.png differ