1
0
mirror of https://github.com/proxysu/ProxySU.git synced 2024-11-24 22:26:07 +03:00
ProxySU/ProxySuper.Core/ViewModels/HysteriaInstallViewModel.cs

67 lines
1.9 KiB
C#
Raw Normal View History

2023-02-27 12:26:55 +03:00
using MvvmCross.Commands;
using MvvmCross.ViewModels;
2022-12-17 05:41:46 +03:00
using ProxySuper.Core.Models;
using ProxySuper.Core.Models.Hosts;
using ProxySuper.Core.Models.Projects;
2023-02-27 12:26:55 +03:00
using ProxySuper.Core.Services;
2022-12-17 05:41:46 +03:00
using System;
using System.Collections.Generic;
2023-02-27 12:26:55 +03:00
using System.IO;
2022-12-17 05:41:46 +03:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProxySuper.Core.ViewModels
{
public class HysteriaInstallViewModel : MvxViewModel<Record>
{
2023-02-27 12:26:55 +03:00
public Host _host { get; set; }
2022-12-17 05:41:46 +03:00
2023-02-27 12:26:55 +03:00
public HysteriaSettings _settings { get; set; }
public HysteriaService _service { get; set; }
2022-12-17 05:41:46 +03:00
public override void Prepare(Record parameter)
{
2023-02-27 12:26:55 +03:00
_host = parameter.Host;
_settings = parameter.HysteriaSettings;
}
public override Task Initialize()
{
_service = new HysteriaService(_host, _settings);
_service.Progress.StepUpdate = () => RaisePropertyChanged("Progress");
_service.Progress.LogsUpdate = () => RaisePropertyChanged("Logs");
_service.Connect();
return base.Initialize();
}
public override void ViewDestroy(bool viewFinishing = true)
{
_service.Disconnect();
this.SaveInstallLog();
base.ViewDestroy(viewFinishing);
}
public ProjectProgress Progress => _service.Progress;
public string Logs => _service.Progress.Logs;
public IMvxCommand InstallCommand => new MvxCommand(_service.Install);
public IMvxCommand UninstallCommand => new MvxCommand(_service.Uninstall);
private void SaveInstallLog()
{
if (!Directory.Exists("Logs"))
{
Directory.CreateDirectory("Logs");
}
var fileName = System.IO.Path.Combine("Logs", DateTime.Now.ToString("yyyy-MM-dd hh-mm") + ".hysteria.txt");
File.WriteAllText(fileName, Logs);
2022-12-17 05:41:46 +03:00
}
}
}