Exemplo n.º 1
0
        public void Dispose()
        {
            if (this.disposed)
            {
                return;
            }

            this.disposed = true;

            if (this.DeleteOnDispose)
            {
                this.log?.LogDebug("Deleting contents of: " + this.DiskPath);
                DirectoryEx.Delete(this.DiskPath);

                try
                {
                    this.log?.LogDebug("Deleting workspace: " + this.Workspace.Name);
                    this.Workspace.Delete();
                }
                catch (Exception ex)
                {
                    this.log?.LogWarning("Error deleting workspace: " + ex.Message);
                }
            }
            else
            {
                this.log?.LogDebug($"Workspace {this.Workspace.Name} will be persisted.");
            }
        }
Exemplo n.º 2
0
        private static MappedWorkspace GetOrCreate(WorkspaceInfo workspaceInfo, VersionControlServer versionControlServer, TfsSourcePath sourcePath, ILogSink log)
        {
            var workspaces = versionControlServer.QueryWorkspaces(workspaceInfo.Name, versionControlServer.AuthorizedUser, Environment.MachineName);
            var workspace  = workspaces.FirstOrDefault();

            if (workspace == null)
            {
                log?.LogDebug($"Workspace '{workspaceInfo.Name}' was not found for user '{versionControlServer.AuthorizedUser}' on machine '{Environment.MachineName}', creating...");
                workspace = versionControlServer.CreateWorkspace(workspaceInfo.Name);
            }

            log?.LogDebug("Workspace mappings: \r\n" + string.Join(Environment.NewLine, workspace.Folders.Select(m => m.LocalItem + "\t->\t" + m.ServerItem)));

            string diskPath = workspaceInfo.ResolveWorkspaceDiskPath(log);

            if (!workspace.IsLocalPathMapped(diskPath))
            {
                log?.LogDebug($"Local path is not mapped, creating mapping to \"{diskPath}\"...");
                DirectoryEx.Delete(diskPath);
                workspace.Map(sourcePath.AbsolutePath, diskPath);
            }

            if (!workspace.HasReadPermission)
            {
                throw new System.Security.SecurityException($"{versionControlServer.AuthorizedUser} does not have read permission for workspace '{workspaceInfo.Name}' at '{diskPath}'");
            }

            return(new MappedWorkspace(workspace, diskPath, false, log));
        }
            public override Task <object> ExecuteAsync(CancellationToken cancellationToken)
            {
                this.SetProgress(cancellationToken, "ensuring target directory exists");
                DirectoryEx.Create(this.TargetRootPath);

                int index = 0;

                if (this.DeleteExtra)
                {
                    this.SetProgress(cancellationToken, "checking existing files");
                    var remoteFileList = DirectoryEx.GetFileSystemInfos(this.TargetRootPath, MaskingContext.IncludeAll);

                    foreach (var file in remoteFileList)
                    {
                        index++;
                        this.SetProgress(cancellationToken, "checking existing files", 100 * index / remoteFileList.Count);

                        var relativeName = file.FullName.Substring(this.TargetRootPath.Length).Replace('\\', '/').Trim('/');
                        if (file is SlimDirectoryInfo)
                        {
                            if (!this.ExpectedDirectories.Contains(relativeName))
                            {
                                this.LogDebug("Deleting extra directory: " + relativeName);
                                DirectoryEx.Delete(file.FullName);
                            }
                        }
                        else
                        {
                            if (!this.ExpectedFiles.Contains(relativeName))
                            {
                                this.LogDebug($"Deleting extra file: " + relativeName);
                                FileEx.Delete(file.FullName);
                            }
                        }
                    }
                }

                index = 0;
                foreach (var relativeName in this.ExpectedDirectories)
                {
                    index++;
                    this.SetProgress(cancellationToken, "ensuring target subdirectories exist", 100 * index / this.ExpectedDirectories.Length);

                    DirectoryEx.Create(PathEx.Combine(Path.DirectorySeparatorChar, this.TargetRootPath, relativeName));
                }

                index = 0;
                foreach (var relativeName in this.ExpectedFiles)
                {
                    var sourcePath = PathEx.Combine(PathEx.Combine(Path.DirectorySeparatorChar, this.TempDirectoryName, "package"), relativeName);
                    var targetPath = PathEx.Combine(Path.DirectorySeparatorChar, this.TargetRootPath, relativeName);

                    index++;
                    this.SetProgress(cancellationToken, "moving files to target directory", 100 * index / this.ExpectedFiles.Length);

                    FileEx.Move(sourcePath, targetPath, true);
                }

                return(InedoLib.NullTask);
            }
