From c5f35e58d9068d0ba32f6be46874c1ef00f7ed81 Mon Sep 17 00:00:00 2001 From: Marc Hernandez Date: Thu, 4 Jul 2019 07:19:37 -0700 Subject: [PATCH] Write out unfound config files as templates so you can hack around with them later. --- Config.cs | 31 +++++++++++++-- Utilities.cs | 105 +++++++++++++++++++++++++++++---------------------- 2 files changed, 86 insertions(+), 50 deletions(-) diff --git a/Config.cs b/Config.cs index b23997c..bce5613 100644 --- a/Config.cs +++ b/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( load ); res.Mgr.registerSub(typeof(Config)); + + s_cfg = Config.load( 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; } diff --git a/Utilities.cs b/Utilities.cs index 2e3d3d9..09d0248 100644 --- a/Utilities.cs +++ b/Utilities.cs @@ -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); - /// - /// Copy memory. - /// - /// The destination memory location - /// The source memory location. - /// The count. - public static void CopyMemory(IntPtr dest, IntPtr src, int sizeInBytesToCopy) - { - CopyMemory(dest, src, (ulong)sizeInBytesToCopy); - } -#endif -*/ + /// + /// Copy memory. + /// + /// The destination memory location + /// The source memory location. + /// The count. + public static void CopyMemory(IntPtr dest, IntPtr src, int sizeInBytesToCopy) + { + CopyMemory(dest, src, (ulong)sizeInBytesToCopy); + } + #endif + */ - /// - /// Compares two block of memory. - /// - /// The pointer to compare from. - /// The pointer to compare against. - /// The size in bytes to compare. - /// True if the buffers are equivalent, false otherwise. - 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 ); + } + + } + + + /// + /// Compares two block of memory. + /// + /// The pointer to compare from. + /// The pointer to compare against. + /// The size in bytes to compare. + /// True if the buffers are equivalent, false otherwise. + public static unsafe bool CompareMemory(IntPtr from, IntPtr against, int sizeToCompare) { var pSrc = (byte*)from; var pDst = (byte*)against;