using Avalonia.Controls.Shapes; using fis.Upgrader.Helpers; using FisTools; using System; using System.Diagnostics; using System.IO; using System.Threading; using System.Threading.Tasks; namespace fis.Upgrader.Managers { internal class UpgradeManager { private static UpgradeManager _instance; private double _lastProgress; public event EventHandler OnUpgradeProgressChanged; public static UpgradeManager Instance { get { if (_instance == null) { _instance = new UpgradeManager(); } return _instance; } } private UpgradeManager() { } public void RunFullUpgrade() { Task.Run(() => { Thread.Sleep(30000); OnProgressChanged(0.98); Thread.Sleep(15000); OnProgressChanged(1.0); }); ToolManager.Instance.LoaderCenter.KillProcessWithGivenName("fis"); ToolManager.Instance.UpgradeCenter.ExecuteFullUpgrade(Logger.WriteLine, OnProgressChanged); } private void OnProgressChanged(double progress) { if (_lastProgress > progress) { Logger.WriteLine($"{progress} is returned "); return; } _lastProgress = progress; OnUpgradeProgressChanged?.Invoke(null, progress); if (progress >= 1.0) { Task.Run(() => { try { Thread.Sleep(1000); var currentDir = AppDomain.CurrentDomain.BaseDirectory; Logger.WriteLine($"Current dir is{currentDir}"); var fisDir = Directory.GetParent(currentDir)!.Parent!.FullName; Logger.WriteLine($"fis dir is{fisDir}"); var fileFullName = System.IO.Path.Combine(fisDir, "fis.exe"); if (!File.Exists(fileFullName)) { Logger.WriteLine($"{fileFullName} not exist"); } Logger.WriteLine($"Full name is{fileFullName}"); ToolManager.Instance.LoaderCenter.StartProcessDirectly(fileFullName); } catch (Exception ex) { Logger.WriteLine($"Exception happened {ex} "); } finally { ToolManager.Instance.LoaderCenter.KillProcessWithGivenName("fis.Upgrader"); } }); } else { Logger.WriteLine($"Current progress is {progress} "); } } } }