platform/android/Rhodes/src/com/rhomobile/rhodes/Utils.java in rhodes-2.0.3 vs platform/android/Rhodes/src/com/rhomobile/rhodes/Utils.java in rhodes-2.1.0

- old
+ new

@@ -24,26 +24,26 @@ return new FileInputStream(file); } }; public static class AssetsSource extends FileSource { - - private AssetManager amgr; + private AssetManager am; + public AssetsSource(AssetManager a) { - amgr = a; + am = a; } String[] list(String dir) throws IOException { - return amgr.list(dir); - }; + return am.list(dir); + } InputStream open(String file) throws IOException { - return amgr.open(file); + return am.open(file); } - }; + }; public static String getContent(InputStream in) throws IOException { String retval = ""; byte[] buf = new byte[512]; while(true) { @@ -72,24 +72,24 @@ if (stream1 != null) stream1.close(); if (stream2 != null) stream2.close(); } } - public static boolean deleteRecursively(File target) { + public static void deleteRecursively(File target) throws IOException { if (target.isDirectory()) { String[] children = target.list(); for(int i = 0; i != children.length; ++i) - if (!deleteRecursively(new File(target, children[i]))) - return false; + deleteRecursively(new File(target, children[i])); } - return target.delete(); + if (!target.delete()) + throw new IOException("Can not delete " + target.getAbsolutePath()); } public static void copyRecursively(FileSource fs, String source, File target, boolean remove) throws IOException { - if (remove && target.exists() && !deleteRecursively(target)) - throw new IOException("Can not delete " + target.getAbsolutePath()); + if (remove && target.exists()) + deleteRecursively(target); String[] children = fs.list(source); if (children != null && children.length > 0) { if (!target.exists()) target.mkdirs(); @@ -159,7 +159,23 @@ public static String getBaseName(String filePath) { if (filePath == null) return null; return new File(filePath).getName(); } - + + public static boolean isAppHashChanged() { + try { + RhodesService r = RhodesService.getInstance(); + File hash = new File(r.getRootPath(), "hash"); + if (!hash.exists()) + return true; + + FileSource as = new AssetsSource(r.getContext().getResources().getAssets()); + FileSource fs = new FileSource(); + return !Utils.isContentsEquals(as, "hash", fs, hash.getPath()); + } + catch (IOException e) { + return true; + } + } + }