예제 #1
0
  public LibrarySync(Context context) {
    mContext = context;
    mCachePath = ComicLibrary.getThumbCachePath();

    // Get sync preferences
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
    mSyncFld1 = prefs.getString("syncfolder1", "");
    mSyncFld2 = prefs.getString("syncfolder2", "");
    mIncImgFlds = prefs.getBoolean("syncImgFlds", false);
    mUseFldForSeries = prefs.getBoolean("syncFldForSeries", false);

    mCoverHeight = prefs.getInt("syncCoverHeight", 300);
    mCoverQuality = prefs.getInt("syncCoverQuality", 70);
  } // func
예제 #2
0
  /*========================================================
  Process : Create Thumbs, GetPage Count, Remove not found file*/
  private void processLibrary() {
    StringBuilder delList =
        new StringBuilder(); // Can't delete records with an open cursor, save IDs and delete later.
    // int[] outVar = {0,0}; //PageCount,IsCoverCreated
    String[] comicInfo = {"", "", ""}; // Page Count,Path to Cover Entry,Path to Meta Data
    String[] comicMeta; // Title,Series,Volume,Issue
    File file;
    String tmp, comicID, sql, comicPath, seriesName;
    iComicArchive archive;

    Cursor cur = mDb.raw("SELECT comicID,path,isCoverExists,series,title FROM ComicLibrary", null);
    SeriesParser sParser = null;

    for (boolean isOk = cur.moveToFirst(); isOk; isOk = cur.moveToNext()) {
      comicID = cur.getString(0);
      comicPath = cur.getString(1);
      file = new File(comicPath);

      // .........................................
      // if file does not exist, remove from library.
      if (!file.exists()) {
        sendProgress("Removing reference to " + cur.getString(1));
        delList.append(",'" + comicID + "'"); // add id to list

        try { // delete thumbnail if available
          file = new File(mCachePath + comicID + ".jpg");
          if (file.exists()) file.delete();
        } catch (Exception e) {
        }

        continue;
      } // if

      // .........................................
      // if thumb has not been generated.
      if (cur.getString(2).equals("0")) {
        sendProgress("Creating thumbnail for " + comicPath);
        archive = ComicLoader.getArchiveInstance(comicPath);
        archive.getLibraryData(comicInfo);

        // No images in archive, then delete
        if (comicInfo[0] == "0") {
          delList.append(",'" + comicID + "'");
          continue;
        } // if

        sql = "pgCount=" + comicInfo[0]; // Start Building the update query.
        // Create ThumbNail
        if (ComicLibrary.createThumb(
            mCoverHeight, mCoverQuality, archive, comicInfo[1], mCachePath + comicID + ".jpg"))
          sql += ",isCoverExists=1";

        // Get Meta Information
        comicMeta = archive.getMeta(); // Title,Series,Volume,Issue
        if (comicMeta != null) {
          if (!comicMeta[0].isEmpty())
            sql += ",title = '" + comicMeta[0].replaceAll("'", "''") + "'";
          if (!comicMeta[1].isEmpty())
            sql += ",series = '" + comicMeta[1].replaceAll("'", "''") + "'";
        } // if}

        // Save information to the db.
        mDb.execSql(
            String.format("UPDATE ComicLibrary SET %s WHERE comicID = '%s'", sql, comicID), null);
        if (comicMeta != null && comicMeta[1] != "")
          continue; // Since series was updated from meta, Don't continue the rest of the loop which
                    // handles the series
      } // if

      // .........................................
      // if series does not exist, create a series name.
      seriesName = cur.getString(3);
      if (seriesName == null
          || seriesName.isEmpty()
          || seriesName.compareToIgnoreCase(ComicLibrary.UKNOWN_SERIES) == 0) {
        if (mUseFldForSeries) seriesName = sage.io.Path.getParentName(comicPath);
        else {
          if (sParser == null) sParser = new SeriesParser(); // JIT
          seriesName = sParser.get(comicPath);

          // if seriesName ends up being the path, use the parent folder as the series name.
          if (seriesName == comicPath) seriesName = sage.io.Path.getParentName(comicPath);
        } // if

        if (!seriesName.isEmpty())
          mDb.execSql(
              String.format(
                  "UPDATE ComicLibrary SET series='%s' WHERE comicID = '%s'",
                  seriesName.replace("'", "''"), comicID),
              null);
      } // if
    } // for

    cur.close();
    cur = null;

    // .........................................
    // if there is a list of items to delete, do it now in one swoop.
    if (delList.length() > 0) {
      sendProgress("Cleaning up library...");
      mDb.execSql(
          String.format(
              "DELETE FROM ComicLibrary WHERE comicID in (%s)", delList.toString().substring(1)),
          null);
    } // if
  } // func