Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions Assets/PatchKit Patcher/Scripts/AppStarter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@ public AppStarter(App app)

private string ResolveExecutablePath(AppVersion appVersion)
{
PlatformType platformType = Platform.GetPlatformType();

if (!string.IsNullOrEmpty(appVersion.MainExecutable))
{
string executablePath = Path.Combine(_app.LocalDirectory.Path, appVersion.MainExecutable);

if (File.Exists(executablePath))
bool isOSXApp = platformType == PlatformType.OSX &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any chance that Platform.GetPlatformType returns OSX but the application isn't an OSX app?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, it's always the same.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The we shouldn't need all the other conditions, right?

...
executablePath.EndsWith(".app") &&
Directory.Exists(executablePath);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't checking whether application platform that secret we are using is OSX, but whether the appVersion.MainExecutable points to valid OSX .app.

executablePath.EndsWith(".app") &&
Directory.Exists(executablePath);

if (File.Exists(executablePath) || isOSXApp)
{
return executablePath;
}
Expand All @@ -50,7 +56,6 @@ private string ResolveExecutablePath(AppVersion appVersion)

}

PlatformType platformType = Platform.GetPlatformType();
return AppFinder.FindExecutable(_app.LocalDirectory.Path, platformType);
}

Expand Down Expand Up @@ -87,12 +92,7 @@ private void StartAppVersion(AppVersion appVersion)
}
}

var processStartInfo = GetProcessStartInfo(appFilePath, platformType);

if (!string.IsNullOrEmpty(appVersion.MainExecutableArgs))
{
processStartInfo.Arguments += " " + appVersion.MainExecutableArgs;
}
var processStartInfo = GetProcessStartInfo(appFilePath, appVersion.MainExecutableArgs, platformType);

StartAppProcess(processStartInfo);
}
Expand All @@ -102,8 +102,13 @@ private bool NeedPermissionFix(PlatformType platformType)
return platformType == PlatformType.OSX || platformType == PlatformType.Linux;
}

private ProcessStartInfo GetProcessStartInfo(string executablePath, PlatformType platform)
private ProcessStartInfo GetProcessStartInfo(string executablePath, string mainExecutableArgs, PlatformType platform)
{
if (mainExecutableArgs == null)
{
mainExecutableArgs = string.Empty;
}

string workingDir = Path.GetDirectoryName(executablePath) ?? string.Empty;
switch (platform)
{
Expand All @@ -113,20 +118,26 @@ private ProcessStartInfo GetProcessStartInfo(string executablePath, PlatformType
return new ProcessStartInfo
{
FileName = executablePath,
Arguments = string.Format("+patcher-data-location \"{0}\"", _app.LocalMetaData.GetFilePath()),
Arguments = string.Format("+patcher-data-location \"{0}\" " + mainExecutableArgs, _app.LocalMetaData.GetFilePath()),
WorkingDirectory = workingDir
};
case PlatformType.OSX:
if (!string.IsNullOrEmpty(mainExecutableArgs))
{
mainExecutableArgs = " --args " + mainExecutableArgs;
}

return new ProcessStartInfo
{
FileName = "open",
Arguments = string.Format("\"{0}\"", executablePath),
Arguments = string.Format("\"{0}\"{1}", executablePath, mainExecutableArgs),
WorkingDirectory = workingDir
};
case PlatformType.Linux:
return new ProcessStartInfo
{
FileName = executablePath,
Arguments = mainExecutableArgs,
WorkingDirectory = workingDir
};
default:
Expand Down