Skip to content

Commit

Permalink
better error handling for backend setup
Browse files Browse the repository at this point in the history
  • Loading branch information
the-database committed Aug 15, 2024
1 parent 3e1f41b commit becbbd0
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 37 deletions.
16 changes: 8 additions & 8 deletions VideoJaNai/VideoJaNai.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@

<ItemGroup>
<PackageReference Include="Autofac" Version="8.0.0" />
<PackageReference Include="Avalonia" Version="11.1.1" />
<PackageReference Include="Avalonia.Desktop" Version="11.1.1" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.1" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.1.1" />
<PackageReference Include="Avalonia" Version="11.1.3" />
<PackageReference Include="Avalonia.Desktop" Version="11.1.3" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.3" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.1.3" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.1" />
<PackageReference Include="Avalonia.ReactiveUI" Version="11.1.1" />
<PackageReference Include="FluentAvaloniaUI" Version="2.1.0-preview6" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.3" />
<PackageReference Include="Avalonia.ReactiveUI" Version="11.1.3" />
<PackageReference Include="FluentAvaloniaUI" Version="2.1.0" />
<PackageReference Include="HyperText.Avalonia" Version="11.0.0-rc1" />
<PackageReference Include="Material.Icons.Avalonia" Version="2.1.10" />
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.4.4" />
Expand All @@ -49,7 +49,7 @@
<PackageReference Include="SharpZipLib" Version="1.4.2" />
<PackageReference Include="Splat.Autofac" Version="15.1.1" />
<PackageReference Include="System.Management.Automation" Version="7.4.4" />
<PackageReference Include="Velopack" Version="0.0.583" />
<PackageReference Include="Velopack" Version="0.0.589-g4087722" />
</ItemGroup>


Expand Down
133 changes: 104 additions & 29 deletions VideoJaNai/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ public MainWindowViewModel(IPythonService? pythonService = null, IUpdateManagerS
CurrentWorkflow?.Validate();
});



this.WhenAnyValue(x => x.ShowAppSettings).Subscribe(async x =>
{
if (x && string.IsNullOrWhiteSpace(PythonPipList))
{
await PopulatePythonPipList();
}
});

_um = new UpdateManager(new GithubSource("https://github.com/the-database/VideoJaNai", null, false));
CheckForUpdates();
}
Expand Down Expand Up @@ -255,6 +265,16 @@ public bool IsExtractingBackend
}
}

private bool _extractingBackendFailed = false;
public bool ExtractingBackendFailed
{
get => _extractingBackendFailed;
set
{
this.RaiseAndSetIfChanged(ref _extractingBackendFailed, value);
}
}

public bool UpscaleEnabled => CurrentWorkflow.Valid && !Upscaling;

private AvaloniaList<UpscaleWorkflow> _workflows;
Expand Down Expand Up @@ -719,6 +739,12 @@ private void ConsoleQueueEnqueue(string value)
this.RaisePropertyChanged(nameof(ConsoleText));
}

private void BackendSetupSubStatusQueueClear()
{
BackendSetupSubStatusQueue.Clear();
this.RaisePropertyChanged(nameof(BackendSetupSubStatusText));
}

