From: Munkyu Im Date: Wed, 2 Sep 2015 07:09:22 +0000 (+0900) Subject: sdcard: change the way to get sdcard path X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.2~40^2~163 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9adc8e19d8f8c421c37042c6d002eef6fee42a7d;p=sdk%2Femulator%2Fqemu.git sdcard: change the way to get sdcard path Instead of using "sdk.info", get sdcard path from "vm_launch.conf" change encoding when read "vm_launch.conf" Change-Id: Id7c0cad031675e8ee67706d48f0db9cf4a89f05c Signed-off-by: Munkyu Im --- diff --git a/tizen/src/ecs/ecs_sdcard.c b/tizen/src/ecs/ecs_sdcard.c index 00a814021b..8f2e269cf9 100644 --- a/tizen/src/ecs/ecs_sdcard.c +++ b/tizen/src/ecs/ecs_sdcard.c @@ -36,176 +36,9 @@ MULTI_DEBUG_CHANNEL(qemu, ecs); -static char *get_old_tizen_sdk_data_path(void) -{ - char *tizen_sdk_data_path = NULL; - - LOG_INFO("try to search tizen-sdk-data path in another way.\n"); - -#ifndef CONFIG_WIN32 - char tizen_sdk_data[] = "/tizen-sdk-data"; - int tizen_sdk_data_len = 0; - char *home_dir; - - home_dir = (char *)g_getenv("HOME"); - if (!home_dir) { - home_dir = (char *)g_get_home_dir(); - } - - tizen_sdk_data_len = strlen(home_dir) + sizeof(tizen_sdk_data) + 1; - tizen_sdk_data_path = g_malloc(tizen_sdk_data_len); - if (!tizen_sdk_data_path) { - LOG_SEVERE("failed to allocate memory.\n"); - return NULL; - } - g_strlcpy(tizen_sdk_data_path, home_dir, tizen_sdk_data_len); - g_strlcat(tizen_sdk_data_path, tizen_sdk_data, tizen_sdk_data_len); - -#else - char tizen_sdk_data[] = "\\tizen-sdk-data\\"; - gint tizen_sdk_data_len = 0; - HKEY hKey; - char strLocalAppDataPath[1024] = { 0 }; - DWORD dwBufLen = 1024; - - RegOpenKeyEx(HKEY_CURRENT_USER, - "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", - 0, KEY_QUERY_VALUE, &hKey); - - RegQueryValueEx(hKey, "Local AppData", NULL, - NULL, (LPBYTE)strLocalAppDataPath, &dwBufLen); - RegCloseKey(hKey); - - tizen_sdk_data_len = strlen(strLocalAppDataPath) + sizeof(tizen_sdk_data) + 1; - tizen_sdk_data_path = g_malloc(tizen_sdk_data_len); - if (!tizen_sdk_data_path) { - LOG_SEVERE("failed to allocate memory.\n"); - return NULL; - } - - g_strlcpy(tizen_sdk_data_path, strLocalAppDataPath, tizen_sdk_data_len); - g_strlcat(tizen_sdk_data_path, tizen_sdk_data, tizen_sdk_data_len); -#endif - - LOG_INFO("tizen-sdk-data path: %s\n", tizen_sdk_data_path); - return tizen_sdk_data_path; -} - -/* - * get tizen-sdk-data path from sdk.info. - */ -char *get_tizen_sdk_data_path(void) -{ - char const *emul_bin_path = NULL; - char *sdk_info_file_path = NULL; - char *tizen_sdk_data_path = NULL; -#ifndef CONFIG_WIN32 - const char *sdk_info = "../../../../../sdk.info"; -#else - const char *sdk_info = "..\\..\\..\\..\\..\\sdk.info"; -#endif - const char sdk_data_var[] = "TIZEN_SDK_DATA_PATH"; - - FILE *sdk_info_fp = NULL; - int sdk_info_path_len = 0; - - LOG_TRACE("%s\n", __func__); - - emul_bin_path = get_bin_path(); - if (!emul_bin_path) { - LOG_SEVERE("failed to get emulator path.\n"); - return NULL; - } - - sdk_info_path_len = strlen(emul_bin_path) + strlen(sdk_info) + 1; - sdk_info_file_path = g_malloc(sdk_info_path_len); - if (!sdk_info_file_path) { - LOG_SEVERE("failed to allocate sdk-data buffer.\n"); - return NULL; - } - - g_snprintf(sdk_info_file_path, sdk_info_path_len, "%s%s", - emul_bin_path, sdk_info); - LOG_INFO("sdk.info path: %s\n", sdk_info_file_path); - - sdk_info_fp = fopen(sdk_info_file_path, "r"); - g_free(sdk_info_file_path); - - if (sdk_info_fp) { - LOG_TRACE("Succeeded to open [sdk.info].\n"); - - char tmp[256] = { '\0', }; - char *tmpline = NULL; - while (fgets(tmp, sizeof(tmp), sdk_info_fp) != NULL) { - if ((tmpline = g_strstr_len(tmp, sizeof(tmp), sdk_data_var))) { - tmpline += strlen(sdk_data_var) + 1; // 1 for '=' - break; - } - } - - if (tmpline) { - if (tmpline[strlen(tmpline) - 1] == '\n') { - tmpline[strlen(tmpline) - 1] = '\0'; - } - if (tmpline[strlen(tmpline) - 1] == '\r') { - tmpline[strlen(tmpline) - 1] = '\0'; - } - - tizen_sdk_data_path = g_malloc(strlen(tmpline) + 1); - g_strlcpy(tizen_sdk_data_path, tmpline, strlen(tmpline) + 1); - - LOG_INFO("tizen-sdk-data path: %s\n", tizen_sdk_data_path); - - fclose(sdk_info_fp); - return tizen_sdk_data_path; - } - - fclose(sdk_info_fp); - } - - // legacy mode - LOG_SEVERE("Failed to open [sdk.info].\n"); - - return get_old_tizen_sdk_data_path(); -} - -static char* get_emulator_sdcard_path(void) -{ - char *emulator_sdcard_path = NULL; - char *tizen_sdk_data = NULL; - -#ifndef CONFIG_WIN32 - char emulator_sdcard[] = "/emulator/sdcard/"; -#else - char emulator_sdcard[] = "\\emulator\\sdcard\\"; -#endif - - LOG_TRACE("emulator_sdcard: %s, %zu\n", emulator_sdcard, sizeof(emulator_sdcard)); - - tizen_sdk_data = get_tizen_sdk_data_path(); - if (!tizen_sdk_data) { - LOG_SEVERE("failed to get tizen-sdk-data path.\n"); - return NULL; - } - - emulator_sdcard_path = - g_malloc(strlen(tizen_sdk_data) + sizeof(emulator_sdcard) + 1); - if (!emulator_sdcard_path) { - LOG_SEVERE("failed to allocate memory.\n"); - return NULL; - } - - g_snprintf(emulator_sdcard_path, strlen(tizen_sdk_data) + sizeof(emulator_sdcard), - "%s%s", tizen_sdk_data, emulator_sdcard); - - g_free(tizen_sdk_data); - LOG_TRACE("sdcard path: %s\n", emulator_sdcard_path); - return emulator_sdcard_path; -} - -static char* get_sdcard_img_path(char* sdcard_img_name, size_t dataLen) { +static char* get_sdcard_full_path(char* sdcard_img_name, size_t dataLen) { char* sdcard_img_path = NULL; - char* sdcard_path = NULL; + const char* sdcard_path = NULL; if (sdcard_img_name == NULL || dataLen < 3) { return NULL; } @@ -218,13 +51,12 @@ static char* get_sdcard_img_path(char* sdcard_img_name, size_t dataLen) { return NULL; } - sdcard_path = get_emulator_sdcard_path(); + sdcard_path = get_sdcard_image_path(); if (sdcard_path != NULL) { sdcard_img_path = g_malloc(MAXBUFLEN); g_strlcpy(sdcard_img_path, sdcard_path, MAXBUFLEN); g_strlcat(sdcard_img_path, sdcard_img_name, MAXBUFLEN); LOG_TRACE("sdcard img path: [%s] length: %d\n", sdcard_img_path, strlen(sdcard_img_path)); - g_free(sdcard_path); return sdcard_img_path; } return NULL; @@ -319,32 +151,32 @@ void handle_sdcard(char* dataBuf, size_t dataLen) if (ret == '0' ) { /* detach sdcard */ - char* sdcard_img_path = get_sdcard_img_path(dataBuf + 2, dataLen); - LOG_TRACE("sdcard_img_path: %s\n", sdcard_img_path); - err_no = remove_sdcard_lock_os(sdcard_img_path); + char* sdcard_full_path = get_sdcard_full_path(dataBuf + 2, dataLen); + LOG_TRACE("sdcard_full_path: %s\n", sdcard_full_path); + err_no = remove_sdcard_lock_os(sdcard_full_path); if (err_no == 0 && is_sdcard_attached()) { - do_hotplug(DETACH_SDCARD, sdcard_img_path, strlen(sdcard_img_path) + 1); + do_hotplug(DETACH_SDCARD, sdcard_full_path, strlen(sdcard_full_path) + 1); make_send_device_ntf((char*)MSG_TYPE_SDCARD, GROUP_SDCARD, - ACT_SDCARD_DETACH, g_path_get_basename(sdcard_img_path)); + ACT_SDCARD_DETACH, g_path_get_basename(sdcard_full_path)); } else { - LOG_SEVERE("failed to umount: %s, err_no: %d\n", sdcard_img_path, err_no); + LOG_SEVERE("failed to umount: %s, err_no: %d\n", sdcard_full_path, err_no); make_send_device_ntf((char*)MSG_TYPE_SDCARD, GROUP_SDCARD, - err_no, g_path_get_basename(sdcard_img_path)); + err_no, g_path_get_basename(sdcard_full_path)); } - g_free(sdcard_img_path); + g_free(sdcard_full_path); } else if (ret == '1') { /* attach sdcard */ - char* sdcard_img_path = get_sdcard_img_path(dataBuf + 2, dataLen); - LOG_TRACE("sdcard_img_path: %s\n", sdcard_img_path); - if (!is_sdcard_attached() && make_sdcard_lock_os(sdcard_img_path)) { - do_hotplug(ATTACH_SDCARD, sdcard_img_path, strlen(sdcard_img_path) + 1); + char* sdcard_full_path = get_sdcard_full_path(dataBuf + 2, dataLen); + LOG_TRACE("sdcard_full_path: %s\n", sdcard_full_path); + if (!is_sdcard_attached() && make_sdcard_lock_os(sdcard_full_path)) { + do_hotplug(ATTACH_SDCARD, sdcard_full_path, strlen(sdcard_full_path) + 1); make_send_device_ntf((char*)MSG_TYPE_SDCARD, GROUP_SDCARD, - ACT_SDCARD_ATTACH, g_path_get_basename(sdcard_img_path)); + ACT_SDCARD_ATTACH, g_path_get_basename(sdcard_full_path)); } else { make_send_device_ntf((char*)MSG_TYPE_SDCARD, GROUP_SDCARD, - ACT_SDCARD_ATTACH_FAIL, g_path_get_basename(sdcard_img_path)); + ACT_SDCARD_ATTACH_FAIL, g_path_get_basename(sdcard_full_path)); } - g_free(sdcard_img_path); + g_free(sdcard_full_path); } else if (ret == '2') { send_sdcard_status(); diff --git a/tizen/src/emul_state.c b/tizen/src/emul_state.c index 4c65fab2e6..e092bfd002 100644 --- a/tizen/src/emul_state.c +++ b/tizen/src/emul_state.c @@ -763,6 +763,30 @@ const char *get_vm_data_path(void) return vm_data_path; } +const char *get_sdcard_image_path(void) +{ + const char *vm_data_path = get_vm_data_path(); +#ifndef CONFIG_WIN32 + const gchar* sdcard_rel_path = g_strdup_printf("%s/../../sdcard/", vm_data_path); +#else + const gchar* sdcard_rel_path = g_strdup_printf("%s\\..\\..\\sdcard\\", vm_data_path); +#endif + char sdcard_abs_path[PATH_MAX + 1]; + + char *ptr = realpath(sdcard_rel_path, sdcard_abs_path); + if (!ptr) { + LOG_WARNING("fail to get absolute path!\n"); + return sdcard_rel_path; + } +#ifndef CONFIG_WIN32 + const char *sdcard_path = g_strdup_printf("%s/", sdcard_abs_path); +#else + const char *sdcard_path = g_strdup_printf("%s\\", sdcard_abs_path); +#endif + LOG_INFO("SD card path: %s\n", sdcard_path); + return sdcard_path; +} + // display resolution // only set by vl.c when start up int initial_resolution_width = -1; diff --git a/tizen/src/emul_state.h b/tizen/src/emul_state.h index 12e68f0765..211d134aa0 100644 --- a/tizen/src/emul_state.h +++ b/tizen/src/emul_state.h @@ -187,6 +187,7 @@ const char *get_http_proxy_addr(void); const char *get_vm_name(void); const char *get_profile_name(void); const char *get_vm_data_path(void); +const char *get_sdcard_image_path(void); const char* get_host_directory_sharing_path(void); bool is_gpu_accel_enabled(void); diff --git a/tizen/src/emulator_common.h b/tizen/src/emulator_common.h index ad88358a21..bb297d32f0 100644 --- a/tizen/src/emulator_common.h +++ b/tizen/src/emulator_common.h @@ -46,7 +46,7 @@ #include #include #include - +#include #include "config-host.h" #ifdef CONFIG_DARWIN diff --git a/tizen/src/emulator_options.c b/tizen/src/emulator_options.c index c19e49eaea..473bc669bc 100644 --- a/tizen/src/emulator_options.c +++ b/tizen/src/emulator_options.c @@ -28,11 +28,11 @@ #include #include +#include #include "qemu/queue.h" #include "emulator_options.h" #include "emul_state.h" - #define LINE_LIMIT 1024 #define TOKEN_LIMIT 1024 #define OPTION_LIMIT 256 @@ -227,7 +227,7 @@ bool load_conf(const char * const conf) assert(!!conf); filename = g_strdup(conf); - file = fopen(filename, "r"); + file = fopen(filename, "r,css=UTF-8"); if (!file) { fprintf(stderr, "Profile configuration file [%s] is not found.\n", filename);