aboutsummaryrefslogtreecommitdiff
path: root/src/Archive.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2017-12-30 04:32:49 +0100
committerdec05eba <dec05eba@protonmail.com>2017-12-30 05:08:10 +0100
commit98ad7dd049a366e21d60a34548736a3c8ef72877 (patch)
tree45e34eb02f6be9f9130a870a19ef1533e24bf343 /src/Archive.cpp
parent1f583ebb6e3973c992d59886659bf53ff87f41de (diff)
Add support for windows (ugly fast solution)
Diffstat (limited to 'src/Archive.cpp')
-rw-r--r--src/Archive.cpp38
1 files changed, 24 insertions, 14 deletions
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<bool> Archive::extract(const char *source, const char *destination)
+ Result<bool> 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<bool>::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<bool>::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<bool>::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<bool>::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<bool>::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<bool>::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<bool>::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<bool>::Err(errMsg);