Files
romrepomgr/RomRepoMgr/ViewModels/AboutViewModel.cs

166 lines
6.1 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-08 19:34:02 +00:00
using Avalonia.Platform;
2020-08-22 03:13:49 +01:00
using JetBrains.Annotations;
2024-11-08 19:34:02 +00:00
using Microsoft.CodeAnalysis;
2020-08-22 03:13:49 +01:00
using Microsoft.DotNet.PlatformAbstractions;
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;
namespace RomRepoMgr.ViewModels
{
public sealed class AboutViewModel : ViewModelBase
{
readonly About _view;
string _versionText;
public AboutViewModel(About view)
{
_view = view;
VersionText =
(Attribute.GetCustomAttribute(typeof(App).Assembly, typeof(AssemblyInformationalVersionAttribute)) as
AssemblyInformationalVersionAttribute)?.InformationalVersion;
WebsiteCommand = ReactiveCommand.Create(ExecuteWebsiteCommand);
LicenseCommand = ReactiveCommand.Create(ExecuteLicenseCommand);
CloseCommand = ReactiveCommand.Create(ExecuteCloseCommand);
Assemblies = new ObservableCollection<AssemblyModel>();
// TODO: They do not load in time
Task.Run(() =>
{
foreach(Assembly assembly in AppDomain.CurrentDomain.GetAssemblies().OrderBy(a => a.FullName))
{
string name = assembly.GetName().Name;
string version =
(Attribute.GetCustomAttribute(assembly, typeof(AssemblyInformationalVersionAttribute)) as
AssemblyInformationalVersionAttribute)?.InformationalVersion;
if(name is null ||
version is null)
continue;
Assemblies.Add(new AssemblyModel
{
Name = name,
Version = version
});
}
});
}
[NotNull]
2020-08-30 03:00:14 +01:00
public string AboutLabel => Localization.AboutLabel;
2020-08-22 03:13:49 +01:00
[NotNull]
2020-08-30 03:00:14 +01:00
public string LibrariesLabel => Localization.LibrariesLabel;
2020-08-22 03:13:49 +01:00
[NotNull]
2020-08-30 03:00:14 +01:00
public string AuthorsLabel => Localization.AuthorsLabel;
2020-08-22 03:13:49 +01:00
[NotNull]
2020-08-30 03:00:14 +01:00
public string Title => Localization.AboutTitle;
2020-08-22 03:13:49 +01:00
[NotNull]
public string SoftwareName => "RomRepoMgr";
[NotNull]
public string SuiteName => "ROM Repository Manager";
[NotNull]
2024-11-08 19:13:57 +00:00
public string Copyright => "© 2020-2024 Natalia Portillo";
2020-08-22 03:13:49 +01:00
[NotNull]
public string Website => "https://www.claunia.com";
[NotNull]
2020-08-30 03:00:14 +01:00
public string License => Localization.LicenseLabel;
2020-08-22 03:13:49 +01:00
[NotNull]
2020-08-30 03:00:14 +01:00
public string CloseLabel => Localization.CloseLabel;
2020-08-22 03:13:49 +01:00
[NotNull]
2020-08-30 03:00:14 +01:00
public string AssembliesLibraryText => Localization.AssembliesLibraryText;
2020-08-22 03:13:49 +01:00
[NotNull]
2020-08-30 03:00:14 +01:00
public string AssembliesVersionText => Localization.AssembliesVersionText;
2020-08-22 03:13:49 +01:00
[NotNull]
2020-08-30 03:00:14 +01:00
public string Authors => Localization.AuthorsText;
2020-08-22 03:13:49 +01:00
public ReactiveCommand<Unit, Unit> WebsiteCommand { get; }
public ReactiveCommand<Unit, Unit> LicenseCommand { get; }
public ReactiveCommand<Unit, Unit> CloseCommand { get; }
public ObservableCollection<AssemblyModel> Assemblies { get; }
public string VersionText
{
get => _versionText;
set => this.RaiseAndSetIfChanged(ref _versionText, value);
}
void ExecuteWebsiteCommand()
{
var process = new Process
{
StartInfo =
{
UseShellExecute = false,
CreateNoWindow = true,
Arguments = "https://www.claunia.com"
}
};
2024-11-08 19:34:02 +00:00
if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
2020-08-22 03:13:49 +01:00
{
2024-11-08 19:34:02 +00:00
process.StartInfo.FileName = "cmd";
process.StartInfo.Arguments = $"/c start {process.StartInfo.Arguments.Replace("&", "^&")}";
}
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
{
if(Debugger.IsAttached) throw new ArgumentOutOfRangeException();
return;
2020-08-22 03:13:49 +01:00
}
process.Start();
}
void ExecuteLicenseCommand()
{
/* var dialog = new LicenseDialog();
dialog.DataContext = new LicenseViewModel(dialog);
dialog.ShowDialog(_view);*/
}
void ExecuteCloseCommand() => _view.Close();
}
}