Crunchy-Downloader/CRD/ViewModels/MainWindowViewModel.cs
Elwador 3a28c0fbd1 Add - Temp folder option to the settings - episodes are downloaded and processed in this folder an moved afterwards https://github.com/Crunchy-DL/Crunchy-Downloader/issues/62
Chg - Renamed {showTitle} to {seasonTitle} make sure to change it if you have it in the file name
Fix - Height of window increased each about 31px  https://github.com/Crunchy-DL/Crunchy-Downloader/issues/89
Fix - History bar now has a different color for dark mode and light mode https://github.com/Crunchy-DL/Crunchy-Downloader/issues/85
Fix - FFMPEG/Mkvmerge/Mp4decrypt errors are now correctly logged
Fix - Crash with separate video files option
2024-08-20 18:40:45 +02:00

75 lines
2.3 KiB
C#

using System;
using System.IO;
using System.Net.Http;
using System.Reflection;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls.Chrome;
using Avalonia.Media;
using Avalonia.Styling;
using CommunityToolkit.Mvvm.ComponentModel;
using CRD.Downloader;
using CRD.Downloader.Crunchyroll;
using CRD.Utils.Updater;
using FluentAvalonia.Styling;
using Newtonsoft.Json;
namespace CRD.ViewModels;
public partial class MainWindowViewModel : ViewModelBase{
private readonly FluentAvaloniaTheme _faTheme;
[ObservableProperty]
private bool _updateAvailable = true;
[ObservableProperty]
private bool _finishedLoading = false;
public MainWindowViewModel(){
_faTheme = App.Current.Styles[0] as FluentAvaloniaTheme;
Init();
CleanUpOldUpdater();
}
private void CleanUpOldUpdater(){
string backupFilePath = Path.Combine(Directory.GetCurrentDirectory(), "Updater.exe.bak");
if (File.Exists(backupFilePath)){
try{
File.Delete(backupFilePath);
Console.WriteLine($"Deleted old updater file: {backupFilePath}");
} catch (Exception ex){
Console.Error.WriteLine($"Failed to delete old updater file: {ex.Message}");
}
} else{
Console.WriteLine("No old updater file found to delete.");
}
}
public async void Init(){
UpdateAvailable = await Updater.Instance.CheckForUpdatesAsync();
CrunchyrollManager.Instance.InitOptions();
if (CrunchyrollManager.Instance.CrunOptions.AccentColor != null){
_faTheme.CustomAccentColor = Color.Parse(CrunchyrollManager.Instance.CrunOptions.AccentColor);
}
if (CrunchyrollManager.Instance.CrunOptions.Theme == "System"){
_faTheme.PreferSystemTheme = true;
} else if (CrunchyrollManager.Instance.CrunOptions.Theme == "Dark"){
_faTheme.PreferSystemTheme = false;
Application.Current.RequestedThemeVariant = ThemeVariant.Dark;
} else{
_faTheme.PreferSystemTheme = false;
Application.Current.RequestedThemeVariant = ThemeVariant.Light;
}
await CrunchyrollManager.Instance.Init();
FinishedLoading = true;
}
}