I am developing a Setup for some applications and I use SelfExtractor to unzip the files and then run the program that installs and configures the application through PostExtractCommandLine
.
The problem I have is that I cannot find a way to display a progress window when the files are being decompressed, the only thing I have achieved is that the list of files that are being decompressed appears, but it does not report how much remains to finish (in % or in time).
My code:
private static void createSetup(string sVersion, string sModule, string sSetupExeName,
string sDescription, string sPathIn, string sPathOut,
string PostExtractCommandLineParams, string[] sInterfaces, string sInterfaceFile,
string[] sLanguages, string sLanguage)
{
CultureInfo ci = new CultureInfo("en-US");
string nameComponentProduct = sSetupExeName.Replace(".exe", "");
Console.WriteLine("");
Console.WriteLine("Starting " + sModule + "-" + sSetupExeName + "-" +
PostExtractCommandLineParams + "-" + sLanguage);
oFvi = FileVersionInfo.GetVersionInfo(Path.Combine(sPathIn, sSetupExeName));
SelfExtractorSaveOptions options = new SelfExtractorSaveOptions
{
//AdditionalCompilerSwitches = "",
Copyright = String.Format(oFvi.LegalCopyright, P.Year, P.Company),
DefaultExtractDirectory = "",
Description = oFvi.FileDescription,
ExtractExistingFile = ExtractExistingFileAction.OverwriteSilently,
FileVersion = new Version(P.Version),
Flavor = SelfExtractorFlavor.ConsoleApplication,
IconFile = "icono.ico",
PostExtractCommandLine = (oFvi.OriginalFilename + " " +
PostExtractCommandLineParams).Trim(),
ProductName = oFvi.ProductName,
ProductVersion = oFvi.ProductVersion,
Quiet = false,
RemoveUnpackedFilesAfterExecute = true,
SfxExeWindowTitle = ""
};
if (sLanguages != null)
{
string[] split = sLanguage.Split(new Char[] { '_' });
string lang = split[0];
string region = split[1];
ci = new CultureInfo(lang + "-" + region);
options.Description = String.Format(oFvi.FileDescription, P.Version,
ci.EnglishName);
string sLang = sLanguage.Substring(3);
if (sLang == "US") sLang = "EN";
sPathOut = Path.Combine(sPathOut, "NombreApp_" + sModule + "_" + sLang + ".exe");
}
else
sPathOut = Path.Combine(sPathOut, "NombreApp_" + sModule + ".exe");
string DefaultExtractDirectory = Path.Combine(P.PathTmp, nameComponentProduct);
if (Directory.Exists(DefaultExtractDirectory))
System.IO.Directory.Delete(DefaultExtractDirectory, true);
using (ZipFile zip = new ZipFile())
{
zip.StatusMessageTextWriter = System.Console.Out;
zip.AddDirectory(sPathIn, "");
if (sLanguages != null)
zip.Comment = String.Format(oFvi.Comments, ci.EnglishName, PV.Version);
else
zip.Comment = String.Format(oFvi.Comments, P.Version);
options.Description = sDescription + " " + sVersion;
options.DefaultExtractDirectory = DefaultExtractDirectory;
options.SfxExeWindowTitle = String.Format("Extracting {0} ...",
options.Description);
zip.RemoveSelectedEntries("log/*");
zip.RemoveSelectedEntries("*.pdb");
if (sLanguages != null)
{
DefaultExtractDirectory = Path.Combine(P.PathTmp,
Path.Combine(nameComponentProduct, sLanguage));
options.PostExtractCommandLine = sSetupExeName + " " + sLanguage;
foreach (string sLanguage2 in sLanguages)
if (sLanguage != sLanguage2)
zip.RemoveSelectedEntries("*pk_" + sLanguage2 + ".zip");
}
if (sInterfaces != null)
{
foreach (string sInterfaz in sInterfaces)
if (sInterfaz != sInterfaceFile)
zip.RemoveSelectedEntries("*" + sInterfaz);
}
zip.SaveSelfExtractor(sPathOut, options);
}
Console.WriteLine("END.");
Console.WriteLine("");
}
EDIT :
What has come closest to the result I'm looking for is to change the option Flavor
in the SelfExtractorSaveOptions
:
Flavor = SelfExtractorFlavor.ConsoleApplication
: It shows me the console with the list of files that it is decompressing, but it doesn't show me times or % complete, which is what I'm looking for.
Flavor = SelfExtractorFlavor.WinFormsApplication
: It shows me the user interface, with the extraction options and a button to execute the extraction, which doesn't interest me, what I want is for it to be automatic and show me the progress (since some Zips take a while to unzip and may appear to crash the app).
There is also the option Quiet
, if I put it in True
the windows are hidden, that's why I have it in False
.
I have found the solution to my problem:
Looking at the Source Code of
DotNetZip
I have seen that, configuring theSelfExtractorSaveOptions
asFlavor = SelfExtractorFlavor.WinFormsApplication
and adding thatQuiet = true
the application shows a window with progress bars which are not interactive with the user, that is, they are only visible and cannot be interacted with the form controls.The code would be as follows: