Exemplo n.º 1
0
  /**
   * Constructor to load dictionary with given path.
   *
   * @param url Path of one of stardict file or Path of folder contains stardict files
   */
  public StarDict(String url) {
    File file = new File(url);

    if (!file.isDirectory()) {
      strURL = getFileNameWithoutExtension(url);
      Log.d(LOG_TAG, "strURL=" + strURL);
      ifoFile = new IfoFile(strURL + ".ifo");
      idxFile =
          new IdxFile(strURL + ".idx", ifoFile.getLongWordCount(), ifoFile.getLongIdxFileSize());
      dictFile = new DictFile(strURL + ".dict");
      Log.d(LOG_TAG, "done " + ifoFile.isBoolIsLoaded() + " " + idxFile.isLoaded() + " ");
    } else {
      String[] list = file.list();
      strURL = url;
      Log.d(LOG_TAG, "strURL=" + strURL);
      for (int i = list.length - 1; i >= 0; i--) {
        String extension = getExtension(list[i]);
        String path = url + File.separator + list[i];
        if (extension.equals("ifo")) {
          ifoFile = new IfoFile(path);
        } else if (extension.equals("idx")) {
          idxFile = new IdxFile(path, ifoFile.getLongWordCount(), ifoFile.getLongIdxFileSize());
        } else if (extension.equals("dict")) {
          dictFile = new DictFile(path);
        }
      }
    }

    if (ifoFile.isBoolIsLoaded() && idxFile.isLoaded()) {
      boolAvailable = true;
    }
  }
Exemplo n.º 2
0
  public static StarDict loadDict(String url) {
    File file = new File(url);
    String ifoFilePath;

    IfoFile ifoFile = null;
    IdxFile idxFile = null;
    DictFile dictFile = null;

    if (!file.isDirectory()) {
      String filePathNoExt = getFileNameWithoutExtension(url);
      //            LOG.debug("filePathNoExt=" + filePathNoExt);

      ifoFilePath = filePathNoExt + ".ifo";
      if (new File(ifoFilePath).isFile()) {
        ifoFile = new IfoFile(ifoFilePath);
      } else {
        return null;
      }

      idxFile =
          new IdxFile(
              filePathNoExt + ".idx", ifoFile.getLongWordCount(), ifoFile.getLongIdxFileSize());
      dictFile = new DictFile(filePathNoExt + ".dict");
    } else {
      String[] list = file.list();

      for (int i = list.length - 1; i >= 0; i--) {
        String extension = getExtension(list[i]);
        String path = url + File.separator + list[i];
        if (extension.equals("ifo")) {
          ifoFile = new IfoFile(path);
        } else if (extension.equals("idx")) {
          idxFile = new IdxFile(path, ifoFile.getLongWordCount(), ifoFile.getLongIdxFileSize());
        } else if (extension.equals("dict")) {
          dictFile = new DictFile(path);
        } else {
          continue;
        }
      }
    }

    if ((ifoFile == null) || (idxFile == null) || (dictFile == null)) {
      return null;
    }

    StarDict dict = new StarDict(ifoFile, idxFile, dictFile);
    return dict;
  }