| } | } | ||||
| private static class AsyncExtract extends AsyncTask<Void, Void, Integer> { | private static class AsyncExtract extends AsyncTask<Void, Void, Integer> { | ||||
| private final LinkedList<File> mExtractedFiles = new LinkedList<File>(); | |||||
| private final Context mContext; | private final Context mContext; | ||||
| private final int mRawResId; | private final int mRawResId; | ||||
| private final File mOutput; | private final File mOutput; | ||||
| while (!isCancelled() && ((entry = zipStream.getNextEntry()) != null)) { | while (!isCancelled() && ((entry = zipStream.getNextEntry()) != null)) { | ||||
| final File outputFile = new File(mOutput, entry.getName()); | final File outputFile = new File(mOutput, entry.getName()); | ||||
| mExtractedFiles.add(outputFile); | |||||
| if (entry.isDirectory()) { | if (entry.isDirectory()) { | ||||
| outputFile.mkdirs(); | outputFile.mkdirs(); | ||||
| FileUtils.chmod(outputFile); | FileUtils.chmod(outputFile); | ||||
| final String version = FileUtils.read(mContext.getResources().openRawResource(R.raw.espeakdata_version)); | final String version = FileUtils.read(mContext.getResources().openRawResource(R.raw.espeakdata_version)); | ||||
| final File outputFile = new File(mOutput, "espeak-data/version"); | final File outputFile = new File(mOutput, "espeak-data/version"); | ||||
| mExtractedFiles.add(outputFile); | |||||
| FileUtils.write(outputFile, version); | FileUtils.write(outputFile, version); | ||||
| successful = true; | successful = true; | ||||
| } | } | ||||
| if (isCancelled() || !successful) { | if (isCancelled() || !successful) { | ||||
| removeExtractedFiles(); | |||||
| return RESULT_CANCELED; | return RESULT_CANCELED; | ||||
| } | } | ||||
| return RESULT_OK; | return RESULT_OK; | ||||
| } | } | ||||
| private void removeExtractedFiles() { | |||||
| for (File extractedFile : mExtractedFiles) { | |||||
| if (!extractedFile.isDirectory()) { | |||||
| extractedFile.delete(); | |||||
| } | |||||
| } | |||||
| mExtractedFiles.clear(); | |||||
| } | |||||
| } | } | ||||
| } | } |