/// <summary> /// The method ignore backspace as escape character, /// this way "C:\Driver\" I: are turned into two arguments instead of one. /// </summary> public static string[] GetCommandLineArgsIgnoreEscape() { var commandLine = Environment.CommandLine; var argsList = new List <string>(); var startIndex = 0; var endIndex = IndexOfArgumentSeparator(commandLine); while (endIndex != -1) { var length = endIndex - startIndex; var nextArg = commandLine.Substring(startIndex, length).Trim(); nextArg = QuotedStringUtils.Unquote(nextArg); argsList.Add(nextArg); startIndex = endIndex + 1; endIndex = IndexOfArgumentSeparator(commandLine, startIndex); } var lastArg = commandLine.Substring(startIndex).Trim(); lastArg = QuotedStringUtils.Unquote(lastArg); if (lastArg != string.Empty) { argsList.Add(lastArg); } argsList.RemoveAt(0); // remove the executable name return(argsList.ToArray()); }
private void ParseDescriptor(List <string> lines) { ExtentEntries = new List <VirtualMachineDiskExtentEntry>(); foreach (string line in lines) { if (line.StartsWith("version", StringComparison.OrdinalIgnoreCase)) { string value = line.Substring(line.IndexOf('=') + 1).Trim(); Version = Conversion.ToInt32(value); } else if (line.StartsWith("CID", StringComparison.OrdinalIgnoreCase)) { string value = line.Substring(line.IndexOf('=') + 1).Trim(); ContentID = UInt32.Parse(value, System.Globalization.NumberStyles.HexNumber); } else if (line.StartsWith("ParentCID", StringComparison.OrdinalIgnoreCase)) { string value = line.Substring(line.IndexOf('=') + 1).Trim(); ParentContentID = UInt32.Parse(value, System.Globalization.NumberStyles.HexNumber); } else if (line.StartsWith("createType", StringComparison.OrdinalIgnoreCase)) { string value = line.Substring(line.IndexOf('=') + 1).Trim(); value = QuotedStringUtils.Unquote(value); DiskType = GetFromString(value); } else if (line.StartsWith("RW", StringComparison.OrdinalIgnoreCase) || line.StartsWith("RDONLY", StringComparison.OrdinalIgnoreCase) || line.StartsWith("NOACCESS", StringComparison.OrdinalIgnoreCase)) { VirtualMachineDiskExtentEntry entry = VirtualMachineDiskExtentEntry.ParseEntry(line); ExtentEntries.Add(entry); } else if (line.StartsWith("ddb.adapterType", StringComparison.OrdinalIgnoreCase)) { string value = line.Substring(line.IndexOf('=') + 1).Trim(); value = QuotedStringUtils.Unquote(value); Adapter = value; } else if (line.StartsWith("ddb.geometry.sectors", StringComparison.OrdinalIgnoreCase)) { string value = line.Substring(line.IndexOf('=') + 1).Trim(); value = QuotedStringUtils.Unquote(value); SectorsPerTrack = Conversion.ToInt32(value); } else if (line.StartsWith("ddb.geometry.heads", StringComparison.OrdinalIgnoreCase)) { string value = line.Substring(line.IndexOf('=') + 1).Trim(); value = QuotedStringUtils.Unquote(value); TracksPerCylinder = Conversion.ToInt32(value); } else if (line.StartsWith("ddb.geometry.cylinders", StringComparison.OrdinalIgnoreCase)) { string value = line.Substring(line.IndexOf('=') + 1).Trim(); value = QuotedStringUtils.Unquote(value); Cylinders = Conversion.ToInt64(value); } } }
private static int IndexOfArgumentSeparator(string str, int startIndex) { var index = QuotedStringUtils.IndexOfUnquotedChar(str, ' ', startIndex); if (index >= 0) { while (index + 1 < str.Length && str[index + 1] == ' ') { index++; } } return(index); }
public static List <string> GetCommaSeparatedValues(string value) { int commentIndex = QuotedStringUtils.IndexOfUnquotedChar(value, ';'); if (commentIndex >= 0) { value = value.Substring(0, commentIndex); } List <string> values = QuotedStringUtils.SplitIgnoreQuotedSeparators(value, ','); for (int index = 0; index < values.Count; index++) { values[index] = values[index].Trim(); } return(values); }
/// <returns> /// Null if the diskID entry was not found, /// otherwise, the path is supposed to be in the following form: '\WinNT' /// </returns> private static string GeSourceDiskPath(INIFile pnpDriverInf, string diskID, string architectureIdentifier) { var values = pnpDriverInf.GetValuesOfKeyInSection("SourceDisksNames." + architectureIdentifier, diskID); if (values.Count == 0) { values = pnpDriverInf.GetValuesOfKeyInSection("SourceDisksNames", diskID); } if (values.Count > 0) { // diskid = disk-description[,[tag-or-cab-file],[unused],[path],[flags][,tag-file]] var path = INIFile.TryGetValue(values, 3); // Quoted path is allowed (example: SiS 900-Based PCI Fast Ethernet Adapter driver, version 2.0.1039.1190) return(QuotedStringUtils.Unquote(path)); } return(null); }
public static VirtualMachineDiskExtentEntry ParseEntry(string line) { VirtualMachineDiskExtentEntry entry = new VirtualMachineDiskExtentEntry(); List <string> parts = QuotedStringUtils.SplitIgnoreQuotedSeparators(line, ' '); if (String.Equals(parts[0], "RW", StringComparison.InvariantCultureIgnoreCase)) { entry.WriteAccess = true; entry.ReadAccess = true; } else if (String.Equals(parts[0], "RDONLY", StringComparison.InvariantCultureIgnoreCase)) { entry.ReadAccess = true; } entry.SizeInSectors = Conversion.ToInt64(parts[1]); entry.ExtentType = GetExtentTypeFromString(parts[2]); entry.FileName = QuotedStringUtils.Unquote(parts[3]); if (parts.Count > 4) { entry.Offset = Conversion.ToInt64(parts[4]); } return(entry); }
private static int IndexOfUnquotedSpace(string str, int startIndex) { return(QuotedStringUtils.IndexOfUnquotedChar(str, ' ', startIndex)); }
private static void AssignIPAddressToNetDeviceService(NetworkDeviceService netDeviceService, ISystemRegistryHive systemRegistryHive, IPAddress ipAddress, IPAddress subnetMask, IPAddress defaultGateway) { var netCfgInstanceID = netDeviceService.NetCfgInstanceID; var adapterKeyName = @"Parameters\Adapters\" + netCfgInstanceID; var adapterIPConfig = @"Tcpip\Parameters\Interfaces\" + netCfgInstanceID; var interfaceKeyName = @"Parameters\Interfaces\" + netCfgInstanceID; // this is some kind of reference to where the actual TCP/IP configuration is located systemRegistryHive.SetServiceRegistryKey("Tcpip", adapterKeyName, "IpConfig", RegistryValueKind.MultiString, new[] { adapterIPConfig }); // DefaultGateway is not necessary for most people, but can ease the installation for people with complex networks systemRegistryHive.SetServiceRegistryKey("Tcpip", interfaceKeyName, "DefaultGateway", RegistryValueKind.MultiString, new[] { defaultGateway.ToString() }); // Extracurricular note: it's possible to use more than one IP address, but you have to specify subnet mask for it as well. systemRegistryHive.SetServiceRegistryKey("Tcpip", interfaceKeyName, "IPAddress", RegistryValueKind.MultiString, new[] { ipAddress.ToString() }); systemRegistryHive.SetServiceRegistryKey("Tcpip", interfaceKeyName, "SubnetMask", RegistryValueKind.MultiString, new[] { subnetMask.ToString() }); // Note related to GUI mode: // We already bind the device class instance to NetCfgInstanceID, and that's all that's necessary for TCP/IP to work during text-mode. // However, TCP/IP must be bound to NetCfgInstanceID as well, TCP/IP will work in GUI mode without it, but setup will fail at T-39 // with the following error: "setup was unable to initialize Network installation components. the specific error code is 2" // and in the subsequent screen: "LoadLibrary returned error 1114 (45a)" (related to netman.dll, netshell.dll) // The first component in one entry corresponds to the first component in the other entries: systemRegistryHive.SetServiceRegistryKey("Tcpip", "Linkage", "Bind", RegistryValueKind.MultiString, new[] { @"\DEVICE\" + netCfgInstanceID }); systemRegistryHive.SetServiceRegistryKey("Tcpip", "Linkage", "Export", RegistryValueKind.MultiString, new[] { @"\DEVICE\TCPIP_" + netCfgInstanceID }); // NetCfgInstanceID should be quoted, HiveSystemInf should take care of the use of quote characters (special character): systemRegistryHive.SetServiceRegistryKey("Tcpip", "Linkage", "Route", RegistryValueKind.MultiString, new[] { QuotedStringUtils.Quote(netCfgInstanceID) }); }
public static string Unquote(string str) { return(QuotedStringUtils.Unquote(str)); }
protected static string Quote(string str) { return(QuotedStringUtils.Quote(str)); }