For various reasons I use 7z.exe, instead of wrappers, and unzipping looks like this:
var args = new StringBuilder();
args.AppendFormat("x \"{0}\"", source);
args.AppendFormat(" -o\"{0}\"", destination);
args.Append(" -y");
args.AppendFormat(" -p{0}", PassEscape(password)); // the password may contain special characters, etc
var code = ProcessHelper.Run(
new ProcessStartInfo
{
FileName = _zipPath,
Arguments = args.ToString()
},
token,
DefaultTimeout);
error = code != 0 ? ExitCodeTable.GetOrDefault(code, "Unknown 7z error") : null;
return code == 0;
I omit some trivial parts of the code such as ProcessHelper, it just start process and run it to completion. The sample I use for testing contains test password !@#$%^&*()_+";
and using code above it always says the password is wrong.
The function PassEscape is completely unknown to me, because I can't find any info which will help me to completely escape all of those special characters (including other encodings), but currently it is pretty simple:
private static string PassEscape(string input)
{
if (string.IsNullOrEmpty(input))
return input;
var b = new StringBuilder();
b.Append('"');
b.Append(input);
b.Append('"');
return b.ToString();
}
Any help?