[Archive] Implementation of callbacks in all async methods.
authorKrzysztof Lachacz <k.lachacz@samsung.com>
Sat, 20 Dec 2014 13:39:57 +0000 (14:39 +0100)
committerPiotr Kosko <p.kosko@samsung.com>
Mon, 29 Dec 2014 12:40:52 +0000 (13:40 +0100)
[Verification] Code compiles without errors.
Archive object is visible in tizen namespace.
Achive TCT passrate is 61% (65 of 106 tests is passed).

Change-Id: I7c8185b0471e6bb4bd5af77dded8945edbe1dd47
Signed-off-by: Krzysztof Lachacz <k.lachacz@samsung.com>
18 files changed:
src/archive/archive_api.js
src/archive/archive_callback_data.cc
src/archive/archive_callback_data.h
src/archive/archive_file.cc
src/archive/archive_file.h
src/archive/archive_file_entry.cc
src/archive/archive_file_entry.h
src/archive/archive_instance.cc
src/archive/archive_manager.cc
src/archive/archive_manager.h
src/archive/defs.h
src/archive/filesystem_file.cc
src/archive/filesystem_file.h
src/archive/old/JSArchiveManager.cpp
src/archive/un_zip.cc
src/archive/un_zip_extract_request.cc
src/archive/zip.cc
src/archive/zip_add_request.cc

index 630edca60a9a08feb63e234f352b0f2eae76ced4..0d0e71c8721cae1b5a10af9eb39ffac98e2295f1 100644 (file)
@@ -6,9 +6,51 @@ var validator_ = xwalk.utils.validator;
 var types_ = validator_.Types;
 var bridge = xwalk.utils.NativeBridge(extension, true);
 
