1
0
mirror of https://github.com/proxysu/ProxySU.git synced 2024-11-23 05:36:08 +03:00
ProxySU/ProxySuper.Core/ViewModels/TrojanGoInstallViewModel.cs

86 lines
2.4 KiB
C#
Raw Normal View History

2021-08-18 12:34:32 +03:00
using MvvmCross.Commands;
using MvvmCross.ViewModels;
using ProxySuper.Core.Models;
using ProxySuper.Core.Models.Hosts;
using ProxySuper.Core.Models.Projects;
using ProxySuper.Core.Services;
using System;
using System.Collections.Generic;
2021-08-19 07:06:05 +03:00
using System.IO;
2021-08-18 12:34:32 +03:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProxySuper.Core.ViewModels
{
public class TrojanGoInstallViewModel : MvxViewModel<Record>
{
Host _host;
TrojanGoSettings _settings;
TrojanGoService _trojanGoService;
public override void Prepare(Record parameter)
{
_host = parameter.Host;
_settings = parameter.TrojanGoSettings;
}
public override Task Initialize()
{
_trojanGoService = new TrojanGoService(_host, _settings);
_trojanGoService.Progress.StepUpdate = () => RaisePropertyChanged("Progress");
_trojanGoService.Progress.LogsUpdate = () => RaisePropertyChanged("Logs");
_trojanGoService.Connect();
return base.Initialize();
}
public override void ViewDestroy(bool viewFinishing = true)
{
_trojanGoService.Disconnect();
2021-08-19 07:06:05 +03:00
this.SaveInstallLog();
2021-08-18 12:34:32 +03:00
base.ViewDestroy(viewFinishing);
}
public ProjectProgress Progress
{
get => _trojanGoService.Progress;
}
public string Logs
{
get => _trojanGoService.Progress.Logs;
}
#region Command
public IMvxCommand InstallCommand => new MvxCommand(_trojanGoService.Install);
public IMvxCommand UpdateSettingsCommand => new MvxCommand(_trojanGoService.UpdateSettings);
public IMvxCommand UninstallCommand => new MvxCommand(_trojanGoService.Uninstall);
public IMvxCommand UploadCertCommand => new MvxCommand(_trojanGoService.UploadCert);
public IMvxCommand UploadWebCommand => new MvxCommand(_trojanGoService.UploadWeb);
public IMvxCommand ApplyForCertCommand => new MvxCommand(_trojanGoService.ApplyForCert);
#endregion
2021-08-19 07:06:05 +03:00
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") + ".trojan-go.txt");
File.WriteAllText(fileName, Logs);
}
2021-08-18 12:34:32 +03:00
}
}