7-Zip Documentation
repository·main·Indexed 25 days ago
https://github.com/ip7z/7zipSource code and technical reference for 7-Zip, a file archiver with a high compression ratio. Includes detailed documentation on the command-line interface (CLI) syntax and switches, GUI resource macros for Windows executables and DLLs, and the CApp class for managing the File Manager application, including panel management and file operations.
What's inside 7-Zip
- For official releases, documentation, and the primary website of 7-Zip, visit 7-zip.org.
Compile 7-Zip for Unix/Linux/macOS
main7-Zip can be compiled on Unix-like systems using
gccorclangvia themakefile.gccfile. For optimal performance, it is recommended to use an assembler (Asmc or UASM for x86/x64) to enable optimized code paths.To compile the standalone version (
7zz.exeequivalent) usingmake:- Navigate to the
Alone2bundle directory. - Run
makewith the-f makefile.gccflag.
Use the
-jflag to enable parallel builds.cd CPP/7zip/Bundles/Alone2 make -j -f makefile.gcc- Navigate to the
Compile 7-Zip with specific compiler optimizations on Linux/macOS
mainYou can use specific
.makfiles to compile 7-Zip with optimized code and settings. Navigate toCPP/7zip/Bundles/Alone2and use the following commands:- GCC without assembler:
make -j -f ../../cmpl_gcc.mak - CLANG without assembler:
make -j -f ../../cmpl_clang.mak - x86-64 with asmc assembler:
make -j -f ../../cmpl_gcc_x64.mak - arm64 with assembler:
make -j -f ../../cmpl_gcc_arm64.mak - arm64 for macOS:
make -j -f ../../cmpl_mac_arm64.mak
cd CPP/7zip/Bundles/Alone2 # Example: Compile for x86-64 with asmc make -j -f ../../cmpl_gcc_x64.mak- GCC without assembler:
Compile 7-Zip for Windows using MSVC
mainTo compile 7-Zip binaries for Windows, you need the Visual Studio compiler (2017, 2019, or 2022) and the Windows SDK. You can compile for x86, x64, arm64, and arm platforms.
To compile the full x64 version using Visual Studio 2022, use the following command sequence in a command prompt:
- Navigate to the source directory.
- Initialize the environment using
vcvars64.bat. - Run
nmake.
For other platforms, use the corresponding
vcvars*.batfiles from theVS2022\VC\Auxiliary\Builddirectory (e.g.,vcvarsamd64_arm64.bat).cd SRC\CPP\7zip %comspec% /k "C:\Program Files\VS2022\VC\Auxiliary\Build\vcvars64.bat" nmakeCompile 7-Zip standalone console (7za.exe) on Windows
mainTo compile a single standalone binary like
7za.exeon Windows, navigate to the specific bundle directory and usenmake.cd SRC\CPP\7zip\Bundles\Alone\ nmakeConfigure 7-Zip compilation variables
mainWhen compiling with
makefile.gcc, you can pass several variables to modify the build:USE_JWASM=1: Uses JWasm instead of Asmc (Note: JWasm does not support AES instructions, so C-based AES will be used).DISABLE_RAR=1: Removes all RAR-related code from the compilation.DISABLE_RAR_COMPRESS=1: Removes RAR decompression codecs. 7-Zip will still be able to open RAR archives to list files or extract uncompressed files, but cannot decompress them.IS_X64=1 USE_ASM=1 MY_ASM="$UASM": Used to specify a custom path to the UASM assembler for x86-64 builds.
# Example: Using UASM for x86-64 UASM="$PWD/GccUnixR/uasm" cd "7zip-src/CPP/7zip/Bundles/Alone2" make -f makefile.gcc -j IS_X64=1 USE_ASM=1 MY_ASM="$UASM"Configure Benchmark settings in the GUI
mainThe 7-Zip Benchmark dialog allows users to configure specific parameters for performance testing. The following settings are available via the user interface:
- Dictionary size: Selectable via a combobox (
IDC_BENCH_DICTIONARY). - Number of CPU threads: Selectable via a combobox (
IDC_BENCH_NUM_THREADS). - Number of passes: Selectable via a combobox (
IDC_BENCH_NUM_PASSES).
Users can also control the benchmark execution using the following buttons:
- Restart (
IDB_RESTART) - Stop (
IDB_STOP) - Help (
IDHELP) - Cancel (
IDCANCEL)
- Dictionary size: Selectable via a combobox (
Reference: 7-Zip Makefile macro definitions (Windows)
mainWhen using the Windows
makefilevianmake, the following macros can be defined:PLATFORM: Target architecture. Possible values:x64,x86,arm64,arm,ia64.OLD_COMPILER: Used for older VC compilers (e.g.,MSCV 6.0).MY_DYNAMIC_LINK: Enables dynamic linking to the run-time library (msvcrt.dll). The default is static linking.
Reference: 7-Zip Source Package Structure
mainThe 7-Zip source repository is organized into several key directories:
Asm: Optimized assembler code (CRC, SHA, AES, LZMA decoding).C: C source code.CPP: C++ source code.Bundles: Modules that group other modules into specific binaries:Alone:7za.exe(supports 7z/xz/cab/zip/gzip/bzip2/tar).Alone2:7zz.exe(supports all formats).Alone7z:7zr.exe(supports only 7z).Format7z:7za.dll(standalone .7z support).Format7z:7z.dll(all formats support).
UI: User Interface components:Console:7z.exe(Console version).GUI:7zG.exe(GUI version).FileManager:7zFM.exe(File Manager).
Generate version info for 7-Zip applications
mainUse theMY_VERSION_INFO_APPmacro to generate a version resource block specifically for executable files (.exe). It automatically sets the file type toMY_VFT_APPand appends.exeto the original filename.Perform copy or move operations in CApp
mainThe
CApp::OnCopymethod handles the logic for copying or moving files and folders between panels or within the same panel.Parameters
move: Iftrue, performs a move operation; iffalse, performs a copy.copyToSame: Iftrue, copies the selected item to its own location (effectively duplicating it in the same folder).srcPanelIndex: The index of the panel containing the source items.
Key Behaviors
- Destination Selection: If
copyToSameisfalse, the destination is determined by the other panel (in dual-panel mode) or the current path (in single-panel mode). - Dialogs: Displays a
CCopyDialogto allow the user to confirm or change the destination path. - Temporary Directories: If copying between two different file system providers (e.g., an archive and a disk), it may use a temporary directory (
kTempDirPrefix) as an intermediate step. - History: Updates the copy history with the new destination path.
void CApp::OnCopy(bool move, bool copyToSame, unsigned srcPanelIndex)Configure CApp toolbar display settings
mainThe
CAppclass allows programmatic control over the appearance of the application toolbars. These settings can be toggled and saved to persist across sessions.Toolbar Options:
ShowStandardToolbar: Toggles the standard toolbar.ShowArchiveToolbar: Toggles the archive-specific toolbar.ShowButtonsLables: Toggles whether buttons display text labels.LargeButtons: Toggles between standard and large button sizes.
Methods to apply changes:
SwitchStandardToolbar(): Toggles and saves the standard toolbar state.SwitchArchiveToolbar(): Toggles and saves the archive toolbar state.SwitchButtonsLables(): Toggles and saves the button label state.SwitchLargeButtons(): Toggles and saves the large button state.SaveToolbarChanges(): Explicitly persists current toolbar settings.