initial oogynize check in _ this actually used to work!
247
Platform/Env.cs
Normal file
@@ -0,0 +1,247 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace Foo.Platform
|
||||
{
|
||||
/// <summary>
|
||||
/// Oogy Environment Class for getting OS, Application, and Theme Settings
|
||||
/// </summary>
|
||||
public class Env
|
||||
{
|
||||
private static int m_dwMajorVersion = 0;
|
||||
private static int m_dwMinorVersion = 0;
|
||||
private static Themes m_Theme = Themes.Classic;
|
||||
private static AssemblyRunTimePath m_RunTimePath = null;
|
||||
|
||||
/// <summary>
|
||||
/// Public Properties
|
||||
/// </summary>
|
||||
public static int MajorVersion {get{return m_dwMajorVersion;}}
|
||||
public static int MinorVersion {get{return m_dwMinorVersion;}}
|
||||
public static Themes Theme {get{return m_Theme;}}
|
||||
|
||||
/// <summary>
|
||||
/// This is our versioning system, does not correspond to Windows
|
||||
/// </summary>
|
||||
public enum OSVersions : int
|
||||
{
|
||||
OS_WINDOWS_VISTA = 1,
|
||||
OS_WINDOWS_2000 = 2, /*incl. Server OSes*/
|
||||
OS_WINDOWS_2003 = 3, /*incl. Server OSes and Windows XP*/
|
||||
OS_WINDOWS_SE7EN = 7, /*for future use ?*/
|
||||
OS_NOT_SUPPORTED = 99
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This are our Theme Configurations for ButtonHook/GUI components.
|
||||
/// </summary>
|
||||
public enum Themes : int
|
||||
{
|
||||
Classic = 0,
|
||||
XPtheme = 1,
|
||||
AeroTheme = 2,
|
||||
VistaNoAero = 3
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Static Constructor, immediatly sets our environment variables
|
||||
/// </summary>
|
||||
static Env()
|
||||
{
|
||||
ObtainEnvInformation();
|
||||
m_RunTimePath = new AssemblyRunTimePath();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Call this function first - before querying for themes, etc
|
||||
/// </summary>
|
||||
private static void ObtainEnvInformation()
|
||||
{
|
||||
GetSystemInformation(out m_dwMajorVersion, out m_dwMinorVersion);
|
||||
CheckWindowsXPTheme();
|
||||
CheckWindowsVistaTheme();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use to get the Oogy Application path. Creates folder if none exists
|
||||
/// </summary>
|
||||
/// <returns>Path to Ooganizer Application Folder</returns>
|
||||
public static string GetAppdirectory()
|
||||
{
|
||||
string appDataFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData);
|
||||
string oogyAppData = appDataFolder + @"\Ooganizer";
|
||||
|
||||
if (!Directory.Exists(oogyAppData))
|
||||
{
|
||||
// create oogy app data folder
|
||||
Directory.CreateDirectory(oogyAppData);
|
||||
}
|
||||
|
||||
return oogyAppData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use to get the Oogy artifact snapshot image path. Creates folder if none exists
|
||||
/// </summary>
|
||||
/// <returns>Path to Ooganizer artifact snapshot data folder</returns>
|
||||
public static string GetSnapshotDirectory()
|
||||
{
|
||||
string path = Platform.Env.GetAppdirectory() + @"\Snapshots";
|
||||
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
// create snapshot data folder
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use to get the Oogy log path. Creates folder if none exists
|
||||
/// </summary>
|
||||
/// <returns>Path to Ooganizer log folder</returns>
|
||||
public static string GetLogDirectory()
|
||||
{
|
||||
string path = Platform.Env.GetAppdirectory() + @"\Logs";
|
||||
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
// create snapshot data folder
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this to query the current running assembly path
|
||||
/// </summary>
|
||||
/// <returns>Path of assembly location</returns>
|
||||
public static string GetRunTimePath()
|
||||
{
|
||||
return m_RunTimePath.strPath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Quickly Check if the current OS Environment is supported by Oogy
|
||||
/// </summary>
|
||||
/// <returns>true if it is supported, false otherwise</returns>
|
||||
public static bool IsWindowsOSSupported()
|
||||
{
|
||||
OSVersions version = OSVersionCheck();
|
||||
|
||||
if ((version == OSVersions.OS_WINDOWS_2003) ||
|
||||
(version == OSVersions.OS_WINDOWS_VISTA) ||
|
||||
(version == OSVersions.OS_WINDOWS_SE7EN))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves Windows OS specific information
|
||||
/// </summary>
|
||||
/// <param name="dwMajorVersion">dwMajorVersion[out]</param>
|
||||
/// <param name="dwMinorVersion">dwMinorVersion[out]</param>
|
||||
/// <param name="is32bitNT">is32bitNT[out] = supports 32-bit Windows NT</param>
|
||||
/// <returns>true, if succesfully retrieved, false otherwise</returns>
|
||||
private static void GetSystemInformation(out int dwMajorVersion, out int dwMinorVersion)
|
||||
{
|
||||
dwMajorVersion = System.Environment.OSVersion.Version.Major;
|
||||
dwMinorVersion = System.Environment.OSVersion.Version.Minor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this function to obtain the current OS version information
|
||||
/// </summary>
|
||||
/// <returns>Returns the Current OSVersion Enum of this Environment</returns>
|
||||
private static OSVersions OSVersionCheck()
|
||||
{
|
||||
switch(m_dwMajorVersion) // we ignore minor version for now
|
||||
{
|
||||
case 4: // Windows 2000?
|
||||
return (OSVersions.OS_WINDOWS_2000);
|
||||
case 5: // Windows XP && Windows 2003
|
||||
return (OSVersions.OS_WINDOWS_2003);
|
||||
case 6:
|
||||
return (OSVersions.OS_WINDOWS_VISTA);
|
||||
case 7:
|
||||
return (OSVersions.OS_WINDOWS_SE7EN);
|
||||
default:
|
||||
return (OSVersions.OS_NOT_SUPPORTED);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Vista Specific Theme Checking is done here
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static void CheckWindowsVistaTheme()
|
||||
{
|
||||
if(OSVersionCheck() == OSVersions.OS_WINDOWS_VISTA)
|
||||
{
|
||||
bool bIsAero = false;
|
||||
if(Win32.Win32Functions.DwmIsCompositionEnabled(ref bIsAero) < 0)
|
||||
return; //Call Failed
|
||||
|
||||
if (bIsAero)
|
||||
m_Theme = Themes.AeroTheme;
|
||||
else
|
||||
m_Theme = Themes.VistaNoAero;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// XP Specific Theme Checking is done here
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static void CheckWindowsXPTheme()
|
||||
{
|
||||
if (OSVersionCheck() == OSVersions.OS_WINDOWS_2003)
|
||||
{
|
||||
if (Win32.Win32Functions.IsAppThemed())
|
||||
m_Theme = Themes.XPtheme;
|
||||
else
|
||||
m_Theme = Themes.Classic;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Since we only can query the Assembly path by instantiation,
|
||||
/// we have a class that handles it
|
||||
/// </summary>
|
||||
internal class AssemblyRunTimePath
|
||||
{
|
||||
public string strPath;
|
||||
public AssemblyRunTimePath(){strPath = Path.GetDirectoryName(GetType().Assembly.Location);}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// EnvironmentCCW is a wrapper around Env - specifically made to be non-static
|
||||
/// as to be able to be called from COM (ButtonHook/C++ code can now use Environment as well
|
||||
/// </summary>
|
||||
[Guid("85E2E5F6-877F-4edd-B7D1-D52C431F0AFC")]
|
||||
[ClassInterface(ClassInterfaceType.AutoDual)]
|
||||
[ComVisible(true)]
|
||||
public class EnvironmentCCW
|
||||
{
|
||||
public bool IsWindowsOSSupported()
|
||||
{
|
||||
return Env.IsWindowsOSSupported();
|
||||
}
|
||||
public int GetCurWindowsTheme()
|
||||
{
|
||||
return (int)Env.Theme;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
24
Platform/ErrorReporting/UserError.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Foo.Platform.ErrorReporting
|
||||
{
|
||||
public class UserError
|
||||
{
|
||||
/// <summary>
|
||||
/// Display an Error to the User
|
||||
/// </summary>
|
||||
/// <param name="title">Error Title</param>
|
||||
/// <param name="detail">Any Details about the Error that maybe pertinent to the User</param>
|
||||
public static void Show(string title, string detail)
|
||||
{
|
||||
string strTitle = "Error - " + title;
|
||||
string strDetail = detail + "\n\n\nContact Ooganizer Support at http://ooganizer.com/support for more help and information.";
|
||||
|
||||
MessageBox.Show(strDetail,strTitle);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
201
Platform/InstallationSpec.cs
Normal file
@@ -0,0 +1,201 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Microsoft.Win32;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Foo.Platform
|
||||
{
|
||||
/// <summary>
|
||||
/// Installation Specific Settings. "HKLM\Software\Ooganizer",
|
||||
/// The Installer must put the correct values in there so that we know where our files
|
||||
/// are. ~Since now some of our assemblies are in the GAC, we require this.
|
||||
/// </summary>
|
||||
public class InstallationSpec
|
||||
{
|
||||
// Declare the Log4net Variable
|
||||
private static log4net.ILog Log = Logger.GetLog4NetInterface(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
/// <summary>
|
||||
/// private statics
|
||||
/// </summary>
|
||||
private static string m_strInstallPath = "";
|
||||
//private static string m_strPlatformPath = "";
|
||||
//private static string m_strServerPath = "";
|
||||
//private static string m_strLogPath = "";
|
||||
private static RegistryKey s_OogyRootKey;
|
||||
|
||||
/// <summary>
|
||||
/// Public Properties
|
||||
/// </summary>
|
||||
public static string InstallPath { get { return m_strInstallPath; } }
|
||||
//public static string PlatformPath { get { return m_strPlatformPath; } }
|
||||
//public static string ServerPath { get { return m_strServerPath; } }
|
||||
//public static string LogPath { get { return m_strLogPath; } }
|
||||
|
||||
/// <summary>
|
||||
/// Static Constructor, immediatly gets our installation specific variables
|
||||
/// </summary>
|
||||
static InstallationSpec()
|
||||
{
|
||||
s_OogyRootKey = Registry.LocalMachine.OpenSubKey("Software\\Ooganizer",false);
|
||||
if (s_OogyRootKey != null)
|
||||
{
|
||||
object keyvalue = null;
|
||||
|
||||
keyvalue = s_OogyRootKey.GetValue("InstallPath");
|
||||
if (isValidStr(keyvalue))
|
||||
m_strInstallPath = keyvalue.ToString();
|
||||
|
||||
//keyvalue = s_OogyRootKey.GetValue("PlatformPath");
|
||||
//if (isValidStr(keyvalue))
|
||||
// m_strPlatformPath = keyvalue.ToString();
|
||||
|
||||
//keyvalue = s_OogyRootKey.GetValue("ServerPath");
|
||||
//if (isValidStr(keyvalue))
|
||||
// m_strServerPath = keyvalue.ToString();
|
||||
|
||||
//keyvalue = s_OogyRootKey.GetValue("LogPath");
|
||||
//if (isValidStr(keyvalue))
|
||||
// m_strLogPath = keyvalue.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error(string.Format("{0}() - Couldn't Open Software\\Ooganizer Registry Key for Reading", MethodBase.GetCurrentMethod().Name));
|
||||
}
|
||||
}
|
||||
|
||||
/// <returns>Returns true if passed in object is valid and not ""</returns>
|
||||
private static bool isValidStr(object oToValidate)
|
||||
{
|
||||
if ((oToValidate != null) && (oToValidate.ToString() != ""))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this class for Debug Specific Settings
|
||||
/// </summary>
|
||||
public class DebugSpec
|
||||
{
|
||||
public static bool SkipCaptionButtonStarter { get; private set; }
|
||||
|
||||
private static RegistryKey s_DebugSpecRootKey;
|
||||
|
||||
static DebugSpec()
|
||||
{
|
||||
SkipCaptionButtonStarter = false;
|
||||
|
||||
#if DEBUG
|
||||
s_DebugSpecRootKey = Registry.LocalMachine.CreateSubKey("Software\\Ooganizer\\DebugSpec", RegistryKeyPermissionCheck.ReadWriteSubTree);
|
||||
SkipCaptionButtonStarter = GetValB("SkipCaptionButtonStarter");
|
||||
#endif
|
||||
}
|
||||
|
||||
private static bool GetValB(string strValKey)
|
||||
{
|
||||
try
|
||||
{
|
||||
string val = GetVal(strValKey);
|
||||
if (!String.IsNullOrEmpty(val))
|
||||
{
|
||||
bool bVal = Boolean.Parse(val);
|
||||
return bVal;
|
||||
}
|
||||
}
|
||||
catch (Exception) { /* ignore */ }
|
||||
return false;
|
||||
}
|
||||
|
||||
private static string GetVal(string strValKey)
|
||||
{
|
||||
try
|
||||
{
|
||||
object keyvalue = null;
|
||||
keyvalue = s_DebugSpecRootKey.GetValue(strValKey);
|
||||
if (isValidStr(keyvalue))
|
||||
return keyvalue.ToString();
|
||||
}
|
||||
catch (Exception) { }
|
||||
return String.Empty;
|
||||
}
|
||||
|
||||
/// <returns>Returns true if passed in object is valid and not ""</returns>
|
||||
private static bool isValidStr(object oToValidate)
|
||||
{
|
||||
if ((oToValidate != null) && (oToValidate.ToString() != ""))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Temporary Values / "HKLM\Software\Ooganizer\TemporaryVal",
|
||||
/// This class is being used to temporarily store values in the registry and retrieve them.
|
||||
/// Useful for quick and dirty inter process communication. works out well for certain things.
|
||||
/// </summary>
|
||||
public class TemporaryVal
|
||||
{
|
||||
private static RegistryKey s_OogyRootKey;
|
||||
|
||||
static TemporaryVal()
|
||||
{
|
||||
s_OogyRootKey = Registry.LocalMachine.OpenSubKey("Software\\Ooganizer", true);
|
||||
}
|
||||
|
||||
public static void SetVal(string strValue)
|
||||
{
|
||||
try { s_OogyRootKey.SetValue("TemporaryVal", strValue); }
|
||||
catch (Exception) { }
|
||||
}
|
||||
|
||||
public static void SetValI(int iValue)
|
||||
{
|
||||
try{ SetVal(iValue.ToString()); }
|
||||
catch (Exception){}
|
||||
}
|
||||
|
||||
public static string GetVal()
|
||||
{
|
||||
try
|
||||
{
|
||||
object keyvalue = null;
|
||||
keyvalue = s_OogyRootKey.GetValue("TemporaryVal");
|
||||
if (isValidStr(keyvalue))
|
||||
return keyvalue.ToString();
|
||||
}
|
||||
catch (Exception) { }
|
||||
return String.Empty;
|
||||
}
|
||||
|
||||
public static int GetValI()
|
||||
{
|
||||
int I = 0;
|
||||
try
|
||||
{
|
||||
string strVal = GetVal();
|
||||
I = int.Parse(strVal);
|
||||
}
|
||||
catch (Exception) { }
|
||||
return I;
|
||||
}
|
||||
|
||||
public static void DeleteVal()
|
||||
{
|
||||
try { s_OogyRootKey.DeleteValue("TemporaryVal"); }
|
||||
catch (Exception) { }
|
||||
}
|
||||
|
||||
/// <returns>Returns true if passed in object is valid and not ""</returns>
|
||||
private static bool isValidStr(object oToValidate)
|
||||
{
|
||||
if ((oToValidate != null) && (oToValidate.ToString() != ""))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
489
Platform/Interacters/BHInteracter.cs
Normal file
@@ -0,0 +1,489 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
|
||||
namespace Foo.Platform.Interacters
|
||||
{
|
||||
/// <summary>
|
||||
/// BHInteracter - ButtonHook Interacter.
|
||||
/// Use this class abstraction to send/communicate with ButtonHook.
|
||||
/// </summary>
|
||||
public class BHInteracter
|
||||
{
|
||||
////
|
||||
// Our ButtonHook.Dll Entry Points (Delegates)
|
||||
////
|
||||
internal delegate bool MyStartButtonHook();
|
||||
internal static MyStartButtonHook _MyStartButtonHook = null;
|
||||
|
||||
internal delegate bool MyStopButtonHook();
|
||||
internal static MyStopButtonHook _MyStopButtonHook = null;
|
||||
|
||||
internal delegate bool MyIsButtonHookSet();
|
||||
internal static MyIsButtonHookSet _MyIsButtonHookSet = null;
|
||||
|
||||
internal delegate int MyGetAllHookedWindowHandles(IntPtr pBuf);
|
||||
internal static MyGetAllHookedWindowHandles _MyGetAllHookedWindowHandles = null;
|
||||
|
||||
/// <summary>
|
||||
/// Use this to send down to Buttonhook so that it knows what to show
|
||||
/// </summary>
|
||||
public enum BUTTON_HOOK_STATE
|
||||
{
|
||||
BUTTON_NONE = 1,
|
||||
BUTTON_ADD = 2,
|
||||
BUTTON_DELETE = 3
|
||||
}
|
||||
|
||||
// Declare the Log4net Variable
|
||||
private static log4net.ILog Log = Logger.GetLog4NetInterface(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
////
|
||||
// Custom ButtonHook Message Handlers
|
||||
////
|
||||
private const int WM_W32PINGISALIVE = (Platform.Win32.Win32_Constants.WM_USER + 700);
|
||||
private const int WM_W32SETBUTTONSTATE = (Platform.Win32.Win32_Constants.WM_USER + 701);
|
||||
private const int WM_W32GETBUTTONSTATE = (Platform.Win32.Win32_Constants.WM_USER + 702);
|
||||
private const int WM_W32SETPARENTWINDOWTRANSPERANCY = (Platform.Win32.Win32_Constants.WM_USER + 703);
|
||||
private const int WM_W32SETPARENTWINDOWACTIVE = (Platform.Win32.Win32_Constants.WM_USER + 704);
|
||||
private const int WM_W32POSTMESSAGETOPARENTWINDOW = (Platform.Win32.Win32_Constants.WM_USER + 705);
|
||||
|
||||
////
|
||||
// Custom OogyCaptionButton Message Handlers
|
||||
////
|
||||
public const int WM_CAPTIONBUTTON_START = (Platform.Win32.Win32_Constants.WM_USER + 1200);
|
||||
public const int WM_CAPTIONBUTTON_STOP = (Platform.Win32.Win32_Constants.WM_USER + 1201);
|
||||
|
||||
////
|
||||
// OogyCaptionButton Spec
|
||||
////
|
||||
private const int CAPTION_START_STOP_MAX_TRY_COUNT = 5;
|
||||
public const string CAPTIONBUTTON_CMDLINE = @"/App:StartThis4Real639";
|
||||
private const string CAPTIONBUTTON_PROCESSNAME = "CaptionButton";
|
||||
private static string CAPTIONBUTTON_EXE = CAPTIONBUTTON_PROCESSNAME + ".exe";
|
||||
private static string CAPTIONBUTTON_EXE_FULLPATH = InstallationSpec.InstallPath + CAPTIONBUTTON_EXE;
|
||||
private static IntPtr s_CaptionButtonHandle = IntPtr.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// Validity internal State checking for OogyCaptionButton.exe
|
||||
/// </summary>
|
||||
private enum CAPTIONBUTTON_VALIDITY_STATE
|
||||
{
|
||||
VALIDITY_NONE = 1,
|
||||
VALIDITY_CREATEDSUCCESS = 2,
|
||||
VALIDITY_CREATEDFAILED = 3,
|
||||
VALIDITY_STOPPEDSUCCESS = 4,
|
||||
VALIDITY_STOPPEDFAILED = 5,
|
||||
VALIDITY_INTEGRITYCHECK_FAILED = 6
|
||||
}
|
||||
|
||||
// State Success / Error Checking
|
||||
private static CAPTIONBUTTON_VALIDITY_STATE s_CaptionButtonState = CAPTIONBUTTON_VALIDITY_STATE.VALIDITY_NONE;
|
||||
|
||||
/// <summary>
|
||||
/// Static Constructor Loads the ButtonHook.dll dynamically from the correct path
|
||||
/// </summary>
|
||||
static BHInteracter()
|
||||
{
|
||||
try
|
||||
{
|
||||
IntPtr procaddr = IntPtr.Zero;
|
||||
string strButtonHookDll = InstallationSpec.InstallPath + "ButtonHook.dll";
|
||||
|
||||
Log.Info(string.Format("{0}() - BHInteracter() Trying to load ButtonHook.dll {1}", MethodBase.GetCurrentMethod().Name, strButtonHookDll));
|
||||
IntPtr ButtonHook = Win32.Win32Functions.LoadLibrary(strButtonHookDll);
|
||||
if(ButtonHook != IntPtr.Zero)
|
||||
Log.Info(string.Format("{0}() - BHInteracter() loading ButtonHook.dll succeeded", MethodBase.GetCurrentMethod().Name));
|
||||
else
|
||||
Log.Error(string.Format("{0}() - BHInteracter() loading ButtonHook.dll failed!", MethodBase.GetCurrentMethod().Name));
|
||||
|
||||
// StartButtonHook
|
||||
procaddr = Win32.Win32Functions.GetProcAddress(ButtonHook, "_StartButtonHook@0");
|
||||
if(procaddr != null)
|
||||
_MyStartButtonHook = (MyStartButtonHook)Marshal.GetDelegateForFunctionPointer(procaddr, typeof(MyStartButtonHook));
|
||||
else
|
||||
Log.Info(string.Format("{0}() - BHInteracter() GetProcAddress for StartButtonHook Failed", MethodBase.GetCurrentMethod().Name));
|
||||
|
||||
// StopButtonHook
|
||||
procaddr = Win32.Win32Functions.GetProcAddress(ButtonHook, "_StopButtonHook@0");
|
||||
if (procaddr != null)
|
||||
_MyStopButtonHook = (MyStopButtonHook)Marshal.GetDelegateForFunctionPointer(procaddr, typeof(MyStopButtonHook));
|
||||
else
|
||||
Log.Info(string.Format("{0}() - BHInteracter() GetProcAddress for StopButtonHook Failed", MethodBase.GetCurrentMethod().Name));
|
||||
|
||||
// IsButtonHookSet
|
||||
procaddr = Win32.Win32Functions.GetProcAddress(ButtonHook, "_IsButtonHookSet@0");
|
||||
if (procaddr != null)
|
||||
_MyIsButtonHookSet = (MyIsButtonHookSet)Marshal.GetDelegateForFunctionPointer(procaddr, typeof(MyIsButtonHookSet));
|
||||
else
|
||||
Log.Info(string.Format("{0}() - BHInteracter() GetProcAddress for IsButtonHookSet Failed", MethodBase.GetCurrentMethod().Name));
|
||||
|
||||
// GetAllHookedWindowHandles
|
||||
procaddr = Win32.Win32Functions.GetProcAddress(ButtonHook, "_GetAllHookedWindowHandles@4");
|
||||
if (procaddr != null)
|
||||
_MyGetAllHookedWindowHandles = (MyGetAllHookedWindowHandles)Marshal.GetDelegateForFunctionPointer(procaddr, typeof(MyGetAllHookedWindowHandles));
|
||||
else
|
||||
Log.Info(string.Format("{0}() - BHInteracter() GetProcAddress for GetAllHookedWindowHandles Failed", MethodBase.GetCurrentMethod().Name));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(string.Format("{0}() - BHInteracter() Construction Failed", MethodBase.GetCurrentMethod().Name), e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this function wrapper to call the StartButtonHook DLLEntry Point
|
||||
/// </summary>
|
||||
public static void StartButtonHookDLLEntryW()
|
||||
{
|
||||
Log.Info(string.Format("{0}() - CaptionButton - About to call StartButtonHook()", MethodBase.GetCurrentMethod().Name));
|
||||
if (_MyStartButtonHook())
|
||||
Log.Info(string.Format("{0}() - StartButtonHook() Succeeded", MethodBase.GetCurrentMethod().Name));
|
||||
else
|
||||
Log.Error(string.Format("{0}() - StartButtonHook() Failed", MethodBase.GetCurrentMethod().Name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this function wrapper to call the StopButtonHook DLLEntry Point
|
||||
/// </summary>
|
||||
public static void StopButtonHookDLLEntryW()
|
||||
{
|
||||
Log.Info(string.Format("{0}() - CaptionButton - About to call StopButtonHook()", MethodBase.GetCurrentMethod().Name));
|
||||
if (_MyStopButtonHook())
|
||||
Log.Info(string.Format("{0}() - StopButtonHook() Succeeded", MethodBase.GetCurrentMethod().Name));
|
||||
else
|
||||
Log.Error(string.Format("{0}() - StopButtonHook() Failed", MethodBase.GetCurrentMethod().Name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this function wrapper to call the IsButtonHookSet DLLEntry Point
|
||||
/// </summary>
|
||||
public static bool IsButtonHookSetDLLEntryW()
|
||||
{
|
||||
return _MyIsButtonHookSet();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this function wrapper to call the GetAllHookedWindowHandles DLLEntry Point
|
||||
/// </summary>
|
||||
public static void GetAllHookedWindowHandlesDLLEntryW(ref List<IntPtr> handleList)
|
||||
{
|
||||
// Temporary ar buffer
|
||||
int[] ar = new int[Win32.Win32_Constants.MAX_PATH];
|
||||
|
||||
// allocate and reset an new unmanaged buffer
|
||||
IntPtr p = Marshal.AllocHGlobal(Marshal.SizeOf(ar));
|
||||
Marshal.Copy(ar, 0, p, ar.Length);
|
||||
|
||||
// get the size
|
||||
int nsize = _MyGetAllHookedWindowHandles(p);
|
||||
|
||||
// copy data back as needed *delete unmanaged buffer*
|
||||
Marshal.Copy(p,ar,0,nsize);
|
||||
Marshal.FreeHGlobal(p);
|
||||
|
||||
// Make sure the passed in list is empty * and pass out the handle list*
|
||||
handleList.Clear();
|
||||
for (int i = 0; i < nsize; ++i)
|
||||
handleList.Add((IntPtr)ar[i]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// CaptionButton exe is the external process that hosts ButtonHook.dll
|
||||
/// </summary>
|
||||
/// <returns>true if the CaptionButtion exe is running, false otherwise</returns>
|
||||
public static bool IsCaptionButtonRunning()
|
||||
{
|
||||
Process[] processes = Process.GetProcessesByName(CAPTIONBUTTON_PROCESSNAME);
|
||||
return (processes.Length == 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start CaptionButton exe which can host the ButtonHook.dll
|
||||
/// </summary>
|
||||
public static void StartCaptionButton()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!IsCaptionButtonRunning())
|
||||
{
|
||||
TemporaryVal.DeleteVal();
|
||||
ProcessStartInfo startInfo = new ProcessStartInfo(CAPTIONBUTTON_EXE_FULLPATH, CAPTIONBUTTON_CMDLINE);
|
||||
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
||||
startInfo.WorkingDirectory = InstallationSpec.InstallPath;
|
||||
Process p = Process.Start(startInfo);
|
||||
Log.Info(string.Format("{0}() - Created a new Oogy CaptionButton Instance EXE with PID{1}", MethodBase.GetCurrentMethod().Name, p.Id.ToString()));
|
||||
|
||||
// Wait a little before sending any messages
|
||||
Thread.Sleep(3000);
|
||||
|
||||
////
|
||||
// State Checking *IMP* .exe could have not shut down correctly, and buttonhook never got stopped
|
||||
// so let's check to see what is going on
|
||||
////
|
||||
bool bIsInvalidState = ((s_CaptionButtonState != CAPTIONBUTTON_VALIDITY_STATE.VALIDITY_NONE) &&
|
||||
(s_CaptionButtonState != CAPTIONBUTTON_VALIDITY_STATE.VALIDITY_STOPPEDSUCCESS));
|
||||
|
||||
// Let's get the window handle from the child process
|
||||
s_CaptionButtonHandle = (IntPtr)TemporaryVal.GetValI();
|
||||
if (s_CaptionButtonHandle == IntPtr.Zero)
|
||||
Log.Error(string.Format("{0}() - Child Handle is Zero! This means all functions below will return out and everything fails. Check into this.", MethodBase.GetCurrentMethod().Name));
|
||||
|
||||
TemporaryVal.DeleteVal();
|
||||
|
||||
// We somehow got into an invalid state, so let's send Stop Messages and see what happens,
|
||||
// if those failed there is really not much more we can do except fail here
|
||||
if (bIsInvalidState && !Helper_CaptionButtonMessageSender(s_CaptionButtonHandle, WM_CAPTIONBUTTON_STOP))
|
||||
Log.Info(string.Format("{0}() - Trying to StopButtonHook gracefully failed - ignoring and trying to StartButtonHook Anyways", MethodBase.GetCurrentMethod().Name, p.Id.ToString()));
|
||||
|
||||
// Regular starting...
|
||||
if (Helper_CaptionButtonMessageSender(s_CaptionButtonHandle, WM_CAPTIONBUTTON_START))
|
||||
{
|
||||
s_CaptionButtonState = CAPTIONBUTTON_VALIDITY_STATE.VALIDITY_CREATEDSUCCESS;
|
||||
Log.Info(string.Format("{0}() - StartCaptionButton Succeeded - Started the ButtonHook Worked Successfully", MethodBase.GetCurrentMethod().Name, p.Id.ToString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
s_CaptionButtonState = CAPTIONBUTTON_VALIDITY_STATE.VALIDITY_CREATEDFAILED;
|
||||
Log.Error(string.Format("{0}() - StartCaptionButton Failed - Started the ButtonHook Did not work - VALIDITY_CREATEDFAILED - forcefully Killing the Process", MethodBase.GetCurrentMethod().Name, p.Id.ToString()));
|
||||
p.Kill();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Process is already running for some reason - this should never happen, but if it does,
|
||||
// we'll handle it by doing an integrity check
|
||||
Log.Info(string.Format("{0}() - StartCaptionButton - CaptionButton.exe already exists - performing Complete Integrity Check...", MethodBase.GetCurrentMethod().Name));
|
||||
bool bIntegrityIsGood = CompleteButtonHookIntegrityCheck();
|
||||
|
||||
if (bIntegrityIsGood)
|
||||
s_CaptionButtonState = CAPTIONBUTTON_VALIDITY_STATE.VALIDITY_CREATEDSUCCESS;
|
||||
else
|
||||
s_CaptionButtonState = CAPTIONBUTTON_VALIDITY_STATE.VALIDITY_INTEGRITYCHECK_FAILED;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(string.Format("{0}() - StartCaptionButton - Error occured", MethodBase.GetCurrentMethod().Name), e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stop CaptionButton exe which can host the ButtonHook.dll
|
||||
/// </summary>
|
||||
public static void StopCaptionButton()
|
||||
{
|
||||
Log.Info(string.Format("{0}() - StopCaptionButton Called", MethodBase.GetCurrentMethod().Name));
|
||||
if (IsCaptionButtonRunning())
|
||||
{
|
||||
Process[] processes = Process.GetProcessesByName(CAPTIONBUTTON_PROCESSNAME);
|
||||
foreach (Process p in processes)
|
||||
{
|
||||
Log.Info(string.Format("{0}() - Found OogyCaptionButton Pid {1}", MethodBase.GetCurrentMethod().Name, p.Id));
|
||||
|
||||
if (Helper_CaptionButtonMessageSender(s_CaptionButtonHandle, WM_CAPTIONBUTTON_STOP))
|
||||
{
|
||||
s_CaptionButtonState = CAPTIONBUTTON_VALIDITY_STATE.VALIDITY_STOPPEDSUCCESS;
|
||||
Log.Info(string.Format("{0}() - StopCaptionButton Succeeded - Closing the ButtonHook Worked Successfully", MethodBase.GetCurrentMethod().Name, p.Id.ToString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
s_CaptionButtonState = CAPTIONBUTTON_VALIDITY_STATE.VALIDITY_STOPPEDFAILED;
|
||||
Log.Error(string.Format("{0}() - StopCaptionButton Failed - Closing the ButtonHook Did not work - forcefully Killing the Process", MethodBase.GetCurrentMethod().Name, p.Id.ToString()));
|
||||
}
|
||||
|
||||
Log.Info(string.Format("{0}() - Closing a Oogy CaptionButton Instance EXE of PID{1}", MethodBase.GetCurrentMethod().Name, p.Id.ToString()));
|
||||
p.Kill();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this to send the Start/Stop Messages to Oogy CaptionButton.exe. Small Helper
|
||||
/// function allows us to do cleaner error handling for starting and stopping (above)
|
||||
/// </summary>
|
||||
/// <param name="Message">WM_CAPTIONBUTTON_START or WM_CAPTIONBUTTON_STOP</param>
|
||||
/// <returns>returns true if successful, false otherwise</returns>
|
||||
private static bool Helper_CaptionButtonMessageSender(IntPtr hWnd, int Message)
|
||||
{
|
||||
if((hWnd != IntPtr.Zero) &&
|
||||
(Message == WM_CAPTIONBUTTON_START || Message == WM_CAPTIONBUTTON_STOP))
|
||||
{
|
||||
for (int i = 0; i < CAPTION_START_STOP_MAX_TRY_COUNT; ++i)
|
||||
{
|
||||
// Send the Stop ButonHook Message to the Hidden window of the Process
|
||||
Win32.Win32Functions.SendMessage(hWnd, Message, IntPtr.Zero, IntPtr.Zero);
|
||||
|
||||
// Wait a little second before querying for the state
|
||||
Thread.Sleep(500);
|
||||
|
||||
// If this is a start message we can stop once the button hook is started
|
||||
if (Message == WM_CAPTIONBUTTON_START &&
|
||||
IsButtonHookSetDLLEntryW())
|
||||
return true;
|
||||
|
||||
// If this is a stop message we can stop once the button hook no longer set
|
||||
if (Message == WM_CAPTIONBUTTON_STOP &&
|
||||
!IsButtonHookSetDLLEntryW())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check to see if buttonhook is alive for the passed in window
|
||||
/// </summary>
|
||||
/// <param name="hWnd">handle to a buttonHooked Parent Window</param>
|
||||
public static bool IsButtonHookAliveOnWindow(IntPtr hWnd)
|
||||
{
|
||||
if (hWnd != IntPtr.Zero)
|
||||
{
|
||||
int retVal = Win32.Win32Functions.SendMessage((IntPtr)hWnd, WM_W32PINGISALIVE, IntPtr.Zero, IntPtr.Zero);
|
||||
if (retVal == 0)
|
||||
{
|
||||
Log.Error(string.Format("{0}() - IsButtonHookAlive Failed for Window {1}", MethodBase.GetCurrentMethod().Name, hWnd.ToString()));
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Call this function to run a complete ButtonHook Integrity Check
|
||||
/// </summary>
|
||||
/// <returns>true if buttonhook passed all checks, false otherwise</returns>
|
||||
public static bool CompleteButtonHookIntegrityCheck()
|
||||
{
|
||||
bool bSuccess = true;
|
||||
Log.Info(string.Format("{0}() - CompleteButtonHookIntegrityCheck got called", MethodBase.GetCurrentMethod().Name));
|
||||
|
||||
// Make first sure that the Hook Is Set
|
||||
if (!IsButtonHookSetDLLEntryW())
|
||||
bSuccess = false;
|
||||
|
||||
// Now iterate through each hooked window pinging it
|
||||
// for feedback
|
||||
List<IntPtr> handleList = new List<IntPtr>();
|
||||
foreach (IntPtr hWnd in handleList)
|
||||
{
|
||||
if (!IsButtonHookAliveOnWindow(hWnd) && Win32.Win32Functions.IsWindow(hWnd))
|
||||
{
|
||||
bSuccess = false; // buttonhook not responsive on an existing window
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(bSuccess)
|
||||
Log.Info(string.Format("{0}() - CompleteButtonHookIntegrityCheck passed successfully", MethodBase.GetCurrentMethod().Name));
|
||||
else
|
||||
Log.Error(string.Format("{0}() - CompleteButtonHookIntegrityCheck failed", MethodBase.GetCurrentMethod().Name));
|
||||
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this to set the Transparency on a Window that is running the ButtonHook. ~Will Only work
|
||||
/// for those windows.
|
||||
/// </summary>
|
||||
/// <param name="hWnd">handle to a buttonHooked Parent Window</param>
|
||||
/// <param name="alpha">0-255 byte value indicating the Transparency</param>
|
||||
public static void SetWindowTransparency(IntPtr hWnd, byte alpha)
|
||||
{
|
||||
if (hWnd != IntPtr.Zero)
|
||||
{
|
||||
int retVal = Win32.Win32Functions.SendMessage((IntPtr)hWnd, WM_W32SETPARENTWINDOWTRANSPERANCY, IntPtr.Zero, (IntPtr)alpha);
|
||||
if (retVal == 0)
|
||||
Log.Error(string.Format("{0}() - SetWindowTransparency Failed for Window {1} with alpha {2}", MethodBase.GetCurrentMethod().Name, hWnd.ToString(), alpha.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this to set the ActiveWindow on a Window that is running the ButtonHook. ~Will Only work
|
||||
/// for those windows.
|
||||
/// </summary>
|
||||
/// <param name="hWnd">handle to a buttonHooked Parent Window</param>
|
||||
public static void SetAsActiveWindow(IntPtr hWnd)
|
||||
{
|
||||
if (hWnd != IntPtr.Zero)
|
||||
{
|
||||
int retVal = Win32.Win32Functions.SendMessage((IntPtr)hWnd, WM_W32SETPARENTWINDOWACTIVE, IntPtr.Zero, IntPtr.Zero);
|
||||
if (retVal == 0)
|
||||
Log.Error(string.Format("{0}() - SetAsActiveWindow Failed for Window {1}", MethodBase.GetCurrentMethod().Name, hWnd.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this to send a message to a window to send a message to itself
|
||||
/// </summary>
|
||||
/// <param name="hWnd"></param>
|
||||
public static void PostMessageAsIfFromWindow(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam )
|
||||
{
|
||||
if (hWnd != IntPtr.Zero)
|
||||
{
|
||||
StringBuilder strAtom = new StringBuilder(hWnd.ToString() + ";" + Msg.ToString() + ";" + wParam.ToString() + ";" + lParam.ToString());
|
||||
int nAtom = Win32.Win32Functions.GlobalAddAtom(strAtom);
|
||||
|
||||
if (nAtom == 0)
|
||||
Log.Error(string.Format("{0}() - SendMessageAsIfFromWindow GlobalAddAtom Failed for Window {1}", MethodBase.GetCurrentMethod().Name, hWnd.ToString()));
|
||||
|
||||
int retVal = Win32.Win32Functions.SendMessage((IntPtr)hWnd, WM_W32POSTMESSAGETOPARENTWINDOW, IntPtr.Zero, (IntPtr)nAtom);
|
||||
if (retVal == 0)
|
||||
Log.Error(string.Format("{0}() - SendMessageAsIfFromWindow ButtonHook Failed to process the String for Window {1}", MethodBase.GetCurrentMethod().Name, hWnd.ToString()));
|
||||
|
||||
Win32.Win32Functions.GlobalDeleteAtom(nAtom);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this to set a new ButtonState to a buttonhooked window
|
||||
/// </summary>
|
||||
/// <param name="hWnd">handle to a buttonHooked Parent Window</param>
|
||||
/// <param name="buttonState">a new button state</param>
|
||||
public static BUTTON_HOOK_STATE SetW32ButtonToNewState(IntPtr hWnd, BUTTON_HOOK_STATE buttonState)
|
||||
{
|
||||
if (hWnd != IntPtr.Zero)
|
||||
{
|
||||
int retVal = Platform.Win32.Win32Functions.SendMessage((IntPtr)hWnd, WM_W32SETBUTTONSTATE, IntPtr.Zero, (IntPtr)buttonState);
|
||||
if (retVal == 0)
|
||||
Log.Error(string.Format("{0}() - SetW32ButtonToNewState Failed for Window {1} ", MethodBase.GetCurrentMethod().Name, hWnd.ToString()));
|
||||
}
|
||||
return buttonState;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this to get a ButtonState from a buttonhooked window
|
||||
/// </summary>
|
||||
/// <param name="hWnd">handle to a buttonHooked Parent Window</param>
|
||||
/// <param name="buttonState">a new button state</param>
|
||||
public static BUTTON_HOOK_STATE GetW32ButtonState(IntPtr hWnd)
|
||||
{
|
||||
BUTTON_HOOK_STATE buttonState = BUTTON_HOOK_STATE.BUTTON_NONE;
|
||||
if (hWnd != IntPtr.Zero)
|
||||
{
|
||||
int retVal = Platform.Win32.Win32Functions.SendMessage((IntPtr)hWnd, WM_W32GETBUTTONSTATE, IntPtr.Zero, IntPtr.Zero);
|
||||
if (retVal == 0)
|
||||
Log.Error(string.Format("{0}() - SetW32ButtonToNewState Failed for Window {1} ", MethodBase.GetCurrentMethod().Name, hWnd.ToString()));
|
||||
|
||||
try
|
||||
{
|
||||
buttonState = (BUTTON_HOOK_STATE)retVal;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(string.Format("{0}() - Error Thrown ", MethodBase.GetCurrentMethod().Name), e);
|
||||
}
|
||||
}
|
||||
return buttonState;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
58
Platform/Logger.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using log4net;
|
||||
using log4net.Config;
|
||||
using log4net.Core;
|
||||
using log4net.Appender;
|
||||
using log4net.Layout;
|
||||
using log4net.Repository.Hierarchy;
|
||||
|
||||
namespace Foo.Platform
|
||||
{
|
||||
public class Logger
|
||||
{
|
||||
static Logger()
|
||||
{
|
||||
BasicConfigurator.Configure(CreateAndConfigureRollingFileAppender());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the Log4Net Interface
|
||||
/// </summary>
|
||||
/// <param name="type">Object Type to pass in to create Logger for</param>
|
||||
/// <returns>Log4Net Interface</returns>
|
||||
public static ILog GetLog4NetInterface(Type type)
|
||||
{
|
||||
return LogManager.GetLogger(type);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and Configures teh RollingFileAppender *Configuration goes on here *
|
||||
/// </summary>
|
||||
/// <returns>RollingFileAppender Class to be used in Configuring Log4Net</returns>
|
||||
static private RollingFileAppender CreateAndConfigureRollingFileAppender()
|
||||
{
|
||||
RollingFileAppender fileAppender = new RollingFileAppender();
|
||||
fileAppender.Layout = new PatternLayout(PatternLayout.DetailConversionPattern);
|
||||
|
||||
// Locking Minimal allows us to run Log4Net from multiple processes
|
||||
fileAppender.LockingModel = new FileAppender.MinimalLock();
|
||||
|
||||
fileAppender.File = (Env.GetLogDirectory() + @"\LogServer.log");
|
||||
fileAppender.AppendToFile = true;
|
||||
|
||||
#if DEBUG
|
||||
fileAppender.Threshold = Level.All;
|
||||
#else
|
||||
fileAppender.Threshold = Level.Error;
|
||||
#endif
|
||||
|
||||
fileAppender.MaximumFileSize = "5MB";
|
||||
fileAppender.MaxSizeRollBackups = 3;
|
||||
fileAppender.ActivateOptions();
|
||||
return fileAppender;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
BIN
Platform/MyKeyFile.SNK
Normal file
39
Platform/OSWrapper.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Ooganizer.Platform
|
||||
{
|
||||
class OSWrapper
|
||||
{
|
||||
|
||||
|
||||
void Lalelu()
|
||||
{
|
||||
using (OoganizerState oogyState = new OoganizerState())
|
||||
{
|
||||
string curWorkspaceName = oogyState.GetCurrentWorkspace();
|
||||
|
||||
if (curWorkspaceName != null)
|
||||
{
|
||||
using (OoganizerAPIProxy proxy = oogyState.GetAPIProxy())
|
||||
{
|
||||
Workspace curWorkspace = proxy.API.GetWorkspace(curWorkspaceName);
|
||||
|
||||
foreach (OoganizerDAL.Artifact artifact in curWorkspace.Artifacts)
|
||||
{
|
||||
if (curArtifact.Location.ToUpper() == artifact.Location.ToUpper())
|
||||
{
|
||||
bFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
3
Platform/ObjectPooling.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
Enterprise Services (.NET 1.1) Performance Guidelines - Object Pooling
|
||||
http://www.guidanceshare.com/wiki/Enterprise_Services_(.NET_1.1)_Performance_Guidelines_-_Object_Pooling
|
||||
99
Platform/Platform.csproj
Normal file
@@ -0,0 +1,99 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{F6929AFC-BF61-43A0-BABD-F807B65FFFA1}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Foo.Platform</RootNamespace>
|
||||
<AssemblyName>Platform</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<SccProjectName>
|
||||
</SccProjectName>
|
||||
<SccLocalPath>
|
||||
</SccLocalPath>
|
||||
<SccAuxPath>
|
||||
</SccAuxPath>
|
||||
<SccProvider>
|
||||
</SccProvider>
|
||||
<TargetFrameworkSubset>
|
||||
</TargetFrameworkSubset>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<AssemblyOriginatorKeyFile>MyKeyFile.SNK</AssemblyOriginatorKeyFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\Target\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\Target\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Components\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Interacters\BHInteracter.cs" />
|
||||
<Compile Include="Satellite\GUI.cs" />
|
||||
<Compile Include="Utilities\DebugLogger.cs" />
|
||||
<Compile Include="Env.cs" />
|
||||
<Compile Include="ErrorReporting\UserError.cs" />
|
||||
<Compile Include="Utilities\FileM.cs" />
|
||||
<Compile Include="InstallationSpec.cs" />
|
||||
<Compile Include="Logger.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Utilities\RegM.cs" />
|
||||
<Compile Include="Win32.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="MyKeyFile.SNK" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Satellite\Satellite.csproj">
|
||||
<Project>{6DC93F91-D6D4-4C35-8A83-C180E8E22E16}</Project>
|
||||
<Name>Satellite</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>$(FrameworkDir)\regasm.exe "$(SolutionDir)target\$(ConfigurationName)\$(TargetFileName)" /unregister
|
||||
$(FrameworkDir)\regasm.exe "$(SolutionDir)target\$(ConfigurationName)\$(TargetFileName)" /tlb:$(TargetName).tlb /codebase
|
||||
mkdir "$(SolutionDir)target\$(ConfigurationName)\Resources"
|
||||
xcopy "$(ProjectDir)Resources" "$(SolutionDir)target\$(ConfigurationName)\Resources" /E /C /Y
|
||||
copy "$(SolutionDir)Components\log4net.dll" "$(SolutionDir)target\$(ConfigurationName)\log4net.dll" /Y</PostBuildEvent>
|
||||
<PreBuildEvent>
|
||||
</PreBuildEvent>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
36
Platform/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Platform")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Platform")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2008")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("7401c7a2-13c4-4821-9b09-deb707d27b3a")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
BIN
Platform/Resources/Themes/AeroTheme/ButtonDown.ico
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
Platform/Resources/Themes/AeroTheme/ButtonUp.ico
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
Platform/Resources/Themes/AeroTheme/ToggleUp.ico
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
Platform/Resources/Themes/ClassicTheme/ButtonDown.ico
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
Platform/Resources/Themes/ClassicTheme/ButtonUp.ico
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
Platform/Resources/Themes/ClassicTheme/ToggleUp.ico
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
Platform/Resources/Themes/VistaNoAeroTheme/ButtonDown.ico
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
Platform/Resources/Themes/VistaNoAeroTheme/ButtonUp.ico
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
Platform/Resources/Themes/VistaNoAeroTheme/ToggleUp.ico
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
Platform/Resources/Themes/XPTheme/ButtonDown.ico
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
Platform/Resources/Themes/XPTheme/ButtonUp.ico
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
Platform/Resources/Themes/XPTheme/ToggleUp.ico
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
63
Platform/Satellite/GUI.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Resources;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Foo.Platform.Satellite
|
||||
{
|
||||
/// <summary>
|
||||
/// Quick N' Easy access to the Satellite GUI Assembly Resource
|
||||
/// </summary>
|
||||
public static class GUIResx
|
||||
{
|
||||
private static ResourceManager _ResourceManager = null;
|
||||
private static Assembly _Assembly = null;
|
||||
|
||||
/// <summary>
|
||||
/// Construction
|
||||
/// </summary>
|
||||
static GUIResx()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_ResourceManager == null && _Assembly == null)
|
||||
{
|
||||
_Assembly = Assembly.LoadFile(InstallationSpec.InstallPath + "\\" + "Satellite.dll");
|
||||
_ResourceManager = new ResourceManager("Foo.Satellite.GUI", _Assembly);
|
||||
|
||||
// * For Debugging *
|
||||
//string[] resourceNames = _Assembly.GetManifestResourceNames();
|
||||
//foreach (string resourceName in resourceNames)
|
||||
//{
|
||||
// string Doris = resourceName;
|
||||
//}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
string message = e.Message;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a Resource value as a string
|
||||
/// </summary>
|
||||
/// <param name="strName">name of resource to get</param>
|
||||
/// <returns>the value of the resource</returns>
|
||||
public static string GetString(string strName)
|
||||
{
|
||||
string retVal = string.Empty;
|
||||
try
|
||||
{
|
||||
retVal = _ResourceManager.GetString(strName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
string message = e.Message;
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
91
Platform/Utilities/DebugLogger.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using Microsoft.Win32;
|
||||
using System.Reflection;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Ooganizer.Platform.Utilities
|
||||
{
|
||||
public class DebugLogger
|
||||
{
|
||||
private static string s_strFileNPath = "";
|
||||
private static FileM s_fileM = null;
|
||||
private static LogInstantiator s_LogI = null;
|
||||
private static int s_LoadTime = 0;
|
||||
private static bool s_firstTime = true;
|
||||
|
||||
/// <summary>
|
||||
/// Use the Log(string line) method to quickly write to a temp log file in the current assembly directory
|
||||
/// </summary>
|
||||
static DebugLogger()
|
||||
{
|
||||
if (s_LogI == null)
|
||||
{
|
||||
int timebefore = System.Environment.TickCount;
|
||||
s_LogI = new LogInstantiator();
|
||||
s_LoadTime = System.Environment.TickCount - timebefore;
|
||||
}
|
||||
|
||||
if (s_fileM == null)
|
||||
s_fileM = new FileM(s_LogI.strFileName, "log", s_LogI.strDirectoryPath, true);
|
||||
|
||||
if(s_strFileNPath == "")
|
||||
s_strFileNPath = s_fileM.PathNFile;
|
||||
}
|
||||
|
||||
public static void Log(string line)
|
||||
{
|
||||
if (s_firstTime)
|
||||
{
|
||||
//s_fileM.WriteLineUTF8("EasyLogger's Logger.cs was loaded in " + s_LoadTime.ToString() + " miliseconds");
|
||||
s_firstTime = false;
|
||||
}
|
||||
s_fileM.WriteLineUTF8(line);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Small Helper class in order to get the location of the currently running assembly
|
||||
/// </summary>
|
||||
private class LogInstantiator
|
||||
{
|
||||
public string strFileName;
|
||||
public string strDirectoryPath;
|
||||
private static RegistryKey s_OogyRootKey;
|
||||
|
||||
public LogInstantiator()
|
||||
{
|
||||
// For Random File names ~shouldn't be used anymore
|
||||
//string strRandomFileName = Path.GetRandomFileName();
|
||||
//strRandomFileName = strRandomFileName.Substring(0, (strRandomFileName.Length - 4)); // stripe extension (.xyz)
|
||||
//strFileName = strRandomFileName;
|
||||
|
||||
// Find the Calling Assembly that is NOT this one
|
||||
StackTrace stackTrace = new StackTrace();
|
||||
StackFrame stackFrame;
|
||||
MethodBase stackFrameMethod;
|
||||
string typeName;
|
||||
|
||||
int framecount = 3;
|
||||
stackFrame = stackTrace.GetFrame(framecount);
|
||||
stackFrameMethod = stackFrame.GetMethod();
|
||||
typeName = stackFrameMethod.ReflectedType.FullName;
|
||||
|
||||
// *IMP* Use the calling Assembly Type Name as the file name
|
||||
strFileName = typeName;
|
||||
|
||||
// *Work-Around*, we can't have a circular reference with InstallationSpec, so we just
|
||||
// have to Query for the LogPath Directly instead of using Platform.InstallationSpec
|
||||
s_OogyRootKey = Registry.LocalMachine.OpenSubKey("Software\\Ooganizer",false);
|
||||
|
||||
if (s_OogyRootKey != null)
|
||||
{
|
||||
object keyvalue = s_OogyRootKey.GetValue("LogPath");
|
||||
if ((keyvalue != null) && (keyvalue.ToString() != ""))
|
||||
strDirectoryPath = keyvalue.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
154
Platform/Utilities/FileM.cs
Normal file
@@ -0,0 +1,154 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace Ooganizer.Platform.Utilities
|
||||
{
|
||||
public class FileM
|
||||
{
|
||||
private string m_sFileName;
|
||||
private string m_sFileType;
|
||||
private string m_sFileDirPath;
|
||||
|
||||
//Flags
|
||||
private bool m_bIsFileCreated = false;
|
||||
private bool m_bOverideExisting = true;
|
||||
private bool m_bDeleteOnDestruct = false;
|
||||
|
||||
// Creates Temporary File by Default
|
||||
public FileM(string FileType)
|
||||
{
|
||||
m_sFileName = Path.GetRandomFileName();
|
||||
m_sFileType = FileType;
|
||||
m_sFileDirPath = Path.GetTempPath();
|
||||
m_bDeleteOnDestruct = true;
|
||||
}
|
||||
|
||||
public FileM(string FileType, bool bDontDeleteOnDestruct)
|
||||
{
|
||||
m_sFileName = Path.GetRandomFileName();
|
||||
m_sFileType = FileType;
|
||||
m_sFileDirPath = Path.GetTempPath();
|
||||
m_bDeleteOnDestruct = !bDontDeleteOnDestruct;
|
||||
}
|
||||
|
||||
public FileM(string FileName, string FileType, string DirectoryPath, bool OverideExisting)
|
||||
{
|
||||
m_sFileName = FileName;
|
||||
m_sFileType = FileType;
|
||||
if (!Directory.Exists(DirectoryPath))
|
||||
{
|
||||
Directory.CreateDirectory(DirectoryPath);
|
||||
}
|
||||
m_sFileDirPath = DirectoryPath + "\\";
|
||||
m_bOverideExisting = OverideExisting;
|
||||
}
|
||||
|
||||
~FileM()
|
||||
{
|
||||
if (m_bDeleteOnDestruct)
|
||||
{
|
||||
File.Delete(this.PathNFile);
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteLineA(string line)
|
||||
{
|
||||
FileStream fs = CreateFile();
|
||||
StreamWriter sw = new StreamWriter(fs, Encoding.ASCII);
|
||||
sw.WriteLine(line);
|
||||
sw.Flush();
|
||||
sw.Close();
|
||||
fs.Close();
|
||||
}
|
||||
|
||||
public void WriteLineA(string[] lines)
|
||||
{
|
||||
FileStream fs = CreateFile();
|
||||
StreamWriter sw = new StreamWriter(fs, Encoding.ASCII);
|
||||
|
||||
foreach (string line in lines)
|
||||
{
|
||||
sw.WriteLine(line);
|
||||
}
|
||||
|
||||
sw.Flush();
|
||||
sw.Close();
|
||||
fs.Close();
|
||||
}
|
||||
|
||||
public void WriteLineUTF8(string line)
|
||||
{
|
||||
FileStream fs = CreateFile();
|
||||
StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
|
||||
sw.WriteLine(line);
|
||||
sw.Flush();
|
||||
sw.Close();
|
||||
fs.Close();
|
||||
}
|
||||
|
||||
public void WriteLineUTF8(string[] lines)
|
||||
{
|
||||
FileStream fs = CreateFile();
|
||||
StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
|
||||
|
||||
foreach (string line in lines)
|
||||
{
|
||||
sw.WriteLine(line);
|
||||
}
|
||||
|
||||
sw.Flush();
|
||||
sw.Close();
|
||||
fs.Close();
|
||||
}
|
||||
|
||||
public void DeleteIfExists()
|
||||
{
|
||||
if (File.Exists(this.PathNFile))
|
||||
{
|
||||
File.Delete(this.PathNFile);
|
||||
}
|
||||
}
|
||||
|
||||
private FileStream CreateFile()
|
||||
{
|
||||
if (!m_bIsFileCreated && m_bOverideExisting)
|
||||
{
|
||||
m_bIsFileCreated = true;
|
||||
return (new FileStream(this.PathNFile, FileMode.Create));
|
||||
}
|
||||
else
|
||||
{
|
||||
return (new FileStream(this.PathNFile, FileMode.Append));
|
||||
}
|
||||
}
|
||||
|
||||
// public properties
|
||||
public string FileName
|
||||
{
|
||||
get
|
||||
{
|
||||
return (this.FileName);
|
||||
}
|
||||
}
|
||||
|
||||
public string DirectoryPath
|
||||
{
|
||||
get
|
||||
{
|
||||
return (this.m_sFileDirPath);
|
||||
}
|
||||
}
|
||||
|
||||
public string PathNFile
|
||||
{
|
||||
get
|
||||
{
|
||||
return (m_sFileDirPath + m_sFileName + "." + m_sFileType);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
191
Platform/Utilities/RegM.cs
Normal file
@@ -0,0 +1,191 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace Foo.Platform.Utilities
|
||||
{
|
||||
public enum HKEYRoot
|
||||
{
|
||||
ClassesRoot,
|
||||
CurrentUser,
|
||||
LocalMachine,
|
||||
}
|
||||
|
||||
public enum KeySub
|
||||
{
|
||||
Software,
|
||||
Custom
|
||||
}
|
||||
|
||||
public class RegM
|
||||
{
|
||||
|
||||
private RegistryKey _RegKey;
|
||||
|
||||
/// <summary>
|
||||
/// Use this to Open/Automatically Create a Registry Key
|
||||
/// </summary>
|
||||
/// <param name="root">specify registry root</param>
|
||||
/// <param name="sub">specify a sub or custom</param>
|
||||
/// <param name="Key">key you want to open / create </param>
|
||||
/// <param name="bWrite">true if you plan on writing to it</param>
|
||||
public RegM(HKEYRoot root, KeySub sub, string Key, bool bWrite)
|
||||
{
|
||||
string KeyToOpen = String.Empty;
|
||||
if (sub == KeySub.Custom)
|
||||
KeyToOpen = Key;
|
||||
else
|
||||
KeyToOpen = sub.ToString() + "\\" + Key;
|
||||
|
||||
RegistryKeyPermissionCheck permission = RegistryKeyPermissionCheck.ReadSubTree;
|
||||
if (bWrite)
|
||||
permission = RegistryKeyPermissionCheck.ReadWriteSubTree;
|
||||
|
||||
// Open/Create if it doesn't exist, the Proper Key
|
||||
switch (root)
|
||||
{
|
||||
case HKEYRoot.ClassesRoot:
|
||||
_RegKey = Registry.ClassesRoot.CreateSubKey(KeyToOpen, permission);
|
||||
break;
|
||||
|
||||
case HKEYRoot.CurrentUser:
|
||||
_RegKey = Registry.CurrentUser.CreateSubKey(KeyToOpen, permission);
|
||||
break;
|
||||
|
||||
case HKEYRoot.LocalMachine:
|
||||
_RegKey = Registry.LocalMachine.CreateSubKey(KeyToOpen, permission);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#region GetValue Registry Functions
|
||||
|
||||
public bool GetVal_String(string strValKey, out string StringValue)
|
||||
{
|
||||
StringValue = String.Empty;
|
||||
try
|
||||
{
|
||||
object keyvalue = null;
|
||||
keyvalue = _RegKey.GetValue(strValKey);
|
||||
if (isValidStr(keyvalue))
|
||||
StringValue = keyvalue.ToString();
|
||||
return true;
|
||||
}
|
||||
catch (Exception) { /* ignore */ }
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool GetVal_Bool(string strValKey, out bool BoolValue)
|
||||
{
|
||||
BoolValue = false;
|
||||
try
|
||||
{
|
||||
string StringValue;
|
||||
if (GetVal_String(strValKey, out StringValue) &&
|
||||
!String.IsNullOrEmpty(StringValue))
|
||||
BoolValue = Boolean.Parse(StringValue);
|
||||
return true;
|
||||
}
|
||||
catch (Exception) { /* ignore */ }
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool GetVal_Int(string strValKey, out int IntValue)
|
||||
{
|
||||
IntValue = 0;
|
||||
try
|
||||
{
|
||||
string StringValue;
|
||||
if (GetVal_String(strValKey, out StringValue) &&
|
||||
!String.IsNullOrEmpty(StringValue))
|
||||
IntValue = int.Parse(StringValue);
|
||||
return true;
|
||||
}
|
||||
catch (Exception) { /* ignore */ }
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool GetVal_Binary(string strValKey, out byte[] ByteValue)
|
||||
{
|
||||
ByteValue = null;
|
||||
try
|
||||
{
|
||||
string StringValue;
|
||||
if (GetVal_String(strValKey, out StringValue) &&
|
||||
!String.IsNullOrEmpty(StringValue))
|
||||
{
|
||||
ByteValue = new Byte[StringValue.Length];
|
||||
for (int i = 0; i < ByteValue.Length; ++i)
|
||||
{
|
||||
string strByte = Convert.ToString(StringValue[i]);
|
||||
ByteValue[i] = byte.Parse(strByte);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (Exception) { /* ignore */ }
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region SetValue Registry Functions
|
||||
|
||||
public bool SetVal_String(string strValKey, string StringValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
_RegKey.SetValue(strValKey, StringValue, RegistryValueKind.String);
|
||||
return true;
|
||||
}
|
||||
catch (Exception) { /* ignore */ }
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool SetVal_Bool(string strValKey, bool BoolValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
_RegKey.SetValue(strValKey, BoolValue.ToString(), RegistryValueKind.String);
|
||||
return true;
|
||||
}
|
||||
catch (Exception) { /* ignore */ }
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool SetVal_Int(string strValKey, int DwordValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
_RegKey.SetValue(strValKey, DwordValue, RegistryValueKind.DWord);
|
||||
return true;
|
||||
}
|
||||
catch (Exception) { /* ignore */ }
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool SetVal_Binary(string strValKey, byte[] ByteValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
_RegKey.SetValue(strValKey, ByteValue, RegistryValueKind.Binary);
|
||||
return true;
|
||||
}
|
||||
catch (Exception) { /* ignore */ }
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <returns>Returns true if passed in object is valid and not ""</returns>
|
||||
private bool isValidStr(object oToValidate)
|
||||
{
|
||||
if ((oToValidate != null) && (oToValidate.ToString() != ""))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
1362
Platform/Win32.cs
Normal file
3
Platform/app.config
Normal file
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0"?>
|
||||
<configuration>
|
||||
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
|
||||