7-Zip Documentation

repository·main·Indexed 25 days ago

https://github.com/ip7z/7zip

Source 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.

Tokens
10.9K
Snippets
20
Records
49
Agent score
86%

What's inside 7-Zip

  1. Compile 7-Zip for Unix/Linux/macOS

    main

    7-Zip can be compiled on Unix-like systems using gcc or clang via the makefile.gcc file. 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.exe equivalent) using make:

    1. Navigate to the Alone2 bundle directory.
    2. Run make with the -f makefile.gcc flag.

    Use the -j flag to enable parallel builds.

    cd CPP/7zip/Bundles/Alone2
    make -j -f makefile.gcc
  2. Compile 7-Zip with specific compiler optimizations on Linux/macOS

    main

    You can use specific .mak files to compile 7-Zip with optimized code and settings. Navigate to CPP/7zip/Bundles/Alone2 and 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
  3. Compile 7-Zip for Windows using MSVC

    main

    To 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:

    1. Navigate to the source directory.
    2. Initialize the environment using vcvars64.bat.
    3. Run nmake.

    For other platforms, use the corresponding vcvars*.bat files from the VS2022\VC\Auxiliary\Build directory (e.g., vcvarsamd64_arm64.bat).

    cd SRC\CPP\7zip
    %comspec% /k "C:\Program Files\VS2022\VC\Auxiliary\Build\vcvars64.bat"
    nmake
  4. Compile 7-Zip standalone console (7za.exe) on Windows

    main

    To compile a single standalone binary like 7za.exe on Windows, navigate to the specific bundle directory and use nmake.

    cd SRC\CPP\7zip\Bundles\Alone\
    nmake
  5. Configure 7-Zip compilation variables

    main

    When 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"
  6. Configure Benchmark settings in the GUI

    main

    The 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)
  7. Reference: 7-Zip Makefile macro definitions (Windows)

    main

    When using the Windows makefile via nmake, 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.
  8. Reference: 7-Zip Source Package Structure

    main

    The 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).
  9. Generate version info for 7-Zip applications

    main
    Use the MY_VERSION_INFO_APP macro to generate a version resource block specifically for executable files (.exe). It automatically sets the file type to MY_VFT_APP and appends .exe to the original filename.
  10. Perform copy or move operations in CApp

    main

    The CApp::OnCopy method handles the logic for copying or moving files and folders between panels or within the same panel.

    Parameters

    • move: If true, performs a move operation; if false, performs a copy.
    • copyToSame: If true, 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 copyToSame is false, the destination is determined by the other panel (in dual-panel mode) or the current path (in single-panel mode).
    • Dialogs: Displays a CCopyDialog to 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)
  11. Configure CApp toolbar display settings

    main

    The CApp class 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.