Skip to content
Merged
Show file tree
Hide file tree
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
Binary file modified Assets/PatchKit Patcher/Library/PatchKit.Api.dll
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public interface IRemoteMetaData
/// <param name="versionId">The version identifier.</param>
AppDiffSummary GetDiffSummary(int versionId);

/// <summary>
/// Returns the AppVersion model for the specified version id.
/// </summary>
/// <param name="versionId">The version identifier.</param>
AppVersion GetAppVersionInfo(int versionId);

/// <summary>
/// Returns key secret for certain key.
/// </summary>
Expand Down
12 changes: 12 additions & 0 deletions Assets/PatchKit Patcher/Scripts/AppData/Remote/RemoteMetaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,17 @@ public string GetKeySecret(string key, string cachedKeySecret)

return keySecret;
}

public AppVersion GetAppVersionInfo(int versionId)
{
if (versionId <= 0)
{
throw new ArgumentException("Version id is invalid.", "versionId");
}

DebugLogger.Log(string.Format("Getting app version info for version with id {0}", versionId));

return _mainApiConnection.GetAppVersion(_appSecret, versionId);
}
}
}
45 changes: 43 additions & 2 deletions Assets/PatchKit Patcher/Scripts/AppStarter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using System.IO;
using PatchKit.Api.Models.Main;
using PatchKit.Unity.Patcher.AppData;
using PatchKit.Unity.Patcher.Data;
using PatchKit.Unity.Patcher.Debug;
Expand All @@ -26,12 +27,46 @@ public AppStarter(App app)
AppFinder = new AppFinder();
}

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

if (File.Exists(executablePath))
{
return executablePath;
}

// Reports to Sentry
try
{
throw new FileNotFoundException(string.Format("Couldn't resolve executable in {0}", executablePath));
}
catch (Exception e)
{
DebugLogger.LogException(e);
}

}

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

public void Start()
{
var appVersion = _app.RemoteMetaData.GetAppVersionInfo(_app.GetInstalledVersionId());
StartAppVersion(appVersion);
}

private void StartAppVersion(AppVersion appVersion)
{
DebugLogger.Log("Starting application.");

PlatformType platformType = Platform.GetPlatformType();
string appFilePath = AppFinder.FindExecutable(_app.LocalDirectory.Path, platformType);
string appFilePath = ResolveExecutablePath(appVersion);

if (appFilePath == null)
{
throw new InvalidOperationException("Couldn't find executable.");
Expand All @@ -53,6 +88,12 @@ public void Start()
}

var processStartInfo = GetProcessStartInfo(appFilePath, platformType);

if (!string.IsNullOrEmpty(appVersion.MainExecutableArgs))
{
processStartInfo.Arguments += " " + appVersion.MainExecutableArgs;
}

StartAppProcess(processStartInfo);
}

Expand All @@ -67,7 +108,7 @@ private ProcessStartInfo GetProcessStartInfo(string executablePath, PlatformType
switch (platform)
{
case PlatformType.Unknown:
throw new ArgumentException("Unknown");;
throw new ArgumentException("Unknown");
case PlatformType.Windows:
return new ProcessStartInfo
{
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added
- Support for LZMA2 compression using XZ
- Sending all events to Statistics Reporting Service
- Support for main_executable and main_executable_args fields in AppVersion
- Added processing of --online or --offline command line argument
- Sending 'patcher_started' event to Statistics Reporting Service
- Custom building options under `Tools/Build`
Expand Down