OSDN Git Service

Avoid an assertion failure when loading settings from winmerge.ini
[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         return plugin::InvokeUnpackFolder(path, folder, nChanged, m_plugin->m_lpDispatch, m_infoUnpacker.m_subcode) ? S_OK : E_FAIL;
53 }
54
55 HRESULT Merge7zFormatMergePluginImpl::CompressArchive(HWND, LPCTSTR path, Merge7z::DirItemEnumerator *)
56 {
57         return E_FAIL;
58 }
59
60 Merge7z::Format::Inspector *Merge7zFormatMergePluginImpl::Open(HWND, LPCTSTR) { return nullptr; }
61 Merge7z::Format::Updater *Merge7zFormatMergePluginImpl::Update(HWND, LPCTSTR) { return nullptr; }
62 HRESULT Merge7zFormatMergePluginImpl::GetHandlerProperty(HWND, PROPID, PROPVARIANT *, VARTYPE) { return E_FAIL; }
63 BSTR Merge7zFormatMergePluginImpl::GetHandlerName(HWND) { return nullptr; }
64 BSTR Merge7zFormatMergePluginImpl::GetHandlerClassID(HWND) { return nullptr; }
65 BSTR Merge7zFormatMergePluginImpl::GetHandlerExtension(HWND) { return nullptr; }
66 BSTR Merge7zFormatMergePluginImpl::GetHandlerAddExtension(HWND) { return nullptr; }
67 VARIANT_BOOL Merge7zFormatMergePluginImpl::GetHandlerUpdate(HWND) { return VARIANT_FALSE; }
68 VARIANT_BOOL Merge7zFormatMergePluginImpl::GetHandlerKeepName(HWND) { return VARIANT_FALSE; }
69
70 BSTR Merge7zFormatMergePluginImpl::GetDefaultName(HWND, LPCTSTR path)
71 {
72         return SysAllocString(L"");
73 }
74
75 void Merge7zFormatMergePluginImpl::SetPackingInfo(const PackingInfo* infoUnpacker)
76 {
77         GetInstance()->m_infoUnpacker = infoUnpacker ? *infoUnpacker : PackingInfo();
78 }
79
80 PackingInfo *Merge7zFormatMergePluginImpl::GetPackingInfo()
81 {
82         return &GetInstance()->m_infoUnpacker;
83 }