// Determine if we appear to be running on Windows. private static bool IsWindows() { #if !ECMA_COMPAT return(InfoMethods.GetPlatformID() != PlatformID.Unix); #else return(Path.DirectorySeparatorChar == '\\'); #endif }
// Initialize the configuration system. public void Init() { // Bail out if already initialized. if (initialized) { return; } try { // Find the user/global machine defaults files. String userDefaultFile, globalDefaultFile; userDefaultFile = CheckForMachineDefault (InfoMethods.GetUserStorageDir()); globalDefaultFile = CheckForMachineDefault (InfoMethods.GetGlobalConfigDir()); // Find the user/global machine configuration files. String userConfigFile, globalConfigFile; userConfigFile = CheckForMachineConfig (InfoMethods.GetUserStorageDir()); globalConfigFile = CheckForMachineConfig (InfoMethods.GetGlobalConfigDir()); // Find the application's configuration file. String appConfigFile = AppDomain.CurrentDomain.SetupInformation .ConfigurationFile; // Load all of the configuration files that we found. if (globalDefaultFile != null) { Load(globalDefaultFile); } if (globalConfigFile != null) { Load(globalConfigFile); } if (userDefaultFile != null) { Load(userDefaultFile); } if (userConfigFile != null) { Load(userConfigFile); } if (appConfigFile != null && File.Exists(appConfigFile)) { Load(appConfigFile); } } finally { // The system has been initialized. initialized = true; } }
public FileKeyProvider(RegistryHive hive, String name) { // Record the name information for later. this.fullName = name; // Find the root position of the user's storage area. String root = InfoMethods.GetUserStorageDir(); // Build the full pathname for the hive directory. directory = root + Path.DirectorySeparatorChar + "registry"; CreateDirectory(directory); directory = directory + Path.DirectorySeparatorChar + hiveDirectories [((int)hive) - ((int)RegistryHive.ClassesRoot)]; CreateDirectory(directory); }
// Convert the OS version into a string. public override String ToString() { String os; switch (platform) { case PlatformID.Win32S: os = "Microsoft Win32S "; break; case PlatformID.Win32Windows: os = "Microsoft Windows 98 "; break; case PlatformID.Win32NT: os = "Microsoft Windows NT "; break; default: os = "Unix [" + InfoMethods.GetPlatformName() + "] "; break; } return(os + version.ToString()); }
// Get a path to a specific system folder. public static String GetFolderPath(SpecialFolder folder) { // We can use the operating system under Win32. if (InfoMethods.GetPlatformID() != PlatformID.Unix) { // Allocate a buffer to hold the result path. IntPtr buffer = Marshal.AllocHGlobal(260 /*MAX_PATH*/ + 1); // Call "SHGetFolderPath" to retrieve the path. try { SHGetFolderPathA(IntPtr.Zero, (int)folder, IntPtr.Zero, 0, buffer); String value = Marshal.PtrToStringAnsi(buffer); if (value != null && value.Length != 0) { Marshal.FreeHGlobal(buffer); return(value); } } catch (Exception) { // We weren't able to find the function in the DLL. } Marshal.FreeHGlobal(buffer); } // Special handling for some of the cases. String dir = null; switch (folder) { case SpecialFolder.System: { dir = DirMethods.GetSystemDirectory(); } break; case SpecialFolder.ApplicationData: { dir = InfoMethods.GetUserStorageDir() + Path.DirectorySeparatorChar + "ApplicationData"; } break; case SpecialFolder.LocalApplicationData: { dir = InfoMethods.GetUserStorageDir() + Path.DirectorySeparatorChar + "LocalApplicationData"; } break; case SpecialFolder.CommonApplicationData: { dir = InfoMethods.GetUserStorageDir() + Path.DirectorySeparatorChar + "CommonApplicationData"; } break; } if (dir != null && dir.Length > 0) { return(dir); } // The empty string indicates that the value is not present. return(String.Empty); }
/* This is a stupid API simulated to satisfy System.Web * implementation */ internal static String GetMachineConfigPath() { return(CheckForMachineDefault(InfoMethods.GetGlobalConfigDir())); }
// Get the base directory for an isolated storage scope. private static String GetBaseDirectory(IsolatedStorageScope scope) { // Find the base directory to start with. String baseDir; if (InfoMethods.GetPlatformID() == PlatformID.Unix) { // Use the user storage directory under Unix systems. baseDir = InfoMethods.GetUserStorageDir(); } else if ((scope & IsolatedStorageScope.Roaming) != 0) { // Use the roaming application data area under Win32. try { baseDir = Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData); } catch (Exception) { return(null); } } else { // Use the non-roaming application data area under Win32. try { baseDir = Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData); } catch (Exception) { return(null); } } if (baseDir == null || baseDir.Length == 0) { return(null); } baseDir = Path.Combine(baseDir, "isolated-storage"); // Add the assembly sub-directory name. if ((scope & IsolatedStorageScope.Assembly) != 0) { String name = Assembly.GetEntryAssembly().FullName; int index = name.IndexOf(','); if (index != -1) { name = name.Substring(0, index); } baseDir = Path.Combine(baseDir, name); } else { baseDir = Path.Combine(baseDir, "default"); } // Add the domain sub-directory name. if ((scope & IsolatedStorageScope.Domain) != 0) { baseDir = Path.Combine (baseDir, AppDomain.CurrentDomain.ToString()); } return(baseDir); }