public string DownloadCef(IProgressMonitor progressMonitor) { if (!IsCefArchiveAvailable()) { try { Directory.CreateDirectory(_cefPatchFolder); var result = DownloadHelper.DownloadFileFromGithub(_cefDownloadUrl, _cefPatchArchive, progressMonitor); switch (result) { case DownloadHelper.DownloadResult.Canceled: progressMonitor.Log(StringFormat.Format(Resources.Module_Cef_Installer_Download_DeleteIncomplete, _cefPatchArchive)); File.Delete(_cefPatchArchive); throw new OperationCanceledException("Download canceled"); } } catch (OperationCanceledException) { throw; } catch (Exception e) //TODO not good { progressMonitor.Log(StringFormat.Format(Resources.GeneralErrorOccured, e.Message)); File.Delete(_cefPatchArchive); throw; } if (!IsCefArchiveAvailable()) { throw new DirectoryNotFoundException(_cefPatchArchive); } } return(_cefPatchArchive); }
//TODO exception handling public string ExtractCef(IProgressMonitor progressMonitor) { if (IsCefAvailable()) { return(_cefLibFolder); //Done } Directory.CreateDirectory(_cefLibFolder); var unpackingResults = ArchiveUnpackerHelper.ExtractArchive(_cefPatchArchive, _cefLibFolder, progressMonitor); switch (unpackingResults) { case ArchiveUnpackerHelper.ExtractionResult.Complete: progressMonitor.Log(Resources.Module_Cef_Installer_Unpack_Complete); File.Delete(_cefPatchArchive); break; case ArchiveUnpackerHelper.ExtractionResult.Canceled: progressMonitor.Log(StringFormat.Format(Resources.Module_Cef_Installer_Unpack_DeleteIncomplete, _cefLibFolder)); Directory.Delete(_cefLibFolder, true); throw new OperationCanceledException("Unpacking canceled"); } if (!IsCefAvailable()) { //TODO throw exception throw new DirectoryNotFoundException(_cefLibFolder); } return(_cefLibFolder); }
/// <summary> /// /// </summary> /// <param name="progressMonitor"></param> /// <returns></returns> /// <exception cref="DownloadFailedException"></exception> public Result Download(IProgressMonitor progressMonitor) { if (progressMonitor == null) { throw new ArgumentNullException(nameof(progressMonitor)); } if (IsFileAlreadyDownloaded()) { return(Result.Skipped); } try { Directory.CreateDirectory(OutputFolder); var result = DownloadHelper.DownloadFileFromGithub(downloadUrl: URL, destinationFile: FilePath, progressMonitor); switch (result) { case DownloadHelper.DownloadResult.Canceled: DeleteFile(progressMonitor); return(Result.Canceled); } } catch (DownloadFailedException ex) { progressMonitor.Log(StringFormat.Format(Resources.GeneralErrorOccured, ex.Message)); DeleteFile(progressMonitor); throw; } return(Result.Completed); }
private void PerformAutoUpdateInstall(string patchFolder, IProgressMonitor progressMonitor) { logger.Info("Prepare updates"); progressMonitor.StatusText = Resources.Module_Updater_UI_Log_PrepareUpdates; progressMonitor.Progress = 0d; var tmp = System.IO.Path.Combine(patchFolder, "Gobchat"); if (System.IO.Directory.Exists(tmp)) { patchFolder = tmp; } var manager = NAppUpdate.Framework.UpdateManager.Instance; manager.UpdateSource = new NAULocalFileUpdateSource(patchFolder); manager.UpdateFeedReader = new NAULocalFileFeedReader(); manager.Config.UpdateExecutableName = System.AppDomain.CurrentDomain.FriendlyName; manager.ReinstateIfRestarted(); manager.CheckForUpdates(); progressMonitor.Log(StringFormat.Format(Resources.Module_Updater_UI_Log_UpdateCount, manager.UpdatesAvailable)); if (manager.UpdatesAvailable > 0) { manager.PrepareUpdates(); } progressMonitor.StatusText = Resources.Module_Updater_UI_Log_Done; progressMonitor.Progress = 1d; logger.Info($"{manager.UpdatesAvailable} updates prepared."); }
private void DeleteExtractedData(IProgressMonitor progressMonitor) { progressMonitor.Log(Resources.Core_Util_ArchiveUnpacker_DeleteIncomplete); if (DeleteOutputFolderOnFail) { Directory.Delete(OutputFolderPath, true); } }
public Result Extract(IProgressMonitor progressMonitor) { if (progressMonitor == null) { throw new ArgumentNullException(nameof(progressMonitor)); } Directory.CreateDirectory(OutputFolderPath); ArchiveUnpackerHelper.ExtractionResult unpackingResults; try { unpackingResults = ArchiveUnpackerHelper.ExtractArchive(ArchivePath, OutputFolderPath, progressMonitor); } catch (ExtractionFailedException ex) { progressMonitor.Log(StringFormat.Format(Resources.GeneralErrorOccured, ex.Message)); DeleteExtractedData(progressMonitor); DeleteArchive(progressMonitor); throw; } switch (unpackingResults) { case ArchiveUnpackerHelper.ExtractionResult.Complete: progressMonitor.Log(Resources.Core_Util_ArchiveUnpacker_Complete); if (DeleteArchiveOnCompletion) { DeleteArchive(progressMonitor); } return(Result.Completed); case ArchiveUnpackerHelper.ExtractionResult.Canceled: DeleteExtractedData(progressMonitor); return(Result.Canceled); } return(Result.Completed); }
/// <summary> /// Resolves conflicts between all of the resolved references. /// If the same assembly name is duplicated with different versions, /// resolve to the higher version number. /// </summary> private void ResolveConflicts() { var sortedReferences = new List <AssemblyInfo>(); foreach (var usedReference in usedReferences) { try { var assemblyInfo = assemblyCache.GetAssemblyInfo(usedReference.Key); sortedReferences.Add(assemblyInfo); } catch (AssemblyLoadException) { progressMonitor.Log(Util.Logging.Severity.Warning, $"Could not load assembly information from {usedReference.Key}"); } } sortedReferences = sortedReferences.OrderBy(r => r.Version).ToList(); var finalAssemblyList = new Dictionary <string, AssemblyInfo>(); // Pick the highest version for each assembly name foreach (var r in sortedReferences) { finalAssemblyList[r.Name] = r; } // Update the used references list usedReferences.Clear(); foreach (var r in finalAssemblyList.Select(r => r.Value.Filename)) { UseReference(r); } // Report the results foreach (var r in sortedReferences) { var resolvedInfo = finalAssemblyList[r.Name]; if (resolvedInfo.Version != r.Version) { progressMonitor.ResolvedConflict(r.Id, resolvedInfo.Id); ++conflictedReferences; } } }
/// <summary> /// Performs a C# build analysis. /// </summary> /// <param name="options">Analysis options from the command line.</param> /// <param name="progress">Display of analysis progress.</param> public BuildAnalysis(Options options, IProgressMonitor progress) { var startTime = DateTime.Now; progressMonitor = progress; var sourceDir = new DirectoryInfo(options.SrcDir); progressMonitor.FindingFiles(options.SrcDir); allSources = sourceDir.GetFiles("*.cs", SearchOption.AllDirectories) .Select(d => d.FullName) .Where(d => !options.ExcludesFile(d)) .ToArray(); var dllDirNames = options.DllDirs.Select(Path.GetFullPath).ToList(); packageDirectory = new TemporaryDirectory(ComputeTempDirectory(sourceDir.FullName)); if (options.UseNuGet) { try { var nuget = new NugetPackages(sourceDir.FullName, packageDirectory); nuget.InstallPackages(progressMonitor); } catch (FileNotFoundException) { progressMonitor.MissingNuGet(); } } // Find DLLs in the .Net Framework if (options.ScanNetFrameworkDlls) { var runtimeLocation = Runtime.GetRuntime(options.UseSelfContainedDotnet); progressMonitor.Log(Util.Logging.Severity.Debug, $"Runtime location selected: {runtimeLocation}"); dllDirNames.Add(runtimeLocation); } // These files can sometimes prevent `dotnet restore` from working correctly. using (new FileRenamer(sourceDir.GetFiles("global.json", SearchOption.AllDirectories))) using (new FileRenamer(sourceDir.GetFiles("Directory.Build.props", SearchOption.AllDirectories))) { var solutions = options.SolutionFile is not null ? new[] { options.SolutionFile } : sourceDir.GetFiles("*.sln", SearchOption.AllDirectories).Select(d => d.FullName); if (options.UseNuGet) { RestoreSolutions(solutions); } dllDirNames.Add(packageDirectory.DirInfo.FullName); assemblyCache = new BuildAnalyser.AssemblyCache(dllDirNames, progress); AnalyseSolutions(solutions); foreach (var filename in assemblyCache.AllAssemblies.Select(a => a.Filename)) { UseReference(filename); } } ResolveConflicts(); if (options.UseMscorlib) { UseReference(typeof(object).Assembly.Location); } // Output the findings foreach (var r in usedReferences.Keys) { progressMonitor.ResolvedReference(r); } foreach (var r in unresolvedReferences) { progressMonitor.UnresolvedReference(r.Key, r.Value); } progressMonitor.Summary( AllSourceFiles.Count(), ProjectSourceFiles.Count(), MissingSourceFiles.Count(), ReferenceFiles.Count(), UnresolvedReferences.Count(), conflictedReferences, succeededProjects + failedProjects, failedProjects, DateTime.Now - startTime); }
/// <summary> /// /// </summary> /// <param name="downloadUrl"></param> /// <param name="destinationFile"></param> /// <param name="progressMonitor"></param> /// <returns></returns> /// <exception cref="DownloadFailedException"></exception> public static DownloadResult DownloadFileFromGithub(string downloadUrl, string destinationFile, IProgressMonitor progressMonitor) { var cancellationToken = progressMonitor.GetCancellationToken(); if (cancellationToken.IsCancellationRequested) { return(DownloadResult.Canceled); } if (!Directory.Exists(Path.GetDirectoryName(destinationFile))) { throw new DirectoryNotFoundException(Path.GetDirectoryName(destinationFile)); } Exception downloadException = null; using (var webClient = new WebClient()) { var currentVersion = GobchatContext.ApplicationVersion; webClient.Headers.Add("User-Agent", $"Gobchat v{currentVersion}"); progressMonitor.Progress = 0d; progressMonitor.StatusText = Resources.Core_Util_DownloadHelper_Waiting; progressMonitor.Log(Resources.Core_Util_DownloadHelper_Prepare); void OnDownloadProgressChanged(object s, DownloadProgressChangedEventArgs e) { progressMonitor.Progress = e.ProgressPercentage / 100d; progressMonitor.StatusText = StringFormat.Format(Resources.Core_Util_DownloadHelper_Download, e.BytesReceived, e.TotalBytesToReceive); if (cancellationToken.IsCancellationRequested) { progressMonitor.Log(Resources.Core_Util_DownloadHelper_Canceled); webClient.CancelAsync(); } } webClient.DownloadProgressChanged += OnDownloadProgressChanged; try { progressMonitor.Log(StringFormat.Format(Resources.Core_Util_DownloadHelper_Connecting, downloadUrl)); var downloadTask = webClient.DownloadFileTaskAsync(downloadUrl, destinationFile); downloadTask.Wait(); progressMonitor.Progress = 1d; progressMonitor.StatusText = Resources.Core_Util_DownloadHelper_Complete; progressMonitor.Log(Resources.Core_Util_DownloadHelper_Complete); } catch (AggregateException ex) { downloadException = ex.Flatten(); } catch (Exception ex) { downloadException = ex; } } if (downloadException != null && !cancellationToken.IsCancellationRequested) { throw new DownloadFailedException(downloadException.Message, downloadException); } return(cancellationToken.IsCancellationRequested ? DownloadResult.Canceled : DownloadResult.CompletedSuccessfully); }
/// <summary> /// /// </summary> /// <param name="archivePath"></param> /// <param name="destinationFolder"></param> /// <param name="progressMonitor"></param> /// <returns></returns> /// <exception cref="FileNotFoundException"></exception> /// <exception cref="DirectoryNotFoundException"></exception> /// <exception cref="ExtractionFailedException"></exception> public static ExtractionResult ExtractArchive(string archivePath, string destinationFolder, IProgressMonitor progressMonitor) { var cancellationToken = progressMonitor.GetCancellationToken(); if (cancellationToken.IsCancellationRequested) { return(ExtractionResult.Canceled); } if (!File.Exists(archivePath)) { throw new FileNotFoundException(archivePath); } if (!Directory.Exists(destinationFolder)) { throw new DirectoryNotFoundException(destinationFolder); } progressMonitor.StatusText = Resources.Core_Util_ArchiveUnpackerHelper_Unpack; progressMonitor.Progress = 0d; progressMonitor.Log(StringFormat.Format(Resources.Core_Util_ArchiveUnpackerHelper_UnpackLog, archivePath)); try { using (var archive = SharpCompress.Archives.ArchiveFactory.Open(archivePath)) { double totalArchiveSize = 0d; double processedBytes = 0d; foreach (var entry in archive.Entries) { totalArchiveSize += entry.Size; } totalArchiveSize = Math.Max(1, totalArchiveSize); using (var reader = archive.ExtractAllEntries()) { reader.EntryExtractionProgress += (sender, e) => { progressMonitor.Progress = (processedBytes + e.ReaderProgress.BytesTransferred) / totalArchiveSize; }; while (reader.MoveToNextEntry()) { if (cancellationToken.IsCancellationRequested) { progressMonitor.StatusText = Resources.Core_Util_ArchiveUnpackerHelper_Canceled; progressMonitor.Log(Resources.Core_Util_ArchiveUnpackerHelper_Canceled); return(ExtractionResult.Canceled); } var entry = reader.Entry; if (!entry.IsDirectory) { progressMonitor.StatusText = StringFormat.Format(Resources.Core_Util_ArchiveUnpackerHelper_UnpackLog, entry.Key); progressMonitor.Log(StringFormat.Format(Resources.Core_Util_ArchiveUnpackerHelper_UnpackLog, entry.Key)); reader.WriteEntryToDirectory(destinationFolder, new ExtractionOptions() { ExtractFullPath = true, Overwrite = true }); processedBytes += entry.Size; progressMonitor.Progress = processedBytes / totalArchiveSize; } } } } } catch (Exception ex) { throw new ExtractionFailedException(ex.Message, ex); } progressMonitor.StatusText = Resources.Core_Util_ArchiveUnpackerHelper_Complete; progressMonitor.Progress = 1d; return(ExtractionResult.Complete); }
private void DeleteFile(IProgressMonitor progressMonitor) { progressMonitor.Log(StringFormat.Format(Resources.Module_Updater_UI_Log_DeleteFile, FilePath)); File.Delete(FilePath); }
private void DeleteArchive(IProgressMonitor progressMonitor) { progressMonitor.Log(StringFormat.Format(Resources.Core_Util_ArchiveUnpacker_DeleteFile, ArchivePath)); File.Delete(ArchivePath); }