Browse Source

Added ConfigRuntime type

Moved Synchronization.cs to Async folder
4.0.0-beta
Anairkoen Schno 4 years ago
parent
commit
5409bdd16b
4 changed files with 36 additions and 20 deletions
  1. +9
    -16
      IPA.Loader/Config/Config.cs
  2. +24
    -0
      IPA.Loader/Config/ConfigRuntime.cs
  3. +3
    -4
      IPA.Loader/IPA.Loader.csproj
  4. +0
    -0
      IPA.Loader/Utilities/Async/Synchronization.cs

+ 9
- 16
IPA.Loader/Config/Config.cs View File

@ -25,10 +25,11 @@ namespace IPA.Config
}
/// <summary>
/// Specifies that a particular parameter is preferred to be a specific type of <see cref="T:IPA.Config.IConfigProvider" />. If it is not available, also specifies backups. If none are available, the default is used.
/// Specifies that a particular parameter is preferred to use a particular <see cref="IConfigProvider" />.
/// If it is not available, also specifies backups. If none are available, the default is used.
/// </summary>
[AttributeUsage(AttributeTargets.Parameter)]
public class PreferAttribute : Attribute
public sealed class PreferAttribute : Attribute
{
/// <summary>
/// The order of preference for the config type.
@ -52,7 +53,7 @@ namespace IPA.Config
/// Specifies a preferred config name, instead of using the plugin's name.
/// </summary>
[AttributeUsage(AttributeTargets.Parameter)]
public class NameAttribute : Attribute
public sealed class NameAttribute : Attribute
{
/// <summary>
/// The name to use for the config.
@ -96,8 +97,6 @@ namespace IPA.Config
registeredProviders.Add(inst.Extension, inst);
}
private static Dictionary<Config, FileInfo> files = new Dictionary<Config, FileInfo>();
/// <summary>
/// Gets a <see cref="Config"/> object using the specified list of preferred config types.
/// </summary>
@ -109,12 +108,10 @@ namespace IPA.Config
var chosenExt = extensions.FirstOrDefault(s => registeredProviders.ContainsKey(s)) ?? "json";
var provider = registeredProviders[chosenExt];
var config = new Config(configName, provider);
var filename = Path.Combine(BeatSaber.UserDataPath, configName + "." + provider.Extension);
files.Add(config, new FileInfo(filename));
var config = new Config(configName, provider, new FileInfo(filename));
RegisterConfigObject(config);
ConfigRuntime.RegisterConfig(config);
return config;
}
@ -130,11 +127,6 @@ namespace IPA.Config
return GetConfigFor(modName, prefs);
}
private static void RegisterConfigObject(Config obj)
{
// TODO: implement
}
/// <summary>
/// Gets the name associated with this <see cref="Config"/> object.
/// </summary>
@ -145,6 +137,7 @@ namespace IPA.Config
public IConfigProvider Provider { get; private set; }
internal readonly HashSet<IConfigStore> Stores = new HashSet<IConfigStore>();
internal readonly FileInfo File;
/// <summary>
/// Adds an <see cref="IConfigStore"/> to this <see cref="Config"/> object.
@ -154,9 +147,9 @@ namespace IPA.Config
/// otherwise <see langword="false"/></returns>
public bool AddStore(IConfigStore store) => Stores.Add(store);
private Config(string name, IConfigProvider provider)
private Config(string name, IConfigProvider provider, FileInfo file)
{
Name = name; Provider = provider;
Name = name; Provider = provider; File = file;
}
}
}

+ 24
- 0
IPA.Loader/Config/ConfigRuntime.cs View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace IPA.Config
{
internal static class ConfigRuntime
{
private static readonly ConcurrentBag<Config> configs = new ConcurrentBag<Config>();
private static readonly AutoResetEvent memoryChangedWatcher = new AutoResetEvent(false);
public static void RegisterConfig(Config cfg)
{
configs.Add(cfg);
// TODO: register file watcher, reset changed watcher
}
}
}

+ 3
- 4
IPA.Loader/IPA.Loader.csproj View File

@ -85,6 +85,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Config\Config.cs" />
<Compile Include="Config\ConfigRuntime.cs" />
<Compile Include="Config\Providers\JsonConfigProvider.cs" />
<Compile Include="Config\Data\List.cs" />
<Compile Include="Config\Data\Map.cs" />
@ -144,7 +145,7 @@
<Compile Include="Updating\BeatMods\ApiEndpoint.cs" />
<Compile Include="Updating\BeatMods\Updater.cs" />
<Compile Include="Utilities\Extensions.cs" />
<Compile Include="Utilities\Synchronization.cs" />
<Compile Include="Utilities\Async\Synchronization.cs" />
<Compile Include="Utilities\Utils.cs" />
<Compile Include="Utilities\Win32.cs" />
</ItemGroup>
@ -179,8 +180,6 @@
<ItemGroup>
<None Include="icon_black.png" />
</ItemGroup>
<ItemGroup>
<Folder Include="Utilities\Async\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

IPA.Loader/Utilities/Synchronization.cs → IPA.Loader/Utilities/Async/Synchronization.cs View File


Loading…
Cancel
Save