Пример #1
0
 @Override
 public boolean accept(File file) {
   if (file.getName().matches(NdsRom.ZIP_PATTERN)) {
     try {
       return NdsRom.isRomArchive(new ZipFile(file));
     } catch (IOException e) {
       return false;
     }
   }
   return false;
 }
Пример #2
0
  private void scanDirectory(File file, long last_scan, boolean recursive, int recursionLevel) {

    ContentValues vals = new ContentValues();
    NdsRom rom;
    InputStream stream;

    if (recursionLevel > 5)
      return; // if the ROMs are more than 5 layers deep... well... they'll just have to use the
    // file browser

    try {
      // Insert DB entries for all matching rom files
      for (File f : file.listFiles(ALL_ROMS_FILTER)) {
        vals.clear();

        rom = NdsRom.MakeRom(f);
        if (f == null) continue;

        vals.put("path", f.getAbsolutePath());
        vals.put("title", rom.getTitle());
        vals.put("gamecode", rom.getGameCode());

        DB.insertWithOnConflict("roms", null, vals, SQLiteDatabase.CONFLICT_IGNORE);
      }

      // Subdirectories
      if (recursive)
        for (File dir : file.listFiles(DIR_FILTER)) {
          if (dir.lastModified() > last_scan)
            scanDirectory(dir, last_scan, recursive, recursionLevel + 1);
        }
    } catch (Exception e) {
      // on my x86 emulator I'm not allowed to read /mnt/sdcard/.android_secure
      // if we get this, just skip the directory
      Log.d("nds4droid", "Unable to scan " + file.getAbsolutePath());
    }
  }
Пример #3
0
 public NdsRom[] getRoms() {
   if (roms == null) {
     final LinkedList<NdsRom> list = new LinkedList<NdsRom>();
     Cursor c = DB.query("roms", new String[] {"path"}, null, null, null, null, "title");
     while (c.moveToNext()) {
       final NdsRom rom = NdsRom.MakeRom(new File(c.getString(0)));
       if (rom == null) continue;
       list.add(rom);
     }
     roms = new NdsRom[list.size()];
     list.toArray(roms);
     c.close();
   }
   return roms;
 }