OSDN Git Service

Cleanup PLUGIN_MODE usage
authorGreyMerlin <greymerlin7@gmail.com>
Thu, 25 Oct 2018 00:46:30 +0000 (17:46 -0700)
committerGreyMerlin <greymerlin7@gmail.com>
Thu, 25 Oct 2018 00:46:30 +0000 (17:46 -0700)
While modernizing more NULL and BOOL situations, I encountered the following two comments in the
code ...
`// TODO: Convert to PLUGIN_MODE and fix compile error` and
`// TODO: Convert bMode to PLUGIN_MODE and fix compile errors`

* Values of type `PLUGIN_MODE` were being stored into `int` variables, often with a `b` prefix
(implying the variables were boolean in nature).
* And values themselves were sometimes `false`, or `1` although sometimes from the `PLUGIN_MODE`
enumeration.
* Value testing often assumed the values were boolean (i.e. zero or non-zero)

* I've changed all appropriate variables to type `PLUGIN_MODE` and used explicit values from the
enumeration in all related expressions.
* I've also taken the opportunity to modernize all member variables in the `PluginForFile` and
`PackingInfo` classes, by adding an explicit `m_` prefix

--HG--
branch : stable

17 files changed:
Src/DiffTextBuffer.cpp
Src/DiffWrapper.cpp
Src/DirActions.h
Src/FileTransform.cpp
Src/FileTransform.h
Src/FolderCmp.cpp
Src/MainFrm.cpp
Src/Merge.cpp
Src/Merge7zFormatMergePluginImpl.cpp
Src/MergeDoc.cpp
Src/MergeEditView.cpp
Src/OpenView.cpp
Src/PluginManager.cpp
Src/PluginManager.h
Src/SelectUnpackerDlg.cpp
Testing/Data/Office/excel.xls
Testing/GoogleTest/Plugins/Plugins_test.cpp

index 8d6ec48..e52ef51 100644 (file)
@@ -302,10 +302,10 @@ int CDiffTextBuffer::LoadFromFile(LPCTSTR pszFileNameInit,
                InitNew(); // leave crystal editor in valid, empty state
                return FileLoadResult::FRESULT_ERROR_UNPACK;
        }
-       m_unpackerSubcode = infoUnpacker->subcode;
+       m_unpackerSubcode = infoUnpacker->m_subcode;
 
        // we use the same unpacker for both files, so it must be defined after first file
-       ASSERT(infoUnpacker->bToBeScanned != PLUGIN_AUTO);
+       ASSERT(infoUnpacker->m_PluginOrPredifferMode != PLUGIN_AUTO);
        // we will load the transformed file
        LPCTSTR pszFileName = sFileName.c_str();
 
