prefix internal embed files

This commit is contained in:
nakst 2021-09-01 20:39:36 +01:00
parent 6c106d1a1f
commit 1cdbaacdc3
4 changed files with 23 additions and 25 deletions

View File

@ -1167,10 +1167,10 @@ extern "C" void _start(EsProcessStartupInformation *_startupInformation) {
theming.scale = api.systemConstants[ES_SYSTEM_CONSTANT_UI_SCALE] / 100.0f;
size_t fileBytes;
const void *file = EsEmbeddedFileGet(EsLiteral("Theme.dat"), &fileBytes);
const void *file = EsEmbeddedFileGet(EsLiteral("$Desktop/Theme.dat"), &fileBytes);
EsAssert(ThemeLoadData(file, fileBytes));
iconManagement.standardPack = (const uint8_t *) EsEmbeddedFileGet(EsLiteral("Icons.dat"), &iconManagement.standardPackSize);
iconManagement.standardPack = (const uint8_t *) EsEmbeddedFileGet(EsLiteral("$Desktop/Icons.dat"), &iconManagement.standardPackSize);
theming.cursors.width = ES_THEME_CURSORS_WIDTH;
theming.cursors.height = ES_THEME_CURSORS_HEIGHT;
@ -1498,30 +1498,27 @@ void EsInstanceSetActiveUndoManager(EsInstance *_instance, EsUndoManager *manage
}
const void *EsEmbeddedFileGet(const char *_name, ptrdiff_t nameBytes, size_t *byteCount) {
// TODO It's probably a bad idea to let applications load embedded files from Desktop.
uint64_t name = CalculateCRC64(_name, nameBytes == -1 ? EsCStringLength(_name) : nameBytes);
if (nameBytes == -1) {
nameBytes = EsCStringLength(_name);
}
for (uintptr_t i = 0; i < 2; i++) {
if (i == 0 && (api.startupInformation->isDesktop || !api.startupInformation->isBundle)) {
continue;
}
const BundleHeader *header = (const BundleHeader *) BUNDLE_FILE_MAP_ADDRESS;
const BundleHeader *header = (const BundleHeader *) (i ? BUNDLE_FILE_DESKTOP_MAP_ADDRESS : BUNDLE_FILE_MAP_ADDRESS);
const BundleFile *files = (const BundleFile *) (header + 1);
if (nameBytes > 9 && 0 == EsMemoryCompare(_name, "$Desktop/", 9)) {
header = (const BundleHeader *) BUNDLE_FILE_DESKTOP_MAP_ADDRESS;
_name += 9, nameBytes -= 9;
}
if (header->signature != BUNDLE_SIGNATURE) {
return nullptr;
}
const BundleFile *files = (const BundleFile *) (header + 1);
uint64_t name = CalculateCRC64(_name, nameBytes);
for (uintptr_t i = 0; i < header->fileCount; i++) {
if (files[i].nameCRC64 == name) {
if (byteCount) {
*byteCount = files[i].bytes;
}
return (const uint8_t *) header + files[i].offset;
for (uintptr_t i = 0; i < header->fileCount; i++) {
if (files[i].nameCRC64 == name) {
if (byteCount) {
*byteCount = files[i].bytes;
}
return (const uint8_t *) header + files[i].offset;
}
}

View File

@ -163,7 +163,7 @@ EsError KLoadELF(KNode *node, KLoadedExecutable *executable) {
// Look for the executable in the bundle.
#ifdef ARCH_X86_64
uint64_t name = CalculateCRC64(EsLiteral("Executable (x86_64)"));
uint64_t name = CalculateCRC64(EsLiteral("$Executables/x86_64"));
#endif
BundleFile *files = (BundleFile *) ((BundleHeader *) header.mapAddress + 1);

View File

@ -1,6 +1,7 @@
// TODO Prevent Meltdown/Spectre exploits.
// TODO Kernel debugger.
// TODO Passing data to userspace - zeroing padding bits of structures.
// TODO Restoring all registers after system call.
// TODO Remove file extensions?
// TODO Thread-local variables for native applications (already working under the POSIX subsystem).

View File

@ -567,7 +567,7 @@ void BuildDesktop(Application *application) {
ADD_BUNDLE_INPUT("res/Themes/Theme.dat", "Theme.dat", 16);
ADD_BUNDLE_INPUT("res/Themes/elementary Icons.dat", "Icons.dat", 16);
ADD_BUNDLE_INPUT("res/Themes/elementary Icons License.txt", "Icons License.txt", 16);
ADD_BUNDLE_INPUT("bin/Desktop.no_symbols", "Executable (x86_64)", 0x1000);
ADD_BUNDLE_INPUT("bin/Desktop.no_symbols", "$Executables/x86_64", 0x1000);
MakeBundle("root/Essence/Desktop.esx", application->bundleInputFiles, arrlenu(application->bundleInputFiles), 0);
}
@ -630,7 +630,7 @@ void BuildApplication(Application *application) {
ArgString(applicationLinkFlags), "-T", linkerScript);
ExecuteForApp(application, toolchainStrip, "-o", strippedFile, "--strip-all", symbolFile);
ADD_BUNDLE_INPUT(strippedFile, "Executable (x86_64)", 0x1000);
ADD_BUNDLE_INPUT(strippedFile, "$Executables/x86_64", 0x1000);
// Convert any files for the bundle marked with a '!'.
@ -853,7 +853,7 @@ void OutputSystemConfiguration() {
FilePrintFormat(file, "%s=|Fonts:/%.*s.dat\n", fontLines[i].key, (int) fontLines[i].valueBytes - 4, fontLines[i].value);
#endif
} else {
FilePrintFormat(file, "%s=:%s\n", fontLines[i].key, fontLines[i].value);
FilePrintFormat(file, "%s=:$Desktop/%s\n", fontLines[i].key, fontLines[i].value);
}
} else {
size_t bytes = EsINIFormat(fontLines + i, buffer, sizeof(buffer));