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. public ViewModelMain Current { get; private set; }
  9. public UpdateModule.UpdateInstaller Installer { get; set; }
  10. public string UpdateDirectory { get; private set; }
  11. private float progressValue;
  12. public float ProgressValue
  13. {
  14. get => progressValue;
  15. set
  16. {
  17. progressValue = value;
  18. RaisePropertyChanged(nameof(ProgressValue));
  19. }
  20. }
  21. public ViewModelMain()
  22. {
  23. Current = this;
  24. string updateDirectory = Path.GetDirectoryName(Extensions.GetExecutablePath());
  25. #if DEBUG
  26. updateDirectory = Environment.GetCommandLineArgs()[1];
  27. #endif
  28. UpdateDirectory = updateDirectory;
  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. }