/// <summary> /// Makes the self-extracting archive. /// </summary> /// <param name="archive">The archive stream.</param> /// <param name="settings">The sfx settings.</param> /// <param name="sfxFileName">The name of the self-extracting executable.</param> public void MakeSfx(Stream archive, SfxSettings settings, string sfxFileName) { using (Stream sfxStream = File.Create(sfxFileName)) { MakeSfx(archive, settings, sfxStream); } }
/// <summary> /// Validates the sfx scenario commands. /// </summary> /// <param name="settings">The sfx settings dictionary to validate.</param> private void ValidateSettings(SfxSettings settings) { if (_module == SfxModule.Custom) { return; } List <string> commands = _sfxCommands[_module]; if (commands == null) { return; } var invalidCommands = new List <string>(); foreach (string command in settings.Keys) { if (!commands.Contains(command)) { invalidCommands.Add(command); } } if (invalidCommands.Count > 0) { var invalidText = new StringBuilder("\nInvalid commands:\n"); foreach (string str in invalidCommands) { invalidText.Append(str); } throw new KCompressSfxValidationException(invalidText.ToString()); } }
/// <summary> /// Makes the self-extracting archive. /// </summary> /// <param name="archiveFileName">The archive file name.</param> /// <param name="settings">The sfx settings.</param> /// <param name="sfxStream">The stream to write the self-extracting executable to.</param> public void MakeSfx(string archiveFileName, SfxSettings settings, Stream sfxStream) { using (Stream archive = new FileStream(archiveFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite) ) { MakeSfx(archive, settings, sfxStream); } }
/// <summary> /// Gets the stream containing the sfx settings. /// </summary> /// <param name="settings">The sfx settings dictionary.</param> /// <returns></returns> private static Stream GetSettingsStream(SfxSettings settings) { var ms = new MemoryStream(); byte[] buf = Encoding.UTF8.GetBytes(@";!@Install@!UTF-8!" + '\n'); ms.Write(buf, 0, buf.Length); foreach (string command in settings.Keys) { buf = Encoding.UTF8.GetBytes(String.Format(CultureInfo.InvariantCulture, "{0}=\"{1}\"\n", command, settings[command])); ms.Write(buf, 0, buf.Length); } buf = Encoding.UTF8.GetBytes(@";!@InstallEnd@!"); ms.Write(buf, 0, buf.Length); return(ms); }
/// <summary> /// Makes the self-extracting archive. /// </summary> /// <param name="archive">The archive stream.</param> /// <param name="settings">The sfx settings.</param> /// <param name="sfxStream">The stream to write the self-extracting executable to.</param> public void MakeSfx(Stream archive, SfxSettings settings, Stream sfxStream) { if (!sfxStream.CanWrite) { throw new ArgumentException("The specified output stream can not write.", "sfxStream"); } ValidateSettings(settings); using (Stream sfx = _module == SfxModule.Default ? Assembly.GetExecutingAssembly().GetManifestResourceStream( GetResourceString(SfxSupportedModuleNames[_module][0])) : new FileStream(_moduleFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { WriteStream(sfx, sfxStream); } if (_module == SfxModule.Custom || _sfxCommands[_module] != null) { using (Stream set = GetSettingsStream(settings)) { WriteStream(set, sfxStream); } } WriteStream(archive, sfxStream); }
/// <summary> /// Gets the stream containing the sfx settings. /// </summary> /// <param name="settings">The sfx settings dictionary.</param> /// <returns></returns> private static Stream GetSettingsStream(SfxSettings settings) { var ms = new MemoryStream(); byte[] buf = Encoding.UTF8.GetBytes(@";!@Install@!UTF-8!" + '\n'); ms.Write(buf, 0, buf.Length); foreach (string command in settings.Keys) { buf = Encoding.UTF8.GetBytes(String.Format(CultureInfo.InvariantCulture, "{0}=\"{1}\"\n", command, settings[command])); ms.Write(buf, 0, buf.Length); } buf = Encoding.UTF8.GetBytes(@";!@InstallEnd@!"); ms.Write(buf, 0, buf.Length); return ms; }
/// <summary> /// Validates the sfx scenario commands. /// </summary> /// <param name="settings">The sfx settings dictionary to validate.</param> private void ValidateSettings(SfxSettings settings) { if (_module == SfxModule.Custom) { return; } List<string> commands = _sfxCommands[_module]; if (commands == null) { return; } var invalidCommands = new List<string>(); foreach (string command in settings.Keys) { if (!commands.Contains(command)) { invalidCommands.Add(command); } } if (invalidCommands.Count > 0) { var invalidText = new StringBuilder("\nInvalid commands:\n"); foreach (string str in invalidCommands) { invalidText.Append(str); } throw new SevenZipSfxValidationException(invalidText.ToString()); } }