-function throwException_(err) {
-    throw new tizen.WebAPIException(err.code, err.name, err.message);
-}
+function CommonFS() {};
+
+CommonFS.cacheVirtualToReal = {
+    'downloads' : {
+        path : '/opt/usr/media/Downloads'
+    },
+    'documents' : {
+        path : '/opt/usr/media/Documents'
+    },
+    'music' : {
+        path : '/opt/usr/media/Sounds'
+    },
+    'images' : {
+        path : '/opt/usr/media/Images'
+    },
+    'videos' : {
+        path : '/opt/usr/media/Videos'
+    },
+    'ringtones' : {
+        path : '/opt/usr/share/settings/Ringtones'
+    }
+};
+
+CommonFS.toRealPath = function(aPath) {
+    var _fileRealPath = '', _uriPrefix = 'file://', i;
+    if (aPath.indexOf(_uriPrefix) === 0) {
+        _fileRealPath = aPath.substr(_uriPrefix.length);
+    } else if (aPath[0] != '/') {
+        // virtual path$
+        var _pathTokens = aPath.split('/');
+        if (this.cacheVirtualToReal[_pathTokens[0]]
+                && (this.cacheVirtualToReal[_pathTokens[0]].state === undefined || this.cacheVirtualToReal[_pathTokens[0]].state === 'MOUNTED')) {
+            _fileRealPath = this.cacheVirtualToReal[_pathTokens[0]].path;
+            for (i = 1; i < _pathTokens.length; ++i) {
+                _fileRealPath += '/' + _pathTokens[i];
+            }
+        } else {
+            _fileRealPath = aPath;
+        }
+    } else {
+        _fileRealPath = aPath;
+    }
+    console.log("REAL PATH:" + _fileRealPath);
+    return _fileRealPath;
+};
 
 /**
  * Returns new unique opId
@@ -90,11 +132,11 @@ function ArchiveFileEntry(data) {
         throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
     }
 
-    propertyFactory_(this, 'name',           data.name           || "",    Property.E);
-    propertyFactory_(this, 'size',           data.size           || 0,     Property.E);
-    propertyFactory_(this, 'compressedSize', data.compressedSize || 0,     Property.E);
-    propertyFactory_(this, 'modified',       data.modified       || null , Property.E);
-    propertyFactory_(this, '_handle',        data.handle         || -1 );
+    propertyFactory_(this, 'name',           data.name                      || "",    Property.E);
+    propertyFactory_(this, 'size',           data.size                      || 0,     Property.E);
+    propertyFactory_(this, 'compressedSize', data.compressedSize            || 0,     Property.E);
+    propertyFactory_(this, 'modified',       new Date(data.modified * 1000) || null , Property.E);
+    propertyFactory_(this, '_handle',        data.handle                    || -1 );
 }
 
 /**
@@ -102,7 +144,7 @@ function ArchiveFileEntry(data) {
  */
 ArchiveFileEntry.prototype.extract = function () {
     var args = validator_.validateArgs(arguments, [
-        { name: "destDir", type: types_.STRING }, //TODO: add FileReferece validation
+        { name: "destinationDirectory", type: types_.STRING }, //TODO: add FileReferece validation
         { name: "onsuccess", type: types_.FUNCTION, optional: true, nullable: true },
         { name: "onerror", type: types_.FUNCTION, optional: true, nullable: true },
         { name: "onprogress", type: types_.FUNCTION, optional: true, nullable: true },
@@ -114,11 +156,12 @@ ArchiveFileEntry.prototype.extract = function () {
     bridge.async({
         cmd: 'ArchiveFileEntry_extract',
         args: {
-            destDir: args.destDir,
-            stripName: args.stripName,
-            overwrite: args.overwrite,
+            destinationDirectory: CommonFS.toRealPath(args.destinationDirectory),
+            stripName: args.stripName || null,
+            overwrite: args.overwrite || null,
             opId: opId,
-            handle: this._handle
+            handle: this._handle,
+            name: this.name
         }
     }).then({
         success: function () {
@@ -185,11 +228,20 @@ ArchiveFile.prototype.add = function () {
     ]),
     opId = getNextOpId();
 
+    var optionsAttributes = ["destination", "stripSourceDirectory", "compressionLevel"],
+        options = args.options || {};
+
+    for(var i in optionsAttributes) {
+        if (!options[optionsAttributes[i]]) {
+            options[optionsAttributes[i]] = null;
+        }
+    }
+
     bridge.async({
         cmd: 'ArchiveFile_add',
         args: {
-            sourceFile: args.sourceFile,
-            options: args.options || null,
+            sourceFile: CommonFS.toRealPath(args.sourceFile),
+            options: options,
             opId: opId,
             handle: this._handle
         }
@@ -227,19 +279,19 @@ ArchiveFile.prototype.add = function () {
  */
 ArchiveFile.prototype.extractAll = function () {
     var args = validator_.validateArgs(arguments, [
-        { name: "destDir", type: types_.STRING }, //TODO: add FileReferece validation
+        { name: "destinationDirectory", type: types_.STRING }, //TODO: add FileReferece validation
         { name: "onsuccess", type: types_.FUNCTION, optional: true, nullable: true },
         { name: "onerror", type: types_.FUNCTION, optional: true, nullable: true },
         { name: "onprogress", type: types_.FUNCTION, optional: true, nullable: true },
-        { name: "options", type: types_.DICTIONARY, optional: true, nullable: true }
+        { name: "overwrite", type: types_.BOOLEAN, optional: true, nullable: true }
     ]),
     opId = getNextOpId();
 
     bridge.async({
         cmd: 'ArchiveFile_extractAll',
         args: {
-            destDir: args.destDir,
-            options: args.options || null,
+            destinationDirectory: CommonFS.toRealPath(args.destinationDirectory),
+            overwrite: args.overwrite || null,
             opId: opId,
             handle: this._handle
         }
@@ -372,12 +424,21 @@ ArchiveManager.prototype.open = function () {
     ]),
     opId = getNextOpId();
 
+    var optionsAttributes = ["overwrite"],
+        options = args.options || {};
+
+    for(var i in optionsAttributes) {
+        if (!options[optionsAttributes[i]]) {
+            options[optionsAttributes[i]] = null;
+        }
+    }
+
     bridge.async({
         cmd: 'ArchiveManager_open',
         args: {
-            file: args.file,
+            file: CommonFS.toRealPath(args.file),
             mode: args.mode,
-            options: args.options || null,
+            options: options,
             opId: opId
         }
     }).then({
index 207135b756566797bc685930dbd02b19fda8e754..776fe2c06f4c10aa2d972ca3ecc61ccb5b48a744 100755 (executable)
@@ -29,6 +29,8 @@
 #include "un_zip.h"
 #include "zip.h"
 #include "archive_manager.h"
+#include "defs.h"
+#include "archive_instance.h"
 
 namespace extension {
 namespace archive {
@@ -41,8 +43,9 @@ using namespace common;
 
 OperationCallbackData::OperationCallbackData(ArchiveCallbackType callback_type) :
     m_callback_type(callback_type),
-    m_op_id(0),
+    m_op_id(-1),
     m_cid(-1),
+    m_handle(-1),
     m_is_error(false),
     m_is_canceled(false)
 {
@@ -52,8 +55,8 @@ OperationCallbackData::OperationCallbackData(ArchiveCallbackType callback_type)
 OperationCallbackData::~OperationCallbackData()
 {
     LoggerD("Entered");
-    if(m_op_id > 0){
-        //ArchiveManager::getInstance().eraseElementFromArchiveFileMap(m_op_id);
+    if(m_op_id > -1){
+        ArchiveManager::getInstance().eraseElementFromArchiveFileMap(m_op_id);
     }
 }
 
@@ -102,6 +105,16 @@ double OperationCallbackData::getCallbackId() const
     return m_cid;
 }
 
+void OperationCallbackData::setHandle(long handle)
+{
+    m_handle = handle;
+}
+
+long OperationCallbackData::getHandle() const
+{
+    return m_handle;
+}
+
 void OperationCallbackData::setIsCanceled(bool canceled)
 {
     m_is_canceled = canceled;
@@ -198,562 +211,569 @@ void OpenCallbackData::executeOperation(ArchiveFilePtr archive_file_ptr)
         throw UnknownException("g_idle_add fails");
     }
 }
-//
-////----------------------------------------------------------------------------------------
-////GetEntriesCallbackData
-////----------------------------------------------------------------------------------------
-//
-//GetEntriesCallbackData::GetEntriesCallbackData(ArchiveCallbackType callback_type):
-//    OperationCallbackData(callback_type)
-//{
-//    LoggerD("Entered");
-//}
-//GetEntriesCallbackData::~GetEntriesCallbackData()
-//{
-//    LoggerD("Entered");
-//}
-//
-//ArchiveFileEntryPtrMapPtr GetEntriesCallbackData::getEntries() const
-//{
-//    return m_entries;
-//}
-//
-//void GetEntriesCallbackData::setEntries(ArchiveFileEntryPtrMapPtr entries)
-//{
-//    m_entries = entries;
-//}
-//
-//void GetEntriesCallbackData::executeOperation(ArchiveFilePtr archive_file_ptr)
-//{
-//    LoggerD("Entered");
-//
-//    setEntries(archive_file_ptr->getEntryMap());
-//
-//    guint id = g_idle_add(ArchiveFile::getEntriesTaskCompleteCB, this);
-//    if (!id) {
-//        LoggerE("g_idle_add fails");
-//        throw UnknownException("g_idle_add fails");
-//    }
-//}
-//
-////----------------------------------------------------------------------------------------
-////GetEntryByNameCallbackData
-////----------------------------------------------------------------------------------------
-//
-//GetEntryByNameCallbackData::GetEntryByNameCallbackData(ArchiveCallbackType callback_type):
-//    OperationCallbackData(callback_type)
-//{
-//    LoggerD("Entered");
-//}
-//
-//GetEntryByNameCallbackData::~GetEntryByNameCallbackData()
-//{
-//    LoggerD("Entered");
-//}
-//
-//const std::string& GetEntryByNameCallbackData::getName() const
-//{
-//    LoggerD("Entered");
-//    return m_name;
-//}
-//
-//void GetEntryByNameCallbackData::setName(const std::string& name)
-//{
-//    LoggerD("Entered");
-//    m_name = name;
-//}
-//
-//ArchiveFileEntryPtr GetEntryByNameCallbackData::getFileEntry() const
-//{
-//    return m_file_entry;
-//}
-//
-//void GetEntryByNameCallbackData::setFileEntry(ArchiveFileEntryPtr entry)
-//{
-//    m_file_entry = entry;
-//}
-//
-//void GetEntryByNameCallbackData::executeOperation(ArchiveFilePtr archive_file_ptr)
-//{
-//    LoggerD("Entered");
-//
-//    ArchiveFileEntryPtrMapPtr entries = archive_file_ptr->getEntryMap();
-//    auto it = entries->find(getName());
-//
-//    //Not found but if our name does not contain '/'
-//    //try looking for directory with such name
-//    //
-//    if (it == entries->end() && !isDirectoryPath(getName())) {
-//        const std::string try_directory = getName() + "/";
-//        LoggerD("GetEntryByName Trying directory: [%s]", try_directory.c_str());
-//        it = entries->find(try_directory);
-//    }
-//
-//    if (it == entries->end()) {
-//        LoggerE("GetEntryByName Entry with name: [%s] not found", getName().c_str());
-//        LoggerE("Throwing NotFoundException - Entry not found");
-//        throw NotFoundException("Entry not found");
-//    }
-//
-//    setFileEntry(it->second);
-//
-//    guint id = g_idle_add(ArchiveFile::getEntryByNameTaskCompleteCB, this);
-//    if (!id) {
-//        LoggerE("g_idle_add fails");
-//        throw UnknownException("g_idle_add fails");
-//    }
-//}
-//
-////----------------------------------------------------------------------------------------
-////BaseProgressCallback
-////----------------------------------------------------------------------------------------
-//
-//BaseProgressCallback::BaseProgressCallback(ArchiveCallbackType callback_type):
-//    OperationCallbackData(callback_type),
-//    m_overwrite(false)
-//{
-//    LoggerD("Entered");
-//}
-//
-//BaseProgressCallback::~BaseProgressCallback()
-//{
-//    LoggerD("Entered");
-//}
-//
-//bool BaseProgressCallback::getOverwrite() const
-//{
-//    LoggerD("Entered");
-//    return m_overwrite;
-//}
-//
-//void BaseProgressCallback::setOverwrite(bool overwrite)
-//{
-//    LoggerD("Entered");
-//    m_overwrite = overwrite;
-//}
-//
-//struct ProgressHolder
-//{
-//    ProgressHolder() :
-//        overall_progress(0.0),
-//        callback(NULL)
-//    {
-//    };
-//
-//    double overall_progress;
-//    ArchiveFileEntryPtr currently_processed_entry;
-//    BaseProgressCallback* callback;
-//};
-//
-//void BaseProgressCallback::callSuccessCallbackOnMainThread()
-//{
-//    guint id = g_idle_add(BaseProgressCallback::callSuccessCallbackCB,
-//            static_cast<void*>(this));
-//    if (!id) {
-//        LoggerE("g_idle_add fails - success callback will not be called");
-//    }
-//}
-//
-//gboolean BaseProgressCallback::callSuccessCallbackCB(void* data)
-//{
-//    BaseProgressCallback* callback = static_cast<BaseProgressCallback*>(data);
-//    if (!callback) {
-//        LoggerE("callback pointer is NULL");
-//        return false;
-//    }
-//
-//    std::unique_ptr<BaseProgressCallback> cb_ptr(callback);
-//
-//    LoggerW("STUB Not checking if context is still alive");
-//    //JSContextRef context = callback->getContext();
-//    //if (!GlobalContextManager::getInstance()->isAliveGlobalContext(context)) {
-//    //    LoggerE("context closed - unable to call success callback");
-//    //    return false;
-//    //}
-//
-////    try {
-////        callback->callSuccessCallback();
-////    }
-////    catch (const PlatformException &err) {
-////        LoggerE("%s (%s)", err.name().c_str(), err.message().c_str());
-////    }
-////    catch (...) {
-////        LoggerE("Unknown error occurs");
-////    }
-//
-//    callback->setArchiveFile(ArchiveFilePtr());
-//    ArchiveManager::getInstance().eraseElementFromArchiveFileMap(callback->m_op_id);
-//
-//    return false;
-//}
-//
-////void BaseProgressCallback::setProgressCallback(JSValueRef on_progress)
-////{
-////    LoggerD("Entered");
-////    auto ctx = getContext();
-////    if(on_progress && JSValueIsObject(ctx, on_progress)) {
-////        JSObjectRef progress = JSValueToObject(ctx, on_progress, NULL);
-////        this->setCallback(CALLBACK_PROGRESS, progress);
-////    }
-////}
-//
-//void BaseProgressCallback::callProgressCallback(long operationId,
-//        double value,
-//        const std::string& filename)
-//{
-//    LoggerD("Entered");
-//    LoggerW("STUB calling progress callback");
-//
-//    //auto ctx = getContext();
-//    //const int SIZE = 3;
-//    //JSValueRef parameters[SIZE] = {
-//    //        JSUtil::toJSValueRef(ctx, operationId),
-//    //        JSUtil::toJSValueRef(ctx, value),
-//    //        JSUtil::toJSValueRef(ctx, filename)
-//    //    };
-//    //
-//    //this->invokeCallback(CALLBACK_PROGRESS, SIZE, parameters);
-//}
-//
-//void BaseProgressCallback::callProgressCallbackOnMainThread(const double progress,
-//        ArchiveFileEntryPtr current_entry)
-//{
-//    ProgressHolder* ph = new(std::nothrow) ProgressHolder();
-//
-//    if(ph) {
-//        ph->overall_progress = progress;
-//        ph->currently_processed_entry = current_entry;
-//        ph->callback = this;
-//
-//        guint id = g_idle_add(BaseProgressCallback::callProgressCallbackCB,
-//                static_cast<void*>(ph));
-//        if (!id) {
-//            LoggerE("g_idle_add fails");
-//            delete ph;
-//            ph = NULL;
-//        }
-//    } else {
-//        LoggerE("Couldn't allocate ProgressHolder");
-//    }
-//}
-//
-//gboolean BaseProgressCallback::callProgressCallbackCB(void* data)
-//{
-//    ProgressHolder* ph = static_cast<ProgressHolder*>(data);
-//    if (!ph) {
-//        LoggerE("ph is null");
-//        return false;
-//    }
-//
-//    std::unique_ptr<ProgressHolder> ph_ptr(ph);
-//    if (!ph->callback) {
-//        LoggerE("ph->callback is null");
-//        return false;
-//    }
-//
-//    LoggerW("STUB Not checking if context is still alive");
-//    //JSContextRef context = ph->callback->getContext();
-//    //if (!GlobalContextManager::getInstance()->isAliveGlobalContext(context)) {
-//    //    LoggerE("context was closed");
-//    //    return false;
-//    //}
-//
-//    try {
-//        //Error callback is being handled by ArchiveFile queue - see
-//        //ArchiveFile::taskManagerThread function
-//        //
-//        ph->callback->callProgressCallback(
-//                ph->callback->m_op_id,
-//                ph->overall_progress,
-//                ph->currently_processed_entry->getName());
-//    }
-//    catch (const PlatformException &err) {
-//        LoggerE("%s (%s)", err.name().c_str(), err.message().c_str());
-//    }
-//    catch (...) {
-//        LoggerE("Unknown error occurs");
-//    }
-//
-//    return false;
-//}
-//
-////----------------------------------------------------------------------------------------
-////AddProgressCallback
-////----------------------------------------------------------------------------------------
-//
-//AddProgressCallback::AddProgressCallback(ArchiveCallbackType callback_type):
-//    BaseProgressCallback(callback_type)
-//{
-//    LoggerD("Entered");
-//}
-//
-//AddProgressCallback::~AddProgressCallback()
-//{
-//    LoggerD("Entered");
-//}
-//
-//ArchiveFileEntryPtr AddProgressCallback::getFileEntry() const
-//{
-//    LoggerD("Entered");
-//    return m_file_entry;
-//}
-//
-//void AddProgressCallback::setFileEntry(ArchiveFileEntryPtr file_entry)
-//{
-//    LoggerD("Entered");
-//    m_file_entry = file_entry;
-//}
-//
-//void AddProgressCallback::setBasePath(const std::string& path)
-//{
-//    LoggerD("Entered");
-//    m_base_path = path;
-//    m_base_virt_path = filesystem::External::toVirtualPath(m_base_path);
-//    std::string::size_type pos = m_base_virt_path.find(filesystem::Path::getSeparator());
-//    if (pos != std::string::npos)
-//    {
-//        m_base_virt_path = m_base_virt_path.substr(pos + 1);
-//    }
-//    else
-//    {
-//        m_base_virt_path = "";
-//    }
-//}
-//
-//const std::string& AddProgressCallback::getBasePath()
-//{
-//    LoggerD("Entered");
-//    return m_base_path;
-//}
-//
-//const std::string& AddProgressCallback::getBaseVirtualPath()
-//{
-//    LoggerD("Entered");
-//    return m_base_virt_path;
-//}
-//
-//void AddProgressCallback::executeOperation(ArchiveFilePtr archive_file_ptr)
-//{
-//    LoggerD("Entered");
-//
-//    if(!m_file_entry) {
-//        LoggerE("ArchiveFileEntry is not set in callback");
-//        throw UnknownException("Could not add file to archive");
-//    }
-//
-//    if(!archive_file_ptr) {
-//        LoggerE("archive_file_ptr is NULL");
-//        throw UnknownException("Could not extract archive file entry");
-//    }
-//
-//    AddProgressCallback* callback = this;
-//
-//    ZipPtr zip = archive_file_ptr->createZipObject();
-//    zip->addFile(callback);
-//    // Zip is no more needed but it locks file opening while
-//    // it is needed to read entries from file
-//    zip->close();
-//
-//    //We have just finished adding file to archive so now
-//    //this archive file should be valid .zip archive and
-//    //we can remove CreatedAsNewEmptyArchive flag
-//    archive_file_ptr->setCreatedAsNewEmptyArchive(false);
-//
-//    LoggerD("Update decompressed size and entry list");
-//    // update informations about decompressed size and entry list
-//    // TODO FIXME need to resolve problem with access to file by
-//    // more than one thread
-//    try{
-//        archive_file_ptr->updateListOfEntries();
-//    } catch(...){
-//        LoggerD("Unknown error during updating entries list inside archive");
-//    }
-//}
-//
-////----------------------------------------------------------------------------------------
-////ExtractAllProgressCallback
-////----------------------------------------------------------------------------------------
-//
-//ExtractAllProgressCallback::ExtractAllProgressCallback(ArchiveCallbackType callback_type):
-//    BaseProgressCallback(callback_type),
-//    m_files_to_extract(0),
-//    m_expected_decompressed_size(0),
-//    m_files_extracted(0),
-//    m_current_file_size(0),
-//    m_current_file_extracted_bytes(0),
-//    m_progress_overall(0),
-//    m_overall_decompressed(0)
-//{
-//    LoggerD("Entered");
-//}
-//
-//ExtractAllProgressCallback::~ExtractAllProgressCallback()
-//{
-//    LoggerD("Entered");
-//}
-//
-//filesystem::FilePtr ExtractAllProgressCallback::getDirectory() const
-//{
-//    return m_directory;
-//}
-//
-//void ExtractAllProgressCallback::setDirectory(filesystem::FilePtr directory)
-//{
-//    m_directory = directory;
-//}
-//
-//void ExtractAllProgressCallback::startedExtractingFile(unsigned long current_file_size)
-//{
-//    m_current_file_size = current_file_size;
-//    m_current_file_extracted_bytes = 0;
-//}
-//
-//void ExtractAllProgressCallback::extractedPartOfFile(unsigned long bytes_decompressed)
-//{
-//    m_current_file_extracted_bytes += bytes_decompressed;
-//    updateOverallProgress(bytes_decompressed);
-//}
-//
-//void ExtractAllProgressCallback::finishedExtractingFile()
-//{
-//    m_current_file_size = 0;
-//    m_current_file_extracted_bytes = 0;
-//    ++m_files_extracted;
-//    updateOverallProgress(0);
-//}
-//
-//void ExtractAllProgressCallback::updateOverallProgress(unsigned long bytes_decompressed)
-//{
-//    m_overall_decompressed += bytes_decompressed;
-//    m_progress_overall =
-//            static_cast<double>(m_overall_decompressed + m_files_extracted) /
-//            static_cast<double>(m_expected_decompressed_size + m_files_to_extract);
-//
-//    LoggerD("%s of %s - %f%% (%d/%d files)",
-//            bytesToReadableString(m_overall_decompressed).c_str(),
-//            bytesToReadableString(m_expected_decompressed_size).c_str(),
-//            m_progress_overall * 100.0,
-//            m_files_extracted, m_files_to_extract);
-//}
-//
-//double ExtractAllProgressCallback::getCurrentFileProgress() const
-//{
-//    if(m_current_file_size > 0) {
-//        return static_cast<double>(m_current_file_extracted_bytes) /
-//                static_cast<double>(m_current_file_size);
-//    }
-//    else {
-//        return 1.0;
-//    }
-//}
-//
-//double ExtractAllProgressCallback::getOverallProgress() const
-//{
-//    return m_progress_overall;
-//}
-//
-//void ExtractAllProgressCallback::executeOperation(ArchiveFilePtr archive_file_ptr)
-//{
-//    LoggerD("Entered");
-//    archive_file_ptr->extractAllTask(this);
-//}
-//
-//void ExtractAllProgressCallback::setExpectedDecompressedSize(unsigned long exp_dec_size)
-//{
-//    m_expected_decompressed_size = exp_dec_size;
-//}
-//
-//unsigned long ExtractAllProgressCallback::getExpectedDecompressedSize() const
-//{
-//    return m_expected_decompressed_size;
-//}
-//
-//void ExtractAllProgressCallback::setNumberOfFilesToExtract(unsigned long files_count)
-//{
-//    m_files_to_extract = files_count;
-//}
-//
-//unsigned long ExtractAllProgressCallback::getNumberOfFilesToExtract() const
-//{
-//    return m_files_to_extract;
-//}
-//
-////----------------------------------------------------------------------------------------
-////OperationCanceledException
-////----------------------------------------------------------------------------------------
-//
-//const char* OPERATION_CANCELED_EXCEPTION = "OperationCanceledException";
-//
-//OperationCanceledException::OperationCanceledException(const char* message)
-//{
-//    LoggerD("Entered");
-//}
-//
-////----------------------------------------------------------------------------------------
-////ExtractEntryProgressCallback
-////----------------------------------------------------------------------------------------
-//
-//ExtractEntryProgressCallback::ExtractEntryProgressCallback():
-//        ExtractAllProgressCallback(),
-//        m_strip_name(false)
-//{
-//    LoggerD("Entered");
-//    m_callback_type = EXTRACT_ENTRY_PROGRESS_CALLBACK;
-//}
-//
-//ExtractEntryProgressCallback::~ExtractEntryProgressCallback()
-//{
-//    LoggerD("Entered");
-//}
-//
-//ArchiveFileEntryPtr ExtractEntryProgressCallback::getArchiveFileEntry()
-//{
-//    return m_archive_file_entry;
-//}
-//
-//void ExtractEntryProgressCallback::setArchiveFileEntry(ArchiveFileEntryPtr afentry)
-//{
-//    m_archive_file_entry = afentry;
-//}
-//
-//void ExtractEntryProgressCallback::setStripName(bool strip_name)
-//{
-//    m_strip_name = strip_name;
-//}
-//
-//bool ExtractEntryProgressCallback::getStripName() const
-//{
-//    return m_strip_name;
-//}
-//
-//void ExtractEntryProgressCallback::setStripBasePath(
-//        const std::string& strip_base_path)
-//{
-//    m_strip_base_path = strip_base_path;
-//}
-//
-//const std::string& ExtractEntryProgressCallback::getStripBasePath() const
-//{
-//    return m_strip_base_path;
-//}
-//
-//void ExtractEntryProgressCallback::executeOperation(ArchiveFilePtr archive_file_ptr)
-//{
-//    LoggerD("Entered");
-//
-//    if(!m_archive_file_entry) {
-//        LoggerE("ArchiveFileEntry is not set in callback");
-//        throw UnknownException("Could not extract archive file entry");
-//    }
-//
-//    if(!archive_file_ptr) {
-//        LoggerE("archive_file_ptr is NULL");
-//        throw UnknownException("Could not extract archive file entry");
-//    }
-//
-//    UnZipPtr unzip = archive_file_ptr->createUnZipObject();
-//    unzip->extractTo(this);
-//}
+
+//----------------------------------------------------------------------------------------
+//GetEntriesCallbackData
+//----------------------------------------------------------------------------------------
+
+GetEntriesCallbackData::GetEntriesCallbackData(ArchiveCallbackType callback_type):
+    OperationCallbackData(callback_type)
+{
+    LoggerD("Entered");
+}
+
+GetEntriesCallbackData::~GetEntriesCallbackData()
+{
+    LoggerD("Entered");
+}
+
+ArchiveFileEntryPtrMapPtr GetEntriesCallbackData::getEntries() const
+{
+    return m_entries;
+}
+
+void GetEntriesCallbackData::setEntries(ArchiveFileEntryPtrMapPtr entries)
+{
+    m_entries = entries;
+}
+
+void GetEntriesCallbackData::executeOperation(ArchiveFilePtr archive_file_ptr)
+{
+    LoggerD("Entered");
+
+    setEntries(archive_file_ptr->getEntryMap());
+
+    guint id = g_idle_add(ArchiveFile::getEntriesTaskCompleteCB, this);
+    if (!id) {
+        LoggerE("g_idle_add fails");
+        throw UnknownException("g_idle_add fails");
+    }
+}
+
+//----------------------------------------------------------------------------------------
+//GetEntryByNameCallbackData
+//----------------------------------------------------------------------------------------
+
+GetEntryByNameCallbackData::GetEntryByNameCallbackData(ArchiveCallbackType callback_type):
+    OperationCallbackData(callback_type)
+{
+    LoggerD("Entered");
+}
+
+GetEntryByNameCallbackData::~GetEntryByNameCallbackData()
+{
+    LoggerD("Entered");
+}
+
+const std::string& GetEntryByNameCallbackData::getName() const
+{
+    LoggerD("Entered");
+    return m_name;
+}
+
+void GetEntryByNameCallbackData::setName(const std::string& name)
+{
+    LoggerD("Entered");
+    m_name = name;
+}
+
+ArchiveFileEntryPtr GetEntryByNameCallbackData::getFileEntry() const
+{
+    return m_file_entry;
+}
+
+void GetEntryByNameCallbackData::setFileEntry(ArchiveFileEntryPtr entry)
+{
+    m_file_entry = entry;
+}
+
+void GetEntryByNameCallbackData::executeOperation(ArchiveFilePtr archive_file_ptr)
+{
+    LoggerD("Entered");
+
+    ArchiveFileEntryPtrMapPtr entries = archive_file_ptr->getEntryMap();
+    auto it = entries->find(getName());
+
+    //Not found but if our name does not contain '/'
+    //try looking for directory with such name
+    //
+    if (it == entries->end() && !isDirectoryPath(getName())) {
+        const std::string try_directory = getName() + "/";
+        LoggerD("GetEntryByName Trying directory: [%s]", try_directory.c_str());
+        it = entries->find(try_directory);
+    }
+
+    if (it == entries->end()) {
+        LoggerE("GetEntryByName Entry with name: [%s] not found", getName().c_str());
+        LoggerE("Throwing NotFoundException - Entry not found");
+        throw NotFoundException("Entry not found");
+    }
+
+    setFileEntry(it->second);
+
+    guint id = g_idle_add(ArchiveFile::getEntryByNameTaskCompleteCB, this);
+    if (!id) {
+        LoggerE("g_idle_add fails");
+        throw UnknownException("g_idle_add fails");
+    }
+}
+
+//----------------------------------------------------------------------------------------
+//BaseProgressCallback
+//----------------------------------------------------------------------------------------
+
+BaseProgressCallback::BaseProgressCallback(ArchiveCallbackType callback_type):
+    OperationCallbackData(callback_type),
+    m_overwrite(false)
+{
+    LoggerD("Entered");
+}
+
+BaseProgressCallback::~BaseProgressCallback()
+{
+    LoggerD("Entered");
+}
+
+bool BaseProgressCallback::getOverwrite() const
+{
+    LoggerD("Entered");
+    return m_overwrite;
+}
+
+void BaseProgressCallback::setOverwrite(bool overwrite)
+{
+    LoggerD("Entered");
+    m_overwrite = overwrite;
+}
+
+struct ProgressHolder
+{
+    ProgressHolder() :
+        overall_progress(0.0),
+        callback(NULL)
+    {
+    };
+
+    double overall_progress;
+    ArchiveFileEntryPtr currently_processed_entry;
+    BaseProgressCallback* callback;
+};
+
+void BaseProgressCallback::callSuccessCallbackOnMainThread()
+{
+    guint id = g_idle_add(BaseProgressCallback::callSuccessCallbackCB,
+            static_cast<void*>(this));
+    if (!id) {
+        LoggerE("g_idle_add fails - success callback will not be called");
+    }
+}
+
+gboolean BaseProgressCallback::callSuccessCallbackCB(void* data)
+{
+    BaseProgressCallback* callback = static_cast<BaseProgressCallback*>(data);
+    if (!callback) {
+        LoggerE("callback pointer is NULL");
+        return false;
+    }
+
+    std::unique_ptr<BaseProgressCallback> cb_ptr(callback);
+
+    try {
+        picojson::value val = picojson::value(picojson::object());
+        picojson::object& obj = val.get<picojson::object>();
+        obj[JSON_CALLBACK_ID] = picojson::value(callback->getCallbackId());
+
+        if (!callback->isError()) {
+            obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
+
+            LoggerD("%s", val.serialize().c_str());
+
+            ArchiveInstance::getInstance().PostMessage(val.serialize().c_str());
+        } else {
+            LoggerW("Not calling error callback in such case");
+        }
+    }
+    catch (const PlatformException& ex) {
+        LoggerE("%s (%s)", ex.name().c_str(), ex.message().c_str());
+    }
+    catch (...) {
+        LoggerE("Unknown error occurred");
+    }
+
+    callback->setArchiveFile(ArchiveFilePtr());
+    ArchiveManager::getInstance().eraseElementFromArchiveFileMap(callback->m_op_id);
+
+    return false;
+}
+
+void BaseProgressCallback::callProgressCallback(long operationId,
+        double value,
+        const std::string& filename,
+        double callbackId)
+{
+    LoggerD("Entered");
+
+    try {
+        picojson::value val = picojson::value(picojson::object());
+        picojson::object& obj = val.get<picojson::object>();
+        obj[JSON_CALLBACK_ID] = picojson::value(callbackId);
+        obj[JSON_DATA] = picojson::value(picojson::object());
+        picojson::object& args = obj[JSON_DATA].get<picojson::object>();
+
+        obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_PROGRESS);
+        obj[JSON_CALLBACK_KEEP] = picojson::value(true);
+
+        args[PARAM_OPERATION_ID] = picojson::value(static_cast<double>(operationId));
+        args[PARAM_VALUE] = picojson::value(value);
+        args[PARAM_FILENAME] = picojson::value(filename);
+
+        LoggerD("%s", val.serialize().c_str());
+
+        ArchiveInstance::getInstance().PostMessage(val.serialize().c_str());
+    }
+    catch (const PlatformException& ex) {
+        LoggerE("%s (%s)", ex.name().c_str(), ex.message().c_str());
+    }
+    catch (...) {
+        LoggerE("Unknown error occurred");
+    }
+}
+
+void BaseProgressCallback::callProgressCallbackOnMainThread(const double progress,
+        ArchiveFileEntryPtr current_entry)
+{
+    ProgressHolder* ph = new(std::nothrow) ProgressHolder();
+
+    if(ph) {
+        ph->overall_progress = progress;
+        ph->currently_processed_entry = current_entry;
+        ph->callback = this;
+
+        guint id = g_idle_add(BaseProgressCallback::callProgressCallbackCB,
+                static_cast<void*>(ph));
+        if (!id) {
+            LoggerE("g_idle_add fails");
+            delete ph;
+            ph = NULL;
+        }
+    } else {
+        LoggerE("Couldn't allocate ProgressHolder");
+    }
+}
+
+gboolean BaseProgressCallback::callProgressCallbackCB(void* data)
+{
+    ProgressHolder* ph = static_cast<ProgressHolder*>(data);
+    if (!ph) {
+        LoggerE("ph is null");
+        return false;
+    }
+
+    std::unique_ptr<ProgressHolder> ph_ptr(ph);
+    if (!ph->callback) {
+        LoggerE("ph->callback is null");
+        return false;
+    }
+
+    LoggerW("STUB Not checking if context is still alive");
+
+    try {
+        //Error callback is being handled by ArchiveFile queue - see
+        //ArchiveFile::taskManagerThread function
+        //
+        ph->callback->callProgressCallback(
+                ph->callback->m_op_id,
+                ph->overall_progress,
+                ph->currently_processed_entry->getName(),
+                ph->callback->m_cid);
+    }
+    catch (const PlatformException &err) {
+        LoggerE("%s (%s)", err.name().c_str(), err.message().c_str());
+    }
+    catch (...) {
+        LoggerE("Unknown error occurs");
+    }
+
+    return false;
+}
+
+//----------------------------------------------------------------------------------------
+//AddProgressCallback
+//----------------------------------------------------------------------------------------
+
+AddProgressCallback::AddProgressCallback(ArchiveCallbackType callback_type):
+    BaseProgressCallback(callback_type)
+{
+    LoggerD("Entered");
+}
+
+AddProgressCallback::~AddProgressCallback()
+{
+    LoggerD("Entered");
+}
+
+ArchiveFileEntryPtr AddProgressCallback::getFileEntry() const
+{
+    LoggerD("Entered");
+    return m_file_entry;
+}
+
+void AddProgressCallback::setFileEntry(ArchiveFileEntryPtr file_entry)
+{
+    LoggerD("Entered");
+    m_file_entry = file_entry;
+}
+
+void AddProgressCallback::setBasePath(const std::string& path)
+{
+    LoggerD("Entered");
+    m_base_path = path;
+    m_base_virt_path = filesystem::External::toVirtualPath(m_base_path);
+    std::string::size_type pos = m_base_virt_path.find(filesystem::Path::getSeparator());
+    if (pos != std::string::npos)
+    {
+        m_base_virt_path = m_base_virt_path.substr(pos + 1);
+    }
+    else
+    {
+        m_base_virt_path = "";
+    }
+}
+
+const std::string& AddProgressCallback::getBasePath()
+{
+    LoggerD("Entered");
+    return m_base_path;
+}
+
+const std::string& AddProgressCallback::getBaseVirtualPath()
+{
+    LoggerD("Entered");
+    return m_base_virt_path;
+}
+
+void AddProgressCallback::executeOperation(ArchiveFilePtr archive_file_ptr)
+{
+    LoggerD("Entered");
+
+    if(!m_file_entry) {
+        LoggerE("ArchiveFileEntry is not set in callback");
+        throw UnknownException("Could not add file to archive");
+    }
+
+    if(!archive_file_ptr) {
+        LoggerE("archive_file_ptr is NULL");
+        throw UnknownException("Could not extract archive file entry");
+    }
+
+    AddProgressCallback* callback = this;
+
+    ZipPtr zip = archive_file_ptr->createZipObject();
+    zip->addFile(callback);
+    // Zip is no more needed but it locks file opening while
+    // it is needed to read entries from file
+    zip->close();
+
+    //We have just finished adding file to archive so now
+    //this archive file should be valid .zip archive and
+    //we can remove CreatedAsNewEmptyArchive flag
+    archive_file_ptr->setCreatedAsNewEmptyArchive(false);
+
+    LoggerD("Update decompressed size and entry list");
+    // update informations about decompressed size and entry list
+    // TODO FIXME need to resolve problem with access to file by
+    // more than one thread
+    try{
+        archive_file_ptr->updateListOfEntries();
+    } catch(...){
+        LoggerD("Unknown error during updating entries list inside archive");
+    }
+}
+
+//----------------------------------------------------------------------------------------
+//ExtractAllProgressCallback
+//----------------------------------------------------------------------------------------
+
+ExtractAllProgressCallback::ExtractAllProgressCallback(ArchiveCallbackType callback_type):
+    BaseProgressCallback(callback_type),
+    m_files_to_extract(0),
+    m_expected_decompressed_size(0),
+    m_files_extracted(0),
+    m_current_file_size(0),
+    m_current_file_extracted_bytes(0),
+    m_progress_overall(0),
+    m_overall_decompressed(0)
+{
+    LoggerD("Entered");
+}
+
+ExtractAllProgressCallback::~ExtractAllProgressCallback()
+{
+    LoggerD("Entered");
+}
+
+filesystem::FilePtr ExtractAllProgressCallback::getDirectory() const
+{
+    return m_directory;
+}
+
+void ExtractAllProgressCallback::setDirectory(filesystem::FilePtr directory)
+{
+    m_directory = directory;
+}
+
+void ExtractAllProgressCallback::startedExtractingFile(unsigned long current_file_size)
+{
+    m_current_file_size = current_file_size;
+    m_current_file_extracted_bytes = 0;
+}
+
+void ExtractAllProgressCallback::extractedPartOfFile(unsigned long bytes_decompressed)
+{
+    m_current_file_extracted_bytes += bytes_decompressed;
+    updateOverallProgress(bytes_decompressed);
+}
+
+void ExtractAllProgressCallback::finishedExtractingFile()
+{
+    m_current_file_size = 0;
+    m_current_file_extracted_bytes = 0;
+    ++m_files_extracted;
+    updateOverallProgress(0);
+}
+
+void ExtractAllProgressCallback::updateOverallProgress(unsigned long bytes_decompressed)
+{
+    m_overall_decompressed += bytes_decompressed;
+    m_progress_overall =
+            static_cast<double>(m_overall_decompressed + m_files_extracted) /
+            static_cast<double>(m_expected_decompressed_size + m_files_to_extract);
+
+    LoggerD("%s of %s - %f%% (%d/%d files)",
+            bytesToReadableString(m_overall_decompressed).c_str(),
+            bytesToReadableString(m_expected_decompressed_size).c_str(),
+            m_progress_overall * 100.0,
+            m_files_extracted, m_files_to_extract);
+}
+
+double ExtractAllProgressCallback::getCurrentFileProgress() const
+{
+    if(m_current_file_size > 0) {
+        return static_cast<double>(m_current_file_extracted_bytes) /
+                static_cast<double>(m_current_file_size);
+    }
+    else {
+        return 1.0;
+    }
+}
+
+double ExtractAllProgressCallback::getOverallProgress() const
+{
+    return m_progress_overall;
+}
+
+void ExtractAllProgressCallback::executeOperation(ArchiveFilePtr archive_file_ptr)
+{
+    LoggerD("Entered");
+    archive_file_ptr->extractAllTask(this);
+}
+
+void ExtractAllProgressCallback::setExpectedDecompressedSize(unsigned long exp_dec_size)
+{
+    m_expected_decompressed_size = exp_dec_size;
+}
+
+unsigned long ExtractAllProgressCallback::getExpectedDecompressedSize() const
+{
+    return m_expected_decompressed_size;
+}
+
+void ExtractAllProgressCallback::setNumberOfFilesToExtract(unsigned long files_count)
+{
+    m_files_to_extract = files_count;
+}
+
+unsigned long ExtractAllProgressCallback::getNumberOfFilesToExtract() const
+{
+    return m_files_to_extract;
+}
+
+//----------------------------------------------------------------------------------------
+//OperationCanceledException
+//----------------------------------------------------------------------------------------
+
+const char* OPERATION_CANCELED_EXCEPTION = "OperationCanceledException";
+
+OperationCanceledException::OperationCanceledException(const char* message)
+{
+    LoggerD("Entered");
+}
+
+//----------------------------------------------------------------------------------------
+//ExtractEntryProgressCallback
+//----------------------------------------------------------------------------------------
+
+ExtractEntryProgressCallback::ExtractEntryProgressCallback():
+        ExtractAllProgressCallback(),
+        m_strip_name(false)
+{
+    LoggerD("Entered");
+    m_callback_type = EXTRACT_ENTRY_PROGRESS_CALLBACK;
+}
+
+ExtractEntryProgressCallback::~ExtractEntryProgressCallback()
+{
+    LoggerD("Entered");
+}
+
+ArchiveFileEntryPtr ExtractEntryProgressCallback::getArchiveFileEntry()
+{
+    return m_archive_file_entry;
+}
+
+void ExtractEntryProgressCallback::setArchiveFileEntry(ArchiveFileEntryPtr afentry)
+{
+    m_archive_file_entry = afentry;
+}
+
+void ExtractEntryProgressCallback::setStripName(bool strip_name)
+{
+    m_strip_name = strip_name;
+}
+
+bool ExtractEntryProgressCallback::getStripName() const
+{
+    return m_strip_name;
+}
+
+void ExtractEntryProgressCallback::setStripBasePath(
+        const std::string& strip_base_path)
+{
+    m_strip_base_path = strip_base_path;
+}
+
+const std::string& ExtractEntryProgressCallback::getStripBasePath() const
+{
+    return m_strip_base_path;
+}
+
+void ExtractEntryProgressCallback::executeOperation(ArchiveFilePtr archive_file_ptr)
+{
+    LoggerD("Entered");
+
+    if(!m_archive_file_entry) {
+        LoggerE("ArchiveFileEntry is not set in callback");
+        throw UnknownException("Could not extract archive file entry");
+    }
+
+    if(!archive_file_ptr) {
+        LoggerE("archive_file_ptr is NULL");
+        throw UnknownException("Could not extract archive file entry");
+    }
+
+    UnZipPtr unzip = archive_file_ptr->createUnZipObject();
+    unzip->extractTo(this);
+}
 
 } //namespace archive
 } //namespace extension
index acd12901d537be3d39612c91880127659cd16407..a77c3539ac922bb237fa1eac07eb821a50e94534 100644 (file)
@@ -70,6 +70,8 @@ public:
     long getOperationId() const;
     void setCallbackId(double cid);
     double getCallbackId() const;
+    void setHandle(long handle);
+    long getHandle() const;
 
     ArchiveCallbackType getCallbackType() const;
 
@@ -85,6 +87,7 @@ protected:
     ArchiveCallbackType m_callback_type;
     long m_op_id;
     double m_cid;
+    long m_handle;
 
 private:
     bool m_is_error;
@@ -101,11 +104,6 @@ public:
     OpenCallbackData(ArchiveCallbackType callback_type = OPEN_CALLBACK_DATA);
     virtual ~OpenCallbackData();
 
-    void setFile(std::string file);
-    const std::string& getFile() const;
-    //void setMode(FileMode mode);
-    //FileMode getMode() const;
-
     virtual void executeOperation(ArchiveFilePtr archive_file_ptr);
 
 private:
@@ -161,12 +159,13 @@ public:
             ArchiveFileEntryPtr current_entry);
     void callSuccessCallbackOnMainThread();
 
-    virtual void executeOperation(ArchiveFilePtr archive_file_ptr);
+    virtual void executeOperation(ArchiveFilePtr archive_file_ptr) = 0;
 
 protected:
     void callProgressCallback(long operationId,
             double value,
-            const std::string& filename);
+            const std::string& filename,
+            double callbackId);
 
 private:
     static gboolean callProgressCallbackCB(void* data);
index ef6b9f52448db27aac10c65b54e1f17633396f89..c728d7614d6657943cabeb588be762350446db08 100644 (file)
@@ -93,45 +93,42 @@ gboolean ArchiveFile::openTaskCompleteCB(void *data)
         return false;
     }
 
-    picojson::value val = picojson::value(picojson::object());
-    picojson::object& obj = val.get<picojson::object>();
-
-    obj["action"] = picojson::value("success");
-    obj["cid"] = picojson::value(callback->getCallbackId());
-    obj["args"] = picojson::value(picojson::object());
-    picojson::object& obj1 = obj["args"].get<picojson::object>();
-    obj1["mode"] = picojson::value("r");
-
-    LoggerD("%s", val.serialize().c_str());
-
-    ArchiveInstance::getInstance().PostMessage(val.serialize().c_str());
-
-//     JSContextRef context = callback->getContext();
-//     if (!GlobalContextManager::getInstance()->isAliveGlobalContext(context)) {
-//         LoggerE("context was closed");
-//         delete callback;
-//         callback = NULL;
-//         return false;
-//     }
-//     try {
-//         if (callback->isError()) {
-//             JSObjectRef errobj = JSWebAPIErrorFactory::makeErrorObject(context,
-//                     callback->getErrorName(),
-//                     callback->getErrorMessage());
-//             callback->callErrorCallback(errobj);
-//         }
-//         else {
-//             JSObjectRef result = JSArchiveFile::makeJSObject(context,
-//                     callback->getArchiveFile());
-//             callback->callSuccessCallback(result);
-//         }
-//     }
-//     catch (const PlatformException &err) {
-//         LoggerE("%s (%s)", err.name().c_str(), err.message().c_str());
-//     }
-//     catch (...) {
-//         LoggerE("Unknown error occurs");
-//     }
+    try {
+        auto archive_file = callback->getArchiveFile();
+
+        picojson::value val = picojson::value(picojson::object());
+        picojson::object& obj = val.get<picojson::object>();
+        obj[JSON_CALLBACK_ID] = picojson::value(callback->getCallbackId());
+        obj[JSON_DATA] = picojson::value(picojson::object());
+
+        picojson::object& args = obj[JSON_DATA].get<picojson::object>();
+
+        if (!callback->isError()) {
+            long handle = ArchiveManager::getInstance().addPrivData(archive_file);
+
+            obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
+
+            args[ARCHIVE_FILE_ATTR_MODE] = picojson::value(
+                    fileModeToString(archive_file->getFileMode()));
+            args[ARCHIVE_FILE_ATTR_DECOMPRESSED_SIZE] = picojson::value();
+            args[ARCHIVE_FILE_HANDLE] = picojson::value(static_cast<double>(handle));
+        } else {
+            obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
+
+            args[ERROR_CALLBACK_NAME] = picojson::value(callback->getErrorName());
+            args[ERROR_CALLBACK_MESSAGE] = picojson::value(callback->getErrorMessage());
+        }
+
+        LoggerD("%s", val.serialize().c_str());
+
+        ArchiveInstance::getInstance().PostMessage(val.serialize().c_str());
+    }
+    catch (const PlatformException& ex) {
+        LoggerE("%s (%s)", ex.name().c_str(), ex.message().c_str());
+    }
+    catch (...) {
+        LoggerE("Unknown error occurred");
+    }
 
     delete callback;
     callback = NULL;
@@ -142,7 +139,6 @@ gboolean ArchiveFile::openTaskCompleteCB(void *data)
 gboolean ArchiveFile::callErrorCallback(void* data)
 {
     LoggerD("Entered");
-    LoggerW("STUB Not calling success/error callback");
 
     auto callback = static_cast<OperationCallbackData*>(data);
     if (!callback) {
@@ -150,31 +146,33 @@ gboolean ArchiveFile::callErrorCallback(void* data)
         return false;
     }
 
-//     JSContextRef context = callback->getContext();
-//     if (!GlobalContextManager::getInstance()->isAliveGlobalContext(context)) {
-//         LoggerE("context was closed");
-//         delete callback;
-//         callback = NULL;
-//         return false;
-//     }
-//
-//     try {
-//         if (callback->isError()) {
-//             JSObjectRef errobj = JSWebAPIErrorFactory::makeErrorObject(context,
-//                     callback->getErrorName(),
-//                     callback->getErrorMessage());
-//             callback->callErrorCallback(errobj);
-//         }
-//         else {
-//             LoggerW("The success callback should be not be called in this case");
-//         }
-//     }
-//     catch (const PlatformException &err) {
-//         LoggerE("%s (%s)", err.name().c_str(), err.message().c_str());
-//     }
-//     catch (...) {
-//         LoggerE("Unknown error occurs");
-//     }
+    try {
+        picojson::value val = picojson::value(picojson::object());
+        picojson::object& obj = val.get<picojson::object>();
+        obj[JSON_CALLBACK_ID] = picojson::value(callback->getCallbackId());
+        obj[JSON_DATA] = picojson::value(picojson::object());
+
+        picojson::object& args = obj[JSON_DATA].get<picojson::object>();
+
+        if (!callback->isError()) {
+            LoggerW("The success callback should be not be called in this case");
+        } else {
+            obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
+
+            args[ERROR_CALLBACK_NAME] = picojson::value(callback->getErrorName());
+            args[ERROR_CALLBACK_MESSAGE] = picojson::value(callback->getErrorMessage());
+        }
+
+        LoggerD("%s", val.serialize().c_str());
+
+        ArchiveInstance::getInstance().PostMessage(val.serialize().c_str());
+    }
+    catch (const PlatformException& ex) {
+        LoggerE("%s (%s)", ex.name().c_str(), ex.message().c_str());
+    }
+    catch (...) {
+        LoggerE("Unknown error occured");
+    }
 
     delete callback;
     callback = NULL;
@@ -252,11 +250,12 @@ void* ArchiveFile::taskManagerThread(void *data)
     return NULL;
 }
 
-long ArchiveFile::addOperation(OperationCallbackData* callback)
+void ArchiveFile::addOperation(OperationCallbackData* callback)
 {
     LoggerD("Entered callback type:%d", callback->getCallbackType());
 
     const long operation_id = callback->getOperationId();
+    callback->setArchiveFile(shared_from_this());
     std::size_t size = 0;
     {
         std::lock_guard<std::mutex> lock(m_mutex);
@@ -283,7 +282,6 @@ long ArchiveFile::addOperation(OperationCallbackData* callback)
             LoggerE("Thread detachment failed");
         }
     }
-    return operation_id;
 }
 
 void ArchiveFile::extractAllTask(ExtractAllProgressCallback* callback)
@@ -334,7 +332,7 @@ void ArchiveFile::extractAllTask(ExtractAllProgressCallback* callback)
     unzip->extractAllFilesTo(directory->getNode()->getPath()->getFullPath(), callback);
 }
 
-long ArchiveFile::getEntries(GetEntriesCallbackData* callback)
+void ArchiveFile::getEntries(GetEntriesCallbackData* callback)
 {
     LoggerD("Entered");
     if(!callback) {
@@ -344,7 +342,7 @@ long ArchiveFile::getEntries(GetEntriesCallbackData* callback)
 
     throwInvalidStateErrorIfArchiveFileIsClosed();
 
-    return addOperation(callback);
+    addOperation(callback);
 }
 
 gboolean ArchiveFile::getEntriesTaskCompleteCB(void *data)
@@ -358,40 +356,53 @@ gboolean ArchiveFile::getEntriesTaskCompleteCB(void *data)
         return false;
     }
 
-//     JSContextRef context = callback->getContext();
-//     if (!GlobalContextManager::getInstance()->isAliveGlobalContext(context)) {
-//         LoggerE("context was closed");
-//         delete callback;
-//         callback = NULL;
-//         return false;
-//     }
-//
-//     try {
-//         ArchiveFileEntryPtrMapPtr entries = callback->getEntries();
-//         unsigned int size = entries->size();
-// 
-//         JSObjectRef objArray[size];
-//         int i = 0;
-//         for(auto it = entries->begin(); it != entries->end(); it++) {
-//             objArray[i] = JSArchiveFileEntry::makeJSObject(context, it->second);
-//             i++;
-//         }
-// 
-//         JSValueRef exception = NULL;
-//         JSObjectRef jsResult = JSObjectMakeArray(context, size,
-//                 size > 0 ? objArray : NULL, &exception);
-//         if (exception != NULL) {
-//             throw Common::UnknownException(context, exception);
-//         }
-// 
-//         callback->callSuccessCallback(jsResult);
-//     }
-//     catch (const PlatformException &err) {
-//         LoggerE("%s (%s)", err.name().c_str(), err.message().c_str());
-//     }
-//     catch (...) {
-//         LoggerE("Unknown error occurs");
-//     }
+    try {
+        picojson::value val = picojson::value(picojson::object());
+        picojson::object& obj = val.get<picojson::object>();
+        obj[JSON_CALLBACK_ID] = picojson::value(callback->getCallbackId());
+
+        if (!callback->isError()) {
+            obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
+            obj[JSON_DATA] = picojson::value(picojson::array());
+            picojson::array &arr = obj[JSON_DATA].get<picojson::array>();
+
+            ArchiveFileEntryPtrMapPtr entries = callback->getEntries();
+            for(auto it = entries->begin(); it != entries->end(); it++) {
+                picojson::value val = picojson::value(picojson::object());
+                picojson::object& obj = val.get<picojson::object>();
+
+                obj[ARCHIVE_FILE_ENTRY_ATTR_NAME] = picojson::value(
+                        it->second->getName());
+                obj[ARCHIVE_FILE_ENTRY_ATTR_SIZE] = picojson::value(
+                        static_cast<double>(it->second->getSize()));
+                obj[ARCHIVE_FILE_ENTRY_ATTR_MODIFIED] = picojson::value(
+                        static_cast<double>(it->second->getModified()));
+                obj[ARCHIVE_FILE_ENTRY_ATTR_COMPRESSED_SIZE] = picojson::value(
+                        static_cast<double>(it->second->getCompressedSize()));
+                obj[ARCHIVE_FILE_HANDLE] = picojson::value(
+                        static_cast<double>(callback->getHandle()));
+
+                arr.push_back(val);
+            }
+        } else {
+            obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
+            obj[JSON_DATA] = picojson::value(picojson::object());
+            picojson::object& args = obj[JSON_DATA].get<picojson::object>();
+
+            args[ERROR_CALLBACK_NAME] = picojson::value(callback->getErrorName());
+            args[ERROR_CALLBACK_MESSAGE] = picojson::value(callback->getErrorMessage());
+        }
+
+        LoggerD("%s", val.serialize().c_str());
+
+        ArchiveInstance::getInstance().PostMessage(val.serialize().c_str());
+    }
+    catch (const PlatformException& ex) {
+        LoggerE("%s (%s)", ex.name().c_str(), ex.message().c_str());
+    }
+    catch (...) {
+        LoggerE("Unknown error occured");
+    }
 
     delete callback;
     callback = NULL;
@@ -399,7 +410,7 @@ gboolean ArchiveFile::getEntriesTaskCompleteCB(void *data)
     return false;
 }
 
-long ArchiveFile::extractAll(ExtractAllProgressCallback *callback)
+void ArchiveFile::extractAll(ExtractAllProgressCallback *callback)
 {
     LoggerD("Entered");
     if(!callback) {
@@ -409,10 +420,10 @@ long ArchiveFile::extractAll(ExtractAllProgressCallback *callback)
 
     throwInvalidStateErrorIfArchiveFileIsClosed();
 
-    return addOperation(callback);
+    addOperation(callback);
 }
 
-long ArchiveFile::extractEntryTo(ExtractEntryProgressCallback* callback)
+void ArchiveFile::extractEntryTo(ExtractEntryProgressCallback* callback)
 {
     LoggerD("Entered");
     if(!callback) {
@@ -431,11 +442,11 @@ long ArchiveFile::extractEntryTo(ExtractEntryProgressCallback* callback)
         throw UnknownException("Archive is not opened");
     }
 
-    return addOperation(callback);
+    addOperation(callback);
 }
 
 
-long ArchiveFile::add(AddProgressCallback *callback)
+void ArchiveFile::add(AddProgressCallback *callback)
 {
     LoggerD("Entered");
     if(!callback) {
@@ -449,7 +460,7 @@ long ArchiveFile::add(AddProgressCallback *callback)
 
     throwInvalidStateErrorIfArchiveFileIsClosed();
 
-    return addOperation(callback);
+    addOperation(callback);
 }
 
 void ArchiveFile::close()
@@ -464,7 +475,7 @@ void ArchiveFile::close()
     return;
 }
 
-long ArchiveFile::getEntryByName(GetEntryByNameCallbackData* callback)
+void ArchiveFile::getEntryByName(GetEntryByNameCallbackData* callback)
 {
     LoggerD("Entered");
     if(!callback) {
@@ -474,13 +485,12 @@ long ArchiveFile::getEntryByName(GetEntryByNameCallbackData* callback)
 
     throwInvalidStateErrorIfArchiveFileIsClosed();
 
-    return addOperation(callback);
+    addOperation(callback);
 }
 
 gboolean ArchiveFile::getEntryByNameTaskCompleteCB(void *data)
 {
     LoggerD("Entered");
-    LoggerW("STUB Not calling success/error callback");
 
     auto callback = static_cast<GetEntryByNameCallbackData*>(data);
     if (!callback) {
@@ -488,32 +498,44 @@ gboolean ArchiveFile::getEntryByNameTaskCompleteCB(void *data)
         return false;
     }
 
-//     JSContextRef context = callback->getContext();
-//     if (!GlobalContextManager::getInstance()->isAliveGlobalContext(context)) {
-//         LoggerE("context was closed");
-//         delete callback;
-//         callback = NULL;
-//         return false;
-//     }
-//     try {
-//         if (callback->isError()) {
-//             JSObjectRef errobj = JSWebAPIErrorFactory::makeErrorObject(context,
-//                     callback->getErrorName(),
-//                     callback->getErrorMessage());
-//             callback->callErrorCallback(errobj);
-//         }
-//         else {
-//             JSObjectRef entry = JSArchiveFileEntry::makeJSObject(context,
-//                     callback->getFileEntry());
-//             callback->callSuccessCallback(entry);
-//         }
-//     }
-//     catch (const PlatformException &err) {
-//         LoggerE("%s (%s)", err.name().c_str(), err.message().c_str());
-//     }
-//     catch (...) {
-//         LoggerE("Unknown error occurs");
-//     }
+    try {
+        picojson::value val = picojson::value(picojson::object());
+        picojson::object& obj = val.get<picojson::object>();
+        obj[JSON_CALLBACK_ID] = picojson::value(callback->getCallbackId());
+        obj[JSON_DATA] = picojson::value(picojson::object());
+        picojson::object& args = obj[JSON_DATA].get<picojson::object>();
+
+        if (!callback->isError()) {
+            obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
+
+            ArchiveFileEntryPtr ent = callback->getFileEntry();
+
+            args[ARCHIVE_FILE_ENTRY_ATTR_NAME] = picojson::value(ent->getName());
+            args[ARCHIVE_FILE_ENTRY_ATTR_SIZE] = picojson::value(
+                    static_cast<double>(ent->getSize()));
+            args[ARCHIVE_FILE_ENTRY_ATTR_MODIFIED] = picojson::value(
+                    static_cast<double>(ent->getModified()));
+            args[ARCHIVE_FILE_ENTRY_ATTR_COMPRESSED_SIZE] = picojson::value(
+                    static_cast<double>(ent->getCompressedSize()));
+            args[ARCHIVE_FILE_HANDLE] = picojson::value(
+                    static_cast<double>(callback->getHandle()));
+        } else {
+            obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
+
+            args[ERROR_CALLBACK_NAME] = picojson::value(callback->getErrorName());
+            args[ERROR_CALLBACK_MESSAGE] = picojson::value(callback->getErrorMessage());
+        }
+
+        LoggerD("%s", val.serialize().c_str());
+
+        ArchiveInstance::getInstance().PostMessage(val.serialize().c_str());
+    }
+    catch (const PlatformException& ex) {
+        LoggerE("%s (%s)", ex.name().c_str(), ex.message().c_str());
+    }
+    catch (...) {
+        LoggerE("Unknown error occured");
+    }
 
     delete callback;
     callback = NULL;
@@ -610,11 +632,11 @@ UnZipPtr ArchiveFile::createUnZipObject()
         throw UnknownException("File is null");
     }
 
-//     filesystem::NodePtr node = m_file->getNode();
-//     if(!node) {
-//         LoggerE("Node is null");
-//         throw UnknownException("Node is null");
-//     }
+    filesystem::NodePtr node = m_file->getNode();
+    if(!node) {
+        LoggerE("Node is null");
+        throw UnknownException("Node is null");
+    }
 
     UnZipPtr unzip = UnZip::open(m_file->getNode()->getPath()->getFullPath());
     return unzip;
@@ -633,11 +655,11 @@ ZipPtr ArchiveFile::createZipObject()
         throw UnknownException("File is null");
     }
 
-//     filesystem::NodePtr node = m_file->getNode();
-//     if(!node) {
-//         LoggerE("Node is null");
-//         throw UnknownException("Node is null");
-//     }
+    filesystem::NodePtr node = m_file->getNode();
+    if(!node) {
+        LoggerE("Node is null");
+        throw UnknownException("Node is null");
+    }
 
     ZipPtr zip = Zip::open(m_file->getNode()->getPath()->getFullPath());
     return zip;
index 9612fcaec6a5731c6b8e96b05fb9658b4930c719..9efd712b182b0087fca4a074f2034e94a48b5f33 100755 (executable)
@@ -79,10 +79,10 @@ public:
     ArchiveFile(FileMode file_mode);
     virtual ~ArchiveFile();
 
-    long getEntries(GetEntriesCallbackData* callback);
-    long getEntryByName(GetEntryByNameCallbackData* callback);
-    long extractAll(ExtractAllProgressCallback *callback);
-    long add(AddProgressCallback *callback);
+    void getEntries(GetEntriesCallbackData* callback);
+    void getEntryByName(GetEntryByNameCallbackData* callback);
+    void extractAll(ExtractAllProgressCallback *callback);
+    void add(AddProgressCallback *callback);
     void close();
 
     filesystem::FilePtr getFile() const;
@@ -102,7 +102,7 @@ public:
 
 
     //Used by ArchiveFileEntry
-    long extractEntryTo(ExtractEntryProgressCallback* callback);
+    void extractEntryTo(ExtractEntryProgressCallback* callback);
 
     bool isAllowedOperation(const std::string& method_name);
     FileMode getFileMode() const;
@@ -165,7 +165,7 @@ private:
     static gboolean getEntryByNameTaskCompleteCB(void *data);
 
     static void* taskManagerThread(void *data);
-    long addOperation(OperationCallbackData* callback);
+    void addOperation(OperationCallbackData* callback);
     static gboolean callErrorCallback(void* data);
 
     void extractAllTask(ExtractAllProgressCallback* callback);
index 4a10d25c3797f940c26f8a8fb69c28c79a729c9b..3715fec3d3fe12c5c9c20a3c9a41d4c28290a454 100644 (file)
@@ -137,7 +137,7 @@ ArchiveFile* ArchiveFileEntry::getArchiveFileNonProtectPtr()
     return m_archive;
 }
 
-long ArchiveFileEntry::extractTo(ExtractEntryProgressCallback* callback)
+void ArchiveFileEntry::extractTo(ExtractEntryProgressCallback* callback)
 {
     if(!m_archive) {
         LOGE("m_archive is NULL");
@@ -165,7 +165,7 @@ long ArchiveFileEntry::extractTo(ExtractEntryProgressCallback* callback)
         callback->setStripBasePath(base_path_name);
     }
 
-    return m_archive->extractEntryTo(callback);
+    m_archive->extractEntryTo(callback);
 }
 
 } // archive
index d6582f40e77b366a4a3412c98f6e466e57db1449..57831d9d9c7512a2869ab36fc5eb0bbc7c9e94a1 100755 (executable)
@@ -60,7 +60,7 @@ public:
     void setArchiveFileNonProtectPtr(ArchiveFile* ptr);
     ArchiveFile* getArchiveFileNonProtectPtr();
 
-    long extractTo(ExtractEntryProgressCallback* callback);
+    void extractTo(ExtractEntryProgressCallback* callback);
 
 private:
     filesystem::FilePtr m_file;
index c46c0d26aa57ebc92518dc212d025e3feabccda3..13cbc0da93c2355ad15d344b46efabaf955ba8bb 100644 (file)
@@ -63,86 +63,352 @@ void ArchiveInstance::Open(const picojson::value& args, picojson::object& out) {
     LoggerD("%s", args.serialize().c_str());
 
     picojson::object data = args.get(JSON_DATA).get<picojson::object>();
-    picojson::value v_file = data.at("file");
-    picojson::value v_mode = data.at("mode");
-    //picojson::object options = data.at("options").get<picojson::object>();
-    //picojson::value v_overwrite = options.at("overwrite");
+    picojson::value v_file = data.at(PARAM_FILE);
+    picojson::value v_mode = data.at(PARAM_MODE);
+    picojson::value v_op_id = data.at(PARAM_OPERATION_ID);
+    picojson::object options = data.at(PARAM_OPTIONS).get<picojson::object>();
+    picojson::value v_overwrite = options.at(PARAM_OVERWRITE);
     const double callbackId = args.get(JSON_CALLBACK_ID).get<double>();
-    const long operationId = static_cast<long>(data.at("opId").get<double>());
-
-    /*
-    bool overwrite = false;
-    if (v_overwrite.is<bool>()) {
-        overwrite = v_overwrite.get<bool>();
-    }
-    */
-
+    const long operationId = static_cast<long>(v_op_id.get<double>());
     FileMode fm = stringToFileMode(v_mode.get<std::string>());
-    const std::string& file = v_file.get<std::string>();
-    auto json = std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
-    picojson::object& obj = json->get<picojson::object>();
-    obj[JSON_CALLBACK_ID] = picojson::value(callbackId);
-
-    LoggerD("opId: %d", operationId);
-    LoggerD("filename: %s", file.c_str());
-    LoggerD("callbackId: %d", callbackId);
 
     OpenCallbackData *callback = new OpenCallbackData();
 
-    NodePtr node = Node::resolve(Path::create(file));
-    FilePtr file_ptr = FilePtr(new File(node, File::PermissionList()));
-    ArchiveFilePtr a_ptr = ArchiveFilePtr(new ArchiveFile(FileMode::READ));
-    a_ptr->setFile(file_ptr);
-
-    callback->setArchiveFile(a_ptr);
-    //callback->setFile(file);
-    callback->setOperationId(operationId);
-    callback->setCallbackId(callbackId);
-    //callback->setMode(FileMode::READ);
-    //callback->setJson(json);
-    ArchiveManager::getInstance().open(callback);
+    try {
+        FilePtr file_ptr;
+
+        callback->setOperationId(operationId);
+        callback->setCallbackId(callbackId);
+
+        bool overwrite = false;
+        if(v_overwrite.is<bool>()) {
+            overwrite = v_overwrite.get<bool>();
+        }
+
+        std::string location_full_path = v_file.get<std::string>();
+
+        try {
+            NodePtr node = Node::resolve(Path::create(location_full_path));
+            file_ptr = FilePtr(new File(node, File::PermissionList()));
+            LoggerD("open: %s mode: 0x%x overwrite: %d", location_full_path.c_str(), fm, overwrite);
+
+            if(FileMode::WRITE == fm || FileMode::READ_WRITE == fm) {
+                if(overwrite) {
+                    try {
+                        LoggerD("Deleting existing file: %s", location_full_path.c_str());
+                        file_ptr->getNode()->remove(OPT_RECURSIVE);
+                        file_ptr.reset();   //We need to create new empty file
+                    } catch(...) {
+                        LoggerE("Couldn't remove existing file: %s", location_full_path.c_str());
+                        throw IOException("Could not remove existing file");
+                    }
+                }
+                else if(FileMode::WRITE == fm) {
+                    LoggerE("open: %s with mode: \"w\" file exists and overwrite is FALSE!"
+                            " throwing InvalidModificationException", location_full_path.c_str());
+                    throw InvalidModificationException("Zip archive already exists");
+                }
+            }
+        } catch (const NotFoundException& nfe) {
+            LoggerD("location_string: %s is not file reference", location_full_path.c_str());
+            file_ptr.reset();
+        }
+
+        if (!file_ptr) {
+            NodePtr node_ptr;
+
+            if(FileMode::WRITE == fm ||
+                    FileMode::READ_WRITE == fm ||
+                    FileMode::ADD == fm) {
+                LoggerD("Archive file not found - trying to create new one at: "
+                        "full: %s", location_full_path.c_str());
+
+                PathPtr path = Path::create(location_full_path);
+
+                std::string parent_path_string = path->getPath();
+                PathPtr parent_path = Path::create(parent_path_string);
+                LoggerD("Parent path: %s", parent_path_string.c_str());
+
+                NodePtr parent_node = Node::resolve(parent_path);
+                parent_node->setPermissions(PERM_READ | PERM_WRITE);
+                std::string filename = path->getName();
+                LoggerD("File name: %s", filename.c_str());
+                node_ptr = parent_node->createChild(Path::create(filename), NT_FILE);
+            }
+            else {
+                LoggerE("Archive file not found");
+                throw NotFoundException("Archive file not found");
+            }
+            file_ptr = FilePtr(new File(node_ptr, File::PermissionList()));
+        }
+
+        ArchiveFilePtr afp = ArchiveFilePtr(new ArchiveFile(fm));
+        afp->setFile(file_ptr);
+        afp->setOverwrite(overwrite);
+        callback->setArchiveFile(afp);
+
+        ArchiveManager::getInstance().open(callback);
+    }
+    catch (...) {
+        LoggerE("Exception occurred");
+        delete callback;
+        callback = NULL;
+        throw;
+    }
 }
 
 void ArchiveInstance::Abort(const picojson::value& args, picojson::object& out)
 {
     LoggerD("Entered");
+    LoggerD("%s", args.serialize().c_str());
+
+    picojson::object data = args.get(JSON_DATA).get<picojson::object>();
+    picojson::value v_op_id = data.at(PARAM_OPERATION_ID);
+
+    const long op_id = static_cast<long>(v_op_id.get<double>());
+
+    ArchiveManager::getInstance().abort(op_id);
+
     ReportSuccess(out);
 }
 
 void ArchiveInstance::Add(const picojson::value& args, picojson::object& out)
 {
     LoggerD("Entered");
-    ReportSuccess(out);
+    LoggerD("%s", args.serialize().c_str());
+
+    picojson::object data = args.get(JSON_DATA).get<picojson::object>();
+    picojson::value v_source = data.at(PARAM_SOURCE_FILE);
+    //picojson::value v_options = data.at(PARAM_OPTIONS);
+    picojson::value v_op_id = data.at(PARAM_OPERATION_ID);
+    picojson::value v_handle = data.at(ARCHIVE_FILE_HANDLE);
+
+    const double callbackId = args.get(JSON_CALLBACK_ID).get<double>();
+    const long operationId = static_cast<long>(v_op_id.get<double>());
+    const long handle = static_cast<long>(v_handle.get<double>());
+
+    AddProgressCallback *callback = new AddProgressCallback();
+
+    try {
+        NodePtr node = Node::resolve(Path::create(v_source.get<std::string>()));
+        FilePtr file_ptr = FilePtr(new File(node, File::PermissionList()));
+
+        ArchiveFileEntryPtr afep = ArchiveFileEntryPtr(
+                new ArchiveFileEntry(file_ptr));
+
+        callback->setOperationId(operationId);
+        callback->setCallbackId(callbackId);
+        callback->setFileEntry(afep);
+
+        callback->setBasePath(file_ptr->getNode()->getPath()->getPath());
+        LoggerD("base path:%s base virt:%s", callback->getBasePath().c_str(),
+                callback->getBaseVirtualPath().c_str());
+
+        ArchiveFilePtr priv = ArchiveManager::getInstance().getPrivData(handle);
+        if (!priv->isAllowedOperation(ARCHIVE_FUNCTION_API_ARCHIVE_FILE_ADD)) {
+            LoggerE("Not allowed operation");
+            throw InvalidAccessException("Not allowed operation");
+        }
+
+        priv->add(callback);
+    }
+    catch (...) {
+        LoggerE("Exception occurred");
+        delete callback;
+        callback = NULL;
+        throw;
+    }
 }
 
 void ArchiveInstance::ExtractAll(const picojson::value& args, picojson::object& out)
 {
     LoggerD("Entered");
-    ReportSuccess(out);
+    LoggerD("%s", args.serialize().c_str());
+
+    picojson::object data = args.get(JSON_DATA).get<picojson::object>();
+    picojson::value v_dest_dir = data.at(PARAM_DESTINATION_DIR);
+    picojson::value v_overwrite = data.at(PARAM_OVERWRITE);
+    picojson::value v_op_id = data.at(PARAM_OPERATION_ID);
+    picojson::value v_handle = data.at(ARCHIVE_FILE_HANDLE);
+
+    const double callbackId = args.get(JSON_CALLBACK_ID).get<double>();
+    const long operationId = static_cast<long>(v_op_id.get<double>());
+    const long handle = static_cast<long>(v_handle.get<double>());
+
+    ExtractAllProgressCallback *callback = new ExtractAllProgressCallback();
+
+    try {
+        NodePtr node = Node::resolve(Path::create(v_dest_dir.get<std::string>()));
+        FilePtr file_ptr = FilePtr(new File(node, File::PermissionList()));
+
+        callback->setDirectory(file_ptr);
+        callback->setOperationId(operationId);
+        callback->setCallbackId(callbackId);
+
+        if (v_overwrite.is<bool>()) {
+            callback->setOverwrite(v_overwrite.get<bool>());
+        }
+
+        ArchiveFilePtr priv = ArchiveManager::getInstance().getPrivData(handle);
+        if (!priv->isAllowedOperation(ARCHIVE_FUNCTION_API_ARCHIVE_FILE_EXTRACT_ALL)) {
+            LoggerE("Not allowed operation");
+            throw InvalidAccessException("Not allowed operation");
+        }
+        priv->extractAll(callback);
+    }
+    catch (...) {
+        LoggerE("Exception occurred");
+        delete callback;
+        callback = NULL;
+        throw;
+    }
 }
 
 void ArchiveInstance::GetEntries(const picojson::value& args, picojson::object& out)
 {
     LoggerD("Entered");
-    ReportSuccess(out);
+    LoggerD("%s", args.serialize().c_str());
+
+    picojson::object data = args.get(JSON_DATA).get<picojson::object>();
+    picojson::value v_op_id = data.at(PARAM_OPERATION_ID);
+    picojson::value v_handle = data.at(ARCHIVE_FILE_HANDLE);
+
+    const double callbackId = args.get(JSON_CALLBACK_ID).get<double>();
+    const long operationId = static_cast<long>(v_op_id.get<double>());
+    const long handle = static_cast<long>(v_handle.get<double>());
+
+    GetEntriesCallbackData *callback = new GetEntriesCallbackData();
+
+    try {
+        callback->setOperationId(operationId);
+        callback->setCallbackId(callbackId);
+        callback->setHandle(handle);
+
+        ArchiveFilePtr priv = ArchiveManager::getInstance().getPrivData(handle);
+        if (!priv->isAllowedOperation(ARCHIVE_FUNCTION_API_ARCHIVE_FILE_GET_ENTRIES)) {
+            LoggerE("Not allowed operation");
+            throw InvalidAccessException("Not allowed operation");
+        }
+
+        priv->getEntries(callback);
+    }
+    catch (...) {
+        LoggerE("Exception occurred");
+        delete callback;
+        callback = NULL;
+        throw;
+    }
 }
 
 void ArchiveInstance::GetEntryByName(const picojson::value& args, picojson::object& out)
 {
     LoggerD("Entered");
-    ReportSuccess(out);
+    LoggerD("%s", args.serialize().c_str());
+
+    picojson::object data = args.get(JSON_DATA).get<picojson::object>();
+    picojson::value v_op_id = data.at(PARAM_OPERATION_ID);
+    picojson::value v_handle = data.at(ARCHIVE_FILE_HANDLE);
+    picojson::value v_name = data.at(PARAM_NAME);
+
+    const double callbackId = args.get(JSON_CALLBACK_ID).get<double>();
+    const long operationId = static_cast<long>(v_op_id.get<double>());
+    const long handle = static_cast<long>(v_handle.get<double>());
+
+    GetEntryByNameCallbackData *callback = new GetEntryByNameCallbackData();
+
+    try {
+        callback->setOperationId(operationId);
+        callback->setCallbackId(callbackId);
+        callback->setName(v_name.get<std::string>());
+        callback->setHandle(handle);
+
+        ArchiveFilePtr priv = ArchiveManager::getInstance().getPrivData(handle);
+        if (!priv->isAllowedOperation(ARCHIVE_FUNCTION_API_ARCHIVE_FILE_GET_ENTRY_BY_NAME)) {
+            LoggerE("Not allowed operation");
+            throw InvalidAccessException("Not allowed operation");
+        }
+
+        priv->getEntryByName(callback);
+    }
+    catch (...) {
+        LoggerE("Exception occurred");
+        delete callback;
+        callback = NULL;
+        throw;
+    }
 }
 
 void ArchiveInstance::Close(const picojson::value& args, picojson::object& out)
 {
     LoggerD("Entered");
+    LoggerD("%s", args.serialize().c_str());
+
+    picojson::object data = args.get(JSON_DATA).get<picojson::object>();
+    picojson::value v_handle = data.at(ARCHIVE_FILE_HANDLE);
+
+    const long handle = static_cast<long>(v_handle.get<double>());
+
+    ArchiveFilePtr priv = ArchiveManager::getInstance().getPrivData(handle);
+    priv->close();
+    ArchiveManager::getInstance().erasePrivData(handle);
+
     ReportSuccess(out);
 }
 
 void ArchiveInstance::Extract(const picojson::value& args, picojson::object& out)
 {
     LoggerD("Entered");
-    ReportSuccess(out);
+    LoggerD("%s", args.serialize().c_str());
+
+    picojson::object data = args.get(JSON_DATA).get<picojson::object>();
+    picojson::value v_dest_dir = data.at(PARAM_DESTINATION_DIR);
+    picojson::value v_strip_name = data.at(PARAM_STRIP_NAME);
+    picojson::value v_overwrite = data.at(PARAM_OVERWRITE);
+    picojson::value v_op_id = data.at(PARAM_OPERATION_ID);
+    picojson::value v_handle = data.at(ARCHIVE_FILE_HANDLE);
+    picojson::value v_entry_name = data.at(PARAM_NAME);
+
+    const double callbackId = args.get(JSON_CALLBACK_ID).get<double>();
+    const long operationId = static_cast<long>(v_op_id.get<double>());
+    const long handle = static_cast<long>(v_handle.get<double>());
+
+    ExtractEntryProgressCallback *callback = new ExtractEntryProgressCallback();
+
+    try {
+        NodePtr node = Node::resolve(Path::create(v_dest_dir.get<std::string>()));
+        FilePtr file_ptr = FilePtr(new File(node, File::PermissionList()));
+
+        callback->setDirectory(file_ptr);
+        callback->setOperationId(operationId);
+        callback->setCallbackId(callbackId);
+
+        if (v_overwrite.is<bool>()) {
+            callback->setOverwrite(v_overwrite.get<bool>());
+        }
+        if (v_strip_name.is<bool>()) {
+            callback->setStripName(v_strip_name.get<bool>());
+        }
+        ArchiveFilePtr archive_file_ptr = ArchiveManager::getInstance().getPrivData(handle);
+        ArchiveFileEntryPtrMapPtr entries = archive_file_ptr->getEntryMap();
+        auto it = entries->find(v_entry_name.get<std::string>());
+
+        //Not found but if our name does not contain '/'
+        //try looking for directory with such name
+        //
+        if (it == entries->end() && !isDirectoryPath(v_entry_name.get<std::string>())) {
+            const std::string try_directory = v_entry_name.get<std::string>() + "/";
+            LoggerD("GetEntryByName Trying directory: [%s]", try_directory.c_str());
+            it = entries->find(try_directory);
+        }
+
+        it->second->extractTo(callback);
+    }
+    catch (...) {
+        LoggerE("Exception occurred");
+        delete callback;
+        callback = NULL;
+        throw;
+    }
 }
 
 } // namespace archive
index d6d4a75ceae92bb9842e5364fbb1824b4b444505..3cf818a81097c42ed57ecbe5b8283028ac56ede7 100644 (file)
@@ -27,7 +27,7 @@ namespace archive {
 using namespace filesystem;
 
 ArchiveManager::ArchiveManager():
-    m_next_unique_id(0)
+        m_next_unique_id(0)
 {
     LoggerD("Initialize ArchiveManager");
 }
@@ -64,6 +64,34 @@ void ArchiveManager::abort(long operation_id)
     LoggerD("The Operation Identifier not found");
 }
 
+void ArchiveManager::erasePrivData(long handle)
+{
+    LoggerD("Entered");
+
+    ArchiveFileMap::iterator it = m_priv_map.find(handle);
+    if (it != m_priv_map.end()) {
+        m_priv_map.erase(it);
+    }
+}
+
+long ArchiveManager::addPrivData(ArchiveFilePtr archive_file_ptr)
+{
+    LoggerD("Entered");
+
+    long handle = ++m_next_unique_id;
+    m_priv_map.insert(ArchiveFilePair(handle, archive_file_ptr));
+    return handle;
+}
+
+ArchiveFilePtr ArchiveManager::getPrivData(long handle)
+{
+    ArchiveFileMap::iterator it = m_priv_map.find(handle);
+    if (it != m_priv_map.end()) {
+        return it->second;
+    }
+    throw UnknownException("Priv is null");
+}
+
 long ArchiveManager::open(OpenCallbackData* callback)
 {
     LoggerD("Entered");
@@ -76,15 +104,7 @@ long ArchiveManager::open(OpenCallbackData* callback)
 //    ArchiveFilePtr a_ptr = ArchiveFilePtr(new ArchiveFile(FileMode::READ));
 
     ArchiveFilePtr a_ptr = callback->getArchiveFile();
-    return a_ptr->addOperation(callback);
-}
-
-long ArchiveManager::getNextOperationId(ArchiveFilePtr archive_file_ptr)
-{
-    LoggerD("Entered");
-    long op_id = ++m_next_unique_id;
-    m_archive_file_map.insert(ArchiveFilePair(op_id, archive_file_ptr));
-    return op_id;
+    a_ptr->addOperation(callback);
 }
 
 void ArchiveManager::eraseElementFromArchiveFileMap(long operation_id)
index 00b8ea988f7ba52d160fa18ef79feff00d0197bb..1644a00ebed5a5536eed1674581512035893b40d 100755 (executable)
@@ -37,8 +37,10 @@ public:
     ~ArchiveManager();
 
     void abort(long operation_id);
-    long getNextOperationId(ArchiveFilePtr archive_file_ptr);
     void eraseElementFromArchiveFileMap(long operation_id);
+    void erasePrivData(long handle);
+    long addPrivData(ArchiveFilePtr archive_file_ptr);
+    ArchiveFilePtr getPrivData(long handle);
     long open(OpenCallbackData* callback);
 
 private:
@@ -47,9 +49,9 @@ private:
     void operator=(ArchiveManager const&);
 
     ArchiveFileMap m_archive_file_map;
+    ArchiveFileMap m_priv_map;
 
     long m_next_unique_id;
-
 };
 
 } // archive
index a9880e8148f0532c9185cbbd87cdf6b6e2aa1b34..fa0aae89fedf5357d64f74262f02c0f4aae013dc 100755 (executable)
 #define JSON_CALLBACK_KEEP                                      "keep"
 #define JSON_DATA                                               "args"
 
+#define PARAM_FILE                                              "file"
+#define PARAM_MODE                                              "mode"
+#define PARAM_OPTIONS                                           "options"
+#define PARAM_SOURCE_FILE                                       "sourceFile"
+#define PARAM_DESTINATION_DIR                                   "destinationDirectory"
+#define PARAM_OVERWRITE                                         "overwrite"
+#define PARAM_NAME                                              "name"
+#define PARAM_STRIP_NAME                                        "stripName"
+#define PARAM_OPERATION_ID                                      "opId"
+#define PARAM_VALUE                                             "value"
+#define PARAM_FILENAME                                          "filename"
+
 #define ARCHIVE_FILE_ATTR_MODE                                  "mode"
 #define ARCHIVE_FILE_ATTR_DECOMPRESSED_SIZE                     "decompressedSize"
+#define ARCHIVE_FILE_HANDLE                                     "handle"
 
 #define ARCHIVE_FILE_ENTRY_ATTR_NAME                            "name"
 #define ARCHIVE_FILE_ENTRY_ATTR_SIZE                            "size"
 #define ARCHIVE_FILE_ENTRY_ATTR_COMPRESSED_SIZE                 "compressedSize"
 #define ARCHIVE_FILE_ENTRY_ATTR_MODIFIED                        "modified"
 
+#define ERROR_CALLBACK_NAME                                     "name"
+#define ERROR_CALLBACK_MESSAGE                                  "message"
+
 #endif // _ARCHIVE_PLUGIN_DEFS_H_
index f530eb09c43212cf8ab54e5628dbe4daa8116986..15eea84089c64278c37023e6cbfbe23abf370935 100644 (file)
@@ -67,5 +67,12 @@ const std::string& File::getOriginalFullPath() const
     return m_original_fullpath;
 }
 
+std::string External::toVirtualPath(const std::string& path)
+{
+    //TODO::implement this method
+    LoggerW("Just STUB");
+    return path;
+}
+
 } // filesystem
 } // extension
