private async Task <string> LoadWinWrapper(CancellationToken cancellation) { var wrapperFilename = FilesStorage.Instance.GetFilename("Server Wrapper", "AcServerWrapper.exe"); var data = await CmApiProvider.GetStaticDataAsync("ac_server_wrapper"); if (cancellation.IsCancellationRequested || data == null) { return(null); } if (data.Item2) { // Freshly loaded var wrapperBytes = await FileUtils.ReadAllBytesAsync(data.Item1); if (cancellation.IsCancellationRequested) { return(null); } await Task.Run(() => { using (var stream = new MemoryStream(wrapperBytes, false)) using (var archive = new ZipArchive(stream)){ try { File.WriteAllBytes(wrapperFilename, archive.GetEntry("acServerWrapper.exe").Open().ReadAsBytesAndDispose()); } catch (Exception e) { Logging.Warning(e); } } }); } return(File.Exists(wrapperFilename) ? wrapperFilename : null); }
private static async Task DownloadAndInstall(CancellationToken token) { var directory = _directory ?? MainExecutingFile.Directory; try { var data = await CmApiProvider.GetStaticDataAsync("visual_cpp", TimeSpan.FromDays(1), cancellation : token); if (data == null) { ManualInstallation(null, directory); } else { await Task.Run(() => { using (var archive = ZipFile.OpenRead(data.Item1)) { foreach (var file in archive.Entries) { var completeFileName = Path.Combine(directory, file.FullName); if (file.Name == "" || File.Exists(completeFileName)) { continue; } FileUtils.EnsureFileDirectoryExists(completeFileName); file.ExtractToFile(completeFileName, true); } } }); FileUtils.TryToDelete(data.Item1); if (ModernDialog.ShowMessage("The package is installed. Now, app needs to be restarted. Restart it now?", "The package is installed", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { WindowsHelper.RestartCurrentApplication(); } } } catch (Exception e) when(e.IsCancelled()) { } catch (Exception e) { ManualInstallation(e, directory); } }
private async Task <string> LoadLinux64Wrapper(CancellationToken cancellation) { return((await CmApiProvider.GetStaticDataAsync("ac_server_wrapper-linux-x64"))?.Item1); }