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