rikyoz / bit7z

A C++ static library offering a clean and simple interface to the 7-zip shared libraries.
https://rikyoz.github.io/bit7z
Mozilla Public License 2.0
634 stars 116 forks source link

[Feature Request]: Exception too long path #151

Closed anywhereyang closed 1 year ago

anywhereyang commented 1 year ago

Feature description

23.7z has one file: safasfffasfafasafasfffasfafasafasfffasfafasafasfffasfafasafasfffasfafasafasfffasfafasafasfffasfafasafasfffasfafasafasfffasfafasafasfffasfafasafasfffasfafasafasfffasfafasafasfffasfafasafasfffasfafasafasfffasfafasafa.txt

and the code will exception:

void Test() { try { bit7z::Bit7zLibrary lib{ L"7z.dll" }; bit7z::BitExtractor extractor{ lib, bit7z::BitFormat::SevenZip }; extractor.extract(LR"(D:\Code\Game\Cef109\Bin\temp\23.7z)", LR"(D:\Code\Game\Cef109\Bin\temp\saddfsddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd)"); } catch (const bit7z::BitException& e) { MessageBoxA(0,e.what(), "error", 0); int c = 0; } }

Additional context

No response

Code of Conduct

rikyoz commented 1 year ago

Hi! You can build and use bit7z with the BIT7Z_AUTO_PREFIX_LONG_PATHS option enabled to make the library correctly handle long paths on Windows. It should fix your issue!

anywhereyang commented 1 year ago

i downlaod bit7z-3.2.0.zip,and search 'BIT7Z_AUTO_PREFIX_LONG_PATHS' in the source files ,but not found,,how to use ?

rikyoz commented 1 year ago

Sorry, I thought you were using the latest v4 release candidate, which introduced the BIT7Z_AUTO_PREFIX_LONG_PATHS option. Unfortunately, the v3.2 doesn't support such an option. When dealing with long paths, one possible workaround is to prepend the string \\?\ (\\\\?\\ escaped) to every path string you use (https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry). E.g.:

extractor.extract(LR"(\\?\D:\Code\Game\Cef109\Bin\temp\23.7z)", LR"(\\?\D:\Code\Game\Cef109\Bin\temp\saddfsddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd)");
anywhereyang commented 1 year ago

ok,thanks

rikyoz commented 1 year ago

You're welcome!