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

89 lines
2.4 KiB
C#
Raw Normal View History

2021-08-16 13:25:43 +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-16 13:25:43 +03:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProxySuper.Core.ViewModels
{
public class XrayInstallViewModel : MvxViewModel<Record>
{
Host _host;
XraySettings _settings;
XrayService _xrayService;
public override void ViewDestroy(bool viewFinishing = true)
{
_xrayService.Disconnect();
2021-08-19 07:06:05 +03:00
this.SaveInstallLog();
2021-08-16 13:25:43 +03:00
base.ViewDestroy(viewFinishing);
}
public override void Prepare(Record parameter)
{
this._host = parameter.Host;
this._settings = parameter.XraySettings;
}
public override Task Initialize()
{
_xrayService = new XrayService(_host, _settings);
_xrayService.Progress.StepUpdate = () => RaisePropertyChanged("Progress");
2021-08-18 12:34:32 +03:00
_xrayService.Progress.LogsUpdate = () => RaisePropertyChanged("Logs");
2021-08-16 13:25:43 +03:00
_xrayService.Connect();
return base.Initialize();
}
public ProjectProgress Progress
{
get => _xrayService.Progress;
}
public string Logs
{
get => _xrayService.Progress.Logs;
}
2021-08-18 12:34:32 +03:00
#region Command
2021-08-16 13:25:43 +03:00
public IMvxCommand InstallCommand => new MvxCommand(_xrayService.Install);
2021-08-18 12:34:32 +03:00
public IMvxCommand UpdateSettingsCommand => new MvxCommand(_xrayService.UpdateSettings);
public IMvxCommand UpdateXrayCoreCommand => new MvxCommand(_xrayService.UpdateXrayCore);
public IMvxCommand UninstallCommand => new MvxCommand(_xrayService.Uninstall);
public IMvxCommand UploadCertCommand => new MvxCommand(_xrayService.UploadCert);
public IMvxCommand UploadWebCommand => new MvxCommand(_xrayService.UploadWeb);
public IMvxCommand ApplyForCertCommand => new MvxCommand(_xrayService.ApplyForCert);
#endregion
2021-08-19 07:06:05 +03:00
private void SaveInstallLog()
{
if (!Directory.Exists("Logs"))
{
Directory.CreateDirectory("Logs");
}
var fileName = Path.Combine("Logs", DateTime.Now.ToString("yyyy-MM-dd hh-mm") + ".xary.txt");
File.WriteAllText(fileName, Logs);
}
2021-08-16 13:25:43 +03:00
}
}