Esempio n. 1
0
  private void CopyAssets() {
    AssetManager assetManager = getAssets();
    String[] files = null;
    try {
      if (Build.VERSION.SDK_INT >= 21) files = assetManager.list("api-16");
      else files = assetManager.list("");
    } catch (IOException e) {
      Log.e(TAG, e.getMessage());
    }
    if (files != null) {
      for (String file : files) {
        InputStream in = null;
        OutputStream out = null;
        try {

          if (Build.VERSION.SDK_INT >= 21) in = assetManager.open("api-16/" + file);
          else in = assetManager.open(file);
          out = new FileOutputStream("/data/data/org.proxydroid/" + file);
          copyFile(in, out);
          in.close();
          in = null;
          out.flush();
          out.close();
          out = null;
        } catch (Exception e) {
          Log.e(TAG, e.getMessage());
        }
      }
    }
  }
Esempio n. 2
0
  private void copyDemoProject2() {
    AssetManager assetManager = getResources().getAssets();

    // now we copy soundscape.rss file
    String[] files2 = null;
    try {
      files2 = assetManager.list("rssDemoProject");
    } catch (Exception e) {
      Log.e("creation of RSS of Demo Project - ERROR", e.toString());
      e.printStackTrace();
    }
    for (int i = 0; i < files2.length; i++) {
      InputStream in = null;
      OutputStream out = null;
      try {
        in = assetManager.open("rssDemoProject/" + files2[i]);
        out = new FileOutputStream("/storage/emulated/0/notours/noToursDemo/" + files2[i]);
        copyFile(in, out);
        in.close();
        in = null;
        out.flush();
        out.close();
        out = null;
      } catch (Exception e) {
        Log.e("copy RSS of Demo - ERROR", e.toString());
        e.printStackTrace();
      }
    }

    // copy sounds
    String[] files = null;
    try {
      files = assetManager.list("soundsDemoProject");
    } catch (Exception e) {
      Log.e("creation of Sounds of Demo Project - ERROR", e.toString());
      e.printStackTrace();
    }
    for (int i = 0; i < files.length; i++) {
      InputStream in = null;
      OutputStream out = null;
      try {
        in = assetManager.open("soundsDemoProject/" + files[i]);
        out = new FileOutputStream("/storage/emulated/0/notours/noToursDemo/sound/" + files[i]);
        copyFile(in, out);
        in.close();
        in = null;
        out.flush();
        out.close();
        out = null;
      } catch (Exception e) {
        Log.e("copy sounds of Demo - ERROR", e.toString());
        e.printStackTrace();
      }
    }

    // end of for
  }
Esempio n. 3
0
  @Override
  public void onResume() {

    super.onResume();

    res = getResources();
    am = res.getAssets();

    String[] files = null;
    try {
      files = am.list("");
    } catch (IOException e) {
      e.printStackTrace();
    }

    fileList = null;
    if (files != null) {
      fileList = new ArrayList<String>();
      for (String file : files) {
        if (file.endsWith(".json")) fileList.add(file);
      }
      if (fileList.size() > 0) {
        ImportFileAdapter fileAdapter =
            new ImportFileAdapter(this, android.R.layout.simple_list_item_1, fileList);
        ListView listView = (ListView) findViewById(R.id.import_list);
        listView.setAdapter(fileAdapter);
        listView.setOnItemClickListener(fileClickListener);
        fileAdapter.notifyDataSetChanged();
      }
    }
  }
Esempio n. 4
0
  void writeToSDCard() {

    OutputStream outputStream = null;
    try {
      AssetManager am = getAssets();
      String[] files = am.list("");

      InputStream is = am.open(fileName);

      File file = new File(Environment.getExternalStorageDirectory(), fileName);
      outputStream = new FileOutputStream(file);
      int read = 0;
      byte[] bytes = new byte[1024];

      while ((read = is.read(bytes)) != -1) {
        outputStream.write(bytes, 0, read);
      }
      is.close();
      outputStream.close();

    } catch (FileNotFoundException e) {
      // handle exception
    } catch (IOException e) {
      // handle exception
    }
  }
  public static void firstTimeServerSetup(final Context context) {
    final AssetManager assetManager = context.getAssets();
    final String[] files;
    try {
      files = assetManager.list("");
      for (String filename : files) {
        if (filename.endsWith(".xml")) {
          final InputStream in = assetManager.open(filename);
          final File outFile = new File(getSharedPreferencesPath(context));
          if (outFile.exists() || outFile.mkdir()) {
            final File file = new File(getSharedPreferencesPath(context), filename);
            final FileOutputStream out = new FileOutputStream(file);

            byte[] buffer = new byte[2048];
            int read;
            while ((read = in.read(buffer)) != -1) {
              out.write(buffer, 0, read);
            }

            in.close();
            out.flush();
            out.close();
          }
        }
      }
    } catch (final IOException e) {
      e.printStackTrace();
    }
  }
 /**
  * assetsフォルダ内のSQLファイルを実行します。<br>
  * ファイル内に複数のSQL文を記述する場合、区切り文字("@@")でSQL文を分割します。
  *
  * @param db データベース
  * @param assetsDir assetsフォルダ内のフォルダのパス
  * @throws IOException
  */
 private void execSql(SQLiteDatabase db, String assetsDir) throws IOException {
   // **********************************************************************
   // * assetsフォルダ内のSQLファイルを実行する
   // **********************************************************************
   AssetManager as = this.context.getResources().getAssets();
   try {
     // assetsフォルダ配下のファイルを取得する
     String files[] = as.list(assetsDir);
     // ファイルの件数分ループする
     for (int i = 0; i < files.length; i++) {
       // SQLファイルを読み込む
       String sql_str = IOUtils.readFile(as.open(assetsDir + "/" + files[i]), "UTF-8");
       // 区切り文字("@@")で分割した件数分ループする
       for (String sql : sql_str.split("@@")) {
         // SQL文字列が存在する場合
         if (sql != null && sql.length() > 0) {
           // SQLを実行する
           db.execSQL(sql);
         }
       }
     }
   }
   // 例外が発生した場合:[入出力例外]
   catch (IOException ioe) {
     ioe.printStackTrace();
   }
   // 例外が発生した場合:[一般例外]
   catch (Exception e) {
     e.printStackTrace();
   }
 }
Esempio n. 7
0
 private void dumpAssets(AssetManager assetManager) {
   String path = "www";
   try {
     if (assetManager == null) {
       Log.w(LOGTAG, "AssetManager null");
       return;
     }
     String[] list;
     try {
       list = assetManager.list(path);
     } catch (IOException e) {
       Log.w(LOGTAG, "Error listing assets: " + path, e);
       return;
     }
     if (list == null) {
       Log.w(LOGTAG, "Asset list null");
       return;
     }
     for (String s : list) {
       Log.w(LOGTAG, "Found asset: " + s);
     }
   } catch (Exception e) {
     Log.w(LOGTAG, "Error while dumping files in " + path, e);
   }
 }
