public virtual string Gzip(IAbsoluteFilePath file, IAbsoluteFilePath dest = null, bool preserveFileNameAndModificationTime = true, ITProgress status = null) { Contract.Requires<ArgumentNullException>(file != null); Contract.Requires<ArgumentException>(file.Exists); var defDest = (file + ".gz").ToAbsoluteFilePath(); if (dest == null) dest = defDest; var cmd = $"-f --best --rsyncable --keep \"{file}\""; if (!preserveFileNameAndModificationTime) cmd = "-n " + cmd; dest.RemoveReadonlyWhenExists(); var startInfo = new ProcessStartInfoBuilder(Common.Paths.ToolPath.GetChildFileWithName("gzip.exe"), cmd) { WorkingDirectory = file.ParentDirectoryPath }.Build(); var srcSize = file.FileInfo.Length; ProcessExitResultWithOutput ret; var predictedSize = srcSize*DefaultPredictedCompressionRatio; using (StatusProcessor.Conditional(defDest, status, (long) predictedSize)) ret = ProcessManager.LaunchAndGrabTool(startInfo, "Gzip pack"); if (Path.GetFullPath(dest.ToString()) != Path.GetFullPath(defDest.ToString())) FileUtil.Ops.MoveWithRetry(defDest, dest); return ret.StandardOutput + ret.StandardError; }
void CreateFiles(string outFile, bool overwrite = false, int bits = SshKeyPair.DefaultBits, string type = SshKeyPair.DefaultType) { if (!overwrite && File.Exists(outFile)) throw new IOException("File exists " + outFile); var startInfo = new ProcessStartInfoBuilder(sshKeyGenBin, GetParameters(outFile, bits, type)).Build(); _processManager.LaunchAndGrabTool(startInfo); }
public void RunExtractPboWithParameters(IAbsoluteFilePath input, IAbsoluteDirectoryPath output, params string[] parameters) { if (!input.Exists) throw new IOException("File doesn't exist: " + input); var startInfo = new ProcessStartInfoBuilder(_extractPboBin, BuildParameters(input.ToString(), output.ToString(), parameters)).Build(); ProcessExitResult(_processManager.LaunchAndGrabTool(startInfo)); }
public void Launch(IProcessManager processManager) { Contract.Requires<ArgumentNullException>(Path != null); Contract.Requires<ArgumentException>(!String.IsNullOrWhiteSpace(Path)); //if (!UserSettings.Current.AppOptions.UseElevatedService) { var startInfo = new ProcessStartInfoBuilder(Path, Parameters) { WorkingDirectory = Path.ToAbsoluteFilePath().ParentDirectoryPath, //AsAdministrator = RunAsAdmin }.Build(); MainLog.Logger.Info("Launching external app: " + startInfo.Format()); processManager.StartAndForget(startInfo); //} else { // _wcfClient.Value.Updater_StartAndForget(Path, Parameters, System.IO.Path.GetDirectoryName(Path), RunAsAdmin); //} }
public virtual string GzipStdOut(IAbsoluteFilePath inputFile, IAbsoluteFilePath outputFile = null, bool preserveFileNameAndModificationTime = true, ITProgress status = null) { Contract.Requires<ArgumentException>(inputFile != null); Contract.Requires<ArgumentException>(inputFile.Exists); if (outputFile == null) outputFile = (inputFile + ".gz").ToAbsoluteFilePath(); var cmd = $"-f --best --rsyncable --keep --stdout \"{inputFile}\" > \"{outputFile}\""; if (!preserveFileNameAndModificationTime) cmd = "-n " + cmd; outputFile.RemoveReadonlyWhenExists(); var startInfo = new ProcessStartInfoBuilder(Common.Paths.ToolPath.GetChildFileWithName("gzip.exe"), cmd) { WorkingDirectory = Common.Paths.LocalDataPath }.Build(); var srcSize = inputFile.FileInfo.Length; ProcessExitResultWithOutput ret; var predictedSize = srcSize*DefaultPredictedCompressionRatio; using (StatusProcessor.Conditional(outputFile, status, (long) predictedSize)) ret = ProcessManager.LaunchAndGrabToolCmd(startInfo, "Gzip pack"); return ret.StandardOutput + ret.StandardError; }
protected static async Task BuildAndRunBatFile(IProcessManager pm, IAbsoluteDirectoryPath tmpFolder, IEnumerable<string> commands, bool asAdministrator = false, bool noisy = false) { var batFile = tmpFolder.GetChildFileWithName("install.bat"); var actualCommands = new[] {"chcp 65001"}.Concat(commands) .Concat(new[] {"echo finished"}) .Select(x => x == "" ? x : x + " >> install.log"); var commandBat = string.Join("\r\n", new[] {"", "echo starting > install.log"}.Concat(actualCommands) .Concat(new[] {""})); var encoding = Encoding.UTF8; File.WriteAllText(batFile.ToString(), commandBat, encoding); if (Common.Flags.Verbose || noisy) MainLog.Logger.Info("install.bat content:\n" + commandBat); try { var pInfo = new ProcessStartInfoBuilder(batFile) { WorkingDirectory = tmpFolder //WindowStyle = ProcessWindowStyle.Minimized }.Build(); pInfo.CreateNoWindow = true; var basicLaunchInfo = new BasicLaunchInfo(pInfo) {StartMinimized = true}; var r = await (asAdministrator ? pm.LaunchElevatedAsync(basicLaunchInfo) : pm.LaunchAsync(basicLaunchInfo)); r.ConfirmSuccess(); } catch (Win32Exception ex) { if (ex.IsElevationCancelled()) throw ex.HandleUserCancelled(); throw; } var logFile = tmpFolder.GetChildFileWithName("install.log"); var output = File.ReadAllText(logFile.ToString(), encoding); if (Common.Flags.Verbose || noisy) MainLog.Logger.Info("install.bat output:\n" + output); }
public virtual ProcessExitResultWithOutput LaunchAndGrabToolCmd(ProcessStartInfo info, string tool) { var startInfo = new ProcessStartInfoBuilder(Common.Paths.CmdExe, $"/C \"\"{info.FileName}\" {info.Arguments}\"") { WorkingDirectory = info.WorkingDirectory.ToAbsoluteDirectoryPathNullSafe() }.Build(); return LaunchAndGrabTool(startInfo, tool); }
void RunMakePbo(string parameters) { var startInfo = new ProcessStartInfoBuilder(_makePboBin, parameters).Build(); ProcessExitResult(_processManager.LaunchAndGrabTool(startInfo)); }
public void SignFile(IAbsoluteFilePath file, IAbsoluteFilePath privateFile) { Contract.Requires<ArgumentNullException>(file != null); if (!file.Exists) throw new IOException("File doesn't exist: " + file); if (!privateFile.Exists) throw new IOException("File doesn't exist: " + privateFile); var startInfo = new ProcessStartInfoBuilder(_dsSignFileBin, BuildPathParameters(privateFile.ToString(), file.ToString())) { WorkingDirectory = Common.Paths.StartPath }.Build(); ProcessExitResult(_processManager.LaunchAndGrabTool(startInfo)); }
public void CreateKey(IAbsoluteFilePath outFile, bool overwrite = false) { Contract.Requires<ArgumentNullException>(outFile != null); var privateFile = outFile + ".biprivatekey"; var publicFile = outFile + ".bikey"; if (!overwrite) { if (File.Exists(privateFile)) throw new IOException("File exists: " + privateFile); if (File.Exists(publicFile)) throw new IOException("File exists: " + publicFile); } var parentPath = outFile.ParentDirectoryPath; if (!parentPath.Exists) throw new InvalidOperationException("Does not exist: " + parentPath + " of: " + outFile); var startInfo = new ProcessStartInfoBuilder(_dsCreateKeyBin, BuildPathParameters(outFile.FileName)) { WorkingDirectory = parentPath }.Build(); ProcessExitResult(_processManager.LaunchAndGrabTool(startInfo)); }