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]
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;

View File

@ -42,31 +42,31 @@ namespace lib
public static class Util
{
/*
#if XENKO_PLATFORM_UWP
/*
#if XENKO_PLATFORM_UWP
public static unsafe void CopyMemory(IntPtr dest, IntPtr src, int sizeInBytesToCopy)
{
Interop.memcpy((void*)dest, (void*)src, sizeInBytesToCopy);
}
#else
#if XENKO_PLATFORM_WINDOWS_DESKTOP
#else
#if XENKO_PLATFORM_WINDOWS_DESKTOP
private const string MemcpyDll = "msvcrt.dll";
#elif XENKO_PLATFORM_ANDROID
#elif XENKO_PLATFORM_ANDROID
private const string MemcpyDll = "libc.so";
#elif XENKO_PLATFORM_UNIX
#elif XENKO_PLATFORM_UNIX
// We do not specifiy the .so extension as libc.so on Linux
// is actually not a .so files but a script. Using just libc
// will automatically find the corresponding .so.
private const string MemcpyDll = "libc";
#elif XENKO_PLATFORM_IOS
#elif XENKO_PLATFORM_IOS
private const string MemcpyDll = ObjCRuntime.Constants.SystemLibrary;
#else
# error Unsupported platform
#endif
#else
# error Unsupported platform
#endif
[DllImport(MemcpyDll, EntryPoint = "memcpy", CallingConvention = CallingConvention.Cdecl, SetLastError = false)]
#if !XENKO_RUNTIME_CORECLR
#if !XENKO_RUNTIME_CORECLR
[SuppressUnmanagedCodeSecurity]
#endif
#endif
private static extern IntPtr CopyMemory(IntPtr dest, IntPtr src, ulong sizeInBytesToCopy);
/// <summary>
@ -79,8 +79,21 @@ namespace lib
{
CopyMemory(dest, src, (ulong)sizeInBytesToCopy);
}
#endif
*/
#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.