Base Image: add checking routine (custom base image path)
authorjihye424.kim <jihye424.kim@samsung.com>
Mon, 26 Oct 2015 04:26:42 +0000 (13:26 +0900)
committerJiHye Kim <jihye424.kim@samsung.com>
Thu, 29 Oct 2015 02:43:46 +0000 (11:43 +0900)
- check point
-- file format is qcow2
-- file is child image or not
-- job making custom base image is completed

Change-Id: I70165e32e368dd85400d9bf47c13f0459da96d04
Signed-off-by: jihye424.kim <jihye424.kim@samsung.com>
src/org/tizen/emulator/manager/console/ConsoleCreateVM.java
src/org/tizen/emulator/manager/ui/detail/item/property/BaseImageViewItem.java
src/org/tizen/emulator/manager/ui/renewal/item/modify/baseimage/BaseImageFileItem.java
src/org/tizen/emulator/manager/vms/helper/HelperClass.java

index 58156f2..daf1e25 100644 (file)
@@ -583,7 +583,7 @@ public class ConsoleCreateVM {
                        throw new ConsoleException(Messages.getString("ConsoleCreateVM.BaseImageError.1") + value + ")"); //$NON-NLS-1$ //$NON-NLS-2$
                }
 
-               if(!HelperClass.isPathAvaliable(value)) {
+               if(!HelperClass.isAvailablePath(value)) {
                        throw new ConsoleException(Messages.getString("ConsoleCreateVM.BaseImageError.2") //$NON-NLS-1$
                                        + StringResources.NEW_LINE
                                        + Messages.getString("ConsoleCreateVM.BaseImageError.3")); //$NON-NLS-1$
index 9995551..ee0d0ad 100644 (file)
@@ -223,7 +223,7 @@ public class BaseImageViewItem extends ComboViewItem {
 
                                String path = fd.open();
                                if (path != null) {
-                                       if (!HelperClass.isPathAvaliable(path)) {
+                                       if (!HelperClass.isAvailablePath(path)) {
                                                new MessageDialog()
                                                                .openWarningDialog(Messages.getString("BaseImageViewItem.CustomImageError.0") //$NON-NLS-1$
                                                                                + StringResources.NEW_LINE
index a042ef6..146ab60 100644 (file)
 
 package org.tizen.emulator.manager.ui.renewal.item.modify.baseimage;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.FileDialog;
+import org.tizen.emulator.manager.platform.baseimage.CustomBaseImageLoader;
 import org.tizen.emulator.manager.renewal.resources.ImageResources;
+import org.tizen.emulator.manager.resources.FilePathResources;
 import org.tizen.emulator.manager.resources.StringResources;
 import org.tizen.emulator.manager.ui.renewal.MainDialog;
 import org.tizen.emulator.manager.ui.renewal.dialog.MessageBox;
@@ -42,26 +47,26 @@ import org.tizen.emulator.manager.ui.renewal.item.modify.common.ModifyDialogItem
 import org.tizen.emulator.manager.ui.renewal.item.modify.comp.PropertyValue;
 import org.tizen.emulator.manager.vms.VMProperty.Architecture;
 import org.tizen.emulator.manager.vms.helper.HelperClass;
+import org.tizen.emulator.manager.vms.helper.QemuImgProc;
 
 public class BaseImageFileItem extends FileDialogItem {
-       private static final String NAME="imagefile";
-       private static final String TITLE="Image File";
+       private static final String NAME ="imagefile";
+       private static final String TITLE ="Image File";
        private final int TEXT_BOX_WIDTH = 233;
 
        private String imageFilePath;
-       // TODO
-       //private File imageFile;
 
        private FileDialog fd;
 
        public BaseImageFileItem() {
                super(NAME, TITLE);
        }
+
        @Override
        public void create(Composite parent) {
                create(parent, getTitle(), ImageResources.ICON_TITLE_IMAGE_FILE, TEXT_BOX_WIDTH);
                if (imageFilePath == null || imageFilePath.isEmpty()) {
-                       setTextBox("(select base imaeg path...)");
+                       setTextBox("(select base image path...)");
                } else {
                        setTextBox(imageFilePath);
                }
@@ -87,6 +92,7 @@ public class BaseImageFileItem extends FileDialogItem {
                if (fd == null) {
                        fd = new FileDialog(MainDialog.getShell(), SWT.OPEN);
                        fd.setText("Select Base Image");
+
                        String[] filter = null;
                        String[] filterName = null;
                        filter = new String[] { // "*.x86;*.i386;*.x86_64"
@@ -105,24 +111,49 @@ public class BaseImageFileItem extends FileDialogItem {
                        fd.setFilterNames(filterName);
                }
 
+               fd.setFilterPath(CustomBaseImageLoader.getLastDirectroy());
+
                String path = fd.open();
                if (path != null) {
-                       if (!HelperClass.isPathAvaliable(path)) {
-                               MessageBox
-                                               .openMessageBox("This base image not ready yet."
-                                                               + StringResources.NEW_LINE
-                                                               + "Please, select again in a few seconds.");
+                       // check file path
+                       if (!checkFilePath(path)) {
                                return null;
                        }
-                       // TODO: need to check file format
+
                        return path;
                }
                return null;
        }
 
+       private boolean checkFilePath(String path) {
+               // check file available
+               if (!HelperClass.isAvailablePath(path)) {
+                       MessageBox.openMessageBox("This base image not ready yet."
+                                                       + StringResources.NEW_LINE
+                                                       + "Please, select again in a few seconds.");
+                       return false;
+               }
+
+               // check - format of file is qcow2
+               // check - file is child image file or not
+               String qemuImgPath = FilePathResources.getEmulatorQemuImgPath();
+               List<String> cmd = new ArrayList<String>();
+               cmd.add(qemuImgPath);
+               cmd.add("info"); //$NON-NLS-1$
+               cmd.add(path);
+
+               String errorMsg = new QemuImgProc(cmd).RunningForCheckImg();
+               if (errorMsg != null) {
+                       MessageBox.openMessageBox(errorMsg);
+                       return false;
+               }
+               return true;
+       }
+
        @Override
        public void fileSelected() {
                imageFilePath = filePath;
+               // for setting default name of custom base image
                getDialog().getPropertyValue().setImageFilePath(imageFilePath);
                getDialog().changeItemList("");
        }
index 847e226..c1e855d 100644 (file)
@@ -116,7 +116,7 @@ public class HelperClass {
                return null;
        }
 
-       public static boolean isPathAvaliable(String path) {
+       public static boolean isAvailablePath(String path) {
                if (path != null) {
                        File partFile = new File(path+".part"); //$NON-NLS-1$
                        if (partFile.exists()) {