using System;
using System.IO;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace Foo.Platform
{
///
/// Oogy Environment Class for getting OS, Application, and Theme Settings
///
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;
///
/// Public Properties
///
public static int MajorVersion {get{return m_dwMajorVersion;}}
public static int MinorVersion {get{return m_dwMinorVersion;}}
public static Themes Theme {get{return m_Theme;}}
///
/// This is our versioning system, does not correspond to Windows
///
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
}
///
/// This are our Theme Configurations for ButtonHook/GUI components.
///
public enum Themes : int
{
Classic = 0,
XPtheme = 1,
AeroTheme = 2,
VistaNoAero = 3
}
///
/// Static Constructor, immediatly sets our environment variables
///
static Env()
{
ObtainEnvInformation();
m_RunTimePath = new AssemblyRunTimePath();
}
///
/// Call this function first - before querying for themes, etc
///
private static void ObtainEnvInformation()
{
GetSystemInformation(out m_dwMajorVersion, out m_dwMinorVersion);
CheckWindowsXPTheme();
CheckWindowsVistaTheme();
}
///
/// Use to get the Oogy Application path. Creates folder if none exists
///
/// Path to Ooganizer Application Folder
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;
}
///
/// Use to get the Oogy artifact snapshot image path. Creates folder if none exists
///
/// Path to Ooganizer artifact snapshot data folder
public static string GetSnapshotDirectory()
{
string path = Platform.Env.GetAppdirectory() + @"\Snapshots";
if (!Directory.Exists(path))
{
// create snapshot data folder
Directory.CreateDirectory(path);
}
return path;
}
///
/// Use to get the Oogy log path. Creates folder if none exists
///
/// Path to Ooganizer log folder
public static string GetLogDirectory()
{
string path = Platform.Env.GetAppdirectory() + @"\Logs";
if (!Directory.Exists(path))
{
// create snapshot data folder
Directory.CreateDirectory(path);
}
return path;
}
///
/// Use this to query the current running assembly path
///
/// Path of assembly location
public static string GetRunTimePath()
{
return m_RunTimePath.strPath;
}
///
/// Quickly Check if the current OS Environment is supported by Oogy
///
/// true if it is supported, false otherwise
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;
}
}
///
/// Retrieves Windows OS specific information
///
/// dwMajorVersion[out]
/// dwMinorVersion[out]
/// is32bitNT[out] = supports 32-bit Windows NT
/// true, if succesfully retrieved, false otherwise
private static void GetSystemInformation(out int dwMajorVersion, out int dwMinorVersion)
{
dwMajorVersion = System.Environment.OSVersion.Version.Major;
dwMinorVersion = System.Environment.OSVersion.Version.Minor;
}
///
/// Use this function to obtain the current OS version information
///
/// Returns the Current OSVersion Enum of this Environment
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);
}
}
///
/// Vista Specific Theme Checking is done here
///
///
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;
}
}
///
/// XP Specific Theme Checking is done here
///
///
private static void CheckWindowsXPTheme()
{
if (OSVersionCheck() == OSVersions.OS_WINDOWS_2003)
{
if (Win32.Win32Functions.IsAppThemed())
m_Theme = Themes.XPtheme;
else
m_Theme = Themes.Classic;
}
}
}
///
/// Since we only can query the Assembly path by instantiation,
/// we have a class that handles it
///
internal class AssemblyRunTimePath
{
public string strPath;
public AssemblyRunTimePath(){strPath = Path.GetDirectoryName(GetType().Assembly.Location);}
}
///
/// 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
///
[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;
}
}
}