Skip to content

Commit eafb250

Browse files
authored
Merge pull request #85 from patchkit-net/feature/v3.x.x/1022-and-1021-app-version-process-info
Feature/v3.x.x/1022 and 1021 app version process info
2 parents 378e143 + 1bf7d0f commit eafb250

File tree

5 files changed

+62
-2
lines changed

5 files changed

+62
-2
lines changed
2.5 KB
Binary file not shown.

Assets/PatchKit Patcher/Scripts/AppData/Remote/IRemoteMetaData.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ public interface IRemoteMetaData
2626
/// <param name="versionId">The version identifier.</param>
2727
AppDiffSummary GetDiffSummary(int versionId);
2828

29+
/// <summary>
30+
/// Returns the AppVersion model for the specified version id.
31+
/// </summary>
32+
/// <param name="versionId">The version identifier.</param>
33+
AppVersion GetAppVersionInfo(int versionId);
34+
2935
/// <summary>
3036
/// Returns key secret for certain key.
3137
/// </summary>

Assets/PatchKit Patcher/Scripts/AppData/Remote/RemoteMetaData.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,17 @@ public string GetKeySecret(string key, string cachedKeySecret)
9595

9696
return keySecret;
9797
}
98+
99+
public AppVersion GetAppVersionInfo(int versionId)
100+
{
101+
if (versionId <= 0)
102+
{
103+
throw new ArgumentException("Version id is invalid.", "versionId");
104+
}
105+
106+
DebugLogger.Log(string.Format("Getting app version info for version with id {0}", versionId));
107+
108+
return _mainApiConnection.GetAppVersion(_appSecret, versionId);
109+
}
98110
}
99111
}

Assets/PatchKit Patcher/Scripts/AppStarter.cs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Diagnostics;
33
using System.IO;
4+
using PatchKit.Api.Models.Main;
45
using PatchKit.Unity.Patcher.AppData;
56
using PatchKit.Unity.Patcher.Data;
67
using PatchKit.Unity.Patcher.Debug;
@@ -26,12 +27,46 @@ public AppStarter(App app)
2627
AppFinder = new AppFinder();
2728
}
2829

30+
private string ResolveExecutablePath(AppVersion appVersion)
31+
{
32+
if (!string.IsNullOrEmpty(appVersion.MainExecutable))
33+
{
34+
string executablePath = Path.Combine(_app.LocalDirectory.Path, appVersion.MainExecutable);
35+
36+
if (File.Exists(executablePath))
37+
{
38+
return executablePath;
39+
}
40+
41+
// Reports to Sentry
42+
try
43+
{
44+
throw new FileNotFoundException(string.Format("Couldn't resolve executable in {0}", executablePath));
45+
}
46+
catch (Exception e)
47+
{
48+
DebugLogger.LogException(e);
49+
}
50+
51+
}
52+
53+
PlatformType platformType = Platform.GetPlatformType();
54+
return AppFinder.FindExecutable(_app.LocalDirectory.Path, platformType);
55+
}
56+
2957
public void Start()
58+
{
59+
var appVersion = _app.RemoteMetaData.GetAppVersionInfo(_app.GetInstalledVersionId());
60+
StartAppVersion(appVersion);
61+
}
62+
63+
private void StartAppVersion(AppVersion appVersion)
3064
{
3165
DebugLogger.Log("Starting application.");
3266

3367
PlatformType platformType = Platform.GetPlatformType();
34-
string appFilePath = AppFinder.FindExecutable(_app.LocalDirectory.Path, platformType);
68+
string appFilePath = ResolveExecutablePath(appVersion);
69+
3570
if (appFilePath == null)
3671
{
3772
throw new InvalidOperationException("Couldn't find executable.");
@@ -53,6 +88,12 @@ public void Start()
5388
}
5489

5590
var processStartInfo = GetProcessStartInfo(appFilePath, platformType);
91+
92+
if (!string.IsNullOrEmpty(appVersion.MainExecutableArgs))
93+
{
94+
processStartInfo.Arguments += " " + appVersion.MainExecutableArgs;
95+
}
96+
5697
StartAppProcess(processStartInfo);
5798
}
5899

@@ -67,7 +108,7 @@ private ProcessStartInfo GetProcessStartInfo(string executablePath, PlatformType
67108
switch (platform)
68109
{
69110
case PlatformType.Unknown:
70-
throw new ArgumentException("Unknown");;
111+
throw new ArgumentException("Unknown");
71112
case PlatformType.Windows:
72113
return new ProcessStartInfo
73114
{

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
### Added
99
- Support for LZMA2 compression using XZ
1010
- Sending all events to Statistics Reporting Service
11+
- Support for main_executable and main_executable_args fields in AppVersion
1112
- Added processing of --online or --offline command line argument
1213
- Sending 'patcher_started' event to Statistics Reporting Service
1314
- Custom building options under `Tools/Build`

0 commit comments

Comments
 (0)