Fix handling of the widget resources file by creating a data-fork resource file that lives in the application directory (bug 146895). r=ccarlen, sr=beard, a=asa for mach-o-only changes.

This commit is contained in:
bryner%netscape.com 2002-06-09 00:05:37 +00:00
Родитель 1345a2f35c
Коммит 64fdfa2e89
12 изменённых файлов: 285 добавлений и 126 удалений

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

@ -3810,6 +3810,12 @@
isa = PBXTargetDependency;
target = F58581AE022B8D62010001CA;
};
F585F52902B2C66C01A967F3 = {
fileRef = F5F14E9602A5A43A01A967F3;
isa = PBXBuildFile;
settings = {
};
};
F58A94F2023F10CA010001CA = {
children = (
29B97319FDCFA39411CA2CEA,
@ -5805,6 +5811,7 @@
F5BAAC3E02AC6AA201A967F3,
F5BAAC3F02AC6AA201A967F3,
F5BAAC4002AC6AA201A967F3,
F585F52902B2C66C01A967F3,
);
isa = PBXCopyFilesBuildPhase;
name = "Copy Files";
@ -6073,6 +6080,18 @@
name = "Gray Images";
refType = 4;
};
F5F14E9602A5A43A01A967F3 = {
isa = PBXFileReference;
name = libwidget.rsrc;
path = ../dist/Embed/libwidget.rsrc;
refType = 2;
};
F5F14E9802A5A43A01A967F3 = {
fileRef = F5F14E9602A5A43A01A967F3;
isa = PBXBuildFile;
settings = {
};
};
F5F181C50208006F0124611D = {
isa = PBXFileReference;
name = history.xpt;
@ -6200,6 +6219,7 @@
F6BD638101B30EA301A962F7,
F6BD638201B30EA301A962F7,
F6BD638701B30F5301A962F7,
F5F14E9602A5A43A01A967F3,
F5247C2F0228B5E7013DD99A,
F6BD645501B3167601A962F7,
F6BD64FB01B3184301A962F7,
@ -6222,6 +6242,7 @@
F6BD638C01B30F5301A962F7,
F6BD638D01B30F5301A962F7,
F6BD638E01B30F5301A962F7,
F5F14E9802A5A43A01A967F3,
);
isa = PBXCopyFilesBuildPhase;
name = "Copy Files";

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

@ -3810,6 +3810,12 @@
isa = PBXTargetDependency;
target = F58581AE022B8D62010001CA;
};
F585F52902B2C66C01A967F3 = {
fileRef = F5F14E9602A5A43A01A967F3;
isa = PBXBuildFile;
settings = {
};
};
F58A94F2023F10CA010001CA = {
children = (
29B97319FDCFA39411CA2CEA,
@ -5805,6 +5811,7 @@
F5BAAC3E02AC6AA201A967F3,
F5BAAC3F02AC6AA201A967F3,
F5BAAC4002AC6AA201A967F3,
F585F52902B2C66C01A967F3,
);
isa = PBXCopyFilesBuildPhase;
name = "Copy Files";
@ -6073,6 +6080,18 @@
name = "Gray Images";
refType = 4;
};
F5F14E9602A5A43A01A967F3 = {
isa = PBXFileReference;
name = libwidget.rsrc;
path = ../dist/Embed/libwidget.rsrc;
refType = 2;
};
F5F14E9802A5A43A01A967F3 = {
fileRef = F5F14E9602A5A43A01A967F3;
isa = PBXBuildFile;
settings = {
};
};
F5F181C50208006F0124611D = {
isa = PBXFileReference;
name = history.xpt;
@ -6200,6 +6219,7 @@
F6BD638101B30EA301A962F7,
F6BD638201B30EA301A962F7,
F6BD638701B30F5301A962F7,
F5F14E9602A5A43A01A967F3,
F5247C2F0228B5E7013DD99A,
F6BD645501B3167601A962F7,
F6BD64FB01B3184301A962F7,
@ -6222,6 +6242,7 @@
F6BD638C01B30F5301A962F7,
F6BD638D01B30F5301A962F7,
F6BD638E01B30F5301A962F7,
F5F14E9802A5A43A01A967F3,
);
isa = PBXCopyFilesBuildPhase;
name = "Copy Files";

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

