Exemplo n.º 1
0
 /// <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);
     }
 }
Exemplo n.º 2
0
        /// <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());
            }
        }
Exemplo n.º 3
0
 /// <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);
     }
 }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
 /// <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);
 }
Exemplo n.º 6
0
 /// <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);
     }
 }
Exemplo n.º 7
0
 /// <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);
 }
Exemplo n.º 8
0
 /// <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);
     }
 }
Exemplo n.º 9
0
 /// <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;
 }
Exemplo n.º 10
0
 /// <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());
     }
 }