1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- namespace PixiEditor.UpdateInstaller
- {
- public class ViewModelMain : ViewModelBase
- {
- public ViewModelMain Current { get; private set; }
- public UpdateModule.UpdateInstaller Installer { get; set; }
- public string UpdateDirectory { get; private set; }
- private float _progressValue;
- public float ProgressValue
- {
- get => _progressValue;
- set
- {
- _progressValue = value;
- RaisePropertyChanged(nameof(ProgressValue));
- }
- }
- public ViewModelMain()
- {
- Current = this;
- string updateDirectory = Path.GetDirectoryName(Extensions.GetExecutablePath());
- #if DEBUG
- updateDirectory = Environment.GetCommandLineArgs()[1];
- #endif
- UpdateDirectory = updateDirectory;
- }
- public void InstallUpdate()
- {
- string[] files = Directory.GetFiles(UpdateDirectory, "update-*.zip");
- if (files.Length > 0)
- {
- Installer = new UpdateModule.UpdateInstaller(files[0]);
- Installer.ProgressChanged += Installer_ProgressChanged;
- Installer.Install();
- }
- else
- {
- ProgressValue = 100;
- }
- }
- private void Installer_ProgressChanged(object sender, UpdateModule.UpdateProgressChangedEventArgs e)
- {
- ProgressValue = e.Progress;
- }
- }
- }
|