Files
romrepomgr/RomRepoMgr/ViewModels/AboutViewModel.cs

149 lines
5.9 KiB
C#
Raw Normal View History

2020-08-22 03:13:49 +01:00
/******************************************************************************
// RomRepoMgr - ROM repository manager
// ----------------------------------------------------------------------------
//
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
2024-11-08 19:13:57 +00:00
// Copyright © 2020-2024 Natalia Portillo
2020-08-22 03:13:49 +01:00
*******************************************************************************/
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Reactive;
using System.Reflection;
2024-11-08 19:34:02 +00:00
using System.Runtime.InteropServices;
2020-08-22 03:13:49 +01:00
using System.Threading.Tasks;
2024-11-09 06:14:25 +00:00
using Avalonia.Threading;
2020-08-22 03:13:49 +01:00
using ReactiveUI;
2020-08-22 13:36:39 +01:00
using RomRepoMgr.Core.Models;
2020-08-30 03:00:14 +01:00
using RomRepoMgr.Resources;
2020-08-22 03:13:49 +01:00
using RomRepoMgr.Views;
2024-11-09 01:37:59 +00:00
namespace RomRepoMgr.ViewModels;
public sealed class AboutViewModel : ViewModelBase
2020-08-22 03:13:49 +01:00
{
2024-11-09 01:37:59 +00:00
readonly About _view;
string _versionText;
2020-08-22 03:13:49 +01:00
2024-11-09 01:37:59 +00:00
public AboutViewModel(About view)
{
_view = view;
2020-08-22 03:13:49 +01:00
2024-11-09 01:37:59 +00:00
VersionText =
(Attribute.GetCustomAttribute(typeof(App).Assembly, typeof(AssemblyInformationalVersionAttribute)) as
AssemblyInformationalVersionAttribute)?.InformationalVersion;
2020-08-22 03:13:49 +01:00
2024-11-09 01:37:59 +00:00
WebsiteCommand = ReactiveCommand.Create(ExecuteWebsiteCommand);
LicenseCommand = ReactiveCommand.Create(ExecuteLicenseCommand);
CloseCommand = ReactiveCommand.Create(ExecuteCloseCommand);
2020-08-22 03:13:49 +01:00
2024-11-12 06:39:06 +00:00
Assemblies = [];
2020-08-22 03:13:49 +01:00
_ = Task.Run(() =>
2024-11-09 01:37:59 +00:00
{
foreach(Assembly assembly in AppDomain.CurrentDomain.GetAssemblies().OrderBy(a => a.FullName))
2020-08-22 03:13:49 +01:00
{
2024-11-09 01:37:59 +00:00
string name = assembly.GetName().Name;
2020-08-22 03:13:49 +01:00
2024-11-09 01:37:59 +00:00
string version =
(Attribute.GetCustomAttribute(assembly, typeof(AssemblyInformationalVersionAttribute)) as
AssemblyInformationalVersionAttribute)?.InformationalVersion;
2020-08-22 03:13:49 +01:00
2024-11-09 01:37:59 +00:00
if(name is null || version is null) continue;
2020-08-22 03:13:49 +01:00
2024-11-09 06:14:25 +00:00
Dispatcher.UIThread.Post(() =>
2024-11-09 01:37:59 +00:00
{
2024-11-09 06:14:25 +00:00
Assemblies.Add(new AssemblyModel
{
Name = name,
Version = version
});
2024-11-09 01:37:59 +00:00
});
2024-11-08 19:34:02 +00:00
}
2024-11-09 01:37:59 +00:00
});
}
2024-11-09 06:14:25 +00:00
public string AboutLabel => Localization.AboutLabel;
public string LibrariesLabel => Localization.LibrariesLabel;
public string AuthorsLabel => Localization.AuthorsLabel;
public string Title => Localization.AboutTitle;
public string SoftwareName => "RomRepoMgr";
public string SuiteName => "ROM Repository Manager";
public string Copyright => "© 2020-2024 Natalia Portillo";
public string Website => "https://www.claunia.com";
public string License => Localization.LicenseLabel;
public string CloseLabel => Localization.CloseLabel;
public string AssembliesLibraryText => Localization.AssembliesLibraryText;
public string AssembliesVersionText => Localization.AssembliesVersionText;
public string Authors => Localization.AuthorsText;
public ReactiveCommand<Unit, Unit> WebsiteCommand { get; }
public ReactiveCommand<Unit, Unit> LicenseCommand { get; }
public ReactiveCommand<Unit, Unit> CloseCommand { get; }
public ObservableCollection<AssemblyModel> Assemblies { get; }
2024-11-09 01:37:59 +00:00
public string VersionText
{
get => _versionText;
set => this.RaiseAndSetIfChanged(ref _versionText, value);
}
2024-11-08 19:34:02 +00:00
2024-11-09 01:37:59 +00:00
void ExecuteWebsiteCommand()
{
var process = new Process
{
StartInfo =
{
UseShellExecute = false,
CreateNoWindow = true,
Arguments = "https://www.claunia.com"
2020-08-22 03:13:49 +01:00
}
2024-11-09 01:37:59 +00:00
};
2020-08-22 03:13:49 +01:00
2024-11-09 01:37:59 +00:00
if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
process.StartInfo.FileName = "cmd";
process.StartInfo.Arguments = $"/c start {process.StartInfo.Arguments.Replace("&", "^&")}";
2020-08-22 03:13:49 +01:00
}
2024-11-09 01:37:59 +00:00
else if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ||
RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD))
process.StartInfo.FileName = "xdg-open";
else if(RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
process.StartInfo.FileName = "open";
else
2020-08-22 03:13:49 +01:00
{
2024-11-09 01:37:59 +00:00
if(Debugger.IsAttached) throw new ArgumentOutOfRangeException();
return;
2020-08-22 03:13:49 +01:00
}
2024-11-09 01:37:59 +00:00
process.Start();
2020-08-22 03:13:49 +01:00
}
2024-11-09 01:37:59 +00:00
void ExecuteLicenseCommand()
{
/* var dialog = new LicenseDialog();
dialog.DataContext = new LicenseViewModel(dialog);
2024-11-09 06:21:49 +00:00
dialog.ShowWindowDialogAsync(_view);*/
2024-11-09 01:37:59 +00:00
}
void ExecuteCloseCommand() => _view.Close();
2020-08-22 03:13:49 +01:00
}