#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
+#include <linux/limits.h>
+
+#include <storage.h>
+#include <app_common.h>
#include "utils.h"
#include "log.h"
}
}
+static bool storage_cb(int id, storage_type_e type, storage_state_e state, const char *path, void *user_data)
+{
+ int* tmp = (int*)user_data;
+ if (type == STORAGE_TYPE_INTERNAL)
+ {
+ *tmp = id;
+ return false;
+ }
+
+ return true;
+}
+
+static void initEnvForSpecialFolder()
+{
+ int storageId;
+ int error;
+ char *path = NULL;
+
+ error = storage_foreach_device_supported(storage_cb, &storageId);
+ if (error != STORAGE_ERROR_NONE) {
+ return;
+ }
+
+ error = storage_get_directory(storageId, STORAGE_DIRECTORY_IMAGES, &path);
+ if (error == STORAGE_ERROR_NONE && path != NULL) {
+ setenv("XDG_PICTURES_DIR", const_cast<char *>(path), 1);
+ free(path);
+ path = NULL;
+ }
+
+ error = storage_get_directory(storageId, STORAGE_DIRECTORY_MUSIC, &path);
+ if (error == STORAGE_ERROR_NONE && path != NULL) {
+ setenv("XDG_MUSIC_DIR", const_cast<char *>(path), 1);
+ free(path);
+ path = NULL;
+ }
+
+ error = storage_get_directory(storageId, STORAGE_DIRECTORY_VIDEOS, &path);
+ if (error == STORAGE_ERROR_NONE && path != NULL) {
+ setenv("XDG_VIDEOS_DIR", const_cast<char *>(path), 1);
+ free(path);
+ path = NULL;
+ }
+}
+
CoreRuntime::CoreRuntime(const char* mode) :
initializeClr(nullptr),
executeAssembly(nullptr),
shutdown(nullptr),
createDelegate(nullptr),
+ setEnvironmentVariable(nullptr),
+ multiByteToWideChar(nullptr),
__coreclrLib(nullptr),
__hostHandle(nullptr),
__domainId(-1),
// read string from external file and set them to environment value.
setEnvFromFile();
+ // Set environment for System.Environment.SpecialFolder
+ initEnvForSpecialFolder();
+
if (initializePathManager(std::string(), std::string(), std::string()) < 0) {
_ERR("Failed to initialize PathManager");
return -1;
CORELIB_RETURN_IF_NOSYM(coreclr_execute_assembly_ptr, executeAssembly, "coreclr_execute_assembly");
CORELIB_RETURN_IF_NOSYM(coreclr_shutdown_ptr, shutdown, "coreclr_shutdown");
CORELIB_RETURN_IF_NOSYM(coreclr_create_delegate_ptr, createDelegate, "coreclr_create_delegate");
+ CORELIB_RETURN_IF_NOSYM(set_environment_variable_ptr, setEnvironmentVariable, "SetEnvironmentVariableW");
+ CORELIB_RETURN_IF_NOSYM(multi_byte_to_wide_char_ptr, multiByteToWideChar, "MultiByteToWideChar");
#undef CORELIB_RETURN_IF_NOSYM
if (fd2 >= 0)
close(fd2);
+ // set application data path to coreclr environment.
+ // application data path can be changed by owner. So, we have to set data path just before launching.
+ char* localDataPath = app_get_data_path();
+ if (localDataPath != nullptr) {
+ char16_t envval[PATH_MAX] = {0};
+ int copied = multiByteToWideChar(0 /* CP_ACP */, 0, localDataPath, -1, envval, PATH_MAX);
+ if (copied >= PATH_MAX) {
+ _ERR("Data Path is bigger than PATH_MAX");
+ }
+
+ if (!setEnvironmentVariable(u"XDG_DATA_HOME", envval)) {
+ _ERR("Failed to set XDG_DATA_HOME");
+ }
+ }
+
pluginBeforeExecute();
_INFO("execute assembly : %s", path);