stop patching exe files

This commit is contained in:
Timothy Baldridge 2019-09-26 22:07:54 -06:00
parent 7c4c2a586c
commit f82d6a39f7
12 changed files with 212 additions and 76 deletions

View File

@ -2,7 +2,8 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Wabbajack" xmlns:local="clr-namespace:Wabbajack"
StartupUri="MainWindow.xaml"> StartupUri="ModeSelectionWindow.xaml"
ShutdownMode="OnExplicitShutdown">
<Application.Resources> <Application.Resources>
<ResourceDictionary> <ResourceDictionary>
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>

View File

@ -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 public string ModListName
{ {
get => _modListName; get => _modListName;
@ -360,7 +338,7 @@ namespace Wabbajack
private void UpdateLoop() private void UpdateLoop()
{ {
while (true) while (Running)
{ {
if (Dirty) if (Dirty)
lock (InternalStatus) lock (InternalStatus)
@ -399,6 +377,8 @@ namespace Wabbajack
} }
} }
public bool Running { get; set; } = true;
internal void ConfigureForInstall(ModList modlist) internal void ConfigureForInstall(ModList modlist)
{ {
_modList = modlist; _modList = modlist;
@ -503,7 +483,6 @@ namespace Wabbajack
{ {
var installer = new Installer(_modList, Location); var installer = new Installer(_modList, Location);
installer.IgnoreMissingFiles = IgnoreMissingFiles;
installer.DownloadFolder = DownloadLocation; installer.DownloadFolder = DownloadLocation;
var th = new Thread(() => var th = new Thread(() =>
{ {
@ -530,7 +509,6 @@ namespace Wabbajack
else if (_mo2Folder != null) else if (_mo2Folder != null)
{ {
var compiler = new Compiler(_mo2Folder); var compiler = new Compiler(_mo2Folder);
compiler.IgnoreMissingFiles = IgnoreMissingFiles;
compiler.MO2Profile = ModListName; compiler.MO2Profile = ModListName;
var th = new Thread(() => var th = new Thread(() =>
{ {

View File

@ -246,16 +246,34 @@ namespace Wabbajack
}; };
GenerateReport(); GenerateReport();
PatchExecutable(); ExportModlist();
ResetMembers(); ResetMembers();
ShowReport(); ShowReport();
Info("Done Building Modpack"); Info("Done Building Modlist");
return true; 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() private void ShowReport()
{ {
if (!ShowReportWhenFinished) return; if (!ShowReportWhenFinished) return;
@ -1141,15 +1159,6 @@ namespace Wabbajack
{ {
var orig_pos = os.Length; var orig_pos = os.Length;
os.Position = 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(); var formatter = new BinaryFormatter();
using (var compressed = LZ4Stream.Encode(bw.BaseStream, using (var compressed = LZ4Stream.Encode(bw.BaseStream,

View File

@ -357,7 +357,10 @@ namespace Wabbajack
vfiles.DoIndexed((idx, file) => vfiles.DoIndexed((idx, file) =>
{ {
Utils.Status("Installing files", idx * 100 / vfiles.Count); 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"); Status("Unstaging files");
@ -578,7 +581,7 @@ namespace Wabbajack
{ {
var read = webs.Read(buffer, 0, buffer_size); var read = webs.Read(buffer, 0, buffer_size);
if (read == 0) break; 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); fs.Write(buffer, 0, read);
total_read += read; total_read += read;
@ -618,33 +621,30 @@ namespace Wabbajack
return HashArchive(e); return HashArchive(e);
} }
public static ModList CheckForModList() public static ModList LoadModlist(string file)
{ {
Utils.Log("Looking for attached modlist"); Utils.Log("Reading Modlist, this may take a moment");
using (var s = File.OpenRead(Assembly.GetExecutingAssembly().Location)) try
{ {
var magic_bytes = Encoding.ASCII.GetBytes(Consts.ModListMagic); using (var s = File.OpenRead(file))
s.Position = s.Length - magic_bytes.Length;
using (var br = new BinaryReader(s))
{ {
var bytes = br.ReadBytes(magic_bytes.Length); using (var br = new BinaryReader(s))
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))
{ {
IFormatter formatter = new BinaryFormatter(); using (var dc = LZ4Stream.Decode(br.BaseStream, leaveOpen: true))
var list = formatter.Deserialize(dc); {
Utils.Log("Modlist loaded."); IFormatter formatter = new BinaryFormatter();
return (ModList) list; var list = formatter.Deserialize(dc);
Utils.Log("Modlist loaded.");
return (ModList) list;
}
} }
} }
} }
catch (Exception)
{
Utils.Log("Error Loading modlist");
return null;
}
} }
} }
} }

View File

@ -115,6 +115,5 @@
<Button Content="View Modlist Contents" Grid.Row="5" Grid.Column="1" Height="30" Visibility="{Binding ShowReportButton}" <Button Content="View Modlist Contents" Grid.Row="5" Grid.Column="1" Height="30" Visibility="{Binding ShowReportButton}"
Command="{Binding ShowReportCommand}" Margin="10" /> Command="{Binding ShowReportCommand}" Margin="10" />
<Button Content="Begin" Grid.Row="6" Height="30" Grid.Column="1" Command="{Binding Begin}" IsEnabled="{Binding UIReady}" Margin="10"/> <Button Content="Begin" Grid.Row="6" Height="30" Grid.Column="1" Command="{Binding Begin}" IsEnabled="{Binding UIReady}" Margin="10"/>
<CheckBox Content="Ignore Missing Files" Grid.Row="7" Height="20" IsChecked="{Binding IgnoreMissingFiles}" IsEnabled="{Binding UIReady}" Visibility="Collapsed"/>
</Grid> </Grid>
</Window> </Window>

View File

@ -2,7 +2,11 @@
using System.ComponentModel; using System.ComponentModel;
using System.Threading; using System.Threading;
using System.Windows; using System.Windows;
using System.Windows.Forms;
using Alphaleonis.Win32.Filesystem;
using Wabbajack.Common; using Wabbajack.Common;
using Application = System.Windows.Application;
using MessageBox = System.Windows.MessageBox;
namespace Wabbajack namespace Wabbajack
{ {
@ -13,20 +17,18 @@ namespace Wabbajack
{ {
private AppState _state; private AppState _state;
public MainWindow() public enum RunMode
{
Compile,
Install
}
public MainWindow(RunMode mode, string source)
{ {
var args = Environment.GetCommandLineArgs(); var args = Environment.GetCommandLineArgs();
var DebugMode = false; var DebugMode = false;
string MO2Folder = null, InstallFolder = null, MO2Profile = null; string MO2Folder = null, InstallFolder = null, MO2Profile = null;
if (args.Length > 1)
{
DebugMode = true;
MO2Folder = args[1];
MO2Profile = args[2];
InstallFolder = args[3];
}
InitializeComponent(); InitializeComponent();
var context = new AppState(Dispatcher, "Building"); var context = new AppState(Dispatcher, "Building");
@ -44,12 +46,36 @@ namespace Wabbajack
new Thread(() => new Thread(() =>
{ {
context.UIReady = false; if (mode == RunMode.Compile)
var modlist = Installer.CheckForModList(); {
if (modlist == null) Utils.Log("Compiler ready to execute");
Utils.Log("No Modlist found, running in Compiler mode."); context.Location = Path.GetDirectoryName(source);
else }
context.ConfigureForInstall(modlist); else if (mode == RunMode.Install)
{
context.UIReady = false;
var modlist = Installer.LoadModlist(source);
if (modlist == null)
{
MessageBox.Show("Invalid Modlist, or file not found.", "Invalid Modlist", MessageBoxButton.OK,
MessageBoxImage.Error);
Dispatcher.Invoke(() =>
{
context.Running = false;
ExitWhenClosing = false;
var window = new ModeSelectionWindow();
window.ShowActivated = true;
window.Show();
Close();
});
}
else
{
context.ConfigureForInstall(modlist);
}
}
context.UIReady = true; context.UIReady = true;
}).Start(); }).Start();
} }
@ -66,9 +92,13 @@ namespace Wabbajack
_state.LogMsg(((Exception) e.ExceptionObject).ExceptionToString()); _state.LogMsg(((Exception) e.ExceptionObject).ExceptionToString());
} }
internal bool ExitWhenClosing = true;
private void Window_Closing(object sender, CancelEventArgs e) private void Window_Closing(object sender, CancelEventArgs e)
{ {
Application.Current.Shutdown(); if (ExitWhenClosing)
Application.Current.Shutdown();
} }
} }
} }

View File

@ -0,0 +1,25 @@
<Window x:Class="Wabbajack.ModeSelectionWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Style="{StaticResource {x:Type Window}}" Icon="square_transparent_icon.ico" WindowStyle="ToolWindow"
xmlns:local="clr-namespace:Wabbajack"
mc:Ignorable="d"
Title="ModeSelectionWindow" Height="450" Width="800" ResizeMode="NoResize"
Closing="Close_Window">
<Grid Margin="20">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition Height="70"></RowDefinition>
<RowDefinition Height="70"></RowDefinition>
</Grid.RowDefinitions>
<Image Name="Banner"></Image>
<Button Name="InstallModlist" Grid.Row="1" Margin="2" Click="InstallModlist_Click">
<TextBlock FontSize="40">Install a ModList</TextBlock>
</Button>
<Button Name="CreateModlist" Grid.Row="2" Margin="2" Click="CreateModlist_Click">
<TextBlock FontSize="40">Create a ModList</TextBlock>
</Button>
</Grid>
</Window>

View File

@ -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
{
/// <summary>
/// Interaction logic for ModeSelectionWindow.xaml
/// </summary>
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;
}
}

View File

@ -6,6 +6,8 @@ using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Media.Imaging;
using System.Windows.Threading; using System.Windows.Threading;
using Microsoft.WindowsAPICodePack.Dialogs; using Microsoft.WindowsAPICodePack.Dialogs;
using Wabbajack.Common; using Wabbajack.Common;
@ -62,6 +64,24 @@ namespace Wabbajack
return null; 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; } public static Dispatcher Dispatcher { get; set; }
} }
} }

View File

@ -182,6 +182,9 @@
</ApplicationDefinition> </ApplicationDefinition>
<Compile Include="Data.cs" /> <Compile Include="Data.cs" />
<Compile Include="LambdaCommand.cs" /> <Compile Include="LambdaCommand.cs" />
<Compile Include="ModeSelectionWindow.xaml.cs">
<DependentUpon>ModeSelectionWindow.xaml</DependentUpon>
</Compile>
<Compile Include="ReportBuilder.cs" /> <Compile Include="ReportBuilder.cs" />
<Compile Include="Themes\LeftMarginMultiplierConverter.cs" /> <Compile Include="Themes\LeftMarginMultiplierConverter.cs" />
<Compile Include="Themes\TreeViewItemExtensions.cs" /> <Compile Include="Themes\TreeViewItemExtensions.cs" />
@ -203,6 +206,10 @@
<DependentUpon>MainWindow.xaml</DependentUpon> <DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Page Include="ModeSelectionWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Themes\Styles.xaml"> <Page Include="Themes\Styles.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
@ -274,6 +281,9 @@
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="banner.png" /> <EmbeddedResource Include="banner.png" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<EmbeddedResource Include="banner_small.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Fody.5.1.1\build\Fody.targets" Condition="Exists('..\packages\Fody.5.1.1\build\Fody.targets')" /> <Import Project="..\packages\Fody.5.1.1\build\Fody.targets" Condition="Exists('..\packages\Fody.5.1.1\build\Fody.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

BIN
Wabbajack/banner_small.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 KiB

BIN
logos/banner_small.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 KiB