// // Copyright (c) 2008-2011, Kenneth Bell // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // namespace DiscUtils.BootConfig { using DiscUtils.Registry; using System; using System.Collections.Generic; /// /// Represents a Boot Configuration Database store (i.e. a BCD file). /// public class Store { private BaseStorage _store; /// /// Initializes a new instance of the Store class. /// /// The registry key that is the root of the configuration database. public Store(RegistryKey key) { _store = new DiscUtilsRegistryStorage(key); } /// /// Gets the objects within the store. /// public IEnumerable Objects { get { foreach (var obj in _store.EnumerateObjects()) { yield return new BcdObject(_store, obj); } } } /// /// Initializes a new Boot Configuration Database. /// /// The registry key at the root of the database. /// The BCD store. public static Store Initialize(RegistryKey root) { RegistryKey descKey = root.CreateSubKey("Description"); descKey.SetValue("KeyName", "BCD00000001"); root.CreateSubKey("Objects"); return new Store(root); } /// /// Gets an object from the store. /// /// The identity of the object. /// The requested object, or null. public BcdObject GetObject(Guid id) { if (_store.ObjectExists(id)) { return new BcdObject(_store, id); } else { return null; } } /// /// Creates a specific object. /// /// The identity of the object to create. /// The object's type. /// The object representing the new application. public BcdObject CreateObject(Guid id, int type) { _store.CreateObject(id, type); return new BcdObject(_store, id); } /// /// Creates an application object. /// /// The image type of the application. /// The application's type. /// The object representing the new application. public BcdObject CreateApplication(ApplicationImageType imageType, ApplicationType appType) { Guid obj = _store.CreateObject(Guid.NewGuid(), BcdObject.MakeApplicationType(imageType, appType)); return new BcdObject(_store, obj); } /// /// Creates an application object. /// /// The identity of the object to create. /// The image type of the application. /// The application's type. /// The object representing the new application. public BcdObject CreateApplication(Guid id, ApplicationImageType imageType, ApplicationType appType) { Guid obj = _store.CreateObject(id, BcdObject.MakeApplicationType(imageType, appType)); return new BcdObject(_store, obj); } /// /// Creates an 'inherit' object that contains common settings. /// /// The type of object the settings apply to. /// The object representing the new settings. public BcdObject CreateInherit(InheritType inheritType) { Guid obj = _store.CreateObject(Guid.NewGuid(), BcdObject.MakeInheritType(inheritType)); return new BcdObject(_store, obj); } /// /// Creates an 'inherit' object that contains common settings. /// /// The identity of the object to create. /// The type of object the settings apply to. /// The object representing the new settings. public BcdObject CreateInherit(Guid id, InheritType inheritType) { Guid obj = _store.CreateObject(id, BcdObject.MakeInheritType(inheritType)); return new BcdObject(_store, obj); } /// /// Creates a new device object, representing a partition. /// /// The object representing the new device. public BcdObject CreateDevice() { Guid obj = _store.CreateObject(Guid.NewGuid(), 0x30000000); return new BcdObject(_store, obj); } /// /// Removes an object. /// /// The identity of the object to remove. public void RemoveObject(Guid id) { _store.DeleteObject(id); } } }