@ -3810,6 +3810,12 @@
isa = PBXTargetDependency;
target = F58581AE022B8D62010001CA;
};
F585F52902B2C66C01A967F3 = {
fileRef = F5F14E9602A5A43A01A967F3;
isa = PBXBuildFile;
settings = {
};
};
F58A94F2023F10CA010001CA = {
children = (
29B97319FDCFA39411CA2CEA,
@ -5805,6 +5811,7 @@
F5BAAC3E02AC6AA201A967F3,
F5BAAC3F02AC6AA201A967F3,
F5BAAC4002AC6AA201A967F3,
F585F52902B2C66C01A967F3,
);
isa = PBXCopyFilesBuildPhase;
name = "Copy Files";
@ -6073,6 +6080,18 @@
name = "Gray Images";
refType = 4;
};
F5F14E9602A5A43A01A967F3 = {
isa = PBXFileReference;
name = libwidget.rsrc;
path = ../dist/Embed/libwidget.rsrc;
refType = 2;
};
F5F14E9802A5A43A01A967F3 = {
fileRef = F5F14E9602A5A43A01A967F3;
isa = PBXBuildFile;
settings = {
};
};
F5F181C50208006F0124611D = {
isa = PBXFileReference;
name = history.xpt;
@ -6200,6 +6219,7 @@
F6BD638101B30EA301A962F7,
F6BD638201B30EA301A962F7,
F6BD638701B30F5301A962F7,
F5F14E9602A5A43A01A967F3,
F5247C2F0228B5E7013DD99A,
F6BD645501B3167601A962F7,
F6BD64FB01B3184301A962F7,
@ -6222,6 +6242,7 @@
F6BD638C01B30F5301A962F7,
F6BD638D01B30F5301A962F7,
F6BD638E01B30F5301A962F7,
F5F14E9802A5A43A01A967F3,
);
isa = PBXCopyFilesBuildPhase;
name = "Copy Files";

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

@ -3810,6 +3810,12 @@
isa = PBXTargetDependency;
target = F58581AE022B8D62010001CA;
};
F585F52902B2C66C01A967F3 = {
fileRef = F5F14E9602A5A43A01A967F3;
isa = PBXBuildFile;
settings = {
};
};
F58A94F2023F10CA010001CA = {
children = (
29B97319FDCFA39411CA2CEA,
@ -5805,6 +5811,7 @@
F5BAAC3E02AC6AA201A967F3,
F5BAAC3F02AC6AA201A967F3,
F5BAAC4002AC6AA201A967F3,
F585F52902B2C66C01A967F3,
);
isa = PBXCopyFilesBuildPhase;
name = "Copy Files";
@ -6073,6 +6080,18 @@
name = "Gray Images";
refType = 4;
};
F5F14E9602A5A43A01A967F3 = {
isa = PBXFileReference;
name = libwidget.rsrc;
path = ../dist/Embed/libwidget.rsrc;
refType = 2;
};
F5F14E9802A5A43A01A967F3 = {
fileRef = F5F14E9602A5A43A01A967F3;
isa = PBXBuildFile;
settings = {
};
};
F5F181C50208006F0124611D = {
isa = PBXFileReference;
name = history.xpt;
@ -6200,6 +6219,7 @@
F6BD638101B30EA301A962F7,
F6BD638201B30EA301A962F7,
F6BD638701B30F5301A962F7,
F5F14E9602A5A43A01A967F3,
F5247C2F0228B5E7013DD99A,
F6BD645501B3167601A962F7,
F6BD64FB01B3184301A962F7,
@ -6222,6 +6242,7 @@
F6BD638C01B30F5301A962F7,
F6BD638D01B30F5301A962F7,
F6BD638E01B30F5301A962F7,
F5F14E9802A5A43A01A967F3,
);
isa = PBXCopyFilesBuildPhase;
name = "Copy Files";

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

@ -17,3 +17,4 @@ trace.lib
elf-dynstr-gc
final-link-libs
doxygen.cfg
asdecode

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

@ -41,7 +41,7 @@ else
CSRCS = nsinstall.c pathsub.c
endif
TARGETS = $(HOST_PROGRAM) $(PROGRAM) $(PLSRCS:.pl=)
TARGETS = $(HOST_PROGRAM) $(PROGRAM) $(PLSRCS:.pl=) $(SIMPLE_PROGRAMS)
# Generate the build number on the fly.
TARGETS += build_number nsBuildID.h
@ -50,6 +50,10 @@ ifdef USE_ELF_DYNSTR_GC
TARGETS += elf-dynstr-gc
endif
ifeq ($(OS_ARCH), Darwin)
SIMPLE_PROGRAMS += asdecode
endif
# IMPORTANT: Disable NSBUILDROOT for this directory only, otherwise we have
# a recursive rule for finding nsinstall and the Perl scripts.
ifdef NSBUILDROOT

