diff --git a/Library b/Library index 7289c5b..dae226d 160000 --- a/Library +++ b/Library @@ -1 +1 @@ -Subproject commit 7289c5bd2c06b2f2e766ec1bf016964ed8361186 +Subproject commit dae226d7aad2548e9a5fe402636e22ddd6b8e1b9 diff --git a/Program.cs b/Program.cs index 247be6a..6b311ed 100644 --- a/Program.cs +++ b/Program.cs @@ -137,8 +137,9 @@ static async Task Main(string[] args) List defaultComponents = new List(); // Add Microsoft-Windows-Shell-Setup in oobeSystem pass. It's already filled in, but add it anyway - SystemComponent defaultComponent = new SystemComponent("Microsoft-Windows-Shell-Setup"); - defaultComponent.Passes.Add(new SystemPass("oobeSystem")); + List defaultPasses = new List(); + defaultPasses.Add(new SystemPass("oobeSystem")); + SystemComponent defaultComponent = new SystemComponent("Microsoft-Windows-Shell-Setup", defaultPasses); defaultComponents.Add(defaultComponent); Console.WriteLine($"UnattendGen{(File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DT")) ? " for DISMTools" : "")}, version {Assembly.GetEntryAssembly().GetName().Version.ToString()}"); diff --git a/Tests/userAccounts.xml b/Tests/userAccounts.xml index f8652ce..330e672 100644 --- a/Tests/userAccounts.xml +++ b/Tests/userAccounts.xml @@ -6,4 +6,6 @@ + + \ No newline at end of file diff --git a/UserSettings/PartitionMode.cs b/UserSettings/PartitionMode.cs index 83b9bd7..62a7f3a 100644 --- a/UserSettings/PartitionMode.cs +++ b/UserSettings/PartitionMode.cs @@ -9,29 +9,64 @@ namespace UnattendGen.UserSettings { + /// + /// Partition settings for Disk 0 + /// public class DiskZeroSettings { public enum PartitionStyle { + /// + /// MBR partition table, used by default on systems that use BIOS instead of UEFI + /// MBR, + /// + /// GUID Partition Table, used by default on newer systems with UEFI firmware + /// GPT } public enum RecoveryEnvironmentMode { + /// + /// The Recovery Environment will not be present + /// None, + /// + /// The Recovery Environment will be installed on a separate disk partition + /// Partition, + /// + /// The Recovery Environment will be installed on the Windows installation + /// Windows } + /// + /// The style of the partition table + /// public PartitionStyle partStyle; + /// + /// The size of the EFI System Partition, in MB + /// public int ESPSize; + /// + /// The availability and location of the Recovery Environment (WinRE) + /// public RecoveryEnvironmentMode recoveryEnvironment; + /// + /// The size of the Recovery Environment partition, in MB + /// public int recEnvSize; + /// + /// Loads the disk settings specified by the user in a configuration file + /// + /// The path of the configuration file + /// The disk settings public static DiskZeroSettings? LoadDiskSettings(string filePath) { DiskZeroSettings diskZero = new DiskZeroSettings(); @@ -99,16 +134,36 @@ public enum RecoveryEnvironmentMode } + /// + /// Partition settings for DiskPart scripts + /// public class DiskPartSettings { + /// + /// The path of the specified DiskPart script + /// public string? scriptFile; + /// + /// Determine whether or not to install Windows to the first available partition that has enough space and does not already contain an installation of Windows, after DiskPart configuration has finished + /// public bool automaticInstall; + /// + /// Disk number for OS installation. Only used when is set to false + /// public int diskNum; + /// + /// Partition number for OS installation. Only used when is set to false + /// public int partNum; + /// + /// Loads the DiskPart settings specified by the user in a configuration file + /// + /// The path of the configuration file + /// The DiskPart configuration public static DiskPartSettings? LoadDiskSettings(string filePath) { DiskPartSettings diskPart = new DiskPartSettings(); diff --git a/UserSettings/RegionFile.cs b/UserSettings/RegionFile.cs index 99d1013..6f94d45 100644 --- a/UserSettings/RegionFile.cs +++ b/UserSettings/RegionFile.cs @@ -60,9 +60,7 @@ public GeoIds(string id, string displayName) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "GeoId") { - GeoIds geo = new GeoIds(); - geo.Id = reader.GetAttribute("Id"); - geo.DisplayName = reader.GetAttribute("DisplayName"); + GeoIds geo = new GeoIds(reader.GetAttribute("Id"), reader.GetAttribute("DisplayName")); geoList.Add(geo); } } @@ -115,9 +113,7 @@ public ImageLanguages(string id, string displayName) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "ImageLanguage") { - ImageLanguages lang = new ImageLanguages(); - lang.Id = reader.GetAttribute("Id"); - lang.DisplayName = reader.GetAttribute("DisplayName"); + ImageLanguages lang = new ImageLanguages(reader.GetAttribute("Id"), reader.GetAttribute("DisplayName")); langList.Add(lang); } } @@ -174,10 +170,9 @@ public KeyboardIdentifiers(string id, string displayName, string type) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "KeyboardIdentifier") { - KeyboardIdentifiers keyboard = new KeyboardIdentifiers(); - keyboard.Id = reader.GetAttribute("Id"); - keyboard.DisplayName = reader.GetAttribute("DisplayName"); - keyboard.Type = reader.GetAttribute("Type"); + KeyboardIdentifiers keyboard = new KeyboardIdentifiers(reader.GetAttribute("Id"), + reader.GetAttribute("DisplayName"), + reader.GetAttribute("Type")); keyboardList.Add(keyboard); } } @@ -232,9 +227,7 @@ public TimeOffsets(string id, string displayName) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "TimeOffset") { - TimeOffsets offset = new TimeOffsets(); - offset.Id = reader.GetAttribute("Id"); - offset.DisplayName = reader.GetAttribute("DisplayName"); + TimeOffsets offset = new TimeOffsets(reader.GetAttribute("Id"), reader.GetAttribute("DisplayName")); offsetList.Add(offset); } } @@ -299,12 +292,11 @@ public UserLocales(string id, string displayName, string lcid, string keybId, st { if (reader.NodeType == XmlNodeType.Element && reader.Name == "UserLocale") { - UserLocales locale = new UserLocales(); - locale.Id = reader.GetAttribute("Id"); - locale.DisplayName = reader.GetAttribute("DisplayName"); - locale.LCID = reader.GetAttribute("LCID"); - locale.KeybId = reader.GetAttribute("KeyboardLayout"); - locale.GeoLoc = reader.GetAttribute("GeoLocation"); + UserLocales locale = new UserLocales(reader.GetAttribute("Id"), + reader.GetAttribute("DisplayName"), + reader.GetAttribute("LCID"), + reader.GetAttribute("KeyboardLayout"), + reader.GetAttribute("GeoLocation")); localeList.Add(locale); } } diff --git a/UserSettings/SystemComponent.cs b/UserSettings/SystemComponent.cs index 880a806..fdaaccb 100644 --- a/UserSettings/SystemComponent.cs +++ b/UserSettings/SystemComponent.cs @@ -19,8 +19,14 @@ public class SystemComponent public SystemComponent() { } public SystemComponent(string? id) + { + this.Id = id; + } + + public SystemComponent(string? id, List? passes) { Id = id; + Passes = passes; } public static List? LoadComponents(string? filePath) @@ -39,12 +45,12 @@ public SystemComponent(string? id) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "Component") { - SystemComponent component = new SystemComponent(); - component.Id = reader.GetAttribute("Id"); string passList = reader.GetAttribute("Passes"); List passListTemp = new List(); passListTemp = passList.Split(new char[] { ',' }).ToList(); + List passes = new List(); + List knownPasses = [ .. new string[] { "offlineServicing", "windowsPE", "generalize", "specialize", "auditSystem", "auditUser", "oobeSystem" }, @@ -57,8 +63,11 @@ public SystemComponent(string? id) Debug.WriteLine($"Unknown pass \"{pass}\""); continue; } - component?.Passes.Add(new SystemPass(pass)); + passes.Add(new SystemPass(pass)); } + + SystemComponent component = new SystemComponent(reader.GetAttribute("Id"), passes); + componentList.Add(component); } } diff --git a/UserSettings/SystemEdition.cs b/UserSettings/SystemEdition.cs index d31453e..2164f15 100644 --- a/UserSettings/SystemEdition.cs +++ b/UserSettings/SystemEdition.cs @@ -44,9 +44,9 @@ public SystemEdition(string? id, string? displayName, string? productKey) if (reader.NodeType == XmlNodeType.Element && reader.Name == "Edition") { - edition.Id = reader.GetAttribute("Id"); - edition.DisplayName = reader.GetAttribute("DisplayName"); - edition.ProductKey = reader.GetAttribute("Key"); + edition = new SystemEdition(reader.GetAttribute("Id"), + reader.GetAttribute("DisplayName"), + reader.GetAttribute("Key")); } } diff --git a/UserSettings/UserAccounts.cs b/UserSettings/UserAccounts.cs index 4ce60ca..a7a30ab 100644 --- a/UserSettings/UserAccounts.cs +++ b/UserSettings/UserAccounts.cs @@ -27,6 +27,22 @@ public enum UserGroup public UserGroup Group; + public UserAccount() + { + Enabled = false; + Name = ""; + Password = ""; + Group = UserGroup.Users; + } + + public UserAccount(bool enabled, string? name, string? password, UserGroup group) + { + Enabled = enabled; + Name = name; + Password = password; + Group = group; + } + public static List? LoadAccounts(string filePath) { List accountList = new List(); @@ -43,26 +59,30 @@ public enum UserGroup { if (reader.NodeType == XmlNodeType.Element && reader.Name == "UserAccount") { - UserAccount account = new UserAccount(); - account.Enabled = reader.GetAttribute("Enabled") switch + int nameLength = reader.GetAttribute("Name").Length; + + UserAccount account = new UserAccount(reader.GetAttribute("Enabled") switch + { + "1" => true, + "0" => false, + _ => false + }, + (reader.GetAttribute("Name").Length > 20 ? + reader.GetAttribute("Name").Substring(0, 20) : + reader.GetAttribute("Name")), + reader.GetAttribute("Password"), + reader.GetAttribute("Group") switch + { + "Admins" => UserGroup.Administrators, + "Users" => UserGroup.Users, + _ => UserGroup.Users + }); + + + if (nameLength > 20) { - "1" => true, - "0" => false, - _ => false - }; - account.Name = reader.GetAttribute("Name"); - if (account.Name.Length > 20) - { - Console.WriteLine($"WARNING: Account name {account.Name} is over 20 characters long. Truncating to 20 characters..."); - account.Name = account.Name.Substring(0, 20); + Console.WriteLine($"WARNING: Account name \"{reader.GetAttribute("Name")}\" has been truncated to 20 characters because its length exceeds the limit."); } - account.Password = reader.GetAttribute("Password"); - account.Group = reader.GetAttribute("Group") switch - { - "Admins" => UserGroup.Administrators, - "Users" => UserGroup.Users, - _ => UserGroup.Users - }; accountList.Add(account); } diff --git a/UserSettings/WirelessNetwork.cs b/UserSettings/WirelessNetwork.cs index 13f565f..fbef5d7 100644 --- a/UserSettings/WirelessNetwork.cs +++ b/UserSettings/WirelessNetwork.cs @@ -26,6 +26,22 @@ public enum AuthenticationProtocol public bool NonBroadcast; + public WirelessNetwork() + { + SSID = ""; + Password = ""; + Authentication = AuthenticationProtocol.WPA2; + NonBroadcast = false; + } + + public WirelessNetwork(string? ssid, string? password, AuthenticationProtocol authProtocol, bool nonBroadcast) + { + SSID = ssid; + Password = password; + Authentication = authProtocol; + NonBroadcast = nonBroadcast; + } + public static WirelessNetwork? LoadSettings(string filePath) { try @@ -40,22 +56,21 @@ public enum AuthenticationProtocol { if (reader.NodeType == XmlNodeType.Element && reader.Name == "WirelessNetwork") { - WirelessNetwork network = new WirelessNetwork(); - network.SSID = reader.GetAttribute("Name"); - network.Password = reader.GetAttribute("Password"); - network.Authentication = reader.GetAttribute("AuthMode") switch - { - "Open" => AuthenticationProtocol.Open, - "WPA2" => AuthenticationProtocol.WPA2, - "WPA3" => AuthenticationProtocol.WPA3, - _ => AuthenticationProtocol.WPA2 - }; - network.NonBroadcast = reader.GetAttribute("NonBroadcast") switch - { - "1" => true, - "0" => false, - _ => false - }; + WirelessNetwork network = new WirelessNetwork(reader.GetAttribute("Name"), + reader.GetAttribute("Password"), + reader.GetAttribute("AuthMode") switch + { + "Open" => AuthenticationProtocol.Open, + "WPA2" => AuthenticationProtocol.WPA2, + "WPA3" => AuthenticationProtocol.WPA3, + _ => AuthenticationProtocol.WPA2 + }, + reader.GetAttribute("NonBroadcast") switch + { + "1" => true, + "0" => false, + _ => false + }); return network; }