Skip to content

Commit

Permalink
Fix #239: Allow relative paths in LEProc and LEGUI
Browse files Browse the repository at this point in the history
  • Loading branch information
xupefei committed Aug 12, 2016
1 parent 55765cd commit e6fb474
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
5 changes: 5 additions & 0 deletions LECommonLibrary/SystemHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public static string RedirectToWow64(string path)
return path.Replace(system, systemWow64);
}

public static string EnsureAbsolutePath(string path)
{
return Path.IsPathRooted(path) ? path : Path.GetFullPath(path);
}

public static bool Is4KDisplay()
{
Graphics g = Graphics.FromHwnd(IntPtr.Zero);
Expand Down
2 changes: 1 addition & 1 deletion LEGUI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private void App_OnStartup(object sender, StartupEventArgs e)
{
if (e.Args.Length != 0)
{
StandaloneFilePath = e.Args[0];
StandaloneFilePath = SystemHelper.EnsureAbsolutePath(e.Args[0]);

// This happens when user is trying to drop a exe onto LEGUI.
if (!StandaloneFilePath.EndsWith(".le.config", true, null))
Expand Down
24 changes: 15 additions & 9 deletions LEProc/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,15 @@ private static void Main(string[] args)

private static void RunWithDefaultProfile(string path)
{
path = SystemHelper.EnsureAbsolutePath(path);

DoRunWithLEProfile(path, 1, new LEProfile(true));
}

private static void RunWithGlobalProfile(string guid, string path)
{
path = SystemHelper.EnsureAbsolutePath(path);

// We do not check whether the config exists because only when it exists can this method be called.

var profile = LEConfig.GetProfiles().First(p => p.Guid == guid);
Expand All @@ -146,6 +150,8 @@ private static void RunWithGlobalProfile(string guid, string path)

private static void RunWithIndependentProfile(string path)
{
path = SystemHelper.EnsureAbsolutePath(path);

var conf = path + ".le.config";

if (!File.Exists(conf))
Expand All @@ -161,7 +167,7 @@ private static void RunWithIndependentProfile(string path)
}
}

private static void DoRunWithLEProfile(string path, int argumentsStart, LEProfile profile)
private static void DoRunWithLEProfile(string absPath, int argumentsStart, LEProfile profile)
{
try
{
Expand Down Expand Up @@ -191,13 +197,13 @@ private static void DoRunWithLEProfile(string path, int argumentsStart, LEProfil
var applicationName = string.Empty;
var commandLine = string.Empty;

if (Path.GetExtension(path).ToLower() == ".exe")
if (Path.GetExtension(absPath).ToLower() == ".exe")
{
applicationName = path;
applicationName = absPath;

commandLine = path.StartsWith("\"")
? $"{path} "
: $"\"{path}\" ";
commandLine = absPath.StartsWith("\"")
? $"{absPath} "
: $"\"{absPath}\" ";

// use arguments in le.config, prior to command line arguments
commandLine += string.IsNullOrEmpty(profile.Parameter) && Args.Skip(argumentsStart).Any()
Expand All @@ -206,7 +212,7 @@ private static void DoRunWithLEProfile(string path, int argumentsStart, LEProfil
}
else
{
var jb = AssociationReader.GetAssociatedProgram(Path.GetExtension(path));
var jb = AssociationReader.GetAssociatedProgram(Path.GetExtension(absPath));

if (jb == null)
return;
Expand All @@ -216,10 +222,10 @@ private static void DoRunWithLEProfile(string path, int argumentsStart, LEProfil
commandLine = jb[0].StartsWith("\"")
? $"{jb[0]} "
: $"\"{jb[0]}\" ";
commandLine += jb[1].Replace("%1", path).Replace("%*", profile.Parameter);
commandLine += jb[1].Replace("%1", absPath).Replace("%*", profile.Parameter);
}

var currentDirectory = Path.GetDirectoryName(path);
var currentDirectory = Path.GetDirectoryName(absPath);
var ansiCodePage = (uint) CultureInfo.GetCultureInfo(profile.Location).TextInfo.ANSICodePage;
var oemCodePage = (uint) CultureInfo.GetCultureInfo(profile.Location).TextInfo.OEMCodePage;
var localeID = (uint) CultureInfo.GetCultureInfo(profile.Location).TextInfo.LCID;
Expand Down

0 comments on commit e6fb474

Please sign in to comment.