Пример #1
0
        public async Task InstallOrUpgradeAsync(IApp app)
        {
            consoleLogger.Info($"Installing '{app.AppId}'");
            var preInstallDesktopSystemEntries = desktopRepository.LoadSystemEntries();

            var preInstallVerificationResult = await VerifyAppAsync(app);

            var actionScript = GetActionScript(app, preInstallVerificationResult);

            if (!string.IsNullOrWhiteSpace(actionScript))
            {
                await powerShell.ExecuteAsync(actionScript);
                await VerifyAppAsync(app);
            }

            var postInstallDesktopSystemEntries = desktopRepository.LoadSystemEntries();
            var desktopSystemEntriesToDelete    = postInstallDesktopSystemEntries.Except(preInstallDesktopSystemEntries).ToList();

            if (desktopSystemEntriesToDelete.Any())
            {
                desktopRepository.DeletePaths(desktopSystemEntriesToDelete);
            }

            consoleLogger.Result($"Installed '{app.AppId}'");
        }
        public async Task InstallAsync(IDownloadApp app)
        {
            consoleLogger.Info($"Installing '{app.AppId}'");

            IDownloader downloader = downloaderFactory.GetDownloader(app.Downloader);

            var downloadedFilePath = await downloader.DownloadAsync(app.DownloaderArgs.ToString() !);

            var installScript = $"{app.InstallScript} {downloadedFilePath}";

            if (app.VerificationScript == null)
            {
                await powerShell.ExecuteAsync(installScript);
            }
            else
            {
                await powerShell.ExecuteAsync(installScript, app.VerificationScript);
            }

            consoleLogger.Result($"Installed '{app.AppId}'");
        }
        public async Task SetExecutionPolicyAsync()
        {
            var executionPolicy = "RemoteSigned";
            var script          = @$ "Set-ExecutionPolicy {executionPolicy} -Force
Get-ExecutionPolicy";

            var powerShellResult = await powerShell.ExecuteAsync(script);

            consoleLogger.Result($"PowerShell - Execution Policy: {powerShellResult.AsString}");

            windowsPowerShell.Execute(script);
            consoleLogger.Result($"Windows PowerShell - Execution Policy: {executionPolicy}");
        }
        public async Task <string> DownloadAsync(string argsJson)
        {
            var args = jsonSerializer.Deserialize <GitHubAssetDownloaderArgs>(argsJson) !;

            var getAssetInfoScript =
                @$ "$asset = (iwr https://api.github.com/repos/{args.User}/{args.Repo}/releases/latest | ConvertFrom-Json).assets | ? {{ $_.name -like '{args.Extension}' }}
$downloadUrl = $asset | select -exp browser_download_url
$fileName = $asset | select -exp name
Write-Output " "{{ `" "FileName`" ": `" "$fileName`" ", `" "Url`" ": `" "$downloadUrl`" " }}" "";

            var result = await powerShell.ExecuteAsync(getAssetInfoScript);

            var assetInfo = jsonSerializer.Deserialize <GitHubAssetInfo>(result.AsString) !;

            return(await resourceDownloader.DownloadAsync(assetInfo.Url, assetInfo.Filename));
        }
        public async Task InstallAsync()
        {
            await downloadAppInstaller.InstallAsync(WingetCliApp);

            await powerShell.ExecuteAsync("winget list winget --accept-source-agreements");
        }