Show progress window with SelfExtractor (Ionic.Zip)

1

I am developing a Setup for some applications and use SelfExtractor to decompress the files and then run the program that installs and configures the application through PostExtractCommandLine .

The problem that I have, is that I can not find a way to see a progress window when the files are being unzipped, the only thing I have achieved is that I see the list of files that are being decompressed, but not report how much is left 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 :

The closest thing to the result I'm looking for is changing the option of Flavor in SelfExtractorSaveOptions :

Flavor = SelfExtractorFlavor.ConsoleApplication : It shows me the console with the list of files that it is decompressing, but it does not show me times or% completed, 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, something that I'm not interested in, what I'm looking for is that it be automatic and show me the progress (since some Zips it takes a while to decompress and it may seem that the application is blocked).

There's also the option Quiet , if I put it in True the windows are hidden, that's why I have it in False .

    
asked by Marc 27.10.2017 в 09:01
source

1 answer

0

I have found the solution to the problem that I pose:

Looking at the Source Code of DotNewZip I've seen that, setting the SelfExtractorSaveOptions as Flavor = SelfExtractorFlavor.WinFormsApplication and adding that Quiet = true the application shows a window with progress bars which are not interactive with the user, that is, they are only visible and can not interact with the controls of the form.

The code would look like this:

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.WinFormsApplication,
    IconFile = "icono.ico",
    PostExtractCommandLine = (oFvi.OriginalFilename + " " +  
        PostExtractCommandLineParams).Trim(),
    ProductName = oFvi.ProductName,
    ProductVersion = oFvi.ProductVersion,
    Quiet = true,
    RemoveUnpackedFilesAfterExecute = true,
    SfxExeWindowTitle = ""
};
    
answered by 07.11.2017 / 11:55
source