Skip to content
This repository has been archived by the owner on May 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #30 from leeanchu/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Anchu committed Aug 1, 2019
2 parents 63b942a + 6aa0ba9 commit 53022fc
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 22 deletions.
13 changes: 11 additions & 2 deletions Rofl.Executables/ExeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ public void SetDefaultExectuable(string name)
_executables.Add(oldDefault);
}

public void ReplaceDefaultExecutable(LeagueExecutable exe)
{
_defaultExecutable = exe;
}

public void UpdateExecutableTarget(string name)
{
LeagueExecutable targetExe = GetExecutable(name);
Expand All @@ -210,6 +215,7 @@ private LeagueExecutable SetupFirstExe()
returnExe.ModifiedDate = ExeTools.GetLastModifiedDate(returnExe.TargetPath);
returnExe.PatchVersion = ExeTools.GetLeagueVersion(returnExe.TargetPath);
returnExe.AllowUpdates = true;
returnExe.UseOldLaunchArguments = false;
returnExe.IsDefault = true;
returnExe.Name = "Default";

Expand All @@ -224,7 +230,7 @@ private LeagueExecutable SetupFirstExe()
/// <exception cref="ArgumentException"></exception>
/// <exception cref="DirectoryNotFoundException"></exception>
/// <exception cref="FileNotFoundException"></exception>
public void ValidateExecutable(LeagueExecutable exe)
public void ValidateExecutable(LeagueExecutable exe, bool requireUniqueName = true)
{
// Name must not already exist
// Start folder must exist
Expand All @@ -251,7 +257,10 @@ where e.Name.ToUpper().Equals(exe.Name.ToUpper())

bool defaultMatches = _defaultExecutable.Name.ToUpper().Equals(exe.Name);

if (matchingExe != null || defaultMatches) { throw new ArgumentException($"{_exceptionOriginName} - Executable by \"{exe.Name}\" already exists"); }
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"); }
Expand Down
3 changes: 3 additions & 0 deletions Rofl.Executables/Models/LeagueExecutable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public class LeagueExecutable
[JsonProperty("allow-updates")]
public bool AllowUpdates { get; set; }

[JsonProperty("use-old-launch-args")]
public bool UseOldLaunchArguments { get; set; }

[JsonProperty("default")]
public bool IsDefault { get; set; }

Expand Down
12 changes: 10 additions & 2 deletions Rofl.Executables/Utilities/ReplayPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public void Play(LeagueExecutable leagueExe, string replayPath)
}

// This will throw an exception if exe has issues
_exeManager.ValidateExecutable(leagueExe);
// 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>
Expand All @@ -40,10 +41,17 @@ public void Play(LeagueExecutable leagueExe, string replayPath)
combinedArgs += $" \"{arg}\"";
}

var launchArgs = combinedArgs;

if(leagueExe.UseOldLaunchArguments)
{
launchArgs = "\"" + replayPath + "\"";
}

