本文整理汇总了C#中IExecutionContext.AddProcess方法的典型用法代码示例。如果您正苦于以下问题:C# IExecutionContext.AddProcess方法的具体用法?C# IExecutionContext.AddProcess怎么用?C# IExecutionContext.AddProcess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IExecutionContext
的用法示例。
在下文中一共展示了IExecutionContext.AddProcess方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Install
public override void Install(IApplicationLicense license, IExecutionContext context, ref bool forceCreation)
{
if (context.HasCompleted | context.AutoLaunch)
{
#region Variables
string executablePath = String.Empty,
workingDirectory = String.Empty,
arguments = String.Empty;
var key = license.KeyAs<SteamLicenseKey>();
#endregion
#region Initialize Variables
if (!String.IsNullOrWhiteSpace(context.Executable.ExecutablePath))
{
executablePath = Environment.ExpandEnvironmentVariables(context.Executable.ExecutablePath);
}
else
{
throw new ArgumentNullException("Steam executable path invalid", "ExecutablePath");
}
if (!String.IsNullOrWhiteSpace(context.Executable.WorkingDirectory))
{
workingDirectory = Environment.ExpandEnvironmentVariables(context.Executable.WorkingDirectory);
}
else
{
workingDirectory = Path.GetDirectoryName(executablePath);
}
if (!String.IsNullOrWhiteSpace(context.Executable.Arguments))
{
arguments = Environment.ExpandEnvironmentVariables(context.Executable.Arguments);
}
arguments = String.Format("-login {0} {1} {2}", key.Username, key.Password, arguments);
#endregion
#region Initialize Process
var streamProcess = new Process();
streamProcess.StartInfo.FileName = executablePath;
streamProcess.StartInfo.WorkingDirectory = workingDirectory;
streamProcess.StartInfo.Arguments = arguments;
streamProcess.StartInfo.UseShellExecute = false;
streamProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
streamProcess.EnableRaisingEvents = true;
streamProcess.Exited += new EventHandler(OnInternalProcessExited);
#endregion
#region Start steam process
context.ExecutionStateChaged += OnExecutionStateChaged;
//set environment variables
if (!String.IsNullOrWhiteSpace(key.Username))
Environment.SetEnvironmentVariable("LICENSEKEYUSER", key.Username);
if (!String.IsNullOrWhiteSpace(key.AccountId))
Environment.SetEnvironmentVariable("LICENSEKEYUSERID", key.AccountId);
if (streamProcess.Start())
{
//executables process creation should not be forced
forceCreation = false;
//add process to context
context.AddProcess(streamProcess, true);
}
else
{
throw new Exception("Steam process was not created.");
}
#endregion
}
}
示例2: Install
//.........这里部分代码省略.........
string processName = Path.GetFileNameWithoutExtension(originPath);
#region Initialize Process
//get existing origin process
var originProcess = Process.GetProcessesByName(processName).Where(x => String.Compare(x.MainModule.FileName, originPath, true) == 0).FirstOrDefault();
bool processExisted = originProcess != null;
if (!processExisted)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = originPath;
startInfo.Arguments = "/NoEULA";
startInfo.WorkingDirectory = Path.GetDirectoryName(originPath);
startInfo.ErrorDialog = false;
startInfo.UseShellExecute = false;
//create origin process
originProcess = new Process() { StartInfo = startInfo };
}
originProcess.EnableRaisingEvents = true;
originProcess.Exited += new EventHandler(OnInternalProcessExited);
#endregion
#region Start Origin
if (processExisted || originProcess.Start())
{
//mark process created
forceCreation = true;
//atach handlers
context.ExecutionStateChaged += OnExecutionStateChaged;
//add process to context process list
context.AddProcess(originProcess, true);
if (CoreProcess.WaitForWindowCreated(originProcess, 120000, true))
{
try
{
IntPtr mainWindow = originProcess.MainWindowHandle;
//create input simulator
WindowsInput.KeyboardSimulator sim = new WindowsInput.KeyboardSimulator();
if (!this.FocusField(originProcess, OriginInputFileds.Username, 50))
return;
//clear username filed
sim.ModifiedKeyStroke(WindowsInput.Native.VirtualKeyCode.LCONTROL, WindowsInput.Native.VirtualKeyCode.VK_A);
//send back to clear any possible typed value
sim.KeyPress(WindowsInput.Native.VirtualKeyCode.BACK);
//set username
sim.TextEntry(license.KeyAs<UserNamePasswordLicenseKeyBase>().Username);
if (!this.FocusField(originProcess, OriginInputFileds.Password, 50))
return;
//clear password filed
sim.ModifiedKeyStroke(WindowsInput.Native.VirtualKeyCode.LCONTROL, WindowsInput.Native.VirtualKeyCode.VK_A);
//send back to clear any possible typed value
sim.KeyPress(WindowsInput.Native.VirtualKeyCode.BACK);
//set password
sim.TextEntry(license.KeyAs<UserNamePasswordLicenseKeyBase>().Password);
//proceed with login
sim.KeyPress(WindowsInput.Native.VirtualKeyCode.RETURN);
//set environment variable
Environment.SetEnvironmentVariable("LICENSEKEYUSER", license.KeyAs<OriginLicenseKey>().Username);
//wait for window to be destroyed
if (CoreProcess.WaitForWindowDestroyed(mainWindow, 120000))
//delay installation process
System.Threading.Thread.Sleep(3000);
}
catch
{
throw;
}
}
else
{
context.Client.Log.AddError("Origin client window was not created after specified period of time.", null, LogCategories.Configuration);
}
}
else
{
context.Client.Log.AddError(String.Format("Origin client executable {0} could not be started.", originPath), null, LogCategories.Configuration);
}
#endregion
}
}
示例3: Install
public override void Install(IApplicationLicense license, IExecutionContext context, ref bool forceCreation)
{
if (context.HasCompleted | context.AutoLaunch)
{
#region Validation
//get installation directory
string uplayPath = this.GetUplayPath();
if (String.IsNullOrWhiteSpace(uplayPath) || !File.Exists(uplayPath))
{
context.Client.Log.AddError(String.Format("Uplay client executable not found at {0}.", uplayPath), null, LogCategories.Configuration);
return;
}
#endregion
string processName = Path.GetFileNameWithoutExtension(uplayPath);
#region Initialize Process
//get existing uplay process
var uplayProcess = Process.GetProcessesByName(processName).Where(x => String.Compare(x.MainModule.FileName, uplayPath, true) == 0).FirstOrDefault();
bool processExisted = uplayProcess != null;
if(!processExisted)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = uplayPath;
startInfo.WorkingDirectory = Path.GetDirectoryName(uplayPath);
startInfo.ErrorDialog = false;
startInfo.UseShellExecute = false;
//create uplay process
uplayProcess = new Process() { StartInfo = startInfo };
}
uplayProcess.EnableRaisingEvents = true;
uplayProcess.Exited += new EventHandler(OnInternalProcessExited);
#endregion
#region Start Uplay
if (uplayProcess.Start())
{
//mark process created
forceCreation = true;
//atach handlers
context.ExecutionStateChaged += OnExecutionStateChaged;
//add process to context process list
context.AddProcess(uplayProcess, true);
if (CoreProcess.WaitForWindowCreated(uplayProcess, 120000, true))
{
try
{
//disable input
User32.BlockInput(true);
//get window
WindowInfo uplayWindow = new WindowInfo(uplayProcess.MainWindowHandle);
//activate origin window
uplayWindow.BringToFront();
uplayWindow.Activate();
//give some time to activate fields
System.Threading.Thread.Sleep(5000);
//disable input
User32.BlockInput(true);
//activate origin window
uplayWindow.BringToFront();
uplayWindow.Activate();
//create input simulator
WindowsInput.KeyboardSimulator sim = new WindowsInput.KeyboardSimulator();
//send tab
sim.ModifiedKeyStroke(WindowsInput.Native.VirtualKeyCode.LCONTROL, WindowsInput.Native.VirtualKeyCode.TAB);
//clear username filed
sim.ModifiedKeyStroke(WindowsInput.Native.VirtualKeyCode.LCONTROL, WindowsInput.Native.VirtualKeyCode.VK_A);
//disable input
User32.BlockInput(true);
//activate origin window
uplayWindow.BringToFront();
uplayWindow.Activate();
//send back to clear any possible typed value
sim.KeyDown(WindowsInput.Native.VirtualKeyCode.BACK);
//disable input
User32.BlockInput(true);
//activate origin window
uplayWindow.BringToFront();
uplayWindow.Activate();
//.........这里部分代码省略.........