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,10 +116,21 @@ 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,54 +42,67 @@ namespace lib
public static class Util
{
/*
#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
private const string MemcpyDll = "msvcrt.dll";
#elif XENKO_PLATFORM_ANDROID
private const string MemcpyDll = "libc.so";
#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
private const string MemcpyDll = ObjCRuntime.Constants.SystemLibrary;
#else
# error Unsupported platform
#endif
[DllImport(MemcpyDll, EntryPoint = "memcpy", CallingConvention = CallingConvention.Cdecl, SetLastError = false)]
#if !XENKO_RUNTIME_CORECLR
[SuppressUnmanagedCodeSecurity]
#endif
private static extern IntPtr CopyMemory(IntPtr dest, IntPtr src, ulong sizeInBytesToCopy);
/*
#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
private const string MemcpyDll = "msvcrt.dll";
#elif XENKO_PLATFORM_ANDROID
private const string MemcpyDll = "libc.so";
#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
private const string MemcpyDll = ObjCRuntime.Constants.SystemLibrary;
#else
# error Unsupported platform
#endif
[DllImport(MemcpyDll, EntryPoint = "memcpy", CallingConvention = CallingConvention.Cdecl, SetLastError = false)]
#if !XENKO_RUNTIME_CORECLR
[SuppressUnmanagedCodeSecurity]
#endif
private static extern IntPtr CopyMemory(IntPtr dest, IntPtr src, ulong sizeInBytesToCopy);
/// <summary>
/// Copy memory.
/// </summary>
/// <param name="dest">The destination memory location</param>
/// <param name="src">The source memory location.</param>
/// <param name="sizeInBytesToCopy">The count.</param>
public static void CopyMemory(IntPtr dest, IntPtr src, int sizeInBytesToCopy)
{
CopyMemory(dest, src, (ulong)sizeInBytesToCopy);
}
#endif
*/
/// <summary>
/// Copy memory.
/// </summary>
/// <param name="dest">The destination memory location</param>
/// <param name="src">The source memory location.</param>
/// <param name="sizeInBytesToCopy">The count.</param>
public static void CopyMemory(IntPtr dest, IntPtr src, int sizeInBytesToCopy)
{
CopyMemory(dest, src, (ulong)sizeInBytesToCopy);
}
#endif
*/
/// <summary>
/// Compares two block of memory.
/// </summary>
/// <param name="from">The pointer to compare from.</param>
/// <param name="against">The pointer to compare against.</param>
/// <param name="sizeToCompare">The size in bytes to compare.</param>
/// <returns>True if the buffers are equivalent, false otherwise.</returns>
public static unsafe bool CompareMemory(IntPtr from, IntPtr against, int sizeToCompare)
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>
/// <param name="from">The pointer to compare from.</param>
/// <param name="against">The pointer to compare against.</param>
/// <param name="sizeToCompare">The size in bytes to compare.</param>
/// <returns>True if the buffers are equivalent, false otherwise.</returns>
public static unsafe bool CompareMemory(IntPtr from, IntPtr against, int sizeToCompare)
{
var pSrc = (byte*)from;
var pDst = (byte*)against;