2 * @file Merge7zFormatMergePluginImpl.cpp
4 * @brief Implementation file for Merge7zFormatMergePluginImpl class
7 #include "Merge7zFormatMergePluginImpl.h"
10 #include "Merge7zFormatRegister.h"
11 #include "OptionsMgr.h"
12 #include "OptionsDef.h"
15 #include <Poco/Mutex.h>
17 static Merge7zFormatRegister g_autoregister(&Merge7zFormatMergePluginImpl::GuessFormat);
18 static __declspec(thread) Merge7zFormatMergePluginImpl *g_pluginformat;
19 static std::list<std::unique_ptr<Merge7zFormatMergePluginImpl> > g_pluginformat_list;
20 static Poco::FastMutex g_mutex;
22 static Merge7zFormatMergePluginImpl *GetInstance()
24 if (g_pluginformat == nullptr)
26 g_pluginformat = new Merge7zFormatMergePluginImpl();
27 Poco::FastMutex::ScopedLock lock(g_mutex);
28 g_pluginformat_list.emplace_back(g_pluginformat);
30 return g_pluginformat;
33 Merge7z::Format *Merge7zFormatMergePluginImpl::GuessFormat(const String& path)
35 if (!GetOptionsMgr()->GetBool(OPT_PLUGINS_ENABLED))
37 Merge7zFormatMergePluginImpl *format = GetInstance();
38 PluginInfo *plugin = nullptr;
39 if (format->m_infoUnpacker.GetPluginPipeline().find(_T("<Automatic>")) != String::npos)
40 plugin = CAllThreadsScripts::GetActiveSet()->GetAutomaticPluginByFilter(L"FILE_FOLDER_PACK_UNPACK", path);
41 else if (!format->m_infoUnpacker.GetPluginPipeline().empty())
42 plugin = CAllThreadsScripts::GetActiveSet()->GetPluginByName(L"FILE_FOLDER_PACK_UNPACK", format->m_infoUnpacker.GetPluginPipeline());
43 if (plugin == nullptr)
45 if (!plugin::InvokeIsFolder(path, plugin->m_lpDispatch))
47 format->m_plugin = plugin;
51 HRESULT Merge7zFormatMergePluginImpl::DeCompressArchive(HWND, LPCTSTR path, LPCTSTR folder)
53 if (m_plugin == nullptr)
55 paths::CreateIfNeeded(path);
58 return plugin::InvokeUnpackFolder(path, folder, nChanged, m_plugin->m_lpDispatch, subcode) ? S_OK : E_FAIL;
61 HRESULT Merge7zFormatMergePluginImpl::CompressArchive(HWND, LPCTSTR path, Merge7z::DirItemEnumerator *)
66 Merge7z::Format::Inspector *Merge7zFormatMergePluginImpl::Open(HWND, LPCTSTR) { return nullptr; }
67 Merge7z::Format::Updater *Merge7zFormatMergePluginImpl::Update(HWND, LPCTSTR) { return nullptr; }
68 HRESULT Merge7zFormatMergePluginImpl::GetHandlerProperty(HWND, PROPID, PROPVARIANT *, VARTYPE) { return E_FAIL; }
69 BSTR Merge7zFormatMergePluginImpl::GetHandlerName(HWND) { return nullptr; }
70 BSTR Merge7zFormatMergePluginImpl::GetHandlerClassID(HWND) { return nullptr; }
71 BSTR Merge7zFormatMergePluginImpl::GetHandlerExtension(HWND) { return nullptr; }
72 BSTR Merge7zFormatMergePluginImpl::GetHandlerAddExtension(HWND) { return nullptr; }
73 VARIANT_BOOL Merge7zFormatMergePluginImpl::GetHandlerUpdate(HWND) { return VARIANT_FALSE; }
74 VARIANT_BOOL Merge7zFormatMergePluginImpl::GetHandlerKeepName(HWND) { return VARIANT_FALSE; }
76 BSTR Merge7zFormatMergePluginImpl::GetDefaultName(HWND, LPCTSTR path)
78 return SysAllocString(L"");
81 void Merge7zFormatMergePluginImpl::SetPackingInfo(const PackingInfo* infoUnpacker)
83 GetInstance()->m_infoUnpacker = infoUnpacker ? *infoUnpacker : PackingInfo();
86 PackingInfo *Merge7zFormatMergePluginImpl::GetPackingInfo()
88 return &GetInstance()->m_infoUnpacker;