/// <summary> /// Finds the relevant exe and runs it /// </summary> /// <param name="app"></param> public void OpenApp(AppsResponse.App app) { string targetFolderName = Path.Combine(appsInstallPath, app.name); //// go up to 3 levels deep //string folder = null; //for (int i = 0; i < 3; i++) //{ // if (Directory.EnumerateFiles(targetFolderName).Contains("UnityCrashHandler64.exe")) // { // folder = true; // break; // } //} //if (folder == null) return; List <string> filteredFiles = Directory.EnumerateFiles(targetFolderName).Where(f => f.EndsWith(".exe") && !f.EndsWith("UnityCrashHandler64.exe")).ToList(); if (filteredFiles.Count != 1) { return; } Process.Start(new ProcessStartInfo { FileName = filteredFiles[0], UseShellExecute = true }); }
public void UninstallApp(AppsResponse.App app) { string targetFolderName = Path.Combine(appsInstallPath, app.name); Directory.Delete(targetFolderName, true); RefreshUI(); }
public void InstallApp(AppsResponse.App app) { string downloadsFolderName = Path.Combine(appsInstallPath, "Downloads"); string filename = Path.Combine(downloadsFolderName, Path.GetFileName(app.download)); WebClient webClient = new WebClient(); webClient.DownloadProgressChanged += (s, e) => { ProgressChanged(app, e.ProgressPercentage); }; webClient.DownloadFileCompleted += (s, e) => { ActuallyInstallApp(filename, app); }; if (!Directory.Exists(downloadsFolderName)) { Directory.CreateDirectory(downloadsFolderName); } webClient.DownloadFileAsync(new Uri(app.download), filename); }
private string GetInstalledAppVersion(AppsResponse.App app) { string targetFolderName = Path.Combine(appsInstallPath, app.name); if (!Directory.Exists(targetFolderName)) { return(null); } string versionFile = Path.Combine(targetFolderName, versionFileName); if (!File.Exists(versionFile)) { return(null); } return(File.ReadAllText(versionFile)); }
private void ActuallyInstallApp(string zipName, AppsResponse.App app) { try { string targetFolderName = Path.Combine(appsInstallPath, app.name); // unzip the zip 🤐 ZipFile.ExtractToDirectory(zipName, targetFolderName, true); // add the version file string versionFile = Path.Combine(targetFolderName, versionFileName); File.WriteAllText(versionFile, app.version); } catch (Exception e) { Console.WriteLine($"Can't read downloaded zip.\n{e}"); } RefreshUI(); }
/// <summary> /// Progress bar is hidden when progress is at 0 or 1 /// </summary> /// <param name="app"></param> /// <param name="progressPercentage">int 0-100</param> private void ProgressChanged(AppsResponse.App app, int progressPercentage) { progressBars[app].Visibility = progressPercentage == 0 || progressPercentage == 100 ? Visibility.Collapsed : Visibility.Visible; progressBars[app].Value = progressPercentage; }
public bool IsAppInstalled(AppsResponse.App app) { string targetFolderName = Path.Combine(appsInstallPath, app.name); return(Directory.Exists(targetFolderName)); }
private void AddAppUI(AppsResponse.App app) { GroupBox groupBox = new GroupBox { Margin = new Thickness(12), }; appsContainer.Children.Add(groupBox); appsUI.Add(groupBox); groupBox.Header = app.name; StackPanel panel = new StackPanel { Width = 250, Height = 250, }; groupBox.Content = panel; Label title = new Label { Content = app.name, HorizontalAlignment = HorizontalAlignment.Center, FontWeight = FontWeights.Bold }; //panel.Children.Add(title); Image thumbnail = new Image { Source = new BitmapImage(new Uri(app.thumbnail)), MaxHeight = 150, Margin = new Thickness(0, 0, 0, 4), }; panel.Children.Add(thumbnail); var buttonPadding = new Thickness(6, 2, 6, 2); if (IsAppInstalled(app)) { if (GetInstalledAppVersion(app) != app.version) { Button updateButton = new Button { Content = "Update", Margin = buttonPadding, }; updateButton.Click += new RoutedEventHandler((s, e) => { InstallApp(app); }); panel.Children.Add(updateButton); } Button openButton = new Button { Content = "Open", Margin = buttonPadding, }; openButton.Click += new RoutedEventHandler((s, e) => { OpenApp(app); }); panel.Children.Add(openButton); Button uninstallButton = new Button { Content = "Uninstall", Margin = buttonPadding, }; uninstallButton.Click += new RoutedEventHandler((s, e) => { UninstallApp(app); }); panel.Children.Add(uninstallButton); } else { Button installButton = new Button { Content = "Install", Margin = buttonPadding, }; installButton.Click += new RoutedEventHandler((s, e) => { InstallApp(app); }); panel.Children.Add(installButton); } ProgressBar progressBar = new ProgressBar { Visibility = Visibility.Collapsed, Height = 14, Margin = buttonPadding, }; panel.Children.Add(progressBar); progressBars[app] = progressBar; }