146
config/asdecode.cpp Normal file
Просмотреть файл

@ -0,0 +1,146 @@
/* -*- Mode: C++; tab-width: 2; 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 the AppleSingle decoder.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Patrick Beard <beard@netscape.com> (Original author)
* Brian Ryner <bryner@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stdlib.h>
#define EXIT_IF_FALSE(x) if (!(x)) exit(1);
// decodes a file into data and resource forks.
static int read_int(FILE* f)
{
int result;
EXIT_IF_FALSE(fread(&result, sizeof(result), 1, f) == 1);
return result;
}
static void copy_range(FILE* input, size_t offset, size_t length,
const char* output_name)
{
FILE* output = fopen(output_name, "wb");
EXIT_IF_FALSE(output != NULL);
fseek(input, offset, SEEK_SET);
while (length != 0) {
char buffer[4096];
size_t amount = (length > sizeof(buffer) ? sizeof(buffer) : length);
EXIT_IF_FALSE(fread(buffer, 1, amount, input) == amount);
fwrite(buffer, 1, amount, output);
length -= amount;
}
fclose(output);
}
int main(int argc, char** argv)
{
if (argc < 3) {
printf("usage: %s input output\n", argv[0]);
exit(1);
}
FILE* input = fopen(argv[1], "rb");
if (input == NULL) {
printf("can't open file `%s'\n", argv[1]);
exit(2);
}
struct header {
int magic_number;
int version_number;
char filler[16];
} header;
EXIT_IF_FALSE(fread(&header, sizeof(header), 1, input) == 1);
EXIT_IF_FALSE(header.magic_number == 0x00051600);
EXIT_IF_FALSE(header.version_number <= 0x00020000);
// printf("sizeof(header) == %d\n", sizeof(header));
short entry_count;
EXIT_IF_FALSE(fread(&entry_count, sizeof(entry_count), 1, input) == 1);
struct entry {
unsigned int id;
unsigned int offset;
unsigned int length;
};
entry* entries = new entry[entry_count];
EXIT_IF_FALSE(fread(entries, sizeof(entry), entry_count, input) == entry_count);
entry* data_entry = NULL;
entry* rez_entry = NULL;
for (int i = 0; i < entry_count; i++) {
entry& entry = entries[i];
switch (entry.id) {
case 1:
// data fork.
data_entry = &entry;
break;
case 2:
rez_entry = &entry;
break;
}
}
const char* data_name = argv[2];
if (data_entry && data_entry->length) {
copy_range(input, data_entry->offset, data_entry->length, data_name);
} else {
// always create the data fork, even if the file doesn't have one.
FILE* tmp = fopen(data_name, "wb");
EXIT_IF_FALSE(tmp);
fclose(tmp);
}
if (rez_entry && rez_entry->length) {
char rez_name[512];
strcpy(rez_name, data_name);
strcat(rez_name, "/rsrc");
copy_range(input, rez_entry->offset, rez_entry->length, rez_name);
}
delete[] entries;
fclose(input);
return 0;
}

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

@ -232,6 +232,7 @@ components/uriloader.xpt
; widget
components/libwidget_mac.dylib
components/widget.xpt
libwidget.rsrc
; xpconnect
components/libxpconnect.dylib

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

@ -97,6 +97,21 @@ XPIDLSRCS += \
SHARED_LIBRARY_LIBS = $(DIST)/lib/libxpwidgets_s.a
# nsMacWidget.rsrc is an AppleSingle encoded resource file.
# For Mach-O, we want to decode it and copy it to a data-fork resource file
# that lives in the application directory.
RES_DEST = $(DIST)/bin/libwidget.rsrc
RES_SRC = $(srcdir)/../mac/nsMacWidget.rsrc
$(RES_DEST): $(RES_SRC)
$(DIST)/bin/asdecode $(RES_SRC) $(RES_DEST).tmp
rm -f $(RES_DEST)
cp $(RES_DEST).tmp/rsrc $(RES_DEST)
rm -rf $(RES_DEST).tmp
libs:: $(RES_DEST)
EXTRA_DSO_LDOPTS += \
$(MOZ_UNICHARUTIL_LIBS) \
$(TK_LIBS) \

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

@ -1,119 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* 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/
*
* 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.org code.
*
* 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):
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsMacResources.h"
#include <Resources.h>
short nsMacResources::mRefNum = kResFileNotOpened;
short nsMacResources::mSaveResFile = 0;
#if !defined(XP_MACOSX)
pascal OSErr __NSInitialize(const CFragInitBlock *theInitBlock);
pascal OSErr __initializeResources(const CFragInitBlock *theInitBlock);
pascal void __NSTerminate(void);
pascal void __terminateResources(void);
//----------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------
pascal OSErr __initializeResources(const CFragInitBlock *theInitBlock)
{
OSErr err = __NSInitialize(theInitBlock);
if (err)
return err;
short saveResFile = ::CurResFile();
short refNum = FSpOpenResFile(theInitBlock->fragLocator.u.onDisk.fileSpec, fsRdPerm);
nsMacResources::SetLocalResourceFile(refNum);
::UseResFile(saveResFile);
return ::ResError();
}
//----------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------
pascal void __terminateResources(void)
{
::CloseResFile(nsMacResources::GetLocalResourceFile());
__NSTerminate();
}
#endif /*!XP_MACOSX*/
//----------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------
nsresult nsMacResources::OpenLocalResourceFile()
{
#ifdef XP_MACOSX
// XXX quick and dirty hack to make resources available so we don't crash.
if (mRefNum == kResFileNotOpened) {
FSSpec spec = { 0, 0, "\plibwidget.rsrc" };
if (FindFolder(kUserDomain, kDomainLibraryFolderType, false, &spec.vRefNum, &spec.parID) == noErr)
mRefNum = FSpOpenResFile(&spec, fsRdPerm);
}
#endif
if (mRefNum == kResFileNotOpened)
return NS_ERROR_NOT_INITIALIZED;
mSaveResFile = ::CurResFile();
::UseResFile(mRefNum);
return (::ResError() == noErr ? NS_OK : NS_ERROR_FAILURE);
}
//----------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------
nsresult nsMacResources::CloseLocalResourceFile()
{
if (mRefNum == kResFileNotOpened)
return NS_ERROR_NOT_INITIALIZED;
::UseResFile(mSaveResFile);
return (::ResError() == noErr ? NS_OK : NS_ERROR_FAILURE);
}

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

