/// <summary> /// Tries to create all system-folders, as defined in <see cref="VirtualFolder"/>. /// </summary> /// <param name="rootDirectory">The folder under which all system folders must be created.</param> /// <returns>True if all folders are created; False if the creation of one or more folders failed.</returns> private static void CreateSystemFolders(string rootDirectory) { EngineCore.Log.Message("Creating system folders for a virtual environment with root \"{0}\"", rootDirectory); foreach (VirtualFolder virtualFolder in Enum.GetValues(typeof(VirtualFolder))) { if (!HostFileSystem.TryCreateDirectory(Path.Combine(rootDirectory, virtualFolder.ToPath()))) { EngineCore.Log.Critical("Failed to create virtual system folder: " + virtualFolder); } } }
/// <summary> /// Returns an initialized <see cref="IDictionary{TKey,TValue}"/>, /// filled with all known system variables. /// </summary> /// <returns></returns> private static IDictionary <string, VirtualFolder> InitializeSystemVariables() { IDictionary <string, VirtualFolder> systemVariables = new Dictionary <string, VirtualFolder>(); string tmp; // Will contain the temporary values used in this method. // Always check if the dictionary doesn't already contain the same key. // The users might have configured the specialfolders to use the same folder. // BUG: Such configurations might lead to inconsistencies between different host systems. tmp = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); if (!string.IsNullOrEmpty(tmp) && !systemVariables.ContainsKey(tmp.ToLowerInvariant())) { systemVariables.Add(tmp.ToLowerInvariant(), VirtualFolder.UserDocuments); } tmp = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); if (!string.IsNullOrEmpty(tmp) && !systemVariables.ContainsKey(tmp.ToLowerInvariant())) { systemVariables.Add(tmp.ToLowerInvariant(), VirtualFolder.UserPictures); } tmp = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic); if (!string.IsNullOrEmpty(tmp) && !systemVariables.ContainsKey(tmp.ToLowerInvariant())) { systemVariables.Add(tmp.ToLowerInvariant(), VirtualFolder.UserMusic); } // UserData tmp = Environment.GetFolderPath(Environment.SpecialFolder.Personal); if (!string.IsNullOrEmpty(tmp) && !systemVariables.ContainsKey(tmp.ToLowerInvariant())) { systemVariables.Add(tmp.ToLowerInvariant(), VirtualFolder.UserData); } // Application Data tmp = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); if (!string.IsNullOrEmpty(tmp) && !systemVariables.ContainsKey(tmp.ToLowerInvariant())) { systemVariables.Add(tmp.ToLowerInvariant(), VirtualFolder.ApplicationData); } tmp = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData).ToLowerInvariant(); if (!systemVariables.ContainsKey(tmp)) { systemVariables.Add(tmp, VirtualFolder.ApplicationData); } tmp = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); if (!string.IsNullOrEmpty(tmp) && !systemVariables.ContainsKey(tmp.ToLowerInvariant())) { systemVariables.Add(tmp.ToLowerInvariant(), VirtualFolder.ApplicationData); } // Temporary Folders var folders = HostFileSystem.GetTemporaryFolders(); foreach (var folder in folders) { tmp = folder.ToLowerInvariant(); if (!systemVariables.ContainsKey(tmp)) { systemVariables.Add(tmp, VirtualFolder.Temporary); } } // Program Files tmp = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles).ToLowerInvariant(); if (!systemVariables.ContainsKey(tmp)) { systemVariables.Add(tmp, VirtualFolder.ProgramFiles); } // System tmp = Environment.GetEnvironmentVariable("systemroot"); if (!string.IsNullOrEmpty(tmp) && !systemVariables.ContainsKey(tmp.ToLowerInvariant())) { systemVariables.Add(tmp.ToLowerInvariant(), VirtualFolder.System); } tmp = Environment.GetFolderPath(Environment.SpecialFolder.System).ToLowerInvariant(); if (!string.IsNullOrEmpty(tmp) && !systemVariables.ContainsKey(tmp)) { systemVariables.Add(tmp, VirtualFolder.System32); } // Start Menu tmp = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu); if (!string.IsNullOrEmpty(tmp) && !systemVariables.ContainsKey(tmp.ToLowerInvariant())) { systemVariables.Add(tmp.ToLowerInvariant(), VirtualFolder.StartMenu); } tmp = HostFileSystem.GetCommonMenuFolder(); if (!string.IsNullOrEmpty(tmp) && !systemVariables.ContainsKey(tmp.ToLowerInvariant())) { systemVariables.Add(tmp.ToLowerInvariant(), VirtualFolder.StartMenu); } return(systemVariables); }