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());
+ }
+ }
}
}
+++ /dev/null
-/*
- * Emulator Manager
- *
- * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * SeokYeon Hwang <syeon.hwang@samsung.com>
- * JiHye Kim <jihye1128.kim@samsung.com>
- * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
- *
- * 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<File> vmList = new ArrayList<File>();
- 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());
- }
- }
- }
-}