Bug 214889 - remove nsFileSpec from xpinstall, patch by cls r=me

This commit is contained in:
benjamin%smedbergs.us 2006-03-27 20:21:22 +00:00
Родитель a5342e1803
Коммит b5852605a5
8 изменённых файлов: 66 добавлений и 170 удалений

Просмотреть файл

@ -62,8 +62,9 @@ LIBXUL_LIBRARY = 1
PACKAGE_FILE = base.pkg
EXTRA_DSO_LIBS = mozreg_s
REQUIRES = xpcom \
xpcom_obsolete \
string \
jar \
caps \
@ -157,7 +158,6 @@ EXTRA_DSO_LDOPTS = \
$(MOZ_COMPONENT_LIBS) \
$(MOZ_UNICHARUTIL_LIBS) \
$(ZLIB_LIBS) \
$(MOZ_XPCOM_OBSOLETE_LIBS) \
$(NULL)
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))

Просмотреть файл

@ -49,8 +49,6 @@
#include "nsUnicharUtils.h"
#include "nsNativeCharsetUtils.h"
#include "nsXPIDLString.h"
#include "nsFileSpec.h"
#include "nsIFileSpec.h"
#include "nsIFile.h"
#include "nsILocalFile.h"
#include "nsDirectoryService.h"
@ -59,6 +57,7 @@
#ifdef XP_WIN
#include <stdarg.h>
#include <stdlib.h>
#include <winbase.h>
#include <winreg.h>
#endif
@ -276,27 +275,23 @@ nsInstallFolder::SetDirectoryPath(const nsAString& aFolderID, const nsString& aR
{
if (!aRelativePath.IsEmpty())
{
nsFileSpec tmpSpec;
nsCAutoString tmpPath("file:///");
nsCAutoString nativePath;
nsCOMPtr<nsILocalFile> localFile;
NS_CopyUnicodeToNative(aRelativePath, nativePath);
tmpPath.Append(nativePath);
tmpSpec = nsFileURL(tmpPath.get());
rv = NS_FileSpecToIFile( &tmpSpec, getter_AddRefs(localFile) );
if (NS_SUCCEEDED(rv))
{
rv = NS_NewNativeLocalFile(nativePath, PR_TRUE, getter_AddRefs(localFile));
if (rv == NS_ERROR_FILE_UNRECOGNIZED_PATH) {
// we need to convert this relative path to absolute
directoryService->Get(NS_OS_CURRENT_PROCESS_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(localFile));
if (localFile)
rv = localFile->AppendRelativeNativePath(nativePath);
}
if (NS_SUCCEEDED(rv)) {
mFileSpec = do_QueryInterface(localFile);
}
}
// file:// is a special case where it returns and does not
// go to the standard relative path code below. This is
// so that nsFile(Spec|Path) will work properly. (ie. Passing
// just "file://" to the nsFileSpec && nsFileURL is wrong).
// go to the standard relative path code below.
return;
}
break;

Просмотреть файл

@ -43,8 +43,6 @@
#include "nsInstall.h"
#include "nsFileSpec.h"
#include "nsFileStream.h"
#include "nsDirectoryService.h"
#include "nsDirectoryServiceDefs.h"
#include "nsAppDirectoryServiceDefs.h"
@ -52,6 +50,8 @@
#include "nsNativeCharsetUtils.h"
#include "nspr.h"
#include "plstr.h"
#include "nsNetUtil.h"
#ifdef XP_MAC
#define INSTALL_LOG NS_LITERAL_CSTRING("Install Log")
@ -59,6 +59,9 @@
#define INSTALL_LOG NS_LITERAL_CSTRING("install.log")
#endif
#define _SMALL_TEXT_BUFFER_SIZE 64
#define _MEDIUM_TEXT_BUFFER_SIZE 1024
#define _LARGE_TEXT_BUFFER_SIZE 2048
nsLoggingProgressListener::nsLoggingProgressListener()
: mLogStream(0)
@ -69,10 +72,9 @@ nsLoggingProgressListener::~nsLoggingProgressListener()
{
if (mLogStream)
{
NS_WARN_IF_FALSE(PR_FALSE, "We're being destroyed before script finishes!");
mLogStream->close();
delete mLogStream;
mLogStream = 0;
NS_ERROR("We're being destroyed before script finishes!");
mLogStream->Close();
mLogStream = nsnull;
}
}
@ -82,7 +84,6 @@ NS_IMETHODIMP
nsLoggingProgressListener::OnInstallStart(const PRUnichar *URL)
{
nsCOMPtr<nsIFile> iFile;
nsFileSpec *logFile = nsnull;
nsresult rv = NS_OK;
// Not in stub installer
@ -175,27 +176,22 @@ nsLoggingProgressListener::OnInstallStart(const PRUnichar *URL)
if (NS_FAILED(rv) || !bWritable) return NS_ERROR_FAILURE;
}
rv = Convert_nsIFile_To_nsFileSpec(iFile, &logFile);
rv = NS_NewLocalFileOutputStream(getter_AddRefs(mLogStream), iFile,
PR_WRONLY | PR_CREATE_FILE | PR_APPEND,
0744);
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);
char buffer[_LARGE_TEXT_BUFFER_SIZE];
PRUint32 dummy;
mLogStream->seek(logFile->GetFileSize());
*mLogStream << "-------------------------------------------------------------------------------" << nsEndl;
*mLogStream << NS_ConvertUTF16toUTF8(URL).get() << " -- " << time << nsEndl;
*mLogStream << "-------------------------------------------------------------------------------" << nsEndl;
*mLogStream << nsEndl;
snprintf(buffer, sizeof(buffer), "-------------------------------------------------------------------------------\n%s -- %s\n-------------------------------------------------------------------------------\n\n", NS_ConvertUTF16toUTF8(URL).get(), time);
PL_strfree(time);
if (logFile)
delete logFile;
rv = mLogStream->Write(buffer, strlen(buffer), &dummy);
if (NS_FAILED(rv)) return rv;
return NS_OK;
}
@ -203,42 +199,48 @@ nsLoggingProgressListener::OnInstallStart(const PRUnichar *URL)
NS_IMETHODIMP
nsLoggingProgressListener::OnInstallDone(const PRUnichar *aURL, PRInt32 aStatus)
{
nsresult rv;
PRUint32 dummy;
char buffer[_SMALL_TEXT_BUFFER_SIZE];
if (mLogStream == nsnull) return NS_ERROR_NULL_POINTER;
*mLogStream << nsEndl;
rv = mLogStream->Write("\n", 1, &dummy);
if (NS_FAILED(rv)) return rv;
switch (aStatus)
{
case nsInstall::SUCCESS:
*mLogStream << " Install completed successfully";
snprintf(buffer, sizeof(buffer), " Install completed successfully");
break;
case nsInstall::REBOOT_NEEDED:
*mLogStream << " Install completed successfully, restart required";
snprintf(buffer, sizeof(buffer), " Install completed successfully, restart required");
break;
case nsInstall::INSTALL_CANCELLED:
*mLogStream << " Install cancelled by script";
snprintf(buffer, sizeof(buffer), " Install cancelled by script");
break;
case nsInstall::USER_CANCELLED:
*mLogStream << " Install cancelled by user";
snprintf(buffer, sizeof(buffer), " Install cancelled by user");
break;
default:
*mLogStream << " Install **FAILED** with error " << aStatus;
snprintf(buffer, sizeof(buffer), " Install **FAILED** with error %d", aStatus);
break;
}
rv = mLogStream->Write(buffer, strlen(buffer), &dummy);
if (NS_FAILED(rv)) return rv;
char* time;
GetTime(&time);
*mLogStream << " -- " << time << nsEndl << nsEndl;
snprintf(buffer, sizeof(buffer), " -- %s\n\n", time);
rv = mLogStream->Write(buffer, strlen(buffer), &dummy);
PL_strfree(time);
if (NS_FAILED(rv)) return rv;
mLogStream->close();
delete mLogStream;
mLogStream->Close();
mLogStream = nsnull;
return NS_OK;
@ -249,8 +251,9 @@ nsLoggingProgressListener::OnPackageNameSet(const PRUnichar *URL, const PRUnicha
{
if (mLogStream == nsnull) return NS_ERROR_NULL_POINTER;
// char* time;
// GetTime(&time);
char buffer[_MEDIUM_TEXT_BUFFER_SIZE];
PRUint32 dummy;
nsresult rv;
nsCString name;
nsCString version;
@ -266,16 +269,10 @@ nsLoggingProgressListener::OnPackageNameSet(const PRUnichar *URL, const PRUnicha
for ( unsigned int i=0; i < name.Length(); ++i)
uline.Append('-');
*mLogStream << " " << name.get() << " (version " << version.get() << ")" << nsEndl;
*mLogStream << " " << uline.get() << nsEndl;
*mLogStream << nsEndl;
// *mLogStream << " Starting Installation at " << time << nsEndl;
// *mLogStream << nsEndl;
// PL_strfree(time);
return NS_OK;
snprintf(buffer, sizeof(buffer), " %s (version %s)\n %s\n\n",
name.get(), version.get(), uline.get());
rv = mLogStream->Write(buffer, strlen(buffer), &dummy);
return rv;
}
NS_IMETHODIMP
@ -288,6 +285,9 @@ NS_IMETHODIMP
nsLoggingProgressListener::OnFinalizeProgress(const PRUnichar* aMessage, PRInt32 aItemNum, PRInt32 aTotNum )
{
nsCString messageConverted;
nsresult rv;
char buffer[_MEDIUM_TEXT_BUFFER_SIZE];
PRUint32 dummy;
// this Lossy conversion is safe because the input source came from a
// similar fake-ascii-to-not-really-unicode conversion.
@ -297,8 +297,10 @@ nsLoggingProgressListener::OnFinalizeProgress(const PRUnichar* aMessage, PRInt32
if (mLogStream == nsnull) return NS_ERROR_NULL_POINTER;
*mLogStream << " [" << (aItemNum) << "/" << aTotNum << "]\t" << messageConverted.get() << nsEndl;
return NS_OK;
snprintf(buffer, sizeof(buffer), " [%d/%d]\t%s\n", aItemNum, aTotNum,
messageConverted.get());
rv = mLogStream->Write(buffer, strlen(buffer), &dummy);
return rv;
}
void
@ -315,47 +317,15 @@ NS_IMETHODIMP
nsLoggingProgressListener::OnLogComment(const PRUnichar* aComment)
{
nsCString commentConverted;
nsresult rv;
char buffer[_MEDIUM_TEXT_BUFFER_SIZE];
PRUint32 dummy;
NS_CopyUnicodeToNative(nsDependentString(aComment), commentConverted);
if (mLogStream == nsnull) return NS_ERROR_NULL_POINTER;
*mLogStream << " ** " << commentConverted.get() << nsEndl;
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<nsILocalFileMac> iFileMac;
iFileMac = do_QueryInterface(aInIFile, &rv);
if (NS_SUCCEEDED(rv))
{
iFileMac->GetFSSpec(&fsSpec);
*aOutFileSpec = new nsFileSpec(fsSpec, PR_FALSE);
}
#else
nsCAutoString path;
rv = aInIFile->GetNativePath(path);
if (NS_SUCCEEDED(rv))
{
*aOutFileSpec = new nsFileSpec(path.get(), PR_FALSE);
}
// NOTE: don't release path since nsFileSpec's mPath points to it
#endif
if (!*aOutFileSpec)
rv = NS_ERROR_FAILURE;
snprintf(buffer, sizeof(buffer), " ** %s\n", commentConverted.get());
rv = mLogStream->Write(buffer, strlen(buffer), &dummy);
return rv;
}

Просмотреть файл

@ -1,71 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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 the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
* Samir Gehani <sgehani@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsLoggingProgressNotifier_H__
#define nsLoggingProgressNotifier_H__
#include "nsIXPINotifier.h"
#include "nsFileStream.h"
#include "nsIFile.h"
class nsLoggingProgressListener : public nsIXPIListener
{
public:
nsLoggingProgressListener();
virtual ~nsLoggingProgressListener();
NS_DECL_ISUPPORTS
// nsIXPIListener interfaces
NS_DECL_NSIXPILISTENER
private:
void GetTime(char** aString);
nsOutputFileStream *mLogStream;
};
nsresult Convert_nsIFile_To_nsFileSpec(nsIFile *aInIFile,
nsFileSpec **aOutFileSpec);
#endif

Просмотреть файл

@ -38,6 +38,7 @@
* ***** END LICENSE BLOCK ***** */
#include "prprf.h"
#include "nsCRT.h"
#include "nsRegisterItem.h"
#include "nsInstallResources.h"
#include "nsNetUtil.h"

Просмотреть файл

@ -54,6 +54,7 @@
#include "nsNetUtil.h"
#include "nspr.h"
#include "plstr.h"
#include "jsapi.h"
#include "nsIEventQueueService.h"

Просмотреть файл

@ -38,6 +38,7 @@
* ***** END LICENSE BLOCK ***** */
#include "nscore.h"
#include "plstr.h"
#include "nsXPITriggerInfo.h"
#include "nsNetUtil.h"
#include "nsDebug.h"

Просмотреть файл

@ -44,7 +44,6 @@
#include "nsVoidArray.h"
#include "nsCOMPtr.h"
#include "nsISupportsUtils.h"
#include "nsIFileSpec.h"
#include "nsILocalFile.h"
#include "nsIOutputStream.h"
#include "jsapi.h"