private void BackendSetupSubStatusQueueEnqueue(string value)
{
while (BackendSetupSubStatusQueue.Count > BACKEND_SETUP_SUB_STATUS_QUEUE_CAPACITY)
Expand Down Expand Up @@ -780,28 +806,44 @@ public async Task CheckAndExtractBackend()
{
await Task.Run(async () =>
{
var failureMsg = "Backend setup failed. Try reinstalling Python environment or report the issue on GitHub if it persists.";
BackendSetupSubStatusQueueClear();
IsExtractingBackend = true;

if (!_pythonService.IsPythonInstalled())
{
// 1. Install embedded Python + portable VS
await InstallPortableVapourSynth();
try
{
// 1. Install embedded Python + portable VS
await InstallPortableVapourSynth();

// 2. Python dependencies
await RunInstallCommand(_pythonService.InstallUpdatePythonDependenciesCommand);
// 2. Python dependencies
await RunInstallCommand(_pythonService.InstallUpdatePythonDependenciesCommand);

// 3. VapourSynth plugins
await RunInstallCommand(_pythonService.InstallVapourSynthPluginsCommand);
await InstallVapourSynthMiscFilters();
await InstallVapourSynthAkarin();
// 3. VapourSynth plugins
await RunInstallCommand(_pythonService.InstallVapourSynthPluginsCommand);
await InstallVapourSynthMiscFilters();
await InstallVapourSynthAkarin();

// 4. vs-mlrt
await InstallVsmlrt();
// 4. vs-mlrt
await InstallVsmlrt();

// 5. RIFE models
await InstallRife();
// 5. RIFE models
await InstallRife();

CleanupInstall();
CleanupInstall();
}
catch (Exception ex)
{
BackendSetupSubStatusQueueEnqueue(ex.Message);
if (ex.StackTrace != null)
{
BackendSetupSubStatusQueueEnqueue(ex.StackTrace);
}
ExtractingBackendFailed = true;
BackendSetupMainStatus = failureMsg;
return;
}
}
else
{
Expand All @@ -824,30 +866,61 @@ await Task.Run(async () =>

if (!_pythonService.AreModelsInstalled())
{
await InstallModels();
try
{
await InstallModels();
}
catch (Exception ex)
{
BackendSetupSubStatusQueueEnqueue(ex.Message);
if (ex.StackTrace != null)
{
BackendSetupSubStatusQueueEnqueue(ex.StackTrace);
}
ExtractingBackendFailed = true;
BackendSetupMainStatus = failureMsg;
return;
}
}

if (!_pythonService.IsFfmpegInstalled())
{
await InstallFfmpeg();
try
{
await InstallFfmpeg();
}
catch (Exception ex)
{
BackendSetupSubStatusQueueEnqueue(ex.Message);
if (ex.StackTrace != null)
{
BackendSetupSubStatusQueueEnqueue(ex.StackTrace);
}
ExtractingBackendFailed = true;
BackendSetupMainStatus = failureMsg;
return;
}
}

IsExtractingBackend = false;

RunningPython = true;
try
{
var pipList = await RunPythonPipList();
PythonPipList = $"Python Packages:\n{pipList}";
//var vsrepos = await RunVsrepoInstalled(); // too slow
var vsmlrtVer = await RunVsmlrtVersion();
PythonPipList = $"Python Packages:\n{pipList}\n\nvsmlrt.py Version:\n{vsmlrtVer}";
}
catch (Exception ex) { }
RunningPython = false;
});
}

public async Task PopulatePythonPipList()
{
RunningPython = true;
try
{
var pipList = await RunPythonPipList();
PythonPipList = $"Python Packages:\n{pipList}";
//var vsrepos = await RunVsrepoInstalled(); // too slow
var vsmlrtVer = await RunVsmlrtVersion();
PythonPipList = $"Python Packages:\n{pipList}\n\nvsmlrt.py Version:\n{vsmlrtVer}";
}
catch (Exception) { }
RunningPython = false;
}

public async Task ReinstallBackend()
{
if (Directory.Exists(_pythonService.FfmpegDirectory))
Expand Down Expand Up @@ -1039,7 +1112,7 @@ await Downloader.DownloadFileAsync(downloadUrl, targetPath, (progress) =>
private async Task InstallVsmlrt()
{
BackendSetupMainStatus = "Downloading vs-mlrt...";
var downloadUrl = "https://github.com/AmusementClub/vs-mlrt/releases/download/v14.test3/vsmlrt-windows-x64-cuda.v14.test3.7z";
var downloadUrl = "https://github.com/AmusementClub/vs-mlrt/releases/download/v15.2/vsmlrt-windows-x64-cuda.v15.2.7z";
var targetPath = Path.Join(_pythonService.BackendDirectory, "vsmlrt.7z");
await Downloader.DownloadFileAsync(downloadUrl, targetPath, (progress) =>
{
Expand Down Expand Up @@ -1080,6 +1153,8 @@ async Task InstallRife()
"rife_v4.18.7z",
"rife_v4.19.7z",
"rife_v4.20.7z",
"rife_v4.21.7z",
"rife_v4.22.7z",
];

var downloadUrlBase = "https://github.com/AmusementClub/vs-mlrt/releases/download/external-models/";
Expand Down Expand Up @@ -1638,7 +1713,7 @@ public bool EnableRife

public List<string> RifeModelList { get => Vm?.RifeModels; }

private string _rifeModel = "RIFE 4.20";
private string _rifeModel = "RIFE 4.22";
[DataMember]
public string RifeModel
{
Expand Down
8 changes: 8 additions & 0 deletions VideoJaNai/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,14 @@
<ScrollViewer Margin="0,10,0,0" Background="#111111" Height="450" Width="1200" HorizontalScrollBarVisibility="Auto" Foreground="Gray" PropertyChanged="ConsoleScrollViewer_PropertyChanged">
<SelectableTextBlock Margin="20" Text="{Binding BackendSetupSubStatusText}" FontFamily="Consolas" PropertyChanged="ConsoleTextBlock_PropertyChanged" />
</ScrollViewer>
<StackPanel IsVisible="{Binding ExtractingBackendFailed}">
<StackPanel Orientation="Horizontal" Margin="0,10,0,0" Width="1200">
<Button FontWeight="Bold" Background="Red" Content="Reinstall Python Environment" Click="ReinstallBackendClick" IsEnabled="{Binding AllowReinstall}" />
<TextBlock Foreground="Gray" Width="400" TextWrapping="WrapWithOverflow" FontSize="12" VerticalAlignment="Center" Margin="20,0,0,0">
Reinstall the Python environment. Try this if you are having any problems getting upscales to work. This process may take several minutes.
</TextBlock>
</StackPanel>
</StackPanel>
</StackPanel>
</Grid>
</Grid>
Expand Down

0 comments on commit becbbd0

Please sign in to comment.