From bb04d12834e703f6128b5aaa31b3d1d9ef5b9c03 Mon Sep 17 00:00:00 2001 From: "sgehani%netscape.com" Date: Mon, 8 May 2000 23:54:05 +0000 Subject: [PATCH] Fixing mac aliasing and AppleSingle decoding. git-svn-id: svn://10.0.0.236/trunk@68752 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpinstall/src/nsInstallFileOpItem.cpp | 47 ++++-- mozilla/xpinstall/src/nsInstallFileOpItem.h | 2 +- mozilla/xpinstall/src/nsJSFile.cpp | 144 ++++++++++-------- 3 files changed, 114 insertions(+), 79 deletions(-) diff --git a/mozilla/xpinstall/src/nsInstallFileOpItem.cpp b/mozilla/xpinstall/src/nsInstallFileOpItem.cpp index d38cb98f0ad..ffbec8ae0fc 100644 --- a/mozilla/xpinstall/src/nsInstallFileOpItem.cpp +++ b/mozilla/xpinstall/src/nsInstallFileOpItem.cpp @@ -34,7 +34,9 @@ #include "Aliases.h" #include "Gestalt.h" #include "Resources.h" +#include "TextUtils.h" #include "script.h" +#include "MoreFilesExtras.h" #include "nsILocalFileMac.h" #endif @@ -1113,37 +1115,60 @@ nsInstallFileOpItem::NativeFileOpMacAliasComplete() nsCOMPtr localFileMacTarget = do_QueryInterface(mTarget); nsCOMPtr localFileMacSrc = do_QueryInterface(mSrc); - FSSpec *fsPtrAlias, *srcPtrAlias; + FSSpec fsSource, fsAliasParent, fsAlias; AliasHandle aliasH; FInfo info; OSErr err = noErr; + nsresult rv = NS_OK; + long aliasDirID; + Boolean isDir; + char *aliasLeaf; - localFileMacTarget->GetFSSpec(fsPtrAlias); - localFileMacSrc->GetFSSpec(srcPtrAlias); + // nsIFile sucks so we have to do special hackery here + rv = localFileMacSrc->GetResolvedFSSpec(&fsSource); + if (!NS_SUCCEEDED(rv)) return rv; + rv = localFileMacTarget->GetFSSpec(&fsAliasParent); + if (!NS_SUCCEEDED(rv)) return rv; + rv = localFileMacTarget->GetAppendedPath(&aliasLeaf); + if (!NS_SUCCEEDED(rv)) return rv; - err = NewAliasMinimal( srcPtrAlias, &aliasH ); + // construct target alias FSSpec using parent and leaf path + err = FSpGetDirectoryID(&fsAliasParent, &aliasDirID, &isDir); + if (err != noErr) + { + if (aliasLeaf) + nsAllocator::Free(aliasLeaf); + return err; + } + c2pstr(aliasLeaf); + FSMakeFSSpec(fsAliasParent.vRefNum, aliasDirID, (unsigned char *) aliasLeaf, &fsAlias); + p2cstr((unsigned char *)aliasLeaf); + if (aliasLeaf) + nsAllocator::Free(aliasLeaf); + + err = NewAliasMinimal( &fsSource, &aliasH ); if (err != noErr) // bubble up Alias Manager error return err; // create the alias file - FSpGetFInfo(srcPtrAlias, &info); - FSpCreateResFile(fsPtrAlias, info.fdCreator, info.fdType, smRoman); - short refNum = FSpOpenResFile(fsPtrAlias, fsRdWrPerm); + FSpGetFInfo(&fsSource, &info); + FSpCreateResFile(&fsAlias, info.fdCreator, info.fdType, smRoman); + short refNum = FSpOpenResFile(&fsAlias, fsRdWrPerm); if (refNum != -1) { UseResFile(refNum); - AddResource((Handle)aliasH, rAliasType, 0, fsPtrAlias->name); + AddResource((Handle)aliasH, rAliasType, 0, fsAlias.name); ReleaseResource((Handle)aliasH); UpdateResFile(refNum); CloseResFile(refNum); } else - return nsInstall::SUCCESS; + return nsInstall::SUCCESS; // non-fatal so prevent internal abort // mark newly created file as an alias file - FSpGetFInfo(fsPtrAlias, &info); + FSpGetFInfo(&fsAlias, &info); info.fdFlags |= kIsAlias; - FSpSetFInfo(fsPtrAlias, &info); + FSpSetFInfo(&fsAlias, &info); #endif return nsInstall::SUCCESS; diff --git a/mozilla/xpinstall/src/nsInstallFileOpItem.h b/mozilla/xpinstall/src/nsInstallFileOpItem.h index 16eda0d4c89..f193d931e75 100644 --- a/mozilla/xpinstall/src/nsInstallFileOpItem.h +++ b/mozilla/xpinstall/src/nsInstallFileOpItem.h @@ -59,7 +59,7 @@ class nsInstallFileOpItem : public nsInstallObject nsInstallFileOpItem(nsInstall* installObj, PRInt32 aCommand, nsIFile* aSrc, - nsIFile* aTarget, + nsIFile* aTarget, PRInt32* aReturn); // used by: diff --git a/mozilla/xpinstall/src/nsJSFile.cpp b/mozilla/xpinstall/src/nsJSFile.cpp index 9bc8f63feb8..ca0115f4bff 100644 --- a/mozilla/xpinstall/src/nsJSFile.cpp +++ b/mozilla/xpinstall/src/nsJSFile.cpp @@ -1081,15 +1081,13 @@ InstallFileOpFileWindowsShortcut(JSContext *cx, JSObject *obj, uintN argc, jsval JSBool PR_CALLBACK InstallFileOpFileMacAlias(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsInstall *nativeThis = (nsInstall*)JS_GetPrivate(cx, obj); - PRInt32 nativeRet; - nsAutoString b0; - nsAutoString b1; - nsAutoString b2; - nsAutoString b3; - //JSObject *jsObj; - //nsInstallFolder *folder; - + nsInstall *nativeThis = (nsInstall *)JS_GetPrivate(cx, obj); + PRInt32 nativeRet; + nsAutoString sourceLeaf, aliasLeaf; + JSObject *jsoSourceFolder, *jsoAliasFolder; + nsInstallFolder *nsifSourceFolder, *nsifAliasFolder; + nsresult rv1 = NS_OK, rv2 = NS_OK; + *rval = JSVAL_NULL; // If there's no private data, this must be the prototype, so ignore @@ -1098,41 +1096,11 @@ InstallFileOpFileMacAlias(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, return JS_TRUE; } - if(argc >= 4) + if(argc >= 3) { - // public int FileMacAlias( String aSourceFolder, - // String aSourceFileName, - // String aAliasFolder, - // String aAliasName ); - // where - // aSourceFolder -- the folder of the installed file from Get*Folder() APIs - // aSourceName -- the installed file's name - // aAliasFolder -- the folder of the new alias from Get*Folder() APIs - // aAliasName -- the actual name of the new alias - // - // returns SUCCESS for successful scheduling of operation - // UNEXPECTED_ERROR for failure - - ConvertJSValToStr(b0, cx, argv[0]); - ConvertJSValToStr(b1, cx, argv[1]); - ConvertJSValToStr(b2, cx, argv[2]); - ConvertJSValToStr(b3, cx, argv[3]); - - b0 += b1; - b2 += b3; - - if(NS_OK != nativeThis->FileOpFileMacAlias(b0, b2, &nativeRet)) - { - return JS_TRUE; - } - - *rval = INT_TO_JSVAL(nativeRet); - } - else if (argc >= 3) - { - // public int FileMacAlias( String aSourceFolder, - // String aSourceName, - // String aAliasFolder ); + // public int FileMacAlias( InstallFolder aSourceFolder, + // String aSourceName, + // InstallFolder aAliasFolder ); // where // aSourceFolder -- the folder of the installed file from Get*Folder() APIs // aSourceName -- the installed file's name @@ -1144,45 +1112,87 @@ InstallFileOpFileMacAlias(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, // returns SUCCESS for successful scheduling of operation // UNEXPECTED_ERROR for failure - ConvertJSValToStr(b0, cx, argv[0]); - ConvertJSValToStr(b1, cx, argv[1]); - ConvertJSValToStr(b2, cx, argv[2]); - - b0 += b1; - b2 += b1; - b2.AppendWithConversion(" alias"); // XXX use GetResourcedString(id) - - if(NS_OK != nativeThis->FileOpFileMacAlias(b0, b2, &nativeRet)) + if (argv[0] == JSVAL_NULL || !JSVAL_IS_OBJECT(argv[0]) || // InstallFolder aSourceFolder + argv[2] == JSVAL_NULL || !JSVAL_IS_OBJECT(argv[2])) // InstallFolder aAliasFolder { - return JS_TRUE; + *rval = INT_TO_JSVAL(nsInstall::INVALID_ARGUMENTS); + return JS_TRUE; } - *rval = INT_TO_JSVAL(nativeRet); - } - else if (argc >= 2) - { - // public int FileMacAlias( String aSourcePath, - // String aAliasPath ); + jsoSourceFolder = JSVAL_TO_OBJECT(argv[0]); + jsoAliasFolder = JSVAL_TO_OBJECT(argv[2]); + if ((!JS_InstanceOf(cx, jsoSourceFolder, &FileSpecObjectClass, nsnull)) || + (!JS_InstanceOf(cx, jsoAliasFolder, &FileSpecObjectClass, nsnull))) + { + *rval = INT_TO_JSVAL(nsInstall::INVALID_ARGUMENTS); + return JS_TRUE; + } + + nsifSourceFolder = (nsInstallFolder *) JS_GetPrivate(cx, jsoSourceFolder); + nsifAliasFolder = (nsInstallFolder *) JS_GetPrivate(cx, jsoAliasFolder); + if (!nsifSourceFolder || !nsifAliasFolder) + { + *rval = INT_TO_JSVAL(nsInstall::INVALID_ARGUMENTS); + return JS_TRUE; + } + + // make copies of the InstallFolders leaving originals uncontaminated + nsCOMPtr iFileSourceOrig = nsifSourceFolder->GetFileSpec(); + nsCOMPtr iFileAliasOrig = nsifAliasFolder->GetFileSpec(); + nsCOMPtr iFileSource; + nsCOMPtr iFileAlias; + rv1 = iFileSourceOrig->Clone(getter_AddRefs(iFileSource)); + rv2 = iFileAliasOrig->Clone(getter_AddRefs(iFileAlias)); + if (!NS_SUCCEEDED(rv1) || !NS_SUCCEEDED(rv2)) + { + *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR); + return JS_TRUE; + } + + ConvertJSValToStr(sourceLeaf, cx, argv[1]); + rv1 = iFileSource->Append(nsAutoCString(sourceLeaf)); + + // public int FileMacAlias( InstallFolder aSourceFolder, + // String aSourceFileName, + // InstallFolder aAliasFolder, + // String aAliasName ); // where - // aSourcePath -- the full path to the installed file - // aAliasPath -- the full path to the new alias + // aSourceFolder -- the folder of the installed file from Get*Folder() APIs + // aSourceName -- the installed file's name + // aAliasFolder -- the folder of the new alias from Get*Folder() APIs + // aAliasName -- the actual name of the new alias // // returns SUCCESS for successful scheduling of operation // UNEXPECTED_ERROR for failure - ConvertJSValToStr(b0, cx, argv[0]); - ConvertJSValToStr(b1, cx, argv[1]); - - if(NS_OK != nativeThis->FileOpFileMacAlias(b0, b1, &nativeRet)) + if (argc >= 4) { - return JS_TRUE; + ConvertJSValToStr(aliasLeaf, cx, argv[3]); + } + else + { + aliasLeaf = sourceLeaf; + aliasLeaf.AppendWithConversion(" alias"); // XXX use GetResourcedString(id) + } + + rv2 = iFileAlias->Append(nsAutoCString(aliasLeaf)); + if (!NS_SUCCEEDED(rv1) || !NS_SUCCEEDED(rv2)) + { + *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR); + return JS_TRUE; + } + + if(NS_OK != nativeThis->FileOpFileMacAlias(iFileSource, iFileAlias, &nativeRet)) + { + *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR); + return JS_TRUE; } *rval = INT_TO_JSVAL(nativeRet); } else { - JS_ReportError(cx, "Function FileMacAlias requires 2 to 4 parameters"); + JS_ReportError(cx, "Function FileMacAlias requires 3 or 4 parameters"); return JS_TRUE; }