コード例 #1
0
ファイル: LocalPath.cpp プロジェクト: Mrdini/XCSoar
static TCHAR *
FindDataPath()
{
  if (is_altair() && is_embedded())
    /* hard-coded path for Altair */
    return _tcsdup(_T("\\NOR Flash"));

  if (is_android()) {
    /* XXX use Environment.getExternalStorageDirectory() */

#ifdef ANDROID
    /* hack for Samsung Galaxy S and Samsung Galaxy Tab (which has a
       build-in and an external SD card) */
    struct stat st;
    if (stat("/sdcard/external_sd", &st) == 0 &&
        (st.st_mode & S_IFDIR) != 0 &&
        fgrep("/proc/mounts", "/sdcard/external_sd "))
      return strdup("/sdcard/external_sd/XCSoarData");
#endif

    /* hard-coded path for Android */
    return _tcsdup(_T("/sdcard/XCSoarData"));
  }

#ifdef _WIN32_WCE
  /* if XCSoar was started from a flash disk, put the XCSoarData onto
     it, too */
  {
    TCHAR buffer[MAX_PATH];
    if (ModuleInFlash(NULL, buffer) != NULL) {
      _tcscat(buffer, _T(DIR_SEPARATOR_S));
      _tcscat(buffer, XCSDATADIR);
      if (Directory::Exists(buffer))
        return _tcsdup(buffer);
    }

    /* if a flash disk with XCSoarData exists, use it */
    if (ExistingDataOnFlash(buffer) != NULL)
      return _tcsdup(buffer);
  }
#endif

  {
    TCHAR buffer[MAX_PATH];
    const TCHAR *path = GetHomeDataPath(buffer);
    if (path != NULL)
      return _tcsdup(path);
  }

  return NULL;
}
コード例 #2
0
ファイル: LocalPath.cpp プロジェクト: LK8000/LK8000
static
void getExternalStoragePublicDirectory(TCHAR* szPath, size_t MaxSize) {
    /* on Samsung Galaxy S4 (and others), the "external" SD card is
       mounted here */
    if (lk::filesystem::isDirectory(_T("/mnt/extSdCard" LKDATADIR))
        && access(_T("/mnt/extSdCard" LKDATADIR),W_OK) == 0) {
        /* found writable XCSoarData: use this SD card */
        _tcsncpy(szPath, _T("/mnt/extSdCard"), MaxSize);
        return;
    }

    /* hack for Samsung Galaxy S and Samsung Galaxy Tab (which has a
       built-in and an external SD card) */
    struct stat st;
    if (stat(ANDROID_SAMSUNG_EXTERNAL_SD, &st) == 0 &&
        S_ISDIR(st.st_mode) &&
        fgrep("/proc/mounts", ANDROID_SAMSUNG_EXTERNAL_SD " ", "tmpfs ")) {

        __android_log_print(ANDROID_LOG_DEBUG, "LK8000", "Enable Samsung hack : " ANDROID_SAMSUNG_EXTERNAL_SD);

        _tcsncpy(szPath, _T(ANDROID_SAMSUNG_EXTERNAL_SD), MaxSize);
        return;
    }

    /* try Context.getExternalStoragePublicDirectory() */
    if (Environment::getExternalStoragePublicDirectory(szPath, MaxSize, LKDATADIR) != nullptr) {
        TCHAR* szEnd = _tcsrchr(szPath, '/');
        if(szEnd) {
            *szEnd = _T('\0');
        }
        __android_log_print(ANDROID_LOG_DEBUG, "LK8000", "Environment.getExternalStoragePublicDirectory()='%s'", szPath);
        return;
    }

    /* now try Context.getExternalStorageDirectory(), because
       getExternalStoragePublicDirectory() needs API level 8 */
    if (Environment::getExternalStorageDirectory(szPath, MaxSize - 32) != nullptr) {
        return;
    }

    /* hard-coded path for Android */
    __android_log_print(ANDROID_LOG_DEBUG, "L8000", "Fallback : " ANDROID_SDCARD);

    _tcsncpy(szPath, _T(ANDROID_SDCARD), MaxSize);
}