ViewModelMain.cs 1.6 KB

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