-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2271 from peppy/portable-installation-support
Add support for portable installations
- Loading branch information
Showing
25 changed files
with
428 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using osu.Framework.Platform; | ||
|
||
namespace osu.Framework.Tests.IO | ||
{ | ||
/// <summary> | ||
/// Ad headless host for testing purposes. Contains an arbitrary game that is running after construction. | ||
/// </summary> | ||
public class BackgroundGameHeadlessGameHost : HeadlessGameHost | ||
{ | ||
private TestGame testGame; | ||
|
||
public BackgroundGameHeadlessGameHost(string gameName = @"", bool bindIPC = false, bool realtime = true, bool portableInstallation = false) | ||
: base(gameName, bindIPC, realtime, portableInstallation) | ||
{ | ||
Task.Run(() => | ||
{ | ||
try | ||
{ | ||
Run(testGame = new TestGame()); | ||
} | ||
catch | ||
{ | ||
// may throw an unobserved exception if we don't handle here. | ||
} | ||
}); | ||
|
||
while (testGame?.HasProcessed != true) | ||
Thread.Sleep(10); | ||
} | ||
|
||
private class TestGame : Game | ||
{ | ||
public bool HasProcessed; | ||
|
||
protected override void Update() | ||
{ | ||
base.Update(); | ||
HasProcessed = true; | ||
} | ||
} | ||
|
||
protected override void Dispose(bool isDisposing) | ||
{ | ||
if (ExecutionState != ExecutionState.Stopped) | ||
Exit(); | ||
base.Dispose(isDisposing); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.IO; | ||
using NUnit.Framework; | ||
using osu.Framework.Configuration; | ||
using osu.Framework.Platform; | ||
|
||
namespace osu.Framework.Tests.Platform | ||
{ | ||
[TestFixture] | ||
public class PortableInstallationTest | ||
{ | ||
[Test] | ||
public void TestPortableInstall() | ||
{ | ||
Assert.IsFalse(File.Exists(FrameworkConfigManager.FILENAME)); | ||
|
||
using (var portable = new HeadlessGameHost(@"portable", portableInstallation: true)) | ||
{ | ||
portable.Run(new TestGame()); | ||
Assert.AreEqual(Path.GetFullPath(FrameworkConfigManager.FILENAME), portable.Storage.GetFullPath(FrameworkConfigManager.FILENAME)); | ||
} | ||
|
||
// portable mode should write the configuration | ||
Assert.IsTrue(File.Exists(FrameworkConfigManager.FILENAME)); | ||
|
||
// subsequent startups should detect the portable config and continue running in portable mode, even though it is not explicitly specified | ||
using (var portable = new HeadlessGameHost(@"portable")) | ||
{ | ||
portable.Run(new TestGame()); | ||
Assert.AreEqual(Path.GetFullPath(FrameworkConfigManager.FILENAME), portable.Storage.GetFullPath(FrameworkConfigManager.FILENAME)); | ||
} | ||
|
||
Assert.IsTrue(File.Exists(FrameworkConfigManager.FILENAME)); | ||
} | ||
|
||
[Test] | ||
public void TestNonPortableInstall() | ||
{ | ||
Assert.IsFalse(File.Exists(FrameworkConfigManager.FILENAME)); | ||
|
||
using (var portable = new HeadlessGameHost(@"non-portable")) | ||
{ | ||
portable.Run(new TestGame()); | ||
Assert.AreEqual(Path.GetFullPath(Path.Combine(@"headless-non-portable", FrameworkConfigManager.FILENAME)), portable.Storage.GetFullPath(FrameworkConfigManager.FILENAME)); | ||
} | ||
|
||
Assert.IsFalse(File.Exists(FrameworkConfigManager.FILENAME)); | ||
} | ||
|
||
[TearDown] | ||
[SetUp] | ||
public void TearDown() | ||
{ | ||
File.Delete(FrameworkConfigManager.FILENAME); | ||
} | ||
|
||
private class TestGame : Game | ||
{ | ||
protected override void Update() | ||
{ | ||
base.Update(); | ||
Exit(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using osu.Framework.Platform; | ||
|
||
namespace osu.Framework.iOS | ||
{ | ||
public class IOSStorage : NativeStorage | ||
{ | ||
protected override string LocateBasePath() => Environment.GetFolderPath(Environment.SpecialFolder.Personal); | ||
|
||
public IOSStorage(string baseName, IOSGameHost host = null) | ||
: base(baseName, host) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.