public void Extract(string compresedFile, string uncompresedDir) { try { UnZipFromMTAThread(compresedFile, uncompresedDir); } catch (Exception e) { installationPackage.ErrorMessage = e.Message; installationPackage.OnInstallFailed(ErrorConsts.ERR_EXTRACT_GENERAL, installationPackage.ErrorMessage); } installationPackage.HandleExtractEnded(); }
internal void Run(string runName, string runParam = "") { _runnerThread = new Thread(() => { lock (terminationLock) { try { try { Process p = null; #if DEBUG Logger.GetLogger().Info($"Running {runName} {runParam}"); #endif if (_installationPackage.RunWithBits && !FileUtils.IsRunnableFile(runName, false)) { #if DEBUG Logger.GetLogger().Info($"{runName} sets to run with BITS but it's not an executable file. BITS is not going to be used"); #endif _installationPackage.RunWithBits = false; } if (_installationPackage.RunWithBits) { BitsEnabled = true; } else { p = new Process(); p.StartInfo.FileName = runName; p.StartInfo.Arguments = runParam; p.StartInfo.UseShellExecute = !FileUtils.IsExeFileExtension(runName); } if (Path.GetExtension(runName).ToLower() == ".msi") { int msiTimeout = _installationPackage.msiTimeout; if (!WaitForMsi(runName, msiTimeout)) { throw new Win32Exception(ERROR_INSTALL_ALREADY_RUNNING); } } _installationPackage.HandleRunStart(); _processRunTime = Stopwatch.StartNew(); Process[] preRunningProcesses = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(runName)); int preRunningProcessesCount = preRunningProcesses.Length; foreach (Process preProcess in preRunningProcesses) { preProcess.EnableRaisingEvents = true; preProcess.Exited += new EventHandler(delegate(object sender, EventArgs e) { preRunningProcessesCount--; }); } //release the JobTransferred lock if (_installationPackage.onRunWithBits.Set() && BitsEnabled) { Process[] processByName = new Process[] { }; Stopwatch timer = new Stopwatch(); timer.Start(); do { processByName = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(runName)); Thread.Sleep(100); } while (processByName.Length <= preRunningProcessesCount && timer.Elapsed.TotalSeconds < 10); timer.Stop(); if (processByName.Length > preRunningProcessesCount) { foreach (Process candidate in processByName) { if (preRunningProcesses.All(current => current.Id != candidate.Id) && candidate.ProcessName != candidate.Parent()?.ProcessName) { p = candidate; break; } } } } if (p != null) { p.EnableRaisingEvents = true; p.Exited += (object sender, EventArgs e) => { if (sender is Process process) { _installationPackage.runExitCode = process.ExitCode; ConfigParser.GetConfig().SetProductSettingsXml(_installationPackage.ProdSettings, "StaticData/CustomData/RunData/ExitCode", process.ExitCode.ToString()); if (_processRunTime != null) { ConfigParser.GetConfig().SetProductSettingsXml (_installationPackage.ProdSettings, "StaticData/CustomData/RunData/RunTimeMS", _processRunTime.ElapsedMilliseconds.ToString()); } if (_installationPackage.WaitForIt) { _installationPackage.HandleRunEnd(); } } }; if (!BitsEnabled) { p.Start(); } } else { throw new Exception($"Process not found: {Path.GetFileName(runName)}"); } } catch (Win32Exception ex) { _installationPackage.runErrorCode = ex.NativeErrorCode; throw; } finally { BitsEnabled = false; } } catch (Exception ex) { _installationPackage.ErrorMessage = $"Running {runName} {runParam} - {ex.Message}"; _installationPackage.OnInstallFailed(ErrorConsts.ERR_RUN_GENERAL, _installationPackage.ErrorMessage); } if (!_installationPackage.WaitForIt) { _installationPackage.HandleRunEnd(); } } }); _runnerThread.Start(); }