Files
WowUp/WowUp.WPF/ViewModels/AboutViewModel.cs
jliddev 93abd85965 Beta 1.15.0-4
Add the ability to switch WowUp release types on via setting.
Update to the newest api to fetch the version.
Add events for preference changes.
More polish on options page.
2020-08-30 11:23:29 -05:00

67 lines
1.8 KiB
C#

using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Reflection;
using WowUp.Common.Models;
using WowUp.WPF.Services.Contracts;
using WowUp.WPF.Utilities;
namespace WowUp.WPF.ViewModels
{
public class AboutViewModel : BaseViewModel
{
private readonly IWowUpService _wowUpService;
private string _version;
public string Version
{
get => _version;
set { SetProperty(ref _version, value); }
}
public ObservableCollection<ChangeLog> ChangeLogs { get; set; }
public AboutViewModel(IWowUpService wowUpService)
{
_wowUpService = wowUpService;
ChangeLogs = new ObservableCollection<ChangeLog>();
InitializeView();
}
private async void InitializeView()
{
Version = $"v{AppUtilities.LongVersionName}";
var changeLogFile = await _wowUpService.GetChangeLogFile();
if (changeLogFile == null)
{
return;
}
foreach (var changeLog in changeLogFile.ChangeLogs)
{
ChangeLogs.Add(changeLog);
}
}
public string ReadResource(string name)
{
// Determine path
var assembly = Assembly.GetExecutingAssembly();
string resourcePath = name;
// Format: "{Namespace}.{Folder}.{filename}.{Extension}"
if (!name.StartsWith(nameof(WowUp)))
{
resourcePath = assembly.GetManifestResourceNames()
.Single(str => str.EndsWith(name));
}
using Stream stream = assembly.GetManifestResourceStream(resourcePath);
using StreamReader reader = new StreamReader(stream);
return reader.ReadToEnd();
}
}
}