import org.tizen.emulator.manager.resources.StringResources;
import org.tizen.emulator.manager.ui.detail.item.template.ComboViewItem;
import org.tizen.emulator.manager.ui.dialog.MessageDialog;
+import org.tizen.emulator.manager.ui.dialog.TapGuideDialogForMac;
import org.tizen.emulator.manager.ui.dialog.TapGuideDialogForWin;
import org.tizen.emulator.manager.vms.helper.HelperClass;
import org.tizen.emulator.manager.vms.helper.ProcessOutputReader;
}
+ private static Boolean MANUAL_BRIDGE = null;
+ public static void showGuideForMac() {
+ // check version
+ if (MANUAL_BRIDGE == null) {
+ MANUAL_BRIDGE = checkMacOSVersionForBridge();
+ }
+
+ if (!MANUAL_BRIDGE) {
+ return;
+ }
+
+ // check bridge is ready;
+ if (!getBridgeNameForMac().isEmpty()) {
+ return;
+ }
+
+ // show guide
+ final MessageDialog resultDialog = new MessageDialog();
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ int res = resultDialog
+ .openSelectionDialog(
+ "You need some configuration for bridge network."
+ + StringResources.NEW_LINE
+ + "Would you like to see a guide?");
+ if (res == SWT.OK) {
+ // Show bridge guide dialog
+ TapGuideDialogForMac.open();
+ }
+ }
+ });
+
+ }
+
+ // return true if a guide for manual bridge is needed.
+ private static boolean checkMacOSVersionForBridge() {
+ String newLine = StringResources.NEW_LINE;
+ String command = "#!/bin/sh"
+ + newLine + "do_version_check() {"
+ + newLine + " if [ \"$1\" == \"$2\" ]; then"
+ + newLine + " echo \"same\""
+ + newLine + " exit 0"
+ + newLine + " fi"
+ + newLine + " ver1front=`echo $1 | cut -d \".\" -f -1`"
+ + newLine + " ver1back=`echo $1 | cut -d \".\" -f 2-`"
+ + newLine + " ver2front=`echo $2 | cut -d \".\" -f -1`"
+ + newLine + " ver2back=`echo $2 | cut -d \".\" -f 2-`"
+ + newLine + " if [ \"$ver1front\" != \"$1\" ] || [ \"$ver2front\" != \"$2\" ]; then"
+ + newLine + " if [ \"$ver1front\" -gt \"$ver2front\" ]; then"
+ + newLine + " echo \"greater\""
+ + newLine + " exit 1"
+ + newLine + " fi"
+ + newLine + " if [ \"$ver1front\" -lt \"$ver2front\" ]; then"
+ + newLine + " echo \"lesser\""
+ + newLine + " exit -1"
+ + newLine + " fi"
+ + newLine + " if [ \"$ver1front\" == \"$1\" ] || [ -z \"$ver1back\" ]; then"
+ + newLine + " ver1back=0"
+ + newLine + " fi"
+ + newLine + " if [ \"$ver2front\" == \"$2\" ] || [ -z \"$ver2back\" ]; then"
+ + newLine + " ver2back = 0"
+ + newLine + " fi"
+ + newLine + " do_version_check \"$ver1back\" \"$ver2back\""
+ + newLine + " elif [ \"$1\" -gt \"$2\" ]; then"
+ + newLine + " echo \"greater\""
+ + newLine + " exit 1"
+ + newLine + " else"
+ + newLine + " echo \"lesser\""
+ + newLine + " exit -1"
+ + newLine + " fi"
+ + newLine + "}"
+ + newLine + "MAC_VER=\"`sw_vers | grep ProductVersion | awk '{print $2}'`\""
+ + newLine + "do_version_check \"$MAC_VER\" \"10.9\"";
+
+ File tmpFile = createTmpFileWithContent(command);
+
+ if (tmpFile == null || !tmpFile.exists()) {
+ return true;
+ }
+
+ List<String> cmd = Arrays.asList("/bin/sh", tmpFile.getAbsolutePath());
+ ProcessResult res = HelperClass.runProcess(cmd);
+ if (!res.isSuccess()) {
+ EMLogger.getLogger().info("Check os version for bridge fail : "
+ + res.getResultMessage());
+ return true;
+ }
+
+ // return false is version is lesser than 10.9.x (exit value : -1)
+ return !(res.getExitValue() == -1);
+
+ }
+
+
private static File TMP_SCRIPT_FILE = null;
public static String getBridgeNameForMac() {
+ newLine + " fi"
+ newLine + " fi"
+ newLine + "done";
- BufferedWriter writer = null;
- try {
- TMP_SCRIPT_FILE = File.createTempFile("tap", ".sh");
- TMP_SCRIPT_FILE.deleteOnExit();
- writer = new BufferedWriter(new FileWriter(TMP_SCRIPT_FILE));
- writer.append(command);
- writer.flush();
-
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- if (writer != null) {
- try {
- writer.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
+ TMP_SCRIPT_FILE = createTmpFileWithContent(command);
}
if (TMP_SCRIPT_FILE == null || !TMP_SCRIPT_FILE.exists()) {
return result.get(0);
}
+
+ private static File createTmpFileWithContent(String content) {
+ BufferedWriter writer = null;
+ File file = null;
+ try {
+ file = File.createTempFile("tap", ".sh");
+ file.deleteOnExit();
+ writer = new BufferedWriter(new FileWriter(file));
+ writer.append(content);
+ writer.flush();
+
+ } catch (IOException e) {
+ e.printStackTrace();
+
+ } finally {
+ if (writer != null) {
+ try {
+ writer.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ return file;
+ }
+
public static String getDnsFromTap(String tapName) {
String dns = ""; //$NON-NLS-1$
if (EmulatorManager.isLinux()) {
--- /dev/null
+/* Emulator Manager
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Minkee Lee <minkee.lee@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho1206.park@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.ui.dialog;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.layout.RowData;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.tizen.emulator.manager.resources.ColorResources;
+import org.tizen.emulator.manager.resources.FontResources;
+import org.tizen.emulator.manager.resources.StringResources;
+import org.tizen.emulator.manager.ui.MainDialog;
+
+public class TapGuideDialogForMac {
+
+ private static Shell dialog = null;
+ private static int WIDTH = 500;
+ private static int HEIGHT = 400;
+
+ private static int TITLE_INDENT = 7;
+ private static int CONTENT_INDENT = 15;
+
+ public static void open() {
+ makeDialog();
+ dialog.open();
+ while (!dialog.isDisposed()) {
+ if (!Display.getCurrent().readAndDispatch()) {
+ Display.getCurrent().sleep();
+ }
+ }
+ }
+
+ private static void makeDialog() {
+ dialog = new Shell(MainDialog.getShell(), SWT.DIALOG_TRIM | SWT.NONE);
+ dialog.setText("Using Bridge Network");
+ dialog.setSize(WIDTH, HEIGHT);
+ dialog.setBackground(ColorResources.TAB_CONTENTS_BG_COLOR.getColor());
+ RowLayout rowLayout = new RowLayout();
+ rowLayout.type = 512;
+ rowLayout.marginTop = 15;
+ rowLayout.marginLeft = 10;
+ rowLayout.spacing = 3;
+ dialog.setLayout(rowLayout);
+ makeContent();
+
+ if (MainDialog.getShell() != null) {
+ Point p = MainDialog.getShell().getLocation();
+ Rectangle rect = MainDialog.getShell().getBounds();
+ int posX = p.x + (rect.width - WIDTH) / 2;
+ int posY = p.y + (rect.height - HEIGHT) / 2;
+ dialog.setLocation(posX, posY);
+ }
+
+ }
+
+ private static void makeContent() {
+
+ Composite comp = new Composite(dialog, SWT.BORDER);
+ comp.setLayoutData(new RowData(WIDTH - 30, HEIGHT - 60));
+ comp.setLayout(new FormLayout());
+
+ String newLine = StringResources.NEW_LINE;
+ Label objective = new Label(comp, SWT.NONE);
+ objective.setFont(FontResources.DETAIL_TITLE_FONT.getFont());
+ objective.setText(
+ "To use bridge network in Tizen emulator, bridge connection should be"
+ + newLine
+ + "created with proper TCP/IP setting.");
+ FormData data = new FormData();
+ data.left = new FormAttachment(0, TITLE_INDENT);
+ data.top = new FormAttachment(0, 5);
+ data.width = WIDTH - 50;
+ data.height = 40;
+ objective.setLayoutData(data);
+
+ Label title1 = new Label(comp, SWT.NONE);
+ title1.setFont(FontResources.DETAIL_TOP_FONT.getFont());
+ title1.setForeground(ColorResources.TEAL.getColor());
+ title1.setText("Create a network bridge");
+ data = new FormData();
+ data.left = new FormAttachment(0, TITLE_INDENT);
+ data.top = new FormAttachment(objective, 3);
+ data.width = WIDTH - 50;
+ data.height = 20;
+ title1.setLayoutData(data);
+
+ Label content1 = new Label(comp, SWT.NONE);
+ String msg = "1. Choose Apple menu > System Preferences, then click working network."
+ + newLine + newLine
+ + "2. Click the action pop-up menu(serrated wheel icon), then choose "
+ + newLine
+ + "Manage Virtual Interfaces"
+ + newLine + newLine
+ + "3. Click Add(plus icon), choose New Bridge, "
+ + newLine
+ + "then select the Ethernet interfaces to include in the bridge.";
+
+ content1.setFont(FontResources.DETAIL_TITLE_FONT.getFont());
+ content1.setText(msg);
+ data = new FormData();
+ data.left = new FormAttachment(0, CONTENT_INDENT);
+ data.top = new FormAttachment(title1, 5);
+ data.width = WIDTH - 50;
+ data.height = 100;
+ content1.setLayoutData(data);
+
+ Label title2 = new Label(comp, SWT.NONE);
+ title2.setFont(FontResources.DETAIL_TOP_FONT.getFont());
+ title2.setForeground(ColorResources.TEAL.getColor());
+ title2.setText("TCP/IP setting for bridge connection");
+ data = new FormData();
+ data.left = new FormAttachment(0, TITLE_INDENT);
+ data.top = new FormAttachment(content1, 20);
+ data.width = WIDTH - 50;
+ data.height = 20;
+ title2.setLayoutData(data);
+
+ Label content2 = new Label(comp, SWT.NONE);
+ String msg2 = "Set TCP/IP configuration for bridge.(IP, DNS and so on)";
+
+ content2.setFont(FontResources.DETAIL_TITLE_FONT.getFont());
+ content2.setText(msg2);
+ data = new FormData();
+ data.left = new FormAttachment(0, CONTENT_INDENT);
+ data.top = new FormAttachment(title2, 5);
+ data.width = WIDTH - 50;
+ data.height = 50;
+ content2.setLayoutData(data);
+
+
+ Label end = new Label(comp, SWT.NONE);
+ String endMsg = "Finally, check if your host network works and continue launching VM."
+ + newLine
+ + "If host network doesn't work like before, there may be some problems in"
+ + newLine
+ + "bridge configuration.";
+ end.setFont(FontResources.DETAIL_TITLE_FONT.getFont());
+ end.setText(endMsg);
+ data = new FormData();
+ data.left = new FormAttachment(0, TITLE_INDENT);
+ data.top = new FormAttachment(content2, 0);
+ data.width = WIDTH - 50;
+ data.height = 50;
+ end.setLayoutData(data);
+ }
+
+}