30 #include <nsICategoryManager.h>
32 #include <nsIObserverService.h>
33 #include <nsIProperties.h>
39 #include <nsDirectoryServiceDefs.h>
40 #include <nsNetUtil.h>
41 #include <nsServiceManagerUtils.h>
42 #include <nsStringAPI.h>
43 #include <nsXPCOMCID.h>
51 #elif defined(XP_MACOSX)
52 #include <crt_externs.h>
58 #define NS_APPSTARTUP_CATEGORY "app-startup"
59 #define XRE_UPDATE_ROOT_DIR "UpdRootD"
60 #define TOPIC_UPDATE_STATUS "update-service-pre-update-status"
63 # define __FUNCTION__ __PRETTY_FUNCTION__
71 static PRLogModuleInfo* gDistHelperEnvWriterLog = nsnull;
72 #define TRACE(args) PR_LOG(gDistHelperEnvWriterLog , PR_LOG_DEBUG, args)
73 #define LOG(args) PR_LOG(gDistHelperEnvWriterLog , PR_LOG_WARN, args)
84 if (!gDistHelperEnvWriterLog)
85 gDistHelperEnvWriterLog = PR_NewLogModule(
"sbDistHelperEnvWriter");
89 sbDistHelperEnvWriter::~sbDistHelperEnvWriter()
96 const char* aLoaderStr,
98 const nsModuleComponentInfo* aInfo)
100 nsresult rv = NS_ERROR_UNEXPECTED;
101 nsCOMPtr<nsICategoryManager> categoryManager =
102 do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
103 NS_ENSURE_SUCCESS(rv, rv);
107 "sbDistHelperEnvWriter",
109 PR_TRUE, PR_TRUE, &previousEntry);
110 NS_ENSURE_SUCCESS(rv, rv);
112 NS_Free(previousEntry);
121 const char *aLoaderStr,
122 const nsModuleComponentInfo *aInfo)
127 nsCOMPtr<nsICategoryManager> categoryManager =
128 do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
129 NS_ENSURE_SUCCESS(rv, rv);
133 "sbDistHelperEnvWriter",
135 NS_ENSURE_SUCCESS(rv, rv);
144 TRACE((
"%s", __FUNCTION__));
145 NS_ENSURE_ARG_POINTER(aUpdateDir);
147 nsCOMPtr<nsIFile> outFile;
148 rv = aUpdateDir->Clone(getter_AddRefs(outFile));
149 NS_ENSURE_SUCCESS(rv, rv);
150 rv = outFile->Append(NS_LITERAL_STRING(
"disthelper.env"));
151 NS_ENSURE_SUCCESS(rv, rv);
153 nsCOMPtr<nsIOutputStream> outStream;
154 rv = NS_NewLocalFileOutputStream(getter_AddRefs(outStream),
156 NS_ENSURE_SUCCESS(rv, rv);
160 const WCHAR ENV_PREFIX[] = L
"DISTHELPER_";
161 LPWSTR env = GetEnvironmentStringsW();
163 if (!wcsncmp(ENV_PREFIX, env, NS_ARRAY_LENGTH(ENV_PREFIX) - 1)) {
164 nsCAutoString envString;
165 CopyUTF16toUTF8(nsDependentString(env), envString);
166 TRACE((
"env var: %s", envString.get()));
167 envString.Append(
'\n');
168 PRUint32 bytesWritten;
169 rv = outStream->Write(envString.get(),
172 NS_ENSURE_SUCCESS(rv, rv);
174 env += wcslen(env) + 1;
177 const char ENV_PREFIX[] =
"DISTHELPER_";
179 #if defined(XP_MACOSX)
181 env = *_NSGetEnviron();
185 for (; *env; ++env) {
186 if (!strncmp(ENV_PREFIX, *env, NS_ARRAY_LENGTH(ENV_PREFIX) - 1)) {
187 nsCAutoString envString(*env);
188 TRACE((
"env var: %s", envString.get()));
189 envString.Append(
'\n');
190 PRUint32 bytesWritten;
191 rv = outStream->Write(envString.get(),
194 NS_ENSURE_SUCCESS(rv, rv);
198 rv = outStream->Close();
199 NS_ENSURE_SUCCESS(rv, rv);
207 sbDistHelperEnvWriter::Observe(
nsISupports *aSubject,
209 const PRUnichar *
aData)
212 TRACE((
"%s: %s", __FUNCTION__, aTopic));
215 nsCOMPtr<nsIObserverService> obsSvc =
216 do_GetService(NS_OBSERVERSERVICE_CONTRACTID, &rv);
217 NS_ENSURE_SUCCESS(rv, rv);
218 rv = obsSvc->AddObserver(
this, NS_XPCOM_SHUTDOWN_OBSERVER_ID,
false);
219 NS_ENSURE_SUCCESS(rv, rv);
221 NS_ENSURE_SUCCESS(rv, rv);
223 else if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
224 nsCOMPtr<nsIObserverService> obsSvc =
225 do_GetService(NS_OBSERVERSERVICE_CONTRACTID, &rv);
226 rv = obsSvc->RemoveObserver(
this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
227 NS_ENSURE_SUCCESS(rv, rv);
229 NS_ENSURE_SUCCESS(rv, rv);
232 if (NS_LITERAL_STRING(
"pending").Equals(aData)) {
233 nsCOMPtr<nsIFile> updateDir = do_QueryInterface(aSubject);
234 NS_ENSURE_TRUE(updateDir, NS_ERROR_FAILURE);
236 NS_ENSURE_SUCCESS(rv, rv);
nsresult OnUpdatePending(nsIFile *aUpdateDir)
NS_IMPL_ISUPPORTS1(sbDeviceCapabilitiesUtils, sbIDeviceCapabilitiesUtils) sbDeviceCapabilitiesUtils
static NS_METHOD RegisterSelf(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *aLoaderStr, const char *aType, const nsModuleComponentInfo *aInfo)
#define SB_DISTHELPER_ENV_WRITER_CONTRACTID
#define NS_APPSTARTUP_CATEGORY
static NS_METHOD UnregisterSelf(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *aLoaderStr, const nsModuleComponentInfo *aInfo)
#define TOPIC_UPDATE_STATUS
_updateTextAndScrollDataForFrame aData