index b9f0f044ae9d7cb7e884982b69149c24ca2cf458..562f3c717fd178e0b356eeba0414951ecdcef8aa 100755 (executable)
@@ -59,7 +59,6 @@ private:
 class External {
 public:
     static std::string toVirtualPath(const std::string& path);
-    static void removeDirectoryRecursive(const std::string& fullpath);
 };
 
 
index 2ba13b88ea2413fc6906654deaa98a1494d4603a..7169a6d05205933595e4c43b434798bb6e8ea427 100755 (executable)
@@ -188,7 +188,7 @@ JSValueRef JSArchiveManager::open(JSContextRef context,
             file_ptr.reset();
         }
 
-        if(!file_ptr) {
+        if (!file_ptr) {
             NodePtr node_ptr;
 
             if(FileMode::WRITE == fm ||
index 525571ec6e941200585e47e72e9dcfef1f42af74..ec74c484e0598548aecf9e92b9b2ae4684413619 100644 (file)
@@ -43,11 +43,11 @@ UnZip::UnZip(const std::string& filename) :
         m_unzip(NULL),
         m_default_buffer_size(1024 * 1024)
 {
-    LOGD("Entered");
+    LoggerD("Entered");
 
     m_unzip = unzOpen(filename.c_str());
     if(!m_unzip) {
-        LOGE("unzOpen returned NULL : It means the file is invalid.");
+        LoggerE("unzOpen returned NULL : It means the file is invalid.");
         throw InvalidValuesException("Failed to open zip file");
     }
     m_is_open = true;
@@ -60,9 +60,9 @@ UnZip::~UnZip()
 
 void UnZip::close()
 {
-    LOGD("Entered");
+    LoggerD("Entered");
     if(!m_is_open) {
-        LOGD("Unzip already closed - exiting");
+        LoggerD("Unzip already closed - exiting");
         return;
     }
 
@@ -70,7 +70,7 @@ void UnZip::close()
     m_unzip = NULL;
 
     if (errclose != UNZ_OK) {
-        LOGE("ret: %d",errclose);
+        LoggerE("ret: %d",errclose);
         throwArchiveException(errclose, "unzClose()");
     }
     m_is_open = false;
@@ -78,20 +78,20 @@ void UnZip::close()
 
 UnZipPtr UnZip::open(const std::string& filename)
 {
-    LOGD("Entered");
+    LoggerD("Entered");
     return UnZipPtr(new UnZip(filename));
 }
 
 ArchiveFileEntryPtrMapPtr UnZip::listEntries(unsigned long *decompressedSize)
 {
     if(!m_is_open) {
-        LOGE("Failed to get list of entries - UnZip closed");
+        LoggerE("Failed to get list of entries - UnZip closed");
         throw UnknownException("Failed to get list of files in zip archive");
     }
     unz_global_info gi;
     int err = unzGetGlobalInfo (m_unzip, &gi);
     if (UNZ_OK != err) {
-        LOGE("ret: %d",err);
+        LoggerE("ret: %d",err);
         throwArchiveException(err, "unzGetGlobalInfo()");
     }
 
@@ -105,7 +105,7 @@ ArchiveFileEntryPtrMapPtr UnZip::listEntries(unsigned long *decompressedSize)
 
     err = unzGoToFirstFile(m_unzip);
     if (err != UNZ_OK) {
-        LOGW("%s",getArchiveLogMessage(err, "unzGoToFirstFile()").c_str());
+        LoggerW("%s",getArchiveLogMessage(err, "unzGoToFirstFile()").c_str());
     }
 
     for (uLong i = 0; i < gi.number_entry; i++) {
@@ -113,11 +113,11 @@ ArchiveFileEntryPtrMapPtr UnZip::listEntries(unsigned long *decompressedSize)
         err = unzGetCurrentFileInfo(m_unzip, &file_info,
                 filename_inzip, sizeof(filename_inzip), NULL, 0, NULL, 0);
         if (err != UNZ_OK) {
-            LOGE("ret: %d",err);
+            LoggerE("ret: %d",err);
             throwArchiveException(err, "unzGetCurrentFileInfo()");
         }
 
-        LOGD("file: %s | unc size: %d | comp size: %d", filename_inzip,
+        LoggerD("file: %s | unc size: %d | comp size: %d", filename_inzip,
                 file_info.uncompressed_size, file_info.compressed_size);
 
         ArchiveFileEntryPtr entry = ArchiveFileEntryPtr(new ArchiveFileEntry());
@@ -137,7 +137,7 @@ ArchiveFileEntryPtrMapPtr UnZip::listEntries(unsigned long *decompressedSize)
         date.tm_wday = 0;
         date.tm_yday = 0;
         date.tm_isdst = 0;
-        LOGD("%d, %d, %d, %d, %d, %d", date.tm_hour, date.tm_min, date.tm_sec, date.tm_mday, date.tm_mon, date.tm_year);
+        LoggerD("%d, %d, %d, %d, %d, %d", date.tm_hour, date.tm_min, date.tm_sec, date.tm_mday, date.tm_mon, date.tm_year);
         entry->setModified(mktime(&date));
 
         map->insert(std::make_pair(filename_inzip, entry));
@@ -146,7 +146,7 @@ ArchiveFileEntryPtrMapPtr UnZip::listEntries(unsigned long *decompressedSize)
 
             err = unzGoToNextFile(m_unzip);
             if (UNZ_OK != err) {
-                LOGE("ret: %d",err);
+                LoggerE("ret: %d",err);
                 throwArchiveException(err, "unzGoToNextFile()");
             }
         }
@@ -161,7 +161,7 @@ void UnZip::extractAllFilesTo(const std::string& extract_path,
         ExtractAllProgressCallback* callback)
 {
     if(!m_is_open) {
-        LOGE("Failed to extract files - UnZip closed");
+        LoggerE("Failed to extract files - UnZip closed");
         throw UnknownException("Failed to extract zip archive");
     }
 
@@ -176,13 +176,13 @@ void UnZip::extractAllFilesTo(const std::string& extract_path,
     //
     int err = unzGoToFirstFile(m_unzip);
     if (err != UNZ_OK) {
-        LOGW("%s",getArchiveLogMessage(err, "unzGoToFirstFile()").c_str());
+        LoggerW("%s",getArchiveLogMessage(err, "unzGoToFirstFile()").c_str());
     }
 
     for (uLong i = 0; i < gi.number_entry; i++) {
 
         if (callback->isCanceled()) {
-            LOGD("Operation cancelled");
+            LoggerD("Operation cancelled");
             throw OperationCanceledException();
         }
 
@@ -191,7 +191,7 @@ void UnZip::extractAllFilesTo(const std::string& extract_path,
         if ((i + 1) < gi.number_entry) {
             err = unzGoToNextFile(m_unzip);
             if (UNZ_OK != err) {
-                LOGE("ret: %d",err);
+                LoggerE("ret: %d",err);
                 throwArchiveException(err, "unzGoToNextFile()");
             }
         }
@@ -211,41 +211,41 @@ struct ExtractDataHolder
 void UnZip::extractTo(ExtractEntryProgressCallback* callback)
 {
     if(!m_is_open) {
-        LOGE("Extract archive file entry failed - UnZip closed");
+        LoggerE("Extract archive file entry failed - UnZip closed");
         throw UnknownException("Extract archive file entry failed");
     }
 
     if(!callback) {
-        LOGE("callback is NULL");
+        LoggerE("callback is NULL");
         throw UnknownException("Extract archive file entry failed");
     }
 
     if(!callback->getArchiveFileEntry()) {
-        LOGE("callback->getArchiveFileEntry() is NULL");
+        LoggerE("callback->getArchiveFileEntry() is NULL");
         throw UnknownException("Extract archive file entry failed");
     }
 
     filesystem::FilePtr out_dir = callback->getDirectory();
     if(!out_dir) {
-        LOGE("Output directory is not valid");
+        LoggerE("Output directory is not valid");
         throw InvalidValuesException("Output directory is not correct");
     }
 
-//     filesystem::NodePtr out_node = out_dir->getNode();
-//     if(!out_node) {
-//         LOGE("Output directory is not valid");
-//         throw InvalidValuesException("Output directory is not correct");
-//     }
-//
-//     filesystem::PathPtr out_path = out_node->getPath();
-//     if(!out_path) {
-//         LOGE("Output directory is not valid");
-//         throw InvalidValuesException("Output directory is not correct");
-//     }
+    NodePtr out_node = out_dir->getNode();
+    if(!out_node) {
+        LoggerE("Output directory is not valid");
+        throw InvalidValuesException("Output directory is not correct");
+    }
+
+    PathPtr out_path = out_node->getPath();
+    if(!out_path) {
+        LoggerE("Output directory is not valid");
+        throw InvalidValuesException("Output directory is not correct");
+    }
 
     auto entry_name_in_zip = callback->getArchiveFileEntry()->getName();
     auto root_output_path = out_dir->getNode()->getPath()->getFullPath();
-    LOGD("Extract: [%s] to root output directory: [%s] (stripBasePath: [%s])",
+    LoggerD("Extract: [%s] to root output directory: [%s] (stripBasePath: [%s])",
             entry_name_in_zip.c_str(),
             root_output_path.c_str(),
             callback->getStripBasePath().c_str());
@@ -279,7 +279,7 @@ void UnZip::extractItFunction(const std::string& file_name, unz_file_info& file_
 {
     ExtractDataHolder* h = static_cast<ExtractDataHolder*>(user_data);
     if(!h) {
-        LOGE("ExtractDataHolder is NULL!");
+        LoggerE("ExtractDataHolder is NULL!");
         throw UnknownException("Could not list content of zip archive");
     }
 
@@ -296,7 +296,7 @@ unsigned int UnZip::IterateFilesInZip(unz_global_info& gi,
 {
     int err = unzGoToFirstFile(m_unzip);
     if (UNZ_OK != err) {
-        LOGW("%s",getArchiveLogMessage(err, "unzGoToFirstFile()").c_str());
+        LoggerW("%s",getArchiveLogMessage(err, "unzGoToFirstFile()").c_str());
     }
 
     unsigned int num_file_or_folder_matched = 0;
@@ -308,14 +308,14 @@ unsigned int UnZip::IterateFilesInZip(unz_global_info& gi,
     for (uLong i = 0; i < gi.number_entry; i++) {
 
         if (callback->isCanceled()) {
-            LOGD("Operation cancelled");
+            LoggerD("Operation cancelled");
             throw OperationCanceledException();
         }
 
         err = unzGetCurrentFileInfo(m_unzip, &cur_file_info,
                 tmp_fname, sizeof(tmp_fname), NULL, 0, NULL, 0);
         if (UNZ_OK != err) {
-            LOGE("ret: %d",err);
+            LoggerE("ret: %d",err);
             throwArchiveException(err, "unzGetCurrentFileInfo()");
         }
 
@@ -341,7 +341,7 @@ unsigned int UnZip::IterateFilesInZip(unz_global_info& gi,
         if ((i + 1) < gi.number_entry) {
             err = unzGoToNextFile(m_unzip);
             if (UNZ_OK != err) {
-                LOGE("ret: %d",err);
+                LoggerE("ret: %d",err);
                 throwArchiveException(err, "unzGoToNextFile()");
             }
         }
@@ -354,14 +354,14 @@ void UnZip::extractCurrentFile(const std::string& extract_path,
         const std::string& base_strip_path,
         BaseProgressCallback* callback)
 {
-    LOGD("Entered");
+    LoggerD("Entered");
 
     if (callback->isCanceled()) {
-        LOGD("Operation cancelled");
+        LoggerD("Operation cancelled");
         throw OperationCanceledException();
     }
 
-    LOGD("extract_path: [%s] base_strip_path: [%s] ", extract_path.c_str(),
+    LoggerD("extract_path: [%s] base_strip_path: [%s] ", extract_path.c_str(),
             base_strip_path.c_str());
     UnZipExtractRequest::execute(*this, extract_path, base_strip_path, callback);
 }
@@ -399,7 +399,7 @@ void UnZip::updateCallbackWithArchiveStatistics(ExtractAllProgressCallback* call
 {
     int err = unzGetGlobalInfo(m_unzip, &out_global_info);
     if (UNZ_OK != err) {
-        LOGE("ret: %d",err);
+        LoggerE("ret: %d",err);
         throwArchiveException(err, "unzGetGlobalInfo()");
     }
 
@@ -407,18 +407,18 @@ void UnZip::updateCallbackWithArchiveStatistics(ExtractAllProgressCallback* call
     const auto num_matched = IterateFilesInZip(out_global_info, optional_filter,
             callback, generateArchiveStatistics, &astats);
     if(0 == num_matched) {
-        LOGE("No matching file/directory: [%s] has been found in zip archive",
+        LoggerE("No matching file/directory: [%s] has been found in zip archive",
                 optional_filter.c_str());
-        LOGE("Throwing NotFoundException - Could not extract file from archive");
+        LoggerE("Throwing NotFoundException - Could not extract file from archive");
         throw NotFoundException("Could not extract file from archive");
     }
 
     callback->setExpectedDecompressedSize(astats.uncompressed_size);
-    LOGD("Expected uncompressed size: %s",
+    LoggerD("Expected uncompressed size: %s",
             bytesToReadableString(astats.uncompressed_size).c_str());
 
     callback->setNumberOfFilesToExtract(astats.number_of_files);
-    LOGD("Number entries to extract: files: %d folders: %d", astats.number_of_files,
+    LoggerD("Number entries to extract: files: %d folders: %d", astats.number_of_files,
             astats.number_of_folders);
 }
 
index 3ac57814b30e2a7bc9dd28d5d258b9428552c3bb..1ac274967bd4cbbe03b345981f5cd8bf153567ec 100644 (file)
@@ -75,7 +75,7 @@ void createMissingDirectories(const std::string& path, bool check_first = true)
 {
     if(check_first) {
         const FilePathStatus path_status = getPathStatus(path);
-        //LOGD("[%s] status: %d", path.c_str(), path_status);
+        //LoggerD("[%s] status: %d", path.c_str(), path_status);
         if(FPS_DIRECTORY == path_status) {
             return;
         }
@@ -89,12 +89,12 @@ void createMissingDirectories(const std::string& path, bool check_first = true)
 
             const std::string left_part = path.substr(0,i+1);
             const FilePathStatus status = getPathStatus(left_part);
-            //LOGD("left_part: [%s] status:%d", left_part.c_str(), status);
+            //LoggerD("left_part: [%s] status:%d", left_part.c_str(), status);
 
             if(FPS_DIRECTORY != status) {
                 //TODO investigate 0775 (mode) - filesystem assumed that file should have parent mode
                 if(mkdir(left_part.c_str(), 0775) == -1) {
-                    LOGE("Couldn't create new directory: %s errno:%s",
+                    LoggerE("Couldn't create new directory: %s errno:%s",
                             left_part.c_str(), strerror(errno));
                //TODO check why mkdir return -1 but directory is successfully created
                //     throw UnknownException(
@@ -124,7 +124,7 @@ void changeFileAccessAndModifyDate(const std::string& filepath, tm_unz tmu_date)
 
   ut.actime = ut.modtime = mktime(&newdate);
   if(utime(filepath.c_str(), &ut) == -1) {
-      LOGE("Couldn't set time for: [%s] errno:%s", filepath.c_str(), strerror(errno));
+      LoggerE("Couldn't set time for: [%s] errno:%s", filepath.c_str(), strerror(errno));
   }
 }
 
@@ -155,14 +155,14 @@ UnZipExtractRequest::UnZipExtractRequest(UnZip& owner,
         m_is_directory_entry(false)
 {
     if(!m_callback){
-        LOGE("Callback is null");
+        LoggerE("Callback is null");
         throw UnknownException("Problem with callback functionality");
     }
 }
 
 void UnZipExtractRequest::run()
 {
-    LOGD("Entered");
+    LoggerD("Entered");
 
     getCurrentFileInfo();
 
@@ -182,7 +182,7 @@ UnZipExtractRequest::~UnZipExtractRequest()
 
     if(m_delete_output_file && !m_is_directory_entry) {
         if(std::remove(m_output_filepath.c_str()) != 0) {
-            LOGE("Couldn't remove partial file! "
+            LoggerE("Couldn't remove partial file! "
                     "std::remove(\"%s\") failed with errno:%s",
                     m_output_filepath.c_str(), strerror(errno));
         }
@@ -194,43 +194,43 @@ UnZipExtractRequest::~UnZipExtractRequest()
     if(m_close_unz_current_file) {
         int err = unzCloseCurrentFile (m_owner.m_unzip);
         if(UNZ_OK != err) {
-            LOGW("%s",getArchiveLogMessage(err, "unzCloseCurrentFile()").c_str());
+            LoggerW("%s",getArchiveLogMessage(err, "unzCloseCurrentFile()").c_str());
         }
     }
 }
 
 void UnZipExtractRequest::getCurrentFileInfo()
 {
-    LOGD("Entered");
+    LoggerD("Entered");
     int err = unzGetCurrentFileInfo(m_owner.m_unzip, &m_file_info,
             m_filename_inzip, sizeof(m_filename_inzip), NULL, 0, NULL, 0);
     if (err != UNZ_OK) {
-        LOGE("ret: %d", err);
+        LoggerE("ret: %d", err);
         throwArchiveException(err, "unzGetCurrentFileInfo()");
     }
 
-    LOGD("Input from ZIP: m_filename_inzip: [%s]", m_filename_inzip);
-    LOGD("m_base_strip_path: [%s]", m_base_strip_path.c_str());
+    LoggerD("Input from ZIP: m_filename_inzip: [%s]", m_filename_inzip);
+    LoggerD("m_base_strip_path: [%s]", m_base_strip_path.c_str());
 
     std::string file_path = m_filename_inzip;
     if(!m_base_strip_path.empty()) {
         if(file_path.find(m_base_strip_path) != 0) {
-            LOGW("m_base_strip_path: [%s] is not begin of m_filename_inzip: [%s]!",
+            LoggerW("m_base_strip_path: [%s] is not begin of m_filename_inzip: [%s]!",
                     m_base_strip_path.c_str(),
                     m_filename_inzip);
         }
         else {
             file_path = file_path.substr(m_base_strip_path.length());
-            LOGD("Stripped file name: [%s]", file_path.c_str());
+            LoggerD("Stripped file name: [%s]", file_path.c_str());
         }
     }
     else {
-        LOGD("Not stripped file name: [%s]", file_path.c_str());
+        LoggerD("Not stripped file name: [%s]", file_path.c_str());
     }
 
     m_output_filepath = removeDuplicatedSlashesFromPath(m_extract_path + "/" + file_path);
 
-    LOGD("Packed: [%s], uncompressed_size: %d, will extract to: [%s]",
+    LoggerD("Packed: [%s], uncompressed_size: %d, will extract to: [%s]",
             m_filename_inzip, m_file_info.uncompressed_size,
             m_output_filepath.c_str());
 
@@ -240,7 +240,7 @@ void UnZipExtractRequest::getCurrentFileInfo()
     m_new_dir_status = getPathStatus(m_new_dir_path);
     m_is_directory_entry = name.empty();
 
-    LOGD("New output dir: [%s] status: %d m_is_directory_entry: %d",
+    LoggerD("New output dir: [%s] status: %d m_is_directory_entry: %d",
             m_new_dir_path.c_str(), m_new_dir_status, m_is_directory_entry);
 
     if(FPS_DIRECTORY != m_new_dir_status) {
@@ -258,11 +258,11 @@ void UnZipExtractRequest::getCurrentFileInfo()
                 }
             }
 
-            LOGD("Type: DIRECTORY checking base output directories: [%s]",
+            LoggerD("Type: DIRECTORY checking base output directories: [%s]",
                     base_directories.c_str());
             createMissingDirectories(base_directories, false);
         } else {
-            LOGD("Type: FILE checking output dir: [%s]", m_new_dir_path.c_str());
+            LoggerD("Type: FILE checking output dir: [%s]", m_new_dir_path.c_str());
             createMissingDirectories(m_new_dir_path, false);
         }
     }
@@ -270,20 +270,20 @@ void UnZipExtractRequest::getCurrentFileInfo()
 
 void UnZipExtractRequest::handleDirectoryEntry()
 {
-    LOGD("Entered");
+    LoggerD("Entered");
     if(FPS_DIRECTORY != m_new_dir_status) {
 
         if(FPS_FILE == m_new_dir_status) {
             if(m_callback->getOverwrite()) {    //Is a file & overwrite is set:
                 std::string fn = removeTrailingDirectorySlashFromPath(m_new_dir_path);
                 if(std::remove(fn.c_str()) != 0) {
-                    LOGE("std::remove(\"%s\") failed with errno:%s",
+                    LoggerE("std::remove(\"%s\") failed with errno:%s",
                             m_new_dir_path.c_str(), strerror(errno));
                     throw UnknownException(
                             "Could not overwrite file in output directory");
                 }
             } else {                            //Is a file & overwrite is not set:
-                LOGE("Failed to extract directory, "
+                LoggerE("Failed to extract directory, "
                         "file with the same name exists in output directory");
                 throw UnknownException("Failed to extract directory, "
                         "file with the same name exists in output directory");
@@ -292,14 +292,14 @@ void UnZipExtractRequest::handleDirectoryEntry()
 
         //Try to create new directory in output directory
         if(mkdir(m_new_dir_path.c_str(), 0775) == -1) {
-            LOGE("Couldn't create new directory: %s errno:%s",
+            LoggerE("Couldn't create new directory: %s errno:%s",
                     m_new_dir_path.c_str(), strerror(errno));
             throw UnknownException(
                     "Could not create new directory in extract output directory");
         }
     }
 
-    LOGD("Set dir: [%s] access and modify to: %4d-%2d-%2d %2d:%2d:%2d", m_new_dir_path.c_str(),
+    LoggerD("Set dir: [%s] access and modify to: %4d-%2d-%2d %2d:%2d:%2d", m_new_dir_path.c_str(),
             m_file_info.tmu_date.tm_year,
             m_file_info.tmu_date.tm_mon,
             m_file_info.tmu_date.tm_mday,
@@ -310,16 +310,16 @@ void UnZipExtractRequest::handleDirectoryEntry()
     // Directory already exists we only need to update time
     changeFileAccessAndModifyDate(m_new_dir_path, m_file_info.tmu_date);
 
-    LOGD("Extracted directory entry: [%s]", m_new_dir_path.c_str());
+    LoggerD("Extracted directory entry: [%s]", m_new_dir_path.c_str());
 }
 
 bool UnZipExtractRequest::prepareOutputSubdirectory()
 {
-    LOGD("Entered");
+    LoggerD("Entered");
     //This zip entry points to file - verify that parent directory in output dir exists
     if(FPS_DIRECTORY != m_new_dir_status) {
         if(FPS_FILE == m_new_dir_status) {
-            LOGE("Path: %s is pointing to file not directory!",
+            LoggerE("Path: %s is pointing to file not directory!",
                     m_new_dir_path.c_str());
             throw UnknownException("Failed to extract file from zip archive, "
                     "output path is invalid");
@@ -328,7 +328,7 @@ bool UnZipExtractRequest::prepareOutputSubdirectory()
         //Try to create new directory in output directory
         //TODO investigate 0775 (mode) - filesystem assumed that file should have parent mode
         if(mkdir(m_new_dir_path.c_str(), 0775) == -1) {
-            LOGW("couldn't create new directory: %s errno:%s",
+            LoggerW("couldn't create new directory: %s errno:%s",
                     m_new_dir_path.c_str(), strerror(errno));
             //TODO check why mkdir return -1 but directory is successfully created
             //     throw UnknownException(
@@ -337,14 +337,14 @@ bool UnZipExtractRequest::prepareOutputSubdirectory()
     }
 
     if(m_callback->isCanceled()) {
-        LOGD("Operation cancelled");
+        LoggerD("Operation cancelled");
         throw OperationCanceledException();
     }
 
     const FilePathStatus output_fstatus = getPathStatus(m_output_filepath);
     if(FPS_NOT_EXIST != output_fstatus) {
         if(!m_callback->getOverwrite()) {
-            LOGW("%s exists at output path: [%s], overwrite is set to FALSE",
+            LoggerW("%s exists at output path: [%s], overwrite is set to FALSE",
                     (FPS_DIRECTORY == output_fstatus ? "Directory" : "File"),
                     m_output_filepath.c_str());
 
@@ -353,20 +353,17 @@ bool UnZipExtractRequest::prepareOutputSubdirectory()
         } else {
             if(FPS_DIRECTORY == output_fstatus) {
                 try {
-                    LOGW("STUB Not removing directory");
-                    //filesystem::PathPtr path = filesystem::Path::create(m_output_filepath);
-                    //filesystem::NodePtr node = filesystem::Node::resolve(path);
-                    //node->remove(filesystem::OPT_RECURSIVE);
-                    filesystem::External::removeDirectoryRecursive(m_output_filepath);
-
-                    LOGD("Removed directory: [%s]", m_output_filepath.c_str());
+                    filesystem::PathPtr path = filesystem::Path::create(m_output_filepath);
+                    filesystem::NodePtr node = filesystem::Node::resolve(path);
+                    node->remove(filesystem::OPT_RECURSIVE);
+                    LoggerD("Removed directory: [%s]", m_output_filepath.c_str());
                 } catch(PlatformException& ex) {
-                    LOGE("Remove dir: [%s] failed with exception: %s:%s",
+                    LoggerE("Remove dir: [%s] failed with exception: %s:%s",
                             m_output_filepath.c_str(),
                             ex.name().c_str(), ex.message().c_str());
                     throw UnknownException("Could not overwrite existing directory");
                 } catch (...) {
-                    LOGE("Remove dir: [%s] failed", m_output_filepath.c_str());
+                    LoggerE("Remove dir: [%s] failed", m_output_filepath.c_str());
                     throw UnknownException("Could not overwrite existing directory");
                 }
             } //else {
@@ -380,16 +377,16 @@ bool UnZipExtractRequest::prepareOutputSubdirectory()
 
 void UnZipExtractRequest::handleFileEntry()
 {
-    LOGD("Entered");
+    LoggerD("Entered");
     if(!prepareOutputSubdirectory()) {
-        LOGE("File exists but overwrite is false");
+        LoggerE("File exists but overwrite is false");
         throw InvalidModificationException("file already exists.");
     }
 
     int err = unzOpenCurrentFilePassword(m_owner.m_unzip,
         NULL); //password is not supported yet therefore passing NULL
     if (UNZ_OK != err) {
-        LOGE("ret: %d", err);
+        LoggerE("ret: %d", err);
         throwArchiveException(err, "unzOpenCurrentFilePassword()");
     }
 
@@ -399,14 +396,14 @@ void UnZipExtractRequest::handleFileEntry()
     const size_t buffer_size = m_owner.m_default_buffer_size;
     m_buffer = new(std::nothrow) char[buffer_size];
     if(!m_buffer) {
-        LOGE("Couldn't allocate buffer with size: %s",
+        LoggerE("Couldn't allocate buffer with size: %s",
                 bytesToReadableString(buffer_size).c_str());
         throw UnknownException("Memory allocation failed");
     }
 
     m_output_file = fopen(m_output_filepath.c_str(), "wb");
     if(!m_output_file) {
-        LOGE("Couldn't open output file: %s", m_output_filepath.c_str());
+        LoggerE("Couldn't open output file: %s", m_output_filepath.c_str());
         throw UnknownException("Could not create extracted file");
     }
     m_delete_output_file = true;
@@ -414,7 +411,7 @@ void UnZipExtractRequest::handleFileEntry()
     int read_size = 0;
     bool marked_as_finished = false;
 
-    LOGD("Started extracting: [%s] uncompressed size: %d - %s", m_filename_inzip,
+    LoggerD("Started extracting: [%s] uncompressed size: %d - %s", m_filename_inzip,
             m_file_info.uncompressed_size,
             bytesToReadableString(m_file_info.uncompressed_size).c_str());
 
@@ -428,19 +425,19 @@ void UnZipExtractRequest::handleFileEntry()
     ArchiveFileEntryPtrMapPtr entries = m_callback->getArchiveFile()->getEntryMap();
     auto it = entries->find(m_filename_inzip);
     if (it == entries->end()) {
-        LOGE("Entry not found");
+        LoggerE("Entry not found");
         throw NotFoundException("Entry not found");
     }
 
     while(true) {
         if(m_callback->isCanceled()) {
-            LOGD("Operation cancelled");
+            LoggerD("Operation cancelled");
             throw OperationCanceledException();
         }
 
         read_size = unzReadCurrentFile(m_owner.m_unzip, m_buffer, buffer_size);
         if (read_size < 0) {
-            LOGE("unzReadCurrentFile failed with error code:%d for file:%s", read_size,
+            LoggerE("unzReadCurrentFile failed with error code:%d for file:%s", read_size,
                     m_filename_inzip);
             throw UnknownException("Failed to extract file from zip archive");
         }
@@ -448,12 +445,12 @@ void UnZipExtractRequest::handleFileEntry()
 
             if(extract_callback) {
                 if(!marked_as_finished) {
-                    LOGD("NOT marked_as_finished -> increment extracted files counter");
+                    LoggerD("NOT marked_as_finished -> increment extracted files counter");
                     extract_callback->finishedExtractingFile();
 
                     //Call progress callback only if we expected empty file
                     if(m_file_info.uncompressed_size == 0) {
-                        LOGD("Calling progress callback(%f, %s)",
+                        LoggerD("Calling progress callback(%f, %s)",
                                 extract_callback->getOverallProgress(), m_filename_inzip);
                         extract_callback->callProgressCallbackOnMainThread(
                                 extract_callback->getOverallProgress(), it->second);
@@ -466,14 +463,14 @@ void UnZipExtractRequest::handleFileEntry()
         }
 
         if (fwrite(m_buffer, read_size, 1, m_output_file) != 1) {
-            LOGE("Couldn't write extracted data to output file:%s",
+            LoggerE("Couldn't write extracted data to output file:%s",
                     m_output_filepath.c_str());
             throw UnknownException("Could not write extract file into output file");
         }
 
         if(extract_callback) {
             extract_callback->extractedPartOfFile(read_size);
-            LOGD("File: [%s] extracted: %s - %f%%; total progress %f%%", m_filename_inzip,
+            LoggerD("File: [%s] extracted: %s - %f%%; total progress %f%%", m_filename_inzip,
                     bytesToReadableString(read_size).c_str(),
                     100.0f * extract_callback->getCurrentFileProgress(),
                     100.0f * extract_callback->getOverallProgress());
@@ -482,14 +479,14 @@ void UnZipExtractRequest::handleFileEntry()
             // overal progres: 1.0 if all files are extracted
             //
             if(extract_callback->getCurrentFileProgress() >= 1.0) {
-                LOGD("Current file: [%s] progress: %f >= 1.0 -> "
+                LoggerD("Current file: [%s] progress: %f >= 1.0 -> "
                         "marked_as_finished = true and increment extracted files counter",
                         m_filename_inzip, extract_callback->getCurrentFileProgress());
                 marked_as_finished = true;
                 extract_callback->finishedExtractingFile();
             }
 
-            LOGD("Calling progress callback(%f, %s)",
+            LoggerD("Calling progress callback(%f, %s)",
                     extract_callback->getOverallProgress(), m_filename_inzip);
             extract_callback->callProgressCallbackOnMainThread(
                     extract_callback->getOverallProgress(), it->second);
index 12ba712784b2c1179dabd1ec71eb4d6bcbf2d285..1de915d66ef91b6dbf267fbae10870173b18ecd2 100644 (file)
@@ -71,7 +71,7 @@ Zip::Zip(const std::string& filename, ZipOpenMode open_mode) :
         m_zip(NULL),
         m_default_buffer_size(1024 * 1024)
 {
-    LOGD("Entered");
+    LoggerD("Entered");
 
     int append_mode = APPEND_STATUS_CREATE;
     if(ZOM_CREATEAFTER == open_mode) {
@@ -79,11 +79,11 @@ Zip::Zip(const std::string& filename, ZipOpenMode open_mode) :
     } else if(ZOM_ADDINZIP == open_mode) {
         append_mode = APPEND_STATUS_ADDINZIP;
     }
-    LOGD("append_mode: %d", append_mode);
+    LoggerD("append_mode: %d", append_mode);
 
     m_zip = zipOpen(filename.c_str(), append_mode);
     if(!m_zip) {
-        LOGE("zipOpen returned NULL!");
+        LoggerE("zipOpen returned NULL!");
         throw UnknownException("Opening/creating zip file failed");
     }
     m_is_open = true;
@@ -96,9 +96,9 @@ Zip::~Zip()
 
 void Zip::close()
 {
-    LOGD("Entered");
+    LoggerD("Entered");
     if(!m_is_open) {
-        LOGD("Already closed - exiting.");
+        LoggerD("Already closed - exiting.");
         return;
     }
 
@@ -106,7 +106,7 @@ void Zip::close()
     m_zip = NULL;
 
     if (errclose != ZIP_OK) {
-        LOGE("ret: %d", errclose);
+        LoggerE("ret: %d", errclose);
         throwArchiveException(errclose, "zipClose()");
     }
     m_is_open = false;
@@ -114,25 +114,25 @@ void Zip::close()
 
 ZipPtr Zip::createNew(const std::string& filename)
 {
-    LOGD("Entered");
+    LoggerD("Entered");
     return ZipPtr(new Zip(filename, ZOM_CREATE));
 }
 
 ZipPtr Zip::open(const std::string& filename)
 {
-    LOGD("Entered");
+    LoggerD("Entered");
     return ZipPtr(new Zip(filename, ZOM_ADDINZIP));
 }
 
 void Zip::addFile(AddProgressCallback*& callback)
 {
-    LOGD("Entered");
+    LoggerD("Entered");
     if(!callback) {
-        LOGE("callback is NULL!");
+        LoggerE("callback is NULL!");
         throw UnknownException("Could not add file(-s) to archive");
     }
     if(!m_is_open) {
-        LOGE("Zip file not opened - exiting");
+        LoggerE("Zip file not opened - exiting");
         throw UnknownException("Could not add file(-s) to archive - zip file closed");
     }
 
index ac04515979515ba2f9d5b1602e194de3e7ceb290..7665cdf6cda0a72ca96cb6cdb2a9371ff0607b73 100644 (file)
@@ -58,7 +58,7 @@ ZipAddRequest::~ZipAddRequest()
     if(m_new_file_in_zip_opened) {
         int err = zipCloseFileInZip(m_owner.m_zip);
         if (ZIP_OK != err) {
-            LOGE("%s",getArchiveLogMessage(err, "zipCloseFileInZip()").c_str());
+            LoggerE("%s",getArchiveLogMessage(err, "zipCloseFileInZip()").c_str());
         }
     }
 }
@@ -72,17 +72,17 @@ void ZipAddRequest::execute(Zip& owner, AddProgressCallback*& callback)
 void ZipAddRequest::run()
 {
     if(!m_callback) {
-        LOGE("m_callback is NULL");
+        LoggerE("m_callback is NULL");
         throw UnknownException("Could not add file(-s) to archive");
     }
 
     if(!m_callback->getFileEntry()) {
-        LOGE("m_callback->getFileEntry() is NULL");
+        LoggerE("m_callback->getFileEntry() is NULL");
         throw InvalidValuesException("Provided ArchiveFileEntry is not correct");
     }
 
     if(m_callback->isCanceled()) {
-        LOGD("Operation cancelled");
+        LoggerD("Operation cancelled");
         throw OperationCanceledException();
     }
 
@@ -91,7 +91,7 @@ void ZipAddRequest::run()
     m_root_src_file_node = m_root_src_file->getNode();
 
     //We just need read permission to list files in subdirectories
-    LOGW("STUB Not setting PERM_READ permissions");
+    LoggerW("STUB Not setting PERM_READ permissions");
     //m_root_src_file_node->setPermissions(filesystem::PERM_READ);
 
     std::string src_basepath, src_name;
@@ -99,7 +99,7 @@ void ZipAddRequest::run()
             src_name);
 
     m_absoulte_path_to_extract = src_basepath;
-    LOGD("m_absoulte_path_to_extract: [%s]", m_absoulte_path_to_extract.c_str());
+    LoggerD("m_absoulte_path_to_extract: [%s]", m_absoulte_path_to_extract.c_str());
 
     m_destination_path_in_zip = removeDuplicatedSlashesFromPath(
             m_callback->getFileEntry()->getDestination());
@@ -108,7 +108,7 @@ void ZipAddRequest::run()
     // inside this zip archive.
     //
     if(m_destination_path_in_zip.length() > 0) {
-        LOGD("destination is: [%s]", m_destination_path_in_zip.c_str());
+        LoggerD("destination is: [%s]", m_destination_path_in_zip.c_str());
 
         for(size_t i = 0; i < m_destination_path_in_zip.length(); ++i) {
             const char cur_char = m_destination_path_in_zip[i];
@@ -119,7 +119,7 @@ void ZipAddRequest::run()
                 //Extract left side with '/':
                 const std::string new_dir = m_destination_path_in_zip.substr(0, i + 1);
 
-                LOGD("Adding empty directory: [%s] to archive", new_dir.c_str());
+                LoggerD("Adding empty directory: [%s] to archive", new_dir.c_str());
                 addEmptyDirectoryToZipArchive(new_dir);
             }
         }
@@ -131,7 +131,7 @@ void ZipAddRequest::run()
     addNodeAndSubdirsToList(m_root_src_file_node, all_sub_nodes);
 
     if(m_callback->isCanceled()) {
-        LOGD("Operation cancelled");
+        LoggerD("Operation cancelled");
         throw OperationCanceledException();
     }
 
@@ -150,17 +150,17 @@ void ZipAddRequest::run()
             ++m_files_to_compress;
         }
 
-        LOGD("[%d] : [%s] --zip--> [%s] | size: %s", i, (*it)->getPath()->getFullPath().c_str(),
+        LoggerD("[%d] : [%s] --zip--> [%s] | size: %s", i, (*it)->getPath()->getFullPath().c_str(),
                 getNameInZipArchiveFor(*it, m_callback->getFileEntry()->getStriped()).c_str(),
                 bytesToReadableString(size).c_str());
     }
 
-    LOGD("m_files_to_compress: %d", m_files_to_compress);
-    LOGD("m_bytes_to_compress: %llu (%s)", m_bytes_to_compress,
+    LoggerD("m_files_to_compress: %d", m_files_to_compress);
+    LoggerD("m_bytes_to_compress: %llu (%s)", m_bytes_to_compress,
             bytesToReadableString(m_bytes_to_compress).c_str());
 
     if(m_callback->isCanceled()) {
-        LOGD("Operation cancelled");
+        LoggerD("Operation cancelled");
         throw OperationCanceledException();
     }
 
@@ -180,7 +180,7 @@ void ZipAddRequest::addNodeAndSubdirsToList(filesystem::NodePtr src_node,
     out_list_of_child_nodes.push_back(src_node);
 
     if(filesystem::NT_DIRECTORY == src_node->getType()) {
-        LOGW("STUB Not generating recursive list of files in directory");
+        LoggerW("STUB Not generating recursive list of files in directory");
         //auto child_nodes = src_node->getChildNodes();
         //for(auto it = child_nodes.begin(); it != child_nodes.end(); ++it) {
         //    addNodeAndSubdirsToList(*it, out_list_of_child_nodes);
@@ -190,24 +190,24 @@ void ZipAddRequest::addNodeAndSubdirsToList(filesystem::NodePtr src_node,
 
 void ZipAddRequest::addEmptyDirectoryToZipArchive(std::string name_in_zip)
 {
-    LOGD("Entered name_in_zip:%s", name_in_zip.c_str());
+    LoggerD("Entered name_in_zip:%s", name_in_zip.c_str());
 
     if(name_in_zip.length() == 0) {
-        LOGW("Trying to create directory with empty name - \"\"");
+        LoggerW("Trying to create directory with empty name - \"\"");
         return;
     }
 
     const char last_char = name_in_zip[name_in_zip.length()-1];
     if(last_char != '/' && last_char != '\\') {
             name_in_zip += "/";
-            LOGD("Corrected name_in_zip: [%s]", name_in_zip.c_str());
+            LoggerD("Corrected name_in_zip: [%s]", name_in_zip.c_str());
     }
 
     if(m_new_file_in_zip_opened) {
-        LOGE("WARNING: Previous new file in zip archive is opened!");
+        LoggerE("WARNING: Previous new file in zip archive is opened!");
         int err = zipCloseFileInZip(m_owner.m_zip);
         if (ZIP_OK != err) {
-            LOGE("%s",getArchiveLogMessage(err, "zipCloseFileInZip()").c_str());
+            LoggerE("%s",getArchiveLogMessage(err, "zipCloseFileInZip()").c_str());
         }
     }
 
@@ -218,18 +218,18 @@ void ZipAddRequest::addEmptyDirectoryToZipArchive(std::string name_in_zip)
             &is_directory, &conflicting_name)) {
 
         if(!is_directory) {
-            LOGE("Entry: [%s] exists and is NOT directory!", conflicting_name.c_str());
+            LoggerE("Entry: [%s] exists and is NOT directory!", conflicting_name.c_str());
 
-            LOGE("Throwing InvalidValuesException - File with the same name exists");
+            LoggerE("Throwing InvalidValuesException - File with the same name exists");
             throw InvalidValuesException("File with the same name exists");
         }
 
-        LOGD("Directory: [%s] already exists -> nothing to do", name_in_zip.c_str());
+        LoggerD("Directory: [%s] already exists -> nothing to do", name_in_zip.c_str());
             return;
     }
 
     if(m_callback->isCanceled()) {
-        LOGD("Operation cancelled");
+        LoggerD("Operation cancelled");
         throw OperationCanceledException();
     }
 
@@ -258,7 +258,7 @@ void ZipAddRequest::addEmptyDirectoryToZipArchive(std::string name_in_zip)
             NULL, 0);
 
     if (err != ZIP_OK) {
-        LOGE("ret: %d", err);
+        LoggerE("ret: %d", err);
         throwArchiveException(err, "zipOpenNewFileInZip3()");
     }
 
@@ -266,10 +266,10 @@ void ZipAddRequest::addEmptyDirectoryToZipArchive(std::string name_in_zip)
 
     err = zipCloseFileInZip(m_owner.m_zip);
     if (ZIP_OK != err) {
-        LOGE("%s",getArchiveLogMessage(err, "zipCloseFileInZip()").c_str());
+        LoggerE("%s",getArchiveLogMessage(err, "zipCloseFileInZip()").c_str());
     }
 
-    LOGD("Added new empty directory to archive: [%s]", name_in_zip.c_str());
+    LoggerD("Added new empty directory to archive: [%s]", name_in_zip.c_str());
     m_new_file_in_zip_opened = false;
 }
 
@@ -279,22 +279,22 @@ void ZipAddRequest::addToZipArchive(filesystem::NodePtr src_file_node)
             m_callback->getFileEntry()->getStriped());
     const std::string src_file_path = src_file_node->getPath()->getFullPath();
 
-    LOGD("Compress: [%s] to zip archive as: [%s]", src_file_path.c_str(),
+    LoggerD("Compress: [%s] to zip archive as: [%s]", src_file_path.c_str(),
             name_in_zip.c_str());
 
     zip_fileinfo new_file_info;
     Zip::generateZipFileInfo(src_file_path, new_file_info);
 
     if(m_new_file_in_zip_opened) {
-        LOGE("WARNING: Previous new file in zip archive is opened!");
+        LoggerE("WARNING: Previous new file in zip archive is opened!");
         int err = zipCloseFileInZip(m_owner.m_zip);
         if (ZIP_OK != err) {
-            LOGE("zipCloseFileInZip failed with error: %d", err);
+            LoggerE("zipCloseFileInZip failed with error: %d", err);
         }
     }
 
     if(m_callback->isCanceled()) {
-        LOGD("Operation cancelled");
+        LoggerD("Operation cancelled");
         throw OperationCanceledException();
     }
 
@@ -302,11 +302,11 @@ void ZipAddRequest::addToZipArchive(filesystem::NodePtr src_file_node)
     if(m_callback->getArchiveFile()->isEntryWithNameInArchive(name_in_zip,
             NULL, &conflicting_name)) {
 
-        LOGE("Cannot add new entry with name name: [%s] "
+        LoggerE("Cannot add new entry with name name: [%s] "
                 "it would conflict with existing entry: [%s]",
                 name_in_zip.c_str(), conflicting_name.c_str());
 
-        LOGE("Throwing InvalidModificationException - Archive entry name conflicts");
+        LoggerE("Throwing InvalidModificationException - Archive entry name conflicts");
         throw InvalidModificationException("Archive entry name conflicts");
     }
 
@@ -318,14 +318,14 @@ void ZipAddRequest::addToZipArchive(filesystem::NodePtr src_file_node)
             NULL, 0);
 
     if (err != ZIP_OK) {
-        LOGE("Error opening new file: [%s] in zipfile", name_in_zip.c_str());
+        LoggerE("Error opening new file: [%s] in zipfile", name_in_zip.c_str());
         throw UnknownException("Could not add new file to zip archive");
     }
 
     m_new_file_in_zip_opened = true;
 
     if(m_input_file) {
-        LOGW("WARNING: Previous m_input_file has not been closed");
+        LoggerW("WARNING: Previous m_input_file has not been closed");
         fclose(m_input_file);
         m_input_file = NULL;
     }
@@ -342,16 +342,16 @@ void ZipAddRequest::addToZipArchive(filesystem::NodePtr src_file_node)
     cur_afentry->setStriped(entry->getStriped());
     cur_afentry->setSize(0);
 
-    LOGD("m_bytes_compressed:%llu / m_bytes_to_compress: %llu",
+    LoggerD("m_bytes_compressed:%llu / m_bytes_to_compress: %llu",
             m_bytes_compressed, m_bytes_to_compress);
 
-    LOGD("m_files_compressed:%d / m_files_to_compress: %d",
+    LoggerD("m_files_compressed:%d / m_files_to_compress: %d",
             m_files_compressed, m_files_to_compress);
 
     if(src_file_node->getType() == filesystem::NT_FILE) {
         m_input_file = fopen(src_file_path.c_str(), "rb");
         if (!m_input_file) {
-            LOGE("Error opening source file:%s", src_file_path.c_str());
+            LoggerE("Error opening source file:%s", src_file_path.c_str());
             throw UnknownException("Could not open file to be added");
         }
 
@@ -359,7 +359,7 @@ void ZipAddRequest::addToZipArchive(filesystem::NodePtr src_file_node)
         fseek(m_input_file, 0, SEEK_END);
         const size_t in_file_size = ftell(m_input_file);
         fseek(m_input_file, 0, SEEK_SET);
-        LOGD("Source file: [%s] size: %d - %s", src_file_path.c_str(),
+        LoggerD("Source file: [%s] size: %d - %s", src_file_path.c_str(),
                 in_file_size,
                 bytesToReadableString(in_file_size).c_str());
 
@@ -368,7 +368,7 @@ void ZipAddRequest::addToZipArchive(filesystem::NodePtr src_file_node)
         if(!m_buffer) {
             m_buffer = new(std::nothrow) char[m_buffer_size];
             if(!m_buffer) {
-                LOGE("Couldn't allocate m_buffer");
+                LoggerE("Couldn't allocate m_buffer");
                 throw UnknownException("Memory allocation error");
             }
         }
@@ -380,11 +380,11 @@ void ZipAddRequest::addToZipArchive(filesystem::NodePtr src_file_node)
             size_read = fread(m_buffer, 1, m_buffer_size, m_input_file);
             if (size_read < m_buffer_size &&
                         feof(m_input_file) == 0) {
-                LOGE("Error reading source file: %s\n", src_file_path.c_str());
+                LoggerE("Error reading source file: %s\n", src_file_path.c_str());
                 throw UnknownException("New file addition failed");
             }
 
-            LOGD("Read: %d bytes from input file:[%s]", size_read,
+            LoggerD("Read: %d bytes from input file:[%s]", size_read,
                     src_file_path.c_str());
             total_bytes_read += size_read;
             m_bytes_compressed += size_read;
@@ -392,19 +392,19 @@ void ZipAddRequest::addToZipArchive(filesystem::NodePtr src_file_node)
             if (size_read > 0) {
                 err = zipWriteInFileInZip (m_owner.m_zip, m_buffer, size_read);
                 if (err < 0) {
-                    LOGE("Error during adding file: %s into zip archive",
+                    LoggerE("Error during adding file: %s into zip archive",
                             src_file_path.c_str());
                     throw UnknownException("New file addition failed");
                 }
             }
 
             if(total_bytes_read == in_file_size) {
-                LOGD("Finished reading and compressing source file: [%s]",
+                LoggerD("Finished reading and compressing source file: [%s]",
                         src_file_path.c_str());
                 ++m_files_compressed;
             }
 
-            LOGD("Callculatting overall progress: %llu/%llu bytes; "
+            LoggerD("Callculatting overall progress: %llu/%llu bytes; "
                     "%d/%d files; current file: [%s] progress: %d/%d bytes; ",
                     m_bytes_compressed, m_bytes_to_compress,
                     m_files_compressed, m_files_to_compress,
@@ -417,18 +417,18 @@ void ZipAddRequest::addToZipArchive(filesystem::NodePtr src_file_node)
                         static_cast<double>(m_bytes_to_compress + m_files_to_compress);
             }
 
-            LOGD("Wrote: %s total progress: %.2f%% %d/%d files",
+            LoggerD("Wrote: %s total progress: %.2f%% %d/%d files",
                     bytesToReadableString(size_read).c_str(), progress * 100.0,
                     m_files_compressed, m_files_to_compress);
 
-            LOGD("Calling add onprogress callback(%f, %s)", progress,
+            LoggerD("Calling add onprogress callback(%f, %s)", progress,
                     name_in_zip.c_str());
             m_callback->callProgressCallbackOnMainThread(progress, cur_afentry);
 
         } while (size_read > 0 && total_bytes_read < in_file_size);
 
         if(in_file_size != total_bytes_read) {
-            LOGE("in_file_size(%d) != total_bytes_read(%d)", in_file_size,
+            LoggerE("in_file_size(%d) != total_bytes_read(%d)", in_file_size,
                     total_bytes_read);
             throw UnknownException("Could not add file to archive");
         }
@@ -439,7 +439,7 @@ void ZipAddRequest::addToZipArchive(filesystem::NodePtr src_file_node)
 
     err = zipCloseFileInZip(m_owner.m_zip);
     if (ZIP_OK != err) {
-        LOGE("Error in closing added file:%s in zipfile", src_file_path.c_str());
+        LoggerE("Error in closing added file:%s in zipfile", src_file_path.c_str());
     }
 
     m_new_file_in_zip_opened = false;
@@ -499,17 +499,17 @@ std::string ZipAddRequest::getNameInZipArchiveFor(filesystem::NodePtr node, bool
 
     const size_t pos = node_full_path.find(m_absoulte_path_to_extract);
     if(std::string::npos == pos) {
-        LOGW("node: [%s] is not containing m_absoulte_path_to_extract: [%s]!",
+        LoggerW("node: [%s] is not containing m_absoulte_path_to_extract: [%s]!",
                 node_full_path.c_str(),
                 m_absoulte_path_to_extract.c_str());
     }
 
     cut_path = node_full_path.substr(pos+m_absoulte_path_to_extract.length());
-    LOGD("node_full_path:%s cut_path: %s", node_full_path.c_str(), cut_path.c_str());
+    LoggerD("node_full_path:%s cut_path: %s", node_full_path.c_str(), cut_path.c_str());
 
     if(!strip) {
         cut_path = m_callback->getBaseVirtualPath() + "/" + cut_path;
-        LOGD("nonstripped cut_path: %s", cut_path.c_str());
+        LoggerD("nonstripped cut_path: %s", cut_path.c_str());
     }
 
     std::string name = generateFullPathForZip(m_destination_path_in_zip + "/" + cut_path);
@@ -518,7 +518,7 @@ std::string ZipAddRequest::getNameInZipArchiveFor(filesystem::NodePtr node, bool
                 && name[name.length()-1] != '/'
                 && name[name.length()-1] != '\\') {
             name += "/";
-            LOGD("Directory: [%s] added \\", name.c_str());
+            LoggerD("Directory: [%s] added \\", name.c_str());
         }
     }