import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
+import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.logging.Level;
public static void CheckSDCardDir() {
File dir = new File(FilePathResources.getSDCardPath());
-
+
if (!dir.exists()) {
dir.mkdir();
}
Path source = Paths.get(FilePathResources.getBaseSdcardPath(), s);
Path target = Paths.get(FilePathResources.getSDCardPath(), s);
- if (!target.toFile().exists()) {
- try {
- Files.copy(source, target, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
- } catch (IOException e2) {
- EMLogger.getLogger().log(Level.WARNING, "Failed to create SD card image!"
- + StringResources.NEW_LINE + e2.getMessage());
+ if (!Files.exists(source)) {
+ EMLogger.getLogger().log(Level.SEVERE, "Base SDCARD image is not exist !!!");
+ break;
+ }
+
+ try {
+ if (Files.exists(target)) {
+ BasicFileAttributes sourceAttr = Files.readAttributes(source, BasicFileAttributes.class);
+ BasicFileAttributes targetAttr = Files.readAttributes(target, BasicFileAttributes.class);
+
+ // copy sdcard images if only new sdcard images are provided.
+ if (sourceAttr.lastModifiedTime().compareTo(targetAttr.lastModifiedTime()) <= 0) {
+ // FIXME: if newer images are exist,
+ // we should warn to user before replace legacy images.
+ continue;
+ }
}
+
+ Files.copy(source, target, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
+ } catch (IOException e) {
+ EMLogger.getLogger().log(Level.SEVERE, "Failed to create SDCARD image !!!"
+ + StringResources.NEW_LINE + e.getMessage());
}
}
}