From bfdec13982e063a3115b711067dfd81b1da5c779 Mon Sep 17 00:00:00 2001 From: anders_k Date: Mon, 25 Jun 2018 21:33:30 +0000 Subject: [PATCH] List plug-in directories when plug-in call fails git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@7011 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/Platform.h | 13 +++++++++++++ Source/Plugins.cpp | 34 ++++++++++++++++++++++++++++++++++ Source/Plugins.h | 1 + Source/build.h | 8 ++------ Source/exehead/fileform.h | 2 +- Source/script.cpp | 3 +++ Source/util.cpp | 4 ++-- 7 files changed, 56 insertions(+), 9 deletions(-) diff --git a/Source/Platform.h b/Source/Platform.h index 341367a0..a2c8761a 100644 --- a/Source/Platform.h +++ b/Source/Platform.h @@ -1046,6 +1046,11 @@ typedef struct tagVS_FIXEDFILEINFO { #else # define NSIS_CXX_NOEXCEPT() throw() // Can't specialize __declspec(nothrow) because MSVC requires it before the function name #endif +#if defined(_MSC_VER) && _MSC_VER <= 1200 +# define NSIS_CXX_TYPENAME // VC6 can't handle typename in some places but GCC requires it +#else +# define NSIS_CXX_TYPENAME typename +#endif #define BUGBUG64TRUNCATE(cast,xpr) ( (cast) (xpr) ) /* @@ -1090,4 +1095,12 @@ FORCEINLINE BOOL NoDepr_GetVersionExW(OSVERSIONINFOW*p) { __pragma(warning(push) #endif //~ _MSC_VER >= 1500 #endif //~ _MSC_VER + +#ifdef __cplusplus +namespace STLHelpers +{ + template struct mapped_type_helper { typedef typename M::value_type::second_type type; }; // VC6 uses referent_type and not mapped_type +} +#endif //~ __cplusplus + #endif // EOF diff --git a/Source/Plugins.cpp b/Source/Plugins.cpp index 4d6a2406..ff4750c4 100644 --- a/Source/Plugins.cpp +++ b/Source/Plugins.cpp @@ -76,6 +76,16 @@ V get_paired_value(const C& cntnr, const K& key, const V& defval) } +static tstring GetDllPath(const tstring&fullpath) +{ + tstring::size_type platsep = fullpath.rfind(PLATFORM_PATH_SEPARATOR_STR); + tstring::size_type unixsep = platsep; + if (PLATFORM_PATH_SEPARATOR_C != _T('/')) unixsep = fullpath.rfind(_T("/")); // Ideally get_dir_name would do this for us + tstring::size_type lastsep = platsep != string::npos && unixsep != string::npos ? STD_MAX(platsep, unixsep) : STD_MIN(platsep, unixsep); + if (lastsep == string::npos) return _T(""); + return fullpath.substr(0, lastsep); +} + static inline tstring GetDllName(const tstring&command) { return get_string_prefix(command, _T("::")); @@ -253,4 +263,28 @@ bool Plugins::IsPluginCallSyntax(const tstring& token) return dllname.length() + 2 < token.length(); } +struct PrintPluginDirsHelper { + template static void print(const C&c, const char*indent = "") + { + std::/*unordered_*/set::type +#ifdef _WIN32 + , Plugins::strnocasecmp +#endif + > seen; + for (NSIS_CXX_TYPENAME C::const_iterator it = c.begin(); it != c.end(); ++it) + { + const tstring path = GetDllPath(it->second); + if (contains(seen, path)) continue; + seen.insert(path); + _ftprintf(g_output, _T("%") NPRIns _T("%") NPRIs _T("\n"), indent, path.c_str()); + } + } +}; + +void Plugins::PrintPluginDirs() +{ + _ftprintf(g_output, _T("Plugin directories:\n")); + PrintPluginDirsHelper::print(m_dllname_to_path, " "); +} + #endif diff --git a/Source/Plugins.h b/Source/Plugins.h index d4c0bdc0..4c93f00f 100644 --- a/Source/Plugins.h +++ b/Source/Plugins.h @@ -57,6 +57,7 @@ class Plugins int GetDllDataHandle(bool uninst, const tstring& command) const; void SetDllDataHandle(bool uninst, tstring&canoniccmd, int dataHandle); static bool IsPluginCallSyntax(const tstring& token); + void PrintPluginDirs(); private: // methods void GetExports(const tstring &pathToDll, bool pe64, bool displayInfo); diff --git a/Source/build.h b/Source/build.h index 8d94a4ea..5ebc1101 100644 --- a/Source/build.h +++ b/Source/build.h @@ -169,15 +169,11 @@ namespace MakensisAPI { #define FLAG_OFFSET(flag) (FIELD_OFFSET(exec_flags_t, flag)/sizeof(int)) class DiagState { - template struct mapped_type_helper { typedef typename M::value_type::second_type type; }; // VC6 uses referent_type and not mapped_type + template struct mapped_type_helper { typedef typename STLHelpers::mapped_type_helper::type type; }; template void insert_or_assign(C&c, const K&k, V val) { typename C::value_type item(k, val); -#if defined(_MSC_VER) && _MSC_VER <= 1200 - std::pair ret = c.insert(item); -#else - std::pair ret = c.insert(item); -#endif + std::pair ret = c.insert(item); if (!ret.second) ret.first->second = val; } template typename mapped_type_helper::type get_paired_value(const C&c, const K&k, typename mapped_type_helper::type defval) const diff --git a/Source/exehead/fileform.h b/Source/exehead/fileform.h index 9788b8bc..4dbf7ccf 100644 --- a/Source/exehead/fileform.h +++ b/Source/exehead/fileform.h @@ -516,7 +516,7 @@ typedef struct { #define REGROOTVIEW32 0x40000000 #define REGROOTVIEW64 0x20000000 -#define REGROOTVIEWTOSAMVIEW(rv) ( ((UINT_PTR)(rv)&(REGROOTVIEW32|REGROOTVIEW64)) >> 21 ) // REGROOTVIEWxx to KEY_WOW64_xxKEY +#define REGROOTVIEWTOSAMVIEW(rv) ( (UINT)(((UINT_PTR)(rv)&(REGROOTVIEW32|REGROOTVIEW64)) >> 21) ) // REGROOTVIEWxx to KEY_WOW64_xxKEY #define IsRegRootkeyForcedView(hKey) ( ((UINT_PTR) (hKey) & (REGROOTVIEW32|REGROOTVIEW64)) ) #define MAKEREGROOTVIEW(r, fv) ( (HKEY) ((UINT_PTR)(r) | (fv)) ) #define HKSHCTX ( (HKEY) 0 ) // Converted to HKCU or HKLM by GetRegRootKey diff --git a/Source/script.cpp b/Source/script.cpp index 16635bf7..bb7fe37c 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -297,7 +297,10 @@ parse_again: { #ifdef NSIS_CONFIG_PLUGIN_SUPPORT if (Plugins::IsPluginCallSyntax(tokstr0)) + { + if (m_pPlugins && display_warnings) m_pPlugins->PrintPluginDirs(); ERROR_MSG(_T("Plugin%") NPRIs _T(" not found, cannot call %") NPRIs _T("\n"),m_pPlugins && m_pPlugins->IsKnownPlugin(tokstr0) ? _T(" function") : _T(""),tokstr0); + } else #endif ERROR_MSG(_T("Invalid command: \"%") NPRIs _T("\"\n"),tokstr0); diff --git a/Source/util.cpp b/Source/util.cpp index ad1b444c..2a2e8f4c 100644 --- a/Source/util.cpp +++ b/Source/util.cpp @@ -1023,14 +1023,14 @@ int RunChildProcessRedirected(LPCWSTR cmdprefix, LPCWSTR cmdmain, bool ForceUTF8 { bool fullbuf = false, utf8 = CP_UTF8 == cp, okt; char iobuf[512]; - DWORD cbRead, cbOfs = 0, cchwb = 0; + DWORD cbRead, cbOfs = 0, cchwb = 0, i; WCHAR wbuf[100], wchbuf[2+1]; // A surrogate pair + \0 for(;;) { BOOL okr = ReadFile(hSORd, iobuf+cbOfs, sizeof(iobuf)-cbOfs, &cbRead, 0); cbRead += cbOfs, cbOfs = 0; unsigned char cbTrail, cch; - for(DWORD i = 0; i < cbRead;) + for(i = 0; i < cbRead;) { cch = 0; if (utf8)