Merge pull request #208 from Noggog/progress-bar

Progress Bar Systems Rewired
This commit is contained in:
Timothy Baldridge 2019-11-24 05:57:04 -07:00 committed by GitHub
commit 390e27f34a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 106 additions and 67 deletions

View File

@ -38,9 +38,9 @@ namespace Wabbajack.Common
_progress.OnNext(0.0f);
}
public void MakeUpdate(double progress)
public void MakeUpdate(float progress)
{
_progress.OnNext((float)0.0);
_progress.OnNext(progress);
}
public void MakeUpdate(int max, int curr)

View File

@ -34,6 +34,12 @@ namespace Wabbajack
private readonly ObservableAsPropertyHelper<bool> _compiling;
public bool Compiling => _compiling.Value;
private readonly ObservableAsPropertyHelper<float> _percentCompleted;
public float PercentCompleted => _percentCompleted.Value;
public ObservableCollectionExtended<CPUStatus> StatusList { get; } = new ObservableCollectionExtended<CPUStatus>();
public ObservableCollectionExtended<string> Log => MWVM.Log;
public CompilerVM(MainWindowVM mainWindowVM)
{
MWVM = mainWindowVM;
@ -102,7 +108,7 @@ namespace Wabbajack
.ToProperty(this, nameof(Compiling));
// Compile progress updates and populate ObservableCollection
var subscription = this.WhenAny(x => x.Compiler.ActiveCompilation)
this.WhenAny(x => x.Compiler.ActiveCompilation)
.SelectMany(c => c?.QueueStatus ?? Observable.Empty<CPUStatus>())
.ObserveOn(RxApp.TaskpoolScheduler)
.ToObservableChangeSet(x => x.ID)
@ -110,9 +116,24 @@ namespace Wabbajack
.EnsureUniqueChanges()
.ObserveOn(RxApp.MainThreadScheduler)
.Sort(SortExpressionComparer<CPUStatus>.Ascending(s => s.ID), SortOptimisations.ComparesImmutableValuesOnly)
.Bind(MWVM.StatusList)
.Bind(StatusList)
.Subscribe()
.DisposeWith(CompositeDisposable);
_percentCompleted = this.WhenAny(x => x.Compiler.ActiveCompilation)
.StartWith(default(ACompiler))
.Pairwise()
.Select(c =>
{
if (c.Current == null)
{
return Observable.Return<float>(c.Previous == null ? 0f : 1f);
}
return c.Current.PercentCompleted;
})
.Switch()
.Debounce(TimeSpan.FromMilliseconds(25))
.ToProperty(this, nameof(PercentCompleted));
}
}
}

View File

