From 77501bf37cfebeb72e484598d5d7b9bc8615a730 Mon Sep 17 00:00:00 2001 From: nakst <> Date: Sun, 29 Aug 2021 10:37:03 +0100 Subject: [PATCH] store settings path per application --- desktop/desktop.cpp | 36 +++++++++++++-------------- desktop/prefix.h | 2 +- desktop/syscall.cpp | 2 +- res/System Configuration Template.ini | 2 +- util/build_core.c | 3 ++- 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/desktop/desktop.cpp b/desktop/desktop.cpp index da7b088..155a130 100644 --- a/desktop/desktop.cpp +++ b/desktop/desktop.cpp @@ -40,9 +40,9 @@ #define APPLICATION_PERMISSION_SHUTDOWN (1 << 4) #define APPLICATION_PERMISSION_VIEW_FILE_TYPES (1 << 5) -#define APPLICATION_ID_DESKTOP_BLANK_TAB (-1) -#define APPLICATION_ID_DESKTOP_SETTINGS (-2) -#define APPLICATION_ID_DESKTOP_CRASHED (-3) +#define APPLICATION_ID_DESKTOP_BLANK_TAB (-0x70000000) +#define APPLICATION_ID_DESKTOP_SETTINGS (-0x70000001) +#define APPLICATION_ID_DESKTOP_CRASHED (-0x70000002) #define CRASHED_TAB_FATAL_ERROR (0) #define CRASHED_TAB_PROGRAM_NOT_FOUND (1) @@ -110,6 +110,8 @@ struct OpenDocument { struct InstalledApplication { char *cName; char *cExecutable; + char *settingsPath; + size_t settingsPathBytes; void (*createInstance)(EsMessage *); // For applications provided by Desktop. int64_t id; uint32_t iconID; @@ -987,12 +989,8 @@ bool ApplicationInstanceStart(int64_t applicationID, EsApplicationStartupInforma } { - size_t settingsPathBytes, settingsFolderBytes; - char *settingsFolder = EsSystemConfigurationReadString(EsLiteral("general"), EsLiteral("settings_path"), &settingsFolderBytes); - char *settingsPath = EsStringAllocateAndFormat(&settingsPathBytes, "%s/%z", settingsFolderBytes, settingsFolder, application->cName); - error = NodeOpen(settingsPath, settingsPathBytes, ES_NODE_DIRECTORY | ES_NODE_CREATE_DIRECTORIES | _ES_NODE_DIRECTORY_WRITE, &settingsNode); - EsHeapFree(settingsPath); - EsHeapFree(settingsFolder); + error = NodeOpen(application->settingsPath, application->settingsPathBytes, + ES_NODE_DIRECTORY | ES_NODE_CREATE_DIRECTORIES | _ES_NODE_DIRECTORY_WRITE, &settingsNode); if (error == ES_SUCCESS) { EsMountPoint settings = {}; @@ -1117,6 +1115,7 @@ void ApplicationTemporaryDestroy(InstalledApplication *application) { desktop.installedApplications.Delete(i); EsHeapFree(application->cName); EsHeapFree(application->cExecutable); + EsHeapFree(application->settingsPath); EsHeapFree(application); // TODO Delete the settings folder. return; @@ -1270,7 +1269,7 @@ void OpenDocumentWithApplication(EsApplicationStartupInformation *startupInforma OpenDocumentCloseReference(startupInformation->documentID); } -EsError TemporaryFileCreate(EsHandle *handle, char **path, size_t *pathBytes) { +EsError TemporaryFileCreate(EsHandle *handle, char **path, size_t *pathBytes, uint32_t additionalFlags) { char temporaryFileName[32]; for (uintptr_t i = 0; i < sizeof(temporaryFileName); i++) { @@ -1284,7 +1283,7 @@ EsError TemporaryFileCreate(EsHandle *handle, char **path, size_t *pathBytes) { temporaryFolderBytes, temporaryFolder, sizeof(temporaryFileName), temporaryFileName); EsFileInformation file = EsFileOpen(temporaryFilePath, temporaryFilePathBytes, - ES_FILE_WRITE_EXCLUSIVE | ES_NODE_FAIL_IF_FOUND | ES_NODE_CREATE_DIRECTORIES); + ES_NODE_FAIL_IF_FOUND | ES_NODE_CREATE_DIRECTORIES | additionalFlags); EsHeapFree(temporaryFolder); @@ -1372,7 +1371,7 @@ void ApplicationInstanceRequestSave(ApplicationInstance *instance, const char *n document->temporarySavePath = nullptr; EsHandle fileHandle; - m.tabOperation.error = TemporaryFileCreate(&fileHandle, &document->temporarySavePath, &document->temporarySavePathBytes); + m.tabOperation.error = TemporaryFileCreate(&fileHandle, &document->temporarySavePath, &document->temporarySavePathBytes, ES_FILE_WRITE_EXCLUSIVE); if (m.tabOperation.error == ES_SUCCESS) { document->currentWriter = instance->embeddedWindowID; @@ -1540,15 +1539,11 @@ void ConfigurationLoadApplications() { InstalledApplication *application = (InstalledApplication *) EsHeapAllocate(sizeof(InstalledApplication), true); application->cName = EsSystemConfigurationGroupReadString(group, EsLiteral("name")); - size_t executableBytes = 0; + application->cExecutable = EsSystemConfigurationGroupReadString(group, EsLiteral("executable")); + application->settingsPath = EsSystemConfigurationGroupReadString(group, EsLiteral("settings_path"), &application->settingsPathBytes); char *icon = EsSystemConfigurationGroupReadString(group, EsLiteral("icon")); application->iconID = EsIconIDFromString(icon); EsHeapFree(icon); - char *executable = EsSystemConfigurationGroupReadString(group, EsLiteral("executable"), &executableBytes); - application->cExecutable = (char *) EsHeapAllocate(executableBytes + 1, false); - EsMemoryCopy(application->cExecutable, executable, executableBytes); - application->cExecutable[executableBytes] = 0; - EsHeapFree(executable); application->useSingleProcess = EsSystemConfigurationGroupReadInteger(group, EsLiteral("use_single_process"), true); application->hidden = EsSystemConfigurationGroupReadInteger(group, EsLiteral("hidden"), false); application->id = EsIntegerParse(group->section, group->sectionBytes); @@ -1909,7 +1904,7 @@ void DesktopMessage2(EsMessage *message, uint8_t *buffer, EsBuffer *pipe) { EsHandle handle; char *path; size_t pathBytes; - EsError error = TemporaryFileCreate(&handle, &path, &pathBytes); + EsError error = TemporaryFileCreate(&handle, &path, &pathBytes, ES_FILE_WRITE_EXCLUSIVE); if (error == ES_SUCCESS) { if (desktop.nextClipboardFile) { @@ -2034,6 +2029,9 @@ void DesktopMessage2(EsMessage *message, uint8_t *buffer, EsBuffer *pipe) { application->cName = (char *) EsHeapAllocate(32, false); for (int i = 1; i < 31; i++) application->cName[i] = (EsRandomU8() % 26) + 'a'; application->cName[0] = '_', application->cName[31] = 0; + EsHandle handle; + EsError error = TemporaryFileCreate(&handle, &application->settingsPath, &application->settingsPathBytes, ES_NODE_DIRECTORY); + if (error == ES_SUCCESS) EsHandleClose(handle); desktop.installedApplications.Add(application); ApplicationInstanceCreate(application->id, nullptr, nullptr); } diff --git a/desktop/prefix.h b/desktop/prefix.h index c2ee888..cd29434 100644 --- a/desktop/prefix.h +++ b/desktop/prefix.h @@ -281,7 +281,7 @@ struct BundleFile { #define K_OS_FOLDER K_BOOT_DRIVE "/Essence" #define K_DESKTOP_EXECUTABLE K_OS_FOLDER "/Desktop.esx" -#define K_SYSTEM_CONFIGURATION K_OS_FOLDER "/System Configuration.ini" +#define K_SYSTEM_CONFIGURATION K_OS_FOLDER "/Default.ini" #define CREATION_ARGUMENT_MAIN (0) #define CREATION_ARGUMENT_ENVIRONMENT (1) diff --git a/desktop/syscall.cpp b/desktop/syscall.cpp index d5d35af..7301137 100644 --- a/desktop/syscall.cpp +++ b/desktop/syscall.cpp @@ -250,7 +250,7 @@ EsFileInformation EsFileOpen(const char *path, ptrdiff_t pathLength, uint32_t fl _EsNodeInformation node; EsError result = NodeOpen(path, pathLength, flags, &node); - if (result == ES_SUCCESS && node.type == ES_NODE_DIRECTORY) { + if (result == ES_SUCCESS && node.type == ES_NODE_DIRECTORY && (~flags & ES_NODE_DIRECTORY /* for internal use only */)) { result = ES_ERROR_INCORRECT_NODE_TYPE; EsHandleClose(node.handle); } diff --git a/res/System Configuration Template.ini b/res/System Configuration Template.ini index 6b3bc02..7a02d48 100644 --- a/res/System Configuration Template.ini +++ b/res/System Configuration Template.ini @@ -3,7 +3,7 @@ startup_sound=0:/Essence/Media/Startup Sound.wav fonts_path=0:/Essence/Fonts temporary_path=0:/Essence/Temporary -settings_path=0:/Settings +default_settings_path=0:/Settings default_user_documents_path=0:/ installation_state=0 click_chain_timeout_ms=500 diff --git a/util/build_core.c b/util/build_core.c index 55c90a0..a66edd8 100644 --- a/util/build_core.c +++ b/util/build_core.c @@ -758,7 +758,7 @@ void OutputSystemConfiguration() { EsINIState s = {}; char *config = (char *) LoadFile("res/System Configuration Template.ini", &s.bytes); s.buffer = config; - File file = FileOpen("root/Essence/System Configuration.ini", 'w'); + File file = FileOpen("root/Essence/Default.ini", 'w'); while (EsINIParse(&s)) { EsINIZeroTerminate(&s); @@ -815,6 +815,7 @@ void OutputSystemConfiguration() { FilePrintFormat(file, "\n[@application %d]\n", applications[i].id); FilePrintFormat(file, "name=%s\n", applications[i].name); FilePrintFormat(file, "executable=0:/Applications/%s.esx\n", applications[i].name); + FilePrintFormat(file, "settings_path=0:/Settings/%s\n", applications[i].name); FilePrintFormat(file, "is_file_manager=%d\n", 0 == strcmp(applications[i].name, "File Manager") ? 1 : 0); for (uintptr_t j = 0; j < arrlenu(applications[i].properties); j++) {