Added the ability to have app config.

master
Pacman Ghost 8 years ago
parent 7ec71a1760
commit 2edede86f8
  1. 37
      MainApp/AppConfig.cs
  2. 7
      MainApp/MouseDll.cs
  3. 1
      MainApp/MouseInterception.csproj
  4. 8
      MainApp/Program.cs
  5. 4
      MouseDll/api.cpp
  6. 4
      MouseDll/main.cpp
  7. 8
      MouseDll/main.hpp

@ -0,0 +1,37 @@
using System.IO ;
using System.Xml ;
using System.Runtime.InteropServices ;
namespace MouseInterception
{
class AppConfig
{
[StructLayout( LayoutKind.Sequential , CharSet=CharSet.Unicode , Pack=1 )]
public struct Settings
{
}
private Settings mSettings ;
public Settings settings { get { return mSettings ; } }
public AppConfig( string fname )
{
// load the AppConfig
mSettings = new Settings() ;
if ( ! File.Exists( fname ) )
return ;
XmlReaderSettings xmlReaderSettings = new XmlReaderSettings() ;
xmlReaderSettings.IgnoreComments = true ;
xmlReaderSettings.IgnoreProcessingInstructions = true ;
xmlReaderSettings.IgnoreWhitespace = true ;
XmlDocument xmlDoc = new XmlDocument() ;
using ( XmlReader xmlReader = XmlReader.Create( fname , xmlReaderSettings ) )
xmlDoc.Load( xmlReader ) ;
// parse the values
XmlNode configXmlNode = xmlDoc.SelectSingleNode( "/config" ) ;
}
}
}

@ -18,7 +18,7 @@ namespace MouseInterception
[DllImport( @DLL_NAME , CallingConvention=CallingConvention.Cdecl )]
[return: MarshalAs(UnmanagedType.BStr)]
private static extern string reload_config( ref DebugConfig.Settings pDebugSettings ) ;
private static extern string reload_config( ref AppConfig.Settings pAppSettings , ref DebugConfig.Settings pDebugSettings ) ;
public MouseDll( bool initConsole )
{
@ -41,8 +41,9 @@ namespace MouseInterception
public void reloadConfig()
{
// reload the config
DebugConfig.Settings settings = Program.debugConfig.settings ;
string errorMsg = reload_config( ref settings ) ;
AppConfig.Settings appSettings = Program.appConfig.settings ;
DebugConfig.Settings debugSettings = Program.debugConfig.settings ;
string errorMsg = reload_config( ref appSettings , ref debugSettings ) ;
if ( errorMsg != null )
throw new Exception( errorMsg ) ;
}

@ -49,6 +49,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AppConfig.cs" />
<Compile Include="DebugConfig.cs" />
<Compile Include="MainForm.cs">
<SubType>Form</SubType>

@ -8,6 +8,7 @@ namespace MouseInterception
static class Program
{
private static string mBaseDir ;
private static AppConfig mAppConfig ;
private static DebugConfig mDebugConfig ;
[DllImport( "kernel32.dll" )]
@ -23,8 +24,12 @@ namespace MouseInterception
if ( Directory.Exists( baseDir ) )
mBaseDir = baseDir ;
// load the app config
string fname = getAppRelativePath( "config.xml" ) ; // FIXME! this s.b. in the user's AppData folder
mAppConfig = new AppConfig( fname ) ;
// load the debug config
string fname = getAppRelativePath( "debug.xml" ) ; // FIXME! make this configurable
fname = getAppRelativePath( "debug.xml" ) ; // FIXME! make this configurable
mDebugConfig = new DebugConfig( fname ) ;
if ( args.Length > 0 )
@ -53,6 +58,7 @@ namespace MouseInterception
return System.IO.Path.GetFullPath( path );
}
public static AppConfig appConfig { get { return mAppConfig ; } }
public static DebugConfig debugConfig { get { return mDebugConfig ; } }
}

@ -42,12 +42,12 @@ close_api()
// ---------------------------------------------------------------------
extern "C" __declspec(dllexport) BSTR
reload_config( const DebugConfig* pDebugConfig )
reload_config( const AppConfig* pAppConfig , const DebugConfig* pDebugConfig )
{
// reload the config
try
{
reloadConfig( pDebugConfig ) ;
reloadConfig( pAppConfig , pDebugConfig ) ;
return NULL ;
}
catch ( exception& xcptn )

@ -77,9 +77,11 @@ closeApi()
// ---------------------------------------------------------------------
void
reloadConfig( const DebugConfig* pDebugConfig )
reloadConfig( const AppConfig* pAppConfig , const DebugConfig* pDebugConfig )
{
// validate the parameters
if ( pAppConfig == NULL )
throw runtime_error( "Missing AppConfig." ) ;
if ( pDebugConfig == NULL )
throw runtime_error( "Missing DebugConfig." ) ;
const wchar_t* pLogFilename = pDebugConfig->mpLogFilename ;

@ -3,6 +3,12 @@
// ---------------------------------------------------------------------
struct AppConfig
{
} ;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
struct DebugConfig
{
const wchar_t* mpLogFilename ;
@ -13,7 +19,7 @@ struct DebugConfig
extern void openApi( bool initConsole ) ;
extern void closeApi() ;
extern void reloadConfig( const DebugConfig* pDebugConfig ) ;
extern void reloadConfig( const AppConfig* pAppConfig , const DebugConfig* pDebugConfig ) ;
// ---------------------------------------------------------------------

Loading…
Cancel
Save