Créer des archives SFX auto-extractibles

Aspose.ZIP permet de créer une archive auto-extractible (SFX). Il s’agit d’un type spécial de fichier zippé, dont le nom de fichier porte l’extension .exe. Vous pouvez décompresser un fichier auto-extractible en double-cliquant dessus.

Création d’une archive auto-extractible

Pour composer une archive auto-extractible, instanciez SelfExtractorOptions et passez-le à ArchiveSaveOptions lors de l’enregistrement.

1try (FileOutputStream zipFile = new FileOutputStream("archive.exe")) {
2    try (Archive archive = new Archive()) {
3        archive.createEntry("entry.bin", "data.bin") ;
4        ArchiveSaveOptions options = new ArchiveSaveOptions() ;
5        options.setSelfExtractorOptions(new SelfExtractorOptions()) ;
6        archive.save(zipFile, options) ;
7    }
8} catch (IOException ex) {
9}

Exécution d’une archive auto-extractible

L’archive que vous produisez est exécutable et nécessite .NET Framework 2.0 ou supérieur pour fonctionner. Ces cadres sont fournis avec Windows Vista et les versions supérieures. Vous pouvez l’exécuter comme un programme normal en double-cliquant dessus, ou l’exécuter via l’interface de ligne de commande. Si vous souhaitez démarrer l’extraction automatiquement, spécifiez l’option de ligne de commande -autoExtract. Exemple :

1C:\>archive.exe -autoExtract -password:T0p$ecret

Options de ligne de commande pour les archives auto-extractibles

OptionMeaningSample
-autoExtract

Primary option - without it decompression does not start.

Extraction starts automatically, other options apply.

sfx.exe -autoExtract
-autoCloseWindow closes when the extraction is complete. This option only makes sense if -autoExtract option is present.sfx.exe -autoExtract -autoClose
-forceOverwriteOverwrites all existing files without prompt if there are any. This option only makes sense if -autoExtract option present.sfx.exe -autoExtract -forceOverwrite
-password:

Provides a password to encrypted entries. This option only makes sense if -autoExtract option is present.

If you have spaces within the password quote it.

sfx.exe -autoExtract -password:T0p$ecret
-destination:

Extracts files to the supplied directory. This option only makes sense if -autoExtract option is present.

If you have spaces within the path quote it.

sfx.exe -autoExtract -destination:"C:\My Documents"

Vous pouvez utiliser ces options pour composer des Batch Script sous Windows.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.