fixing bug #55253 - Browser cannot launch after update.html from Win 9x only. sr=brendan,warren moa=dveditz r=dveditz,sgehani. Checking in only to the trunk for QA testing. Will check in to the BRANCH after QA certifies OK.

This commit is contained in:
ssu%netscape.com 2000-10-14 23:37:16 +00:00
parent 8d51f86ad3
commit 68638e15e2
3 changed files with 107 additions and 0 deletions

View File

@ -1973,6 +1973,63 @@ nsInstall::FileOpFileRename(nsInstallFolder& aSrc, nsString& aTarget, PRInt32* a
return NS_OK;
}
#ifdef _WINDOWS
#include <winbase.h>
#endif
PRInt32
nsInstall::FileOpFileWindowsGetShortName(nsInstallFolder& aTarget, nsString& aShortPathName)
{
#ifdef _WINDOWS
PRInt32 err;
PRBool flagExists;
nsString tmpNsString;
nsXPIDLCString nativeTargetPath;
char nativeShortPathName[MAX_PATH];
nsCOMPtr<nsIFile> localTarget(aTarget.GetFileSpec());
if(localTarget == nsnull)
return NS_OK;
localTarget->Exists(&flagExists);
if(flagExists)
{
memset(nativeShortPathName, 0, MAX_PATH);
localTarget->GetPath(getter_Copies(nativeTargetPath));
err = GetShortPathName(nativeTargetPath, nativeShortPathName, MAX_PATH);
if((err > 0) && (*nativeShortPathName == '\0'))
{
// NativeShortPathName buffer not big enough.
// Reallocate and try again.
// err will have the required size.
char *nativeShortPathNameTmp = new char[err + 1];
if(nativeShortPathNameTmp == nsnull)
return NS_OK;
err = GetShortPathName(nativeTargetPath, nativeShortPathNameTmp, err + 1);
// Is it safe to assume that the second time around the buffer is big enough
// and not to worry about it unless it's a different problem?
// if err is 0, it's not a buffer size problem. It's something else unexpected.
if(err != 0)
aShortPathName.AssignWithConversion(nativeShortPathNameTmp);
if(nativeShortPathNameTmp)
delete [] nativeShortPathNameTmp;
}
else if(err != 0)
// if err is 0, it's not a buffer size problem. It's something else unexpected.
aShortPathName.AssignWithConversion(nativeShortPathName);
}
#endif
return NS_OK;
}
PRInt32
nsInstall::FileOpFileWindowsShortcut(nsIFile* aTarget, nsIFile* aShortcutPath, nsString& aDescription, nsIFile* aWorkingPath, nsString& aParams, nsIFile* aIcon, PRInt32 aIconId, PRInt32* aReturn)
{

View File

@ -252,6 +252,7 @@ class nsInstall
PRInt32 FileOpFileModDateChanged(nsInstallFolder& aTarget, double aOldStamp, PRBool* aReturn);
PRInt32 FileOpFileMove(nsInstallFolder& aSrc, nsInstallFolder& aTarget, PRInt32* aReturn);
PRInt32 FileOpFileRename(nsInstallFolder& aSrc, nsString& aTarget, PRInt32* aReturn);
PRInt32 FileOpFileWindowsGetShortName(nsInstallFolder& aTarget, nsString& aShortPathName);
PRInt32 FileOpFileWindowsShortcut(nsIFile* aTarget, nsIFile* aShortcutPath, nsString& aDescription, nsIFile* aWorkingPath, nsString& aParams, nsIFile* aIcon, PRInt32 aIconId, PRInt32* aReturn);
PRInt32 FileOpFileMacAlias(nsIFile *aSourceFile, nsIFile *aAliasFile, PRInt32* aReturn);
PRInt32 FileOpFileUnixLink(nsInstallFolder& aTarget, PRInt32 aFlags, PRInt32* aReturn);

View File

@ -991,6 +991,54 @@ InstallFileOpFileRename(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, j
return JS_TRUE;
}
//
// Native method FileWindowsGetShortName
//
JSBool PR_CALLBACK
InstallFileOpFileWindowsGetShortName(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsAutoString shortPathName;
nsInstall* nativeThis = (nsInstall*)JS_GetPrivate(cx, obj);
JSObject *jsObj;
nsInstallFolder *longPathName;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if(nsnull == nativeThis)
{
return JS_TRUE;
}
// public String windowsGetShortName (File NativeFolderPath);
if ( argc == 0 || argv[0] == JSVAL_NULL || !JSVAL_IS_OBJECT(argv[0])) //argv[0] MUST be a jsval
{
// error, return NULL
return JS_TRUE;
}
jsObj = JSVAL_TO_OBJECT(argv[0]);
if (!JS_InstanceOf(cx, jsObj, &FileSpecObjectClass, nsnull))
{
// error, return NULL
return JS_TRUE;
}
longPathName = (nsInstallFolder*)JS_GetPrivate(cx, jsObj);
if(!longPathName || NS_OK != nativeThis->FileOpFileWindowsGetShortName(*longPathName, shortPathName))
{
return JS_TRUE;
}
if(shortPathName.Length() != 0)
*rval = STRING_TO_JSVAL(JS_NewUCStringCopyN(cx, NS_STATIC_CAST(const jschar*, shortPathName.GetUnicode()), shortPathName.Length()));
return JS_TRUE;
}
//
// Native method FileWindowsShortcut
//
@ -1362,6 +1410,7 @@ static JSFunctionSpec FileOpMethods[] =
{"modDateChanged", InstallFileOpFileModDateChanged, 2},
{"move", InstallFileOpFileMove, 2},
{"rename", InstallFileOpFileRename, 2},
{"windowsGetShortName", InstallFileOpFileWindowsGetShortName, 1},
{"windowsShortcut", InstallFileOpFileWindowsShortcut, 7},
{"macAlias", InstallFileOpFileMacAlias, 2},
{"unixLink", InstallFileOpFileUnixLink, 2},