2025-10-15 21:25:05 +01:00
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Windows.Input;
|
2025-10-15 22:05:55 +01:00
|
|
|
using Aaru.Helpers;
|
|
|
|
|
using Aaru.Tui.Models;
|
2025-10-15 21:25:05 +01:00
|
|
|
using Avalonia;
|
|
|
|
|
using Avalonia.Controls.ApplicationLifetimes;
|
2025-10-15 22:05:55 +01:00
|
|
|
using Avalonia.Media;
|
2025-10-15 21:25:05 +01:00
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
using CommunityToolkit.Mvvm.Input;
|
2025-10-15 22:05:55 +01:00
|
|
|
using Color = Avalonia.Media.Color;
|
2025-10-15 21:25:05 +01:00
|
|
|
|
|
|
|
|
namespace Aaru.Tui.ViewModels.Windows;
|
|
|
|
|
|
2025-10-15 22:05:55 +01:00
|
|
|
public sealed partial class MainWindowViewModel : ViewModelBase
|
2025-10-15 21:25:05 +01:00
|
|
|
{
|
|
|
|
|
[ObservableProperty]
|
2025-10-15 22:05:55 +01:00
|
|
|
public string _copyright;
|
|
|
|
|
[ObservableProperty]
|
2025-10-15 22:44:09 +01:00
|
|
|
public string _currentPath;
|
|
|
|
|
[ObservableProperty]
|
2025-10-15 22:05:55 +01:00
|
|
|
ObservableCollection<FileModel> _files = [];
|
2025-10-15 21:25:05 +01:00
|
|
|
[ObservableProperty]
|
|
|
|
|
public string _informationalVersion;
|
|
|
|
|
|
|
|
|
|
public MainWindowViewModel()
|
|
|
|
|
{
|
|
|
|
|
ExitCommand = new RelayCommand(Exit);
|
|
|
|
|
|
|
|
|
|
InformationalVersion =
|
|
|
|
|
Assembly.GetExecutingAssembly()
|
|
|
|
|
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
|
|
|
|
|
?.InformationalVersion ??
|
|
|
|
|
"?.?.?";
|
2025-10-15 22:05:55 +01:00
|
|
|
|
|
|
|
|
Copyright = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyCopyrightAttribute>()?.Copyright ?? "";
|
2025-10-15 21:25:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ICommand ExitCommand { get; }
|
|
|
|
|
|
|
|
|
|
void Exit()
|
|
|
|
|
{
|
|
|
|
|
var lifetime = Application.Current!.ApplicationLifetime as IControlledApplicationLifetime;
|
|
|
|
|
lifetime!.Shutdown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoadComplete()
|
|
|
|
|
{
|
2025-10-15 22:44:09 +01:00
|
|
|
CurrentPath = Directory.GetCurrentDirectory();
|
|
|
|
|
|
2025-10-15 22:05:55 +01:00
|
|
|
var parentDirectory = new FileModel
|
|
|
|
|
{
|
|
|
|
|
Filename = "..",
|
|
|
|
|
Path = Path.GetRelativePath(Directory.GetCurrentDirectory(), ".."),
|
|
|
|
|
ForegroundBrush =
|
|
|
|
|
new SolidColorBrush(Color.Parse(DirColorsParser.Instance.DirectoryColor ??
|
|
|
|
|
DirColorsParser.Instance.NormalColor))
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Files.Add(parentDirectory);
|
|
|
|
|
|
|
|
|
|
foreach(FileModel model in Directory
|
|
|
|
|
.GetDirectories(Directory.GetCurrentDirectory(), "*", SearchOption.TopDirectoryOnly)
|
|
|
|
|
.Select(directory => new FileModel
|
|
|
|
|
{
|
|
|
|
|
Path = directory,
|
|
|
|
|
Filename = Path.GetFileName(directory),
|
|
|
|
|
ForegroundBrush =
|
|
|
|
|
new SolidColorBrush(Color.Parse(DirColorsParser.Instance.DirectoryColor ??
|
|
|
|
|
DirColorsParser.Instance.NormalColor))
|
|
|
|
|
}))
|
|
|
|
|
Files.Add(model);
|
2025-10-15 21:25:05 +01:00
|
|
|
|
2025-10-15 22:44:09 +01:00
|
|
|
foreach(string file in Directory.GetFiles(Directory.GetCurrentDirectory(), "*", SearchOption.TopDirectoryOnly))
|
2025-10-15 22:05:55 +01:00
|
|
|
{
|
|
|
|
|
var model = new FileModel
|
|
|
|
|
{
|
|
|
|
|
Path = file,
|
|
|
|
|
Filename = Path.GetFileName(file)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
string extension = Path.GetExtension(file);
|
|
|
|
|
|
|
|
|
|
model.ForegroundBrush =
|
|
|
|
|
new SolidColorBrush(Color.Parse(DirColorsParser.Instance.ExtensionColors.TryGetValue(extension,
|
|
|
|
|
out string? hex)
|
|
|
|
|
? hex
|
|
|
|
|
: DirColorsParser.Instance.NormalColor));
|
|
|
|
|
|
|
|
|
|
Files.Add(model);
|
|
|
|
|
}
|
2025-10-15 21:25:05 +01:00
|
|
|
}
|
|
|
|
|
}
|