Show pop-up message when fail to remove VM directory.
authorminkee.lee <minkee.lee@samsung.com>
Tue, 13 May 2014 13:40:31 +0000 (22:40 +0900)
committerminkee.lee <minkee.lee@samsung.com>
Tue, 16 Sep 2014 11:34:06 +0000 (20:34 +0900)
- When user try to "delete" VM, VM data directory is not removed occasionally
because some files or directories in VM data directory are being used by other process.
In this case, emulator-manager show warning message. Then user should check and remove
VM data directory completely. If data directory remains, creating a new VM with same name
is impossible.

Change-Id: I2406639a10c72c8365fac02235400abe4fceb9d0
Signed-off-by: minkee.lee <minkee.lee@samsung.com>
common-project/src/org/tizen/emulator/manager/console/ConsoleProcessor.java
common-project/src/org/tizen/emulator/manager/ui/MenuHandling.java
common-project/src/org/tizen/emulator/manager/ui/dialog/MessageDialog.java
common-project/src/org/tizen/emulator/manager/vms/VMWorkerCommon.java

index 8256da2..461e2ff 100644 (file)
@@ -42,6 +42,7 @@ import org.tizen.emulator.manager.platform.PlatformList;
 import org.tizen.emulator.manager.plugin.EMPlugin;
 import org.tizen.emulator.manager.plugin.ExtensionItem;
 import org.tizen.emulator.manager.plugin.PluginStringResources;
+import org.tizen.emulator.manager.resources.FilePathResources;
 import org.tizen.emulator.manager.resources.StringResources;
 import org.tizen.emulator.manager.tool.About;
 import org.tizen.emulator.manager.vms.EmulatorVMList;
@@ -256,7 +257,11 @@ public class ConsoleProcessor {
                }
 
                try {
-                       prop.getWorker().deleteVM();
+                       if (!prop.getWorker().deleteVM()) {
+                               System.out.println("Warning: Fail to delete VM directory complete.");
+                               System.out.println(" - Please check and remove VM directory completely.");
+                               System.out.println(" - path : " + FilePathResources.getTizenVmsPath() + File.separator + name);
+                       }
                } catch (VMWorkerException e) {
                        System.out.println("Error: " + e.getMessage());
                        return false;
index 1601f97..6bd0dc5 100644 (file)
@@ -30,6 +30,8 @@
 
 package org.tizen.emulator.manager.ui;
 
+import java.io.File;
+
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.FileDialog;
 import org.eclipse.swt.widgets.Shell;
@@ -108,7 +110,10 @@ public class MenuHandling {
                        }
                }
 
-               property.getWorker().deleteVM();
+               File vmDirectory = property.getPropertyFile().getParentFile();
+               if (!property.getWorker().deleteVM()) {
+                       msg.openRemoveVMFailDialog(vmDirectory.getAbsolutePath(), property.getName());
+               }
 
                return true;
        }
index 738e23e..e87d1df 100644 (file)
@@ -40,6 +40,7 @@ import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Link;
 import org.eclipse.swt.widgets.Shell;
 import org.tizen.emulator.manager.resources.StringResources;
 import org.tizen.emulator.manager.ui.MainDialog;
@@ -83,6 +84,91 @@ public class MessageDialog
                return openMessageDialog(title, message,  SWT.ICON_QUESTION, SWT.OK | SWT.CANCEL);
        }
 
