diff --git a/xpinstall/stub/xpistub.cpp b/xpinstall/stub/xpistub.cpp index 7a9b29039a31..294949a9c9ed 100644 --- a/xpinstall/stub/xpistub.cpp +++ b/xpinstall/stub/xpistub.cpp @@ -40,6 +40,10 @@ #include "plstr.h" +#ifdef XP_PC +#include +#endif + //------------------------------------------------------------------------ @@ -75,7 +79,34 @@ PR_PUBLIC_API(nsresult) XPI_Init( if (!NS_SUCCEEDED(rv)) return rv; +#ifdef XP_PC + // + // Passing 0 as the 2nd parameter to AutoRegister() will tell it to + // automatically determine the path to the components directory. + // Since XPI_Init() is being called by Setup.exe, not apprunner.exe, + // the wrong components directory is determined. + // As a requirement to loading xpistub.dll, it must be loaded from + // the same directory as xpcom.dll. + // This makes is easy to locate the correct components directory by + // using a form of GetCurrentDirectory(). + // + // Since nsFileSpec() does not contain a GetCwd() function, + // a call to getcwd() is being used under Windows only. + // + + char szTemp[_MAX_PATH]; + getcwd(szTemp, _MAX_PATH); + PL_strcat(szTemp, "\\"); + PL_strcat(szTemp, "components"); + nsfsDirectory = szTemp; + rv = NS_NewFileSpecWithSpec(*(&nsfsDirectory), getter_AddRefs(nsIfsDirectory)); + if(NS_FAILED(rv)) + return rv; + + rv = nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup, nsIfsDirectory); +#else rv = nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup, 0); +#endif if (NS_SUCCEEDED(rv)) { rv = nsComponentManager::CreateInstance(kSoftwareUpdateCID,