Esempio n. 8
0
  private static void writeStaticAssets(AssetManager assets, ZipOutputStream out, String path) {
    try {
      for (String item : assets.list(path)) {
        try {
          InputStream fileIn = assets.open(path + "/" + item);

          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          BufferedInputStream bin = new BufferedInputStream(fileIn);

          byte[] buffer = new byte[8192];
          int read = 0;

          while ((read = bin.read(buffer, 0, buffer.length)) != -1) {
            baos.write(buffer, 0, read);
          }

          bin.close();
          baos.close();

          ZipEntry entry = new ZipEntry(path + "/" + item);
          out.putNextEntry(entry);
          out.write(baos.toByteArray());
          out.closeEntry();
        } catch (IOException e) {
          BootstrapSiteExporter.writeStaticAssets(assets, out, path + "/" + item);
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Esempio n. 9
0
 /** svg image on sdcard */
 public static void unpackOnSdCard(AssetManager assetManager) throws IOException {
   if (Environment.getExternalStorageState().compareTo(Environment.MEDIA_MOUNTED) == 0) {
     File sdcard = Environment.getExternalStorageDirectory();
     String irrlichtPath = sdcard.getAbsoluteFile() + "/Irrlicht/";
     File irrlichtDir = new File(irrlichtPath);
     if (irrlichtDir.exists() && !irrlichtDir.isDirectory()) {
       throw new IOException("Irrlicht exists and is not a directory on SD Card");
     } else if (!irrlichtDir.exists()) {
       irrlichtDir.mkdirs();
     }
     // Note: /sdcard/irrlicht dir exists
     String[] filenames = assetManager.list("data");
     for (String filename : filenames) {
       InputStream inputStream = assetManager.open("data/" + filename);
       OutputStream outputStream = new FileOutputStream(irrlichtPath + "/" + filename);
       // copy
       byte[] buffer = new byte[4096];
       int length;
       while ((length = inputStream.read(buffer)) > 0) {
         outputStream.write(buffer, 0, length);
       }
       outputStream.flush();
       outputStream.close();
       inputStream.close();
     }
   } else {
     throw new IOException("SD Card not available");
   }
 }
  public static void unpackAssets(Context context, Handler handler) {
    Log.i(TAG, "Setting up assets in " + app_opt);
    try {
      FileUtils.deleteDirectory(app_opt);
    } catch (IOException e) {
      e.printStackTrace();
    }
    setupEmptyDirs();
    writeShProfile();

    AssetManager am = context.getAssets();
    final String[] assetList;
    try {
      assetList = am.list("");
    } catch (IOException e) {
      Log.e(TAG, "cannot get asset list", e);
      return;
    }
    // unpack the assets to app_opt
    for (String asset : assetList) {
      if (asset.equals("images")
          || asset.equals("sounds")
          || asset.equals("webkit")
          || asset.equals("databases") // Motorola
          || asset.equals("kioskmode")) // Samsung
      continue;
      Log.i(TAG, "copying asset: " + asset);
      showMessageInDialog("unpacking '" + asset + "'...", handler);
      copyFileOrDir(asset, app_opt);
    }

    Posix.chmod("0755", app_opt, true);
    writeVersionFile(context);
  }
Esempio n. 11
0
  public void resetQuiz() {
    AssetManager assets = getActivity().getAssets();
    fileNameList.clear();

    try {
      String[] paths = assets.list("Flag");

      for (String path : paths) {
        fileNameList.add(path.replace(".png", ""));
      }
    } catch (IOException e) {
      Log.e(TAG, "Error", e);
    }

    questionNumber = 0;
    totalGuesses = 0;
    flagflagList.clear();

    int flagCounter = 1;
    int numberOfflags = fileNameList.size();

    while (flagCounter <= NUMBER_OF_QUESTIONS) {
      int randomIndex = random.nextInt(numberOfflags);

      String fileName = fileNameList.get(randomIndex);

      if (!flagflagList.contains(fileName)) {
        flagflagList.add(fileName);
        ++flagCounter;
      }
    }
    //        scoreTimer.scheduleAtFixedRate(scoreTask, 0, 800);

    loadNextFlag();
  }
Esempio n. 12
0
  public static @NonNull LinkedList<ThemeInfo> enumerateThemes(@NonNull Context context) {
    LinkedList<ThemeInfo> themes = new LinkedList<>();
    AssetManager manager = context.getAssets();

    // load themes from assets
    try {
      String[] builtin_themes = manager.list("");
      for (String theme : builtin_themes) {
        if (!theme.toLowerCase().endsWith("theme.properties")) continue;
        Properties p = loadColorScheme(theme, manager);
        if (p != null) themes.add(new ThemeInfo(p.getProperty("NAME", theme), theme));
      }
    } catch (IOException e) {
      e.printStackTrace();
    }

    // load themes from disk
    File dir = new File(SEARCH_DIR);
    if (dir.exists()) {
      File[] files = dir.listFiles();
      if (files != null) {
        for (File file : files) {
          if (!file.getName().toLowerCase().endsWith("theme.properties")) continue;
          Properties p = loadColorScheme(file.getAbsolutePath(), null);
          if (p != null)
            themes.add(
                new ThemeInfo(p.getProperty("NAME", file.getName()), file.getAbsolutePath()));
        }
      }
    }
    return themes;
  }
Esempio n. 13
0
  private void qaulCopyFileOrDir(String path) {
    AssetManager assetManager = this.getAssets();
    String assets[] = null;
    try {
      Log.i(MSG_TAG, "copyFileOrDir() " + path);
      assets = assetManager.list(path);
      if (assets.length == 0) {
        qaulCopyFile(path);
      } else {
        String fullPath = dataPathString + "/" + path;
        Log.i(MSG_TAG, "path=" + fullPath);
        File dir = new File(fullPath);
        if (!dir.exists()
            && !path.startsWith("images")
            && !path.startsWith("sounds")
            && !path.startsWith("webkit")) if (!dir.mkdirs()) ;
        Log.i(MSG_TAG, "could not create dir " + fullPath);
        for (int i = 0; i < assets.length; ++i) {
          String p;
          if (path.equals("")) p = "";
          else p = path + "/";

          if (!path.startsWith("images")
              && !path.startsWith("sounds")
              && !path.startsWith("webkit")) qaulCopyFileOrDir(p + assets[i]);
        }
      }
    } catch (IOException ex) {
      Log.e(MSG_TAG, "I/O Exception", ex);
    }
  }
Esempio n. 14
0
  public void buildData() {

    try {
      _files = _assMan.list("files");
    } catch (IOException e) {
      e.printStackTrace();
    }

    for (int i = 0; i < _files.length; ++i) {
      Scanner scan;
      HashMap<String, Integer> hash;
      try {
        scan = new Scanner(_assMan.open(_files[i]));
        hash = new HashMap<String, Integer>();

        while (scan.hasNext()) {
          String[] current = scan.nextLine().split(" ");
          hash.put(current[0], Integer.valueOf(current[1]));
        }
        _map.put(_files[i].split(".")[0], hash);
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
Esempio n. 15
0
  private void resetQuiz() {
    AssetManager assets = getAssets();
    filenameList.clear();
    try {
      Set<String> regions = regionsMap.keySet();
      for (String region : regions) {
        if (regionsMap.get(region)) {
          String[] paths = assets.list(region);
          for (String path : paths) {
            filenameList.add(path.replace(".png", ""));
          }
        }
      }
    } catch (IOException e) {
      Log.e(TAG, "Error loading image file names", e);
    }
    correctAnswers = 0;
    totalGuesses = 0;

    quizCountriesList.clear();
    int flagCounter = 1;
    int numberOfFlags = filenameList.size();

    while (flagCounter <= 10) {
      int randomIndex = random.nextInt(numberOfFlags);
      String fileName = filenameList.get(randomIndex);
      if (!quizCountriesList.contains(fileName)) {
        quizCountriesList.add(fileName);
        ++flagCounter;
      }
    }
    loadNextFlag();
  }
 private void copyVideoToCard() {
   // open file in assets
   AssetManager assetManager = getAssets();
   String[] videoAsset = null;
   try {
     videoAsset = assetManager.list(folder);
   } catch (IOException e) {
     Log.e(TAG, e.getMessage());
   }
   InputStream in = null;
   OutputStream out = null;
   try {
     int assetIndex = MyApp.config().getInt("videoassetnumber", 0);
     if (assetIndex > videoAsset.length) {
       assetIndex = videoAsset.length - 1;
     }
     in = assetManager.open(folder + "/" + videoAsset[assetIndex]);
     out = new FileOutputStream("/sdcard/" + videoName);
     // actually copy over file
     byte[] buffer = new byte[1024];
     int read;
     while ((read = in.read(buffer)) != -1) {
       out.write(buffer, 0, read);
     }
     // close up everything
     in.close();
     in = null;
     out.flush();
     out.close();
     out = null;
     // assetManager.close();
   } catch (Exception e) {
     Log.e(TAG, e.getMessage());
   }
 }
Esempio n. 17
0
  public static void copyFileFromSdcard(AssetManager assetManager) {
    // AssetManager assetManager = getAssets();
    String[] files = null;
    try {
      files = assetManager.list("");
    } catch (IOException e) {
      Log.e("", e.getMessage());
    }
    String strSdcardPath = "/sdcard/irrlicht/";
    String strDestFile;
    int iFileCnt = files.length;
    for (int i = 0; i < iFileCnt; i++) {
      String strFileNameSrc = files[i];
      if (strFileNameSrc.contentEquals("images")
          || strFileNameSrc.contentEquals("sounds")
          || strFileNameSrc.contentEquals("skins")
          || strFileNameSrc.contentEquals("webkit")) {

        // dont copy.. not really a asset file
        continue;
      }
      strDestFile = strSdcardPath + strFileNameSrc;
      VxCopyAsssetToSdcard(strFileNameSrc, strDestFile, assetManager, true);
    }
  }
Esempio n. 18
0
 public static void assetsCopy(Context c, String assetsPath, String dirPath) throws IOException {
   AssetManager manager = c.getAssets();
   String[] list = manager.list(assetsPath);
   if (list.length == 0) { // 文件
     InputStream in = manager.open(assetsPath);
     File file = new File(dirPath);
     file.getParentFile().mkdirs();
     file.createNewFile();
     FileOutputStream fout = new FileOutputStream(file);
     /* 复制 */
     byte[] buf = new byte[1024];
     int count;
     while ((count = in.read(buf)) != -1) {
       fout.write(buf, 0, count);
       fout.flush();
     }
     /* 关闭 */
     in.close();
     fout.close();
   } else { // 目录
     for (String path : list) {
       assetsCopy(c, assetsPath + "/" + path, dirPath + "/" + path);
     }
   }
 }
 public static boolean exists(String fileName, String path, AssetManager assetManager)
     throws IOException {
   for (String currentFileName : assetManager.list(path)) {
     if (currentFileName.equals(fileName)) {
       return true;
     }
   }
   return false;
 }
Esempio n. 20
0
  public static Bitmap[] load(String src, int width, int height) {
    Bitmap[] texture = null;
    InputStream is = null;
    AssetManager am = resources.getAssets();
    String[] nameOfBoxs = null;

    try {
      nameOfBoxs = am.list(src);
    } catch (IOException e) {
      Log.d("GraphicMaster", "Culd not find folder " + src);
    }

    Log.d("GraphicMaster", "NameOfBoxs.length = " + nameOfBoxs.length);
    texture = new Bitmap[nameOfBoxs.length];

    for (int i = 0; i < nameOfBoxs.length; i++) {
      try {
        is = resources.getAssets().open(src + "/" + nameOfBoxs[i]);

        texture[i] = BitmapFactory.decodeStream(is);

        /*	if(width > 0 && height > 0)
        texture[i] = Bitmap.createScaledBitmap(texture[i], width, height, false);*/

        Log.d(
            "GraphicMaster",
            "Scaled from "
                + new Integer((int) (texture[i].getWidth())).toString()
                + " "
                + new Integer((int) (texture[i].getHeight())).toString()
                + " to "
                + new Integer((int) (texture[i].getWidth() * GameSettings.widthM)).toString()
                + " "
                + new Integer((int) (GameSettings.heightM * texture[i].getWidth())).toString());

        Log.d(
            "GraphicMaster",
            "Scale"
                + new Double(GameSettings.widthM).toString()
                + " "
                + new Double(GameSettings.heightM).toString());

        if (GameSettings.widthM != 1 && GameSettings.heightM != 1)
          texture[i] =
              Bitmap.createScaledBitmap(
                  texture[i],
                  (int) (texture[i].getWidth() * GameSettings.widthM),
                  (int) (texture[i].getHeight() * GameSettings.heightM),
                  false);

      } catch (IOException e) {
        Log.d("GraphicMaster", "Culd not read: " + src + nameOfBoxs[i]);
      }
    }

    return texture;
  }
Esempio n. 21
0
    private void extractResources() {
      final File dataDir = new File(PathUtils.getDataDirectory(mContext));

      final String timestamp = checkTimestamp(dataDir);
      if (timestamp != null) {
        deleteFiles();
      }

      final AssetManager manager = mContext.getResources().getAssets();
      try {
        byte[] buffer = null;
        final String[] assets = manager.list("");
        for (String asset : assets) {
          if (!mResources.contains(asset)) continue;
          final File output = new File(dataDir, asset);
          if (output.exists()) continue;
          InputStream is = null;
          OutputStream os = null;
          try {
            is = manager.open(asset);
            os = new FileOutputStream(output);
            if (buffer == null) {
              buffer = new byte[BUFFER_SIZE];
            }

            int count = 0;
            while ((count = is.read(buffer, 0, BUFFER_SIZE)) != -1) {
              os.write(buffer, 0, count);
            }
            os.flush();
          } finally {
            try {
              if (is != null) {
                is.close();
              }
            } finally {
              if (os != null) {
                os.close();
              }
            }
          }
        }
      } catch (IOException e) {
        Log.w(TAG, "Exception unpacking resources: " + e.getMessage());
        deleteFiles();
        return;
      }

      if (timestamp != null) {
        try {
          new File(dataDir, timestamp).createNewFile();
        } catch (IOException e) {
          Log.w(TAG, "Failed to write resource timestamp");
        }
      }
    }
 public boolean isDirectory() {
   if (type == AltFileType.Internal) {
     try {
       return assets.list(file.getPath()).length > 0;
     } catch (IOException ex) {
       return false;
     }
   }
   return super.isDirectory();
 }
Esempio n. 23
0
  /** Copy all Assets by Type to the local storage returns boolean Uses by InitialActivity */
  public static boolean copyAssets(Context context, String assetType, boolean rewrite) {
    Log.d(TAG, "copyAssets(), assetType=" + assetType);

    // Get asset manager and define list of files to copy
    AssetManager assetManager = context.getAssets();
    String[] files = null;
    try {
      files = assetManager.list(assetType);
    } catch (IOException ioe) {
      // exit if something wrong with assets
      Log.d(TAG, "copyAssets(),Failed to get asset file list.", ioe);
      return false;
    }
    // copy files if exists
    for (String fileName : files) {
      InputStream in = null;
      OutputStream out = null;
      File outFile = null;

      // define full path to outFile (depends of asset_type)
      if (assetType == TYPE_DATABASE) {
        // check if database directory exists and create if necessary
        File dir = new File(context.getDatabasePath(fileName).getParent());
        if (!dir.exists()) dir.mkdirs(); // create folders where write files
        outFile = context.getDatabasePath(fileName);
      } else {
        outFile = new File(context.getExternalFilesDir(assetType), fileName);
      }
      // copy file from asset if file doesn't exists or it need to be rewrited
      if (rewrite || (!outFile.exists())) {
        try {
          // get input stream from Assets
          in = new BufferedInputStream(assetManager.open(assetType + "/" + fileName), BUFFER_SIZE);
          out = new BufferedOutputStream(new FileOutputStream(outFile), BUFFER_SIZE);
          // copy from in to out
          copyFile(in, out);
        } catch (IOException ioe) {
          Log.e(TAG, "copyAssets(), Failed to copy asset: " + fileName, ioe);
        } finally {
          // try to close input stream
          try {
            in.close();
          } catch (IOException ein) {
            Log.e(TAG, "copyAssets(), filed to close in, file: " + fileName, ein);
          }
          try {
            out.close();
          } catch (IOException eout) {
            Log.e(TAG, "copyAssets(), filed to close out, file: " + fileName, eout);
          }
        }
      }
    }
    return true;
  }
  private List<String> listFiles(String dirFrom) throws IOException {
    Resources res = getResources();
    AssetManager am = res.getAssets();
    String fileList[] = am.list(dirFrom);

    if (fileList != null) {
      for (int i = 0; i < fileList.length; i++) {
        Log.d("", fileList[i]);
      }
    }
    return (List<String>) Arrays.asList(fileList);
  }
Esempio n. 25
0
  public static boolean exists(AssetManager assetManager, String source) {
    try {
      String[] s = assetManager.list(source);
      if (s == null || s.length == 0) {
        return false;
      }

      return true;
    } catch (IOException e) {
      return false;
    }
  }
 public AltFileHandle[] list() {
   if (type == AltFileType.Internal) {
     try {
       String[] relativePaths = assets.list(file.getPath());
       AltFileHandle[] handles = new AltFileHandle[relativePaths.length];
       for (int i = 0, n = handles.length; i < n; i++)
         handles[i] = new AltAndroidFileHandle(assets, new File(file, relativePaths[i]), type);
       return handles;
     } catch (Exception ex) {
       throw new RuntimeException("Error listing children: " + file + " (" + type + ")", ex);
     }
   }
   return super.list();
 }
Esempio n. 27
0
 private void deployResources() {
   AssetManager assetManager = this.getAssets();
   try {
     String[] files = assetManager.list(DEPLOY_RESOURCES_DIR_NAME);
     String deployTargetDir = this.getFilesDir().getAbsolutePath();
     for (String filename : files) {
       copyAsset(DEPLOY_RESOURCES_DIR_NAME + "/" + filename, deployTargetDir + "/" + filename);
     }
     SetDataLocation(deployTargetDir);
   } catch (IOException e) {
     Log.e(TAG, "Failed to deploy necessary assets!");
     e.printStackTrace();
   }
 }
Esempio n. 28
0
 private static void listFontFiles(AssetManager assets, Collection<String> fonts, String path) {
   try {
     String[] list = assets.list(path);
     if (list.length > 0) {
       // it's a folder
       for (String file : list) {
         String prefix = "".equals(path) ? "" : path + File.separator;
         listFontFiles(assets, fonts, prefix + file);
       }
     } else if (path.endsWith("ttf")) {
       // it's a font file
       fonts.add(path);
     }
   } catch (IOException ignore) {
   }
 }
 private String[] listAssets(String assetPath) throws IOException {
   if (assetPath.startsWith("/")) {
     assetPath = assetPath.substring(1);
   }
   lazyInitCaches();
   String[] ret = listCache.get(assetPath);
   if (ret == null) {
     if (listCacheFromFile) {
       ret = new String[0];
     } else {
       ret = assetManager.list(assetPath);
       listCache.put(assetPath, ret);
     }
   }
   return ret;
 }
  @Override
  public String call() throws IOException {
    AssetManager assMan = mParent.getResources().getAssets();
    File cacheDir = mParent.getCacheDir();
    String dataDirName = "tessdata";
    File tessCacheDir = new File(cacheDir, dataDirName);
    boolean succeeded = false;
    for (int tries = 0; !succeeded; tries++) {
      InputStream istream = null;
      FileOutputStream ostream = null;
      try {
        if (!(tessCacheDir.mkdir() || tessCacheDir.isDirectory()))
          throw new IOException("Couldn't create tessCacheDir " + tessCacheDir.toString());

        //                List<String> cacheDirFiles = Arrays.asList(tessCacheDir.list(new
        // FilenameFilter() {
        //                    @Override public boolean accept(File dir, String filename) { return
        // filename.endsWith(".traineddata"); }
        //                }));

        String[] tessDataFilenames = assMan.list(dataDirName);
        for (String dataFilename : tessDataFilenames) {
          //                    if (cacheDirFiles.contains(dataFilename))
          //                        continue;

          istream = assMan.open(dataDirName + "/" + dataFilename, AssetManager.ACCESS_STREAMING);
          ostream = new FileOutputStream(new File(tessCacheDir, dataFilename));
          byte[] buffer = new byte[0x80000];
          int bytes_read;
          while ((bytes_read = istream.read(buffer)) != -1) ostream.write(buffer, 0, bytes_read);
        }
        succeeded = true;
      } catch (IOException ioe) {
        if (tries >= 3) throw ioe;
        try {
          Thread.sleep(1000);
        } catch (InterruptedException ie) {
        }
      } finally {
        if (istream != null) istream.close();
        if (ostream != null) ostream.close();
      }
    }
    return cacheDir.getAbsolutePath();
  }