Skip to content

Commit

Permalink
Fix exporting and importing (of "script" and "condition")
Browse files Browse the repository at this point in the history
  • Loading branch information
renyuneyun committed May 9, 2018
1 parent 18585d5 commit 3d203a4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions app/src/main/java/ryey/easer/core/data/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -40,23 +41,24 @@ public static void export_data(Context context, File dest) throws IOException {

File parent_dir = context.getFilesDir();

addDirToZip(zip, parent_dir, "event");
addDirToZip(zip, parent_dir, "scenario");
addDirToZip(zip, parent_dir, "profile");
for (File file : parent_dir.listFiles()) {
if (file.isDirectory())
addDirToZip(zip, parent_dir, file.getName());
}

zip.close();
}

private static boolean is_valid_easer_export_data(Context context, Uri uri) throws IOException {
final String re_top_level = "^[^/]+$";
final String re_any_of_three_any = "^(?:(?:event)|(?:profile)|(?:scenario))(?:/.*)?$";
final String re_any_of_valid_dirs = "^(?:(?:event)|(?:script)|(?:profile)|(?:scenario)|(?:condition))(?:/.*)?$";

InputStream inputStream = context.getContentResolver().openInputStream(uri);
ZipInputStream zip = new ZipInputStream(inputStream);
try {
for (ZipEntry entry = zip.getNextEntry(); entry != null; entry = zip.getNextEntry()) {
String name = entry.getName();
if (!name.matches(re_any_of_three_any)) {
if (!name.matches(re_any_of_valid_dirs)) {
return false;
}
if (name.matches(re_top_level)) {
Expand Down

0 comments on commit 3d203a4

Please sign in to comment.