コード例 #1
0
  public void testContainer() throws IOException, InterruptedException {

    storageHandler.copyImage(currentProjectName, testImage.getAbsolutePath(), null);

    String checksumImage = Utils.md5Checksum(testImage);

    FileChecksumContainer fileChecksumContainer = projectManager.getFileChecksumContainer();
    assertTrue(
        "Checksum isn't in container", fileChecksumContainer.containsChecksum(checksumImage));

    // wait to get a different timestamp on next file
    Thread.sleep(2000);

    File newTestImage =
        storageHandler.copyImage(currentProjectName, testImage.getAbsolutePath(), null);
    File imageDirectory =
        new File(
            Constants.DEFAULT_ROOT
                + "/"
                + currentProjectName
                + "/"
                + Constants.IMAGE_DIRECTORY
                + "/");
    File[] filesImage = imageDirectory.listFiles();

    // nomedia file is also in images folder
    assertEquals("Wrong amount of files in folder", 2, filesImage.length);

    File newTestSound = storageHandler.copySoundFile(testSound.getAbsolutePath());
    String checksumSound = Utils.md5Checksum(testSound);
    assertTrue(
        "Checksum isn't in container", fileChecksumContainer.containsChecksum(checksumSound));
    File soundDirectory =
        new File(
            Constants.DEFAULT_ROOT + "/" + currentProjectName + "/" + Constants.SOUND_DIRECTORY);
    File[] filesSound = soundDirectory.listFiles();

    // nomedia file is also in sounds folder
    assertEquals("Wrong amount of files in folder", 2, filesSound.length);

    fileChecksumContainer.decrementUsage(newTestImage.getAbsolutePath());
    assertTrue("Checksum was deleted", fileChecksumContainer.containsChecksum(checksumImage));
    fileChecksumContainer.decrementUsage(newTestImage.getAbsolutePath());
    assertFalse("Checksum wasn't deleted", fileChecksumContainer.containsChecksum(checksumImage));
    fileChecksumContainer.decrementUsage(newTestSound.getAbsolutePath());
    assertFalse("Checksum wasn't deleted", fileChecksumContainer.containsChecksum(checksumSound));
  }
コード例 #2
0
ファイル: SpeakAction.java プロジェクト: sy1121/thor
  public void setText(String text) {
    if (text == null) {
      text = "";
    }
    this.text = text;

    hashText = Utils.md5Checksum(text);
    String fileName = hashText;
    File pathToSpeechFile = new File(Constants.TEXT_TO_SPEECH_TMP_PATH);
    pathToSpeechFile.mkdirs();
    speechFile = new File(pathToSpeechFile, fileName + Constants.TEXT_TO_SPEECH_EXTENSION);
  }
コード例 #3
0
ファイル: LookFragment.java プロジェクト: vidak92/Catroid
  private void loadPocketPaintImageIntoCatroid(Intent intent) {
    Bundle bundle = intent.getExtras();
    String pathOfPocketPaintImage = bundle.getString(Constants.EXTRA_PICTURE_PATH_POCKET_PAINT);

    int[] imageDimensions = ImageEditing.getImageDimensions(pathOfPocketPaintImage);
    if (imageDimensions[0] < 0 || imageDimensions[1] < 0) {
      Utils.showErrorDialog(getActivity(), this.getString(R.string.error_load_image));
      return;
    }

    String actualChecksum = Utils.md5Checksum(new File(pathOfPocketPaintImage));

    // If look changed --> saving new image with new checksum and changing lookData
    if (!selectedLookData.getChecksum().equalsIgnoreCase(actualChecksum)) {
      String oldFileName = selectedLookData.getLookFileName();
      String newFileName = oldFileName.substring(oldFileName.indexOf('_') + 1);

      // HACK for https://github.com/Catrobat/Catroid/issues/81
      if (!newFileName.endsWith(".png")) {
        newFileName = newFileName + ".png";
      }

      String projectName = ProjectManager.getInstance().getCurrentProject().getName();

      try {
        File newLookFile =
            StorageHandler.getInstance()
                .copyImage(projectName, pathOfPocketPaintImage, newFileName);
        File temporaryPictureFileInPocketPaint = new File(pathOfPocketPaintImage);
        temporaryPictureFileInPocketPaint.delete(); // delete temp file in paintroid

        StorageHandler.getInstance()
            .deleteFile(
                selectedLookData.getAbsolutePath()); // reduce usage in container or delete it

        selectedLookData.setLookFilename(newLookFile.getName());
        selectedLookData.resetThumbnailBitmap();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }