summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWoongsuk Cho <ws77.cho@samsung.com>2018-08-08 14:54:45 +0900
committer조웅석/Tizen Platform Lab(SR)/Staff Engineer/삼성전자 <ws77.cho@samsung.com>2018-09-06 10:22:00 +0900
commit6695a6255a14bd98691369a0158ea26e3a4b082a (patch)
tree29b9e5690795ea3bfb814812e2407dc13f0e3ad1
parentd8343b17367950df1c30434cdf291eefd9f37c1a (diff)
downloadlauncher-6695a6255a14bd98691369a0158ea26e3a4b082a.tar.gz
launcher-6695a6255a14bd98691369a0158ea26e3a4b082a.tar.bz2
launcher-6695a6255a14bd98691369a0158ea26e3a4b082a.zip
set environment for corefx special folder
Change-Id: I80e0dafb32f1b716142c50371a1bd5779ca01559
-rw-r--r--NativeLauncher/CMakeLists.txt2
-rw-r--r--NativeLauncher/inc/coreclr_host.h11
-rw-r--r--NativeLauncher/launcher/dotnet/dotnet_launcher.cc71
-rw-r--r--NativeLauncher/launcher/dotnet/dotnet_launcher.h2
-rw-r--r--packaging/dotnet-launcher.spec2
5 files changed, 87 insertions, 1 deletions
diff --git a/NativeLauncher/CMakeLists.txt b/NativeLauncher/CMakeLists.txt
index 42a59d1..93cd551 100644
--- a/NativeLauncher/CMakeLists.txt
+++ b/NativeLauncher/CMakeLists.txt
@@ -4,7 +4,7 @@ PROJECT("dotnet-tools")
MESSAGE("CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
INCLUDE(FindPkgConfig)
-PKG_CHECK_MODULES(${PROJECT_NAME} REQUIRED aul pkgmgr-info pkgmgr-installer dlog ecore bundle dlog launchpad elementary glib-2.0 libsmack)
+PKG_CHECK_MODULES(${PROJECT_NAME} REQUIRED aul pkgmgr-info pkgmgr-installer dlog ecore bundle dlog launchpad elementary glib-2.0 libsmack capi-appfw-app-common storage)
FOREACH(flag ${${PROJECT_NAME}_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
diff --git a/NativeLauncher/inc/coreclr_host.h b/NativeLauncher/inc/coreclr_host.h
index 7dbd137..3b96d6c 100644
--- a/NativeLauncher/inc/coreclr_host.h
+++ b/NativeLauncher/inc/coreclr_host.h
@@ -47,6 +47,17 @@ extern "C"
const char* entryPointTypeName,
const char* entryPointMethodName,
void** delegate);
+
+ typedef bool (*set_environment_variable_ptr)(const char16_t* name,
+ const char16_t* value);
+
+ typedef int (*multi_byte_to_wide_char_ptr)(
+ unsigned int CodePage,
+ unsigned int dwFlags,
+ const char * lpMultiByteStr,
+ int cbMultiByte,
+ char16_t * lpWideCharStr,
+ int cchWideChar);
}
#endif /* __CORECLR_HOST_H__ */
diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc
index 18a5c3e..d33c0d7 100644
--- a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc
+++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc
@@ -28,6 +28,10 @@
#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"
@@ -158,11 +162,58 @@ static void registerSigHandler()
}
}
+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),
@@ -220,6 +271,9 @@ int CoreRuntime::initialize(bool standalone)
// 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;
@@ -264,6 +318,8 @@ int CoreRuntime::initialize(bool standalone)
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
@@ -395,6 +451,21 @@ int CoreRuntime::launch(const char* appId, const char* root, const char* path, i
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);
diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.h b/NativeLauncher/launcher/dotnet/dotnet_launcher.h
index 8be7617..a00b32e 100644
--- a/NativeLauncher/launcher/dotnet/dotnet_launcher.h
+++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.h
@@ -40,6 +40,8 @@ class CoreRuntime
coreclr_execute_assembly_ptr executeAssembly;
coreclr_shutdown_ptr shutdown;
coreclr_create_delegate_ptr createDelegate;
+ set_environment_variable_ptr setEnvironmentVariable;
+ multi_byte_to_wide_char_ptr multiByteToWideChar;
std::string __nativeLibDirectory;
void* __coreclrLib;
void* __hostHandle;
diff --git a/packaging/dotnet-launcher.spec b/packaging/dotnet-launcher.spec
index 572ffb8..d7d100f 100644
--- a/packaging/dotnet-launcher.spec
+++ b/packaging/dotnet-launcher.spec
@@ -18,6 +18,8 @@ BuildRequires: pkgconfig(pkgmgr-installer)
BuildRequires: pkgconfig(elementary)
BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(libsmack)
+BuildRequires: pkgconfig(capi-appfw-app-common)
+BuildRequires: pkgconfig(storage)
BuildRequires: aul-devel
BuildRequires: dotnet-build-tools