Exemplo n.º 4
0
 private void RestoreBackup()
 {
     for (int i = 0; i < this._fileList.Count; i++)
     {
         PatchInfo item = this._fileList[i];
         FileEx.Move(item.DestinationFile, item.TempFile, true);
         FileEx.Move(item.BackupFile, item.DestinationFile, true);
         this.ReportProgress(BackgroundFilePatcher.States.RestoringBackup, BackgroundFilePatcher.CalculateProgress(i, this._fileList.Count));
     }
     DirectoryEx.Delete(Paths.Elsword.Media);
     DirectoryEx.Delete(Paths.Elsword.Backup);
 }
Exemplo n.º 5
0
        public bool Save()
        {
            bool IsOk = true;

            DirectoryEx.Delete(ParaPath);
            if (!DirectoryEx.Exist(ParaPath))
            {
                DirectoryEx.Create(ParaPath);
            }
            IsOk = IsOk && XML <BindingList <CameraPara> > .Write(CameraParaList, ParaPath + @"\" + "CameraParaList.xml");

            return(IsOk);
        }
Exemplo n.º 6
0
 public static void UnblockLogs()
 {
     foreach (string str in Paths.Elsword.LogFiles.Where <string>((string logFile) => {
         if (!PathEx.Exists(logFile))
         {
             return(true);
         }
         return(!PathEx.IsFile(logFile));
     }))
     {
         PathEx.RemoveAttributes(str);
         DirectoryEx.Delete(str);
     }
 }
Exemplo n.º 7
0
 private void CancelBtn_Click(object sender, EventArgs e)
 {
     try
     {
         if (Transferor.IsBusy)
         {
             Transferor.CancelAsync();
         }
         DirectoryEx.Delete(CachePaths.UpdateDir);
     }
     catch (Exception ex) when(ex.IsCaught())
     {
         Log.Write(ex);
     }
     Application.Exit();
 }
Exemplo n.º 8
0
        private void CleanTempDirectory()
        {
            var tempDirectory = PathEx.Combine(RompConfig.DefaultWorkingDirectory, "_E" + this.ExecutionId);

            DirectoryEx.Delete(tempDirectory);
        }
Exemplo n.º 9
0
        protected override async Task <object> RemoteExecuteAsync(IRemoteOperationExecutionContext context)
        {
            var fullPath = context.ResolvePath(this.FileName);

            this.LogInformation($"Changing \"{fullPath}\" package version to {AH.CoalesceString(this.NewVersion, "remove pre-release label")}...");

            var tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("n"));

            try
            {
                DirectoryEx.Create(tempPath);
                UniversalPackageMetadata currentMetadata;
                using (var upack = new UniversalPackage(fullPath))
                {
                    currentMetadata = upack.GetFullMetadata();
                    await upack.ExtractAllItemsAsync(tempPath, context.CancellationToken);

                    FileEx.Delete(PathEx.Combine(tempPath, "upack.json"));
                }

                var newMetadata = currentMetadata.Clone();
                if (string.IsNullOrEmpty(this.NewVersion))
                {
                    newMetadata.Version = new UniversalPackageVersion(currentMetadata.Version.Major, currentMetadata.Version.Minor, currentMetadata.Version.Patch);
                }
                else
                {
                    newMetadata.Version = UniversalPackageVersion.Parse(this.NewVersion);
                }

                if (currentMetadata.Version == newMetadata.Version)
                {
                    this.LogWarning($"Current package version {currentMetadata.Version} and the new version {newMetadata.Version} are the same; nothing to do.");
                    return(null);
                }

                this.LogInformation("New version: " + newMetadata.Version);

                this.LogDebug("Adding repacking entry...");
                newMetadata.RepackageHistory.Add(
                    new RepackageHistoryEntry
                {
                    Id     = new UniversalPackageId(currentMetadata.Group, currentMetadata.Name) + ":" + currentMetadata.Version,
                    Date   = DateTimeOffset.Now,
                    Using  = SDK.ProductName + "/" + SDK.ProductVersion,
                    Reason = this.Reason
                }
                    );

                using (var builder = new UniversalPackageBuilder(fullPath, newMetadata))
                {
                    await builder.AddRawContentsAsync(tempPath, string.Empty, true, c => true, context.CancellationToken);
                }

                this.LogInformation("Package version changed.");

                return(null);
            }
            finally
            {
                try
                {
                    this.LogDebug($"Deleting temporary files from {tempPath}...");
                    DirectoryEx.Clear(tempPath);
                    DirectoryEx.Delete(tempPath);
                }
                catch (Exception ex)
                {
                    this.LogWarning("Unable to delete temporary files: " + ex.Message);
                }
            }
        }
