OSDN Git Service

Shell Extension for Windows 11 or later (5)
[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 "OptionsMgr.h"
12 #include "OptionsDef.h"
13 #include "MergeApp.h"
14 #include <list>
15 #include <Poco/Mutex.h>
16
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;
21
22 static Merge7zFormatMergePluginImpl *GetInstance()
23 {
24         if (g_pluginformat == nullptr)
25         {
26                 g_pluginformat = new Merge7zFormatMergePluginImpl();
27                 Poco::FastMutex::ScopedLock lock(g_mutex);
28                 g_pluginformat_list.emplace_back(g_pluginformat);
29         }
30         return g_pluginformat;
31 }
32
33 Merge7z::Format *Merge7zFormatMergePluginImpl::GuessFormat(const String& path)
34 {
35         if (!GetOptionsMgr()->GetBool(OPT_PLUGINS_ENABLED))
36                 return nullptr;
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)
44                 return nullptr;
45         if (!plugin::InvokeIsFolder(path, plugin->m_lpDispatch))
46                 return nullptr;
47         format->m_plugin = plugin;
48         return format;
49 }
50
51 HRESULT Merge7zFormatMergePluginImpl::DeCompressArchive(HWND, LPCTSTR path, LPCTSTR folder)
52 {
53         if (m_plugin == nullptr)
54                 return E_FAIL;
55         paths::CreateIfNeeded(path);
56         int nChanged = 0;
57         int subcode = 0;
58         return plugin::InvokeUnpackFolder(path, folder, nChanged, m_plugin->m_lpDispatch, subcode) ? S_OK : E_FAIL;
59 }
60
61 HRESULT Merge7zFormatMergePluginImpl::CompressArchive(HWND, LPCTSTR path, Merge7z::DirItemEnumerator *)
62 {
63         return E_FAIL;
64 }
65
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; }
75
76 BSTR Merge7zFormatMergePluginImpl::GetDefaultName(HWND, LPCTSTR path)
77 {
78         return SysAllocString(L"");
79 }
80
81 void Merge7zFormatMergePluginImpl::SetPackingInfo(const PackingInfo* infoUnpacker)
82 {
83         GetInstance()->m_infoUnpacker = infoUnpacker ? *infoUnpacker : PackingInfo();
84 }
85
86 PackingInfo *Merge7zFormatMergePluginImpl::GetPackingInfo()
87 {
88         return &GetInstance()->m_infoUnpacker;
89 }