Skip to content

Commit

Permalink
-DUNRAR config option to allow using libunrar + unrar instead of bund…
Browse files Browse the repository at this point in the history
…led sources or not using unrar at all (touch #977790)
  • Loading branch information
elfmz committed Feb 14, 2023
1 parent d8fbdd0 commit f399cb6
Show file tree
Hide file tree
Showing 8 changed files with 265 additions and 85 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Expand Up @@ -88,6 +88,10 @@ if (NOT DEFINED USEWX)
set(USEWX "YES")
endif()

if (NOT DEFINED UNRAR)
set(UNRAR "bundled")
endif()

# EACP disabled by default for now as FAR's GetCodePageInfo rejects all multibyte charsets due to BUGBUG.
# Uncomment EACP-stuff here when that will be fixed. See https://github.com/elfmz/far2l/issues/1179
#if (NOT DEFINED EACP)
Expand Down
12 changes: 9 additions & 3 deletions README.md
Expand Up @@ -39,6 +39,7 @@ FreeBSD/MacOS (Cirrus CI): [![Cirrus](https://api.cirrus-ci.com/github/elfmz/far
* libnfs-dev (needed for NetRocks/NFS)
* libneon27-dev (or later, needed for NetRocks/WebDAV)
* libarchive-dev (needed for better archives support in multiarc)
* libunrar-dev (optionally needed for RAR archives support in multiarc - see UNRAR command line option)
* libpcre3-dev (or in older distributives - libpcre2-dev) (needed for custom archives support in multiarc)
* cmake ( >= 3.2.2 )
* g++
Expand Down Expand Up @@ -78,13 +79,18 @@ cmake --build .

##### Additional build configuration options:

To build without WX backend (console version only): change -DUSEWX=yes to -DUSEWX=no also in this case dont need to install libwxgtk\*-dev package
To build without WX backend (console version only): change `-DUSEWX=yes` to `-DUSEWX=no` also in this case dont need to install libwxgtk\*-dev package

To force-disable TTY|X and TTY|Xi backends: add argument -DTTYX=no; to disable only TTY|Xi - add argument -DTTYXI=no
To force-disable TTY|X and TTY|Xi backends: add argument `-DTTYX=no`; to disable only TTY|Xi - add argument `-DTTYXI=no`

To eliminate libuchardet requirement to reduce far2l dependencies by cost of losing automatic charset detection functionality: add -DUSEUCD=no

To build with Python plugin: add argument -DPYTHON=yes
To build with Python plugin: add argument `-DPYTHON=yes`

To control how RAR archives will be handled in multiarc:
`-DUNRAR=bundled` (default) use bundled sources found in multiarc/src/formats/rar/unrar
`-DUNRAR=lib` use libunrar and unrar utility, also build requires libunrar-dev to be installed
`-DUNRAR=NO` dont use special unrar code, rar archives will be handled by libarchive unless its also disabled

There're also options to toggle other plugins build in same way: ALIGN AUTOWRAP CALC COLORER COMPARE DRAWLINE EDITCASE EDITORCOMP FARFTP FILECASE INCSRCH INSIDE MULTIARC NETROCKS SIMPLEINDENT TMPPANEL

Expand Down
30 changes: 30 additions & 0 deletions cmake/modules/FindUnrar.cmake
@@ -0,0 +1,30 @@
# - Find unrar
# Find the native UNRAR includes and library
#
# UNRAR_INCLUDE_DIR - where to find rar.hpp, etc.
# UNRAR_LIBRARIES - List of libraries when using unrar.
# UNRAR_FOUND - True if unrar found.


IF (UNRAR_INCLUDE_DIR)
# Already in cache, be silent
SET(UNRAR_FIND_QUIETLY TRUE)
ENDIF (UNRAR_INCLUDE_DIR)

FIND_PATH(UNRAR_INCLUDE_DIR rar.hpp PATH_SUFFIXES unrar)

SET(UNRAR_NAMES unrar)
FIND_LIBRARY(UNRAR_LIBRARY NAMES ${UNRAR_NAMES} )

# handle the QUIETLY and REQUIRED arguments and set UNRAR_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Unrar DEFAULT_MSG UNRAR_LIBRARY UNRAR_INCLUDE_DIR)

IF(UNRAR_FOUND)
SET( UNRAR_LIBRARIES ${UNRAR_LIBRARY} )
ELSE(UNRAR_FOUND)
SET( UNRAR_LIBRARIES )
ENDIF(UNRAR_FOUND)

MARK_AS_ADVANCED( UNRAR_LIBRARY UNRAR_INCLUDE_DIR )
134 changes: 79 additions & 55 deletions multiarc/CMakeLists.txt
Expand Up @@ -12,65 +12,12 @@ set(SOURCES
src/global.cpp
src/arcread.cpp
src/arccmd.cpp
src/formats/rar/rar.cpp
src/formats/ha/ha.cpp
src/formats/arj/arj.cpp
src/formats/ace/ace.cpp
src/formats/arc/arc.cpp
src/formats/zip/zip.cpp
src/formats/lzh/lzh.cpp
src/formats/rar/unrar/scantree.cpp
src/formats/rar/unrar/sha1.cpp
src/formats/rar/unrar/threadpool.cpp
src/formats/rar/unrar/crc.cpp
src/formats/rar/unrar/hash.cpp
src/formats/rar/unrar/strlist.cpp
src/formats/rar/unrar/rs16.cpp
src/formats/rar/unrar/resource.cpp
src/formats/rar/unrar/consio.cpp
src/formats/rar/unrar/secpassword.cpp
src/formats/rar/unrar/qopen.cpp
src/formats/rar/unrar/recvol.cpp
src/formats/rar/unrar/rijndael.cpp
src/formats/rar/unrar/timefn.cpp
src/formats/rar/unrar/encname.cpp
src/formats/rar/unrar/rawread.cpp
src/formats/rar/unrar/file.cpp
src/formats/rar/unrar/strfn.cpp
src/formats/rar/unrar/sha256.cpp
src/formats/rar/unrar/filefn.cpp
src/formats/rar/unrar/filcreat.cpp
src/formats/rar/unrar/headers.cpp
src/formats/rar/unrar/blake2s.cpp
src/formats/rar/unrar/options.cpp
src/formats/rar/unrar/volume.cpp
src/formats/rar/unrar/system.cpp
src/formats/rar/unrar/crypt.cpp
src/formats/rar/unrar/rar.cpp
src/formats/rar/unrar/cmddata.cpp
src/formats/rar/unrar/extinfo.cpp
src/formats/rar/unrar/filestr.cpp
src/formats/rar/unrar/ui.cpp
src/formats/rar/unrar/list.cpp
src/formats/rar/unrar/find.cpp
src/formats/rar/unrar/smallfn.cpp
src/formats/rar/unrar/unicode.cpp
src/formats/rar/unrar/pathfn.cpp
src/formats/rar/unrar/global.cpp
src/formats/rar/unrar/rarvm.cpp
src/formats/rar/unrar/getbits.cpp
src/formats/rar/unrar/rs.cpp
src/formats/rar/unrar/errhnd.cpp
src/formats/rar/unrar/archive.cpp
src/formats/rar/unrar/dll.cpp
src/formats/rar/unrar/extract.cpp
src/formats/rar/unrar/match.cpp
src/formats/rar/unrar/unpack.cpp
src/formats/rar/unrar/arcread.cpp
src/formats/rar/unrar/rdwrfn.cpp
src/formats/rar/unrar/rarpch.cpp



src/formats/7z/7z.cpp
src/formats/7z/7zMain.c
Expand Down Expand Up @@ -138,6 +85,69 @@ set(SOURCES
src/formats/ha/ha/swdict.c
)

if("${UNRAR}" STREQUAL "lib")
set(SOURCES
${SOURCES}
src/formats/rar/rar.cpp
src/formats/rar/rarmainstub.cpp
)
elseif(UNRAR)
set(SOURCES
${SOURCES}
src/formats/rar/rar.cpp
src/formats/rar/unrar/scantree.cpp
src/formats/rar/unrar/sha1.cpp
src/formats/rar/unrar/threadpool.cpp
src/formats/rar/unrar/crc.cpp
src/formats/rar/unrar/hash.cpp
src/formats/rar/unrar/strlist.cpp
src/formats/rar/unrar/rs16.cpp
src/formats/rar/unrar/resource.cpp
src/formats/rar/unrar/consio.cpp
src/formats/rar/unrar/secpassword.cpp
src/formats/rar/unrar/qopen.cpp
src/formats/rar/unrar/recvol.cpp
src/formats/rar/unrar/rijndael.cpp
src/formats/rar/unrar/timefn.cpp
src/formats/rar/unrar/encname.cpp
src/formats/rar/unrar/rawread.cpp
src/formats/rar/unrar/file.cpp
src/formats/rar/unrar/strfn.cpp
src/formats/rar/unrar/sha256.cpp
src/formats/rar/unrar/filefn.cpp
src/formats/rar/unrar/filcreat.cpp
src/formats/rar/unrar/headers.cpp
src/formats/rar/unrar/blake2s.cpp
src/formats/rar/unrar/options.cpp
src/formats/rar/unrar/volume.cpp
src/formats/rar/unrar/system.cpp
src/formats/rar/unrar/crypt.cpp
src/formats/rar/unrar/cmddata.cpp
src/formats/rar/unrar/extinfo.cpp
src/formats/rar/unrar/filestr.cpp
src/formats/rar/unrar/ui.cpp
src/formats/rar/unrar/list.cpp
src/formats/rar/unrar/find.cpp
src/formats/rar/unrar/smallfn.cpp
src/formats/rar/unrar/unicode.cpp
src/formats/rar/unrar/pathfn.cpp
src/formats/rar/unrar/global.cpp
src/formats/rar/unrar/rarvm.cpp
src/formats/rar/unrar/getbits.cpp
src/formats/rar/unrar/rs.cpp
src/formats/rar/unrar/errhnd.cpp
src/formats/rar/unrar/archive.cpp
src/formats/rar/unrar/dll.cpp
src/formats/rar/unrar/extract.cpp
src/formats/rar/unrar/match.cpp
src/formats/rar/unrar/unpack.cpp
src/formats/rar/unrar/arcread.cpp
src/formats/rar/unrar/rdwrfn.cpp
src/formats/rar/unrar/rarpch.cpp
src/formats/rar/unrar/rar.cpp
)
endif()

if(PCRE_FOUND)
set(SOURCES
${SOURCES}
Expand Down Expand Up @@ -165,11 +175,25 @@ endif()

add_library (multiarc MODULE ${SOURCES})

target_compile_definitions(multiarc PRIVATE -DRARDLL -D_7ZIP_ST -D_7ZIP_PPMD_SUPPPORT)
target_compile_definitions(multiarc PRIVATE -D_7ZIP_ST -D_7ZIP_PPMD_SUPPPORT)

target_link_libraries(multiarc utils far2l)

target_include_directories(multiarc PRIVATE src/formats/rar/unrar)
if(NOT UNRAR)
message(STATUS "${ColorRed}rar archives support disabled due to UNRAR=${UNRAR}.${ColorNormal}")

elseif("${UNRAR}" STREQUAL "lib")
message(STATUS "Using system unrar - will need libunrar and unrar tool.")
find_package(Unrar REQUIRED)
target_include_directories(multiarc PRIVATE ${UNRAR_INCLUDE_DIR})
target_compile_definitions(multiarc PRIVATE -DRARDLL -DHAVE_UNRAR)
target_link_libraries(multiarc ${UNRAR_LIBRARIES})
else()
message(STATUS "Using bundled unrar sources")
target_include_directories(multiarc PRIVATE src/formats/rar/unrar)
target_compile_definitions(multiarc PRIVATE -DRARDLL -DHAVE_UNRAR)
endif()

target_include_directories(multiarc PRIVATE src)
target_include_directories(multiarc PRIVATE src/libpcre)
target_include_directories(multiarc PRIVATE ../WinPort)
Expand Down
9 changes: 8 additions & 1 deletion multiarc/src/ArcMix.cpp
Expand Up @@ -101,7 +101,9 @@ const char *GetMsg(int MsgId)
}


#ifdef HAVE_UNRAR
int rar_main(int argc, char *argv[]);
#endif
extern "C" int sevenz_main(int argc, char *argv[]);
extern "C" int ha_main(int argc, char *argv[]);

Expand All @@ -115,8 +117,13 @@ SHAREDSYMBOL int BuiltinMain(int argc, char * argv[])
return -1;

int r = -2;
if (strcmp(argv[0], "rar")==0) {

if (strcmp(argv[0], "7z")==0) {
r = sevenz_main(argc, &argv[0]);
#ifdef HAVE_UNRAR
} else if (strcmp(argv[0], "rar")==0) {
r = rar_main(argc, &argv[0]);
#endif
} else if (strcmp(argv[0], "7z")==0) {
r = sevenz_main(argc, &argv[0]);
} else if (strcmp(argv[0], "ha")==0) {
Expand Down
3 changes: 2 additions & 1 deletion multiarc/src/ArcPlg.cpp
Expand Up @@ -54,9 +54,10 @@ ArcPlugins::ArcPlugins(const char *ModuleName)
AddPluginItem(TARGZ_IsArchive, TARGZ_OpenArchive, TARGZ_GetArcItem, NULL,
TARGZ_CloseArchive, TARGZ_GetFormatName, TARGZ_GetDefaultCommands, TARGZ_SetFarInfo, TARGZ_GetSFXPos);
#endif

#ifdef HAVE_UNRAR
AddPluginItem(RAR_IsArchive, RAR_OpenArchive, RAR_GetArcItem, NULL,
RAR_CloseArchive, RAR_GetFormatName, RAR_GetDefaultCommands, RAR_SetFarInfo, RAR_GetSFXPos);
#endif

AddPluginItem(ZIP_IsArchive, ZIP_OpenArchive, ZIP_GetArcItem, NULL,
ZIP_CloseArchive, ZIP_GetFormatName, ZIP_GetDefaultCommands, NULL, ZIP_GetSFXPos);
Expand Down
26 changes: 1 addition & 25 deletions multiarc/src/formats/rar/rar.cpp
Expand Up @@ -11,6 +11,7 @@

#include <windows.h>
#include <string.h>
#include <assert.h>
#include <farplug-mb.h>
using namespace oldfar;
#include "fmt.hpp"
Expand All @@ -27,29 +28,6 @@ using namespace oldfar;
#pragma pack(push,1)
#endif



#define LHD_LARGE 0x0100
#define LHD_UNICODE 0x0200
#define LHD_SALT 0x0400
#define LHD_EXTTIME 0x1000
#define LHD_WINDOWMASK 0x00e0
#define LHD_DIRECTORY 0x00e0
#define LONG_BLOCK 0x8000

enum HEADER_TYPE {
MARK_HEAD=0x72,
MAIN_HEAD=0x73,
FILE_HEAD=0x74,
COMM_HEAD=0x75,
AV_HEAD=0x76,
SUB_HEAD=0x77,
PROTECT_HEAD=0x78,
SIGN_HEAD=0x79,
NEWSUB_HEAD=0x7a,
ENDARC_HEAD=0x7b
};

static const char * const RarOS[]={"DOS","OS/2","Windows","Unix","MacOS","BeOS"};

static DWORD SFXSize,Flags;
Expand Down Expand Up @@ -309,5 +287,3 @@ BOOL WINAPI _export RAR_GetDefaultCommands(int Type,int Command,char *Dest)
}
return(FALSE);
}


0 comments on commit f399cb6

Please sign in to comment.