ProcessStartInfo processStartInfo = new ProcessStartInfo
{
FileName = leagueExe.TargetPath,
Arguments = combinedArgs,
Arguments = launchArgs,

// The game client uses the working directory to find the data files
WorkingDirectory = Path.GetDirectoryName(leagueExe.TargetPath)
Expand Down
2 changes: 1 addition & 1 deletion Rofl.Logger/Scribe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void WriteToFile()

foreach (LogEntry entry in _entryList)
{
logOutput += $"{entry.Timestamp}\t|\t{entry.ClassName} -> {entry.MethodName}\t|\t{entry.Level}\t|\t{entry.Message}\n";
logOutput += $"{entry.Timestamp} | {entry.ClassName} -> {entry.MethodName} | {entry.Level} | {entry.Message}\n";
}

File.WriteAllText(outputFileName, logOutput);
Expand Down
16 changes: 7 additions & 9 deletions Rofl.Main/DetailForm.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Rofl.Executables;
using Rofl.Executables.Models;
using Rofl.Executables.Utilities;
using Rofl.Logger;
using Rofl.Main.Managers;
using Rofl.Reader.Models;
using Rofl.Requests;
Expand All @@ -20,13 +21,15 @@ public partial class DetailForm : Form
private RequestManager _requestManager;
private ExeManager _exeManager;
private ReplayPlayer _replayPlayer;
private Scribe _logger;

public DetailForm(ReplayFile replayFile, RequestManager requestManager, ExeManager exeManager, ReplayPlayer replayPlayer)
public DetailForm(ReplayFile replayFile, RequestManager requestManager, ExeManager exeManager, ReplayPlayer replayPlayer, Scribe scribe)
{
_replayFile = replayFile;
_requestManager = requestManager;
_exeManager = exeManager;
_replayPlayer = replayPlayer;
_logger = scribe;

InitializeComponent();

Expand Down Expand Up @@ -151,7 +154,7 @@ private void StartReplay(string execName = "default")
} else
{
// Start update form with target
var result = new UpdateSplashForm(execName).ShowDialog();
var result = new UpdateSplashForm(_exeManager, execName).ShowDialog();

if (result == DialogResult.OK)
{
Expand Down Expand Up @@ -184,13 +187,8 @@ private void StartReplay(string execName = "default")
{
if (t.IsFaulted)
{
string exceptionMsg = $"{t.Exception.GetType().ToString()} : {t.Exception.Message}\n";
foreach (var exception in t.Exception.InnerExceptions)
{
exceptionMsg += $"\n{exception.GetType().ToString()} : {exception.Message}\n";
}
MessageBox.Show("Failed to play replay!\n\n" + exceptionMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
_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;
}));
Expand Down
25 changes: 21 additions & 4 deletions Rofl.Main/ExecAddForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 28 additions & 1 deletion Rofl.Main/ExecAddForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,19 @@ public ExecAddForm(LeagueExecutable leagueExecutable)
InitForm();
toolTip = new ToolTip();

NewLeagueExec = leagueExecutable;
NewLeagueExec = new LeagueExecutable()
{
TargetPath = leagueExecutable.TargetPath,
Name = leagueExecutable.Name,
StartFolder = leagueExecutable.StartFolder,
PatchVersion = leagueExecutable.PatchVersion,
ModifiedDate = leagueExecutable.ModifiedDate,
AllowUpdates = leagueExecutable.AllowUpdates,
IsDefault = leagueExecutable.IsDefault,
UseOldLaunchArguments = leagueExecutable.UseOldLaunchArguments
};


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);
Expand All @@ -50,6 +62,7 @@ public ExecAddForm(LeagueExecutable leagueExecutable)
this.GBoxFileDescTextBox.Text = fileInfo.FileDescription;
this.GBoxLastModifTextBox.Text = NewLeagueExec.ModifiedDate.ToString("yyyy/dd/MM");
this.ExecUpdateCheckbox.Checked = NewLeagueExec.AllowUpdates;
this.ExecArgsCheckbox.Checked = NewLeagueExec.UseOldLaunchArguments;

this.Text = "Edit Executable...";
}
Expand Down Expand Up @@ -179,6 +192,11 @@ private void ExecUpdateCheckbox_CheckedChanged(object sender, EventArgs e)
NewLeagueExec.AllowUpdates = this.ExecUpdateCheckbox.Checked;
}

private void ExecArgsCheckbox_CheckedChanged(object sender, EventArgs e)
{
NewLeagueExec.UseOldLaunchArguments = this.ExecArgsCheckbox.Checked;
}

private void ExecUpdateCheckbox_ToolTip(object sender, EventArgs e)
{
CheckBox updateBox = (CheckBox)sender;
Expand All @@ -188,6 +206,15 @@ private void ExecUpdateCheckbox_ToolTip(object sender, EventArgs e)
toolTip.Show("ROFLPlayer can automatically update target path when League of Legends updates", updateBox, 0, 20, visTime);
}

private void ExecArgsCheckbox_ToolTip(object sender, EventArgs e)
{
CheckBox updateBox = (CheckBox)sender;

var visTime = 3000;

toolTip.Show("Use old launch arguments, required for old versions of League of Legends", updateBox, 0, 20, visTime);
}

private void ExecSaveButton_Click(object sender, EventArgs e)
{
if(!ValidateForm())
Expand Down
4 changes: 2 additions & 2 deletions Rofl.Main/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static void Main(string[] args)

RequestManager requestManager = new RequestManager();

Application.Run(new DetailForm(replayFile.Result, requestManager, exeManager, replayPlayer));
Application.Run(new DetailForm(replayFile.Result, requestManager, exeManager, replayPlayer, logger));
}
}
}
Expand Down Expand Up @@ -173,7 +173,7 @@ private static void StartReplay(string replayPath, ExeManager exeManager, Replay
else
{
// Start update form with target
var result = new UpdateSplashForm(execName).ShowDialog();
var result = new UpdateSplashForm(exeManager, execName).ShowDialog();

if (result == DialogResult.OK)
{
Expand Down
4 changes: 4 additions & 0 deletions Rofl.Main/SettingsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ private void ExecEditButton_Click(object sender, EventArgs e)
_exeManager.DeleteExecutable(selectedName);
_exeManager.AddExecutable(newExec);
}
else
{
_exeManager.ReplaceDefaultExecutable(newExec);
}

// Refresh list of execs
RefreshExecListBox();
Expand Down
3 changes: 2 additions & 1 deletion Rofl.Main/UpdateSplashForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ public UpdateSplashForm(ExeManager exeManager)
InitializeComponent();
}

public UpdateSplashForm(string targetExec)
public UpdateSplashForm(ExeManager exeManager, string targetExec)
{
_exeManager = exeManager;
TargetExecToUpdate = targetExec;
InitializeComponent();
}
Expand Down

0 comments on commit 53022fc

Please sign in to comment.