private void StartReplay(string execName = "default") { LeagueExecutable exec = null; // Get default exec or specified exec if (execName.Equals("default")) { // Start update form with default var result = new UpdateSplashForm(_exeManager).ShowDialog(); if (result == DialogResult.OK) { exec = _exeManager.GetDefaultExecutable(); } else { // Failed to get exec, stop this.GeneralPlayReplaySplitButton.Enabled = true; return; } } else { // Start update form with target var result = new UpdateSplashForm(_exeManager, execName).ShowDialog(); if (result == DialogResult.OK) { exec = _exeManager.GetExecutable(execName); } else { // Failed to get exec, stop this.GeneralPlayReplaySplitButton.Enabled = true; return; } } // This really shouldn't happen, but just to be safe if (exec == null) { MessageBox.Show($"Could not find executable data {execName}\nPlease run ROFL Player and check the executables", "Failed to start replay", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Start League of Legends, var playtask = Task.Run(() => { //ReplayManager.StartReplay(_fileInfo.Location, exec.TargetPath); _replayPlayer.Play(exec, _replayFile.Location); }).ContinueWith((t) => // When the user closes the game { this.BeginInvoke((Action)(() => { if (t.IsFaulted) { _logger.Error(this.GetType().ToString(), t.Exception.ToString()); MessageBox.Show("Failed to play replay! Check logs for detailed information", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } GeneralPlayReplaySplitButton.Enabled = true; })); }); }
[STAThread] // This is required for system dialogs static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Scribe logger = new Scribe(); //*/ try { ExeManager exeManager = null; try { exeManager = new ExeManager(); } catch (Exception ex) { MessageBox.Show("ROFLPlayer was not able to find League of Legends. Please add it now.", "First time setup", MessageBoxButtons.OK, MessageBoxIcon.Information); logger.Info(_className, $"First time setup kicked off by exception:\n{ex.ToString()}"); // Start add exec form var addForm = new ExecAddForm(new ExeTools()); var formResult = addForm.ShowDialog(); // If form exited with ok if (formResult == DialogResult.OK) { // Get new exec LeagueExecutable newExec = addForm.NewLeagueExec; newExec.IsDefault = true; // Save execinfo file exeManager = new ExeManager(newExec); exeManager.Save(); } else { // Exit if form exited any other way Environment.Exit(1); } addForm.Dispose(); } ReplayPlayer replayPlayer = new ReplayPlayer(exeManager); if (args.Length == 0) { // Update default exec Application.Run(new UpdateSplashForm(exeManager)); Application.Run(new SettingsForm(exeManager)); } else { // StartupMode, 1 = show detailed information, 0 = launch replay immediately if (RoflSettings.Default.StartupMode == 0) { StartReplay(args[0], exeManager, replayPlayer); } else { var replayFile = Task.Run(() => SetupReplayFileAsync(args[0])); replayFile.Wait(); RequestManager requestManager = new RequestManager(); Application.Run(new DetailForm(replayFile.Result, requestManager, exeManager, replayPlayer, logger)); } } } catch (Exception ex) { MessageBox.Show(@"ROFLPlayer encountered an unhandled exception, please record this message and report it here https://github.com/andrew1421lee/ROFL-Player/issues" + "\n\n" + ex.ToString(), "Critical Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); logger.Error(_className, "Unhandled exception: " + ex.ToString()); Environment.Exit(1); } //*/ }