Skip to content

Commit

Permalink
Merge pull request tomap#15 from squid-box/tomapGH-3
Browse files Browse the repository at this point in the history
Maybe solved the creation of SFX archives
  • Loading branch information
squid-box authored Jul 31, 2018
2 parents 054f607 + 4d15654 commit d4a46a8
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 41 deletions.
13 changes: 5 additions & 8 deletions SevenZip.Tests/MiscellaneousTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,15 @@ public void SerializationTest()
[Test]
public void CreateSfxArchiveTest()
{
Assert.Ignore("Legacy bug, needs investigation.");

var sfxFile = Path.Combine(OutputDirectory, "sfx.exe");

var sfx = new SevenZipSfx();
var compressor = new SevenZipCompressor();

using (var ms = new MemoryStream())
{
compressor.CompressFiles(ms, @"TestData\zip.zip");
sfx.MakeSfx(ms, sfxFile);
}
var compressor = new SevenZipCompressor {DirectoryStructure = false};

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

sfx.MakeSfx(TemporaryFile, sfxFile);

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

Expand Down
15 changes: 14 additions & 1 deletion SevenZip.Tests/TestBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace SevenZip.Tests
{
using System.IO;
using System.Threading;

using NUnit.Framework;

Expand All @@ -20,7 +21,19 @@ public void SetUp()
[TearDown]
public void TearDown()
{
Directory.Delete(OutputDirectory, true);
// Sometimes the Sfx test locks the .exe file for a few milliseconds.
for (var n = 0; n < 10; n++)
{
try
{
Directory.Delete(OutputDirectory, true);
break;
}
catch
{
Thread.Sleep(20);
}
}
}
}
}
28 changes: 14 additions & 14 deletions SevenZip/SevenZip.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@
<Compile Include="StreamWrappers.cs" />
</ItemGroup>
<ItemGroup>
<None Include="sfx\7zS.sfx" />
<None Include="sfx\7zxSD_All.sfx" />
<EmbeddedResource Include="sfx\7zS.sfx" />
<EmbeddedResource Include="sfx\7zxSD_All.sfx" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="sfx\Configs.xml" />
Expand All @@ -138,10 +138,10 @@
<Content Include="sfx\Configs.xslt" />
</ItemGroup>
<ItemGroup>
<None Include="sfx\7zSD.sfx" />
<None Include="sfx\7zxSD_Deflate.sfx" />
<None Include="sfx\7zxSD_LZMA.sfx" />
<None Include="sfx\7zxSD_PPMd.sfx" />
<EmbeddedResource Include="sfx\7zSD.sfx" />
<EmbeddedResource Include="sfx\7zxSD_Deflate.sfx" />
<EmbeddedResource Include="sfx\7zxSD_LZMA.sfx" />
<EmbeddedResource Include="sfx\7zxSD_PPMd.sfx" />
<EmbeddedResource Include="sfx\Configs.xsd" />
</ItemGroup>
<ItemGroup>
Expand All @@ -156,14 +156,14 @@
<EmbeddedResource Include="arch\Test.txt.xz" />
<EmbeddedResource Include="arch\Test.zip" />
<None Include="SevenZip.snk" />
<None Include="sfx\7z.sfx" />
<None Include="sfx\7zCon.sfx" />
<None Include="sfx\7zxSD_All_x64.sfx" />
<None Include="sfx\7zxSD_Deflate_x64.sfx" />
<None Include="sfx\7zxSD_LZMA2.sfx" />
<None Include="sfx\7zxSD_LZMA2_x64.sfx" />
<None Include="sfx\7zxSD_LZMA_x64.sfx" />
<None Include="sfx\7zxSD_PPMd_x64.sfx" />
<EmbeddedResource Include="sfx\7z.sfx" />
<EmbeddedResource Include="sfx\7zCon.sfx" />
<EmbeddedResource Include="sfx\7zxSD_All_x64.sfx" />
<EmbeddedResource Include="sfx\7zxSD_Deflate_x64.sfx" />
<EmbeddedResource Include="sfx\7zxSD_LZMA2.sfx" />
<EmbeddedResource Include="sfx\7zxSD_LZMA2_x64.sfx" />
<EmbeddedResource Include="sfx\7zxSD_LZMA_x64.sfx" />
<EmbeddedResource Include="sfx\7zxSD_PPMd_x64.sfx" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
Expand Down
41 changes: 26 additions & 15 deletions SevenZip/SevenZipSfx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,30 @@ public enum SfxModule
/// </summary>
public class SevenZipSfx
{
private static readonly Dictionary<SfxModule, List<string>> SfxSupportedModuleNames =
new Dictionary<SfxModule, List<string>>(3)
private static Dictionary<SfxModule, List<string>> SfxSupportedModuleNames
{
get
{
{SfxModule.Default, new List<string>(1) {"7zxSD_All.sfx"}},
{SfxModule.Simple, new List<string>(2) {"7z.sfx", "7zCon.sfx"}},
{SfxModule.Installer, new List<string>(2) {"7zS.sfx", "7zSD.sfx"}},
var result = new Dictionary<SfxModule, List<string>>(3)
{
SfxModule.Extended,
new List<string>(4) {"7zxSD_All.sfx", "7zxSD_Deflate", "7zxSD_LZMA", "7zxSD_PPMd"}
}
};
{SfxModule.Simple, new List<string>(2) {"7z.sfx", "7zCon.sfx"}},
{SfxModule.Installer, new List<string>(2) {"7zS.sfx", "7zSD.sfx"}}
};

if (Environment.Is64BitProcess)
{
result.Add(SfxModule.Default, new List<string>(1) { "7zxSD_All_x64.sfx" });
result.Add(SfxModule.Extended, new List<string>(4) { "7zxSD_All_x64.sfx", "7zxSD_Deflate_x64", "7zxSD_LZMA_x64", "7zxSD_PPMd_x64" });
}
else
{
result.Add(SfxModule.Default, new List<string>(1) { "7zxSD_All.sfx" });
result.Add(SfxModule.Extended, new List<string>(4) { "7zxSD_All.sfx", "7zxSD_Deflate", "7zxSD_LZMA", "7zxSD_PPMd" });
}

return result;
}
}

private SfxModule _module = SfxModule.Default;
private string _moduleFileName;
Expand Down Expand Up @@ -395,21 +408,19 @@ public void MakeSfx(Stream archive, SfxSettings settings, Stream 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))
using (var sfx = Assembly.GetExecutingAssembly().GetManifestResourceStream(GetResourceString(SfxSupportedModuleNames[_module][0])))
{
WriteStream(sfx, sfxStream);
}

if (_module == SfxModule.Custom || _sfxCommands[_module] != null)
{
using (Stream set = GetSettingsStream(settings))
using (var set = GetSettingsStream(settings))
{
WriteStream(set, sfxStream);
}
}

WriteStream(archive, sfxStream);
}

Expand Down
3 changes: 0 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ This is a fork from [tomap's fork](https://github.com/tomap/SevenZipSharp) of th

Issues, suggestions, and Pull Requests are welcome!

## Known issues:
* Self-extracting archives cannot be created.

-------------------------------------------------------------

Original project information below, some information might be outdated or won't apply to this fork:
Expand Down

0 comments on commit d4a46a8

Please sign in to comment.