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;
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);
}
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"
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("");
}