From 98ad7dd049a366e21d60a34548736a3c8ef72877 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 30 Dec 2017 04:32:49 +0100 Subject: Add support for windows (ugly fast solution) --- src/Archive.cpp | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'src/Archive.cpp') diff --git a/src/Archive.cpp b/src/Archive.cpp index 08ab42b..506b020 100644 --- a/src/Archive.cpp +++ b/src/Archive.cpp @@ -6,6 +6,14 @@ using namespace std; +#if OS_FAMILY == OS_FAMILY_POSIX +#define archive_read_open_filename_native archive_read_open_filename +#define archive_entry_pathname_native archive_entry_pathname +#else +#define archive_read_open_filename_native archive_read_open_filename_w +#define archive_entry_pathname_native archive_entry_pathname_w +#endif + class FileHandler { DISABLE_COPY(FileHandler) @@ -53,7 +61,7 @@ namespace sibs } } - Result Archive::extract(const char *source, const char *destination) + Result Archive::extract(const _tinydir_char_t *source, const _tinydir_char_t *destination) { struct archive *a; struct archive *ext; @@ -67,7 +75,7 @@ namespace sibs flags |= ARCHIVE_EXTRACT_ACL; flags |= ARCHIVE_EXTRACT_FFLAGS; - string rootName; + FileString rootName; a = archive_read_new(); archive_read_support_format_all(a); @@ -77,10 +85,10 @@ namespace sibs archive_write_disk_set_standard_lookup(ext); - if ((r = archive_read_open_filename(a, source, 10240))) + if ((r = archive_read_open_filename_native(a, source, 10240))) { string errMsg = "Failed to extract archive: "; - errMsg += source; + errMsg += toUtf8(source); return Result::Err(errMsg); } @@ -92,7 +100,7 @@ namespace sibs else if (r < ARCHIVE_OK) { string errMsg = "Failed to extract archive: "; - errMsg += source; + errMsg += toUtf8(source); errMsg += "; reason: "; errMsg += archive_error_string(a); return Result::Err(errMsg); @@ -100,25 +108,27 @@ namespace sibs else if (r < ARCHIVE_WARN) { string errMsg = "Failed to extract archive: "; - errMsg += source; + errMsg += toUtf8(source); errMsg += "; reason: "; errMsg += archive_error_string(a); return Result::Err(errMsg); } - const char* currentFile = archive_entry_pathname(entry); + const _tinydir_char_t* currentFile = archive_entry_pathname_native(entry); if(rootName.empty()) rootName = currentFile; - std::string fullOutputPath = destination; + FileString fullOutputPath = destination; fullOutputPath += (currentFile + (rootName.empty() ? 0 : rootName.size() - 1)); - archive_entry_set_pathname(entry, fullOutputPath.c_str()); + // TODO: Verify if this really works. Why doesn't libarchive have wide string version of archive_entry_set_pathname? + string fullOutputPathUtf8 = toUtf8(fullOutputPath); + archive_entry_set_pathname(entry, fullOutputPathUtf8.c_str()); r = archive_write_header(ext, entry); if (r < ARCHIVE_OK) { string errMsg = "Failed to extract archive: "; - errMsg += source; + errMsg += toUtf8(source); errMsg += "; reason: "; errMsg += archive_error_string(ext); return Result::Err(errMsg); @@ -128,7 +138,7 @@ namespace sibs if (r < ARCHIVE_OK) { string errMsg = "Failed to extract archive: "; - errMsg += source; + errMsg += toUtf8(source); errMsg += "; reason: "; errMsg += archive_error_string(ext); return Result::Err(errMsg); @@ -136,7 +146,7 @@ namespace sibs else if (r < ARCHIVE_WARN) { string errMsg = "Failed to extract archive: "; - errMsg += source; + errMsg += toUtf8(source); errMsg += "; reason: "; errMsg += archive_error_string(ext); return Result::Err(errMsg); @@ -147,7 +157,7 @@ namespace sibs if (r < ARCHIVE_OK) { string errMsg = "Failed to extract archive: "; - errMsg += source; + errMsg += toUtf8(source); errMsg += "; reason: "; errMsg += archive_error_string(ext); return Result::Err(errMsg); @@ -155,7 +165,7 @@ namespace sibs else if (r < ARCHIVE_WARN) { string errMsg = "Failed to extract archive: "; - errMsg += source; + errMsg += toUtf8(source); errMsg += "; reason: "; errMsg += archive_error_string(ext); return Result::Err(errMsg); -- cgit v1.2.3