From: SeokYeon Hwang Date: Fri, 12 Jun 2015 03:32:21 +0000 (+0900) Subject: job: a SDCard preparation logic is moved X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7510dccf4fff591617ed6ca6e0e21717c78c44fc;p=sdk%2Femulator%2Femulator-manager.git job: a SDCard preparation logic is moved Change-Id: Ie4de35a93e69dd4eb883538adbe6671a8d21a4be Signed-off-by: SeokYeon Hwang --- diff --git a/src/org/tizen/emulator/manager/job/CheckSDCard.java b/src/org/tizen/emulator/manager/job/CheckSDCard.java index 6e8bee6..c8c906d 100644 --- a/src/org/tizen/emulator/manager/job/CheckSDCard.java +++ b/src/org/tizen/emulator/manager/job/CheckSDCard.java @@ -1,10 +1,54 @@ package org.tizen.emulator.manager.job; -import org.tizen.emulator.manager.tool.CheckEmulatorDir; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.logging.Level; + +import org.tizen.emulator.manager.logging.EMLogger; +import org.tizen.emulator.manager.resources.FilePathResources; +import org.tizen.emulator.manager.resources.StringResources; public class CheckSDCard implements Job { @Override public void work() { - CheckEmulatorDir.CheckSDCardDir(); + File dir = new File(FilePathResources.getSDCardPath()); + + if (!dir.exists()) { + dir.mkdir(); + } + + for (String s : StringResources.SD_CARD) { + Path source = Paths.get(FilePathResources.getBaseSdcardPath(), s); + Path target = Paths.get(FilePathResources.getSDCardPath(), s); + + 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()); + } + } } } diff --git a/src/org/tizen/emulator/manager/tool/CheckEmulatorDir.java b/src/org/tizen/emulator/manager/tool/CheckEmulatorDir.java deleted file mode 100644 index 22bba76..0000000 --- a/src/org/tizen/emulator/manager/tool/CheckEmulatorDir.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Emulator Manager - * - * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: - * SeokYeon Hwang - * JiHye Kim - * YeongKyoon Lee - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Contributors: - * - S-Core Co., Ltd - * - */ - -package org.tizen.emulator.manager.tool; - -import java.io.File; -import java.io.FileFilter; -import java.io.IOException; -import java.nio.file.Files; -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; - -import org.tizen.emulator.manager.logging.EMLogger; -import org.tizen.emulator.manager.resources.FilePathResources; -import org.tizen.emulator.manager.resources.StringResources; - -public class CheckEmulatorDir { - private CheckEmulatorDir() { - } - - public static boolean CheckOldEmulatorVmsDir() { - File emulator_vms = new File(FilePathResources.getOldTizenSdkDataEmulatorPath()); - if (emulator_vms == null || !emulator_vms.exists()) { - return false; - - } else if (emulator_vms.list() == null) { - return false; - - } else if (emulator_vms.list().length == 0) { // empty dir - emulator_vms.delete(); - return false; - } - - File vms = new File(FilePathResources.getOldSdkDataVmsPath()); - if (vms == null || !vms.exists()) { - return false; - } - - File[] files = vms.listFiles(new FileFilter() { - @Override - public boolean accept(File pathname) { - if(!pathname.isDirectory()) { - return false; - } - return true; - } - }); - - if (files == null || files.length == 0) { - return false; - } - - String configFilename = null; - File configFile = null; - ArrayList vmList = new ArrayList(); - for(File vm : files) { - configFilename = StringResources.PROPERTY_XML_NAME; - configFile = new File(vm, configFilename); - if(!configFile.exists()) { - continue ; // FIXME - } else { - vmList.add(vm); - } - } - - if (vmList.isEmpty()) { - return false; - } - - return true; - } - - public static void CheckSDCardDir() { - File dir = new File(FilePathResources.getSDCardPath()); - - if (!dir.exists()) { - dir.mkdir(); - } - - for (String s : StringResources.SD_CARD) { - Path source = Paths.get(FilePathResources.getBaseSdcardPath(), s); - Path target = Paths.get(FilePathResources.getSDCardPath(), s); - - 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()); - } - } - } -}