+       public int openRemoveVMFailDialog(final String path, final String vmName) {
+               msgResponse = 0;
+               return openRemoveVMFailDialog("Emulator Manager", path, vmName, SWT.ICON_WARNING, SWT.OK);
+       }
+
+       public int openRemoveVMFailDialog(final String title, final String path, final String vmName,
+                       final int icon_style, final int style) {
+               dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
+               dialog.setText(title);
+               dialog.setLayout(new GridLayout(2, false));
+               dialog.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
+
+               Label icon = new Label(dialog, SWT.NONE);
+               icon.setImage(Display.getCurrent().getSystemImage(icon_style));
+               icon.pack();
+               Composite textComp = new Composite(dialog, SWT.NONE);
+               GridLayout layout = new GridLayout(1, true);
+               layout.horizontalSpacing        = 0;
+               layout.verticalSpacing          = 0;
+               layout.marginBottom             = 0;
+               layout.marginHeight             = 0;
+               layout.marginLeft                       = 5;
+               layout.marginRight                      = 10;
+               layout.marginTop                        = 0;
+               layout.marginWidth                      = 0;
+               textComp.setLayout(layout);
+               textComp.setLayoutData(new GridData(SWT.RIGHT, SWT.BOTTOM, false, false));
+
+               Label content = new Label(textComp, SWT.NONE);
+               content.setText("Fail to remove VM(" + vmName + ")\'s directory because\n"
+                               + "some directories or files are opened. \n"
+                               + "Please check and remove completely.\n");
+               content.pack();
+
+               Link vmDirectory = new Link(textComp, SWT.NONE);
+               vmDirectory.setText("<a>" + path +"</a>");
+               vmDirectory.addSelectionListener(new SelectionListener() {
+                       @Override
+                       public void widgetDefaultSelected(SelectionEvent arg0) {
+                       }
+                       @Override
+                       public void widgetSelected(SelectionEvent arg0) {
+                               try {
+                                       org.eclipse.swt.program.Program.launch(path);
+                               } catch (Throwable e) {
+                                       return;
+                               }
+                       }
+               });
+               vmDirectory.pack();
+
+               textComp.pack();
+               int x = icon.getSize().x + textComp.getSize().x;
+               int y = 0;
+               if (icon.getSize().y > textComp.getSize().y ) {
+                       y = icon.getSize().y;
+               } else {
+                       y = textComp.getSize().y;
+               }
+
+               dialog.setSize(x + 50, y + 100);
+
+               if (MainDialog.getShell() != null) {
+                       Point p = MainDialog.getShell().getLocation();
+                       Point s = MainDialog.getShell().getSize();
+                       dialog.setLocation(p.x + (s.x>>2), p.y + (s.y>>2));
+               }
+
+               //TODO : dummy label
+               new Label(dialog, SWT.NONE);
+               new Label(dialog, SWT.NONE);
+               new Label(dialog, SWT.NONE);
+
+               makeButtonComposite(style);
+
+               dialog.open();
+               while(!dialog.isDisposed()) {
+                       if(!Display.getCurrent().readAndDispatch()) {
+                               Display.getCurrent().sleep();
+                       }
+               }
+
+               return msgResponse;
+       }
+
        int msgResponse = 0;
        private Shell dialog = null;
        public int openMessageDialog(final String title, final String message, final int icon_style, final int style) {
index a43ab2e..1de2db5 100644 (file)
@@ -319,7 +319,10 @@ public abstract class VMWorkerCommon {
                }
        }
 
-       public void deleteVM() throws VMWorkerException {
+       public boolean deleteVM() throws VMWorkerException {
+
+               boolean result = true;
+
                // lock.acquire
                WorkerLock.acquire();
 
@@ -342,19 +345,7 @@ public abstract class VMWorkerCommon {
                        }
 
                        if (vmDirectory.exists()) {
-                               for (File dir : vmDirectory.listFiles()) {
-                                       if (dir.isFile()) {
-                                               dir.delete();
-                                       } else { // directory
-                                               for (File sub : dir.listFiles()) {
-                                                       if (sub.isFile()) {
-                                                               sub.delete();
-                                                       }
-                                               }
-                                               dir.delete();
-                                       }
-                               }
-                               vmDirectory.delete();
+                               result = deleteFile(vmDirectory);
                        }
                } catch (VMWorkerException e) {
                        throw e;
@@ -362,6 +353,8 @@ public abstract class VMWorkerCommon {
                        // lock.release
                        WorkerLock.release();
                }
+
+               return result;
        }
 
        public void resetVM() throws VMWorkerException {
@@ -641,6 +634,35 @@ public abstract class VMWorkerCommon {
                        }
                }
        }
+
+       // Remove directory files recursively.
+       // Return false if one or more files fail to delete.
+       public static boolean deleteFile(File file){
+               boolean result = true;
+               if (!file.exists()) {
+                       return result;
+               }
+
+               if (file.isDirectory()) {
+                       // delete child
+                       for (File f : file.listFiles()) {
+                               if (!deleteFile(f)) {
+                                       result = false;
+                               }
+                       }
+                       // delete directory
+                       if (!file.delete()) {
+                               result = false;
+                       }
+               } else {
+                       // delete file
+                       if (!file.delete()) {
+                               result = false;
+                       }
+               }
+
+               return result;
+       }
 }
 
 /*