@@ -319,8 +319,8 @@ int CDiffTextBuffer::LoadFromFile(LPCTSTR pszFileNameInit,
        if (def && def->encoding != -1)
                m_nSourceEncoding = def->encoding;
        
-       UniFile *pufile = infoUnpacker->pufile;
-       if (pufile == 0)
+       UniFile *pufile = infoUnpacker->m_pufile;
+       if (pufile == nullptr)
                pufile = new UniMemFile;
 
        // Now we only use the UniFile interface
@@ -338,7 +338,7 @@ int CDiffTextBuffer::LoadFromFile(LPCTSTR pszFileNameInit,
        }
        else
        {
-               if (infoUnpacker->pluginName.length() > 0)
+               if (infoUnpacker->m_PluginName.length() > 0)
                {
                        // re-detect codepage
                        int iGuessEncodingType = GetOptionsMgr()->GetInt(OPT_CP_DETECT);
@@ -496,7 +496,7 @@ int CDiffTextBuffer::SaveToFile (const String& pszFileName,
 
        if (nCrlfStyle == CRLF_STYLE_AUTOMATIC &&
                !GetOptionsMgr()->GetBool(OPT_ALLOW_MIXED_EOL) ||
-               infoUnpacker && infoUnpacker->disallowMixedEOL)
+               infoUnpacker!=nullptr && infoUnpacker->m_bDisallowMixedEOL)
        {
                        // get the default nCrlfStyle of the CDiffTextBuffer
                nCrlfStyle = GetCRLFMode();
@@ -609,7 +609,7 @@ int CDiffTextBuffer::SaveToFile (const String& pszFileName,
                ASSERT(infoUnpacker != nullptr);
                // repack the file here, overwrite the temporary file we did save in
                String csTempFileName = sIntermediateFilename;
-               infoUnpacker->subcode = m_unpackerSubcode;
+               infoUnpacker->m_subcode = m_unpackerSubcode;
                if (!FileTransform::Packing(csTempFileName, *infoUnpacker))
                {
                        try
index 5575d87..a255cd3 100644 (file)
@@ -718,16 +718,16 @@ bool CDiffWrapper::RunFileDiff()
                                String sError = strutils::format(
                                        _T("An error occurred while prediffing the file '%s' with the plugin '%s'. The prediffing is not applied any more."),
                                        strFileTemp[file].c_str(),
-                                       m_infoPrediffer->pluginName.c_str());
+                                       m_infoPrediffer->m_PluginName.c_str());
                                AppErrorMessageBox(sError);
                                // don't use any more this prediffer
-                               m_infoPrediffer->bToBeScanned = false;
-                               m_infoPrediffer->pluginName.erase();
+                               m_infoPrediffer->m_PluginOrPredifferMode = PLUGIN_MANUAL;
+                               m_infoPrediffer->m_PluginName.erase();
                        }
 
                        // We use the same plugin for both files, so it must be defined before
                        // second file
-                       assert(!m_infoPrediffer->bToBeScanned);
+                       assert(m_infoPrediffer->m_PluginOrPredifferMode == PLUGIN_MANUAL);
                }
        }
 
index 5d81f3b..70d0778 100644 (file)
@@ -6,6 +6,7 @@
 #include "paths.h"
 #include "IntToIntMap.h"
 #include <algorithm>
+#include "FileTransform.h"
 
 struct DIFFITEM;
 class CDiffContext;
@@ -651,7 +652,7 @@ void ApplyFolderNameAndFileName(const InputIterator& begin, const InputIterator&
  * @brief Apply specified setting for prediffing to all selected items
  */
 template<class InputIterator>
-void ApplyPluginPrediffSetting(const InputIterator& begin, const InputIterator& end, const CDiffContext& ctxt, int newsetting)
+void ApplyPluginPrediffSetting(const InputIterator& begin, const InputIterator& end, const CDiffContext& ctxt, PLUGIN_MODE newsetting)
 {
        // Unlike other group actions, here we don't build an action list
        // to execute; we just apply this change directly
@@ -705,7 +706,7 @@ std::pair<int, int> CountPredifferYesNo(const InputIterator& begin, const InputI
                        PackingInfo * unpacker;
                        PrediffingInfo * prediffer;
                        const_cast<CDiffContext&>(ctxt).FetchPluginInfos(filteredFilenames, &unpacker, &prediffer);
-                       if (prediffer->bToBeScanned == 1 || !prediffer->pluginName.empty())
+                       if (prediffer->m_PluginOrPredifferMode == PLUGIN_AUTO || !prediffer->m_PluginName.empty())
                                nPredifferYes ++;
                        else
                                nPredifferNo ++;
index b1ea3ef..8c6749a 100644 (file)
@@ -38,8 +38,8 @@ using Poco::Exception;
 namespace FileTransform
 {
 
-int g_bUnpackerMode = PLUGIN_MANUAL;
-int g_bPredifferMode = PLUGIN_MANUAL;
+PLUGIN_MODE g_UnpackerMode = PLUGIN_MANUAL;
+PLUGIN_MODE g_PredifferMode = PLUGIN_MANUAL;
 
 
 
@@ -52,7 +52,7 @@ int g_bPredifferMode = PLUGIN_MANUAL;
 bool Packing(String & filepath, PackingInfo handler)
 {
        // no handler : return true
-       if (handler.pluginName.empty())
+       if (handler.m_PluginName.empty())
                return true;
 
        storageForPlugins bufferData;
@@ -61,13 +61,13 @@ bool Packing(String & filepath, PackingInfo handler)
        // control value
        bool bHandled = false;
 
-       PluginInfo * plugin = CAllThreadsScripts::GetActiveSet()->GetPluginByName(L"FILE_PACK_UNPACK", handler.pluginName);
+       PluginInfo * plugin = CAllThreadsScripts::GetActiveSet()->GetPluginByName(L"FILE_PACK_UNPACK", handler.m_PluginName);
        if (plugin == nullptr)
-               plugin = CAllThreadsScripts::GetActiveSet()->GetPluginByName(L"FILE_FOLDER_PACK_UNPACK", handler.pluginName);
+               plugin = CAllThreadsScripts::GetActiveSet()->GetPluginByName(L"FILE_FOLDER_PACK_UNPACK", handler.m_PluginName);
        if (plugin == nullptr)
-               plugin = CAllThreadsScripts::GetActiveSet()->GetPluginByName(L"BUFFER_PACK_UNPACK", handler.pluginName);
+               plugin = CAllThreadsScripts::GetActiveSet()->GetPluginByName(L"BUFFER_PACK_UNPACK", handler.m_PluginName);
        LPDISPATCH piScript = plugin->m_lpDispatch;
-       if (handler.bWithFile)
+       if (handler.m_bWithFile)
        {
                // use a temporary dest name
                String srcFileName = bufferData.GetDataFileAnsi(); // <-Call order is important
@@ -75,7 +75,7 @@ bool Packing(String & filepath, PackingInfo handler)
                bHandled = plugin::InvokePackFile(srcFileName,
                        dstFileName,
                        bufferData.GetNChanged(),
-                       piScript, handler.subcode);
+                       piScript, handler.m_subcode);
                if (bHandled)
                        bufferData.ValidateNewFile();
        }
@@ -83,7 +83,7 @@ bool Packing(String & filepath, PackingInfo handler)
        {
                bHandled = plugin::InvokePackBuffer(*bufferData.GetDataBufferAnsi(),
                        bufferData.GetNChanged(),
-                       piScript, handler.subcode);
+                       piScript, handler.m_subcode);
                if (bHandled)
                        bufferData.ValidateNewBuffer();
        }
@@ -106,7 +106,7 @@ bool Packing(String & filepath, PackingInfo handler)
 bool Unpacking(String & filepath, const PackingInfo * handler, int * handlerSubcode)
 {
        // no handler : return true
-       if (handler == nullptr || handler->pluginName.empty())
+       if (handler == nullptr || handler->m_PluginName.empty())
                return true;
 
        storageForPlugins bufferData;
@@ -118,16 +118,16 @@ bool Unpacking(String & filepath, const PackingInfo * handler, int * handlerSubc
        // control value
        bool bHandled = false;
 
-       PluginInfo * plugin = CAllThreadsScripts::GetActiveSet()->GetPluginByName(L"FILE_PACK_UNPACK", handler->pluginName);
+       PluginInfo * plugin = CAllThreadsScripts::GetActiveSet()->GetPluginByName(L"FILE_PACK_UNPACK", handler->m_PluginName);
        if (plugin == nullptr)
-               plugin = CAllThreadsScripts::GetActiveSet()->GetPluginByName(L"FILE_FOLDER_PACK_UNPACK", handler->pluginName);
+               plugin = CAllThreadsScripts::GetActiveSet()->GetPluginByName(L"FILE_FOLDER_PACK_UNPACK", handler->m_PluginName);
        if (plugin == nullptr)
-               plugin = CAllThreadsScripts::GetActiveSet()->GetPluginByName(L"BUFFER_PACK_UNPACK", handler->pluginName);
+               plugin = CAllThreadsScripts::GetActiveSet()->GetPluginByName(L"BUFFER_PACK_UNPACK", handler->m_PluginName);
        if (plugin == nullptr)
                return false;
 
        LPDISPATCH piScript = plugin->m_lpDispatch;
-       if (handler->bWithFile)
+       if (handler->m_bWithFile)
        {
                // use a temporary dest name
                String srcFileName = bufferData.GetDataFileAnsi(); // <-Call order is important
@@ -170,13 +170,13 @@ bool Unpacking(String & filepath, const PackingInfo * handler, int * handlerSubc
 bool Unpacking(String & filepath, const String& filteredText, PackingInfo * handler, int * handlerSubcode)
 {
        // PLUGIN_BUILTIN_XML : read source file through custom UniFile
-       if (handler->bToBeScanned == PLUGIN_BUILTIN_XML)
+       if (handler->m_PluginOrPredifferMode == PLUGIN_BUILTIN_XML)
        {
-               handler->pufile = new UniMarkdownFile;
-               handler->textType = _T("xml");
-               handler->disallowMixedEOL = true;
-               handler->pluginName.erase(); // Make FileTransform_Packing() a NOP
-               // Leave bToBeScanned alone so above lines will continue to execute on
+               handler->m_pufile = new UniMarkdownFile;
+               handler->m_textType = _T("xml");
+               handler->m_bDisallowMixedEOL = true;
+               handler->m_PluginName.erase(); // Make FileTransform_Packing() a NOP
+               // Leave eToBeScanned alone so above lines will continue to execute on
                // subsequent calls to this function
                return true;
        }
@@ -192,15 +192,15 @@ bool Unpacking(String & filepath, const String& filteredText, PackingInfo * hand
                plugin = CAllThreadsScripts::GetActiveSet()->GetAutomaticPluginByFilter(L"FILE_FOLDER_PACK_UNPACK", filteredText);
        if (plugin != nullptr)
        {
-               handler->pluginName = plugin->m_name;
-               handler->bWithFile = true;
+               handler->m_PluginName = plugin->m_name;
+               handler->m_bWithFile = true;
                // use a temporary dest name
                String srcFileName = bufferData.GetDataFileAnsi(); // <-Call order is important
                String dstFileName = bufferData.GetDestFileName(); // <-Call order is important
                bHandled = plugin::InvokeUnpackFile(srcFileName,
                        dstFileName,
                        bufferData.GetNChanged(),
-                       plugin->m_lpDispatch, handler->subcode);
+                       plugin->m_lpDispatch, handler->m_subcode);
                if (bHandled)
                        bufferData.ValidateNewFile();
        }
@@ -213,11 +213,11 @@ bool Unpacking(String & filepath, const String& filteredText, PackingInfo * hand
                plugin = CAllThreadsScripts::GetActiveSet()->GetAutomaticPluginByFilter(L"BUFFER_PACK_UNPACK", filteredText);
                if (plugin != nullptr)
                {
-                       handler->pluginName = plugin->m_name;
-                       handler->bWithFile = false;
+                       handler->m_PluginName = plugin->m_name;
+                       handler->m_bWithFile = false;
                        bHandled = plugin::InvokeUnpackBuffer(*bufferData.GetDataBufferAnsi(),
                                bufferData.GetNChanged(),
-                               plugin->m_lpDispatch, handler->subcode);
+                               plugin->m_lpDispatch, handler->m_subcode);
                        if (bHandled)
                                bufferData.ValidateNewBuffer();
                }
@@ -226,16 +226,16 @@ bool Unpacking(String & filepath, const String& filteredText, PackingInfo * hand
        if (!bHandled)
        {
                // we didn't find any unpacker, just hope it is normal Ansi/Unicode
-               handler->pluginName = _T("");
-               handler->subcode = 0;
+               handler->m_PluginName = _T("");
+               handler->m_subcode = 0;
                bHandled = true;
        }
 
        // the handler is now defined
-       handler->bToBeScanned = false;
+       handler->m_PluginOrPredifferMode = PLUGIN_MANUAL;
 
        // assign the sucode
-       *handlerSubcode = handler->subcode;
+       *handlerSubcode = handler->m_subcode;
 
        // if the buffer changed, write it before leaving
        bool bSuccess = true;
@@ -249,10 +249,10 @@ bool Unpacking(String & filepath, const String& filteredText, PackingInfo * hand
 
 bool Unpacking(PackingInfo *handler, String& filepath, const String& filteredText)
 {
-       if (handler->bToBeScanned)
-               return Unpacking(filepath, filteredText, handler, &handler->subcode);
+       if (handler->m_PluginOrPredifferMode != PLUGIN_MANUAL)
+               return Unpacking(filepath, filteredText, handler, &handler->m_subcode);
        else
-               return Unpacking(filepath, handler, &handler->subcode);
+               return Unpacking(filepath, handler, &handler->m_subcode);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -262,7 +262,7 @@ bool Unpacking(PackingInfo *handler, String& filepath, const String& filteredTex
 bool Prediffing(String & filepath, PrediffingInfo handler, bool bMayOverwrite)
 {
        // no handler : return true
-       if (handler.pluginName.empty())
+       if (handler.m_PluginName.empty())
                return true;
 
        storageForPlugins bufferData;
@@ -274,15 +274,15 @@ bool Prediffing(String & filepath, PrediffingInfo handler, bool bMayOverwrite)
        // control value
        bool bHandled = false;
 
-       PluginInfo * plugin = CAllThreadsScripts::GetActiveSet()->GetPluginByName(L"FILE_PREDIFF", handler.pluginName);
+       PluginInfo * plugin = CAllThreadsScripts::GetActiveSet()->GetPluginByName(L"FILE_PREDIFF", handler.m_PluginName);
        if (plugin == nullptr)
        {
-               plugin = CAllThreadsScripts::GetActiveSet()->GetPluginByName(L"BUFFER_PREDIFF", handler.pluginName);
+               plugin = CAllThreadsScripts::GetActiveSet()->GetPluginByName(L"BUFFER_PREDIFF", handler.m_PluginName);
                if (plugin == nullptr)
                        return false;
        }
        LPDISPATCH piScript = plugin->m_lpDispatch;
-       if (handler.bWithFile)
+       if (handler.m_bWithFile)
        {
                // use a temporary dest name
                String srcFileName = bufferData.GetDataFileAnsi(); // <-Call order is important
@@ -335,8 +335,8 @@ bool Prediffing(String & filepath, const String& filteredText, PrediffingInfo *
        PluginInfo * plugin = CAllThreadsScripts::GetActiveSet()->GetAutomaticPluginByFilter(L"FILE_PREDIFF", filteredText);
        if (plugin != nullptr)
        {
-               handler->pluginName = plugin->m_name;
-               handler->bWithFile = true;
+               handler->m_PluginName = plugin->m_name;
+               handler->m_bWithFile = true;
                // use a temporary dest name
                String srcFileName = bufferData.GetDataFileAnsi(); // <-Call order is important
                String dstFileName = bufferData.GetDestFileName(); // <-Call order is important
@@ -353,8 +353,8 @@ bool Prediffing(String & filepath, const String& filteredText, PrediffingInfo *
                plugin = CAllThreadsScripts::GetActiveSet()->GetAutomaticPluginByFilter(L"BUFFER_PREDIFF", filteredText);
                if (plugin != nullptr)
                {
-                       handler->pluginName = plugin->m_name;
-                       handler->bWithFile = false;
+                       handler->m_PluginName = plugin->m_name;
+                       handler->m_bWithFile = false;
                        // probably it is for VB/VBscript so use a BSTR as argument
                        bHandled = plugin::InvokePrediffBuffer(*bufferData.GetDataBufferUnicode(),
                                bufferData.GetNChanged(),
@@ -367,12 +367,12 @@ bool Prediffing(String & filepath, const String& filteredText, PrediffingInfo *
        if (!bHandled)
        {
                // we didn't find any prediffer, that is OK anyway
-               handler->pluginName = _T("");
+               handler->m_PluginName = _T("");
                bHandled = true;
        }
 
        // the handler is now defined
-       handler->bToBeScanned = false;
+       handler->m_PluginOrPredifferMode = PLUGIN_MANUAL;
 
        // if the buffer changed, write it before leaving
        bool bSuccess = true;
@@ -386,7 +386,7 @@ bool Prediffing(String & filepath, const String& filteredText, PrediffingInfo *
 
 bool Prediffing(PrediffingInfo * handler, String & filepath, const String& filteredText, bool bMayOverwrite)
 {
-       if (handler->bToBeScanned)
+       if (handler->m_PluginOrPredifferMode != PLUGIN_MANUAL)
                return Prediffing(filepath, filteredText, handler, bMayOverwrite);
        else
                return Prediffing(filepath, *handler, bMayOverwrite);
index 9421cc9..1c076e0 100644 (file)
 #include "UnicodeString.h"
 #include "MergeApp.h"
 
-namespace FileTransform
-{
-extern int g_bUnpackerMode;
-extern int g_bPredifferMode;
-}
-
-class UniFile;
-
 /**
  * @brief Modes for plugin (Modes for prediffing included)
  */
 enum PLUGIN_MODE
 {
-       // Modes for unpacking
+       // Modes for "unpacking"
        PLUGIN_MANUAL,
        PLUGIN_AUTO,
        PLUGIN_BUILTIN_XML,
-       // Modes for prediffing
+
+       // Modes for "prediffing"
        PREDIFF_MANUAL = PLUGIN_MANUAL,
        PREDIFF_AUTO = PLUGIN_AUTO,
 };
 
+namespace FileTransform
+{
+extern PLUGIN_MODE g_UnpackerMode;
+extern PLUGIN_MODE g_PredifferMode;
+}
+
+class UniFile;
+
 /**
  * @brief Plugin information for a given file
  *
@@ -59,34 +60,34 @@ enum PLUGIN_MODE
 class PluginForFile
 {
 public:
-       void Initialize(int bMode)
+       void Initialize(PLUGIN_MODE Mode)
        {
-               // TODO: Convert bMode to PLUGIN_MODE and fix compile errors
-               // init functions as a valid "do nothing" unpacker
-               bWithFile = false;
-               // and init bAutomatic flag and name according to global variable
-               if (bMode != PLUGIN_AUTO)
+               // initialize functions with a valid "do nothing" unpacker
+               m_bWithFile = false;
+               // and init Plugin/Prediffer mode and Plugin name accordingly
+               m_PluginOrPredifferMode = Mode;
+               if (Mode != PLUGIN_AUTO)
                {
-                       pluginName.erase();
+                       m_PluginName.erase();
                }
                else
                {
-                       pluginName = _("<Automatic>");
+                       m_PluginName = _("<Automatic>");
                }
-               bToBeScanned = bMode;
        };
-       explicit PluginForFile(PLUGIN_MODE bMode) 
+       explicit PluginForFile(PLUGIN_MODE Mode) 
        {
-               Initialize(bMode);
+               Initialize(Mode);
        };
 public:
-       /// TRUE if the plugin will be defined during the first use (through scan of all available plugins)
-       int bToBeScanned; // TODO: Convert to PLUGIN_MODE and fix compile errors
+       /// PLUGIN_AUTO if the plugin will be defined during the first use (via scan of all available plugins)
+       PLUGIN_MODE     m_PluginOrPredifferMode;
+
        /// plugin name when it is defined
-       String pluginName;
+       String          m_PluginName;
 
        /// `true` if the plugins exchange data through a file, `false` is the data is passed as parameter (BSTR/ARRAY)
-       bool    bWithFile;
+       bool            m_bWithFile;
 };
 
 /**
@@ -99,21 +100,21 @@ public:
 class PackingInfo : public PluginForFile
 {
 public:
-       explicit PackingInfo(PLUGIN_MODE bMode = (PLUGIN_MODE)FileTransform::g_bUnpackerMode)
-       : PluginForFile(bMode)
-       , subcode(0)
-       , pufile(nullptr)
-       , disallowMixedEOL(false)
+       explicit PackingInfo(PLUGIN_MODE Mode = FileTransform::g_UnpackerMode)
+       : PluginForFile(Mode)
+       , m_subcode(0)
+       , m_pufile(nullptr)
+       , m_bDisallowMixedEOL(false)
        {
        }
 public:
        /// keep some info from unpacking for packing
-       int subcode;
+       int                     m_subcode;
        /// text type to override syntax highlighting
-       String textType;
+       String          m_textType;
        /// custom UniFile
-       UniFile *pufile;
-       bool disallowMixedEOL;
+       UniFile*        m_pufile;
+       bool            m_bDisallowMixedEOL;
 };
 
 /**
@@ -124,8 +125,8 @@ public:
 class PrediffingInfo : public PluginForFile
 {
 public:
-       explicit PrediffingInfo(PLUGIN_MODE bMode = (PLUGIN_MODE)FileTransform::g_bPredifferMode)
-       : PluginForFile(bMode)
+       explicit PrediffingInfo(PLUGIN_MODE Mode = FileTransform::g_PredifferMode)
+       : PluginForFile(Mode)
        {
        }
 };
index 269ac8d..eea253e 100644 (file)
@@ -117,7 +117,7 @@ int FolderCmp::prepAndCompareFiles(CDiffContext * pCtxt, DIFFITEM &di)
                                        goto exitPrepAndCompare;
 
                                // we use the same plugins for both files, so they must be defined before second file
-                               assert(!infoUnpacker->bToBeScanned);
+                               assert(!infoUnpacker->m_PluginOrPredifferMode != PLUGIN_MANUAL);
                        }
 
                        // As we keep handles open on unpacked files, Transform() may not delete them.
index 175b5fb..1fb05a6 100644 (file)
@@ -889,8 +889,8 @@ bool CMainFrame::DoFileOpen(const PathContext * pFiles /*= nullptr*/,
        if (pDirDoc && !pDirDoc->CloseMergeDocs())
                return false;
 
-       FileTransform::g_eUnpackerMode = static_cast<PLUGIN_MODE>(theApp.GetProfileInt(_T("Settings"), _T("UnpackerMode"), PLUGIN_MANUAL));
-       FileTransform::g_ePredifferMode = static_cast<PLUGIN_MODE>(theApp.GetProfileInt(_T("Settings"), _T("PredifferMode"), PLUGIN_MANUAL));
+       FileTransform::g_UnpackerMode = static_cast<PLUGIN_MODE>(theApp.GetProfileInt(_T("Settings"), _T("UnpackerMode"), PLUGIN_MANUAL));
+       FileTransform::g_PredifferMode = static_cast<PLUGIN_MODE>(theApp.GetProfileInt(_T("Settings"), _T("PredifferMode"), PLUGIN_MANUAL));
 
        Merge7zFormatMergePluginScope scope(infoUnpacker);
 
@@ -1372,13 +1372,13 @@ void CMainFrame::OnPluginUnpackMode(UINT nID )
        switch (nID)
        {
        case ID_UNPACK_MANUAL:
-               FileTransform::g_bUnpackerMode = PLUGIN_MANUAL;
+               FileTransform::g_UnpackerMode = PLUGIN_MANUAL;
                break;
        case ID_UNPACK_AUTO:
-               FileTransform::g_bUnpackerMode = PLUGIN_AUTO;
+               FileTransform::g_UnpackerMode = PLUGIN_AUTO;
                break;
        }
-       theApp.WriteProfileInt(_T("Settings"), _T("UnpackerMode"), FileTransform::g_bUnpackerMode);
+       theApp.WriteProfileInt(_T("Settings"), _T("UnpackerMode"), FileTransform::g_UnpackerMode);
 }
 
 void CMainFrame::OnUpdatePluginUnpackMode(CCmdUI* pCmdUI) 
@@ -1386,27 +1386,27 @@ void CMainFrame::OnUpdatePluginUnpackMode(CCmdUI* pCmdUI)
        pCmdUI->Enable(GetOptionsMgr()->GetBool(OPT_PLUGINS_ENABLED));
 
        if (pCmdUI->m_nID == ID_UNPACK_MANUAL)
-               pCmdUI->SetRadio(PLUGIN_MANUAL == FileTransform::g_bUnpackerMode);
+               pCmdUI->SetRadio(PLUGIN_MANUAL == FileTransform::g_UnpackerMode);
        if (pCmdUI->m_nID == ID_UNPACK_AUTO)
-               pCmdUI->SetRadio(PLUGIN_AUTO == FileTransform::g_bUnpackerMode);
+               pCmdUI->SetRadio(PLUGIN_AUTO == FileTransform::g_UnpackerMode);
 }
 void CMainFrame::OnPluginPrediffMode(UINT nID )
 {
        switch (nID)
        {
        case ID_PREDIFFER_MANUAL:
-               FileTransform::g_bPredifferMode = PLUGIN_MANUAL;
+               FileTransform::g_PredifferMode = PLUGIN_MANUAL;
                break;
        case ID_PREDIFFER_AUTO:
-               FileTransform::g_bPredifferMode = PLUGIN_AUTO;
+               FileTransform::g_PredifferMode = PLUGIN_AUTO;
                break;
        }
        PrediffingInfo infoPrediffer;
        for (auto pMergeDoc : GetAllMergeDocs())
                pMergeDoc->SetPrediffer(&infoPrediffer);
        for (auto pDirDoc : GetAllDirDocs())
-               pDirDoc->GetPluginManager().SetPrediffSettingAll(FileTransform::g_bPredifferMode);
-       theApp.WriteProfileInt(_T("Settings"), _T("PredifferMode"), FileTransform::g_bPredifferMode);
+               pDirDoc->GetPluginManager().SetPrediffSettingAll(FileTransform::g_PredifferMode);
+       theApp.WriteProfileInt(_T("Settings"), _T("PredifferMode"), FileTransform::g_PredifferMode);
 }
 
 void CMainFrame::OnUpdatePluginPrediffMode(CCmdUI* pCmdUI) 
@@ -1414,9 +1414,9 @@ void CMainFrame::OnUpdatePluginPrediffMode(CCmdUI* pCmdUI)
        pCmdUI->Enable(GetOptionsMgr()->GetBool(OPT_PLUGINS_ENABLED));
 
        if (pCmdUI->m_nID == ID_PREDIFFER_MANUAL)
-               pCmdUI->SetRadio(PLUGIN_MANUAL == FileTransform::g_bPredifferMode);
+               pCmdUI->SetRadio(PLUGIN_MANUAL == FileTransform::g_PredifferMode);
        if (pCmdUI->m_nID == ID_PREDIFFER_AUTO)
-               pCmdUI->SetRadio(PLUGIN_AUTO == FileTransform::g_bPredifferMode);
+               pCmdUI->SetRadio(PLUGIN_AUTO == FileTransform::g_PredifferMode);
 }
 /**
  * @brief Called when "Reload Plugins" item is updated
index e55be22..13bb226 100644 (file)
@@ -282,8 +282,8 @@ BOOL CMergeApp::InitInstance()
        charsets_init();
        UpdateCodepageModule();
 
-       FileTransform::g_bUnpackerMode = theApp.GetProfileInt(_T("Settings"), _T("UnpackerMode"), PLUGIN_MANUAL);
-       FileTransform::g_bPredifferMode = theApp.GetProfileInt(_T("Settings"), _T("PredifferMode"), PLUGIN_MANUAL);
+       FileTransform::g_UnpackerMode = static_cast<PLUGIN_MODE>(theApp.GetProfileInt(_T("Settings"), _T("UnpackerMode"), PLUGIN_MANUAL));
+       FileTransform::g_PredifferMode = static_cast<PLUGIN_MODE>(theApp.GetProfileInt(_T("Settings"), _T("PredifferMode"), PLUGIN_MANUAL));
 
        NONCLIENTMETRICS ncm = { sizeof NONCLIENTMETRICS };
        if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof NONCLIENTMETRICS, &ncm, 0))
index c5718e7..18af35c 100644 (file)
@@ -30,10 +30,10 @@ Merge7z::Format *Merge7zFormatMergePluginImpl::GuessFormat(const String& path)
 {
        Merge7zFormatMergePluginImpl *format = GetInstance();
        PluginInfo *plugin = NULL;
-       if (format->m_infoUnpacker.bToBeScanned)
+       if (format->m_infoUnpacker.m_PluginOrPredifferMode != PLUGIN_MANUAL)
                plugin = CAllThreadsScripts::GetActiveSet()->GetAutomaticPluginByFilter(L"FILE_FOLDER_PACK_UNPACK", path);
-       else if (!format->m_infoUnpacker.pluginName.empty())
-               plugin = CAllThreadsScripts::GetActiveSet()->GetPluginByName(L"FILE_FOLDER_PACK_UNPACK", format->m_infoUnpacker.pluginName);
+       else if (!format->m_infoUnpacker.m_PluginName.empty())
+               plugin = CAllThreadsScripts::GetActiveSet()->GetPluginByName(L"FILE_FOLDER_PACK_UNPACK", format->m_infoUnpacker.m_PluginName);
        if (!plugin)
                return NULL;
        if (!plugin::InvokeIsFolder(path, plugin->m_lpDispatch))
@@ -48,7 +48,7 @@ HRESULT Merge7zFormatMergePluginImpl::DeCompressArchive(HWND, LPCTSTR path, LPCT
                return E_FAIL;
        paths::CreateIfNeeded(path);
        int nChanged = 0;
-       return plugin::InvokeUnpackFolder(path, folder, nChanged, m_plugin->m_lpDispatch, m_infoUnpacker.subcode) ? S_OK : E_FAIL;
+       return plugin::InvokeUnpackFolder(path, folder, nChanged, m_plugin->m_lpDispatch, m_infoUnpacker.m_subcode) ? S_OK : E_FAIL;
 }
 
 HRESULT Merge7zFormatMergePluginImpl::CompressArchive(HWND, LPCTSTR path, Merge7z::DirItemEnumerator *)
index 580f511..7baab6e 100644 (file)
@@ -519,7 +519,7 @@ int CMergeDoc::Rescan(bool &bBinary, IDENTLEVEL &identical,
                // Apply flags to lines that are trivial
                PrediffingInfo infoPrediffer;
                GetPrediffer(&infoPrediffer);
-               if (!infoPrediffer.pluginName.empty())
+               if (!infoPrediffer.m_PluginName.empty())
                        FlagTrivialLines();
                
                // Apply flags to lines that moved, to differentiate from appeared/disappeared lines
@@ -1375,13 +1375,13 @@ bool CMergeDoc::TrySaveAs(String &strPath, int &nSaveResult, String & sError,
                                        : (nBuffer == 1 ? 
                                        _("Plugin '%2' cannot pack your changes to the middle file back into '%1'.\n\nThe original file will not be changed.\n\nDo you want to save the unpacked version to another file?"): 
                                        _("Plugin '%2' cannot pack your changes to the right file back into '%1'.\n\nThe original file will not be changed.\n\nDo you want to save the unpacked version to another file?")),
-                               strPath, pInfoTempUnpacker->pluginName);
+                               strPath, pInfoTempUnpacker->m_PluginName);
                }
                else
                {
                        str = strutils::format_string2(nBuffer == 0 ? _("Plugin '%2' cannot pack your changes to the left file back into '%1'.\n\nThe original file will not be changed.\n\nDo you want to save the unpacked version to another file?") : 
                                _("Plugin '%2' cannot pack your changes to the right file back into '%1'.\n\nThe original file will not be changed.\n\nDo you want to save the unpacked version to another file?"),
-                               strPath, pInfoTempUnpacker->pluginName);
+                               strPath, pInfoTempUnpacker->m_PluginName);
                }
                // replace the unpacker with a "do nothing" unpacker
                pInfoTempUnpacker->Initialize(PLUGIN_MANUAL);
@@ -1949,12 +1949,12 @@ void CMergeDoc::OnUpdateStatusNum(CCmdUI* pCmdUI)
 void CMergeDoc::OnUpdatePluginName(CCmdUI* pCmdUI)
 {
        String pluginNames;
-       if (m_pInfoUnpacker && !m_pInfoUnpacker->pluginName.empty())
-               pluginNames += m_pInfoUnpacker->pluginName + _T("&");
+       if (m_pInfoUnpacker && !m_pInfoUnpacker->m_PluginName.empty())
+               pluginNames += m_pInfoUnpacker->m_PluginName + _T("&");
        PrediffingInfo prediffer;
        GetPrediffer(&prediffer);
-       if (!prediffer.pluginName.empty())
-               pluginNames += prediffer.pluginName + _T("&");
+       if (!prediffer.m_PluginName.empty())
+               pluginNames += prediffer.m_PluginName + _T("&");
        pCmdUI->SetText(pluginNames.substr(0, pluginNames.length() - 1).c_str());
 }
 
@@ -2760,8 +2760,8 @@ bool CMergeDoc::OpenDocs(int nFiles, const FileLocation ifileloc[],
 
                for (nBuffer = 0; nBuffer < m_nBuffers; nBuffer++)
                {
-                       if (bFiltersEnabled && m_pInfoUnpacker->textType.length())
-                               sext[nBuffer] = m_pInfoUnpacker->textType;
+                       if (bFiltersEnabled && m_pInfoUnpacker->m_textType.length())
+                               sext[nBuffer] = m_pInfoUnpacker->m_textType;
                        else
                                sext[nBuffer] = GetFileExt(fileloc[nBuffer].filepath.c_str(), m_strDesc[nBuffer].c_str());
                        ForEachView(nBuffer, [&](auto& pView) {
index a2b5ae8..aeb3748 100644 (file)
@@ -2715,9 +2715,9 @@ HMENU CMergeEditView::createPrediffersSubmenu(HMENU hMenu)
        PrediffingInfo prediffer;
        pd->GetPrediffer(&prediffer);
 
-       if (prediffer.bToBeScanned)
+       if (prediffer.m_PluginOrPredifferMode != PLUGIN_MANUAL)
                m_CurrentPredifferID = 0;
-       else if (prediffer.pluginName.empty())
+       else if (prediffer.m_PluginName.empty())
                m_CurrentPredifferID = ID_NO_PREDIFFER;
        else
        {
@@ -2725,14 +2725,14 @@ HMENU CMergeEditView::createPrediffersSubmenu(HMENU hMenu)
                for (iScript = 0 ; iScript < piScriptArray->size() ; iScript++, ID ++)
                {
                        const PluginInfoPtr & plugin = piScriptArray->at(iScript);
-                       if (prediffer.pluginName == plugin->m_name)
+                       if (prediffer.m_PluginName == plugin->m_name)
                                m_CurrentPredifferID = ID;
 
                }
                for (iScript = 0 ; iScript < piScriptArray2->size() ; iScript++, ID ++)
                {
                        const PluginInfoPtr & plugin = piScriptArray2->at(iScript);
-                       if (prediffer.pluginName == plugin->m_name)
+                       if (prediffer.m_PluginName == plugin->m_name)
                                m_CurrentPredifferID = ID;
                }
        }
@@ -3059,14 +3059,14 @@ void CMergeEditView::OnUpdatePrediffer(CCmdUI* pCmdUI)
        PrediffingInfo prediffer;
        pd->GetPrediffer(&prediffer);
 
-       if (prediffer.bToBeScanned)
+       if (prediffer.m_PluginOrPredifferMode != PLUGIN_MANUAL)
        {
                pCmdUI->SetRadio(false);
                return;
        }
 
        // Detect when CDiffWrapper::RunFileDiff has canceled a buggy prediffer
-       if (prediffer.pluginName.empty())
+       if (prediffer.m_PluginName.empty())
                m_CurrentPredifferID = ID_NO_PREDIFFER;
 
        pCmdUI->SetRadio(pCmdUI->m_nID == static_cast<UINT>(m_CurrentPredifferID));
@@ -3113,8 +3113,8 @@ void CMergeEditView::SetPredifferByMenu(UINT nID )
                m_CurrentPredifferID = nID;
                // All flags are set correctly during the construction
                PrediffingInfo *infoPrediffer = new PrediffingInfo;
-               infoPrediffer->bToBeScanned = 0;
-               infoPrediffer->pluginName.clear();
+               infoPrediffer->m_PluginOrPredifferMode = PLUGIN_MANUAL;
+               infoPrediffer->m_PluginName.clear();
                pd->SetPrediffer(infoPrediffer);
                pd->FlushAndRescan(true);
                return;
@@ -3128,23 +3128,23 @@ void CMergeEditView::SetPredifferByMenu(UINT nID )
 
        // build a PrediffingInfo structure fom the ID
        PrediffingInfo prediffer;
-       prediffer.bToBeScanned = false;
+       prediffer.m_PluginOrPredifferMode = PLUGIN_MANUAL;
 
        size_t pluginNumber = nID - ID_PREDIFFERS_FIRST;
        if (pluginNumber < piScriptArray->size())
        {
-               prediffer.bWithFile = true;
+               prediffer.m_bWithFile = true;
                const PluginInfoPtr & plugin = piScriptArray->at(pluginNumber);
-               prediffer.pluginName = plugin->m_name;
+               prediffer.m_PluginName = plugin->m_name;
        }
        else
        {
                pluginNumber -= piScriptArray->size();
                if (pluginNumber >= piScriptArray2->size())
                        return;
-               prediffer.bWithFile = false;
+               prediffer.m_bWithFile = false;
                const PluginInfoPtr & plugin = piScriptArray2->at(pluginNumber);
-               prediffer.pluginName = plugin->m_name;
+               prediffer.m_PluginName = plugin->m_name;
        }
 
        // update data for the radio button
index 63adc72..cd80808 100644 (file)
@@ -306,7 +306,7 @@ void COpenView::OnInitialUpdate()
        if (!bOverwriteRecursive)
                m_bRecurse = GetOptionsMgr()->GetBool(OPT_CMP_INCLUDE_SUBDIRS);
 
-       m_strUnpacker = m_infoHandler.pluginName;
+       m_strUnpacker = m_infoHandler.m_PluginName;
        UpdateData(FALSE);
        SetStatus(IDS_OPEN_FILESDIRS);
        SetUnpackerStatus(IDS_USERCHOICE_NONE); 
@@ -922,7 +922,7 @@ static UINT UpdateButtonStatesThread(LPVOID lpParam)
 void COpenView::UpdateResources()
 {
        theApp.m_pLangDlg->RetranslateDialog(m_hWnd, MAKEINTRESOURCE(IDD_OPEN));
-       if (m_strUnpacker != m_infoHandler.pluginName)
+       if (m_strUnpacker != m_infoHandler.m_PluginName)
                m_strUnpacker = theApp.LoadString(IDS_OPEN_UNPACKERDISABLED);
 }
 
@@ -1069,7 +1069,7 @@ void COpenView::OnSelectUnpacker()
        {
                m_infoHandler = dlg.GetInfoHandler();
 
-               m_strUnpacker = m_infoHandler.pluginName;
+               m_strUnpacker = m_infoHandler.m_PluginName;
 
                UpdateData(FALSE);
        }
index 9e5e558..440e648 100644 (file)
@@ -41,7 +41,7 @@ void PluginManager::FetchPluginInfos(const String& filteredFilenames,
 /**
  * @brief Store specified prediff choice for specified comparison
  */
-void PluginManager::SetPrediffSetting(const String& filteredFilenames, int newsetting)
+void PluginManager::SetPrediffSetting(const String& filteredFilenames, PLUGIN_MODE newsetting)
 {
        PackingInfo * infoUnpacker = nullptr;
        PrediffingInfo * infoPrediffer = nullptr;
@@ -49,7 +49,7 @@ void PluginManager::SetPrediffSetting(const String& filteredFilenames, int newse
        infoPrediffer->Initialize(newsetting);
 }
 
-void PluginManager::SetPrediffSettingAll(int newsetting)
+void PluginManager::SetPrediffSettingAll(PLUGIN_MODE newsetting)
 {
        FastMutex::ScopedLock lock(m_mutex);
        for (PluginFileInfoMap::iterator it = m_pluginSettings.begin(); it != m_pluginSettings.end(); ++it)
@@ -66,5 +66,5 @@ void PluginManager::SetPrediffer(const String& filteredFilenames, const String &
        PackingInfo * infoUnpacker = nullptr;
        PrediffingInfo * infoPrediffer = nullptr;
        FetchPluginInfos(filteredFilenames, &infoUnpacker, &infoPrediffer);
-       infoPrediffer->pluginName = prediffer;
+       infoPrediffer->m_PluginName = prediffer;
 }
\ No newline at end of file
index 6ab8d5e..4952887 100644 (file)
@@ -29,8 +29,8 @@ public:
        typedef std::map<String, PluginFileInfoPtr> PluginFileInfoMap;
 
        ~PluginManager();
-       void SetPrediffSetting(const String& filteredFilenames, int newsetting);
-       void SetPrediffSettingAll(int newsetting);
+       void SetPrediffSetting(const String& filteredFilenames, PLUGIN_MODE newsetting);
+       void SetPrediffSettingAll(PLUGIN_MODE newsetting);
        void SetPrediffer(const String& filteredFilenames, const String& prediffer);
        // Implement IPluginInfos
        virtual void FetchPluginInfos(const String& filteredFilenames, 
index bd94af9..5c8ce68 100644 (file)
@@ -127,7 +127,7 @@ void CSelectUnpackerDlg::SetInitialInfoHandler(PackingInfo * infoHandler)
        // default value
        m_pPlugin = noPlugin.get();
 
-       if (infoHandler && infoHandler->bToBeScanned)
+       if (infoHandler != nullptr && infoHandler->m_PluginOrPredifferMode != PLUGIN_MANUAL)
                // automatic unpacker
                m_pPlugin = automaticPlugin.get();
        else if (infoHandler)
@@ -137,7 +137,7 @@ void CSelectUnpackerDlg::SetInitialInfoHandler(PackingInfo * infoHandler)
                for (i = 0 ; i < m_UnpackerPlugins.GetSize() ; i++)
                {
                        PluginInfo * pPlugin = static_cast<PluginInfo*> (m_UnpackerPlugins.GetAt(i));
-                       if (pPlugin->m_name == infoHandler->pluginName)
+                       if (pPlugin->m_name == infoHandler->m_PluginName)
                                m_pPlugin = pPlugin;
                }
        }
@@ -153,8 +153,8 @@ const PackingInfo CSelectUnpackerDlg::GetInfoHandler()
        {
                // build a real plugin unpacker
                PackingInfo infoHandler;
-               infoHandler.bToBeScanned = FALSE;
-               infoHandler.pluginName = m_strPluginName;
+               infoHandler.m_PluginOrPredifferMode = PLUGIN_MANUAL;
+               infoHandler.m_PluginName = m_strPluginName;
                int i;
                for (i = 0 ; i < m_UnpackerPlugins.GetSize() ; i++)
                {
@@ -162,7 +162,7 @@ const PackingInfo CSelectUnpackerDlg::GetInfoHandler()
                        if (m_pPlugin == pPlugin)
                                break;
                }
-               infoHandler.bWithFile = m_bWithFileFlags.at(i);
+               infoHandler.m_bWithFile = m_bWithFileFlags.at(i);
                return infoHandler;
        }
 }
index c514a5c..bc09e45 100644 (file)
Binary files a/Testing/Data/Office/excel.xls and b/Testing/Data/Office/excel.xls differ
index c13e46f..4d90731 100644 (file)
@@ -57,7 +57,7 @@ namespace
                IPluginInfos *ppi = &pm;
                ppi->FetchPluginInfos(_T("../../Data/Office/excel.xls|../../Data/Office/excel.xls"), &iu, &ip);
                String file = paths::ConcatPath(oldModulePath, _T("..\\..\\Data\\Office\\excel.xls"));
-               FileTransform::Unpacking(file, _T(".*\\.xls"), iu, &iu->subcode);
+               FileTransform::Unpacking(file, _T(".*\\.xls"), iu, &iu->m_subcode);
        }
 
 }  // namespace