Skip to content

Commit 6aa463f

Browse files
committed
Hook up old extraction to Test
1 parent 1980d76 commit 6aa463f

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

Test/Program.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public static void Main(string[] args)
1212
bool extract = true;
1313
bool outputInfo = false;
1414
string outputDirectory = string.Empty;
15+
bool useOld = false;
1516

1617
// If we have no args, show the help and quit
1718
if (args == null || args.Length == 0)
@@ -41,6 +42,10 @@ public static void Main(string[] args)
4142
{
4243
extract = false;
4344
}
45+
else if (arg == "-u" || arg == "--use-old")
46+
{
47+
useOld = true;
48+
}
4449
else if (arg == "-o" || arg == "--output")
4550
{
4651
if (firstFileIndex == args.Length - 1)
@@ -68,9 +73,9 @@ public static void Main(string[] args)
6873
{
6974
string arg = args[i];
7075
if (arg.EndsWith(".cab", StringComparison.OrdinalIgnoreCase))
71-
ProcessCabinetPath(arg, outputInfo, extract, outputDirectory);
76+
ProcessCabinetPath(arg, outputInfo, extract, useOld, outputDirectory);
7277
else if (arg.EndsWith(".hdr", StringComparison.OrdinalIgnoreCase))
73-
ProcessCabinetPath(arg, outputInfo, extract, outputDirectory);
78+
ProcessCabinetPath(arg, outputInfo, extract, useOld, outputDirectory);
7479
else
7580
Console.WriteLine($"{arg} is not a recognized file by extension");
7681
}
@@ -95,6 +100,7 @@ private static void DisplayHelp()
95100
Console.WriteLine(" -i, --info Display cabinet information");
96101
Console.WriteLine(" -n, --no-extract Don't extract the cabinet");
97102
Console.WriteLine(" -o, --output <path> Set the output directory for extraction");
103+
Console.WriteLine(" -u, --use-old Use old extraction method");
98104
Console.WriteLine();
99105
}
100106

@@ -104,7 +110,7 @@ private static void DisplayHelp()
104110
/// <param name="file">Name of the file to process</param>
105111
/// <param name="outputInfo">True to display the cabinet information, false otherwise</param>
106112
/// <param name="outputDirectory">Output directory for extraction</param>
107-
private static void ProcessCabinetPath(string file, bool outputInfo, bool extract, string outputDirectory)
113+
private static void ProcessCabinetPath(string file, bool outputInfo, bool extract, bool useOld, string outputDirectory)
108114
{
109115
if (!File.Exists(file))
110116
{
@@ -178,7 +184,7 @@ private static void ProcessCabinetPath(string file, bool outputInfo, bool extrac
178184
Directory.CreateDirectory(directoryName);
179185

180186
Console.WriteLine($"Outputting file at index {i} to {newfile}...");
181-
cab.FileSave(i, newfile);
187+
cab.FileSave(i, newfile, useOld);
182188
}
183189
}
184190
}

UnshieldSharp/InstallShieldCabinet.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class InstallShieldCabinet
6262
/// <summary>
6363
/// Save the file at the given index to the filename specified
6464
/// </summary>
65-
public bool FileSave(int index, string filename)
65+
public bool FileSave(int index, string filename, bool useOld = false)
6666
{
6767
if (HeaderList == null)
6868
{
@@ -77,7 +77,7 @@ public bool FileSave(int index, string filename)
7777

7878
// If the file is split
7979
if (fileDescriptor.LinkFlags == LinkFlags.LINK_PREV)
80-
return FileSave((int)fileDescriptor.LinkPrevious, filename);
80+
return FileSave((int)fileDescriptor.LinkPrevious, filename, useOld);
8181

8282
// Get the reader at the index
8383
var reader = Reader.Create(this, index, fileDescriptor);
@@ -141,7 +141,10 @@ public bool FileSave(int index, string filename)
141141
ulong readBytes = (ulong)(bytesToRead + 1);
142142

143143
// Uncompress into a buffer
144-
result = Uncompress(outputBuffer, ref bytesToWrite, inputBuffer, ref readBytes);
144+
if (useOld)
145+
result = UncompressOld(outputBuffer, ref bytesToWrite, inputBuffer, ref readBytes);
146+
else
147+
result = Uncompress(outputBuffer, ref bytesToWrite, inputBuffer, ref readBytes);
145148

146149
// If we didn't get a positive result that's not a data error (false positives)
147150
if (result != zlibConst.Z_OK && result != zlibConst.Z_DATA_ERROR)

0 commit comments

Comments
 (0)