From 3d203a4e4d37b1cf6666712cb44495ef97eb5e8c Mon Sep 17 00:00:00 2001 From: "Rui Zhao (renyuneyun)" Date: Thu, 10 May 2018 00:18:18 +0100 Subject: [PATCH] Fix exporting and importing (of "script" and "condition") --- app/src/main/java/ryey/easer/core/data/Helper.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/ryey/easer/core/data/Helper.java b/app/src/main/java/ryey/easer/core/data/Helper.java index cafef3cd..32e3e720 100644 --- a/app/src/main/java/ryey/easer/core/data/Helper.java +++ b/app/src/main/java/ryey/easer/core/data/Helper.java @@ -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; @@ -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)) {