コード例 #1
0
  private void copyResourcesToLocal() {
    String name, sFileName;
    InputStream content;

    R.raw a = new R.raw();
    java.lang.reflect.Field[] t = R.raw.class.getFields();
    Resources resources = getResources();

    boolean succeed = true;

    for (int i = 0; i < t.length; i++) {
      try {
        name = resources.getText(t[i].getInt(a)).toString();
        sFileName = name.substring(name.lastIndexOf('/') + 1, name.length());
        content = getResources().openRawResource(t[i].getInt(a));
        content.reset();

        // perl project
        if (sFileName.endsWith(GlobalConstants.PERL_PROJECT_ZIP_NAME)) {
          succeed &= Utils.unzip(content, this.getFilesDir().getAbsolutePath() + "/", true);
        }
        // perl -> /data/data/com.android.perl/files/perl
        else if (sFileName.endsWith(GlobalConstants.PERL_ZIP_NAME)) {
          succeed &= Utils.unzip(content, this.getFilesDir().getAbsolutePath() + "/", true);
          FileUtils.chmod(new File(this.getFilesDir().getAbsolutePath() + "/perl/perl"), 0755);
        }
        // perl extras -> /sdcard/com.android.perl/perl/site-perl
        else if (sFileName.endsWith(GlobalConstants.PERL_EXTRAS_ZIP_NAME)) {
          Utils.createDirectoryOnExternalStorage(this.getPackageName() + "/" + "extras");
          Utils.createDirectoryOnExternalStorage(
              this.getPackageName() + "/" + "extras" + "/" + "tmp");
          succeed &=
              Utils.unzip(
                  content,
                  Environment.getExternalStorageDirectory().getAbsolutePath()
                      + "/"
                      + this.getPackageName()
                      + "/extras/",
                  true);
        }

      } catch (Exception e) {
        Log.e(GlobalConstants.LOG_TAG, "Failed to copyResourcesToLocal", e);
        succeed = false;
      }
    } // end for all files in res/raw
  }
コード例 #2
0
 private void createOurExternalStorageRootDir() {
   Utils.createDirectoryOnExternalStorage(this.getPackageName());
 }