ViewModelMain.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. namespace PixiEditor.UpdateInstaller
  11. {
  12. public class ViewModelMain : ViewModelBase
  13. {
  14. public ViewModelMain Current { get; private set; }
  15. public UpdateModule.UpdateInstaller Installer { get; set; }
  16. public string UpdateDirectory { get; private set; }
  17. private float _progressValue;
  18. public float ProgressValue
  19. {
  20. get => _progressValue;
  21. set
  22. {
  23. _progressValue = value;
  24. RaisePropertyChanged(nameof(ProgressValue));
  25. }
  26. }
  27. public ViewModelMain()
  28. {
  29. Current = this;
  30. string updateDirectory = Path.GetDirectoryName(Extensions.GetExecutablePath());
  31. #if DEBUG
  32. updateDirectory = Environment.GetCommandLineArgs()[1];
  33. #endif
  34. UpdateDirectory = updateDirectory;
  35. }
  36. public void InstallUpdate()
  37. {
  38. string[] files = Directory.GetFiles(UpdateDirectory, "update-*.zip");
  39. if (files.Length > 0)
  40. {
  41. Installer = new UpdateModule.UpdateInstaller(files[0]);
  42. Installer.ProgressChanged += Installer_ProgressChanged;
  43. Installer.Install();
  44. }
  45. else
  46. {
  47. ProgressValue = 100;
  48. }
  49. }
  50. private void Installer_ProgressChanged(object sender, UpdateModule.UpdateProgressChangedEventArgs e)
  51. {
  52. ProgressValue = e.Progress;
  53. }
  54. }
  55. }