1
0
mirror of https://github.com/proxysu/ProxySU.git synced 2024-11-22 13:16:09 +03:00
ProxySU/ProxySuper.Core/ViewModels/NaiveProxyInstallViewModel.cs

76 lines
2.1 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 NaiveProxyInstallViewModel : MvxViewModel<Record>
{
Host _host;
NaiveProxySettings _settings;
NaiveProxyService _service;
public override void Prepare(Record parameter)
{
_host = parameter.Host;
_settings = parameter.NaiveProxySettings;
}
public override Task Initialize()
{
_service = new NaiveProxyService(_host, _settings);
_service.Progress.StepUpdate = () => RaisePropertyChanged("Progress");
_service.Progress.LogsUpdate = () => RaisePropertyChanged("Logs");
2021-08-19 07:06:05 +03:00
_service.Connect();
2021-08-18 12:34:32 +03:00
return base.Initialize();
}
public override void ViewDestroy(bool viewFinishing = true)
{
_service.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 => _service.Progress;
public string Logs => _service.Progress.Logs;
#region Commands
public IMvxCommand InstallCommand => new MvxCommand(_service.Install);
public IMvxCommand UpdateSettingsCommand => new MvxCommand(_service.UpdateSettings);
public IMvxCommand UninstallCommand => new MvxCommand(_service.Uninstall);
public IMvxCommand UploadWebCommand => new MvxCommand(_service.UploadWeb);
#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") + ".naiveproxy.txt");
File.WriteAllText(fileName, Logs);
}
2021-08-18 12:34:32 +03:00
}
}