mirror of
https://github.com/osukey/osukey.git
synced 2025-08-05 23:53:51 +09:00
Add basic custom data directory support
This commit is contained in:
30
osu.Game/Configuration/StorageConfigManager.cs
Normal file
30
osu.Game/Configuration/StorageConfigManager.cs
Normal file
@ -0,0 +1,30 @@
|
||||
// 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 osu.Framework.Configuration;
|
||||
using osu.Framework.Platform;
|
||||
|
||||
namespace osu.Game.Configuration
|
||||
{
|
||||
public class StorageConfigManager : IniConfigManager<StorageConfig>
|
||||
{
|
||||
protected override string Filename => "storage.ini";
|
||||
|
||||
public StorageConfigManager(Storage storage)
|
||||
: base(storage)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void InitialiseDefaults()
|
||||
{
|
||||
base.InitialiseDefaults();
|
||||
|
||||
Set(StorageConfig.FullPath, string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
public enum StorageConfig
|
||||
{
|
||||
FullPath,
|
||||
}
|
||||
}
|
@ -132,6 +132,8 @@ namespace osu.Game
|
||||
|
||||
dependencies.Cache(contextFactory = new DatabaseContextFactory(Storage));
|
||||
|
||||
dependencies.CacheAs(Storage);
|
||||
|
||||
var largeStore = new LargeTextureStore(Host.CreateTextureLoaderStore(new NamespacedResourceStore<byte[]>(Resources, @"Textures")));
|
||||
largeStore.AddStore(Host.CreateTextureLoaderStore(new OnlineStore()));
|
||||
dependencies.Cache(largeStore);
|
||||
@ -300,8 +302,13 @@ namespace osu.Game
|
||||
{
|
||||
base.SetHost(host);
|
||||
|
||||
if (Storage == null)
|
||||
Storage = host.Storage;
|
||||
var storageConfig = new StorageConfigManager(host.Storage);
|
||||
|
||||
var customStoragePath = storageConfig.Get<string>(StorageConfig.FullPath);
|
||||
|
||||
Storage = !string.IsNullOrEmpty(customStoragePath)
|
||||
? new CustomStorage(customStoragePath, host)
|
||||
: host.Storage;
|
||||
|
||||
if (LocalConfig == null)
|
||||
LocalConfig = new OsuConfigManager(Storage);
|
||||
@ -353,5 +360,17 @@ namespace osu.Game
|
||||
public override bool ChangeFocusOnClick => false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A storage pointing to an absolute location specified by the user to store game data files.
|
||||
/// </summary>
|
||||
private class CustomStorage : NativeStorage
|
||||
{
|
||||
public CustomStorage(string fullPath, GameHost host)
|
||||
: base(string.Empty, host)
|
||||
{
|
||||
BasePath = fullPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user