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 } }
public override void Install(IApplicationLicense license, IExecutionContext context, ref bool forceCreation) { if (context.HasCompleted | context.AutoLaunch) { #region Validation //get installation directory string originPath = this.GetOriginPath(); if (String.IsNullOrWhiteSpace(originPath)) { context.Client.Log.AddError("Could not obtain Origin client executable path.", null, LogCategories.Configuration); return; } if (!File.Exists(originPath)) { context.Client.Log.AddError(String.Format("Origin client executable not found at {0}.", originPath), null, LogCategories.Configuration); return; } #endregion #region Clear XML Configuration //get folder name string folderName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Origin"); //get file name string fileName = Path.Combine(folderName, "local.xml"); if (!Directory.Exists(folderName)) Directory.CreateDirectory(folderName); //create new stream and write or update its configuration data using (var xmlStream = new FileStream(fileName, FileMode.OpenOrCreate)) { XmlDocument document = new XmlDocument(); //preserve white space document.PreserveWhitespace = true; try { document.Load(xmlStream); } catch (XmlException) { //could not load } XmlNode settingsNode = null; #region Find Settings Node if (document.HasChildNodes) { foreach (XmlNode node in document.ChildNodes) { if (node.Name == "Settings") { settingsNode = node; break; } } } #endregion #region Create Settings Node if (settingsNode == null) { settingsNode = document.CreateElement("Settings"); document.AppendChild(settingsNode); } #endregion bool isSet = false; #region Update Existing Node if (settingsNode.HasChildNodes) { foreach (XmlLinkedNode el in settingsNode.ChildNodes) { if (el is XmlElement) { var element = (XmlElement)el; if (element.HasAttribute("key") && element.Attributes["key"].Value == "AcceptedEULAVersion") { if (element.Attributes["value"].Value == "0") element.Attributes["value"].Value = (2).ToString(); isSet = true; break; } } } } #endregion #region Clear Additional Settings if (settingsNode.HasChildNodes) { List<XmlElement> removedElements = new List<XmlElement>(); foreach (XmlLinkedNode el in settingsNode.ChildNodes) { if (el is XmlElement) { var element = (XmlElement)el; if (element.HasAttribute("key") && element.Attributes["key"].Value == "AutoLogin" || element.Attributes["key"].Value == "LoginAsInvisible" || element.Attributes["key"].Value == "LoginEmail" || element.Attributes["key"].Value == "LoginToken" || element.Attributes["key"].Value == "RememberMeEmail") { removedElements.Add(element); } } } foreach (var element in removedElements) { settingsNode.RemoveChild(element); } } #endregion #region Create new node if (!isSet) { var setting = document.CreateElement("Setting"); settingsNode.AppendChild(setting); setting.SetAttribute("key", "AcceptedEULAVersion"); setting.SetAttribute("type", "2"); setting.SetAttribute("value", "2"); } #endregion //reset stream xmlStream.SetLength(0); //save document document.Save(xmlStream); } #endregion 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 } }
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(); //set username sim.TextEntry(license.KeyAs<UserNamePasswordLicenseKeyBase>().Username); //disable input User32.BlockInput(true); //activate origin window uplayWindow.BringToFront(); uplayWindow.Activate(); //swicth field sim.KeyDown(WindowsInput.Native.VirtualKeyCode.TAB); //disable input User32.BlockInput(true); //activate origin window uplayWindow.BringToFront(); uplayWindow.Activate(); //clear password 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(); //set password sim.TextEntry(license.KeyAs<UserNamePasswordLicenseKeyBase>().Password); //disable input User32.BlockInput(true); //activate origin window uplayWindow.BringToFront(); uplayWindow.Activate(); //proceed with login sim.KeyDown(WindowsInput.Native.VirtualKeyCode.RETURN); //disable input User32.BlockInput(true); //activate origin window uplayWindow.BringToFront(); uplayWindow.Activate(); //set environment variable Environment.SetEnvironmentVariable("LICENSEKEYUSER", license.KeyAs<UplayLicenseKey>().Username); //delay installation process System.Threading.Thread.Sleep(5000); } catch { throw; } finally { //enable input User32.BlockInput(false); } } else { context.Client.Log.AddError("Uplay client window was not created after specified period of time.", null, LogCategories.Configuration); } } else { context.Client.Log.AddError(String.Format("Uplay client executable {0} could not be started.", uplayPath), null, LogCategories.Configuration); } #endregion } }