From a72605dabc94f138dea99abe36f97445f5cd8d21 Mon Sep 17 00:00:00 2001 From: "dougt%netscape.com" Date: Thu, 13 May 1999 23:14:47 +0000 Subject: [PATCH] Adding files for Progress support git-svn-id: svn://10.0.0.236/trunk@31501 18797224-902f-48f8-a5cc-f745e15eee43 --- .../src/nsLoggingProgressNotifier.cpp | 117 +++++++++++++ .../xpinstall/src/nsLoggingProgressNotifier.h | 53 ++++++ .../xpinstall/src/nsTopProgressNotifier.cpp | 159 ++++++++++++++++++ mozilla/xpinstall/src/nsTopProgressNotifier.h | 54 ++++++ 4 files changed, 383 insertions(+) create mode 100644 mozilla/xpinstall/src/nsLoggingProgressNotifier.cpp create mode 100644 mozilla/xpinstall/src/nsLoggingProgressNotifier.h create mode 100644 mozilla/xpinstall/src/nsTopProgressNotifier.cpp create mode 100644 mozilla/xpinstall/src/nsTopProgressNotifier.h diff --git a/mozilla/xpinstall/src/nsLoggingProgressNotifier.cpp b/mozilla/xpinstall/src/nsLoggingProgressNotifier.cpp new file mode 100644 index 00000000000..96be16e265f --- /dev/null +++ b/mozilla/xpinstall/src/nsLoggingProgressNotifier.cpp @@ -0,0 +1,117 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Mozilla Communicator client code, + * released March 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + * + * Contributors: + * Douglas Turner + */ + +#include "nsIXPInstallProgressNotifier.h" +#include "nsLoggingProgressNotifier.h" + +#include "nsFileSpec.h" +#include "nsFileStream.h" +#include "nsSpecialSystemDirectory.h" + +#include "nspr.h" + + + +nsLoggingProgressNotifier::nsLoggingProgressNotifier() +{ + nsSpecialSystemDirectory logFile(nsSpecialSystemDirectory::OS_CurrentProcessDirectory); + logFile += "Install.log"; + + mLogStream = new nsOutputFileStream(logFile, PR_WRONLY | PR_CREATE_FILE | PR_APPEND, 0744 ); + mLogStream->seek(logFile.GetFileSize()); +} + +nsLoggingProgressNotifier::~nsLoggingProgressNotifier() +{ + mLogStream->close(); + delete mLogStream; +} + +void +nsLoggingProgressNotifier::BeforeJavascriptEvaluation(void) +{ +} + +void +nsLoggingProgressNotifier::AfterJavascriptEvaluation(void) +{ + char* time; + GetTime(&time); + + *mLogStream << nsEndl; + *mLogStream << " Finished Installation " << time << nsEndl << nsEndl; + + PL_strfree(time); +} + +void +nsLoggingProgressNotifier::InstallStarted(const char* UIPackageName) +{ + char* time; + GetTime(&time); + + *mLogStream << "---------------------------------------------------------------------------" << nsEndl; + *mLogStream << UIPackageName << nsEndl; + *mLogStream << "---------------------------------------------------------------------------" << nsEndl; + *mLogStream << nsEndl; + *mLogStream << " Starting Installation at " << nsAutoCString(time) << nsEndl; + *mLogStream << nsEndl; + + + PL_strfree(time); +} + +long +nsLoggingProgressNotifier::ItemScheduled(const char* message ) +{ + return 0; +} + +void +nsLoggingProgressNotifier::InstallFinalization(const char* message, long itemNum, long totNum ) +{ + *mLogStream << " " << message << nsEndl; +} + +void +nsLoggingProgressNotifier::InstallAborted(void) +{ + char* time; + GetTime(&time); + + *mLogStream << " Aborted Installation at " << time << nsEndl << nsEndl; + + PL_strfree(time); +} + +void +nsLoggingProgressNotifier::GetTime(char** aString) +{ + PRExplodedTime et; + char line[256]; + PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &et); + PR_FormatTimeUSEnglish(line, sizeof(line), "%m/%d/%Y %H:%M:%S", &et); + *aString = PL_strdup(line); +} + diff --git a/mozilla/xpinstall/src/nsLoggingProgressNotifier.h b/mozilla/xpinstall/src/nsLoggingProgressNotifier.h new file mode 100644 index 00000000000..0471be0af77 --- /dev/null +++ b/mozilla/xpinstall/src/nsLoggingProgressNotifier.h @@ -0,0 +1,53 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Mozilla Communicator client code, + * released March 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + * + * Contributors: + * Daniel Veditz + * Douglas Turner + */ + + +#ifndef nsLoggingProgressNotifier_H__ +#define nsLoggingProgressNotifier_H__ + +#include "nsIXPInstallProgressNotifier.h" +#include "nsFileStream.h" + + +class nsLoggingProgressNotifier : public nsIXPInstallProgressNotifier +{ + public: + + nsLoggingProgressNotifier(); + virtual ~nsLoggingProgressNotifier(); + + void BeforeJavascriptEvaluation(void); + void AfterJavascriptEvaluation(void); + void InstallStarted(const char* UIPackageName); + long ItemScheduled(const char* message ); + void InstallFinalization(const char* message, long itemNum, long totNum ); + void InstallAborted(void); + + private: + void GetTime(char** aString); + nsOutputFileStream *mLogStream; +}; + +#endif \ No newline at end of file diff --git a/mozilla/xpinstall/src/nsTopProgressNotifier.cpp b/mozilla/xpinstall/src/nsTopProgressNotifier.cpp new file mode 100644 index 00000000000..cedb9cdbc84 --- /dev/null +++ b/mozilla/xpinstall/src/nsTopProgressNotifier.cpp @@ -0,0 +1,159 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Mozilla Communicator client code, + * released March 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + * + * Contributors: + * Douglas Turner + */ + +#include "nsIXPInstallProgressNotifier.h" +#include "nsTopProgressNotifier.h" + +nsTopProgressNotifier::nsTopProgressNotifier() +{ + mNotifiers = new nsVector(); +} + +nsTopProgressNotifier::~nsTopProgressNotifier() +{ + if (mNotifiers) + { + PRUint32 i=0; + for (; i < mNotifiers->GetSize(); i++) + { + nsIXPInstallProgressNotifier* element = (nsIXPInstallProgressNotifier*)mNotifiers->Get(i); + delete element; + } + + mNotifiers->RemoveAll(); + delete (mNotifiers); + } +} + +long +nsTopProgressNotifier::RegisterNotifier(nsIXPInstallProgressNotifier * newNotifier) +{ + return mNotifiers->Add( newNotifier ); +} + + +void +nsTopProgressNotifier::UnregisterNotifier(long id) +{ + mNotifiers->Set(id, NULL); +} + + + +void +nsTopProgressNotifier::BeforeJavascriptEvaluation(void) +{ + if (mNotifiers) + { + PRUint32 i=0; + for (; i < mNotifiers->GetSize(); i++) + { + nsIXPInstallProgressNotifier* element = (nsIXPInstallProgressNotifier*)mNotifiers->Get(i); + if (element != NULL) + element->BeforeJavascriptEvaluation(); + } + } +} + +void +nsTopProgressNotifier::AfterJavascriptEvaluation(void) +{ + if (mNotifiers) + { + PRUint32 i=0; + for (; i < mNotifiers->GetSize(); i++) + { + nsIXPInstallProgressNotifier* element = (nsIXPInstallProgressNotifier*)mNotifiers->Get(i); + if (element != NULL) + element->AfterJavascriptEvaluation(); + } + } +} + +void +nsTopProgressNotifier::InstallStarted(const char* UIPackageName) +{ + if (mNotifiers) + { + PRUint32 i=0; + for (; i < mNotifiers->GetSize(); i++) + { + nsIXPInstallProgressNotifier* element = (nsIXPInstallProgressNotifier*)mNotifiers->Get(i); + if (element != NULL) + element->InstallStarted(UIPackageName); + } + } +} + +long +nsTopProgressNotifier::ItemScheduled( const char* message ) +{ + long rv = 0; + + if (mNotifiers) + { + PRUint32 i=0; + for (; i < mNotifiers->GetSize(); i++) + { + nsIXPInstallProgressNotifier* element = (nsIXPInstallProgressNotifier*)mNotifiers->Get(i); + if (element != NULL) + if (element->ItemScheduled( message ) != 0) + rv = -1; + } + } + + return rv; +} + +void +nsTopProgressNotifier::InstallFinalization( const char* message, long itemNum, long totNum ) +{ + if (mNotifiers) + { + PRUint32 i=0; + for (; i < mNotifiers->GetSize(); i++) + { + nsIXPInstallProgressNotifier* element = (nsIXPInstallProgressNotifier*)mNotifiers->Get(i); + if (element != NULL) + element->InstallFinalization( message, itemNum, totNum ); + } + } +} + +void +nsTopProgressNotifier::InstallAborted(void) +{ + if (mNotifiers) + { + PRUint32 i=0; + for (; i < mNotifiers->GetSize(); i++) + { + nsIXPInstallProgressNotifier* element = (nsIXPInstallProgressNotifier*)mNotifiers->Get(i); + if (element != NULL) + element->InstallAborted(); + } + } +} + + diff --git a/mozilla/xpinstall/src/nsTopProgressNotifier.h b/mozilla/xpinstall/src/nsTopProgressNotifier.h new file mode 100644 index 00000000000..cb02217d266 --- /dev/null +++ b/mozilla/xpinstall/src/nsTopProgressNotifier.h @@ -0,0 +1,54 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Mozilla Communicator client code, + * released March 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + * + * Contributors: + * Douglas Turner + */ + +#ifndef nsTopProgressNotifier_h__ +#define nsTopProgressNotifier_h__ + +#include "nsIXPInstallProgressNotifier.h" +#include "nsVector.h" + + +class nsTopProgressNotifier : public nsIXPInstallProgressNotifier +{ + public: + + nsTopProgressNotifier(); + virtual ~nsTopProgressNotifier(); + + long RegisterNotifier(nsIXPInstallProgressNotifier * newNotifier); + void UnregisterNotifier(long id); + + void BeforeJavascriptEvaluation(void); + void AfterJavascriptEvaluation(void); + void InstallStarted(const char* UIPackageName); + long ItemScheduled(const char* message ); + void InstallFinalization(const char* message, long itemNum, long totNum ); + void InstallAborted(void); + + private: + nsVector *mNotifiers; + +}; + +#endif