1999-03-23 22:55:00 +00:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
1999-02-05 00:15:30 +00:00
|
|
|
/*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
1999-02-05 00:15:30 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* 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.
|
1999-02-05 00:15:30 +00:00
|
|
|
*
|
1999-03-23 22:55:00 +00:00
|
|
|
* The Original Code is Mozilla Communicator client code,
|
|
|
|
* released March 31, 1998.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
1999-11-06 03:43:54 +00:00
|
|
|
* Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
1999-03-23 22:55:00 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* Contributor(s):
|
1999-03-23 22:55:00 +00:00
|
|
|
* Daniel Veditz <dveditz@netscape.com>
|
|
|
|
* Douglas Turner <dougt@netscape.com>
|
1999-02-05 00:15:30 +00:00
|
|
|
*/
|
|
|
|
|
1999-12-08 05:09:17 +00:00
|
|
|
#include "prprf.h"
|
1999-03-23 22:55:00 +00:00
|
|
|
#include "nsInstallFile.h"
|
1999-02-05 22:27:08 +00:00
|
|
|
#include "nsFileSpec.h"
|
1999-02-05 00:15:30 +00:00
|
|
|
#include "VerReg.h"
|
1999-03-23 22:55:00 +00:00
|
|
|
#include "ScheduledTasks.h"
|
1999-02-22 23:10:23 +00:00
|
|
|
#include "nsInstall.h"
|
1999-05-27 21:02:57 +00:00
|
|
|
#include "nsIDOMInstallVersion.h"
|
1999-05-07 00:05:54 +00:00
|
|
|
#include "nsInstallResources.h"
|
2000-04-26 05:04:21 +00:00
|
|
|
#include "nsInstallLogComment.h"
|
1999-02-05 00:15:30 +00:00
|
|
|
|
|
|
|
/* Public Methods */
|
|
|
|
|
|
|
|
/* Constructor
|
|
|
|
inInstall - softUpdate object we belong to
|
|
|
|
inComponentName - full path of the registry component
|
|
|
|
inVInfo - full version info
|
|
|
|
inJarLocation - location inside the JAR file
|
|
|
|
inFinalFileSpec - final location on disk
|
|
|
|
*/
|
1999-05-27 21:02:57 +00:00
|
|
|
|
1999-11-21 06:03:23 +00:00
|
|
|
MOZ_DECL_CTOR_COUNTER(nsInstallFile);
|
1999-05-27 21:02:57 +00:00
|
|
|
|
1999-02-22 23:10:23 +00:00
|
|
|
nsInstallFile::nsInstallFile(nsInstall* inInstall,
|
1999-03-09 00:50:23 +00:00
|
|
|
const nsString& inComponentName,
|
1999-05-27 21:02:57 +00:00
|
|
|
const nsString& inVInfo,
|
1999-02-05 00:15:30 +00:00
|
|
|
const nsString& inJarLocation,
|
1999-11-21 06:03:23 +00:00
|
|
|
nsInstallFolder *folderSpec,
|
1999-02-05 00:15:30 +00:00
|
|
|
const nsString& inPartialPath,
|
2000-03-22 21:51:26 +00:00
|
|
|
PRInt32 mode,
|
1999-02-05 22:27:08 +00:00
|
|
|
PRInt32 *error)
|
1999-12-08 05:09:17 +00:00
|
|
|
: nsInstallObject(inInstall),
|
|
|
|
mVersionInfo(nsnull),
|
|
|
|
mJarLocation(nsnull),
|
|
|
|
mExtractedFile(nsnull),
|
|
|
|
mFinalFile(nsnull),
|
|
|
|
mVersionRegistryName(nsnull),
|
|
|
|
mReplaceFile(PR_FALSE),
|
|
|
|
mChildFile(PR_TRUE),
|
|
|
|
mUpgradeFile(PR_FALSE),
|
2000-03-24 22:11:55 +00:00
|
|
|
mSkipInstall(PR_FALSE),
|
|
|
|
mMode(mode)
|
1999-02-05 00:15:30 +00:00
|
|
|
{
|
1999-11-21 06:03:23 +00:00
|
|
|
MOZ_COUNT_CTOR(nsInstallFile);
|
|
|
|
|
2000-04-21 18:58:41 +00:00
|
|
|
PRBool flagExists, flagIsFile;
|
2000-04-26 05:04:21 +00:00
|
|
|
mFolderCreateCount = 0;
|
2000-04-21 18:58:41 +00:00
|
|
|
|
1999-11-21 06:03:23 +00:00
|
|
|
if ((folderSpec == nsnull) || (inInstall == NULL))
|
1999-02-05 00:15:30 +00:00
|
|
|
{
|
1999-03-01 21:35:13 +00:00
|
|
|
*error = nsInstall::INVALID_ARGUMENTS;
|
1999-02-05 00:15:30 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-05-27 21:02:57 +00:00
|
|
|
|
1999-12-08 05:09:17 +00:00
|
|
|
*error = nsInstall::SUCCESS;
|
|
|
|
|
1999-05-27 21:02:57 +00:00
|
|
|
/* Check for existence of the newer version */
|
2000-02-20 03:12:59 +00:00
|
|
|
#if 0 // XXX need to re-implement force mode in the opposite sense
|
2000-03-22 21:51:26 +00:00
|
|
|
|
1999-05-27 21:02:57 +00:00
|
|
|
char* qualifiedRegNameString = inComponentName.ToNewCString();
|
|
|
|
|
1999-12-08 05:09:17 +00:00
|
|
|
// --------------------------------------------------------------------
|
|
|
|
// we always install if forceInstall is true, or the new file's
|
|
|
|
// version is null, or the file doesn't previously exist.
|
|
|
|
//
|
|
|
|
// IFF it's not force, AND the new file has a version, AND it's been
|
|
|
|
// previously installed, THEN we have to do the version comparing foo.
|
|
|
|
// --------------------------------------------------------------------
|
2000-03-22 21:51:26 +00:00
|
|
|
if ( !(mode & INSTALL_NO_COMPARE ) && (inVInfo != "") &&
|
|
|
|
( VR_ValidateComponent( qualifiedRegNameString ) == 0 ) )
|
1999-05-27 21:02:57 +00:00
|
|
|
{
|
|
|
|
nsInstallVersion *newVersion = new nsInstallVersion();
|
1999-07-18 20:56:12 +00:00
|
|
|
|
|
|
|
if (newVersion == nsnull)
|
|
|
|
{
|
1999-09-22 04:43:03 +00:00
|
|
|
Recycle(qualifiedRegNameString);
|
1999-07-18 20:56:12 +00:00
|
|
|
*error = nsInstall::OUT_OF_MEMORY;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-05-27 21:02:57 +00:00
|
|
|
newVersion->Init(inVInfo);
|
|
|
|
|
|
|
|
VERSION versionStruct;
|
|
|
|
|
|
|
|
VR_GetVersion( qualifiedRegNameString, &versionStruct );
|
|
|
|
|
|
|
|
nsInstallVersion* oldVersion = new nsInstallVersion();
|
1999-07-18 20:56:12 +00:00
|
|
|
|
2000-01-28 23:22:58 +00:00
|
|
|
if (oldVersion == nsnull)
|
1999-07-18 20:56:12 +00:00
|
|
|
{
|
1999-09-22 04:43:03 +00:00
|
|
|
Recycle(qualifiedRegNameString);
|
1999-07-18 20:56:12 +00:00
|
|
|
delete oldVersion;
|
|
|
|
*error = nsInstall::OUT_OF_MEMORY;
|
|
|
|
return;
|
|
|
|
}
|
1999-05-27 21:02:57 +00:00
|
|
|
|
|
|
|
oldVersion->Init(versionStruct.major,
|
|
|
|
versionStruct.minor,
|
|
|
|
versionStruct.release,
|
|
|
|
versionStruct.build);
|
|
|
|
|
|
|
|
PRInt32 areTheyEqual;
|
|
|
|
newVersion->CompareTo(oldVersion, &areTheyEqual);
|
|
|
|
|
|
|
|
delete oldVersion;
|
|
|
|
delete newVersion;
|
|
|
|
|
1999-12-08 05:09:17 +00:00
|
|
|
if ( areTheyEqual < 0 )
|
1999-05-27 21:02:57 +00:00
|
|
|
{
|
1999-12-08 05:09:17 +00:00
|
|
|
// the file to be installed is OLDER than what is on disk.
|
|
|
|
// Don't install it.
|
|
|
|
mSkipInstall = PR_TRUE;
|
1999-05-27 21:02:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-22 04:43:03 +00:00
|
|
|
Recycle(qualifiedRegNameString);
|
2000-02-20 03:12:59 +00:00
|
|
|
#endif
|
1999-05-27 21:02:57 +00:00
|
|
|
|
2000-04-21 18:58:41 +00:00
|
|
|
nsCOMPtr<nsIFile> tmp = folderSpec->GetFileSpec();
|
1999-11-21 06:03:23 +00:00
|
|
|
if (!tmp)
|
|
|
|
{
|
|
|
|
*error = nsInstall::INVALID_ARGUMENTS;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-04-21 18:58:41 +00:00
|
|
|
tmp->Clone(getter_AddRefs(mFinalFile));
|
1999-07-18 20:56:12 +00:00
|
|
|
if (mFinalFile == nsnull)
|
|
|
|
{
|
|
|
|
*error = nsInstall::OUT_OF_MEMORY;
|
|
|
|
return;
|
|
|
|
}
|
1999-11-21 06:03:23 +00:00
|
|
|
|
2000-04-21 18:58:41 +00:00
|
|
|
mFinalFile->Exists(&flagExists);
|
|
|
|
if (flagExists)
|
1999-07-03 19:00:45 +00:00
|
|
|
{
|
|
|
|
// is there a file with the same name as the proposed folder?
|
2000-04-21 18:58:41 +00:00
|
|
|
mFinalFile->IsFile(&flagIsFile);
|
|
|
|
if ( flagIsFile)
|
1999-07-03 19:00:45 +00:00
|
|
|
{
|
|
|
|
*error = nsInstall::FILENAME_ALREADY_USED;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// else this directory already exists, so do nothing
|
|
|
|
}
|
|
|
|
|
2000-04-21 18:58:41 +00:00
|
|
|
//Need to parse the inPartialPath to remove any separators
|
|
|
|
PRBool finished = PR_FALSE;
|
|
|
|
PRUint32 offset = 0;
|
|
|
|
PRInt32 location = 0, pass = 0;
|
|
|
|
nsString subString;
|
|
|
|
|
|
|
|
//nsString tempPartialPath(inPartialPath);
|
|
|
|
|
|
|
|
while (!finished)
|
|
|
|
{
|
|
|
|
location = inPartialPath.FindChar('/',PR_FALSE, offset);
|
|
|
|
if ((location < 0) && (pass == 0)) //no separators were found
|
|
|
|
{
|
2000-04-24 22:23:44 +00:00
|
|
|
nsAutoCString tempPartialPath(inPartialPath);
|
|
|
|
mFinalFile->Append(tempPartialPath);
|
2000-04-21 18:58:41 +00:00
|
|
|
finished = PR_TRUE;
|
|
|
|
}
|
|
|
|
else if ((location < 0) && (pass > 0) && (offset < inPartialPath.mLength)) //last occurance
|
|
|
|
{
|
2000-04-23 02:09:17 +00:00
|
|
|
nsresult rv = inPartialPath.Mid(subString, offset, inPartialPath.mLength-offset);
|
2000-04-24 22:23:44 +00:00
|
|
|
nsAutoCString tempSubString(subString);
|
|
|
|
mFinalFile->Append(tempSubString);
|
2000-04-21 18:58:41 +00:00
|
|
|
finished = PR_TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-04-23 02:09:17 +00:00
|
|
|
nsresult rv = inPartialPath.Mid(subString, offset, location-offset);
|
2000-04-24 22:23:44 +00:00
|
|
|
nsAutoCString tempSubString(subString);
|
|
|
|
mFinalFile->Append(tempSubString);
|
2000-04-21 18:58:41 +00:00
|
|
|
offset = location + 1;
|
|
|
|
pass++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//{
|
|
|
|
// nsresult rv = mFinalFile->Append(inPartialPath.ToNewCString());
|
|
|
|
// if (rv != NS_OK)
|
|
|
|
// {
|
|
|
|
// *error = nsInstall::ILLEGAL_RELATIVE_PATH;
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
//}
|
1999-05-27 21:02:57 +00:00
|
|
|
|
2000-04-21 18:58:41 +00:00
|
|
|
mFinalFile->Exists(&mReplaceFile);
|
|
|
|
mVersionRegistryName = new nsString(inComponentName);
|
|
|
|
mJarLocation = new nsString(inJarLocation);
|
1999-05-27 21:02:57 +00:00
|
|
|
mVersionInfo = new nsString(inVInfo);
|
1999-07-18 20:56:12 +00:00
|
|
|
|
|
|
|
if (mVersionRegistryName == nsnull ||
|
|
|
|
mJarLocation == nsnull ||
|
|
|
|
mVersionInfo == nsnull )
|
|
|
|
{
|
|
|
|
*error = nsInstall::OUT_OF_MEMORY;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-02-05 00:15:30 +00:00
|
|
|
nsString regPackageName;
|
|
|
|
mInstall->GetRegPackageName(regPackageName);
|
|
|
|
|
|
|
|
// determine Child status
|
2000-03-26 11:02:30 +00:00
|
|
|
if ( regPackageName.IsEmpty() )
|
1999-02-05 00:15:30 +00:00
|
|
|
{
|
|
|
|
// in the "current communicator package" absolute pathnames (start
|
|
|
|
// with slash) indicate shared files -- all others are children
|
|
|
|
mChildFile = ( mVersionRegistryName->CharAt(0) != '/' );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-04-18 05:38:58 +00:00
|
|
|
mChildFile = mVersionRegistryName->EqualsWithConversion( regPackageName,
|
|
|
|
PR_FALSE,
|
|
|
|
regPackageName.Length() );
|
1999-02-05 00:15:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsInstallFile::~nsInstallFile()
|
|
|
|
{
|
1999-03-02 20:25:42 +00:00
|
|
|
if (mVersionRegistryName)
|
|
|
|
delete mVersionRegistryName;
|
|
|
|
|
|
|
|
if (mJarLocation)
|
|
|
|
delete mJarLocation;
|
|
|
|
|
|
|
|
if (mVersionInfo)
|
2000-04-21 18:58:41 +00:00
|
|
|
delete mVersionInfo;
|
|
|
|
|
|
|
|
//if(mFinalFile)
|
|
|
|
// mFinalFile = nsnull;
|
|
|
|
|
|
|
|
//if(mExtractedFile)
|
|
|
|
// mExtractedFile = nsnull;
|
1999-11-21 06:03:23 +00:00
|
|
|
|
|
|
|
MOZ_COUNT_DTOR(nsInstallFile);
|
1999-02-05 00:15:30 +00:00
|
|
|
}
|
|
|
|
|
2000-04-26 05:04:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void nsInstallFile::CreateAllFolders(nsInstall *inInstall, nsIFile *inFolderPath, PRInt32 *error)
|
|
|
|
{
|
|
|
|
/* the nsFileSpecMac.cpp operator += requires "this" (the nsFileSpec)
|
|
|
|
* to be an existing dir
|
|
|
|
*/
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> nsfsFolderPath;
|
|
|
|
nsString nsStrFolder;
|
|
|
|
PRBool flagExists;
|
|
|
|
int result = 0;
|
|
|
|
nsInstallLogComment *ilc = nsnull;
|
|
|
|
|
|
|
|
inFolderPath->Exists(&flagExists);
|
|
|
|
if(!flagExists)
|
|
|
|
{
|
|
|
|
char *szPath = nsnull;
|
|
|
|
|
|
|
|
inFolderPath->GetParent(getter_AddRefs(nsfsFolderPath));
|
|
|
|
CreateAllFolders(inInstall, nsfsFolderPath, error);
|
|
|
|
|
|
|
|
inFolderPath->Create(nsIFile::DIRECTORY_TYPE, 0755); //nsIFileXXX: What kind of permissions are required here?
|
|
|
|
++mFolderCreateCount;
|
|
|
|
|
|
|
|
inFolderPath->GetPath(&szPath);
|
2000-04-27 21:09:10 +00:00
|
|
|
nsStrFolder.AssignWithConversion(szPath);
|
2000-04-26 05:04:21 +00:00
|
|
|
nsAllocator::Free(szPath);
|
2000-04-27 21:09:10 +00:00
|
|
|
ilc = new nsInstallLogComment(inInstall, NS_ConvertASCIItoUCS2("CreateFolder"), nsStrFolder, error);
|
2000-04-26 05:04:21 +00:00
|
|
|
if(ilc == nsnull)
|
|
|
|
*error = nsInstall::OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
if(*error == nsInstall::SUCCESS)
|
|
|
|
*error = mInstall->ScheduleForInstall(ilc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef XXX_SSU
|
|
|
|
void nsInstallFile::RemoveAllFolders()
|
|
|
|
{
|
|
|
|
/* the nsFileSpecMac.cpp operator += requires "this" (the nsFileSpec)
|
|
|
|
* to be an existing dir
|
|
|
|
*/
|
|
|
|
|
|
|
|
PRUint32 i;
|
|
|
|
nsFileSpec nsfsFolder;
|
|
|
|
nsFileSpec nsfsParentFolder;
|
|
|
|
nsString nsStrFolder;
|
|
|
|
|
|
|
|
if(mFinalFile != nsnull)
|
|
|
|
{
|
|
|
|
mFinalFile->GetParent(nsfsFolder);
|
|
|
|
for(i = 0; i < mFolderCreateCount; i++)
|
|
|
|
{
|
|
|
|
nsfsFolder.Delete(PR_FALSE);
|
|
|
|
nsfsFolder.GetParent(nsfsParentFolder);
|
|
|
|
nsfsFolder = nsfsParentFolder;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-02-05 00:15:30 +00:00
|
|
|
/* Prepare
|
1999-03-09 00:50:23 +00:00
|
|
|
* Extracts file out of the JAR archive
|
1999-02-05 00:15:30 +00:00
|
|
|
*/
|
1999-02-05 22:27:08 +00:00
|
|
|
PRInt32 nsInstallFile::Prepare()
|
1999-02-05 00:15:30 +00:00
|
|
|
{
|
2000-04-26 05:04:21 +00:00
|
|
|
PRInt32 error = nsInstall::SUCCESS;
|
|
|
|
|
1999-12-08 05:09:17 +00:00
|
|
|
if (mSkipInstall)
|
|
|
|
return nsInstall::SUCCESS;
|
|
|
|
|
2000-01-28 23:22:58 +00:00
|
|
|
if (mInstall == nsnull || mFinalFile == nsnull || mJarLocation == nsnull )
|
|
|
|
return nsInstall::INVALID_ARGUMENTS;
|
|
|
|
|
2000-04-26 05:04:21 +00:00
|
|
|
if (mReplaceFile == PR_FALSE)
|
|
|
|
{
|
|
|
|
/* although it appears that we are creating the dir _again_ it is necessary
|
|
|
|
* when inPartialPath has arbitrary levels of nested dirs before the leaf
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIFile> parent;
|
|
|
|
mFinalFile->GetParent(getter_AddRefs(parent));
|
|
|
|
CreateAllFolders(mInstall, parent, &error);
|
|
|
|
if(nsInstall::SUCCESS != error)
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2000-04-21 18:58:41 +00:00
|
|
|
return mInstall->ExtractFileFromJar(*mJarLocation, mFinalFile, getter_AddRefs(mExtractedFile));
|
1999-02-05 00:15:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Complete
|
|
|
|
* Completes the install:
|
|
|
|
* - move the downloaded file to the final location
|
|
|
|
* - updates the registry
|
|
|
|
*/
|
1999-02-05 22:27:08 +00:00
|
|
|
PRInt32 nsInstallFile::Complete()
|
1999-02-05 00:15:30 +00:00
|
|
|
{
|
1999-02-22 23:10:23 +00:00
|
|
|
PRInt32 err;
|
1999-02-05 00:15:30 +00:00
|
|
|
|
1999-03-09 00:50:23 +00:00
|
|
|
if (mInstall == nsnull || mVersionRegistryName == nsnull || mFinalFile == nsnull )
|
1999-02-05 00:15:30 +00:00
|
|
|
{
|
1999-03-01 21:35:13 +00:00
|
|
|
return nsInstall::INVALID_ARGUMENTS;
|
1999-02-05 00:15:30 +00:00
|
|
|
}
|
1999-12-08 05:09:17 +00:00
|
|
|
|
|
|
|
if (mSkipInstall)
|
|
|
|
return nsInstall::SUCCESS;
|
1999-02-05 00:15:30 +00:00
|
|
|
|
1999-03-09 00:50:23 +00:00
|
|
|
err = CompleteFileMove();
|
1999-02-05 00:15:30 +00:00
|
|
|
|
1999-03-01 21:35:13 +00:00
|
|
|
if ( 0 == err || nsInstall::REBOOT_NEEDED == err )
|
1999-02-05 00:15:30 +00:00
|
|
|
{
|
2000-02-20 03:12:59 +00:00
|
|
|
// XXX Don't register individual files for now -- crucial performance
|
|
|
|
// speed up on the Mac, and we'll switch uninstall schemes after beta
|
|
|
|
|
|
|
|
// RegisterInVersionRegistry();
|
1999-02-05 00:15:30 +00:00
|
|
|
}
|
1999-02-05 22:27:08 +00:00
|
|
|
|
1999-03-09 00:50:23 +00:00
|
|
|
return err;
|
|
|
|
|
1999-02-05 00:15:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsInstallFile::Abort()
|
|
|
|
{
|
1999-12-08 05:09:17 +00:00
|
|
|
if (mExtractedFile != nsnull)
|
|
|
|
mExtractedFile->Delete(PR_FALSE);
|
1999-02-05 00:15:30 +00:00
|
|
|
}
|
|
|
|
|
1999-12-08 05:09:17 +00:00
|
|
|
#define RESBUFSIZE 1024
|
1999-08-25 01:26:11 +00:00
|
|
|
char* nsInstallFile::toString()
|
1999-02-05 00:15:30 +00:00
|
|
|
{
|
1999-12-08 05:09:17 +00:00
|
|
|
char* buffer = new char[RESBUFSIZE];
|
|
|
|
char* rsrcVal = nsnull;
|
2000-04-21 18:58:41 +00:00
|
|
|
char* fname = nsnull;
|
1999-07-18 20:56:12 +00:00
|
|
|
|
1999-09-21 08:46:10 +00:00
|
|
|
if (buffer == nsnull || !mInstall)
|
|
|
|
return nsnull;
|
1999-12-08 05:09:17 +00:00
|
|
|
else
|
|
|
|
buffer[0] = '\0';
|
1999-09-21 08:46:10 +00:00
|
|
|
|
1999-12-08 05:09:17 +00:00
|
|
|
if (mReplaceFile)
|
1999-05-07 00:05:54 +00:00
|
|
|
{
|
2000-04-18 05:38:58 +00:00
|
|
|
rsrcVal = mInstall->GetResourcedString(NS_ConvertASCIItoUCS2("ReplaceFile"));
|
1999-05-07 00:05:54 +00:00
|
|
|
}
|
1999-12-08 05:09:17 +00:00
|
|
|
else if (mSkipInstall)
|
1999-05-07 00:05:54 +00:00
|
|
|
{
|
2000-04-18 05:38:58 +00:00
|
|
|
rsrcVal = mInstall->GetResourcedString(NS_ConvertASCIItoUCS2("SkipFile"));
|
1999-05-07 00:05:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-04-18 05:38:58 +00:00
|
|
|
rsrcVal = mInstall->GetResourcedString(NS_ConvertASCIItoUCS2("InstallFile"));
|
1999-12-08 05:09:17 +00:00
|
|
|
}
|
1999-09-21 08:46:10 +00:00
|
|
|
|
1999-12-08 05:09:17 +00:00
|
|
|
if (rsrcVal)
|
|
|
|
{
|
|
|
|
if (mFinalFile)
|
2000-04-21 18:58:41 +00:00
|
|
|
mFinalFile->GetPath(&fname);
|
1999-12-08 05:09:17 +00:00
|
|
|
|
|
|
|
PR_snprintf( buffer, RESBUFSIZE, rsrcVal, fname );
|
|
|
|
|
|
|
|
Recycle(rsrcVal);
|
1999-05-07 00:05:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return buffer;
|
1999-02-05 00:15:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-03-09 00:50:23 +00:00
|
|
|
PRInt32 nsInstallFile::CompleteFileMove()
|
1999-02-05 00:15:30 +00:00
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
|
1999-12-08 05:09:17 +00:00
|
|
|
if (mExtractedFile == nsnull)
|
1999-02-05 00:15:30 +00:00
|
|
|
{
|
1999-12-08 05:09:17 +00:00
|
|
|
return nsInstall::UNEXPECTED_ERROR;
|
1999-02-05 00:15:30 +00:00
|
|
|
}
|
1999-03-09 00:50:23 +00:00
|
|
|
|
2000-04-21 18:58:41 +00:00
|
|
|
if ( mExtractedFile == mFinalFile )
|
1999-02-05 00:15:30 +00:00
|
|
|
{
|
|
|
|
/* No need to rename, they are the same */
|
1999-12-08 05:09:17 +00:00
|
|
|
result = nsInstall::SUCCESS;
|
1999-02-05 00:15:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-04-21 18:58:41 +00:00
|
|
|
result = ReplaceFileNowOrSchedule(mExtractedFile, mFinalFile );
|
1999-02-05 00:15:30 +00:00
|
|
|
}
|
|
|
|
|
1999-03-09 00:50:23 +00:00
|
|
|
return result;
|
|
|
|
}
|
1999-02-05 00:15:30 +00:00
|
|
|
|
1999-03-09 00:50:23 +00:00
|
|
|
PRInt32
|
|
|
|
nsInstallFile::RegisterInVersionRegistry()
|
|
|
|
{
|
|
|
|
int refCount;
|
|
|
|
nsString regPackageName;
|
|
|
|
mInstall->GetRegPackageName(regPackageName);
|
|
|
|
|
|
|
|
|
|
|
|
// Register file and log for Uninstall
|
|
|
|
|
|
|
|
if (!mChildFile)
|
1999-02-05 00:15:30 +00:00
|
|
|
{
|
1999-03-09 00:50:23 +00:00
|
|
|
int found;
|
2000-03-26 11:02:30 +00:00
|
|
|
if (!regPackageName.IsEmpty())
|
1999-02-05 00:15:30 +00:00
|
|
|
{
|
1999-05-07 00:05:54 +00:00
|
|
|
found = VR_UninstallFileExistsInList( (char*)(const char*)nsAutoCString(regPackageName) ,
|
|
|
|
(char*)(const char*)nsAutoCString(*mVersionRegistryName));
|
1999-02-05 00:15:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-05-07 00:05:54 +00:00
|
|
|
found = VR_UninstallFileExistsInList( "", (char*)(const char*)nsAutoCString(*mVersionRegistryName) );
|
1999-02-05 00:15:30 +00:00
|
|
|
}
|
1999-03-09 00:50:23 +00:00
|
|
|
|
|
|
|
if (found != REGERR_OK)
|
|
|
|
mUpgradeFile = PR_FALSE;
|
|
|
|
else
|
|
|
|
mUpgradeFile = PR_TRUE;
|
|
|
|
}
|
1999-05-07 00:05:54 +00:00
|
|
|
else if (REGERR_OK == VR_InRegistry( (char*)(const char*)nsAutoCString(*mVersionRegistryName)))
|
1999-03-09 00:50:23 +00:00
|
|
|
{
|
|
|
|
mUpgradeFile = PR_TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mUpgradeFile = PR_FALSE;
|
1999-02-05 00:15:30 +00:00
|
|
|
}
|
|
|
|
|
1999-05-07 00:05:54 +00:00
|
|
|
if ( REGERR_OK != VR_GetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), &refCount ))
|
1999-03-09 00:50:23 +00:00
|
|
|
{
|
|
|
|
refCount = 0;
|
|
|
|
}
|
1999-02-05 00:15:30 +00:00
|
|
|
|
2000-04-21 18:58:41 +00:00
|
|
|
char* temp;
|
|
|
|
mFinalFile->GetPath(&temp);
|
1999-05-07 00:05:54 +00:00
|
|
|
VR_Install( (char*)(const char*)nsAutoCString(*mVersionRegistryName),
|
2000-04-21 18:58:41 +00:00
|
|
|
(char*)(const char*)temp, // DO NOT CHANGE THIS.
|
1999-05-27 21:02:57 +00:00
|
|
|
(char*)(const char*)nsAutoCString(*mVersionInfo),
|
1999-05-07 00:05:54 +00:00
|
|
|
PR_FALSE );
|
|
|
|
|
1999-05-27 21:02:57 +00:00
|
|
|
if (mUpgradeFile)
|
|
|
|
{
|
|
|
|
if (refCount == 0)
|
|
|
|
VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), 1 );
|
|
|
|
else
|
|
|
|
VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), refCount ); //FIX?? what should the ref count be/
|
|
|
|
}
|
|
|
|
else
|
1999-03-09 00:50:23 +00:00
|
|
|
{
|
|
|
|
if (refCount != 0)
|
|
|
|
{
|
1999-05-07 00:05:54 +00:00
|
|
|
VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), refCount + 1 );
|
1999-03-09 00:50:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-05-27 21:02:57 +00:00
|
|
|
if (mReplaceFile)
|
1999-05-07 00:05:54 +00:00
|
|
|
VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), 2 );
|
1999-03-09 00:50:23 +00:00
|
|
|
else
|
1999-05-07 00:05:54 +00:00
|
|
|
VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), 1 );
|
1999-03-09 00:50:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !mChildFile && !mUpgradeFile )
|
|
|
|
{
|
2000-03-26 11:02:30 +00:00
|
|
|
if (!regPackageName.IsEmpty())
|
1999-05-07 00:05:54 +00:00
|
|
|
{
|
|
|
|
VR_UninstallAddFileToList( (char*)(const char*)nsAutoCString(regPackageName),
|
|
|
|
(char*)(const char*)nsAutoCString(*mVersionRegistryName));
|
1999-03-09 00:50:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-05-07 00:05:54 +00:00
|
|
|
VR_UninstallAddFileToList( "", (char*)(const char*)nsAutoCString(*mVersionRegistryName) );
|
1999-03-09 00:50:23 +00:00
|
|
|
}
|
|
|
|
}
|
1999-02-05 00:15:30 +00:00
|
|
|
|
1999-03-09 00:50:23 +00:00
|
|
|
return nsInstall::SUCCESS;
|
1999-02-05 00:15:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* CanUninstall
|
|
|
|
* InstallFile() installs files which can be uninstalled,
|
|
|
|
* hence this function returns true.
|
|
|
|
*/
|
|
|
|
PRBool
|
|
|
|
nsInstallFile::CanUninstall()
|
|
|
|
{
|
1999-09-04 20:25:38 +00:00
|
|
|
return PR_TRUE;
|
1999-02-05 00:15:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* RegisterPackageNode
|
|
|
|
* InstallFile() installs files which need to be registered,
|
|
|
|
* hence this function returns true.
|
|
|
|
*/
|
|
|
|
PRBool
|
|
|
|
nsInstallFile::RegisterPackageNode()
|
|
|
|
{
|
1999-09-04 20:25:38 +00:00
|
|
|
return PR_TRUE;
|
1999-02-05 00:15:30 +00:00
|
|
|
}
|