From: <ag...@us...> - 2011-12-18 04:27:35
|
Revision: 2649 http://zoolib.svn.sourceforge.net/zoolib/?rev=2649&view=rev Author: agreen Date: 2011-12-18 04:27:29 +0000 (Sun, 18 Dec 2011) Log Message: ----------- Some changes to allow version-dependent loading of stuff. Modified Paths: -------------- trunk/zoolib/source/cxx/more/zoolib/netscape/ZNetscape_GuestFactory.cpp trunk/zoolib/source/cxx/more/zoolib/netscape/ZNetscape_GuestFactory.h trunk/zoolib/source/cxx/more/zoolib/netscape/ZNetscape_Host.h Modified: trunk/zoolib/source/cxx/more/zoolib/netscape/ZNetscape_GuestFactory.cpp =================================================================== --- trunk/zoolib/source/cxx/more/zoolib/netscape/ZNetscape_GuestFactory.cpp 2011-12-14 20:56:42 UTC (rev 2648) +++ trunk/zoolib/source/cxx/more/zoolib/netscape/ZNetscape_GuestFactory.cpp 2011-12-18 04:27:29 UTC (rev 2649) @@ -27,6 +27,7 @@ #include "zoolib/ZUnicode.h" #include "zoolib/ZUtil_CF.h" #include "zoolib/ZUtil_MacOSX.h" +#include "zoolib/ZVal_CF.h" #if ZCONFIG_SPI_Enabled(CoreFoundation) #include ZMACINCLUDE2(CoreFoundation,CFBundle.h) @@ -126,6 +127,30 @@ P sLookup_T(CFBundleRef iBundleRef, CFStringRef iName) { return reinterpret_cast<P>(::CFBundleGetFunctionPointerForName(iBundleRef, iName)); } +ZQ<int> spQGetMajorVersion(const ZRef<CFStringRef>& iStringRef) + { + if (iStringRef) + { + if (SInt32 theVal = ::CFStringGetIntValue(iStringRef)) + return theVal; + } + return null; + } + +ZQ<int> spQGetMajorVersion(const ZMap_CF& iMap) + { return spQGetMajorVersion(iMap.Get(kCFBundleVersionKey).GetCFString()); } + +ZQ<int> spQGetMajorVersion(const ZRef<CFBundleRef>& iBundleRef) + { + if (iBundleRef) + { + if (ZRef<CFStringRef> theStringRef = + (CFStringRef)::CFBundleGetValueForInfoDictionaryKey(iBundleRef, kCFBundleVersionKey)) + { return spQGetMajorVersion(theStringRef); } + } + return null; + } + #endif // ZCONFIG_SPI_Enabled(CoreFoundation) // ================================================================================================= @@ -142,6 +167,8 @@ virtual const NPPluginFuncs& GetEntryPoints(); + virtual ZQ<int> QGetMajorVersion(); + private: HMODULE fHMODULE; NPNetscapeFuncs_Z fNPNF; @@ -195,6 +222,9 @@ const NPPluginFuncs& GuestFactory_Win::GetEntryPoints() { return fNPPluginFuncs; } +ZQ<int> GuestFactory_Win::QGetMajorVersion() + { return spQGetMajorVersion(fHMODULE); } + #endif // ZCONFIG_SPI_Enabled(Win) // ================================================================================================= @@ -216,6 +246,8 @@ virtual const NPPluginFuncs& GetEntryPoints(); + virtual ZQ<int> QGetMajorVersion(); + private: ZRef<CFPlugInRef> fPlugInRef; NSModule fNSModule; @@ -240,7 +272,7 @@ // If the plugin contains ObjC code then unloading it will kill the // host application. So (for now at least) we do an extra retain, leaving // the rest of the plugin management as it should be. - ::CFRetain(fPlugInRef); + //##::CFRetain(fPlugInRef); // Get our own copies of our host's function pointers GuestFactory::GetNPNF(fNPNF); @@ -343,6 +375,9 @@ const NPPluginFuncs& GuestFactory_HostMachO::GetEntryPoints() { return fNPPluginFuncs; } +ZQ<int> GuestFactory_HostMachO::QGetMajorVersion() + { return spQGetMajorVersion(fPlugInRef); } + #endif // ZCONFIG_SPI_Enabled(CoreFoundation) && __MACH__ // ================================================================================================= @@ -386,7 +421,7 @@ // If the plugin contains ObjC code then unloading it will kill the // host application. So (for now at least) we do an extra retain, leaving // the rest of the plugin management as it should be. - ::CFRetain(fPlugInRef); + //##::CFRetain(fPlugInRef); // Get local copies of our host's function pointers GuestFactory::GetNPNF(fNPNF); @@ -451,35 +486,52 @@ #pragma mark - #pragma mark * ZNetscape -ZRef<ZNetscape::GuestFactory> ZNetscape::sMakeGuestFactory(const std::string& iNativePath) +ZRef<ZNetscape::GuestFactory> ZNetscape::sMakeGuestFactory + (ZQ<int> iEarliest, ZQ<int> iLatest, const std::string& iNativePath) { try { #if ZCONFIG_SPI_Enabled(Win) - if (HMODULE theHMODULE = ::LoadLibraryW - (ZUnicode::sAsUTF16(iNativePath).c_str())) + if (iEarliest || iLatest) { - try + if (ZQ<uint64,false> theQ = sQGetVersion_File(iNativePath)) + { return null; } + else { - return new GuestFactory_Win(theHMODULE); - } - catch (...) - { - ::FreeLibrary(theHMODULE); - } + int theMajor = *theQ; + if (iEarliest && *iEarliest > theMajor) + { return null; } + else if (iLatest && *iLatest < theMajor) + { return null; } } + + if (HMODULE theHMODULE = ::LoadLibraryW(ZUnicode::sAsUTF16(iNativePath).c_str())) + { + try { return new GuestFactory_Win(theHMODULE); } + catch (...) { ::FreeLibrary(theHMODULE); } + } #endif #if ZCONFIG_SPI_Enabled(CoreFoundation) if (ZRef<CFURLRef> theURL = sAdopt& ::CFURLCreateWithFileSystemPath (nullptr, ZUtil_CF::sString(iNativePath), kCFURLPOSIXPathStyle, true)) { - if (ZRef<CFPlugInRef> thePlugInRef = sAdopt& ::CFPlugInCreate(nullptr, theURL)) + if (ZMap_CF theMap = sAdopt& ::CFBundleCopyInfoDictionaryInDirectory(theURL)) { + if (ZQ<int,false> theQ = spQGetMajorVersion(theMap)) + { return null; } + else if (iEarliest && *iEarliest > *theQ) + { return null; } + else if (iLatest && *iLatest < *theQ) + { return null; } + } + + if (ZRef<CFBundleRef> theBundleRef = sAdopt& ::CFBundleCreate(nullptr, theURL)) + { #if __MACH__ - return new GuestFactory_HostMachO(thePlugInRef); + return new GuestFactory_HostMachO(theBundleRef); #elif ZCONFIG(Processor,PPC) - return new GuestFactory_HostCFM(thePlugInRef); + return new GuestFactory_HostCFM(theBundleRef); #endif } } @@ -491,4 +543,7 @@ return null; } +ZRef<ZNetscape::GuestFactory> ZNetscape::sMakeGuestFactory(const std::string& iNativePath) + { return sMakeGuestFactory(null, null, iNativePath); } + } // namespace ZooLib Modified: trunk/zoolib/source/cxx/more/zoolib/netscape/ZNetscape_GuestFactory.h =================================================================== --- trunk/zoolib/source/cxx/more/zoolib/netscape/ZNetscape_GuestFactory.h 2011-12-14 20:56:42 UTC (rev 2648) +++ trunk/zoolib/source/cxx/more/zoolib/netscape/ZNetscape_GuestFactory.h 2011-12-18 04:27:29 UTC (rev 2649) @@ -33,6 +33,9 @@ #pragma mark - #pragma mark * ZNetscape +ZRef<GuestFactory> sMakeGuestFactory + (ZQ<int> iEarliest, ZQ<int> iLatest, const std::string& iNativePath); + ZRef<GuestFactory> sMakeGuestFactory(const std::string& iNativePath); } // namespace ZNetscape Modified: trunk/zoolib/source/cxx/more/zoolib/netscape/ZNetscape_Host.h =================================================================== --- trunk/zoolib/source/cxx/more/zoolib/netscape/ZNetscape_Host.h 2011-12-14 20:56:42 UTC (rev 2648) +++ trunk/zoolib/source/cxx/more/zoolib/netscape/ZNetscape_Host.h 2011-12-18 04:27:29 UTC (rev 2649) @@ -402,6 +402,8 @@ void GetNPNF(NPNetscapeFuncs_Z& oNPNF); virtual const NPPluginFuncs& GetEntryPoints() = 0; + + virtual ZQ<int> QGetMajorVersion() = 0; }; // ================================================================================================= This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |