public AppInstallerResult Run(AppInstallerArgument appInstallerArgument) { appInstallerArgument.ThrowArgumentExceptionIfNull(nameof(appInstallerArgument)); WaitForExitInInstallDir(appInstallerArgument); var excludeRelativePathRegex = appInstallerArgument .ExcludeRelativePathRegex .Select(reg => new Regex(reg, RegexOptions.IgnoreCase)) .ToList(); var directoryPath = appInstallerArgument.SourceDir.ToDirectoryPath(); var allFiles = directoryPath.GetFiles( "*", SearchOption.AllDirectories); var excludeRelativePaths = allFiles .Select(f => f.ToFilePath().GetRelativePath(appInstallerArgument.SourceDir.ToDirectoryPath()).Value) .Where(f => excludeRelativePathRegex.AnyIsMatch(f)) .ToHashSet(StringComparer.OrdinalIgnoreCase); appInstallerArgument.SourceDir.ToDirectoryPath().CopyDirectory( appInstallerArgument.InstallDir.ToDirectoryPath(), true, true, excludeRelativePaths); var newInstallerPath = Path.Combine(appInstallerArgument.InstallDir, appInstallerAssemblyName); var newArgument = CreateRunNewAppInstallerInAppFolderArgument(appInstallerArgument); newInstallerPath.ToFilePath().RunProcess(newArgument.ToCommandLineString(), true); return(new AppInstallerResult { ResultCode = ResultCode.Success, Updated = true }); }
private static AppInstallerArgument CreateRunAppInstallerInTempArgument( AppInstallerArgument argument, string tempDirectoryPath) { var newArgument = argument.Clone(); newArgument.RunMode = RunMode.RunNewAppInstallerInTempFolder; newArgument.TempFolder = tempDirectoryPath; return(newArgument); }
private void WaitForExitInInstallDir(AppInstallerArgument appInstallerArgument) { if (!appInstallerArgument.OriginalAppPath.IsNullOrEmpty()) { var originalApp = appInstallerArgument.OriginalAppPath.ToFilePath().GetProcessByFileName(); originalApp.Value?.WaitForExit(100000); originalApp.Value?.Dispose(); } var appInstallerPathInInstallDir = Path.Combine(appInstallerArgument.InstallDir, appInstallerAssemblyName); var appInstallerInInstallDir = appInstallerPathInInstallDir.ToFilePath().GetProcessByFileName(); appInstallerInInstallDir.Value?.WaitForExit(100000); appInstallerInInstallDir.Value?.Dispose(); }
public void Run() { // Arrange var target = this.CreateTarget(); AppInstallerArgument argument = new AppInstallerArgument() { InstallDir = InstallDirPath, SourceDir = SourceDirPath }; // Act var result = target.Run(argument); // Assert Assert.AreEqual(ResultCode.Success, result.ResultCode); }
public AppInstallerResult Run(AppInstallerArgument argument) { #pragma warning disable CA1062 // Validate arguments of public methods argument.ThrowArgumentExceptionIfNull(nameof(argument)); var appInstallerPathInTempDir = Path.Combine(argument.TempFolder, this.appInstallerAssemblyName); #pragma warning restore CA1062 // Validate arguments of public methods var appInstallerInInstallDir = appInstallerPathInTempDir.ToFilePath().GetProcessByFileName(); appInstallerInInstallDir.Value?.WaitForExit(5000); Try.To(() => Directory.Delete(argument.TempFolder, true)); argument.OriginalAppPath?.ToFilePath().RunProcess(); appInstallerInInstallDir.Value.Dispose(); return(new AppInstallerResult { ResultCode = ResultCode.Success, Updated = true }); }
static void Main(string[] args) { if (args.Length != 1) { #if DEBUG var appArg = new AppInstallerArgument(RunMode.RunExistingAppInstallerInAppFolder) { SourceDir = @"..\New", InstallDir = @"..\Old", OriginalAppPath = @"Updated.txt", TempFolder = @"..\AppInstaller_Temp", }; appArg.ExcludeRelativePathRegex.Add(@".*\.log"); args = new[] { appArg.ToCommandLineString(false) }; #else return; #endif } AppInstallerResult modeAppInstallerResult; try { modeAppInstallerResult = InternalMain(args[0]); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) #pragma warning restore CA1031 // Do not catch general exception types { modeAppInstallerResult = new AppInstallerResult { ResultCode = ResultCode.InternalError, Message = e.Message }; var message = string.Join(Environment.NewLine, e.Message, args[0]); "Error.log".ToFilePath().WriteAllText(message); } Console.WriteLine(new AppInstallerResultConverter().ToString(modeAppInstallerResult)); }
public AppInstallerResult Run(AppInstallerArgument argument) { #pragma warning disable CA1062 // Validate arguments of public methods argument.ThrowArgumentExceptionIfNull(nameof(argument)); var installDir = argument.InstallDir.ToDirectoryPath().ToFullDirectoryPath().Value; #pragma warning restore CA1062 // Validate arguments of public methods var sourceDir = new DirectoryInfo(argument.SourceDir).FullName; var tempDirectoryPath = Path.Combine(installDir, "..", "AppInstaller_Temp").ToDirectoryPath().ToFullDirectoryPath().Value; CopyAppInstallerFiles(sourceDir, tempDirectoryPath); var appInstallerForUpdatePath = Path.Combine(tempDirectoryPath, appInstallerAssemblyName); var runAppInstallerInTempArg = CreateRunAppInstallerInTempArgument(argument, tempDirectoryPath); appInstallerForUpdatePath.ToFilePath().RunProcess(runAppInstallerInTempArg.ToCommandLineString(), true); return(new AppInstallerResult { ResultCode = ResultCode.Success }); }
private static AppInstallerArgument CreateRunNewAppInstallerInAppFolderArgument(AppInstallerArgument appInstallerArgument) { var newArgument = appInstallerArgument.Clone(); newArgument.RunMode = RunMode.RunNewAppInstallerInAppFolder; return(newArgument); }