private async Task <int> InstallVMBinaries() { try { if (Dirs.VMFolder.EnumerateFiles().Any()) { Console.WriteLine($"Detected already installed vm, reinstall...".Color(Color.Orange)); } if (Dirs.VMFolder.EnumerateFiles().Any()) { _ = Dirs.CompilerFolder.EnumerateFiles().Pipe(x => x.Delete()).ToArray(); } var result = await Appx.By(AppxType.vm) .DownloadAsync(); Console.Write($"{":open_file_folder:".Emoji()} Extract files"); await RuneTask.Fire(() => ZipFile.ExtractToDirectory(result.FullName, Dirs.VMFolder.FullName)); } catch (Exception e) { Console.WriteLine(e); } return(await Success()); }
public async Task <string> AppInstallAsync(DeviceManagementClient client) { try { var appInstallInfo = new AppInstallInfo(); if (null != Dependencies) { foreach (var dependencyBlobInfo in Dependencies) { var depPath = await dependencyBlobInfo.DownloadToTempAsync(client); appInstallInfo.Dependencies.Add(depPath); } } var path = await Appx.DownloadToTempAsync(client); appInstallInfo.AppxPath = path; appInstallInfo.PackageFamilyName = PackageFamilyName; await client.InstallAppAsync(appInstallInfo); var response = JsonConvert.SerializeObject(new { response = "succeeded" }); return(response); } catch (Exception e) { var response = JsonConvert.SerializeObject(new { response = "failed", reason = e.Message }); return(response); } }
// // NOTE: we should consider returning error details (e.g. "executable not found", "unknown exeId", "win32 error") from this function private static MorphicResult <MorphicExecutablePathInfo, MorphicUnit> ConvertExeIdToExecutablePath(string exeId) { bool isAppX = false; string?appPath = null; switch (exeId) { case "calculator": { // option #1: calc.exe in system folder //appPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "calc.exe"); // // option #2: find calc.exe in paths appPath = ApplicationAction.SearchPathEnv("calc.exe"); } break; case "firefox": { appPath = ApplicationAction.SearchAppPaths("firefox.exe"); } break; case "googleChrome": { appPath = ApplicationAction.SearchAppPaths("chrome.exe"); } break; case "microsoftAccess": { appPath = ApplicationAction.SearchAppPaths("MSACCESS.EXE"); } break; case "microsoftExcel": { appPath = ApplicationAction.SearchAppPaths("excel.exe"); } break; case "microsoftEdge": { appPath = ApplicationAction.SearchAppPaths("msedge.exe"); } break; case "microsoftOneNote": { appPath = ApplicationAction.SearchAppPaths("OneNote.exe"); } break; case "microsoftOutlook": { appPath = ApplicationAction.SearchAppPaths("OUTLOOK.EXE"); } break; case "microsoftPowerPoint": { appPath = ApplicationAction.SearchAppPaths("powerpnt.exe"); } break; case "microsoftQuickAssist": { // option #1: exactly as written in Quick Assist shortcut (as of 18-Apr-2021): %WINDIR%\system32\quickassist.exe //var appPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), @"system32\quickassist.exe"); // // option #2: quickassist.exe in system folder appPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "quickassist.exe"); // // option #3: ms url shortcut (NOTE: we have intentionally not used this in case Quick Assist is removed from the system...as the URL does not give us a way to detect that scenario via "file does not exist" checks) //var appPath = "ms-quick-assist:"; } break; case "microsoftSkype": { appPath = ApplicationAction.SearchAppPaths("Skype.exe"); } break; case "microsoftTeams": { // NOTE: this is a very odd path, and it's not in the "AppPaths"; if we can find another way to determine the proper launch path or launch programatically, we should consider another method var userAppDataLocalPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); var fixedAppPath = Path.Combine(new string[] { userAppDataLocalPath, "Microsoft", "Teams", "current", "Teams.exe" }); // NOTE: we could also probably launch Teams via the "ms-teams:" URI, but that wouldn't necessarily help us detect if it's installed // NOTE: in the future, it would be better to launch Update.exe and have it then start Teams (as Microsoft does for their shortcut) -- but we'd probably want to // detect the Teams.exe file itself to detect if it was installed //var fixedAppPath = Path.Combine(new string[] { userAppDataLocalPath, "Microsoft", "Teams", "Update.exe" }); //var params = new string[] { "--processStart", "Teams.exe" }; // NOTE: in Windows 11 (and perhaps in recent releases of Windows 10), Microsoft Teams is installed as an Appx package with the name: // MicrosoftTeams_8wekyb3d8bbwe // ...so we might refer to this as appx:MicrosoftTeams_8wekyb3d8bbwe!MicrosoftTeams // NOTE: this path, including "!MicrosoftTeams" at the end, is the Application User Model ID (AUMID) of Microsoft Teams if (File.Exists(fixedAppPath) == true) { // if the file exists, set appPath to the fixed path appPath = fixedAppPath; } else { // if Teams was not installed as an EXE, check to see if it's installed as an APPX package var packageFamilyName = "MicrosoftTeams_8wekyb3d8bbwe"; var isPackageInstalledResult = Appx.IsPackageInstalled(packageFamilyName); if (isPackageInstalledResult.IsError == true) { return(MorphicResult.ErrorResult()); } var isPackageInstalled = isPackageInstalledResult.Value !; if (isPackageInstalled == true) { appPath = packageFamilyName + "!MicrosoftTeams"; isAppX = true; } } } break; case "microsoftWord": { appPath = ApplicationAction.SearchAppPaths("Winword.exe"); } break; case "opera": { appPath = ApplicationAction.SearchAppPaths("opera.exe"); } break; default: { appPath = null; } break; } if (appPath is not null) { var result = new MorphicExecutablePathInfo() { IsAppx = isAppX, Path = appPath }; return(MorphicResult.OkResult(result)); } else { return(MorphicResult.ErrorResult()); } }