Revert PR #509, #510 (#513)
[platform/core/dotnet/launcher.git] / NativeLauncher / launcher / lib / core_runtime.cc
index 07ec8e9..ba874aa 100644 (file)
@@ -35,9 +35,9 @@
 #include <linux/limits.h>
 #include <pthread.h>
 
-#include <storage.h>
 #include <vconf.h>
 #include <app_common.h>
+#include <tzplatform_config.h>
 
 #include <Ecore.h>
 
@@ -143,55 +143,28 @@ 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 setSpecialFolder(storage_directory_e type, const char* key)
-{
-       int error;
-       char* path = NULL;
-       static int __storageId = -1;
-
-       if (__storageId < 0) {
-               error = storage_foreach_device_supported(storage_cb, &__storageId);
-               if (error != STORAGE_ERROR_NONE) {
-                       return;
-               }
-       }
-
-       error = storage_get_directory(__storageId, type, &path);
-       if (error == STORAGE_ERROR_NONE && path != NULL) {
-               if (setEnvironmentVariable) {
-                       setEnvironmentVariable(key, const_cast<char *>(path));
-               } else {
-                       _ERR("coreclr is not initialized!. setEnvironmentVariable() function is not ready!");
-                       _exit(0);
-               }
-               free(path);
-       }
-}
-
 static void initEnvForSpecialFolder()
 {
+       const char* path = NULL;
        if (getenv("XDG_PICTURES_DIR") == NULL) {
-               setSpecialFolder(STORAGE_DIRECTORY_IMAGES, "XDG_PICTURES_DIR");
+               path = tzplatform_getenv(TZ_USER_IMAGES);
+               if (path) {
+                       setenv("XDG_PICTURES_DIR", path, 1);
+               }
        }
 
        if (getenv("XDG_MUSIC_DIR") == NULL) {
-               setSpecialFolder(STORAGE_DIRECTORY_MUSIC, "XDG_MUSIC_DIR");
+               path = tzplatform_getenv(TZ_USER_MUSIC);
+               if (path) {
+                       setenv("XDG_MUSIC_DIR", path, 1);
+               }
        }
 
        if (getenv("XDG_VIDEOS_DIR") == NULL) {
-               setSpecialFolder(STORAGE_DIRECTORY_VIDEOS, "XDG_VIDEOS_DIR");
+               path = tzplatform_getenv(TZ_USER_VIDEOS);
+               if (path) {
+                       setenv("XDG_VIDEOS_DIR", path, 1);
+               }
        }
 }
 
@@ -381,6 +354,9 @@ int CoreRuntime::initialize(const char* appType, LaunchMode launchMode)
        // Disable config cache to set environment after coreclr_initialize()
        putenv(const_cast<char *>("COMPlus_DisableConfigCache=1"));
 
+       // Set environment variable for System.Environment.SpecialFolder
+       initEnvForSpecialFolder();
+
        // read string from external file and set them to environment value.
        setEnvFromFile();
 
@@ -446,6 +422,11 @@ int CoreRuntime::initialize(const char* appType, LaunchMode launchMode)
                return -1;
        }
 
+       // VD has their own signal handler.
+       if (!pluginHasLogControl()) {
+               registerSigHandler();
+       }
+
        int st = createDelegate(__hostHandle, __domainId, "Tizen.Runtime", "Tizen.Runtime.Environment", "SetEnvironmentVariable", (void**)&setEnvironmentVariable);
        if (st < 0 || setEnvironmentVariable == nullptr) {
                _ERR("Create delegate for Tizen.Runtime.dll -> Tizen.Runtime.Environment -> SetEnvironmentVariable failed (0x%08x)", st);
@@ -476,15 +457,6 @@ int CoreRuntime::initialize(const char* appType, LaunchMode launchMode)
                removeDebugPipe();
        }
 
-
-       // Set environment for System.Environment.SpecialFolder
-       // Below function creates dbus connection by callging storage API.
-       // If dbus connection is created bofere fork(), forked process cannot use dbus.
-       // To avoid gdbus blocking issue, below function should be called after fork()
-       // Addtionally, setenv() is not thread-safe function. storage API makes thread internally
-       // and it makes crash while calling setenv(). So, use setEnvrionmentVariable() instead of setenv()
-       initEnvForSpecialFolder();
-
        __initialized = true;
 
        _INFO("CoreRuntime initialize success");
@@ -551,11 +523,6 @@ int CoreRuntime::launch(const char* appId, const char* root, const char* path, i
                return -1;
        }
 
-       // VD has their own signal handler.
-       if (!pluginHasLogControl()) {
-               registerSigHandler();
-       }
-
        pluginSetAppInfo(appId, path);
 
        // temporal root path is overrided to real application root path