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