예제 #1
0
        public void CreateSfxArchiveTest([Values] SfxModule sfxModule)
        {
            if (sfxModule.HasFlag(SfxModule.Custom))
            {
                Assert.Ignore("No idea how to use SfxModule \"Custom\".");
            }

            var sfxFile    = Path.Combine(OutputDirectory, "sfx.exe");
            var sfx        = new SevenZipSfx(sfxModule);
            var compressor = new SevenZipCompressor {
                DirectoryStructure = false
            };

            compressor.CompressFiles(TemporaryFile, @"TestData\zip.zip");

            sfx.MakeSfx(TemporaryFile, sfxFile);

            Assert.IsTrue(File.Exists(sfxFile));

            using (var extractor = new SevenZipExtractor(sfxFile))
            {
                Assert.AreEqual(1, extractor.FilesCount);
                Assert.AreEqual("zip.zip", extractor.ArchiveFileNames[0]);
            }

            Assert.DoesNotThrow(() =>
            {
                var process = Process.Start(sfxFile);
                process?.Kill();
            });
        }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the KCompressSfx class.
 /// </summary>
 /// <param name="module">The sfx module to use as a front-end.</param>
 public KCompressSfx(SfxModule module)
 {
     if (module == SfxModule.Custom)
     {
         throw new ArgumentException("You must specify the custom module executable.", "module");
     }
     _module = module;
     CommonInit();
 }
 public SevenZipSfx(SfxModule module)
 {
     if (module == SfxModule.Custom)
     {
         throw new ArgumentException("You must specify the custom module executable.", nameof(module));
     }
     this._Module = module;
     this.CommonInit();
 }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the KCompressSfx class.
 /// </summary>
 public KCompressSfx()
 {
     _module = SfxModule.Default;
     CommonInit();
 }
예제 #5
0
 /// <summary>
 /// Loads the commands for each supported sfx module configuration
 /// </summary>
 /// <param name="xmlDefinitions">The resource name for xml definitions</param>
 private void LoadCommandsFromResource(string xmlDefinitions)
 {
     using (Stream cfg = Assembly.GetExecutingAssembly().GetManifestResourceStream(
                GetResourceString(xmlDefinitions + ".xml")))
     {
         if (cfg == null)
         {
             throw new KCompressSfxValidationException("The configuration \"" + xmlDefinitions +
                                                       "\" does not exist.");
         }
         using (Stream schm = Assembly.GetExecutingAssembly().GetManifestResourceStream(
                    GetResourceString(xmlDefinitions + ".xsd")))
         {
             if (schm == null)
             {
                 throw new KCompressSfxValidationException("The configuration schema \"" + xmlDefinitions +
                                                           "\" does not exist.");
             }
             var sc = new XmlSchemaSet();
             using (XmlReader scr = XmlReader.Create(schm))
             {
                 sc.Add(null, scr);
                 var settings = new XmlReaderSettings {
                     ValidationType = ValidationType.Schema, Schemas = sc
                 };
                 string validationErrors = "";
                 settings.ValidationEventHandler +=
                     ((s, t) =>
                 {
                     validationErrors += String.Format(CultureInfo.InvariantCulture, "[{0}]: {1}\n",
                                                       t.Severity.ToString(), t.Message);
                 });
                 using (XmlReader rdr = XmlReader.Create(cfg, settings))
                 {
                     _sfxCommands = new Dictionary <SfxModule, List <string> >();
                     rdr.Read();
                     rdr.Read();
                     rdr.Read();
                     rdr.Read();
                     rdr.Read();
                     rdr.ReadStartElement("sfxConfigs");
                     rdr.Read();
                     do
                     {
                         SfxModule mod = GetModuleByName(rdr["modules"]);
                         rdr.ReadStartElement("config");
                         rdr.Read();
                         if (rdr.Name == "id")
                         {
                             var cmds = new List <string>();
                             _sfxCommands.Add(mod, cmds);
                             do
                             {
                                 cmds.Add(rdr["command"]);
                                 rdr.Read();
                                 rdr.Read();
                             } while (rdr.Name == "id");
                             rdr.ReadEndElement();
                             rdr.Read();
                         }
                         else
                         {
                             _sfxCommands.Add(mod, null);
                         }
                     } while (rdr.Name == "config");
                 }
                 if (!String.IsNullOrEmpty(validationErrors))
                 {
                     throw new KCompressSfxValidationException(
                               "\n" + validationErrors.Substring(0, validationErrors.Length - 1));
                 }
                 _sfxCommands.Add(SfxModule.Default, _sfxCommands[SfxModule.Extended]);
             }
         }
     }
 }
