private void Window_Closing(object sender, CancelEventArgs e) { Utilities.Log("this.Window_Closing() called"); if (GetBattlefield3Process() != null) { Utilities.Log("GetBattlefield3Process() != null"); this.Battlelog.ExecuteJavascript(JSDialog.ShowJavascriptDialog(new OKDialog("Battlefield 3 is still running", "Quit Battlefield 3 before closing Battlelogium"))); e.Cancel = true; return; } // Shutdown WebCore try { Utilities.Log("WebCore.Shutdown()"); WebCore.Shutdown(); } catch (Exception ex) { Utilities.Log("Exception occured when WebCore shutdown"); Utilities.Log(ex.ToString()); } Timer cleanupOriginTimer = new Timer(config.WaitTimeToKillOrigin); cleanupOriginTimer.AutoReset = false; cleanupOriginTimer.Elapsed += delegate { Dispatcher.Invoke(new Action(delegate { if (config.HandleOrigin) { Utilities.Log("managedOrigin.KillOriginProcess()"); managedOrigin.KillOriginProcess(); } Utilities.Log("Utilities.KillProcess(sonarhost)"); Utilities.KillProcess("sonarhost", false, false); if (this.retainOrigin) { Utilities.Log("retainOrigin = True"); //We do not want this instance of Origin to be a child process, otherwise Steam will think we're still in Battlefield 3 Utilities.Log("ManagedOrigin.CreateUnmanagedInstance"); ManagedOrigin.CreateUnmanagedInstance(); } Utilities.Log("!---End Log---!"); Utilities.Log("Press Enter to Exit. Remember to submit battlelogium.log"); Utilities.FreeConsole(); })); }; Utilities.Log("Waiting " + config.WaitTimeToKillOrigin * 1000 + " milliseconds to kill Origin"); notifyIcon.Text = "Battlelogium is waiting for Origin and ESN Sonar to close"; cleanupOriginTimer.Start(); this.Hide(); System.Threading.Thread.Sleep(config.WaitTimeToKillOrigin * 1000 + 5000); notifyIcon.Visible = false; }
/// <summary> Start Origin, then get the bf3.exe handle to be able to close Battlelogium once we're done. private void StartBF3Campaign() { Utilities.Log("BattlelogiumMain.StartBF3Campaign() Called"); if (!this.config.HandleOrigin) { Utilities.Log("!this.config.HandleOrigin"); try { Process.Start(Path.Combine(Utilities.GetBF3Path(), "bf3.exe"), @"-webMode SP -requestState State_ResumeCampaign -onlineEnvironment prod -requestStateParams""<data levelmode=\""sp\""></data>").WaitForExit(); } catch (FileNotFoundException) { CustomMessageBox.Show("Battlefield 3 Not Found. Please install Battlefield 3 before playing"); } this.Close(); } Utilities.Log("this.managedOrigin = new ManagedOrigin(/StartOffline origin://LaunchGame/70619)"); this.managedOrigin = new ManagedOrigin(@"""/StartOffline"" ""origin://LaunchGame/70619"""); //Starts Origin in offline mode, autolaunching Battlefield 3 managedOrigin.StartOriginProcess(); Process battlefield3 = null; Utilities.Log("while (Process battlefield3 == null)"); while (battlefield3 == null) { //Continuously loop through all processes until we find BF3. if (GetBattlefield3Process() != null) { battlefield3 = GetBattlefield3Process(); } } Utilities.Log("Process battlefield3.WaitForExit"); battlefield3.WaitForExit(); Utilities.Log("Battlefield 3 has closed"); this.Close(); }
public ManagedOrigin(string commandLineOptions) : this(ManagedOrigin.GetOriginPath(), commandLineOptions) { }
public BattlelogiumMain() { // Attach a console instance to process Utilities.AttachConsole(-1); //The Steam Overlay will not work if we show splash by the SplashScreen build action, so we manually show it. splash.Show(true); Console.WriteLine(String.Empty); Utilities.Log("Battlelogium is licensed under GNU GPL v3"); Utilities.Log("Battlelogium does not come with any warranty"); Utilities.Log("neither express nor implied"); Console.WriteLine(String.Empty); Utilities.Log("!---Begin Log---!"); Utilities.Log("Version: " + Assembly.GetEntryAssembly().GetName().Version.ToString()); Utilities.Log("=================="); Console.WriteLine(String.Empty); if (Process.GetProcessesByName("Battlelogium").Length > 1) { Utilities.Log("Process.GetProcessesByName(Battlelogium).Length > 1"); CustomMessageBox.Show("There can only be one instance of Battlelogium running at a time. Wait for the other instance to close and try again"); this.Close(); return; } Utilities.Log("BattlelogiumMain.config = new BattlelogiumConfiguration()"); this.config = new BattlelogiumConfiguration(); Utilities.Log(config.ConfigDump()); Utilities.Log("BattlelogiumMain.StartupConnectionCheck()"); this.StartupConnectionCheck(); splash.Close(TimeSpan.Zero); //Close the splash screen or it will hang. if (config.DirectToCampaign) //If we're going directly to campaign, there is no need to initialize the main window { Utilities.Log("BattlelogiumMain.Closing += Window_Closing"); this.Closing += Window_Closing; //Since we don't call InitializeComponent, we need to manually add the closing event handler Utilities.Log("BattlelogiumMain.StartBF3Campaign()"); this.StartBF3Campaign(); } else { if (config.HandleOrigin) { Utilities.Log("BattlelogiumMain.StartOriginProcess(/StartClientMinimized)"); this.retainOrigin = ManagedOrigin.CheckIfOriginIsRunning(); Utilities.Log("retainOrigin = " + retainOrigin.ToString()); Utilities.Log("this.managedOrigin = new ManagedOrigin(/StartClientMinimized)"); this.managedOrigin = new ManagedOrigin("/StartClientMinimized"); try{ this.managedOrigin.StartOriginProcess(); }catch(Exception e){ HandleOriginException(e); } } Utilities.Log("BattlelogiumMain.InitializeComponent()"); this.InitializeComponent(); this.VersionLabel.Content = "Battlelogium " + Assembly.GetEntryAssembly().GetName().Version.ToString(); Utilities.Log("BattlelogiumMain.SetupStoryboards()"); this.SetupStoryboards(); if (config.WindowedMode) { Utilities.Log("BattlelogiumMain.SetWindowed()"); this.SetWindowed(); } Utilities.Log("this.blinkLoading.Begin()"); this.blinkLoading.Begin(); Utilities.Log("this.Battlelog.Websession = CreateBattlelogWebSession()"); this.Battlelog.WebSession = CreateBattlelogWebSession(); if (config.CheckUpdates) { Utilities.Log("Check Updates: new UpdateNotifier(Assembly.GetEntryAssembly().GetName().Version).run()"); new UpdateNotifier(Assembly.GetEntryAssembly().GetName().Version, this.Dispatcher).run(); } if (config.UseSoftwareRender) { Utilities.Log("RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly"); RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; } this.notifyIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"Battlelogium.exe")); this.notifyIcon.Text = String.Format("Battlelogium {0} is running",Assembly.GetEntryAssembly().GetName().Version.ToString()); this.notifyIcon.Visible = true; } }
/// <summary> Start Origin, then get the bf3.exe handle to be able to close Battlelogium once we're done. private void StartBF3Campaign() { Utilities.Log("BattlelogiumMain.StartBF3Campaign() Called"); if (!this.config.HandleOrigin) { Utilities.Log("!this.config.HandleOrigin"); try { Process.Start(Path.Combine(Utilities.GetBF3Path(), "bf3.exe"), @"-webMode SP -requestState State_ResumeCampaign -onlineEnvironment prod -requestStateParams""<data levelmode=\""sp\""></data>").WaitForExit(); } catch (FileNotFoundException) { CustomMessageBox.Show("Battlefield 3 Not Found. Please install Battlefield 3 before playing"); } this.Close(); } Utilities.Log("this.managedOrigin = new ManagedOrigin(/StartOffline origin://LaunchGame/70619)"); this.managedOrigin = new ManagedOrigin(@"""/StartOffline"" ""origin://LaunchGame/70619"""); //Starts Origin in offline mode, autolaunching Battlefield 3 managedOrigin.StartOriginProcess(); Process battlefield3 = null; Utilities.Log("while (Process battlefield3 == null)"); while (battlefield3 == null) { //Continuously loop through all processes until we find BF3. if (GetBattlefield3Process() != null) { battlefield3 = GetBattlefield3Process(); } } Utilities.Log("Process battlefield3.WaitForExit"); battlefield3.WaitForExit(); Utilities.Log("Battlefield 3 has closed"); this.Close(); }
public BattlelogiumMain() { // Attach a console instance to process Utilities.AttachConsole(-1); //The Steam Overlay will not work if we show splash by the SplashScreen build action, so we manually show it. splash.Show(true); Console.WriteLine(String.Empty); Utilities.Log("Battlelogium is licensed under GNU GPL v3"); Utilities.Log("Battlelogium does not come with any warranty"); Utilities.Log("neither express nor implied"); Console.WriteLine(String.Empty); Utilities.Log("!---Begin Log---!"); Utilities.Log("Version: " + Assembly.GetEntryAssembly().GetName().Version.ToString()); Utilities.Log("=================="); Console.WriteLine(String.Empty); if (Process.GetProcessesByName("Battlelogium").Length > 1) { Utilities.Log("Process.GetProcessesByName(Battlelogium).Length > 1"); CustomMessageBox.Show("There can only be one instance of Battlelogium running at a time. Wait for the other instance to close and try again"); this.Close(); return; } Utilities.Log("BattlelogiumMain.config = new BattlelogiumConfiguration()"); this.config = new BattlelogiumConfiguration(); Utilities.Log(config.ConfigDump()); Utilities.Log("BattlelogiumMain.StartupConnectionCheck()"); this.StartupConnectionCheck(); splash.Close(TimeSpan.Zero); //Close the splash screen or it will hang. if (config.DirectToCampaign) //If we're going directly to campaign, there is no need to initialize the main window { Utilities.Log("BattlelogiumMain.Closing += Window_Closing"); this.Closing += Window_Closing; //Since we don't call InitializeComponent, we need to manually add the closing event handler Utilities.Log("BattlelogiumMain.StartBF3Campaign()"); this.StartBF3Campaign(); } else { if (config.HandleOrigin) { Utilities.Log("BattlelogiumMain.StartOriginProcess(/StartClientMinimized)"); this.retainOrigin = ManagedOrigin.CheckIfOriginIsRunning(); Utilities.Log("retainOrigin = " + retainOrigin.ToString()); Utilities.Log("this.managedOrigin = new ManagedOrigin(/StartClientMinimized)"); this.managedOrigin = new ManagedOrigin("/StartClientMinimized"); try{ this.managedOrigin.StartOriginProcess(); }catch (Exception e) { HandleOriginException(e); } } Utilities.Log("BattlelogiumMain.InitializeComponent()"); this.InitializeComponent(); this.VersionLabel.Content = "Battlelogium " + Assembly.GetEntryAssembly().GetName().Version.ToString(); Utilities.Log("BattlelogiumMain.SetupStoryboards()"); this.SetupStoryboards(); if (config.WindowedMode) { Utilities.Log("BattlelogiumMain.SetWindowed()"); this.SetWindowed(); } Utilities.Log("this.blinkLoading.Begin()"); this.blinkLoading.Begin(); Utilities.Log("this.Battlelog.Websession = CreateBattlelogWebSession()"); this.Battlelog.WebSession = CreateBattlelogWebSession(); if (config.CheckUpdates) { Utilities.Log("Check Updates: new UpdateNotifier(Assembly.GetEntryAssembly().GetName().Version).run()"); new UpdateNotifier(Assembly.GetEntryAssembly().GetName().Version, this.Dispatcher).run(); } if (config.UseSoftwareRender) { Utilities.Log("RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly"); RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; } this.notifyIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Battlelogium.exe")); this.notifyIcon.Text = String.Format("Battlelogium {0} is running", Assembly.GetEntryAssembly().GetName().Version.ToString()); this.notifyIcon.Visible = true; } }