/// <summary> /// Actions for ok button /// </summary> private void MainOkButton_Click(object sender, EventArgs e) { // Save selected default exec if (this.GeneralGameComboBox.SelectedItem != null) { string defaultExeName = this.GeneralGameComboBox.SelectedItem.ToString(); LeagueExecutable leagueExecutable = _exeManager.GetExecutable(defaultExeName); _exeManager.SetDefaultExectuable(this.GeneralGameComboBox.SelectedItem.ToString()); } _exeManager.Save(); // Save double click launch option RoflSettings.Default.StartupMode = this.GeneralLaunchComboBox.SelectedIndex; // Save username RoflSettings.Default.Username = this.GeneralUsernameTextBox.Text; // Save region RoflSettings.Default.Region = this.GeneralRegionComboBox.Text; // Save config RoflSettings.Default.Save(); Environment.Exit(1); }
public static Process PlayReplay(this LeagueExecutable executable, string path) { if (!File.Exists(path)) { throw new FileNotFoundException($"Replay \"{path}\" does not exist"); } // This will throw an exception if exe has issues executable.Validate(); // Create the launch arguments, each argument is put in quotes // <replay file path> GameBaseDir=... <other arguments> string launchArgs = $"\"{path}\" " + executable.LaunchArguments + $" \"-Locale={ExeTools.GetLocaleCode(executable.Locale)}\""; ProcessStartInfo processStartInfo = new ProcessStartInfo { FileName = executable.TargetPath, Arguments = launchArgs, // The game client uses the working directory to find the data files WorkingDirectory = Path.GetDirectoryName(executable.TargetPath) }; Process game = Process.Start(processStartInfo); game.EnableRaisingEvents = true; return(game); }
public static void Play(LeagueExecutable leagueExe, string replayPath) { if (!File.Exists(replayPath)) { throw new FileNotFoundException($"Replay does not exist"); } // This will throw an exception if exe has issues ExeTools.ValidateLeagueExecutable(leagueExe); // Create the launch arguments, each argument is put in quotes // <replay file path> GameBaseDir=... <other arguments> string launchArgs = $"\"{replayPath}\" " + leagueExe.LaunchArguments + $" \"-Locale={ExeTools.GetLocaleCode(leagueExe.Locale)}\""; ProcessStartInfo processStartInfo = new ProcessStartInfo { FileName = leagueExe.TargetPath, Arguments = launchArgs, // The game client uses the working directory to find the data files WorkingDirectory = Path.GetDirectoryName(leagueExe.TargetPath) }; Process game = Process.Start(processStartInfo); game.WaitForExit(); return; }
public ExeManager() { string fileDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "data"); if (!Directory.Exists(fileDir)) { Directory.CreateDirectory(fileDir); } _exeInfoFilePath = Path.Combine(fileDir, "executables.json"); ExeTools = new ExeTools(); if (!File.Exists(_exeInfoFilePath)) { _executables = new List <LeagueExecutable>(); // Exe file is missing, create it _defaultExecutable = SetupFirstExe(); } else { InfoFile savedExeObject = JsonConvert.DeserializeObject <InfoFile>(File.ReadAllText(_exeInfoFilePath)); _executables = savedExeObject.Executables; _defaultExecutable = savedExeObject.DefaultExecutable; } }
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().ShowDialog(); if (result == DialogResult.OK) { exec = ExecsManager.GetExec(ExecsManager.GetDefaultExecName()); } else { // Failed to get exec, stop this.GeneralPlayReplaySplitButton.Enabled = true; return; } } else { // Start update form with target var result = new UpdateSplashForm(execName).ShowDialog(); if (result == DialogResult.OK) { exec = ExecsManager.GetExec(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; } var playtask = Task.Run(() => { ReplayManager.StartReplay(replaypath, exec.TargetPath); }).ContinueWith((t) => { this.BeginInvoke((Action)(() => { if (t.IsFaulted) { MessageBox.Show("Failed to play replay: " + t.Exception.GetType().ToString() + "\n" + t.Exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } GeneralPlayReplaySplitButton.Enabled = true; })); }); }
/// <summary> /// Save exec data to file /// </summary> public static string SaveExecFile(LeagueExecutable leagueExecutable) { // Null protection if (leagueExecutable == null) { return(null); } // Path for created file var filePath = Path.Combine(ExecsFolder, leagueExecutable.Name + ".json"); // Double check execs folder exists, create otherwise if (!Directory.Exists(ExecsFolder)) { Directory.CreateDirectory(ExecsFolder); } // Serialize object into json var serialized = JsonConvert.SerializeObject(leagueExecutable); try { // Write json to file File.WriteAllText(filePath, serialized); } catch (Exception ex) { // Return error on exception return("!FAIL" + ex.ToString()); } // return file path return(filePath); }
public ExecAddForm() { InitializeComponent(); InitForm(); NewLeagueExec = new LeagueExecutable(); toolTip = new ToolTip(); }
public ExecAddForm(LeagueExecutable leagueExecutable) { InitializeComponent(); InitForm(); toolTip = new ToolTip(); NewLeagueExec = leagueExecutable; if (!File.Exists(NewLeagueExec.TargetPath)) { MessageBox.Show("Target specified in entry does not exist. Delete and re-add", "Error reading entry", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var fileInfo = FileVersionInfo.GetVersionInfo(NewLeagueExec.TargetPath); this.ExecNameTextBox.Text = NewLeagueExec.Name; this.ExecTargetTextBox.Text = NewLeagueExec.TargetPath; this.ExecStartTextBox.Text = NewLeagueExec.StartFolder; this.GBoxExecNameTextBox.Text = Path.GetFileName(NewLeagueExec.TargetPath); this.GBoxPatchVersTextBox.Text = NewLeagueExec.PatchVersion; this.GBoxFileDescTextBox.Text = fileInfo.FileDescription; this.GBoxLastModifTextBox.Text = NewLeagueExec.ModifiedDate.ToString("yyyy/dd/MM"); this.ExecUpdateCheckbox.Checked = NewLeagueExec.AllowUpdates; this.Text = "Edit Executable..."; }
/// <summary> /// Throws an exception if one of the following assertions fail /// </summary> /// <param name="exe"></param> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentException"></exception> /// <exception cref="DirectoryNotFoundException"></exception> /// <exception cref="FileNotFoundException"></exception> public void ValidateExecutable(LeagueExecutable exe, bool requireUniqueName = true) { // Name must not already exist // Start folder must exist // Target file must exist and be contained in start folder // patch version must pass versionsubstring // allowupdates... // isdefault... // ModifiedDate must not be null // Check all properties if they are null if (String.IsNullOrEmpty(exe.Name) || String.IsNullOrEmpty(exe.TargetPath) || String.IsNullOrEmpty(exe.StartFolder) || String.IsNullOrEmpty(exe.PatchVersion) || exe.ModifiedDate == null) { throw new ArgumentNullException($"{_exceptionOriginName} - Property set to null"); } // Check if executable by the same name already exists LeagueExecutable matchingExe = (from e in _executables where e.Name.ToUpper().Equals(exe.Name.ToUpper()) select e).FirstOrDefault(); bool defaultMatches = _defaultExecutable.Name.ToUpper().Equals(exe.Name); if (requireUniqueName) { if (matchingExe != null || defaultMatches) { throw new ArgumentException($"{_exceptionOriginName} - Executable by \"{exe.Name}\" already exists"); } } // Check if start folder exists if (!Directory.Exists(exe.StartFolder)) { throw new DirectoryNotFoundException($"{_exceptionOriginName} - Start folder \"{exe.StartFolder}\" does not exist"); } // Check if target path begins with stater path if (!exe.TargetPath.StartsWith(exe.StartFolder)) { throw new FileNotFoundException($"{_exceptionOriginName} - Target file \"{exe.TargetPath}\" cannot be found from start folder \"{exe.StartFolder}\""); } // Check if target path exists if (!File.Exists(exe.TargetPath)) { throw new FileNotFoundException($"{_exceptionOriginName} - Target file \"{exe.TargetPath}\" not found"); } // Check if patch version is properly formatted if (exe.PatchVersion.VersionSubstring() == null) { throw new ArgumentException($"{_exceptionOriginName} - Version string \"{exe.PatchVersion}\" not proper format"); } }
public ExecutableLaunchArgsWindow(LeagueExecutable executable) { _executable = executable ?? throw new ArgumentNullException(nameof(executable)); InitializeComponent(); LaunchArgsBox.Text = _executable.LaunchArguments; }
public IList <LeagueExecutable> SearchFolderForExecutables(string startPath) { List <LeagueExecutable> foundExecutables = new List <LeagueExecutable>(); if (!Directory.Exists(startPath)) { _log.Warning($"Input path {startPath} does not exist"); throw new DirectoryNotFoundException($"Input path {startPath} does not exist"); } try { // Look for any and all league of legends executables var exeFiles = Directory.EnumerateFiles(startPath, "League of Legends.exe", SearchOption.AllDirectories); foreach (string exePath in exeFiles) { LeagueExecutable newExe = null; try { newExe = ExeTools.CreateNewLeagueExecutable(exePath); } catch (Exception ex) { _log.Error($"{ex.GetType()} trying to create executable for path = \"{exePath}\""); _log.Error(ex.ToString()); continue; } try { newExe.Locale = ExeTools.DetectExecutableLocale(exePath); } catch (Exception ex) { _log.Error($"{ex.GetType()} trying to find locale for path = \"{exePath}\""); _log.Error(ex.ToString()); newExe.Locale = LeagueLocale.EnglishUS; // do not stop operation } // Do we already have an exe with the same target? if (!foundExecutables.Exists(x => x.TargetPath.Equals(newExe.TargetPath, StringComparison.OrdinalIgnoreCase))) { foundExecutables.Add(newExe); } } } catch (Exception e) { _log.Error(e.ToString()); throw; } return(foundExecutables); }
private void LoadLeagueExecutable(LeagueExecutable executable) { _executable = executable ?? throw new ArgumentNullException(nameof(executable)); TargetTextBox.Text = executable.TargetPath; NameTextBox.Text = executable.Name; LocaleComboBox.SelectedIndex = executable.Locale == LeagueLocale.Custom ? Enum.GetNames(typeof(LeagueLocale)).Length - 1 : (int)executable.Locale; LaunchArgsTextBox.Text = PrettifyLaunchArgs(executable.LaunchArguments); CustomLocaleTextBox.Text = executable.CustomLocale; }
private void ContentDialog_PrimaryButtonClick(object sender, ContentDialogButtonClickEventArgs args) { if (!(ExecutablesListBox.SelectedItem is LeagueExecutable selectedExecutable)) { return; } ; Selection = selectedExecutable; this.Hide(); }
public ExecutableDetailWindow(LeagueExecutable executable) { if (executable == null) { throw new ArgumentNullException(nameof(executable)); } InitializeComponent(); LoadLeagueExecutable(executable); _isEditMode = true; }
private void LoadLeagueExecutable(LeagueExecutable executable) { _executable = executable ?? throw new ArgumentNullException(nameof(executable)); TargetTextBox.Text = executable.TargetPath; NameTextBox.Text = executable.Name; LocaleComboBox.SelectedIndex = (int)executable.Locale; StartPathTextBox.Text = executable.StartFolder; PatchTextBox.Text = executable.PatchNumber; LaunchArgsTextBox.Text = PrettifyLaunchArgs(executable.LaunchArguments); ModifiedDateTextBox.Text = executable.ModifiedDate.ToString("o", CultureInfo.InvariantCulture); }
private void OKButton_Click(object sender, RoutedEventArgs e) { if (!(ExecutablesListBox.SelectedItem is LeagueExecutable selectedExecutable)) { return; } ; Selection = selectedExecutable; this.DialogResult = true; return; }
public ExecutableDetailDialog(LeagueExecutable executable) { if (executable == null) { throw new ArgumentNullException(nameof(executable)); } InitializeComponent(); LoadLeagueExecutable(executable); _isEditMode = true; this.Title = TryFindResource("EditButtonText") as String + " " + this.Title; }
/// <summary> /// Actions for edit exec button, also called on double click action /// </summary> private void ExecEditButton_Click(object sender, EventArgs e) { // Get exec that is selected var selectedName = (string)this.ExecItemsList.SelectedItem; LeagueExecutable exec = _exeManager.GetExecutable(selectedName); // Check is gotten exec if (exec == null) { // This happens when nothing is selected //MessageBox.Show("Specified entry does not exist. Delete and re-add", "Error reading entry", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { // Start add form, but in edit mode var editForm = new ExecAddForm(exec); var formResult = editForm.ShowDialog(); // if form exited with ok if (formResult == DialogResult.OK) { // Get edited exec var newExec = editForm.NewLeagueExec; // Save exec file if (!newExec.IsDefault) { _exeManager.DeleteExecutable(selectedName); _exeManager.AddExecutable(newExec); } else { _exeManager.ReplaceDefaultExecutable(newExec); } // Refresh list of execs RefreshExecListBox(); // Clear info box this.GBoxExecNameTextBox.Text = ""; this.GBoxTargetLocationTextBox.Text = ""; this.GBoxPatchVersTextBox.Text = ""; this.GBoxLastModifTextBox.Text = ""; // disable context buttons ExecDeleteButton.Enabled = false; ExecEditButton.Enabled = false; } } }
private void LoadLeagueExecutable(LeagueExecutable executable) { _executable = executable ?? throw new ArgumentNullException(nameof(executable)); TargetTextBox.Text = executable.TargetPath; NameTextBox.Text = executable.Name; LocaleComboBox.SelectedItem = executable.Locale == LeagueLocale.Custom ? LocaleNames.Last() : LocaleNames.First(x => x.Split('(', ')')[1] == ExeTools.GetLocaleCode(executable.Locale)); LaunchArgsTextBox.Text = PrettifyLaunchArgs(executable.LaunchArguments); CustomLocaleTextBox.Text = executable.CustomLocale; }
/// <summary> /// Deletes the item with name <paramref name="name"/>. Throws <see cref="ArgumentException"/> if name does not exist. /// If default is deleted, default is set to null. /// </summary> /// <param name="name"></param> public void DeleteExecutable(string name) { LeagueExecutable target = GetExecutable(name); if (target == null) { _log.Warning($"Executable with name {name} does not exist"); throw new ArgumentException($"Executable with name {name} does not exist"); } // Delete the executable _log.Information($"Deleting executable {target.Name}"); Settings.Executables.Remove(target); }
// This is a backup constructor that should only be called when the original fails when first launched public ExeManager(LeagueExecutable manualDefault) { string fileDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "data"); if (!Directory.Exists(fileDir)) { Directory.CreateDirectory(fileDir); } _exeInfoFilePath = Path.Combine(fileDir, "executables.json"); ExeTools = new ExeTools(); _executables = new List <LeagueExecutable>(); _defaultExecutable = manualDefault; }
public static void Validate(this LeagueExecutable executable) { // Name must not already exist // Start folder must exist // Target file must exist and be contained in start folder // patch version must pass versionsubstring // allowupdates... // isdefault... // ModifiedDate must not be null // Check all properties if they are null if (executable == null || String.IsNullOrEmpty(executable.Name) || String.IsNullOrEmpty(executable.TargetPath) || String.IsNullOrEmpty(executable.StartFolder) || String.IsNullOrEmpty(executable.PatchNumber) || executable.ModifiedDate == null) { throw new ArgumentNullException(nameof(executable)); } // Check if start folder exists if (!Directory.Exists(executable.StartFolder)) { // _log.Warning(_myName, $"Start folder {executable.StartFolder} does not exist"); throw new DirectoryNotFoundException($"Start folder {executable.StartFolder} does not exist"); } // Check if target path begins with stater path if (!executable.TargetPath.StartsWith(executable.StartFolder, StringComparison.OrdinalIgnoreCase)) { // _log.Warning(_myName, $"Target file {executable.TargetPath} cannot be found from start folder {executable.StartFolder}"); throw new FileNotFoundException($"Target file {executable.TargetPath} cannot be found from start folder {executable.StartFolder}"); } // Check if target path exists if (!File.Exists(executable.TargetPath)) { // _log.Warning(_myName, $"Target file {executable.TargetPath} not found"); throw new FileNotFoundException($"Target file {executable.TargetPath} not found"); } // Check if patch version is properly formatted if (executable.PatchNumber.VersionSubstring() == null) { // _log.Warning(_myName, $"Version string {executable.PatchNumber} not proper format"); throw new ArgumentException($"Version string {executable.PatchNumber} not proper format"); } }
public void UpdateExecutableVersion(LeagueExecutable executable) { if (executable == null) { throw new ArgumentNullException(nameof(executable)); } var currentVersion = ExeTools.GetLeagueVersion(executable.TargetPath); if (!executable.PatchNumber.Equals(currentVersion, StringComparison.OrdinalIgnoreCase)) { _log.Information($"Updating executable {executable.Name} from {executable.PatchNumber} -> {currentVersion}"); executable.PatchNumber = currentVersion; } }
public void UpdateExecutableTarget(string name) { LeagueExecutable targetExe = GetExecutable(name); if (targetExe == null) { throw new KeyNotFoundException($"{_exceptionOriginName} - No executable \"{name}\" found"); } if (!Directory.Exists(targetExe.StartFolder)) { throw new DirectoryNotFoundException($"{_exceptionOriginName} - Start directory does not exist"); } targetExe.TargetPath = ExeTools.FindLeagueExecutablePath(targetExe.StartFolder); }
private static void StartReplay(string replayPath, ExeManager exeManager, ReplayPlayer replayPlayer, 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 MessageBox.Show("Failed to start replay", $"Could not find executable data {execName}", MessageBoxButtons.OK, MessageBoxIcon.Error); 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 MessageBox.Show("Failed to start replay", $"Could not find executable data {execName}", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (exec == null) { MessageBox.Show("Failed to start replay", $"Could not find executable data {execName}", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } replayPlayer.Play(exec, replayPath); }
private LeagueExecutable SetupFirstExe() { LeagueExecutable returnExe = new LeagueExecutable(); returnExe.StartFolder = ExeTools.GetLeagueInstallPathFromRegistry(); returnExe.TargetPath = ExeTools.FindLeagueExecutablePath(returnExe.StartFolder); returnExe.ModifiedDate = ExeTools.GetLastModifiedDate(returnExe.TargetPath); returnExe.PatchVersion = ExeTools.GetLeagueVersion(returnExe.TargetPath); returnExe.AllowUpdates = true; returnExe.UseOldLaunchArguments = false; returnExe.IsDefault = true; returnExe.Name = "Default"; return(returnExe); }
/// <summary> /// Given a executable path, creates a new LeagueExecutable /// </summary> /// <param name="path"></param> /// <returns></returns> public static LeagueExecutable CreateNewLeagueExecutable(string path) { LeagueExecutable newExe = new LeagueExecutable() { TargetPath = path, StartFolder = Path.GetDirectoryName(path), PatchNumber = GetLeagueVersion(path), ModifiedDate = GetLastModifiedDate(path) }; newExe.Name = $"Patch {newExe.PatchNumber.VersionSubstring()}"; newExe.LaunchArguments = $"\"-GameBaseDir={newExe.StartFolder}\"" + " \"-SkipRads\"" + " \"-SkipBuild\"" + " \"-EnableLNP\"" + " \"-UseNewX3D=1\"" + " \"-UseNewX3DFramebuffers=1\""; return(newExe); }
public ExecutableDetailDialog(LeagueExecutable executable) { if (executable == null) { throw new ArgumentNullException(nameof(executable)); } // load locales into drop down, skip parentheses for custom option LocaleNames = Enum.GetNames(typeof(LeagueLocale)) .Select(x => x + (x.StartsWith(LeagueLocale.Custom.ToString(), StringComparison.OrdinalIgnoreCase) ? "" : " (" + ExeTools.GetLocaleCode(x) + ")")) .OrderBy(x => x == LeagueLocale.Custom.ToString()) .ThenBy(x => x); InitializeComponent(); LoadLeagueExecutable(executable); _isEditMode = true; Title = TryFindResource("EditButtonText") as string + " " + Title; }
public void Play(LeagueExecutable leagueExe, string replayPath) { if (!File.Exists(replayPath)) { throw new FileNotFoundException($"{_exceptionOriginName} - replay does not exist"); } // This will throw an exception if exe has issues // Turning off unique name flag, otherwise will trigger exception _exeManager.ValidateExecutable(leagueExe, false); // Create the launch arguments, each argument is put in quotes // <replay file path> GameBaseDir=... <other arguments> string combinedArgs = "\"" + replayPath + "\" " + "\"" + BaseDir + leagueExe.StartFolder + "\""; foreach (string arg in LaunchArguments) { combinedArgs += $" \"{arg}\""; } var launchArgs = combinedArgs; if (leagueExe.UseOldLaunchArguments) { launchArgs = "\"" + replayPath + "\""; } ProcessStartInfo processStartInfo = new ProcessStartInfo { FileName = leagueExe.TargetPath, Arguments = launchArgs, // The game client uses the working directory to find the data files WorkingDirectory = Path.GetDirectoryName(leagueExe.TargetPath) }; Process game = Process.Start(processStartInfo); game.WaitForExit(); return; }
/// <summary> /// Attempt to find League exec and save as default /// </summary> public static string FindAndAddLeagueExec(string startPath = "") { // If start path is empty, use game locator to find one to use if (startPath == "") { if (GameLocator.FindLeagueInstallPath(out string foundPath)) { startPath = foundPath; } else { return("FALSE: Could not find install path"); } } try { var targetPath = GameLocator.FindLeagueExecutable(startPath); var fileInfo = FileVersionInfo.GetVersionInfo(targetPath); var newExec = new LeagueExecutable { StartFolder = startPath, TargetPath = targetPath, IsDefault = true, AllowUpdates = true, PatchVersion = fileInfo.FileVersion, Name = "Default", ModifiedDate = File.GetLastWriteTime(targetPath) }; SaveExecFile(newExec); } catch (Exception ex) { return("FALSE: Exception - " + ex.ToString()); } return("Default"); }