Exemplo n.º 10
0
        public override void Import(IBuildImporterContext context)
        {
            var configurer = (NuGetConfigurer)this.GetExtensionConfigurer();

            if (configurer.AlwaysClearNuGetCache)
            {
                this.LogDebug("Clearing NuGet cache...");
                if (NuGetConfigurer.ClearCache())
                {
                    this.LogDebug("Cache cleared!");
                }
                else
                {
                    this.LogWarning("Error clearing cache; a file may be locked.");
                }
            }

            var nugetExe = configurer != null ? configurer.NuGetExe : null;

            if (string.IsNullOrEmpty(nugetExe))
            {
                nugetExe = Path.Combine(Path.GetDirectoryName(typeof(NuGetBuildImporter).Assembly.Location), "nuget.exe");
            }

            var packageSource = Util.CoalesceStr(this.PackageSource, configurer != null ? configurer.PackageSource : null);

            var args = "install \"" + this.PackageId + "\" -ExcludeVersion -NoCache";

            if (!string.IsNullOrEmpty(this.PackageVersion))
            {
                args += " -Version \"" + this.PackageVersion + "\"";
            }
            if (this.IncludePrerelease)
            {
                args += " -Prerelease";
            }
            if (!string.IsNullOrEmpty(packageSource))
            {
                args += " -Source \"" + packageSource + "\"";
            }

            var tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            try
            {
                Directory.CreateDirectory(tempPath);

                args += " -OutputDirectory \"" + tempPath + "\"";

                if (!string.IsNullOrWhiteSpace(this.AdditionalArguments))
                {
                    args += " " + this.AdditionalArguments;
                }

                this.LogDebug($"Executing {nugetExe} {args}");
                this.LogInformation("Executing NuGet...");

                using (var process = new LocalProcess(new RemoteProcessStartInfo {
                    FileName = nugetExe, Arguments = args
                }))
                {
                    process.OutputDataReceived += this.Process_OutputDataReceived;
                    process.ErrorDataReceived  += this.Process_ErrorDataReceived;
                    process.Start();
                    process.WaitForExit();

                    if (process.ExitCode != 0)
                    {
                        this.LogError($"NuGet failed with exit code {process.ExitCode}.");
                        return;
                    }
                }

                this.LogInformation("NuGet indicated successful package install.");

                var packageRootPath = Path.Combine(tempPath, this.PackageId);
                var artifactName    = this.PackageId;

                if (this.CaptureIdAndVersion || this.IncludeVersionInArtifactName)
                {
                    try
                    {
                        var nupkgPath = Path.Combine(packageRootPath, this.PackageId + ".nupkg");
                        this.LogDebug($"Attempting to gather metadata from {nupkgPath}...");
                        var nuspec = NuGetPackage.ReadFromNupkgFile(nupkgPath);

                        var packageId      = nuspec.Id;
                        var packageVersion = nuspec.Version.OriginalString;

                        if (this.CaptureIdAndVersion)
                        {
                            this.LogDebug("Setting $ImportedPackageId = " + packageId);
                            SetBuildVariable(context, "ImportedPackageId", packageId);

                            this.LogDebug("Setting $ImportedPackageVersion = " + packageVersion);
                            SetBuildVariable(context, "ImportedPackageVersion", packageVersion);
                        }

                        if (this.IncludeVersionInArtifactName)
                        {
                            artifactName = packageId + "." + packageVersion;
                        }
                    }
                    catch (Exception ex)
                    {
                        this.LogError("Could not read package metadata: " + ex.ToString());
                        return;
                    }
                }

                var rootCapturePath = Path.Combine(packageRootPath, (this.PackageArtifactRoot ?? string.Empty).Replace('/', '\\').TrimStart('/', '\\'));
                this.LogDebug($"Capturing files in {rootCapturePath}...");

                var rootEntry = Util.Files.GetDirectoryEntry(
                    new GetDirectoryEntryCommand
                {
                    Path            = rootCapturePath,
                    IncludeRootPath = true,
                    Recurse         = true
                }
                    ).Entry;

                using (var agent = BuildMasterAgent.CreateLocalAgent())
                {
                    var fileOps    = agent.GetService <IFileOperationsExecuter>();
                    var matches    = Util.Files.Comparison.GetMatches(rootCapturePath, rootEntry, new[] { "!\\" + this.PackageId + ".nupkg", "*" });
                    var artifactId = new ArtifactIdentifier(context.ApplicationId, context.ReleaseNumber, context.BuildNumber, context.DeployableId, artifactName);

                    this.LogInformation($"Creating artifact {artifactName}...");
                    using (var artifact = new ArtifactBuilder(artifactId))
                    {
                        artifact.RootPath = rootCapturePath;

                        foreach (var match in matches)
                        {
                            artifact.Add(match, fileOps);
                        }

                        artifact.Commit();
                    }

                    this.LogInformation("Artifact created.");
                }
            }
            finally
            {
                try
                {
                    DirectoryEx.Delete(tempPath);
                }
                catch
                {
                }
            }
        }