예제 #6
0
 /// <summary>
 /// Initializes a new instance of the KCompressSfx class.
 /// </summary>
 /// <param name="moduleFileName"></param>
 public KCompressSfx(string moduleFileName)
 {
     _module        = SfxModule.Custom;
     ModuleFileName = moduleFileName;
     CommonInit();
 }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of the SevenZipSfx class.
 /// </summary>
 /// <param name="module">The sfx module to use as a front-end.</param>
 public SevenZipSfx(SfxModule module)
 {
     if (module == SfxModule.Custom)
     {
         throw new ArgumentException("You must specify the custom module executable.", "module");
     }
     _module = module;
     CommonInit();
 }
예제 #8
0
 /// <summary>
 /// Initializes a new instance of the SevenZipSfx class.
 /// </summary>
 public SevenZipSfx()
 {
     _module = SfxModule.Default;
     CommonInit();
 }
예제 #9
0
 /// <summary>
 /// Initializes a new instance of the SevenZipSfx class.
 /// </summary>
 /// <param name="moduleFileName"></param>
 public SevenZipSfx(string moduleFileName)
 {
     _module = SfxModule.Custom;
     ModuleFileName = moduleFileName;
     CommonInit();
 }
예제 #10
0
 /// <summary>
 /// Initializes a new instance of the SevenZipSfx class.
 /// </summary>
 public SevenZipSfx()
 {
     _module = SfxModule.Default;
     CommonInit();
 }
예제 #11
0
 /// <summary>
 /// Initializes a new instance of the SevenZipSfx class.
 /// </summary>
 /// <param name="moduleFileName"></param>
 public SevenZipSfx(string moduleFileName)
 {
     _module        = SfxModule.Custom;
     ModuleFileName = moduleFileName;
     CommonInit();
 }
 public SevenZipSfx(string moduleFileName)
 {
     this._Module        = SfxModule.Custom;
     this.ModuleFileName = moduleFileName;
     this.CommonInit();
 }
 public SevenZipSfx()
 {
     this._Module = SfxModule.Default;
     this.CommonInit();
 }
 private void LoadCommandsFromResource(string xmlDefinitions)
 {
     using (Stream manifestResourceStream1 = Assembly.GetExecutingAssembly().GetManifestResourceStream(SevenZipSfx.GetResourceString(xmlDefinitions + ".xml")))
     {
         if (manifestResourceStream1 == null)
         {
             throw new SevenZipSfxValidationException("The configuration \"" + xmlDefinitions + "\" does not exist.");
         }
         using (Stream manifestResourceStream2 = Assembly.GetExecutingAssembly().GetManifestResourceStream(SevenZipSfx.GetResourceString(xmlDefinitions + ".xsd")))
         {
             if (manifestResourceStream2 == null)
             {
                 throw new SevenZipSfxValidationException("The configuration schema \"" + xmlDefinitions + "\" does not exist.");
             }
             XmlSchemaSet xmlSchemaSet = new XmlSchemaSet();
             using (XmlReader schemaDocument = XmlReader.Create(manifestResourceStream2))
             {
                 xmlSchemaSet.Add((string)null, schemaDocument);
                 XmlReaderSettings settings = new XmlReaderSettings()
                 {
                     ValidationType = ValidationType.Schema, Schemas = xmlSchemaSet
                 };
                 string validationErrors = "";
                 // ISSUE: reference to a compiler-generated field
                 settings.ValidationEventHandler += (ValidationEventHandler)((s, t) => validationErrors += string.Format((IFormatProvider)CultureInfo.InvariantCulture, "[{0}]: {1}\n", new object[2]
                 {
                     (object)t.Severity.ToString(),
                     (object)t.Message
                 }));
                 using (XmlReader xmlReader = XmlReader.Create(manifestResourceStream1, settings))
                 {
                     this._SfxCommands = new Dictionary <SfxModule, List <string> >();
                     xmlReader.Read();
                     xmlReader.Read();
                     xmlReader.Read();
                     xmlReader.Read();
                     xmlReader.Read();
                     xmlReader.ReadStartElement("sfxConfigs");
                     xmlReader.Read();
                     do
                     {
                         SfxModule moduleByName = SevenZipSfx.GetModuleByName(xmlReader["modules"]);
                         xmlReader.ReadStartElement("config");
                         xmlReader.Read();
                         if (xmlReader.Name == "id")
                         {
                             List <string> stringList = new List <string>();
                             this._SfxCommands.Add(moduleByName, stringList);
                             do
                             {
                                 stringList.Add(xmlReader["command"]);
                                 xmlReader.Read();
                                 xmlReader.Read();
                             }while (xmlReader.Name == "id");
                             xmlReader.ReadEndElement();
                             xmlReader.Read();
                         }
                         else
                         {
                             this._SfxCommands.Add(moduleByName, (List <string>)null);
                         }
                     }while (xmlReader.Name == "config");
                 }
                 if (!string.IsNullOrEmpty(validationErrors))
                 {
                     throw new SevenZipSfxValidationException("\n" + validationErrors.Substring(0, validationErrors.Length - 1));
                 }
                 this._SfxCommands.Add(SfxModule.Default, this._SfxCommands[SfxModule.Extended]);
             }
         }
     }
 }