Write out unfound config files as templates so you can hack around with them later.
This commit is contained in:
parent
1947de8a84
commit
c5f35e58d9
31
Config.cs
31
Config.cs
@ -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,10 +116,21 @@ 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;
|
||||||
}
|
}
|
||||||
|
|||||||
105
Utilities.cs
105
Utilities.cs
@ -42,54 +42,67 @@ namespace lib
|
|||||||
public static class Util
|
public static class Util
|
||||||
{
|
{
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#if XENKO_PLATFORM_UWP
|
#if XENKO_PLATFORM_UWP
|
||||||
public static unsafe void CopyMemory(IntPtr dest, IntPtr src, int sizeInBytesToCopy)
|
public static unsafe void CopyMemory(IntPtr dest, IntPtr src, int sizeInBytesToCopy)
|
||||||
{
|
{
|
||||||
Interop.memcpy((void*)dest, (void*)src, sizeInBytesToCopy);
|
Interop.memcpy((void*)dest, (void*)src, sizeInBytesToCopy);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#if XENKO_PLATFORM_WINDOWS_DESKTOP
|
#if XENKO_PLATFORM_WINDOWS_DESKTOP
|
||||||
private const string MemcpyDll = "msvcrt.dll";
|
private const string MemcpyDll = "msvcrt.dll";
|
||||||
#elif XENKO_PLATFORM_ANDROID
|
#elif XENKO_PLATFORM_ANDROID
|
||||||
private const string MemcpyDll = "libc.so";
|
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
|
// We do not specifiy the .so extension as libc.so on Linux
|
||||||
// is actually not a .so files but a script. Using just libc
|
// is actually not a .so files but a script. Using just libc
|
||||||
// will automatically find the corresponding .so.
|
// will automatically find the corresponding .so.
|
||||||
private const string MemcpyDll = "libc";
|
private const string MemcpyDll = "libc";
|
||||||
#elif XENKO_PLATFORM_IOS
|
#elif XENKO_PLATFORM_IOS
|
||||||
private const string MemcpyDll = ObjCRuntime.Constants.SystemLibrary;
|
private const string MemcpyDll = ObjCRuntime.Constants.SystemLibrary;
|
||||||
#else
|
#else
|
||||||
# error Unsupported platform
|
# error Unsupported platform
|
||||||
#endif
|
#endif
|
||||||
[DllImport(MemcpyDll, EntryPoint = "memcpy", CallingConvention = CallingConvention.Cdecl, SetLastError = false)]
|
[DllImport(MemcpyDll, EntryPoint = "memcpy", CallingConvention = CallingConvention.Cdecl, SetLastError = false)]
|
||||||
#if !XENKO_RUNTIME_CORECLR
|
#if !XENKO_RUNTIME_CORECLR
|
||||||
[SuppressUnmanagedCodeSecurity]
|
[SuppressUnmanagedCodeSecurity]
|
||||||
#endif
|
#endif
|
||||||
private static extern IntPtr CopyMemory(IntPtr dest, IntPtr src, ulong sizeInBytesToCopy);
|
private static extern IntPtr CopyMemory(IntPtr dest, IntPtr src, ulong sizeInBytesToCopy);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Copy memory.
|
/// Copy memory.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dest">The destination memory location</param>
|
/// <param name="dest">The destination memory location</param>
|
||||||
/// <param name="src">The source memory location.</param>
|
/// <param name="src">The source memory location.</param>
|
||||||
/// <param name="sizeInBytesToCopy">The count.</param>
|
/// <param name="sizeInBytesToCopy">The count.</param>
|
||||||
public static void CopyMemory(IntPtr dest, IntPtr src, int sizeInBytesToCopy)
|
public static void CopyMemory(IntPtr dest, IntPtr src, int sizeInBytesToCopy)
|
||||||
{
|
{
|
||||||
CopyMemory(dest, src, (ulong)sizeInBytesToCopy);
|
CopyMemory(dest, src, (ulong)sizeInBytesToCopy);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Compares two block of memory.
|
|
||||||
/// </summary>
|
public static void checkAndAddDirectory( string path )
|
||||||
/// <param name="from">The pointer to compare from.</param>
|
{
|
||||||
/// <param name="against">The pointer to compare against.</param>
|
if( !Directory.Exists( path ) )
|
||||||
/// <param name="sizeToCompare">The size in bytes to compare.</param>
|
{
|
||||||
/// <returns>True if the buffers are equivalent, false otherwise.</returns>
|
lib.Log.info( "Creating directory {0}", path );
|
||||||
public static unsafe bool CompareMemory(IntPtr from, IntPtr against, int sizeToCompare)
|
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 pSrc = (byte*)from;
|
||||||
var pDst = (byte*)against;
|
var pDst = (byte*)against;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user