2026-09-03 22:30:52 +02:00

58 lines
2.0 KiB
C

// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <app/instance.h>
#include <stdbool.h>
#include <tactility/error.h>
#ifdef __cplusplus
extern "C" {
#endif
/** Largest number of directories app_exec_path_add() can hold at once. */
#define APP_EXEC_MAX_PATHS 8
/**
* Registers @a path as a directory whose contents may be executed. Applies recursively to
* subdirectories. Registering the same path twice is a no-op.
* @retval ERROR_OUT_OF_MEMORY the registry already holds APP_EXEC_MAX_PATHS entries
* @retval ERROR_NONE on success (including when @a path was already registered)
*/
error_t app_exec_path_add(const char* path);
/**
* Unregisters a directory previously passed to app_exec_path_add().
* @retval ERROR_NOT_FOUND @a path was not registered
* @retval ERROR_NONE on success
*/
error_t app_exec_path_remove(const char* path);
/**
* True when @a file_path lives under a directory registered with app_exec_path_add(), at any
* depth. Rejects any path containing a ".." segment rather than normalising it.
*/
bool app_exec_path_allowed(const char* file_path);
/**
* Asks the registered APP_LOADER_PATH_SERVICE_ID loader (see app/loader.h) whether @a path is
* runnable on this target, without loading it.
* @return false if @a path can't be run, or if no path loader is registered
*/
bool app_exec_is_executable_path(const char* path);
/**
* Runs @a path directly, without it having to be pre-registered as an app (e.g. via
* app_manager_add() or app_install()), for a file a user picked in a file browser. Internally
* registers (app_manager_add(), APP_MANIFEST_FLAG_HIDDEN so it never shows up in app-browsing
* UIs) a manifest for @a path the first time it's run, reusing that same registration on
* subsequent calls for the same path, then starts it (app_manager_start_with_parameters()).
* @retval ERROR_NOT_ALLOWED app_exec_is_executable_path(path) is false
* @retval ERROR_NONE on success
*/
error_t app_exec_run_path(const char* path, int argc, const char* const argv[], AppInstanceId* out_app_instance_id);
#ifdef __cplusplus
}
#endif