@ -114,6 +114,21 @@ include $(topsrcdir)/config/rules.mk
export:: $(addprefix $(topsrcdir)/gfx/src/mac/,$(GFX_LCPPSRCS))
$(INSTALL) $^ .
# nsMacWidget.rsrc is an AppleSingle encoded resource file.
# For Mach-O, we want to decode it and copy it to a data-fork resource file
# that lives in the application directory.
RES_DEST = $(DIST)/bin/libwidget.rsrc
RES_SRC = $(srcdir)/nsMacWidget.rsrc
$(RES_DEST): $(RES_SRC)
$(DIST)/bin/asdecode $(RES_SRC) $(RES_DEST).tmp
rm -f $(RES_DEST)
cp $(RES_DEST).tmp/rsrc $(RES_DEST)
rm -rf $(RES_DEST).tmp
libs:: $(RES_DEST)
LOCAL_INCLUDES = \
$(TK_CFLAGS) \
-I$(topsrcdir)/gfx/src/mac \

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

@ -37,7 +37,7 @@
#include "nsMacResources.h"
#include <Resources.h>
#include <Processes.h>
short nsMacResources::mRefNum = kResFileNotOpened;
short nsMacResources::mSaveResFile = 0;
@ -86,11 +86,23 @@ pascal void __terminateResources(void)
nsresult nsMacResources::OpenLocalResourceFile()
{
#ifdef XP_MACOSX
// XXX quick and dirty hack to make resources available so we don't crash.
if (mRefNum == kResFileNotOpened) {
FSSpec spec = { 0, 0, "\plibwidget.rsrc" };
if (FindFolder(kUserDomain, kDomainLibraryFolderType, false, &spec.vRefNum, &spec.parID) == noErr)
mRefNum = FSpOpenResFile(&spec, fsRdPerm);
if (mRefNum == kResFileNotOpened) {
ProcessSerialNumber PSN;
ProcessInfoRec pinfo;
FSSpec appSpec;
PSN.highLongOfPSN = 0;
PSN.lowLongOfPSN = kCurrentProcess;
pinfo.processInfoLength = sizeof(pinfo);
pinfo.processName = NULL;
pinfo.processAppSpec = &appSpec;
if (GetProcessInformation(&PSN, &pinfo) == noErr) {
FSSpec resSpec = { appSpec.vRefNum, appSpec.parID, "\plibwidget.rsrc" };
FSRef resRef;
if (FSpMakeFSRef(&resSpec, &resRef) == noErr)
FSOpenResourceFile(&resRef, 0, NULL, fsRdPerm, &mRefNum);
}
}
#endif
if (mRefNum == kResFileNotOpened)