@ -40,11 +40,11 @@ namespace Wabbajack
private readonly ObservableAsPropertyHelper<string> _htmlReport;
public string HTMLReport => _htmlReport.Value;
/// <summary>
/// Tracks whether an install is currently in progress
/// </summary>
[Reactive]
public bool Installing { get; set; }
public AInstaller ActiveInstallation { get; private set; }
private readonly ObservableAsPropertyHelper<bool> _installing;
public bool Installing => _installing.Value;
/// <summary>
/// Tracks whether to show the installing pane
@ -56,9 +56,6 @@ namespace Wabbajack
public FilePickerVM DownloadLocation { get; }
private readonly ObservableAsPropertyHelper<float> _progressPercent;
public float ProgressPercent => _progressPercent.Value;
private readonly ObservableAsPropertyHelper<ImageSource> _image;
public ImageSource Image => _image.Value;
@ -77,6 +74,12 @@ namespace Wabbajack
private readonly ObservableAsPropertyHelper<string> _modListName;
public string ModListName => _modListName.Value;
private readonly ObservableAsPropertyHelper<float> _percentCompleted;
public float PercentCompleted => _percentCompleted.Value;
public ObservableCollectionExtended<CPUStatus> StatusList { get; } = new ObservableCollectionExtended<CPUStatus>();
public ObservableCollectionExtended<string> Log => MWVM.Log;
// Command properties
public IReactiveCommand BeginCommand { get; }
public IReactiveCommand ShowReportCommand { get; }
@ -158,15 +161,25 @@ namespace Wabbajack
_htmlReport = this.WhenAny(x => x.ModList)
.Select(modList => modList?.ReportHTML)
.ToProperty(this, nameof(HTMLReport));
_progressPercent = Observable.CombineLatest(
this.WhenAny(x => x.Installing),
this.WhenAny(x => x.InstallingMode),
resultSelector: (installing, mode) => !installing && mode)
.Select(show => show ? 1f : 0f)
// Disable for now, until more reliable
//this.WhenAny(x => x.MWVM.QueueProgress)
// .Select(i => i / 100f)
.ToProperty(this, nameof(ProgressPercent));
_installing = this.WhenAny(x => x.ActiveInstallation)
.Select(compilation => compilation != null)
.ObserveOnGuiThread()
.ToProperty(this, nameof(Installing));
_percentCompleted = this.WhenAny(x => x.ActiveInstallation)
.StartWith(default(AInstaller))
.Pairwise()
.Select(c =>
{
if (c.Current == null)
{
return Observable.Return<float>(c.Previous == null ? 0f : 1f);
}
return c.Current.PercentCompleted;
})
.Switch()
.Debounce(TimeSpan.FromMilliseconds(25))
.ToProperty(this, nameof(PercentCompleted));
Slideshow = new SlideShow(this);
@ -215,7 +228,7 @@ namespace Wabbajack
canExecute: this.WhenAny(x => x.ModList)
.Select(modList => !string.IsNullOrEmpty(modList?.Readme))
.ObserveOnGuiThread());
BeginCommand = ReactiveCommand.Create(
BeginCommand = ReactiveCommand.CreateFromTask(
execute: ExecuteBegin,
canExecute: Observable.CombineLatest(
this.WhenAny(x => x.Installing),
@ -254,6 +267,19 @@ namespace Wabbajack
return mode ? "Installing" : "Installed";
})
.ToProperty(this, nameof(ProgressTitle));
// Compile progress updates and populate ObservableCollection
this.WhenAny(x => x.ActiveInstallation)
.SelectMany(c => c?.QueueStatus ?? Observable.Empty<CPUStatus>())
.ObserveOn(RxApp.TaskpoolScheduler)
.ToObservableChangeSet(x => x.ID)
.Batch(TimeSpan.FromMilliseconds(250), RxApp.TaskpoolScheduler)
.EnsureUniqueChanges()
.ObserveOn(RxApp.MainThreadScheduler)
.Sort(SortExpressionComparer<CPUStatus>.Ascending(s => s.ID), SortOptimisations.ComparesImmutableValuesOnly)
.Bind(StatusList)
.Subscribe()
.DisposeWith(CompositeDisposable);
}
private void ShowReport()
@ -289,31 +315,36 @@ namespace Wabbajack
}
}
private void ExecuteBegin()
private async Task ExecuteBegin()
{
Installing = true;
InstallingMode = true;
var installer = new MO2Installer(ModListPath, ModList.SourceModList, Location.TargetPath)
AInstaller installer;
try
{
DownloadFolder = DownloadLocation.TargetPath
};
// Compile progress updates and populate ObservableCollection
var subscription = installer.QueueStatus
.ObserveOn(RxApp.TaskpoolScheduler)
.ToObservableChangeSet(x => x.ID)
.Batch(TimeSpan.FromMilliseconds(250), RxApp.TaskpoolScheduler)
.EnsureUniqueChanges()
.ObserveOn(RxApp.MainThreadScheduler)
.Sort(SortExpressionComparer<CPUStatus>.Ascending(s => s.ID), SortOptimisations.ComparesImmutableValuesOnly)
.Bind(MWVM.StatusList)
.Subscribe();
Task.Run(async () =>
installer = new MO2Installer(ModListPath, ModList.SourceModList, Location.TargetPath)
{
DownloadFolder = DownloadLocation.TargetPath
};
}
catch (Exception ex)
{
while (ex.InnerException != null) ex = ex.InnerException;
Utils.Log(ex.StackTrace);
Utils.Log(ex.ToString());
Utils.Log($"{ex.Message} - Can't continue");
ActiveInstallation = null;
return;
}
await Task.Run(async () =>
{
IDisposable subscription = null;
try
{
await installer.Begin();
var workTask = installer.Begin();
ActiveInstallation = installer;
await workTask;
}
catch (Exception ex)
{
@ -325,10 +356,8 @@ namespace Wabbajack
finally
{
// Dispose of CPU tracking systems
subscription.Dispose();
MWVM.StatusList.Clear();
Installing = false;
subscription?.Dispose();
ActiveInstallation = null;
}
});
}

View File

@ -1,4 +1,4 @@
using DynamicData;
using DynamicData;
using DynamicData.Binding;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
@ -24,8 +24,6 @@ namespace Wabbajack
private readonly ObservableAsPropertyHelper<ViewModel> _activePane;
public ViewModel ActivePane => _activePane.Value;
public ObservableCollectionExtended<CPUStatus> StatusList { get; } = new ObservableCollectionExtended<CPUStatus>();
public ObservableCollectionExtended<string> Log { get; } = new ObservableCollectionExtended<string>();
[Reactive]
@ -48,9 +46,9 @@ namespace Wabbajack
.ToObservableChangeSet()
.Buffer(TimeSpan.FromMilliseconds(250), RxApp.TaskpoolScheduler)
.Where(l => l.Count > 0)
.ObserveOn(RxApp.MainThreadScheduler)
.FlattenBufferResult()
.Top(5000)
.ObserveOn(RxApp.MainThreadScheduler)
.Bind(Log)
.Subscribe()
.DisposeWith(CompositeDisposable);
@ -72,21 +70,6 @@ namespace Wabbajack
}
})
.ToProperty(this, nameof(ActivePane));
// Compile progress updates and populate ObservableCollection
/*
_Compiler.WhenAny(c => c.Value.Compiler.)
.ObserveOn(RxApp.TaskpoolScheduler)
.ToObservableChangeSet(x => x.)
/*
.Batch(TimeSpan.FromMilliseconds(250), RxApp.TaskpoolScheduler)
.EnsureUniqueChanges()
.ObserveOn(RxApp.MainThreadScheduler)
.Sort(SortExpressionComparer<CPUStatus>.Ascending(s => s.ID), SortOptimisations.ComparesImmutableValuesOnly)
.Bind(this.StatusList)
.Subscribe()
.DisposeWith(this.CompositeDisposable);*/
}
}
}

