From 138e8760d5f2ea38adee44b611bfeffa557d760a Mon Sep 17 00:00:00 2001 From: "sgehani%netscape.com" Date: Thu, 6 Jul 2000 19:44:09 +0000 Subject: [PATCH] Create install log file in XPCOM's notion of cwd. [nsbeta2+ b = 19034; r = ssu] --- xpinstall/src/nsLoggingProgressNotifier.cpp | 87 +++++++++++++++++++-- xpinstall/src/nsLoggingProgressNotifier.h | 5 ++ 2 files changed, 86 insertions(+), 6 deletions(-) diff --git a/xpinstall/src/nsLoggingProgressNotifier.cpp b/xpinstall/src/nsLoggingProgressNotifier.cpp index 3ae9ed6c5b04..9073f7387d8d 100644 --- a/xpinstall/src/nsLoggingProgressNotifier.cpp +++ b/xpinstall/src/nsLoggingProgressNotifier.cpp @@ -21,6 +21,7 @@ * Contributor(s): * Douglas Turner * Pierre Phaneuf + * Samir Gehani */ #include "nsLoggingProgressNotifier.h" @@ -29,7 +30,7 @@ #include "nsFileSpec.h" #include "nsFileStream.h" -#include "nsSpecialSystemDirectory.h" +#include "nsDirectoryService.h" #include "nspr.h" @@ -57,21 +58,56 @@ NS_IMPL_ISUPPORTS(nsLoggingProgressListener, NS_GET_IID(nsIXPIListener)); NS_IMETHODIMP nsLoggingProgressListener::BeforeJavascriptEvaluation(const PRUnichar *URL) { - nsSpecialSystemDirectory logFile(nsSpecialSystemDirectory::OS_CurrentProcessDirectory); + nsCOMPtr iFile; + nsFileSpec *logFile = nsnull; + nsresult rv = NS_OK; + + // Not in stub installer + if (!nsSoftwareUpdate::GetProgramDirectory()) + { + NS_WITH_SERVICE(nsIProperties, dirSvc, + NS_DIRECTORY_SERVICE_PROGID, &rv); + if (!dirSvc) return NS_ERROR_FAILURE; + dirSvc->Get("system.OS_CurrentProcessDirectory", NS_GET_IID(nsIFile), + getter_AddRefs(iFile)); + } + // In stub installer + else + { + rv = nsSoftwareUpdate::GetProgramDirectory()->Clone( + getter_AddRefs(iFile)); + } + + if (NS_FAILED(rv)) return rv; + #ifdef XP_MAC - logFile += "Install Log"; + rv = iFile->Append("Install Log"); #else - logFile += "install.log"; + rv = iFile->Append("install.log"); #endif - mLogStream = new nsOutputFileStream(logFile, PR_WRONLY | PR_CREATE_FILE | PR_APPEND, 0744 ); + // create log file if it doesn't exist (to work around a mac filespec bug) + PRBool bExists = PR_FALSE; + rv = iFile->Exists(&bExists); + if (NS_FAILED(rv)) return rv; + if (!bExists) + { + rv = iFile->Create(nsIFile::NORMAL_FILE_TYPE, 0644); + if (NS_FAILED(rv)) return rv; + } + + rv = Convert_nsIFile_To_nsFileSpec(iFile, &logFile); + if (NS_FAILED(rv)) return rv; + if (!logFile) return NS_ERROR_NULL_POINTER; + + mLogStream = new nsOutputFileStream(*logFile, PR_WRONLY | PR_CREATE_FILE | PR_APPEND, 0744 ); if (!mLogStream) return NS_ERROR_NULL_POINTER; char* time; GetTime(&time); - mLogStream->seek(logFile.GetFileSize()); + mLogStream->seek(logFile->GetFileSize()); *mLogStream << "-------------------------------------------------------------------------------" << nsEndl; *mLogStream << nsAutoCString(URL) << " -- " << time << nsEndl; @@ -79,6 +115,9 @@ nsLoggingProgressListener::BeforeJavascriptEvaluation(const PRUnichar *URL) *mLogStream << nsEndl; PL_strfree(time); + if (logFile) + delete logFile; + return NS_OK; } @@ -195,3 +234,39 @@ nsLoggingProgressListener::LogComment(const PRUnichar* comment) return NS_OK; } +nsresult +Convert_nsIFile_To_nsFileSpec(nsIFile *aInIFile, nsFileSpec **aOutFileSpec) +{ + nsresult rv = NS_OK; + + if (!aInIFile || !aOutFileSpec) + return NS_ERROR_FAILURE; + + *aOutFileSpec = nsnull; + +#ifdef XP_MAC + FSSpec fsSpec; + nsCOMPtr iFileMac; + + iFileMac = do_QueryInterface(aInIFile, &rv); + if (NS_SUCCEEDED(rv)) + { + iFileMac->GetResolvedFSSpec(&fsSpec); + *aOutFileSpec = new nsFileSpec(fsSpec, PR_FALSE); + } +#else + char *path = nsnull; + + rv = aInIFile->GetPath(&path); + if (NS_SUCCEEDED(rv)) + { + *aOutFileSpec = new nsFileSpec(path, PR_FALSE); + } + // NOTE: don't release path since nsFileSpec's mPath points to it +#endif + + if (!*aOutFileSpec) + rv = NS_ERROR_FAILURE; + + return rv; +} diff --git a/xpinstall/src/nsLoggingProgressNotifier.h b/xpinstall/src/nsLoggingProgressNotifier.h index 099e6c500ea7..5515f8ad4d39 100644 --- a/xpinstall/src/nsLoggingProgressNotifier.h +++ b/xpinstall/src/nsLoggingProgressNotifier.h @@ -21,6 +21,7 @@ * Contributor(s): * Daniel Veditz * Douglas Turner + * Samir Gehani */ @@ -29,6 +30,7 @@ #include "nsIXPINotifier.h" #include "nsFileStream.h" +#include "nsIFile.h" class nsLoggingProgressListener : public nsIXPIListener @@ -48,4 +50,7 @@ class nsLoggingProgressListener : public nsIXPIListener nsOutputFileStream *mLogStream; }; +nsresult Convert_nsIFile_To_nsFileSpec(nsIFile *aInIFile, + nsFileSpec **aOutFileSpec); + #endif