Write out unfound config files as templates so you can hack around with them later.
This commit is contained in:
parent
1947de8a84
commit
c5f35e58d9
29
Config.cs
29
Config.cs
@ -16,6 +16,13 @@ public class DescAttribute : Attribute
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class ConfigCfg : Config
|
||||
{
|
||||
public readonly bool writeOutTemplateFiles = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Serializable]
|
||||
public class Config
|
||||
@ -27,10 +34,15 @@ public class Config
|
||||
}
|
||||
*/
|
||||
|
||||
static public void startup()
|
||||
static ConfigCfg s_cfg = new ConfigCfg();
|
||||
|
||||
static public void startup( string filename )
|
||||
{
|
||||
res.Mgr.register<Config>( load );
|
||||
res.Mgr.registerSub(typeof(Config));
|
||||
|
||||
s_cfg = Config.load<ConfigCfg>( filename );
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -104,9 +116,20 @@ public class Config
|
||||
Log.error( $"Exception while creating config {t.ToString()}, Msg {e.Message}" );
|
||||
}
|
||||
|
||||
cfg.SetFilename( filename );
|
||||
//cfg.SetFilename( filename );
|
||||
|
||||
Config.save( cfg, filename );
|
||||
if( s_cfg.writeOutTemplateFiles )
|
||||
{
|
||||
var templateFile = $"templates/{filename}";
|
||||
|
||||
var dirName = Path.GetDirectoryName( templateFile );
|
||||
|
||||
lib.Util.checkAndAddDirectory( dirName );
|
||||
|
||||
lib.Log.info( $"Writing out template config of type {t.Name} in {templateFile}" );
|
||||
|
||||
Config.save( cfg, templateFile );
|
||||
}
|
||||
}
|
||||
|
||||
return cfg;
|
||||
|
||||
13
Utilities.cs
13
Utilities.cs
@ -82,6 +82,19 @@ namespace lib
|
||||
#endif
|
||||
*/
|
||||
|
||||
|
||||
|
||||
public static void checkAndAddDirectory( string path )
|
||||
{
|
||||
if( !Directory.Exists( path ) )
|
||||
{
|
||||
lib.Log.info( "Creating directory {0}", path );
|
||||
Directory.CreateDirectory( path );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Compares two block of memory.
|
||||
/// </summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user