/// <summary> /// Returns an instance of <see cref="InstallerDescription"/> built from data read from the given <paramref name="line"/>. /// If no instance can be build, null is returned. /// </summary> /// <param name="line"></param> /// <returns></returns> private static InstallerDescription ReadInstallerDescriptionFromLine(string line) { string irTypeString, irId, irDescr; if (!ReadValue(line, "Installer", null, out line) || !ReadValue(line, "Type", "\"", out irTypeString) || !ReadValue(line, "Id", "\"", out irId) || !ReadValue(line, "Description", "\"", out irDescr)) { return(null); } InstallerType irType; if (!ParserHelper.TryParseEnum(irTypeString, out irType)) { return(null); } if (irType == InstallerType.File && File.Exists(irId)) { return(InstallerDescription.CreateForFile(irDescr, irId)); } if (irType == InstallerType.OpaqueString) { return(InstallerDescription.CreateForOpaqueString(irDescr, irId)); } if (irType == InstallerType.Installer) { return(InstallerDescription.CreateForInstaller(irDescr, irId)); } return(null); }
/// <summary> /// Returns an <see cref="InstallerDescription"/> built from data read from the specified registry key. /// </summary> /// <exception cref="ArgumentException"> /// An <see cref="ArgumentException"/> is thrown if any of the values specified in the registrykey is invalid. /// </exception> /// <param name="regKey"></param></param> /// <returns></returns> private static InstallerDescription ReadInstallerDescription(RegistryKey regKey) { var tmp = regKey.GetValue("type"); if (tmp == null) { throw new ArgumentException("The specified registry key doesn't contain a value for \"type\"", "regKey"); } var id = regKey.GetValue("id"); if (id == null) { throw new ArgumentException("The specified registry key doesn't contain a value for \"id\"", "regKey"); } var descr = regKey.GetValue("descr"); if (descr == null) { throw new ArgumentException("The specified registry key doesn't contain a value for \"descr\"", "regKey"); } InstallerType type; if (!ParserHelper.TryParseEnum(tmp.ToString(), out type)) { throw new ArgumentException("The specified registry key contains an invalid value for \"type\"", "regKey"); } switch (type) { case InstallerType.File: return(InstallerDescription.CreateForFile(descr.ToString(), id.ToString())); case InstallerType.Installer: return(InstallerDescription.CreateForInstaller(descr.ToString(), id.ToString())); case InstallerType.OpaqueString: return(InstallerDescription.CreateForOpaqueString(descr.ToString(), id.ToString())); } throw new Exception(); }