mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-22 18:41:26 -07:00
111 lines
3.6 KiB
C#
111 lines
3.6 KiB
C#
using Bloxstrap.Enums;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Input;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using System.Windows.Forms;
|
|
using Wpf.Ui.Mvvm.Interfaces;
|
|
using System.ComponentModel;
|
|
using Bloxstrap.Helpers;
|
|
using Bloxstrap.Models;
|
|
using System.Diagnostics;
|
|
|
|
namespace Bloxstrap.ViewModels
|
|
{
|
|
public class InstallationViewModel : INotifyPropertyChanged
|
|
{
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
public void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
private IEnumerable<string> _channels = DeployManager.ChannelsAbstracted.Contains(App.Settings.Prop.Channel) ? DeployManager.ChannelsAbstracted : DeployManager.ChannelsAll;
|
|
private bool _showAllChannels = !DeployManager.ChannelsAbstracted.Contains(App.Settings.Prop.Channel);
|
|
|
|
public ICommand BrowseInstallLocationCommand => new RelayCommand(BrowseInstallLocation);
|
|
public ICommand OpenFolderCommand => new RelayCommand(OpenFolder);
|
|
|
|
|
|
public DeployInfo? ChannelDeployInfo { get; private set; } = null; //new DeployInfo(){ Version = "hi", VersionGuid = "hi", Timestamp = "January 25 2023 at 6:03:48 PM" };
|
|
|
|
public InstallationViewModel()
|
|
{
|
|
Task.Run(() => LoadChannelDeployInfo(App.Settings.Prop.Channel));
|
|
}
|
|
|
|
private async Task LoadChannelDeployInfo(string channel)
|
|
{
|
|
ChannelDeployInfo = null;
|
|
OnPropertyChanged(nameof(ChannelDeployInfo));
|
|
|
|
ClientVersion info = await DeployManager.GetLastDeploy(channel, true);
|
|
string? strTimestamp = info.Timestamp?.ToString("MM/dd/yyyy h:mm:ss tt", App.CultureFormat);
|
|
|
|
ChannelDeployInfo = new DeployInfo() { Version = info.Version, VersionGuid = info.VersionGuid, Timestamp = strTimestamp! };
|
|
OnPropertyChanged(nameof(ChannelDeployInfo));
|
|
}
|
|
|
|
private void BrowseInstallLocation()
|
|
{
|
|
using var dialog = new FolderBrowserDialog();
|
|
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
InstallLocation = dialog.SelectedPath;
|
|
OnPropertyChanged(nameof(InstallLocation));
|
|
}
|
|
}
|
|
|
|
private void OpenFolder()
|
|
{
|
|
Process.Start("explorer.exe", Directories.Base);
|
|
}
|
|
|
|
public string InstallLocation
|
|
{
|
|
get => App.BaseDirectory;
|
|
set => App.BaseDirectory = value;
|
|
}
|
|
|
|
public IEnumerable<string> Channels
|
|
{
|
|
get => _channels;
|
|
set => _channels = value;
|
|
}
|
|
|
|
public string Channel
|
|
{
|
|
get => App.Settings.Prop.Channel;
|
|
set
|
|
{
|
|
//Task.Run(() => GetChannelInfo(value));
|
|
Task.Run(() => LoadChannelDeployInfo(value));
|
|
App.Settings.Prop.Channel = value;
|
|
}
|
|
}
|
|
|
|
public bool ShowAllChannels
|
|
{
|
|
get => _showAllChannels;
|
|
set
|
|
{
|
|
if (value)
|
|
{
|
|
Channels = DeployManager.ChannelsAll;
|
|
}
|
|
else
|
|
{
|
|
Channels = DeployManager.ChannelsAbstracted;
|
|
Channel = DeployManager.DefaultChannel;
|
|
OnPropertyChanged(nameof(Channel));
|
|
}
|
|
|
|
OnPropertyChanged(nameof(Channels));
|
|
|
|
_showAllChannels = value;
|
|
}
|
|
}
|
|
}
|
|
}
|