OSDN Git Service

FileTransform: Remove m_subcode from PackingInfo class
[winmerge-jp/winmerge-jp.git] / Src / Merge7zFormatMergePluginImpl.cpp
1 /** 
2  * @file  Merge7zFormatMergePluginImpl.cpp
3  *
4  * @brief Implementation file for Merge7zFormatMergePluginImpl class
5  */
6 #include "pch.h"
7 #include "Merge7zFormatMergePluginImpl.h"
8 #include "paths.h"
9 #include "Plugins.h"
10 #include "Merge7zFormatRegister.h"
11 #include <list>
12 #include <Poco/Mutex.h>
13
14 static Merge7zFormatRegister g_autoregister(&Merge7zFormatMergePluginImpl::GuessFormat);
15 static __declspec(thread) Merge7zFormatMergePluginImpl *g_pluginformat;
16 static std::list<std::unique_ptr<Merge7zFormatMergePluginImpl> > g_pluginformat_list;
17 static Poco::FastMutex g_mutex;
18
19 static Merge7zFormatMergePluginImpl *GetInstance()
20 {
21         if (g_pluginformat == nullptr)
22         {
23                 g_pluginformat = new Merge7zFormatMergePluginImpl();
24                 Poco::FastMutex::ScopedLock lock(g_mutex);
25                 g_pluginformat_list.emplace_back(g_pluginformat);
26         }
27         return g_pluginformat;
28 }
29
30 Merge7z::Format *Merge7zFormatMergePluginImpl::GuessFormat(const String& path)
31 {
32         Merge7zFormatMergePluginImpl *format = GetInstance();
33         PluginInfo *plugin = nullptr;
34         if (format->m_infoUnpacker.m_PluginOrPredifferMode != PLUGIN_MODE::PLUGIN_MANUAL)
35                 plugin = CAllThreadsScripts::GetActiveSet()->GetAutomaticPluginByFilter(L"FILE_FOLDER_PACK_UNPACK", path);
36         else if (!format->m_infoUnpacker.m_PluginName.empty())
37                 plugin = CAllThreadsScripts::GetActiveSet()->GetPluginByName(L"FILE_FOLDER_PACK_UNPACK", format->m_infoUnpacker.m_PluginName);
38         if (plugin == nullptr)
39                 return nullptr;
40         if (!plugin::InvokeIsFolder(path, plugin->m_lpDispatch))
41                 return nullptr;
42         format->m_plugin = plugin;
43         return format;
44 }
45
46 HRESULT Merge7zFormatMergePluginImpl::DeCompressArchive(HWND, LPCTSTR path, LPCTSTR folder)
47 {
48         if (m_plugin == nullptr)
49                 return E_FAIL;
50         paths::CreateIfNeeded(path);
51         int nChanged = 0;
52         int subcode = 0;
53         return plugin::InvokeUnpackFolder(path, folder, nChanged, m_plugin->m_lpDispatch, subcode) ? S_OK : E_FAIL;
54 }
55
56 HRESULT Merge7zFormatMergePluginImpl::CompressArchive(HWND, LPCTSTR path, Merge7z::DirItemEnumerator *)
57 {
58         return E_FAIL;
59 }
60
61 Merge7z::Format::Inspector *Merge7zFormatMergePluginImpl::Open(HWND, LPCTSTR) { return nullptr; }
62 Merge7z::Format::Updater *Merge7zFormatMergePluginImpl::Update(HWND, LPCTSTR) { return nullptr; }
63 HRESULT Merge7zFormatMergePluginImpl::GetHandlerProperty(HWND, PROPID, PROPVARIANT *, VARTYPE) { return E_FAIL; }
64 BSTR Merge7zFormatMergePluginImpl::GetHandlerName(HWND) { return nullptr; }
65 BSTR Merge7zFormatMergePluginImpl::GetHandlerClassID(HWND) { return nullptr; }
66 BSTR Merge7zFormatMergePluginImpl::GetHandlerExtension(HWND) { return nullptr; }
67 BSTR Merge7zFormatMergePluginImpl::GetHandlerAddExtension(HWND) { return nullptr; }
68 VARIANT_BOOL Merge7zFormatMergePluginImpl::GetHandlerUpdate(HWND) { return VARIANT_FALSE; }
69 VARIANT_BOOL Merge7zFormatMergePluginImpl::GetHandlerKeepName(HWND) { return VARIANT_FALSE; }
70
71 BSTR Merge7zFormatMergePluginImpl::GetDefaultName(HWND, LPCTSTR path)
72 {
73         return SysAllocString(L"");
74 }
75
76 void Merge7zFormatMergePluginImpl::SetPackingInfo(const PackingInfo* infoUnpacker)
77 {
78         GetInstance()->m_infoUnpacker = infoUnpacker ? *infoUnpacker : PackingInfo();
79 }
80
81 PackingInfo *Merge7zFormatMergePluginImpl::GetPackingInfo()
82 {
83         return &GetInstance()->m_infoUnpacker;
84 }