From 873bb47e35dd14f61dbd2be8e8ea1fe9dec84d9f Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Fri, 2 Aug 2019 17:04:04 -0600 Subject: [PATCH] added an overall progress bar --- Wabbajack.Common/Utils.cs | 7 +++++++ Wabbajack.Common/WorkQueue.cs | 11 ++++++++++- Wabbajack/AppState.cs | 23 +++++++++++++++++++++++ Wabbajack/Compiler.cs | 4 +++- Wabbajack/MainWindow.xaml | 8 +++++--- Wabbajack/MainWindow.xaml.cs | 5 ++--- 6 files changed, 50 insertions(+), 8 deletions(-) diff --git a/Wabbajack.Common/Utils.cs b/Wabbajack.Common/Utils.cs index 0f91348d..6f199904 100644 --- a/Wabbajack.Common/Utils.cs +++ b/Wabbajack.Common/Utils.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Net.Http; using System.Security.Cryptography; using System.Text; +using System.Threading; using System.Threading.Tasks; namespace Wabbajack.Common @@ -163,6 +164,10 @@ namespace Wabbajack.Common public static List PMap(this IEnumerable coll, Func f) { + var colllst = coll.ToList(); + WorkQueue.MaxQueueSize = colllst.Count; + WorkQueue.CurrentQueueSize = 0; + var tasks = coll.Select(i => { TaskCompletionSource tc = new TaskCompletionSource(); @@ -176,6 +181,8 @@ namespace Wabbajack.Common { tc.SetException(ex); } + Interlocked.Increment(ref WorkQueue.CurrentQueueSize); + WorkQueue.ReportNow(); }); return tc.Task; }).ToList(); diff --git a/Wabbajack.Common/WorkQueue.cs b/Wabbajack.Common/WorkQueue.cs index 3ed1155d..72c8285f 100644 --- a/Wabbajack.Common/WorkQueue.cs +++ b/Wabbajack.Common/WorkQueue.cs @@ -15,9 +15,10 @@ namespace Wabbajack.Common [ThreadStatic] private static int CpuId; - public static void Init(Action report_function) + public static void Init(Action report_function, Action report_queue_size) { ReportFunction = report_function; + ReportQueueSize = report_queue_size; ThreadCount = Environment.ProcessorCount; StartThreads(); } @@ -59,7 +60,15 @@ namespace Wabbajack.Common } public static Action ReportFunction { get; private set; } + public static Action ReportQueueSize { get; private set; } public static int ThreadCount { get; private set; } public static List Threads { get; private set; } + public static int MaxQueueSize; + public static int CurrentQueueSize; + + internal static void ReportNow() + { + ReportQueueSize(MaxQueueSize, CurrentQueueSize); + } } } diff --git a/Wabbajack/AppState.cs b/Wabbajack/AppState.cs index ed198e7e..35fe13f1 100644 --- a/Wabbajack/AppState.cs +++ b/Wabbajack/AppState.cs @@ -81,6 +81,23 @@ namespace Wabbajack } } + private int _queueProgress; + public int QueueProgress + { + get + { + return _queueProgress; + } + set + { + if (value != _queueProgress) + { + _queueProgress = value; + OnPropertyChanged("QueueProgress"); + } + } + } + private List InternalStatus { get; } public string LogFile { get; private set; } @@ -162,6 +179,12 @@ namespace Wabbajack } } + public void SetQueueSize(int max, int current) + { + var total = current * 100 / max; + QueueProgress = total; + } + private ICommand _changePath; public ICommand ChangePath { diff --git a/Wabbajack/Compiler.cs b/Wabbajack/Compiler.cs index ec300392..1c21e9ba 100644 --- a/Wabbajack/Compiler.cs +++ b/Wabbajack/Compiler.cs @@ -159,6 +159,7 @@ namespace Wabbajack .Where(p => p.FileExists()) .Select(p => new RawSourceFile() { Path = Path.Combine(Consts.GameFolderFilesDir, p.RelativeTo(GamePath)), AbsolutePath = p }); + Info("Searching for mod files"); AllFiles = mo2_files.Concat(game_files).ToList(); Info("Found {0} files to build into mod list", AllFiles.Count); @@ -192,7 +193,8 @@ namespace Wabbajack ModList = new ModList() { Archives = SelectedArchives, - Directives = InstallDirectives + Directives = InstallDirectives, + Name = MO2Profile }; PatchExecutable(); diff --git a/Wabbajack/MainWindow.xaml b/Wabbajack/MainWindow.xaml index 0a101c41..55e83a28 100644 --- a/Wabbajack/MainWindow.xaml +++ b/Wabbajack/MainWindow.xaml @@ -12,6 +12,7 @@ + @@ -62,9 +63,10 @@ - - + + + - + diff --git a/Wabbajack/MainWindow.xaml.cs b/Wabbajack/MainWindow.xaml.cs index 1d89b0f3..f7aff063 100644 --- a/Wabbajack/MainWindow.xaml.cs +++ b/Wabbajack/MainWindow.xaml.cs @@ -41,7 +41,8 @@ namespace Wabbajack var context = new AppState(Dispatcher, "Building"); this.DataContext = context; - WorkQueue.Init((id, msg, progress) => context.SetProgress(id, msg, progress)); + WorkQueue.Init((id, msg, progress) => context.SetProgress(id, msg, progress), + (max, current) => context.SetQueueSize(max, current)); if (DebugMode) @@ -69,8 +70,6 @@ namespace Wabbajack new Thread(() => { var modlist = Installer.CheckForModPack(); - context.LogMsg($"Modlist returned {modlist != null}"); - if (modlist == null) { }