From 12a6b12a6554565195ed8a4439637b1d6b863d89 Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Tue, 30 Jul 2019 21:59:19 -0600 Subject: [PATCH] Tons of GUI work --- Wabbajack.Common/Utils.cs | 12 +- Wabbajack.sln | 11 + Wabbajack/AppState.cs | 128 +- Wabbajack/Compiler.cs | 3 +- Wabbajack/Installer.cs | 28 + Wabbajack/LambdaCommand.cs | 29 + Wabbajack/MainWindow.xaml | 21 +- Wabbajack/MainWindow.xaml.cs | 58 +- .../Themes/LeftMarginMultiplierConverter.cs | 31 + Wabbajack/Themes/Styles.xaml | 3096 +++++++++++++++++ Wabbajack/Themes/TreeViewItemExtensions.cs | 38 + Wabbajack/Wabbajack.csproj | 18 + Wabbajack/Wabbajack.csproj.user | 10 + Wabbajack/packages.config | 1 + 14 files changed, 3460 insertions(+), 24 deletions(-) create mode 100644 Wabbajack/LambdaCommand.cs create mode 100644 Wabbajack/Themes/LeftMarginMultiplierConverter.cs create mode 100644 Wabbajack/Themes/Styles.xaml create mode 100644 Wabbajack/Themes/TreeViewItemExtensions.cs create mode 100644 Wabbajack/Wabbajack.csproj.user diff --git a/Wabbajack.Common/Utils.cs b/Wabbajack.Common/Utils.cs index c81fa061..0f91348d 100644 --- a/Wabbajack.Common/Utils.cs +++ b/Wabbajack.Common/Utils.cs @@ -87,9 +87,19 @@ namespace Wabbajack.Common File.WriteAllText(filename, JsonConvert.SerializeObject(obj, Formatting.Indented, new JsonSerializerSettings() {TypeNameHandling = TypeNameHandling.Auto})); } + public static string ToJSON(this T obj) + { + return JsonConvert.SerializeObject(obj, Formatting.Indented, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Auto }); + } + public static T FromJSON(this string filename) { - return JsonConvert.DeserializeObject(File.ReadAllText(filename)); + return JsonConvert.DeserializeObject(File.ReadAllText(filename), new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Auto }); + } + + public static T FromJSONString(this string data) + { + return JsonConvert.DeserializeObject(data, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Auto }); } public static T FromJSON(this Stream data) { diff --git a/Wabbajack.sln b/Wabbajack.sln index 17891ae9..295813b4 100644 --- a/Wabbajack.sln +++ b/Wabbajack.sln @@ -21,26 +21,37 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug (no commandargs)|Any CPU = Debug (no commandargs)|Any CPU Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B3F3FB6E-B9EB-4F49-9875-D78578BC7AE5}.Debug (no commandargs)|Any CPU.ActiveCfg = Debug|Any CPU + {B3F3FB6E-B9EB-4F49-9875-D78578BC7AE5}.Debug (no commandargs)|Any CPU.Build.0 = Debug|Any CPU {B3F3FB6E-B9EB-4F49-9875-D78578BC7AE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B3F3FB6E-B9EB-4F49-9875-D78578BC7AE5}.Debug|Any CPU.Build.0 = Debug|Any CPU {B3F3FB6E-B9EB-4F49-9875-D78578BC7AE5}.Release|Any CPU.ActiveCfg = Release|Any CPU {B3F3FB6E-B9EB-4F49-9875-D78578BC7AE5}.Release|Any CPU.Build.0 = Release|Any CPU + {8AA97F58-5044-4BBA-B8D9-A74B6947A660}.Debug (no commandargs)|Any CPU.ActiveCfg = Debug|Any CPU + {8AA97F58-5044-4BBA-B8D9-A74B6947A660}.Debug (no commandargs)|Any CPU.Build.0 = Debug|Any CPU {8AA97F58-5044-4BBA-B8D9-A74B6947A660}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8AA97F58-5044-4BBA-B8D9-A74B6947A660}.Debug|Any CPU.Build.0 = Debug|Any CPU {8AA97F58-5044-4BBA-B8D9-A74B6947A660}.Release|Any CPU.ActiveCfg = Release|Any CPU {8AA97F58-5044-4BBA-B8D9-A74B6947A660}.Release|Any CPU.Build.0 = Release|Any CPU + {33602679-8484-40C7-A10C-774DFF5D8314}.Debug (no commandargs)|Any CPU.ActiveCfg = Debug (no commandargs)|Any CPU + {33602679-8484-40C7-A10C-774DFF5D8314}.Debug (no commandargs)|Any CPU.Build.0 = Debug (no commandargs)|Any CPU {33602679-8484-40C7-A10C-774DFF5D8314}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {33602679-8484-40C7-A10C-774DFF5D8314}.Debug|Any CPU.Build.0 = Debug|Any CPU {33602679-8484-40C7-A10C-774DFF5D8314}.Release|Any CPU.ActiveCfg = Release|Any CPU {33602679-8484-40C7-A10C-774DFF5D8314}.Release|Any CPU.Build.0 = Release|Any CPU + {FF5D892F-8FF4-44FC-8F7F-CD58F307AD1B}.Debug (no commandargs)|Any CPU.ActiveCfg = Debug|Any CPU + {FF5D892F-8FF4-44FC-8F7F-CD58F307AD1B}.Debug (no commandargs)|Any CPU.Build.0 = Debug|Any CPU {FF5D892F-8FF4-44FC-8F7F-CD58F307AD1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {FF5D892F-8FF4-44FC-8F7F-CD58F307AD1B}.Debug|Any CPU.Build.0 = Debug|Any CPU {FF5D892F-8FF4-44FC-8F7F-CD58F307AD1B}.Release|Any CPU.ActiveCfg = Release|Any CPU {FF5D892F-8FF4-44FC-8F7F-CD58F307AD1B}.Release|Any CPU.Build.0 = Release|Any CPU + {BA2CFEA1-072B-42D6-822A-8C6D0E3AE5D9}.Debug (no commandargs)|Any CPU.ActiveCfg = Debug|Any CPU + {BA2CFEA1-072B-42D6-822A-8C6D0E3AE5D9}.Debug (no commandargs)|Any CPU.Build.0 = Debug|Any CPU {BA2CFEA1-072B-42D6-822A-8C6D0E3AE5D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {BA2CFEA1-072B-42D6-822A-8C6D0E3AE5D9}.Debug|Any CPU.Build.0 = Debug|Any CPU {BA2CFEA1-072B-42D6-822A-8C6D0E3AE5D9}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/Wabbajack/AppState.cs b/Wabbajack/AppState.cs index e79902a0..181083cd 100644 --- a/Wabbajack/AppState.cs +++ b/Wabbajack/AppState.cs @@ -5,6 +5,8 @@ using System.ComponentModel; using System.IO; using System.Reflection; using System.Threading; +using System.Windows; +using System.Windows.Input; using System.Windows.Threading; using Wabbajack.Common; @@ -48,8 +50,11 @@ namespace Wabbajack } } - + private string _mo2Folder; private string _modListName; + private ModList _modList; + private string _location; + public string ModListName { get @@ -63,6 +68,19 @@ namespace Wabbajack } } + public string Location + { + get + { + return _location; + } + set + { + _location = value; + OnPropertyChanged("Location"); + } + } + private List InternalStatus { get; } public string LogFile { get; private set; } @@ -113,6 +131,16 @@ namespace Wabbajack } } + internal void ConfigureForInstall(string modlist) + { + MessageBox.Show("Hello, world!"); + _modList = modlist.FromJSONString(); + Mode = "Installing"; + ModListName = _modList.Name; + Location = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + + } + public void LogMsg(string msg) { dispatcher.Invoke(() => Log.Add(msg)); @@ -134,5 +162,103 @@ namespace Wabbajack InternalStatus[id] = new CPUStatus() { ID = id, Msg = msg, Progress = progress }; } } + + private ICommand _changePath; + public ICommand ChangePath + { + get + { + if (_changePath == null) + { + _changePath = new LambdaCommand(() => true, () => this.ExecuteChangePath()); + } + return _changePath; + } + } + + private void ExecuteChangePath() + { + if (Mode == "Installing") + { + var ofd = new Ookii.Dialogs.Wpf.VistaFolderBrowserDialog(); + ofd.Description = "Select Installation Directory"; + ofd.UseDescriptionForTitle = true; + if (ofd.ShowDialog() == true) + { + Location = ofd.SelectedPath; + } + } + else + { + var fsd = new Ookii.Dialogs.Wpf.VistaOpenFileDialog(); + fsd.Title = "Select a ModOrganizer modlist.txt file"; + fsd.Filter = "modlist.txt|modlist.txt"; + if (fsd.ShowDialog() == true) + { + Location = fsd.FileName; + ConfigureForBuild(); + } + } + } + + private void ConfigureForBuild() + { + var profile_folder = Path.GetDirectoryName(Location); + var mo2folder = Path.GetDirectoryName(Path.GetDirectoryName(profile_folder)); + if (!File.Exists(Path.Combine(mo2folder, "ModOrganizer.exe"))) + LogMsg($"Error! No ModOrganizer2.exe found in {mo2folder}"); + + var profile_name = Path.GetFileName(profile_folder); + ModListName = profile_name; + Mode = "Building"; + _mo2Folder = mo2folder; + } + + private ICommand _begin; + public ICommand Begin + { + get + { + if (_begin == null) + { + _begin = new LambdaCommand(() => true, () => this.ExecuteBegin()); + } + return _begin; + } + } + + private void ExecuteBegin() + { + if (Mode == "Installing") + { + var installer = new Installer(_modList, Location, msg => this.LogMsg(msg)); + var th = new Thread(() => + { + try + { + installer.Install(); + } + catch (Exception ex) + { + LogMsg(ex.ToString()); + LogMsg(ex.StackTrace); + } + }); + th.Priority = ThreadPriority.BelowNormal; + th.Start(); + } + else + { + var compiler = new Compiler(_mo2Folder, msg => LogMsg(msg)); + compiler.MO2Profile = ModListName; + var th = new Thread(() => + { + compiler.LoadArchives(); + compiler.Compile(); + }); + th.Priority = ThreadPriority.BelowNormal; + th.Start(); + } + } } } \ No newline at end of file diff --git a/Wabbajack/Compiler.cs b/Wabbajack/Compiler.cs index 17b9a750..f654e959 100644 --- a/Wabbajack/Compiler.cs +++ b/Wabbajack/Compiler.cs @@ -732,7 +732,8 @@ namespace Wabbajack internal void PatchExecutable() { - var data = JsonConvert.SerializeObject(ModList).BZip2String(); + var settings = new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Auto }; + var data = JsonConvert.SerializeObject(ModList, settings).BZip2String(); var executable = Assembly.GetExecutingAssembly().Location; var out_path = Path.Combine(Path.GetDirectoryName(executable), MO2Profile + ".exe"); Info("Patching Executable {0}", Path.GetFileName(out_path)); diff --git a/Wabbajack/Installer.cs b/Wabbajack/Installer.cs index 9871e233..7796cb0f 100644 --- a/Wabbajack/Installer.cs +++ b/Wabbajack/Installer.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Http; +using System.Reflection; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; @@ -347,5 +348,32 @@ namespace Wabbajack } + public static string CheckForModPack() + { + using (var s = File.OpenRead(Assembly.GetExecutingAssembly().Location)) + { + var magic_bytes = Encoding.ASCII.GetBytes(Consts.ModPackMagic); + s.Position = s.Length - magic_bytes.Length; + using (var br = new BinaryReader(s)) + { + var bytes = br.ReadBytes(magic_bytes.Length); + var magic = Encoding.ASCII.GetString(bytes); + if (magic != Consts.ModPackMagic) + { + + return null; + } + + s.Position = s.Length - magic_bytes.Length - 8; + var start_pos = br.ReadInt64(); + s.Position = start_pos; + long length = br.ReadInt64(); + + return br.ReadBytes((int)length).BZip2String(); + + } + } + } + } } diff --git a/Wabbajack/LambdaCommand.cs b/Wabbajack/LambdaCommand.cs new file mode 100644 index 00000000..1da24ef0 --- /dev/null +++ b/Wabbajack/LambdaCommand.cs @@ -0,0 +1,29 @@ +using System; +using System.Windows.Input; + +namespace Wabbajack +{ + internal class LambdaCommand : ICommand + { + private Action _execute; + private Func _canExecute; + + public event EventHandler CanExecuteChanged; + + public LambdaCommand(Func canExecute, Action execute) + { + _execute = execute; + _canExecute = canExecute; + } + + public bool CanExecute(object parameter) + { + return _canExecute(); + } + + public void Execute(object parameter) + { + _execute(); + } + } +} \ No newline at end of file diff --git a/Wabbajack/MainWindow.xaml b/Wabbajack/MainWindow.xaml index 38daf8e3..0a101c41 100644 --- a/Wabbajack/MainWindow.xaml +++ b/Wabbajack/MainWindow.xaml @@ -5,21 +5,33 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:Wabbajack" mc:Ignorable="d" - Title="Wabbajack" Height="600" Width="800" + Title="Wabbajack" Height="700" Width="800" Style="{StaticResource {x:Type Window}}" Icon="square_transparent_icon.ico" WindowStyle="ToolWindow"> + + - + + + + + + + + + + + @@ -50,8 +62,9 @@ - - + + + diff --git a/Wabbajack/MainWindow.xaml.cs b/Wabbajack/MainWindow.xaml.cs index 30ad5ab7..1d89b0f3 100644 --- a/Wabbajack/MainWindow.xaml.cs +++ b/Wabbajack/MainWindow.xaml.cs @@ -25,38 +25,62 @@ namespace Wabbajack { public MainWindow() { + var args = Environment.GetCommandLineArgs(); + bool DebugMode = false; + string MO2Folder = null, InstallFolder = null, MO2Profile = null; + + if (args.Length > 1) + { + DebugMode = true; + MO2Folder = args[1]; + MO2Profile = args[2]; + InstallFolder = args[3]; + } + InitializeComponent(); var context = new AppState(Dispatcher, "Building"); this.DataContext = context; - WorkQueue.Init((id, msg, progress) => context.SetProgress(id, msg, progress)); - var compiler = new Compiler("c:\\Mod Organizer 2", msg => context.LogMsg(msg)); - compiler.MO2Profile = "DEV"; //"Basic Graphics and Fixes"; - context.ModListName = compiler.MO2Profile; - context.Mode = "Building"; - - - new Thread(() => + if (DebugMode) { - compiler.LoadArchives(); - compiler.Compile(); + new Thread(() => + { + var compiler = new Compiler(MO2Folder, msg => context.LogMsg(msg)); + compiler.MO2Profile = MO2Profile; + context.ModListName = compiler.MO2Profile; + context.Mode = "Building"; + compiler.LoadArchives(); + compiler.Compile(); - compiler.ModList.ToJSON("C:\\tmp\\modpack.json"); - var modlist = compiler.ModList; - var create = modlist.Directives.OfType().ToList(); - compiler = null; - var installer = new Installer(modlist, "c:\\tmp\\install\\", msg => context.LogMsg(msg)); - installer.Install(); + var modlist = compiler.ModList.ToJSON(); + compiler = null; - }).Start(); + context.ConfigureForInstall(modlist); + }).Start(); + } + else + { + new Thread(() => + { + var modlist = Installer.CheckForModPack(); + context.LogMsg($"Modlist returned {modlist != null}"); + if (modlist == null) + { + } + else + { + context.ConfigureForInstall(modlist); + } + }).Start(); + } } } } diff --git a/Wabbajack/Themes/LeftMarginMultiplierConverter.cs b/Wabbajack/Themes/LeftMarginMultiplierConverter.cs new file mode 100644 index 00000000..95ce71a0 --- /dev/null +++ b/Wabbajack/Themes/LeftMarginMultiplierConverter.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; + +namespace DarkBlendTheme +{ + public class LeftMarginMultiplierConverter : IValueConverter + { + public double Length { get; set; } + + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + var item = value as TreeViewItem; + if (item == null) + return new Thickness(0); + + return new Thickness(Length * item.GetDepth(), 0, 0, 0); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new System.NotImplementedException(); + } + } +} diff --git a/Wabbajack/Themes/Styles.xaml b/Wabbajack/Themes/Styles.xaml new file mode 100644 index 00000000..95d89b91 --- /dev/null +++ b/Wabbajack/Themes/Styles.xaml @@ -0,0 +1,3096 @@ + + + + + + + #444444 + #333333 + #595959 + #3D3D3D + #424242 + #666666 + + #EFEFEF + + #BDBDBD + #525252 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + M-0.7,5.2 L-2.2,6.7 3.6,12.6 9.5,6.7 8,5.2 3.6,9.6 z + M-2.2,10.9 L-0.7,12.4 3.7,8 8,12.4 9.5,10.9 3.7,5 z + M1.0E-41,4.2 L0,2.1 2.5,4.5 6.7,4.4E-47 6.7,2.3 2.5,6.7 z + M7.2,5 L5.5,7.16 4.16,6.3 3.5,6.7 5.5,8.4 8.6,5.25 C8.6,5.25 8,4.7 7.22,5 + M 0,0 L 4,3.5 L 0,7 Z + M 1,1.5 L 4.5,5 L 8,1.5 + M 1,4.5 L 4.5,1 L 8,4.5 + M6.5,2.6C4.767,0.973 2.509,0 0,0 0,0 0,19 0,19L23,19z + M3.5445026,0 L7.0890052,7.0890053 L3.0459049E-09,7.0890053 z + M-0,6 L-0,8 8,8 8,-0 6,-0 6,6 z + M5,-0 L9,5 1,5 z + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Wabbajack/Themes/TreeViewItemExtensions.cs b/Wabbajack/Themes/TreeViewItemExtensions.cs new file mode 100644 index 00000000..e6c605c7 --- /dev/null +++ b/Wabbajack/Themes/TreeViewItemExtensions.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Media; + +namespace DarkBlendTheme +{ + public static class TreeViewItemExtensions + { + public static int GetDepth(this TreeViewItem item) + { + TreeViewItem parent; + while ((parent = GetParent(item)) != null) + { + return GetDepth(parent) + 1; + } + return 0; + } + + private static TreeViewItem GetParent(TreeViewItem item) + { + var parent = VisualTreeHelper.GetParent(item); + + while (!(parent is TreeViewItem || parent is TreeView)) + { + if (parent == null) return null; + parent = VisualTreeHelper.GetParent(parent); + } + return parent as TreeViewItem; + } + } +} diff --git a/Wabbajack/Wabbajack.csproj b/Wabbajack/Wabbajack.csproj index 91afa830..286ead46 100644 --- a/Wabbajack/Wabbajack.csproj +++ b/Wabbajack/Wabbajack.csproj @@ -40,6 +40,16 @@ square_transparent_icon.ico + + true + bin\Debug %28no commandargs%29\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + true + ..\packages\Costura.Fody.4.0.0\lib\net40\Costura.dll @@ -47,12 +57,19 @@ ..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll + + ..\packages\Ookii.Dialogs.Wpf.1.1.0\lib\net45\Ookii.Dialogs.Wpf.dll + ..\packages\SharpCompress.0.23.0\lib\net45\SharpCompress.dll + + + + @@ -74,6 +91,7 @@ MSBuild:Compile Designer + diff --git a/Wabbajack/Wabbajack.csproj.user b/Wabbajack/Wabbajack.csproj.user new file mode 100644 index 00000000..54a4a4b0 --- /dev/null +++ b/Wabbajack/Wabbajack.csproj.user @@ -0,0 +1,10 @@ + + + + "c:\Mod Organizer 2" "Nexus SSO Test" "c:\tmp\validate" + + + + + + \ No newline at end of file diff --git a/Wabbajack/packages.config b/Wabbajack/packages.config index 0adbe702..910e731d 100644 --- a/Wabbajack/packages.config +++ b/Wabbajack/packages.config @@ -3,6 +3,7 @@ +