View File

@ -56,7 +56,7 @@
Grid.Column="0"
Grid.ColumnSpan="5"
OverhangShadow="True"
ProgressPercent="{Binding ProgressPercent}"
ProgressPercent="{Binding PercentCompleted}"
StatePrefixTitle="Compiling" />
<ScrollViewer
Grid.Row="1"
@ -219,7 +219,7 @@
Grid.ColumnSpan="5"
Margin="5"
Visibility="{Binding Compiling, Converter={StaticResource bool2VisibilityConverter}, FallbackValue=Hidden}">
<local:LogCpuView DataContext="{Binding MWVM}" />
<local:LogCpuView />
</Grid>
</Grid>
</UserControl>

View File

@ -194,7 +194,7 @@
Title="{Binding ModListName}"
Grid.Row="0"
Grid.RowSpan="2"
ProgressPercent="{Binding ProgressPercent}"
ProgressPercent="{Binding PercentCompleted}"
StatePrefixTitle="{Binding ProgressTitle}">
<!-- Readd when Pause/Stop implementations added -->
<!--<Button Grid.Column="2"
@ -342,7 +342,7 @@
Grid.Row="2"
Margin="5,0,5,5"
Visibility="{Binding InstallingMode, Converter={StaticResource bool2VisibilityConverter}, FallbackValue=Hidden}">
<local:LogCpuView DataContext="{Binding MWVM}" />
<local:LogCpuView />
</Grid>
</Grid>
</UserControl>

View File

@ -43,6 +43,8 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoWarn>CS1998</NoWarn>
<WarningsAsErrors>CS4014</WarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>x64</PlatformTarget>
@ -53,6 +55,8 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<NoWarn>CS1998</NoWarn>
<WarningsAsErrors>CS4014</WarningsAsErrors>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Resources\Icons\wabbajack.ico</ApplicationIcon>
@ -66,6 +70,8 @@
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
<NoWarn>CS1998</NoWarn>
<WarningsAsErrors>CS4014</WarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>