Write out unfound config files as templates so you can hack around with them later.

This commit is contained in:
Marc Hernandez 2019-07-04 07:19:37 -07:00
parent 1947de8a84
commit c5f35e58d9
2 changed files with 86 additions and 50 deletions

View File

@ -16,6 +16,13 @@ public class DescAttribute : Attribute
} }
} }
[Serializable]
public class ConfigCfg : Config
{
public readonly bool writeOutTemplateFiles = true;
}
[Serializable] [Serializable]
public class Config 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.register<Config>( load );
res.Mgr.registerSub(typeof(Config)); 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}" ); 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; return cfg;

View File

@ -82,6 +82,19 @@ namespace lib
#endif #endif
*/ */
public static void checkAndAddDirectory( string path )
{
if( !Directory.Exists( path ) )
{
lib.Log.info( "Creating directory {0}", path );
Directory.CreateDirectory( path );
}
}
/// <summary> /// <summary>
/// Compares two block of memory. /// Compares two block of memory.
/// </summary> /// </summary>