Skip to content

Commit ada242c

Browse files
committed
Merge branch 'master' into release
2 parents 818d8a3 + 72bc22a commit ada242c

30 files changed

+600
-162
lines changed

Assets/Editor/Tests/LocalMetaDataTest.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
public class LocalMetaDataTest
66
{
77
private string _filePath;
8+
private string _deprecatedFilePath;
89

910
[SetUp]
1011
public void Setup()
1112
{
1213
_filePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
14+
_deprecatedFilePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
1315
}
1416

1517
[TearDown]
@@ -26,7 +28,7 @@ public void CreateMetaDataFile()
2628
{
2729
Assert.False(File.Exists(_filePath));
2830

29-
var localMetaData = new LocalMetaData(_filePath);
31+
var localMetaData = new LocalMetaData(_filePath, _deprecatedFilePath);
3032

3133
localMetaData.RegisterEntry("test", 1);
3234

@@ -36,12 +38,12 @@ public void CreateMetaDataFile()
3638
[Test]
3739
public void SaveValidFileSinglePass()
3840
{
39-
var localMetaData = new LocalMetaData(_filePath);
41+
var localMetaData = new LocalMetaData(_filePath, _deprecatedFilePath);
4042

4143
localMetaData.RegisterEntry("a", 1);
4244
localMetaData.RegisterEntry("b", 2);
4345

44-
var localMetaData2 = new LocalMetaData(_filePath);
46+
var localMetaData2 = new LocalMetaData(_filePath, _deprecatedFilePath);
4547

4648
Assert.IsTrue(localMetaData2.IsEntryRegistered("a"));
4749
Assert.IsTrue(localMetaData2.IsEntryRegistered("b"));

Assets/Editor/Tests/MagicBytesTest.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,18 @@
33

44
public class MagicBytesTest
55
{
6-
private readonly string _macApp = TestFixtures.GetFilePath("magicbytes-test/mac_app");
7-
private readonly string _windowsApp = TestFixtures.GetFilePath("magicbytes-test/windows_app");
8-
private readonly string _linuxApp = TestFixtures.GetFilePath("magicbytes-test/linux_app");
6+
private string _macApp;
7+
private string _windowsApp;
8+
private string _linuxApp;
99

10+
[SetUp]
11+
public void SetUp()
12+
{
13+
_macApp = TestFixtures.GetFilePath("magicbytes-test/mac_app");
14+
_windowsApp = TestFixtures.GetFilePath("magicbytes-test/windows_app");
15+
_linuxApp = TestFixtures.GetFilePath("magicbytes-test/linux_app");
16+
}
17+
1018
[Test]
1119
public void IsMacExecutable_ForMacApp_ReturnsTrue()
1220
{

Assets/Editor/Tests/ValidateLicenseCommandTest.cs

Lines changed: 131 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,34 @@
22
using System.Collections.Generic;
33
using NSubstitute;
44
using NUnit.Framework;
5+
using PatchKit.Api;
56
using PatchKit.Api.Models.Main;
6-
using PatchKit.Unity.Patcher.AppData.Local;
77
using PatchKit.Unity.Patcher.AppData.Remote;
88
using PatchKit.Unity.Patcher.AppUpdater.Commands;
99
using PatchKit.Unity.Patcher.Cancellation;
1010
using PatchKit.Unity.Patcher.Status;
1111
using PatchKit.Unity.Patcher.UI.Dialogs;
12-
using UnityEngine;
1312

1413
class ValidateLicenseCommandTest
1514
{
15+
private PatchKit.Logging.ILogger _logger;
16+
private IStatusMonitor _statusMonitor;
17+
private MockCache _cache;
18+
19+
[SetUp]
20+
public void SetUp()
21+
{
22+
_logger = Substitute.For<PatchKit.Logging.ILogger>();
23+
_statusMonitor = Substitute.For<IStatusMonitor>();
24+
_cache = new MockCache();
25+
}
26+
1627
[Test]
17-
public void Execute_UsesCachedKey()
28+
public void Execute_CachesKeyAndKeySecret()
1829
{
19-
var cache = new MockCache();
20-
2130
const string key = "this-key-should-be-cached";
22-
31+
const string keySecret = "this-key-secret-should-be-cached";
32+
2333
for (int i = 0; i < 2; i++)
2434
{
2535
var licenseDialog = Substitute.For<ILicenseDialog>();
@@ -34,23 +44,131 @@ public void Execute_UsesCachedKey()
3444
{
3545
UseKeys = true
3646
});
37-
38-
var statusMonitor = Substitute.For<IStatusMonitor>();
39-
40-
var command = new ValidateLicenseCommand(licenseDialog, remoteMetaData, cache);
41-
command.Prepare(statusMonitor);
47+
remoteMetaData.GetKeySecret(key, Arg.Any<string>()).Returns(keySecret);
48+
49+
var command = new ValidateLicenseCommand(licenseDialog, remoteMetaData, _cache, _logger);
50+
command.Prepare(_statusMonitor);
4251
command.Execute(CancellationToken.Empty);
43-
52+
4453
if (i == 0)
4554
{
4655
licenseDialog.Received(1).Display(Arg.Any<LicenseDialogMessageType>());
56+
Assert.IsTrue(_cache.Dictionary.ContainsValue(key));
57+
Assert.IsTrue(_cache.Dictionary.ContainsValue(keySecret));
4758
}
4859
else
4960
{
61+
licenseDialog.Received(1).SetKey(key);
5062
licenseDialog.DidNotReceive().Display(Arg.Any<LicenseDialogMessageType>());
63+
Assert.IsTrue(_cache.Dictionary.ContainsValue(key));
64+
Assert.IsTrue(_cache.Dictionary.ContainsValue(keySecret));
5165
}
5266
}
67+
}
68+
69+
[Test]
70+
public void Execute_ProperlyHandlesSitauationWhenKeysAreNotUsed()
71+
{
72+
var licenseDialog = Substitute.For<ILicenseDialog>();
73+
74+
var remoteMetaData = Substitute.For<IRemoteMetaData>();
75+
remoteMetaData.GetAppInfo().Returns(new App()
76+
{
77+
UseKeys = false
78+
});
79+
80+
var command = new ValidateLicenseCommand(licenseDialog, remoteMetaData, _cache, _logger);
81+
command.Prepare(_statusMonitor);
82+
command.Execute(CancellationToken.Empty);
83+
84+
Assert.AreEqual(command.KeySecret, null);
85+
remoteMetaData.DidNotReceive().GetKeySecret(Arg.Any<string>(), Arg.Any<string>());
86+
licenseDialog.DidNotReceive().Display(Arg.Any<LicenseDialogMessageType>());
87+
}
88+
89+
[TestCase(404, LicenseDialogMessageType.InvalidLicense)]
90+
[TestCase(403, LicenseDialogMessageType.ServiceUnavailable)]
91+
[TestCase(410, LicenseDialogMessageType.BlockedLicense)]
92+
public void Execute_DisplaysDialogMessageForApiError(int statusCode, LicenseDialogMessageType messageType)
93+
{
94+
const string key = "key";
95+
const string keySecret = "key-secret";
96+
97+
var licenseDialog = Substitute.For<ILicenseDialog>();
98+
licenseDialog.Display(Arg.Any<LicenseDialogMessageType>()).ReturnsForAnyArgs(new LicenseDialogResult()
99+
{
100+
Key = key,
101+
Type = LicenseDialogResultType.Confirmed
102+
});
103+
104+
var remoteMetaData = Substitute.For<IRemoteMetaData>();
105+
remoteMetaData.GetAppInfo().Returns(new App()
106+
{
107+
UseKeys = true
108+
});
109+
110+
bool firstAttempt = true;
111+
112+
remoteMetaData.GetKeySecret(key, Arg.Any<string>()).Returns(info =>
113+
{
114+
if (!firstAttempt)
115+
{
116+
return keySecret;
117+
}
118+
119+
firstAttempt = false;
120+
throw new ApiResponseException(statusCode);
121+
});
122+
123+
var command = new ValidateLicenseCommand(licenseDialog, remoteMetaData, _cache, _logger);
124+
command.Prepare(_statusMonitor);
125+
command.Execute(CancellationToken.Empty);
126+
127+
licenseDialog.Received(1).Display(LicenseDialogMessageType.None);
128+
licenseDialog.Received(1).Display(messageType);
129+
licenseDialog.DidNotReceive().Display(Arg.Is<LicenseDialogMessageType>(type => type != LicenseDialogMessageType.None &&
130+
type != messageType));
131+
}
132+
133+
[Test]
134+
public void Execute_DisplaysProperDialogMessageForConnectionError()
135+
{
136+
const string key = "key";
137+
const string keySecret = "key-secret";
138+
139+
var licenseDialog = Substitute.For<ILicenseDialog>();
140+
licenseDialog.Display(Arg.Any<LicenseDialogMessageType>()).ReturnsForAnyArgs(new LicenseDialogResult()
141+
{
142+
Key = key,
143+
Type = LicenseDialogResultType.Confirmed
144+
});
145+
146+
var remoteMetaData = Substitute.For<IRemoteMetaData>();
147+
remoteMetaData.GetAppInfo().Returns(new App()
148+
{
149+
UseKeys = true
150+
});
151+
152+
bool firstAttempt = true;
153+
154+
remoteMetaData.GetKeySecret(key, Arg.Any<string>()).Returns(info =>
155+
{
156+
if (!firstAttempt)
157+
{
158+
return keySecret;
159+
}
160+
161+
firstAttempt = false;
162+
throw new ApiConnectionException(new List<Exception>(), new List<Exception>());
163+
});
53164

54-
Assert.IsTrue(cache.Dictionary.ContainsValue(key));
165+
var command = new ValidateLicenseCommand(licenseDialog, remoteMetaData, _cache, _logger);
166+
command.Prepare(_statusMonitor);
167+
command.Execute(CancellationToken.Empty);
168+
169+
licenseDialog.Received(1).Display(LicenseDialogMessageType.None);
170+
licenseDialog.Received(1).Display(LicenseDialogMessageType.ServiceUnavailable);
171+
licenseDialog.DidNotReceive().Display(Arg.Is<LicenseDialogMessageType>(type => type != LicenseDialogMessageType.None &&
172+
type != LicenseDialogMessageType.ServiceUnavailable));
55173
}
56174
}
17.5 KB
Binary file not shown.
512 Bytes
Binary file not shown.

Assets/PatchKit Patcher/Patcher.unity

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ MonoBehaviour:
237237
m_HorizontalOverflow: 1
238238
m_VerticalOverflow: 1
239239
m_LineSpacing: 1
240-
m_Text: Continue
240+
m_Text: Retry
241241
--- !u!222 &55392231
242242
CanvasRenderer:
243243
m_ObjectHideFlags: 0
@@ -854,6 +854,7 @@ MonoBehaviour:
854854
AppUpdaterConfiguration:
855855
UseTorrents: 1
856856
CheckConsistencyBeforeDiffUpdate: 1
857+
HashSizeThreshold: 1073741824
857858
AutomaticallyStartApp: 0
858859
AutomaticallyCheckForAppUpdates: 1
859860
AutomaticallyInstallApp: 1

Assets/PatchKit Patcher/Patcher_698.unity

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ MonoBehaviour:
237237
m_HorizontalOverflow: 1
238238
m_VerticalOverflow: 1
239239
m_LineSpacing: 1
240-
m_Text: Continue
240+
m_Text: Retry
241241
--- !u!222 &55392231
242242
CanvasRenderer:
243243
m_ObjectHideFlags: 0
@@ -817,7 +817,6 @@ GameObject:
817817
- 4: {fileID: 377531152}
818818
- 114: {fileID: 377531153}
819819
- 114: {fileID: 377531154}
820-
- 114: {fileID: 377531155}
821820
m_Layer: 0
822821
m_Name: Patcher
823822
m_TagString: Untagged
@@ -849,12 +848,13 @@ MonoBehaviour:
849848
m_Name:
850849
m_EditorClassIdentifier:
851850
ErrorDialog: {fileID: 272161832}
852-
EditorAppSecret: 2364b5c2decdbb4e68d1fbeeceff278b
853-
EditorOverrideLatestVersionId: 0
851+
EditorAppSecret: f21ce8123258a787169f16d1dc3702d6
852+
EditorOverrideLatestVersionId: 3
854853
DefaultConfiguration:
855854
AppUpdaterConfiguration:
856855
UseTorrents: 1
857856
CheckConsistencyBeforeDiffUpdate: 1
857+
HashSizeThreshold: 1073741824
858858
AutomaticallyStartApp: 0
859859
AutomaticallyCheckForAppUpdates: 1
860860
AutomaticallyInstallApp: 1
@@ -870,17 +870,6 @@ MonoBehaviour:
870870
m_Name:
871871
m_EditorClassIdentifier:
872872
IgnoreEditorErrors: 1
873-
--- !u!114 &377531155
874-
MonoBehaviour:
875-
m_ObjectHideFlags: 0
876-
m_PrefabParentObject: {fileID: 0}
877-
m_PrefabInternal: {fileID: 0}
878-
m_GameObject: {fileID: 377531151}
879-
m_Enabled: 1
880-
m_EditorHideFlags: 0
881-
m_Script: {fileID: 11500000, guid: a1872f00fdd8e7a47a81b37fbfb1aaf6, type: 3}
882-
m_Name:
883-
m_EditorClassIdentifier:
884873
--- !u!1 &421519242
885874
GameObject:
886875
m_ObjectHideFlags: 0

Assets/PatchKit Patcher/Scripts/App.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ private static IDownloadDirectory CreateDefaultDownloadDirectory(string appDataP
163163

164164
private static ILocalMetaData CreateDefaultLocalMetaData(string appDataPath)
165165
{
166-
return new LocalMetaData(appDataPath.PathCombine("patcher_cache.json"));
166+
return new LocalMetaData(appDataPath.PathCombine("app_data.json"), appDataPath.PathCombine("patcher_cache.json"));
167167
}
168168

169169
private static IRemoteData CreateDefaultRemoteData(string appSecret)

Assets/PatchKit Patcher/Scripts/AppData/Local/ILocalMetaData.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,10 @@ public interface ILocalMetaData
3535
/// </summary>
3636
/// <param name="entryName">Name of the entry.</param>
3737
int GetEntryVersionId(string entryName);
38+
39+
/// <summary>
40+
/// Returns the file path of JSON file the data was loaded from.
41+
/// </summary>
42+
string GetFilePath();
3843
}
3944
}

0 commit comments

Comments
 (0)