[Esbox-commits] r2133 - in branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal: api/vm/vmware vm/vmware/ui/wizards

eswartz at garage.maemo.org eswartz at garage.maemo.org
Thu Sep 10 00:34:59 EEST 2009


Author: eswartz
Date: 2009-09-10 00:34:59 +0300 (Thu, 10 Sep 2009)
New Revision: 2133

Added:
   branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DefaultVMZipExtractor.java
   branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/Tool7zip.java
   branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMUncompressInfoWizardPage.java
Modified:
   branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMDownloader.java
   branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInfo.java
   branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInstaller.java
   branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallData.java
   branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallerContentLabelProvider.java
   branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMSelectionWizardPage.java
Log:
Merge rev 2129 from trunk

Added: branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DefaultVMZipExtractor.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DefaultVMZipExtractor.java	                        (rev 0)
+++ branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DefaultVMZipExtractor.java	2009-09-09 21:34:59 UTC (rev 2133)
@@ -0,0 +1,362 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Nokia Corporation
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Fabrício S Epaminondas
+ *    
+ *******************************************************************************/
+package org.maemo.esbox.internal.api.vm.vmware;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.text.DecimalFormat;
+import java.util.Locale;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.maemo.esbox.internal.vm.vmware.Activator;
+import org.maemo.mica.common.core.Policy;
+import org.maemo.mica.common.core.ui.IProgressReporter;
+import org.maemo.mica.internal.api.common.core.filesystem.FilesystemUtils;
+
+/**
+ * @author Fabrício S Epaminondas
+ * 
+ */
+final class DefaultVMZipExtractor {
+	public static int SINGLE_FILE_PART = 1;
+	public final static int DECOMPRESS_FACTOR = 4;
+	
+	/**
+	 * Extracts the compressed VM file on local machine
+	 * @param fileName
+	 * @param shell
+	 * @param destinationPath
+	 * @param reporter
+	 * @return
+	 */
+	public static IStatus extract(final String fileName, final Shell shell,
+			final String destinationPath, final IProgressReporter reporter) {
+		final IStatus[] status =  { Status.OK_STATUS };
+
+		Display.getDefault().syncExec(new ZipExtractor(status, shell, reporter, fileName, destinationPath));
+		return status[0];
+	}
+
+	/**
+	 * Check if there is enough space to uncompress the Maemo SDK virtual image.
+	 * 
+	 * @param fileName
+	 *            the name of Maemo SDK virtual image.
+	 * @param destinationPath
+	 *            the destination path to uncompress the Maemo SDK virtual
+	 *            image.
+	 * @return boolean if there is enough space to uncompress the Maemo SDK
+	 *         virtual image (if the free space available on disk is bigger than
+	 *         the size of uncompressed Maemo SDK virtual image); false,
+	 *         otherwise.
+	 */
+	public static boolean haveEnoughFreeSpace(String fileName,
+			String destinationPath) {
+		ZipInputStream zipInputStream = null;
+		ZipEntry zipEntry;
+
+		try {
+			long fileSize = 0;
+			zipInputStream = new ZipInputStream(new FileInputStream(fileName));
+
+			// check the total size of zip file. It is necessary to check the
+			// size of each zip file entry.
+			while ((zipEntry = zipInputStream.getNextEntry()) != null) {
+				fileSize += zipEntry.getSize();
+			}
+			long freeSpace = getFreeSpaceSize(destinationPath);
+			return freeSpace > fileSize;
+		} catch (IOException e) {
+			Activator
+					.getErrorLogger()
+					.logError(
+							"Cannot retrieve information about zipped Maemo SDK virtual image. I/O error",
+							e);
+			return false;
+
+		} finally {
+			Policy.close(zipInputStream);
+		}
+	}
+	
+	/**
+	 * @param fileName
+	 * @param numParts
+	 * @return the size in bytes
+	 */
+	public static long getEstimatedDecompressedSize(String fileName,
+			int numParts) {
+		return getCompressedSize(fileName, numParts) * DECOMPRESS_FACTOR;
+	}
+
+	/**
+	 * The compressed size
+	 * 
+	 * @param fileName
+	 * @param numParts
+	 * @return size in bytes
+	 */
+	public static long getCompressedSize(String fileName,
+			int numParts) {
+		File localFile = new File(fileName);
+		long totalSize = 0L;
+		
+		if(numParts > DefaultVMZipExtractor.SINGLE_FILE_PART){
+			for(File f: DefaultVMZipExtractor.getMultipartFiles(fileName, numParts)){
+				totalSize += f.length();
+			}
+		}else{
+			totalSize = localFile.length();
+		}
+		return totalSize;
+	}
+	
+	/**
+	 * the free space available on file location
+	 * @param fileName
+	 * @return the size in bytes
+	 */
+	public static long getFreeSpaceSize(String path) {
+		long freeSpace = 0L;
+
+		try {
+			freeSpace = FilesystemUtils.freeSpaceOS(new Path(path), false);
+		} catch (IOException e) {
+			Activator
+					.getErrorLogger()
+					.logError(
+							"Cannot retrieve information about zipped Maemo SDK virtual image. I/O error",
+							e);
+		}
+		return freeSpace;
+	}
+	
+	/**
+	 * Get the progress value of uncompressing process.
+	 * 
+	 * @param total
+	 * @param read
+	 * @return
+	 */
+	static float getProgress(long total, long read) {
+		return ((float) read / total) * 100;
+	}
+	
+	
+
+	/**
+	 * Return the array of files if this file is a multipart file
+	 * @param fileName
+	 * @param numParts
+	 * @return
+	 */
+	public static File[] getMultipartFiles(String fileName, int numParts){
+		if(numParts <= SINGLE_FILE_PART)
+			return new File[]{new File(fileName)};
+		
+		File[] files = new File[numParts];
+		for(int i =0; i < numParts; i++){
+			String name = getFilePartName(fileName,i+1);
+			files[i] = new File(name);
+		}
+		
+		return files;
+	}
+	
+	/**
+	 * The name of file part
+	 * @param fileName
+	 * @param nPart
+	 * @return
+	 */
+	public static String getFilePartName(String fileName, int nPart) {
+		String name = fileName;
+		int i = name.lastIndexOf('.');
+		if(i != -1)
+			name = name.substring(0,i);
+		DecimalFormat df = new DecimalFormat( "000");
+		String part = df.format(nPart);
+		name= name + '.' + part;
+		return name;
+	}
+
+	
+	static final class ZipExtractor implements Runnable {
+		private final IStatus[] status;
+		private final Shell shell;
+		private final IProgressReporter reporter;
+		private final String fileName;
+		private final String destinationPath;
+
+		ZipExtractor(IStatus[] status, Shell shell, IProgressReporter reporter,
+				String fileName, String destinationPath) {
+			this.status = status;
+			this.shell = shell;
+			this.reporter = reporter;
+			this.fileName = fileName;
+			this.destinationPath = destinationPath;
+		}
+
+		public void run() {
+			try {
+				ProgressMonitorDialog progressMonitor = new ProgressMonitorDialog(
+						shell);
+				progressMonitor.run(true, true,
+						new IRunnableWithProgress() {
+
+							public void run(IProgressMonitor monitor)
+									throws InvocationTargetException,
+									InterruptedException {
+
+								File file = new File(fileName);
+								
+								if (file.length() >= 4L * 1024L * 1024L * 1024L) {
+									status[0] = Activator
+									.createErrorStatus(
+											"JDK only supports uncompression of files smaller than 4Gb.",
+											null);
+								}
+								
+								byte[] buf = new byte[1024];
+								ZipInputStream zipInputStream = null;
+								ZipEntry zipEntry = null;
+								FileOutputStream fileOutputStream = null;
+
+								try {
+									zipInputStream = new ZipInputStream(
+											new FileInputStream(file));
+									zipEntry = zipInputStream
+											.getNextEntry();
+
+									if (zipEntry == null) {
+										status[0] = Activator
+												.createErrorStatus(
+														"Cannot uncompress Maemo SDK virtual image, no zip entry was found.",
+														null);
+									}
+
+									while (zipEntry != null) {
+
+										// for each entry to be extracted
+										String entryName = zipEntry
+												.getName();
+
+										monitor
+												.beginTask(
+														"Uncompressing Maemo SDK virtual image",
+														100);
+
+										long lenght = zipEntry.getSize();
+
+										File newFile = new File(entryName);
+										String directory = newFile
+												.getParent();
+										if (directory == null) {
+											if (newFile.isDirectory())
+												break;
+										}
+
+										fileOutputStream = new FileOutputStream(
+												destinationPath
+														+ File.separator
+														+ entryName);
+										int n;
+										long totalRead = 0;
+										int previousProgressValue = 0;
+										while ((n = zipInputStream.read(
+												buf, 0, 1024)) > -1) {
+											// write on file
+											fileOutputStream.write(buf, 0,
+													n);
+
+											// update progress monitor bar
+											totalRead += n;
+											int progressValue = ((int) getProgress(
+													lenght, totalRead));
+											if (previousProgressValue < progressValue) {
+												previousProgressValue = progressValue;
+												monitor.worked(1);
+											}
+											if (monitor.isCanceled())
+												break;
+											monitor
+													.subTask("Uncompressing "
+															+ zipEntry
+															+ "\t\t"
+															+ String
+																	.format(
+																			Locale.US,
+																			"%.2f",
+																			getProgress(
+																					lenght,
+																					totalRead))
+															+ "%");
+
+										}
+										fileOutputStream.close();
+										zipInputStream.closeEntry();
+
+										if (monitor.isCanceled()) {
+											status[0] = Activator
+													.createErrorStatus(
+															"Installation was cancelled.",
+															null);
+											return;
+										} else {
+											zipEntry = zipInputStream
+													.getNextEntry();
+										}
+									}
+
+								} catch (IOException ioe) {
+									status[0] = Activator
+											.createErrorStatus(
+													"Cannot uncompress Maemo SDK virtual image: I/O error",
+													ioe);
+									reporter
+											.appendStreamText(
+													"Cannot uncompress Maemo SDK virtual image.",
+													true);
+								} finally {
+
+									Policy.close(zipInputStream);
+
+									Policy.close(fileOutputStream);
+
+								}
+
+							}
+
+						});
+			} catch (Exception e) {
+				status[0] = Activator.createErrorStatus(
+						"Cannot uncompress Maemo SDK virtual image.", e);
+				reporter
+						.appendStreamText(
+								"Cannot procced with Maemo SDK virtual image uncompressing.",
+								true);
+			}
+		}
+	}
+}
\ No newline at end of file


Property changes on: branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DefaultVMZipExtractor.java
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMDownloader.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMDownloader.java	2009-09-09 20:34:40 UTC (rev 2132)
+++ branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMDownloader.java	2009-09-09 21:34:59 UTC (rev 2133)
@@ -20,10 +20,10 @@
 import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.text.DecimalFormat;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Path;
@@ -60,10 +60,12 @@
 	
 	/**
 	 * Get URL and size of remote file.
+	 * @param nPart the number of the part to get info, null if it not is a multipart file
 	 * @return URL and size of remote file.
 	 * @throws MicaException
+	 * @throws IOException 
 	 */
-	private Tuple getRemoteFileInfo() throws MicaException {
+	private Tuple getRemoteFileInfo(Integer nPart) throws MicaException, IOException {
 		URL connectionURL = null;
 		try {
 			connectionURL = new URL(MaemoSDKVMInfo.DOWNLOAD_PAGE);
@@ -78,17 +80,29 @@
 		URL remoteURL;
 		int fileSize = 0;
 		try {
-			fileSize = getSizeFor(downloadPage, downloadFile.getDescriptor().getName());
 			remoteURL = getLinkFor(downloadPage, downloadFile.getDescriptor().getName());
+			
+			if (remoteURL == null) {
+				throw new MicaException("Cannot locate ''" + downloadFile.getDescriptor().getName() 
+						+ "'' on " + MaemoSDKVMInfo.DOWNLOAD_PAGE);
+			}
+			
+			if(downloadFile.isMultipart() && nPart != null){
+				String url = remoteURL.toExternalForm();
+				int i = url.lastIndexOf('.');
+				if(i != -1)
+					url = url.substring(0,i);
+				DecimalFormat df = new DecimalFormat( "000");
+				String part = df.format(nPart);
+				remoteURL = new URL(url + '.' + part);
+			}
+			
+			HttpURLConnection conn = (HttpURLConnection) remoteURL.openConnection();
+			fileSize = conn.getContentLength();
 		} catch (MalformedURLException e) {
 			throw new MicaException("Invalid file URL on " + MaemoSDKVMInfo.DOWNLOAD_PAGE, e);
 		}
 				
-		if (remoteURL == null) {
-			throw new MicaException("Cannot locate ''" + downloadFile.getDescriptor().getName() 
-					+ "'' on " + MaemoSDKVMInfo.DOWNLOAD_PAGE);
-		}
-		
 		return new Tuple(remoteURL, fileSize);
 	}
 	
@@ -215,7 +229,7 @@
 				if (matcherLink.find()) {
 					String link = matcherLink.group(1);
 					return (new URL(MaemoSDKVMInfo.DOWNLOAD_PAGE
-							+ link.substring(link.indexOf("?"))));
+							+ (link.contains("?")?link.substring(link.indexOf("?")): link)));
 				}
 			}
 
@@ -223,45 +237,18 @@
 		return null;
 	}
 	
-	/**
-	 * Get the size of a certain remote file. The file is retrieved from html page description.
-	 * @param htmlPage
-	 * @param downloadFileDescription
-	 * @return
-	 */
-	private int getSizeFor(String htmlPage, String downloadFileDescription) {
-		final String DOWNLOAD_FILE_PATTERN = "<tr>\\s*<td class=\"filename\">(.*?)</td>\\s*</tr>";
-		final String SIZE_PATTERN = "<td class=\"filesize\">(.*?)</td>";
-		Pattern fileEntryPattern = Pattern.compile(DOWNLOAD_FILE_PATTERN,
-				Pattern.DOTALL | Pattern.UNIX_LINES);
-		Matcher matcher = fileEntryPattern.matcher(htmlPage);
-		while (matcher.find()) {
-			String fileInfo = matcher.group(0);
-			if (fileInfo.contains(downloadFileDescription)) {
-				Pattern sizePattern = Pattern.compile(SIZE_PATTERN,
-						Pattern.DOTALL | Pattern.UNIX_LINES);
-				Matcher matcherLink = sizePattern.matcher(fileInfo);
-				if (matcherLink.find()) {
-					String size = matcherLink.group(1);
-					return Integer.parseInt(size);
-				}
-			}
-
-		}
-		return 0;
-	}
 	
 	/**
-	 * Get file name of download file to be saved locally
+	 * Get local file to download file 
 	 * 
 	 * @param remoteURL
-	 * @param localPath
+	 * @param installLocation
 	 * @return the name of file to be saved locally
 	 */
-	private String getFileName(URL remoteURL, URL localPath) {
+	private File getLocalFile(URL remoteURL, URL installLocation) {
 		String fileName = (new Path(remoteURL.getFile())).lastSegment();
 		fileName = fileName.substring(fileName.lastIndexOf("=") + 1);
-		return (new Path(localPath.getFile())).append(fileName).toOSString();
+		return new File ((new Path(installLocation.getFile())).append(fileName).toOSString());
 	}
 	
 	/**
@@ -269,15 +256,14 @@
 	 * @param localFileName
 	 * @return
 	 */
-	private long getPreviousDownloadSize(String localFileName) {
-		File previousFile = new File(localFileName);
-		if (previousFile.exists()) {
+	private long getPreviousDownloadSize(File localFile) {
+		if (localFile.exists()) {
 			boolean canResumeDownload = DialogUtils.showQuestionDialog(DialogUtils.getShell(), 
-					"Previous download file founded", "The file " + localFileName + " already exists. Would you like to resume download?");
+					"Previous download file founded", "The file " + localFile + " already exists. Would you like to resume download?");
 			if (canResumeDownload) {
-				return previousFile.length();
+				return localFile.length();
 			} else {
-				previousFile.delete();
+				localFile.delete();
 				return 0L;
 			}			
 		}
@@ -293,100 +279,234 @@
 	private IStatus fileDownloader() throws IOException, MicaException {
 		// Check if file was downloaded before
 		monitor.subTask("Checking information about file to be downloaded ...");
+		
+		if(downloadFile.isMultipart()){
+			//download multipar file
+			return downloadMultiple();
+		}else{
+			//download single file
+			return downloadSingle();
+		}
+	}
+	
+	protected IStatus downloadMultiple() throws MicaException, IOException {
+		
+		for(int nPart = 1; nPart <= downloadFile.getNumParts(); nPart++){
+			Tuple remoteFileInfo = getRemoteFileInfo(nPart);
+			URL remoteURL = (URL) remoteFileInfo.get(0);
+			
+			// Get link of remote file
+			File localFile = getLocalFile(remoteURL, downloadFile.getInstallLocation());
+			if(nPart ==1)
+				downloadFile.setFileName(localFile.getName());
+			
+			downloadFile.setDownloadedSize(getPreviousDownloadSize(localFile));			
+			Integer remoteFileSize = (Integer) remoteFileInfo.get(1);;
+			
+			if (downloadFile.getDownloadedSize() == remoteFileSize.intValue()){
 				
-		Tuple remoteFileInfo = getRemoteFileInfo();
+				if(nPart == downloadFile.getNumParts()){
+					downloadFile.complete();
+					return Activator.createStatus(Status.OK, "Maemo SDK virtual image is already downloaded.");
+				}else
+					continue; //check next part
+			}
+			
+			HttpURLConnection connection = null;
+			RandomFileOutputStream out = null;
+			InputStream in = null;
+			
+			try {
+			
+				// Open connection to URL.
+				monitor.subTask("Establishing connection with " + remoteURL.getHost());
+				connection = (HttpURLConnection) remoteURL.openConnection();
+				
+				// Specify what portion of file to download
+				connection.setRequestProperty("Range", "bytes=" + downloadFile.getDownloadedSize() + "-");
+				
+				// Connect to server
+				connection.connect();
+				monitor.subTask("Connected with " + remoteURL.getHost());
+		
+				IStatus connectionStatus = validateConnection(connection);
+				if (!connectionStatus.isOK()) {
+					cancelDownload(downloadFile,monitor);
+					return errorStatus(connectionStatus.getMessage());
+				}
+				
+				int contentLength = connection.getContentLength();			
+				if (!haveEnoughtFreeSpace(contentLength/1024, localFile)) {
+					cancelDownload(downloadFile, monitor);
+					return errorStatus("There is not enought space to save Maemo SDK virtual machine in your computer.");
+				}
+				
+				// set the size for this download if it hasn't been already set.
+				if (downloadFile.getSize() == -1) {
+					downloadFile.setSize(contentLength);
+				}
+				
+				CopyProgressMonitor progressMonitor = new CopyProgressMonitor(
+						"Downloading Maemo SDK virtual image", remoteFileSize, monitor);
+				progressMonitor.setExistingSize(downloadFile.getDownloadedSize());
+				progressMonitor.start();
+		
+				out = new RandomFileOutputStream(localFile,true);
+				out.setFilePointer(downloadFile.getDownloadedSize());	
+				in = connection.getInputStream();
+				
+				// create and start to download
+				monitor.beginTask(remoteURL.getFile(), remoteFileSize != 0 ? remoteFileSize : IProgressMonitor.UNKNOWN);
+				monitor.worked((int)downloadFile.getDownloadedSize());
+				
+				int bufferSize = 64*1024;//64KB
+				DownloadingThread thread = new DownloadingThread(in, out,bufferSize , progressMonitor, monitor);
+				thread.start();
+	
+				while (!thread.isInterrupted() && thread.isAlive() ) {
+					try {
+						Thread.sleep(1000);
+					} catch (InterruptedException e) {
+						continue;
+					}
+					
+					if (monitor.isCanceled()) {
+						thread.stopDownloading();
+						downloadFile.cancel();					
+						return Status.CANCEL_STATUS;
+					}
+					
+					if(downloadFile.getStatus() == MaemoSDKVMInfo.Status.PAUSED){
+						thread.doPause();
+					}
+					
+					if(downloadFile.getStatus() == MaemoSDKVMInfo.Status.DOWNLOADING){
+						if(thread.isPaused()) thread.doResume();
+					}
+				}
+				
+				if (thread.isCompleted() && nPart == downloadFile.getNumParts()) {
+					downloadFile.complete();
+				}
+				
+				if (thread.getErrorMessage() != null) {
+					downloadFile.error();
+					throw new IOException(thread.getErrorMessage());
+				}
+			} finally {
+	
+				// Close connection to server.
+				if (in != null) {
+					in.close();
+				}
+	
+				if (connection != null)
+					connection.disconnect();
+			}
+		}
+		return Status.OK_STATUS;
+	}
+
+	protected IStatus downloadSingle() throws MicaException, IOException {
+		Tuple remoteFileInfo = getRemoteFileInfo(null);
 		URL remoteURL = (URL) remoteFileInfo.get(0);
-		
+
 		// Get link of remote file
-		String fileName = getFileName(remoteURL, downloadFile.getLocalURL());
-		downloadFile.setLocalURL(new File(fileName).toURL());
-		
-		downloadFile.setDownloadedSize(getPreviousDownloadSize(fileName));			
+		File localFile = getLocalFile(remoteURL, downloadFile.getInstallLocation());
+		downloadFile.setFileName(localFile.getName());
+
+		downloadFile.setDownloadedSize(getPreviousDownloadSize(localFile));
 		Integer remoteFileSize = (Integer) remoteFileInfo.get(1);
-		
+
 		if (downloadFile.getDownloadedSize() == remoteFileSize.intValue()){
 			downloadFile.complete();
-			return Activator.createStatus(Status.OK, "Maemo SDK virtual image is already downloaded.");
+			return Activator.createStatus(Status.OK,
+					"Maemo SDK virtual image is already downloaded.");
 		}
-		
+
 		HttpURLConnection connection = null;
 		RandomFileOutputStream out = null;
 		InputStream in = null;
-		
+
 		try {
-		
+
 			// Open connection to URL.
-			monitor.subTask("Establishing connection with " + remoteURL.getHost());
+			monitor.subTask("Establishing connection with "
+					+ remoteURL.getHost());
 			connection = (HttpURLConnection) remoteURL.openConnection();
-			
+
 			// Specify what portion of file to download
-			connection.setRequestProperty("Range", "bytes=" + downloadFile.getDownloadedSize() + "-");
-			
+			connection.setRequestProperty("Range", "bytes="
+					+ downloadFile.getDownloadedSize() + "-");
+
 			// Connect to server
 			connection.connect();
 			monitor.subTask("Connected with " + remoteURL.getHost());
-	
+
 			IStatus connectionStatus = validateConnection(connection);
 			if (!connectionStatus.isOK()) {
-				cancelDownload(downloadFile,monitor);
+				cancelDownload(downloadFile, monitor);
 				return errorStatus(connectionStatus.getMessage());
 			}
-			
-			Path filePath = new Path(downloadFile.getLocalURL().getPath()); 
-			int contentLength = connection.getContentLength();			
-			if (!haveEnoughtFreeSpace(contentLength/1024, filePath.removeLastSegments(1))) {
+
+			int contentLength = connection.getContentLength();
+			if (!haveEnoughtFreeSpace(contentLength / 1024, localFile)) {
 				cancelDownload(downloadFile, monitor);
 				return errorStatus("There is not enought space to save Maemo SDK virtual machine in your computer.");
 			}
-			
+
 			// set the size for this download if it hasn't been already set.
 			if (downloadFile.getSize() == -1) {
 				downloadFile.setSize(contentLength);
 			}
-			
+
 			CopyProgressMonitor progressMonitor = new CopyProgressMonitor(
-					"Downloading Maemo SDK virtual image", remoteFileSize, monitor);
+					"Downloading Maemo SDK virtual image", remoteFileSize,
+					monitor);
 			progressMonitor.setExistingSize(downloadFile.getDownloadedSize());
 			progressMonitor.start();
-	
-			out = new RandomFileOutputStream(fileName,true);
-			out.setFilePointer(downloadFile.getDownloadedSize());	
+
+			out = new RandomFileOutputStream(localFile, true);
+			out.setFilePointer(downloadFile.getDownloadedSize());
 			in = connection.getInputStream();
-			
+
 			// create and start to download
-			monitor.beginTask(remoteURL.getFile(), remoteFileSize != 0 ? remoteFileSize : IProgressMonitor.UNKNOWN);
-			monitor.worked((int)downloadFile.getDownloadedSize());
-			
-			int bufferSize = 64*1024;//64KB
-			DownloadingThread thread = new DownloadingThread(in, out,bufferSize , progressMonitor, monitor);
+			monitor.beginTask(remoteURL.getFile(),
+					remoteFileSize != 0 ? remoteFileSize
+							: IProgressMonitor.UNKNOWN);
+			monitor.worked((int) downloadFile.getDownloadedSize());
+
+			int bufferSize = 64 * 1024;// 64KB
+			DownloadingThread thread = new DownloadingThread(in, out,
+					bufferSize, progressMonitor, monitor);
 			thread.start();
 
-			while (!thread.isInterrupted() && thread.isAlive() ) {
+			while (!thread.isInterrupted() && thread.isAlive()) {
 				try {
 					Thread.sleep(1000);
 				} catch (InterruptedException e) {
 					continue;
 				}
-				
+
 				if (monitor.isCanceled()) {
 					thread.stopDownloading();
-					downloadFile.cancel();					
+					downloadFile.cancel();
 					return Status.CANCEL_STATUS;
 				}
-				
-				if(downloadFile.getStatus() == MaemoSDKVMInfo.Status.PAUSED){
+
+				if (downloadFile.getStatus() == MaemoSDKVMInfo.Status.PAUSED) {
 					thread.doPause();
 				}
-				
-				if(downloadFile.getStatus() == MaemoSDKVMInfo.Status.DOWNLOADING){
+
+				if (downloadFile.getStatus() == MaemoSDKVMInfo.Status.DOWNLOADING) {
 					thread.doResume();
 				}
 			}
-			
+
 			if (thread.isCompleted()) {
 				downloadFile.complete();
 			}
-			
+
 			if (thread.getErrorMessage() != null) {
 				downloadFile.error();
 				throw new IOException(thread.getErrorMessage());
@@ -401,10 +521,9 @@
 			if (connection != null)
 				connection.disconnect();
 		}
-		
 		return Status.OK_STATUS;
 	}
-	
+
 	/**
 	 * Creates an error status based with the given message.
 	 * @param message
@@ -432,8 +551,8 @@
 	 * @return boolean if there is enough space to uncompress the Maemo SDK virtual image (if the free space
 	 * available on disk is bigger than the size of uncompressed Maemo SDK virtual image); false, otherwise.
 	 */
-	private static boolean haveEnoughtFreeSpace(int fileSize, IPath localURL) throws IOException {
-		long freeSpace = FilesystemUtils.freeSpaceOS(localURL,true);
+	private static boolean haveEnoughtFreeSpace(int fileSize, File localFile) throws IOException {
+		long freeSpace = FilesystemUtils.freeSpaceOS(new Path(localFile.getAbsolutePath()),true);
 		return freeSpace > fileSize;
 	}
 	

Modified: branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInfo.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInfo.java	2009-09-09 20:34:40 UTC (rev 2132)
+++ branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInfo.java	2009-09-09 21:34:59 UTC (rev 2133)
@@ -1,241 +1,278 @@
-/*******************************************************************************
- * Copyright (c) 2009 INdT, (c) 2009 Nokia Corporation
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *    Raul Herbster (INdT) - initial API and implementation
- *******************************************************************************/
-package org.maemo.esbox.internal.api.vm.vmware;
-
-import java.net.URL;
-
-import org.eclipse.jface.operation.IRunnableWithProgress;
-
-/**
- * 
- * @author raulherbster
- * 
- */
-public class MaemoSDKVMInfo implements Comparable<MaemoSDKVMInfo> {
-
-	public static final String DOWNLOAD_PAGE = "http://tablets-dev.nokia.com/maemo-dev-env-downloads.php";
-
-	// status for the file
-	public enum Status {
-		DOWNLOADING, // file is being downloaded
-		PAUSED, // download is waiting
-		COMPLETE, // download is complete
-		CANCELLED, // download was canceled
-		ERROR
-		// an error occurred
-	}
-
-	// main information
-	private MaemoSDKVMDescription descriptor;
-	private long size;
-	private long downloaded;
-	private Status status;
-
-	// urls for download and storage
-	private URL localPathURL;
-
-	private boolean hasMoreParts;
-
-	/**
-	 * Constructor.
-	 */
-	public MaemoSDKVMInfo() {
-		this(null);
-	}
-
-	/**
-	 * Constructor.
-	 * 
-	 * @param url
-	 */
-	public MaemoSDKVMInfo(URL localURL) {
-		this.localPathURL = localURL;
-		size = -1;
-		downloaded = 0;
-		descriptor = null;
-		status = Status.DOWNLOADING;
-	}
-
-	/**
-	 * Get the description of this file.
-	 * 
-	 * @return the description of this file.
-	 */
-	public MaemoSDKVMDescription getDescriptor() {
-		return descriptor;
-	}
-
-	/**
-	 * Set the description of this file.
-	 * 
-	 * @param descriptor
-	 *            the new description.
-	 */
-	public void setDescriptor(MaemoSDKVMDescription descriptor) {
-		this.descriptor = descriptor;
-	}
-
-	/**
-	 * Get this download's URL.
-	 * 
-	 * @return
-	 */
-	public URL getLocalURL() {
-		return localPathURL;
-	}
-
-	/**
-	 * Get this download's URL.
-	 * 
-	 * @return
-	 */
-	public void setLocalURL(URL localURL) {
-		this.localPathURL = localURL;
-	}
-
-	/**
-	 * Get this download's size.
-	 * 
-	 * @return
-	 */
-	public long getSize() {
-		return size;
-	}
-
-	/**
-	 * 
-	 * @param size
-	 */
-	public void setSize(long size) {
-		this.size = size;
-	}
-
-	/**
-	 * Get the number of bytes already downloaded.
-	 * 
-	 * @return
-	 */
-	public long getDownloadedSize() {
-		return downloaded;
-	}
-
-	/**
-	 * Set the number of downloaded bytes.
-	 * 
-	 * @param downloaded
-	 */
-	public void setDownloadedSize(long downloaded) {
-		this.downloaded = downloaded;
-	}
-
-	/**
-	 * Get progress of this download file
-	 * 
-	 * @return
-	 */
-	public float getProgress() {
-		return ((float) downloaded / size) * 100;
-	}
-
-	/**
-	 * Return the status of this download file
-	 * 
-	 * @return
-	 */
-	public Status getStatus() {
-		return status;
-	}
-
-	/**
-	 * Set download state to PAUSED.
-	 */
-	public void pause() {
-		status = Status.PAUSED;
-	}
-
-	/**
-	 * Resume the download.
-	 */
-	public void resume() {
-		status = Status.DOWNLOADING;
-	}
-
-	/**
-	 * Set download state to CANCELLED.
-	 */
-	public void cancel() {
-		status = Status.CANCELLED;
-	}
-
-	/**
-	 * Set download state to ERROR.
-	 */
-	public void error() {
-		status = Status.ERROR;
-	}
-
-	/**
-	 * Set download state to ERROR.
-	 */
-	public void complete() {
-		status = Status.COMPLETE;
-	}
-
-	@Override
-	public boolean equals(Object obj) {
-		if (obj == null)
-			return false;
-		if (obj.getClass() != this.getClass())
-			return false;
-		MaemoSDKVMInfo downloadFile = (MaemoSDKVMInfo) obj;
-		return descriptor.equals(downloadFile.getDescriptor());
-
-	}
-
-	/**
-	 * Check if the file has more than one part.
-	 * 
-	 * @return true, if the file has more than one part; false, otherwise.
-	 */
-	public boolean hasMoreParts() {
-		return this.hasMoreParts;
-	}
-
-	/**
-	 * Set if the file has more than one part.
-	 * 
-	 * @param hasMoreParts
-	 */
-	public void setHasMoreParts(boolean hasMoreParts) {
-		this.hasMoreParts = hasMoreParts;
-	}
-
-	/**
-	 * Download the file.
-	 * 
-	 * @return the runnable process
-	 */
-	public IRunnableWithProgress downloadFile() {
-		return new DownloadExecution(this);
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * @see java.lang.Comparable#compareTo(java.lang.Object)
-	 */
-	public int compareTo(MaemoSDKVMInfo o) {
-		if (o == null)
-			return 1;
-		return getDescriptor().compareTo(o.getDescriptor());
-	}
-	
-	
-}
+/*******************************************************************************
+ * Copyright (c) 2009 INdT, (c) 2009 Nokia Corporation
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Raul Herbster (INdT) - initial API and implementation
+ *******************************************************************************/
+package org.maemo.esbox.internal.api.vm.vmware;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.eclipse.jface.operation.IRunnableWithProgress;
+
+/**
+ * 
+ * @author raulherbster
+ * 
+ */
+public class MaemoSDKVMInfo implements Comparable<MaemoSDKVMInfo> {
+//XXX REMOVE ME	public static final String DOWNLOAD_PAGE = "http://localhost:8080/nokia/";
+	public static final String DOWNLOAD_PAGE = "http://tablets-dev.nokia.com/maemo-dev-env-downloads.php";
+
+	// status for the file
+	public enum Status {
+		DOWNLOADING, // file is being downloaded
+		PAUSED, // download is waiting
+		COMPLETE, // download is complete
+		CANCELLED, // download was canceled
+		ERROR
+		// an error occurred
+	}
+
+	// main information
+	private MaemoSDKVMDescription descriptor;
+	private long size;
+	private long downloaded;
+	private Status status;
+
+	// urls for download and storage
+	private URL installLocaltion;
+	private String fileName;
+
+	private int numParts;
+
+	/**
+	 * Constructor.
+	 */
+	public MaemoSDKVMInfo() {
+		this(null);
+	}
+
+	/**
+	 * Constructor.
+	 * 
+	 * @param url
+	 */
+	public MaemoSDKVMInfo(URL localURL) {
+		this.installLocaltion = localURL;
+		size = -1;
+		downloaded = 0;
+		descriptor = null;
+		status = Status.DOWNLOADING;
+		numParts = DefaultVMZipExtractor.SINGLE_FILE_PART;
+	}
+
+	/**
+	 * Get the description of this file.
+	 * 
+	 * @return the description of this file.
+	 */
+	public MaemoSDKVMDescription getDescriptor() {
+		return descriptor;
+	}
+
+	/**
+	 * Set the description of this file.
+	 * 
+	 * @param descriptor
+	 *            the new description.
+	 */
+	public void setDescriptor(MaemoSDKVMDescription descriptor) {
+		this.descriptor = descriptor;
+	}
+
+	/**
+	 * Get this download's URL.
+	 * 
+	 * @return
+	 */
+	public URL getInstallLocation() {
+		return installLocaltion;
+	}
+
+	/**
+	 * Get this download's URL.
+	 * 
+	 * @return
+	 */
+	public void setInstallLocation(URL localURL) {
+		this.installLocaltion = localURL;
+	}
+	
+	/**
+	 * The name of the file
+	 * @return
+	 */
+	public String getFileName(){
+		return this.fileName;
+	}
+	
+	/**
+	 * @return returns the local downloaded file name, it can be null
+	 */
+	public File resolveLocalFile() {
+		return internalResolveLocalFile(getFileName());
+	}
+
+	private File internalResolveLocalFile(String fileName)  {
+		String path = getInstallLocation().getPath();
+		return new File(path, fileName);
+	}
+	
+	/**
+	 * @param fileName the fileName to set
+	 */
+	public void setFileName(String fileName){
+		this.fileName = fileName;
+	}
+
+	/**
+	 * Get this download's size.
+	 * 
+	 * @return
+	 */
+	public long getSize() {
+		return size;
+	}
+
+	/**
+	 * 
+	 * @param size
+	 */
+	public void setSize(long size) {
+		this.size = size;
+	}
+
+	/**
+	 * Get the number of bytes already downloaded.
+	 * 
+	 * @return
+	 */
+	public long getDownloadedSize() {
+		return downloaded;
+	}
+
+	/**
+	 * Set the number of downloaded bytes.
+	 * 
+	 * @param downloaded
+	 */
+	public void setDownloadedSize(long downloaded) {
+		this.downloaded = downloaded;
+	}
+
+	/**
+	 * Get progress of this download file
+	 * 
+	 * @return
+	 */
+	public float getProgress() {
+		return ((float) downloaded / size) * 100;
+	}
+
+	/**
+	 * Return the status of this download file
+	 * 
+	 * @return
+	 */
+	public Status getStatus() {
+		return status;
+	}
+
+	/**
+	 * Set download state to PAUSED.
+	 */
+	public void pause() {
+		status = Status.PAUSED;
+	}
+
+	/**
+	 * Resume the download.
+	 */
+	public void resume() {
+		status = Status.DOWNLOADING;
+	}
+
+	/**
+	 * Set download state to CANCELLED.
+	 */
+	public void cancel() {
+		status = Status.CANCELLED;
+	}
+
+	/**
+	 * Set download state to ERROR.
+	 */
+	public void error() {
+		status = Status.ERROR;
+	}
+
+	/**
+	 * Set download state to ERROR.
+	 */
+	public void complete() {
+		status = Status.COMPLETE;
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if (obj == null)
+			return false;
+		if (obj.getClass() != this.getClass())
+			return false;
+		MaemoSDKVMInfo downloadFile = (MaemoSDKVMInfo) obj;
+		return descriptor.equals(downloadFile.getDescriptor());
+
+	}
+
+	/**
+	 * Check if the file has more than one part.
+	 * 
+	 * @return true, if the file has more than one part; false, otherwise.
+	 */
+	public boolean isMultipart() {
+		return this.numParts > DefaultVMZipExtractor.SINGLE_FILE_PART;
+	}
+
+	/**
+	 * Set if the file has more than one part.
+	 * 
+	 * @param hasMoreParts
+	 */
+	public void setNumberOfParts(int number) {
+		this.numParts = number;
+	}
+
+	/**
+	 * @return
+	 */
+	public int getNumParts(){
+		return numParts;
+	}
+	/**
+	 * Download the file.
+	 * 
+	 * @return the runnable process
+	 */
+	public IRunnableWithProgress downloadFile() {
+		return new DownloadExecution(this);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see java.lang.Comparable#compareTo(java.lang.Object)
+	 */
+	public int compareTo(MaemoSDKVMInfo o) {
+		if (o == null)
+			return 1;
+		return getDescriptor().compareTo(o.getDescriptor());
+	}
+	
+	
+}

Modified: branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInstaller.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInstaller.java	2009-09-09 20:34:40 UTC (rev 2132)
+++ branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInstaller.java	2009-09-09 21:34:59 UTC (rev 2133)
@@ -1,574 +1,519 @@
-/*******************************************************************************
- * Copyright (c) 2009 INdT, (c) 2009 Nokia Corporation
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *    Raul Herbster (INdT) - initial API and implementation
- *******************************************************************************/
-package org.maemo.esbox.internal.api.vm.vmware;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Locale;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jface.dialogs.ProgressMonitorDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.preference.PreferenceDialog;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.dialogs.PreferencesUtil;
-import org.maemo.esbox.internal.api.maemosdk.ui.preferences.MaemoSDKPreferenceIds;
-import org.maemo.esbox.internal.api.vm.vmware.MaemoSDKVMInfo.Status;
-import org.maemo.esbox.internal.scratchbox.sb1.ui.wizard.NewScratchbox1SDKWizard;
-import org.maemo.esbox.internal.scratchbox.sb1.ui.wizard.NewScratchbox1TargetWizard;
-import org.maemo.esbox.internal.vm.vmware.Activator;
-import org.maemo.esbox.internal.vm.vmware.ui.wizards.MaemoSDKVMInstallData;
-import org.maemo.esbox.vm.core.IVirtualMachine;
-import org.maemo.esbox.vm.core.IVirtualMachineConfiguration;
-import org.maemo.esbox.vm.vmware.IVMwareConfiguration;
-import org.maemo.mica.common.core.Policy;
-import org.maemo.mica.common.core.machine.IBuildMachine;
-import org.maemo.mica.common.core.machine.IMachine;
-import org.maemo.mica.common.core.machine.MachineRegistry;
-import org.maemo.mica.common.core.sdk.ISDKTarget;
-import org.maemo.mica.common.core.sdk.SDKManager;
-import org.maemo.mica.internal.api.common.core.filesystem.FilesystemUtils;
-import org.maemo.mica.internal.api.common.core.sdk.SDKManagerInternal;
-import org.maemo.mica.internal.api.linux.packages.core.aptinstall.AptInstallerHelper;
-
-/**
- * This class wraps the main methods used during installation of Maemo SDK
- * virtual image.
- * 
- * @author raulherbster
- * 
- */
-public class MaemoSDKVMInstaller {
-
-	private MaemoSDKVMInstallData installData;
-
-	/**
-	 * Constructor.
-	 * 
-	 * @param installData
-	 *            the installation data
-	 * @param reporter
-	 *            the progress reporter
-	 */
-	public MaemoSDKVMInstaller(MaemoSDKVMInstallData installData) {
-		this.installData = installData;
-	}
-	
-	/**
-	 * Install component into virtual image based on installer data information
-	 * @param timeout the timeout
-	 * @param shell the shell
-	 * @param monitor the monitor
-	 * @return the result status as result for the installation process.
-	 */
-	public IStatus installVirtualImage(int timeout, Shell shell, IProgressMonitor monitor) {
-		IStatus status = Activator.createStatus(IStatus.OK, "Maemo SDK Virtual Image was properly installed.");
-		
-		if (!installData.canUsePreviousInstallation())
-			status = this.downloadVM(shell, monitor);
-		
-		if (canProceed(status))
-			status = this.uncompressVM(shell, monitor);
-		
-		if (canProceed(status))
-			status = promptPreferencesDialog(shell, monitor);		
-		
-		if (canProceed(status) && installData.canInstallSbox())
-			status = this.installScratchbox(shell,monitor);
-		
-		if (canProceed(status) && installData.canInstallTargets())
-			status = this.installScratchboxTargets(shell,monitor);
-
-		if (canProceed(status) && ((installData.canInstallCppEnv() || installData.canInstallPythonEnv())))
-			status = this.installPackages(shell, monitor);
-		
-		return status;
-	}
-
-	/**
-	 * Check if can go ahead on installation based on given status.
-	 * @param status the status.
-	 * @return true if can go ahead on installation process; false, otherwise.
-	 */
-	private boolean canProceed(IStatus status) {
-		return ! (status.matches(IStatus.CANCEL) || status.matches(IStatus.ERROR));
-	}
-	
-	/**
-	 * Download Maemo SDK virtual image. If the virtual image consists of more
-	 * than one file, the other will be also downloaded.
-	 * 
-	 * @return the result of download process as IStatus
-	 */
-	public IStatus downloadVM(final Shell shell, IProgressMonitor monitor) {
-		monitor.subTask("Downloading image...");
-		//reporter.reportStep("Downloading Maemo SDK virtual image...");
-		
-		Display.getDefault().syncExec(new Runnable() {
-
-			public void run() {
-				MaemoSDKVMInfo fileDownload = installData.getFileToDownload();
-				DownloadExecution downloadWrapper = (DownloadExecution) fileDownload.downloadFile();
-				try {
-					DownloadProgressMonitor progressMonitor = new DownloadProgressMonitor(shell, downloadWrapper);
-					progressMonitor.run(true, true, downloadWrapper);
-				} catch (Exception exception) {
-					Activator.getErrorLogger().logAndShowError("Error during Maemo SDK virtual image downloading", exception);
-				}
-			}
-
-		});
-		IStatus result = Policy.getCancelStatus(Activator.getDefault());
-		Status downloadStatus = installData.getFileToDownload().getStatus();
-		if (downloadStatus.equals(Status.CANCELLED))
-			result = Activator.createErrorStatus(
-					"Maemo SDK virtual image download was canceled.", null);
-		else if (downloadStatus.equals(Status.ERROR))
-			result = Activator.createErrorStatus(
-					"An error occured during Maemo SDK virtual image download.", null);
-		else if (downloadStatus.equals(Status.COMPLETE))
-			result = Activator.createStatus(IStatus.OK,
-					"Maemo SDK virtual image was properly downloaded.");
-		return result;
-
-	}
-
-	/**
-	 * Uncompress the Maemo SDK virtual image.
-	 * 
-	 * @return the result of process as IStatus.
-	 */
-	public IStatus uncompressVM(final Shell shell, IProgressMonitor monitor) {
-		monitor.subTask("Uncompressing image...");
-		//reporter.reportStep("Uncompressing Maemo SDK virtual image...");
-		
-		final String fileName = installData.getPathOfExistentVM() == null ? installData.getFileToDownload().getLocalURL().getFile() :
-			installData.getPathOfExistentVM();
-		final String destinationPath = installData.getInstallationPath();
-		
-		final IStatus[] statuses = { Activator.createStatus(IStatus.OK, "File " + fileName
-				+ " was properly uncompressed into " + destinationPath) } ;
-		
-		if (fileName == null || !haveEnoughFreeSpace(fileName,destinationPath) ) {
-			return Activator.createStatus(IStatus.ERROR,"Cannot retrieve information about zipped Maemo SDK virtual image.");
-		} 
-		
-		Display.getDefault().syncExec(new Runnable() {
-
-			public void run() {
-				try {					
-					ProgressMonitorDialog progressMonitor = new ProgressMonitorDialog(shell);	
-					progressMonitor.run(true, true, new IRunnableWithProgress() {
-						
-						public void run(IProgressMonitor monitor)
-								throws InvocationTargetException,
-								InterruptedException {
-							
-														
-							byte[] buf = new byte[1024];
-							ZipInputStream zipInputStream = null;
-							ZipEntry zipEntry = null;
-							FileOutputStream fileOutputStream = null;
-
-							try {
-								zipInputStream = new ZipInputStream(new FileInputStream(fileName));	
-								zipEntry = zipInputStream.getNextEntry();
-								while (zipEntry != null) {						
-									
-									// for each entry to be extracted
-									String entryName = zipEntry.getName();
-									
-									monitor.beginTask("Uncompressing Maemo SDK virtual image", 100);
-									
-									long lenght = zipEntry.getSize();
-									
-									File newFile = new File(entryName);
-									String directory = newFile.getParent();
-									if (directory == null) {
-										if (newFile.isDirectory())
-											break;
-									}
-
-									fileOutputStream = new FileOutputStream(destinationPath
-											+ File.separator + entryName);
-									int n;
-									long totalRead = 0;
-									int previousProgressValue = 0;
-									while ((n = zipInputStream.read(buf, 0, 1024)) > -1) {
-										// write on file
-										fileOutputStream.write(buf, 0, n);
-										
-										// update progress monitor bar
-										totalRead += n;
-										int progressValue = ((int) getProgress(lenght,totalRead));
-										if (previousProgressValue < progressValue) {
-											previousProgressValue = progressValue;
-											monitor.worked(1);
-										}
-										if (monitor.isCanceled())
-											break;
-										monitor.subTask("Uncompressing " + zipEntry
-												+ "\t\t"
-												+ String.format(Locale.US, "%.2f", getProgress(lenght,totalRead)) + "%");
-										
-									}
-									fileOutputStream.close();
-									zipInputStream.closeEntry();
-									
-									if (monitor.isCanceled()) {
-										statuses[0] = Activator.createErrorStatus("Installation was cancelled.", null);
-										return;
-									} else {
-										zipEntry = zipInputStream.getNextEntry();
-									}
-								}
-
-							} catch (IOException ioe) {
-								statuses[0] = Activator.createErrorStatus("Cannot uncompress Maemo SDK virtual image: I/O error", ioe);
-								//reporter.appendStreamText("Cannot uncompress Maemo SDK virtual image.", true);
-							} finally {
-
-								Policy.close(zipInputStream);
-
-								Policy.close(fileOutputStream);
-
-							}
-							
-						}
-						
-					});
-				} catch (Exception e) {
-					statuses[0] = Activator.createErrorStatus("Cannot uncompress Maemo SDK virtual image.", e);
-					//reporter.appendStreamText("Cannot procced with Maemo SDK virtual image uncompressing.",true);
-				}			
-			}
-		});				
-		
-		return statuses[0];
-	}
-	
-	/**
-	 * Utility method to install Scratchbox into Maemo SDK virtual image.
-	 * @param shell the shell
-	 * @param monitor the progress monitor
-	 * @return the result status of process
-	 */
-	private IStatus installScratchbox(final Shell shell, IProgressMonitor monitor) {
-		monitor.subTask("Installing Scratchbox 1...");
-		//reporter.queryToContinue("Installing Scratchbox 1 on Maemo SDK virtual image. This operation will take several minutes.");
-		
-		final IStatus[] statuses = { Activator.createStatus(IStatus.OK, "Scratchbox was properly installed on Maemo SDK virtual image.") } ;
-		
-		Display.getDefault().syncExec(new Runnable() {
-			
-			public void run() {
-				statuses[0] = NewScratchbox1SDKWizard.startWizard();					
-			}
-			
-		});	
-		
-		return statuses[0];
-	}
-	
-	/**
-	 * Utility method to install Scratchbox targets into Maemo SDK virtual image.
-	 * @param shell the shell
-	 * @param monitor the progress monitor
-	 * @return the result status of process
-	 */
-	private IStatus installScratchboxTargets(final Shell shell, IProgressMonitor monitor) {
-		monitor.subTask("Installing Scratchbox 1 targets...");
-		//reporter.logInfo("Installing Scratchbox 1 Targets on Maemo SDK virtual image.  This operation will take several minutes.");
-		
-		final IStatus[] statuses = { Activator.createStatus(IStatus.OK, "Scratchbox targets were properly installed on Maemo SDK virtual image.") } ;
-		
-		final NewScratchbox1TargetWizard wizard = new NewScratchbox1TargetWizard();
-		wizard.setSuppressNokiaBinariesWizard(true);
-		
-		Display.getDefault().syncExec(new Runnable() {
-			
-			public void run() {
-				statuses[0] = NewScratchbox1TargetWizard.startWizard(wizard);
-			}
-			
-		});	
-		
-		// need to break out of syncexec to launch a new wizard on OS X
-		if (statuses[0].getSeverity() == IStatus.OK
-				|| statuses[0].getSeverity() == IStatus.INFO) {
-			Display.getDefault().syncExec(new Runnable() {
-				
-				public void run() {
-					// now install Nokia binaries synchronously
-					wizard.promptInstallNokiaBinaries(true);
-				}
-			});
-		}
-		
-		return statuses[0];
-	}
-	
-	/**
-	 * Get the progress value of uncompressing process.
-	 * @param total
-	 * @param read
-	 * @return
-	 */
-	private float getProgress(long total, long read) {
-		return ((float) read / total) * 100;
-	}
-	
-	/**
-	 * Show a preference dialog that points to virtual image preference page. It is necessary
-	 * to configure the new virtual image so the installation process can proceeed. 
-	 * @param shell
-	 * @return
-	 */
-	private IStatus promptPreferencesDialog(final Shell shell, IProgressMonitor monitor) {		
-		monitor.subTask("Configuring Maemo SDK virtual image...");
-		//reporter.logInfo("Configuring Maemo SDK virtual image...");
-		
-		final IStatus statuses[] = new IStatus[] {Policy.getCancelStatus(Activator.getDefault())};
-		
-		String vmLocation = configureInitialVMSettings();
-		
-		if (!vmLocation.trim().equals("")) {
-
-			Display.getDefault().syncExec(new Runnable() {
-
-				public void run() {
-					try {
-						SDKManagerInternal.getInstance().lock();
-						
-						PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(
-								null,	/* do not tie to a shell to avoid #4438 */ 
-								MaemoSDKPreferenceIds.BUILD_MACHINE_PREFS_ID,
-								new String[] { 
-									MaemoSDKPreferenceIds.ESBOX_PREFERENCE_CATEGORY_ID,
-										MaemoSDKPreferenceIds.BUILD_MACHINE_PREFS_ID, 
-									},
-								null);
-						int result = dialog.open();
-						
-						// user clicked on Cancel
-						if (result == Window.CANCEL) {
-							statuses[0] = Activator.createErrorStatus("Installation was cancelled.", null);
-							return;
-						}
-						
-						// check for valid build machine
-						if (MachineRegistry.getInstance().getCurrentBuildMachines().length == 0)
-							statuses[0] = Activator.createErrorStatus("Virtual image was not properly configured.", null);
-						else
-							statuses[0] = Activator.createStatus(IStatus.OK, "Virtual image configured.");
-						
-					} finally {
-						SDKManagerInternal.getInstance().unlock();
-					}
-				}			
-			});
-		}
-
-		return statuses[0];
-	}
-	
-	/**
-	 * Configure initial VM settings, such as vmx file path.
-	 */
-	public String configureInitialVMSettings() {
-		IBuildMachine vmwareMachine = getVMWareMachine();
-				
-		IVirtualMachineConfiguration machineConfig = ((IVirtualMachine)vmwareMachine).getConfiguration();
-		
-		MachineRegistry.getInstance().setCurrentBuildMachine(vmwareMachine);
-		
-		String vmxFileLocation = getLocationVMXFile();
-		if (vmxFileLocation != null) {
-			vmxFileLocation = installData.getInstallationPath() + File.separator + vmxFileLocation;
-		} else {
-			vmxFileLocation = "";
-		}
-		
-		((IVMwareConfiguration)machineConfig).setVmxPath(vmxFileLocation);
-		
-		return vmxFileLocation;
-	}
-	
-	/**
-	 * Get current VMWare build machine.
-	 * @return VMWare build machine.
-	 */
-	private IBuildMachine getVMWareMachine() {
-		List<IBuildMachine> availableMachines = new ArrayList<IBuildMachine>(
-				Arrays.asList(MachineRegistry.getInstance().getAvailableBuildMachines()));
-		
-		IBuildMachine vmwareMachine = null;
-		
-		for (IBuildMachine buildMachine : availableMachines) {
-			String machineName = buildMachine.getName();
-			if(machineName.contains("VMware")) {
-				vmwareMachine = buildMachine;
-				break;
-			}
-		}
-		
-		return vmwareMachine;
-	}
-	
-	/**
-	 * Get the location of vmx file.
-	 * @return
-	 */
-	public String getLocationVMXFile() {
-		String result = null;
-		File installationPath = new File(installData.getInstallationPath());
-		if (installationPath != null && installationPath.exists() && installationPath.isDirectory()) {
-			String filesNames[] = installationPath.list();
-			for (String fileName : filesNames) {
-				String ext = fileName.substring(fileName.lastIndexOf('.') + 1, fileName.length());	
-				if (ext.equals("vmx")) {
-					result = fileName;
-					break;
-				}
-			}			
-		}
-		return result;
-	}
-	
-	/**
-	 * Install programming environment packages (python and c++) into Maemo SDK virtual image.
-	 * @param timeout
-	 * @param shell
-	 * @param monitor
-	 * @return
-	 */
-	private IStatus installPackages(Shell shell, IProgressMonitor monitor) {
-		monitor.subTask("Installing programming environment...");
-		//reporter.logInfo("Installing Python/C++ programming environment on Maemo SDK virtual image. This operation may take several minutes.");
-		
-		IStatus status = Policy.getCancelStatus(Activator.getDefault());
-		
-		ISDKTarget[] sdkTargets = getBuildMachineTargets();
-		
-		String[] packages = checkPackagesToInstall();
-		
-		status = AptInstallerHelper.installPackages(sdkTargets, packages, true, shell,
-				"Install C++ and Python Programming Environment",
-				"Install the C++ and Python development metapackages now?",
-				null /*reporter*/, null /*monitor*/);
-				
-		return status;
-	}
-	
-	/**
-	 * Get targets of current build machine.
-	 * @return
-	 */
-	private ISDKTarget[] getBuildMachineTargets() {
-		IMachine currentMachine = getBuildMachine();
-
-		if (currentMachine == null)
-			return new ISDKTarget[0];
-
-		List<ISDKTarget> machineTargets = new ArrayList<ISDKTarget>();
-
-		ISDKTarget[] sdkTargets = SDKManager.getInstance().getAllSDKTargets();
-		for (ISDKTarget target : sdkTargets) {
-			IMachine targetMachine = target.getMachine();
-			if (targetMachine.getName().equals(currentMachine.getName()))
-				machineTargets.add(target);
-		}
-
-		return machineTargets.toArray(new ISDKTarget[machineTargets.size()]);
-	}
-	
-	/**
-	 * Get current build machine.
-	 * @return current build machine or <b>null</b> if any build machine is properly configured.
-	 */
-	private IMachine getBuildMachine() {
-		IBuildMachine buildMachines[] =
-			MachineRegistry.getInstance().getBuildMachines();
-		IBuildMachine machine = null;
-		for (IBuildMachine buildMachine : buildMachines) {
-			if (buildMachine.isAlive()) {
-				machine = buildMachine;
-				break;
-			}
-		}		
-		return machine;
-	}
-	
-	/**
-	 * Get packages to be installed into Maemo SDK virtual image based on the given <i>MaemoSDKVMInstallData</i>.
-	 * @return an array of String with packages to be installed into Maemo SDK virtual image.
-	 */
-	private String[] checkPackagesToInstall() {
-		List<String> packagesToInstall = new ArrayList<String>();
-		
-		if (installData.canInstallCppEnv() || installData.canInstallPythonEnv()) {
-			packagesToInstall.add("maemo-debug-scripts");
-			packagesToInstall.add("maemo-c-debug-tools");
-			if (installData.canInstallCppEnv())
-				packagesToInstall.add("maemo-cplusplus-env");
-			if (installData.canInstallPythonEnv())
-				packagesToInstall.add("maemo-python-env");
-		} 
-		
-		return packagesToInstall.toArray(new String[packagesToInstall.size()]);
-	}
-	
-	/**
-	 * Check if there is enough space to uncompress the Maemo SDK virtual image. 
-	 * @param fileName the name of Maemo SDK virtual image.
-	 * @param destinationPath the destination path to uncompress the Maemo SDK virtual image.
-	 * @return boolean if there is enough space to uncompress the Maemo SDK virtual image (if the free space
-	 * available on disk is bigger than the size of uncompressed Maemo SDK virtual image); false, otherwise.
-	 */
-	private static boolean haveEnoughFreeSpace(String fileName, String destinationPath) {
-		ZipInputStream zipInputStream = null;
-		ZipEntry zipEntry;
-		
-		try {
-			long fileSize = 0;
-			zipInputStream = new ZipInputStream(new FileInputStream(fileName));
-			
-			// check the total size of zip file. It is necessary to check the size of each zip file entry.
-			while ((zipEntry = zipInputStream.getNextEntry()) != null) {
-				fileSize += zipEntry.getSize();
-			}		
-			fileSize = fileSize / 1024; //Kb
-			long freeSpace = FilesystemUtils.freeSpaceOS(new Path(destinationPath),true);
-			return freeSpace > fileSize;
-		} catch (IOException e) {
-			Activator.getErrorLogger().logError("Cannot retrieve information about zipped Maemo SDK virtual image. I/O error", e);
-			return false;
-			
-		} finally {			
-			Policy.close(zipInputStream);			
-		}
-		
-		
-	}
-	
-}
+/*******************************************************************************
+ * Copyright (c) 2009 INdT, (c) 2009 Nokia Corporation
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Raul Herbster (INdT) - initial API and implementation
+ *******************************************************************************/
+package org.maemo.esbox.internal.api.vm.vmware;
+
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.preference.PreferenceDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.dialogs.PreferencesUtil;
+import org.maemo.esbox.internal.api.maemosdk.ui.preferences.MaemoSDKPreferenceIds;
+import org.maemo.esbox.internal.api.vm.vmware.MaemoSDKVMInfo.Status;
+import org.maemo.esbox.internal.scratchbox.sb1.ui.wizard.NewScratchbox1SDKWizard;
+import org.maemo.esbox.internal.scratchbox.sb1.ui.wizard.NewScratchbox1TargetWizard;
+import org.maemo.esbox.internal.vm.vmware.Activator;
+import org.maemo.esbox.internal.vm.vmware.ui.wizards.MaemoSDKVMInstallData;
+import org.maemo.esbox.vm.core.IVirtualMachine;
+import org.maemo.esbox.vm.core.IVirtualMachineConfiguration;
+import org.maemo.esbox.vm.vmware.IVMwareConfiguration;
+import org.maemo.mica.common.core.Policy;
+import org.maemo.mica.common.core.machine.IBuildMachine;
+import org.maemo.mica.common.core.machine.IMachine;
+import org.maemo.mica.common.core.machine.MachineRegistry;
+import org.maemo.mica.common.core.sdk.ISDKTarget;
+import org.maemo.mica.common.core.sdk.SDKManager;
+import org.maemo.mica.common.core.ui.IProgressReporter;
+import org.maemo.mica.common.ui.dialogs.DialogUtils;
+import org.maemo.mica.common.ui.dialogs.StyledTextProgressDialog;
+import org.maemo.mica.internal.api.common.core.GeneralUtils;
+import org.maemo.mica.internal.api.common.core.sdk.SDKManagerInternal;
+import org.maemo.mica.internal.api.linux.packages.core.aptinstall.AptInstallerHelper;
+
+/**
+ * This class wraps the main methods used during installation of Maemo SDK
+ * virtual image.
+ * 
+ * @author raulherbster
+ * 
+ */
+public class MaemoSDKVMInstaller {
+
+	private MaemoSDKVMInstallData installData;
+
+	/**
+	 * Constructor.
+	 * 
+	 * @param installData
+	 *            the installation data
+	 * @param reporter
+	 *            the progress reporter
+	 */
+	public MaemoSDKVMInstaller(MaemoSDKVMInstallData installData) {
+		this.installData = installData;
+	}
+	
+	/**
+	 * Install component into virtual image based on installer data information
+	 * @param timeout the timeout
+	 * @param shell the shell
+	 * @param monitor the monitor
+	 * @return the result status as result for the installation process.
+	 */
+	public IStatus installVirtualImage(int timeout, Shell shell, IProgressMonitor monitor) {
+		IStatus status = Activator.createStatus(IStatus.OK, "Maemo SDK Virtual Image was properly installed.");
+		
+		if (!installData.canUsePreviousInstallation())
+			status = this.downloadVM(shell, monitor);
+		
+		if (canProceed(status))
+			status = this.uncompressVM(shell, monitor);
+		
+		if (canProceed(status))
+			status = promptPreferencesDialog(shell, monitor);		
+		
+		if (canProceed(status) && installData.canInstallSbox())
+			status = this.installScratchbox(shell,monitor);
+		
+		if (canProceed(status) && installData.canInstallTargets())
+			status = this.installScratchboxTargets(shell,monitor);
+
+		if (canProceed(status) && ((installData.canInstallCppEnv() || installData.canInstallPythonEnv())))
+			status = this.installPackages(shell, monitor);
+		
+		return status;
+	}
+
+	/**
+	 * Check if can go ahead on installation based on given status.
+	 * @param status the status.
+	 * @return true if can go ahead on installation process; false, otherwise.
+	 */
+	private boolean canProceed(IStatus status) {
+		return ! (status.matches(IStatus.CANCEL) || status.matches(IStatus.ERROR));
+	}
+	
+	/**
+	 * Download Maemo SDK virtual image. If the virtual image consists of more
+	 * than one file, the other will be also downloaded.
+	 * 
+	 * @return the result of download process as IStatus
+	 */
+	public IStatus downloadVM(final Shell shell, IProgressMonitor monitor) {
+		monitor.subTask("Downloading image...");
+		//reporter.reportStep("Downloading Maemo SDK virtual image...");
+		
+		Display.getDefault().syncExec(new Runnable() {
+
+			public void run() {
+				MaemoSDKVMInfo fileDownload = installData.getFileToDownload();
+				DownloadExecution downloadWrapper = (DownloadExecution) fileDownload.downloadFile();
+				try {
+					DownloadProgressMonitor progressMonitor = new DownloadProgressMonitor(shell, downloadWrapper);
+					progressMonitor.run(true, true, downloadWrapper);
+				} catch (Exception exception) {
+					Activator.getErrorLogger().logAndShowError("Error during Maemo SDK virtual image downloading", exception);
+				}
+			}
+
+		});
+		IStatus result = Policy.getCancelStatus(Activator.getDefault());
+		Status downloadStatus = installData.getFileToDownload().getStatus();
+		if (downloadStatus.equals(Status.CANCELLED))
+			result = Activator.createErrorStatus(
+					"Maemo SDK virtual image download was canceled.", null);
+		else if (downloadStatus.equals(Status.ERROR))
+			result = Activator.createErrorStatus(
+					"An error occured during Maemo SDK virtual image download.", null);
+		else if (downloadStatus.equals(Status.COMPLETE))
+			result = Activator.createStatus(IStatus.OK,
+					"Maemo SDK virtual image was properly downloaded.");
+		return result;
+
+	}
+
+	/**
+	 * Uncompress the Maemo SDK virtual image.
+	 * 
+	 * @return the result of process as IStatus.
+	 */
+	public IStatus uncompressVM(final Shell shell, IProgressMonitor monitor) {
+		final StyledTextProgressDialog dialog = new StyledTextProgressDialog(shell, "Uncompressing Image");
+		dialog.setBlockOnOpen(false);
+		
+		dialog.open();
+		
+		final IStatus[] statuses = { Policy.getCancelStatus(Activator.getDefault()) };
+		final IProgressReporter reporter = dialog.getProgressReporter();
+		try {
+			dialog.run(true, true, new IRunnableWithProgress() {
+
+				public void run(IProgressMonitor monitor)
+						throws InvocationTargetException, InterruptedException {
+					statuses[0] = doUncompressVM(dialog.getShell(), reporter, monitor);
+				}
+			});
+			
+			reporter.log(statuses[0]);
+			
+			if (statuses[0].isOK() || statuses[0].getSeverity() == IStatus.INFO) {
+				dialog.close();
+			}
+			
+			return statuses[0];
+		} catch (Exception e) {
+			Throwable t;
+			if (e instanceof InvocationTargetException)
+				t = ((InvocationTargetException) e).getCause();
+			else
+				t = e;
+			IStatus status = Activator.createErrorStatus("Failed to extract image", t);
+			Activator.getErrorLogger().log(status);
+			return status;
+		}
+	}
+
+	/**
+	 * Uncompress the Maemo SDK virtual image.
+	 * 
+	 * @return the result of process as IStatus.
+	 */
+	private IStatus doUncompressVM(final Shell shell, IProgressReporter reporter, IProgressMonitor monitor) {
+		monitor.subTask("Uncompressing image...");
+		reporter.logInfo("Uncompressing Maemo SDK virtual image...");
+		
+		String fileName = null;
+		MaemoSDKVMInfo fileToDownload = installData.getFileToDownload();
+		
+		if(installData.getPathOfExistentVM() == null){
+			File resolvedLocalFile = fileToDownload.resolveLocalFile();
+			if (resolvedLocalFile == null ) {
+				return Activator.createStatus(IStatus.ERROR,"Cannot retrieve information about zipped Maemo SDK virtual image.");
+			}
+			fileName = resolvedLocalFile.getAbsolutePath();
+		}else{
+			fileName = installData.getPathOfExistentVM();
+		}
+		
+		if (fileName == null ) {
+			return Activator.createStatus(IStatus.ERROR,"Cannot retrieve information about zipped Maemo SDK virtual image.");
+		}
+		
+		final String destinationPath = installData.getInstallationPath();
+		
+		IStatus status =  Activator.createStatus(IStatus.OK, "File " + fileName
+				+ " was properly uncompressed into " + destinationPath)  ;
+		
+		
+		int numParts = fileToDownload.getNumParts();
+		long requiredSpace = DefaultVMZipExtractor.getEstimatedDecompressedSize(fileName, numParts);
+		long freeSpace = DefaultVMZipExtractor.getFreeSpaceSize(fileName);
+		
+		if(installData.getUncompressToolPath() == null){
+			if (!DefaultVMZipExtractor.haveEnoughFreeSpace(fileName,destinationPath) ) {
+				return Activator.createStatus(IStatus.ERROR,"There is not enough free space to uncompress the Maemo SDK virtual image files.");
+			}
+			status = DefaultVMZipExtractor.extract(fileName, shell, destinationPath, reporter);
+		}else{
+			Tool7zip tool = new Tool7zip(installData.getUncompressToolPath());
+			
+			if (freeSpace <= requiredSpace ) {
+				reporter.log(Activator.createStatus(IStatus.WARNING, "Low disk space warning, perform a disk cleanup."));
+				if(!DialogUtils
+						.showQuestionDialog(
+								DialogUtils.getShell(),
+								"Low Disk Space Warning",
+								MessageFormat.format(
+								"The disk might not have enough free space to uncompress the" +
+								" Maemo SDK virtual image files.\n"  +
+								"(Estimated size: {0}, Free space: {1}) \n" + 
+								" Do you want to proceed anyway?",
+								GeneralUtils.getFormattedString(requiredSpace), 
+								GeneralUtils.getFormattedString(freeSpace))) ) {
+					return Activator.createStatus(IStatus.ERROR,"There is not enough free space to uncompress the Maemo SDK virtual image files.");
+				}
+			}
+			status = tool.extractAndGetStatus(fileName, destinationPath, reporter, monitor);
+		}
+		return status;
+	}
+	
+	/**
+	 * Utility method to install Scratchbox into Maemo SDK virtual image.
+	 * @param shell the shell
+	 * @param monitor the progress monitor
+	 * @return the result status of process
+	 */
+	private IStatus installScratchbox(final Shell shell, IProgressMonitor monitor) {
+		monitor.subTask("Installing Scratchbox 1...");
+		//reporter.queryToContinue("Installing Scratchbox 1 on Maemo SDK virtual image. This operation will take several minutes.");
+		
+		final IStatus[] statuses = { Activator.createStatus(IStatus.OK, "Scratchbox was properly installed on Maemo SDK virtual image.") } ;
+		
+		Display.getDefault().syncExec(new Runnable() {
+			
+			public void run() {
+				statuses[0] = NewScratchbox1SDKWizard.startWizard();					
+			}
+			
+		});	
+		
+		return statuses[0];
+	}
+	
+	/**
+	 * Utility method to install Scratchbox targets into Maemo SDK virtual image.
+	 * @param shell the shell
+	 * @param monitor the progress monitor
+	 * @return the result status of process
+	 */
+	private IStatus installScratchboxTargets(final Shell shell, IProgressMonitor monitor) {
+		monitor.subTask("Installing Scratchbox 1 targets...");
+		//reporter.logInfo("Installing Scratchbox 1 Targets on Maemo SDK virtual image.  This operation will take several minutes.");
+		
+		final IStatus[] statuses = { Activator.createStatus(IStatus.OK, "Scratchbox targets were properly installed on Maemo SDK virtual image.") } ;
+		
+		final NewScratchbox1TargetWizard wizard = new NewScratchbox1TargetWizard();
+		wizard.setSuppressNokiaBinariesWizard(true);
+		
+		Display.getDefault().syncExec(new Runnable() {
+			
+			public void run() {
+				statuses[0] = NewScratchbox1TargetWizard.startWizard(wizard);
+			}
+			
+		});	
+		
+		// need to break out of syncexec to launch a new wizard on OS X
+		if (statuses[0].getSeverity() == IStatus.OK
+				|| statuses[0].getSeverity() == IStatus.INFO) {
+			Display.getDefault().syncExec(new Runnable() {
+				
+				public void run() {
+					// now install Nokia binaries synchronously
+					wizard.promptInstallNokiaBinaries(true);
+				}
+			});
+		}
+		
+		return statuses[0];
+	}
+	
+	/**
+	 * Show a preference dialog that points to virtual image preference page. It is necessary
+	 * to configure the new virtual image so the installation process can proceeed. 
+	 * @param shell
+	 * @return
+	 */
+	private IStatus promptPreferencesDialog(final Shell shell, IProgressMonitor monitor) {		
+		monitor.subTask("Configuring Maemo SDK virtual image...");
+		//reporter.logInfo("Configuring Maemo SDK virtual image...");
+		
+		final IStatus statuses[] = new IStatus[] {Policy.getCancelStatus(Activator.getDefault())};
+		
+		String vmLocation = configureInitialVMSettings();
+		
+		if (!vmLocation.trim().equals("")) {
+
+			Display.getDefault().syncExec(new Runnable() {
+
+				public void run() {
+					try {
+						SDKManagerInternal.getInstance().lock();
+						
+						PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(
+								null,	/* do not tie to a shell to avoid #4438 */ 
+								MaemoSDKPreferenceIds.BUILD_MACHINE_PREFS_ID,
+								new String[] { 
+									MaemoSDKPreferenceIds.ESBOX_PREFERENCE_CATEGORY_ID,
+										MaemoSDKPreferenceIds.BUILD_MACHINE_PREFS_ID, 
+									},
+								null);
+						int result = dialog.open();
+						
+						// user clicked on Cancel
+						if (result == Window.CANCEL) {
+							statuses[0] = Activator.createErrorStatus("Installation was cancelled.", null);
+							return;
+						}
+						
+						// check for valid build machine
+						if (MachineRegistry.getInstance().getCurrentBuildMachines().length == 0)
+							statuses[0] = Activator.createErrorStatus("Virtual image was not properly configured.", null);
+						else
+							statuses[0] = Activator.createStatus(IStatus.OK, "Virtual image configured.");
+						
+					} finally {
+						SDKManagerInternal.getInstance().unlock();
+					}
+				}			
+			});
+		}
+
+		return statuses[0];
+	}
+	
+	/**
+	 * Configure initial VM settings, such as vmx file path.
+	 */
+	public String configureInitialVMSettings() {
+		IBuildMachine vmwareMachine = getVMWareMachine();
+				
+		IVirtualMachineConfiguration machineConfig = ((IVirtualMachine)vmwareMachine).getConfiguration();
+		
+		MachineRegistry.getInstance().setCurrentBuildMachine(vmwareMachine);
+		
+		String vmxFileLocation = getLocationVMXFile();
+		if (vmxFileLocation != null) {
+			vmxFileLocation = installData.getInstallationPath() + File.separator + vmxFileLocation;
+		} else {
+			vmxFileLocation = "";
+		}
+		
+		((IVMwareConfiguration)machineConfig).setVmxPath(vmxFileLocation);
+		
+		return vmxFileLocation;
+	}
+	
+	/**
+	 * Get current VMWare build machine.
+	 * @return VMWare build machine.
+	 */
+	private IBuildMachine getVMWareMachine() {
+		List<IBuildMachine> availableMachines = new ArrayList<IBuildMachine>(
+				Arrays.asList(MachineRegistry.getInstance().getAvailableBuildMachines()));
+		
+		IBuildMachine vmwareMachine = null;
+		
+		for (IBuildMachine buildMachine : availableMachines) {
+			String machineName = buildMachine.getName();
+			if(machineName.contains("VMware")) {
+				vmwareMachine = buildMachine;
+				break;
+			}
+		}
+		
+		return vmwareMachine;
+	}
+	
+	/**
+	 * Get the location of vmx file.
+	 * @return
+	 */
+	public String getLocationVMXFile() {
+		String result = null;
+		File installationPath = new File(installData.getInstallationPath());
+		if (installationPath != null && installationPath.exists() && installationPath.isDirectory()) {
+			String filesNames[] = installationPath.list();
+			for (String fileName : filesNames) {
+				String ext = fileName.substring(fileName.lastIndexOf('.') + 1, fileName.length());	
+				if (ext.equals("vmx")) {
+					result = fileName;
+					break;
+				}
+			}			
+		}
+		return result;
+	}
+	
+	/**
+	 * Install programming environment packages (python and c++) into Maemo SDK virtual image.
+	 * @param timeout
+	 * @param shell
+	 * @param monitor
+	 * @return
+	 */
+	private IStatus installPackages(Shell shell, IProgressMonitor monitor) {
+		monitor.subTask("Installing programming environment...");
+		//reporter.logInfo("Installing Python/C++ programming environment on Maemo SDK virtual image. This operation may take several minutes.");
+		
+		IStatus status = Policy.getCancelStatus(Activator.getDefault());
+		
+		ISDKTarget[] sdkTargets = getBuildMachineTargets();
+		
+		String[] packages = checkPackagesToInstall();
+		
+		status = AptInstallerHelper.installPackages(sdkTargets, packages, true, shell,
+				"Install C++ and Python Programming Environment",
+				"Install the C++ and Python development metapackages now?",
+				null /*reporter*/, null /*monitor*/);
+				
+		return status;
+	}
+	
+	/**
+	 * Get targets of current build machine.
+	 * @return
+	 */
+	private ISDKTarget[] getBuildMachineTargets() {
+		IMachine currentMachine = getBuildMachine();
+
+		if (currentMachine == null)
+			return new ISDKTarget[0];
+
+		List<ISDKTarget> machineTargets = new ArrayList<ISDKTarget>();
+
+		ISDKTarget[] sdkTargets = SDKManager.getInstance().getAllSDKTargets();
+		for (ISDKTarget target : sdkTargets) {
+			IMachine targetMachine = target.getMachine();
+			if (targetMachine.getName().equals(currentMachine.getName()))
+				machineTargets.add(target);
+		}
+
+		return machineTargets.toArray(new ISDKTarget[machineTargets.size()]);
+	}
+	
+	/**
+	 * Get current build machine.
+	 * @return current build machine or <b>null</b> if any build machine is properly configured.
+	 */
+	private IMachine getBuildMachine() {
+		IBuildMachine buildMachines[] =
+			MachineRegistry.getInstance().getBuildMachines();
+		IBuildMachine machine = null;
+		for (IBuildMachine buildMachine : buildMachines) {
+			if (buildMachine.isAlive()) {
+				machine = buildMachine;
+				break;
+			}
+		}		
+		return machine;
+	}
+	
+	/**
+	 * Get packages to be installed into Maemo SDK virtual image based on the given <i>MaemoSDKVMInstallData</i>.
+	 * @return an array of String with packages to be installed into Maemo SDK virtual image.
+	 */
+	private String[] checkPackagesToInstall() {
+		List<String> packagesToInstall = new ArrayList<String>();
+		
+		if (installData.canInstallCppEnv() || installData.canInstallPythonEnv()) {
+			packagesToInstall.add("maemo-debug-scripts");
+			packagesToInstall.add("maemo-c-debug-tools");
+			if (installData.canInstallCppEnv())
+				packagesToInstall.add("maemo-cplusplus-env");
+			if (installData.canInstallPythonEnv())
+				packagesToInstall.add("maemo-python-env");
+		} 
+		
+		return packagesToInstall.toArray(new String[packagesToInstall.size()]);
+	}
+	
+}

Added: branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/Tool7zip.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/Tool7zip.java	                        (rev 0)
+++ branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/Tool7zip.java	2009-09-09 21:34:59 UTC (rev 2133)
@@ -0,0 +1,141 @@
+package org.maemo.esbox.internal.api.vm.vmware;
+
+import java.io.File;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.maemo.esbox.internal.vm.vmware.Activator;
+import org.maemo.mica.common.core.MicaException;
+import org.maemo.mica.common.core.machine.IMachine;
+import org.maemo.mica.common.core.machine.MachineRegistry;
+import org.maemo.mica.common.core.machine.MachineUtils;
+import org.maemo.mica.common.core.process.CommandLineArguments;
+import org.maemo.mica.common.core.process.IProcessLauncher;
+import org.maemo.mica.common.core.process.IProcessLauncherFactory;
+import org.maemo.mica.common.core.process.IStreamMonitor;
+import org.maemo.mica.common.core.process.ProcessLauncherParameters;
+import org.maemo.mica.common.core.process.ProcessLauncherUtils;
+import org.maemo.mica.common.core.ui.IProgressReporter;
+import org.maemo.mica.common.core.ui.ProgressReporterStreamTextMonitor;
+
+/**
+ * @author Fabrício S Epaminondas 
+ *
+ */
+public class Tool7zip {
+	/**
+	 * No error 
+	 */
+	public static int EXIT_CODE_NO_ERROR = 0;
+	/**
+	 * Warning (Non fatal error(s)). For example, one or more files were locked by some other application, so they were not compressed.
+	 */
+	public static int EXIT_CODE_WARNING = 1;
+	/**
+	 * Fatal error 
+	 */
+	public static int EXIT_CODE_FATAL = 2;
+	/**
+	 * Command line error 
+	 */
+	public static int EXIT_CODE_ERROR = 7;
+	/**
+	 * Not enough memory for operation 
+	 */
+	public static int EXIT_CODE_NOT_ENOUGH_MEMORY = 8;
+	/**
+	 * User stopped the process 
+	 */
+	public static int EXIT_CODE_STOPPED = 255;
+	
+	private String path;
+	private final IMachine machine;
+	
+	
+	/**
+	 * Creates a 7z tool reference using default path
+	 */
+	public Tool7zip() {
+		super();
+		this.machine = MachineRegistry.getInstance().getLocalMachine();
+		IPath path = MachineUtils.findProgramOnPath(machine, "7z");
+		
+		if(path ==null)
+			throw new IllegalArgumentException("7zip could not be found on machine.");
+		this.path = path.toOSString();
+		
+	}
+	/**
+	 * Creates a 7z tool reference using the passed path
+	 * @param path
+	 * @param machine
+	 * @throws MicaException 
+	 */
+	public Tool7zip(String path) {
+		super();
+		this.machine = MachineRegistry.getInstance().getLocalMachine();
+		
+		if(!machine.getFileSystemAccess().getFileStore(new Path(path)).fetchInfo().exists())
+		 	throw new IllegalArgumentException("7zip could not be found on machine.");
+		this.path = path;
+	}
+
+
+	/**
+	 * @param machine 
+	 * @param fileName
+	 * @param destinationPath
+	 * @param monitor 
+	 * @return
+	 * @throws MicaException 
+	 */
+	public int extract(String fileName,
+			String destinationPath,  final IProgressReporter reporter, IProgressMonitor monitor) throws MicaException {
+		String[] commandArray = new String[] {path, "-y", "x", "-o" +destinationPath, fileName};
+		IProcessLauncherFactory factory = machine.getProcessLauncherFactory();
+		IProcessLauncher launcher = factory.createProcessLauncher(ProcessLauncherParameters.create(
+				new Path(new File(fileName).getParent()),
+					CommandLineArguments.createFromArray(commandArray)));
+		
+		return ProcessLauncherUtils.launchAndMonitorStandardStreams(launcher,
+				new IStreamMonitor[] { new ProgressReporterStreamTextMonitor(reporter)}, monitor);
+	}
+	
+	
+	/**
+	 * @param machine 
+	 * @param fileName
+	 * @param destinationPath
+	 * @param monitor 
+	 * @return
+	 * @throws MicaException 
+	 */
+	public IStatus extractAndGetStatus(String fileName,
+			String destinationPath, IProgressReporter reporter, IProgressMonitor monitor) {
+		IStatus status = Activator.createStatus(IStatus.OK, "No error.");
+		try {
+			int exit = extract(fileName, destinationPath, reporter, monitor);
+			if(exit == EXIT_CODE_NO_ERROR){
+				//Ok, no error 
+			}else if(exit == -1){
+				status = Activator.createStatus(IStatus.ERROR, "The file could not be uncompressed.");
+			}else if(exit == EXIT_CODE_WARNING){
+				status = Activator.createStatus(IStatus.WARNING, "One or more files can be locked by some other application, so they were not compressed.");
+			}else if(exit == EXIT_CODE_FATAL){
+				status = Activator.createStatus(IStatus.ERROR, "Fatal error.");
+			}else if(exit == EXIT_CODE_ERROR){
+				status = Activator.createStatus(IStatus.ERROR, "Command line error.");
+			}else if(exit == EXIT_CODE_NOT_ENOUGH_MEMORY){
+				status = Activator.createStatus(IStatus.CANCEL, "Not enough memory for operation.");
+			}else if(exit == EXIT_CODE_STOPPED){
+				status = Activator.createStatus(IStatus.CANCEL, "User stopped the process.");
+			}
+		} catch (MicaException e) {
+			status = Activator.createErrorStatus("Uncompression failed.", e);
+		}
+		
+		return status;
+	}
+}


Property changes on: branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/Tool7zip.java
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallData.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallData.java	2009-09-09 20:34:40 UTC (rev 2132)
+++ branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallData.java	2009-09-09 21:34:59 UTC (rev 2133)
@@ -1,204 +1,219 @@
-/*******************************************************************************
- * Copyright (c) 2009 INdT, (c) 2009 Nokia Corporation
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *    Raul Herbster (INdT) - initial API and implementation
- *******************************************************************************/
-package org.maemo.esbox.internal.vm.vmware.ui.wizards;
-
-import java.io.File;
-import java.net.MalformedURLException;
-
-import org.maemo.esbox.internal.api.vm.vmware.MaemoSDKVMInfo;
-import org.maemo.esbox.internal.vm.vmware.Activator;
-
-/**
- * This is a wrapper that contains information about Maemo SDK virtual image
- * installation process.
- * 
- * @author raulherbster
- * 
- */
-public class MaemoSDKVMInstallData {
-
-	private MaemoSDKVMInfo fileToDownload;
-	private boolean usePreviousInstallation;
-	private String installationPath;
-	private String pathOfExistentVM;
-	private boolean licenseTermsAgreed;
-	private boolean installSbox;
-	private boolean installTargets;
-	private boolean installCppEnv;
-	private boolean installPythonEnv;
-
-	/**
-	 * Constructor.
-	 */
-	public MaemoSDKVMInstallData() {
-		fileToDownload = new MaemoSDKVMInfo();
-	}
-
-	/**
-	 * Set the file to download.
-	 * 
-	 * @param downloadFile
-	 */
-	public void setFileToDownload(MaemoSDKVMInfo downloadFile) {
-		if (downloadFile == null)
-			return;
-		this.fileToDownload = downloadFile;
-		if (fileToDownload.getLocalURL() == null && installationPath != null)
-			try {
-				fileToDownload.setLocalURL(new File(installationPath).toURL());
-			} catch (MalformedURLException e) {
-				Activator.getErrorLogger().logAndShowError(
-						"Cannot get location for file "
-								+ downloadFile.getDescriptor(), e);
-			}
-	}
-
-	/**
-	 * Return the file to download.
-	 * 
-	 * @return
-	 */
-	public MaemoSDKVMInfo getFileToDownload() {
-		return fileToDownload;
-	}
-
-	/**
-	 * @return the usePreviousInstallation
-	 */
-	public boolean canUsePreviousInstallation() {
-		return usePreviousInstallation;
-	}
-
-	/**
-	 * @param usePreviousInstallation
-	 *            the usePreviousInstallation to set
-	 */
-	public void setUsePreviousInstallation(boolean usePreviousInstallation) {
-		this.usePreviousInstallation = usePreviousInstallation;
-	}
-
-	/**
-	 * @return the installationPath
-	 */
-	public String getInstallationPath() {
-		return installationPath;
-	}
-
-	/**
-	 * @param installationPath
-	 *            the installationPath to set
-	 */
-	public void setInstallationPath(String installationPath) {
-		this.installationPath = installationPath;
-		try {
-			fileToDownload.setLocalURL(new File(installationPath).toURL());
-		} catch (MalformedURLException e) {
-			Activator.getErrorLogger().logAndShowError(
-					"Cannot get location for file "
-							+ fileToDownload.getDescriptor(), e);
-		}
-
-	}
-
-	/**
-	 * @return the pathOfExistentVM
-	 */
-	public String getPathOfExistentVM() {
-		return pathOfExistentVM;
-	}
-
-	/**
-	 * @param pathOfExistentVM
-	 *            the pathOfExistentVM to set
-	 */
-	public void setPathOfExistentVM(String pathOfExistentVM) {
-		this.pathOfExistentVM = pathOfExistentVM;
-	}
-
-	/**
-	 * @return the installSbox
-	 */
-	public boolean canInstallSbox() {
-		return installSbox;
-	}
-
-	/**
-	 * @param installSbox
-	 *            the installSbox to set
-	 */
-	public void setInstallSbox(boolean installSbox) {
-		this.installSbox = installSbox;
-	}
-
-	/**
-	 * @return the installTargets
-	 */
-	public boolean canInstallTargets() {
-		return installTargets;
-	}
-
-	/**
-	 * @param installTargets
-	 *            the installTargets to set
-	 */
-	public void setInstallTargets(boolean installTargets) {
-		this.installTargets = installTargets;
-	}
-
-	/**
-	 * @return true, if it is necessary to install Python programming
-	 *         environment; false, otherwise.
-	 */
-	public boolean canInstallPythonEnv() {
-		return installPythonEnv;
-	}
-
-	/**
-	 * @param installTargets
-	 *            the installTargets to set
-	 */
-	public void setInstallPythonEnv(boolean installPythonEnv) {
-		this.installPythonEnv = installPythonEnv;
-	}
-
-	/**
-	 * 
-	 * @return true, if it is necessary to install CPP programming environment;
-	 *         false, otherwise.
-	 */
-	public boolean canInstallCppEnv() {
-		return installCppEnv;
-	}
-
-	/**
-	 * @param installCppEnv
-	 *            the installTargets to set
-	 */
-	public void setInstallCppEnv(boolean installCppEnv) {
-		this.installCppEnv = installCppEnv;
-	}
-
-	/**
-	 * @return true, if license terms were agreed; false, otherwise.
-	 */
-	public boolean isLicenseTermsAgreed() {
-		return licenseTermsAgreed;
-	}
-
-	/**
-	 * @param licenseTermsAgreed
-	 *            the licenseTermsAgreed to set
-	 */
-	public void setLicenseTermsAgreed(boolean licenseTermsAgreed) {
-		this.licenseTermsAgreed = licenseTermsAgreed;
-	}
-
-}
+/*******************************************************************************
+ * Copyright (c) 2009 INdT, (c) 2009 Nokia Corporation
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Raul Herbster (INdT) - initial API and implementation
+ *******************************************************************************/
+package org.maemo.esbox.internal.vm.vmware.ui.wizards;
+
+import java.io.File;
+import java.net.MalformedURLException;
+
+import org.maemo.esbox.internal.api.vm.vmware.MaemoSDKVMInfo;
+import org.maemo.esbox.internal.vm.vmware.Activator;
+
+/**
+ * This is a wrapper that contains information about Maemo SDK virtual image
+ * installation process.
+ * 
+ * @author raulherbster
+ * 
+ */
+public class MaemoSDKVMInstallData {
+
+	private MaemoSDKVMInfo fileToDownload;
+	private boolean usePreviousInstallation;
+	private String installationPath;
+	private String pathOfExistentVM;
+	private String uncompressToolPath;
+	private boolean licenseTermsAgreed;
+	private boolean installSbox;
+	private boolean installTargets;
+	private boolean installCppEnv;
+	private boolean installPythonEnv;
+
+	/**
+	 * Constructor.
+	 */
+	public MaemoSDKVMInstallData() {
+		fileToDownload = new MaemoSDKVMInfo();
+	}
+
+	/**
+	 * Set the file to download.
+	 * 
+	 * @param downloadFile
+	 */
+	public void setFileToDownload(MaemoSDKVMInfo downloadFile) {
+		if (downloadFile == null)
+			return;
+		this.fileToDownload = downloadFile;
+		if (fileToDownload.getInstallLocation() == null && installationPath != null)
+			try {
+				fileToDownload.setInstallLocation(new File(installationPath).toURL());
+			} catch (MalformedURLException e) {
+				Activator.getErrorLogger().logAndShowError(
+						"Cannot get location for file "
+								+ downloadFile.getDescriptor(), e);
+			}
+	}
+
+	/**
+	 * Return the file to download.
+	 * 
+	 * @return
+	 */
+	public MaemoSDKVMInfo getFileToDownload() {
+		return fileToDownload;
+	}
+
+	/**
+	 * @return the usePreviousInstallation
+	 */
+	public boolean canUsePreviousInstallation() {
+		return usePreviousInstallation;
+	}
+
+	/**
+	 * @param usePreviousInstallation
+	 *            the usePreviousInstallation to set
+	 */
+	public void setUsePreviousInstallation(boolean usePreviousInstallation) {
+		this.usePreviousInstallation = usePreviousInstallation;
+	}
+
+	/**
+	 * @return the installationPath
+	 */
+	public String getInstallationPath() {
+		return installationPath;
+	}
+
+	/**
+	 * @param installationPath
+	 *            the installationPath to set
+	 */
+	public void setInstallationPath(String installationPath) {
+		this.installationPath = installationPath;
+		try {
+			fileToDownload.setInstallLocation(new File(installationPath).toURL());
+		} catch (MalformedURLException e) {
+			Activator.getErrorLogger().logAndShowError(
+					"Cannot get location for file "
+							+ fileToDownload.getDescriptor(), e);
+		}
+
+	}
+
+	/**
+	 * @return the pathOfExistentVM
+	 */
+	public String getPathOfExistentVM() {
+		return pathOfExistentVM;
+	}
+	
+	/**
+	 * @return the path of uncompress tool to be used.
+	 */
+	public String getUncompressToolPath() {
+		return uncompressToolPath;
+	}
+	
+	/**
+	 * @param pathOfExistentVM
+	 *            the pathOfExistentVM to set
+	 */
+	public void setPathOfExistentVM(String pathOfExistentVM) {
+		this.pathOfExistentVM = pathOfExistentVM;
+	}
+
+	/**
+	 * @return the installSbox
+	 */
+	public boolean canInstallSbox() {
+		return installSbox;
+	}
+
+	/**
+	 * @param installSbox
+	 *            the installSbox to set
+	 */
+	public void setInstallSbox(boolean installSbox) {
+		this.installSbox = installSbox;
+	}
+
+	/**
+	 * @return the installTargets
+	 */
+	public boolean canInstallTargets() {
+		return installTargets;
+	}
+
+	/**
+	 * @param installTargets
+	 *            the installTargets to set
+	 */
+	public void setInstallTargets(boolean installTargets) {
+		this.installTargets = installTargets;
+	}
+
+	/**
+	 * @return true, if it is necessary to install Python programming
+	 *         environment; false, otherwise.
+	 */
+	public boolean canInstallPythonEnv() {
+		return installPythonEnv;
+	}
+
+	/**
+	 * @param installTargets
+	 *            the installTargets to set
+	 */
+	public void setInstallPythonEnv(boolean installPythonEnv) {
+		this.installPythonEnv = installPythonEnv;
+	}
+
+	/**
+	 * 
+	 * @return true, if it is necessary to install CPP programming environment;
+	 *         false, otherwise.
+	 */
+	public boolean canInstallCppEnv() {
+		return installCppEnv;
+	}
+
+	/**
+	 * @param installCppEnv
+	 *            the installTargets to set
+	 */
+	public void setInstallCppEnv(boolean installCppEnv) {
+		this.installCppEnv = installCppEnv;
+	}
+
+	/**
+	 * @return true, if license terms were agreed; false, otherwise.
+	 */
+	public boolean isLicenseTermsAgreed() {
+		return licenseTermsAgreed;
+	}
+
+	/**
+	 * @param licenseTermsAgreed
+	 *            the licenseTermsAgreed to set
+	 */
+	public void setLicenseTermsAgreed(boolean licenseTermsAgreed) {
+		this.licenseTermsAgreed = licenseTermsAgreed;
+	}
+	
+	/**
+	 * @param path the path of the uncompress tool to be used during virtual image uncompressing.
+	 */
+	public void setUncompressToolPath(String path) {
+		this.uncompressToolPath = path;
+	}
+
+}

Modified: branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallerContentLabelProvider.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallerContentLabelProvider.java	2009-09-09 20:34:40 UTC (rev 2132)
+++ branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallerContentLabelProvider.java	2009-09-09 21:34:59 UTC (rev 2133)
@@ -1,271 +1,271 @@
-/*******************************************************************************
- * Copyright (c) 2009 INdT, (c) 2009 Nokia Corporation
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *    Raul Herbster (INdT) - initial API and implementation
- *******************************************************************************/
-package org.maemo.esbox.internal.vm.vmware.ui.wizards;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.eclipse.swt.graphics.Image;
-import org.maemo.esbox.internal.api.vm.vmware.MaemoSDKVMDescription;
-import org.maemo.esbox.internal.api.vm.vmware.MaemoSDKVMInfo;
-import org.maemo.esbox.internal.vm.vmware.Activator;
-import org.maemo.mica.internal.api.common.ui.LazyLoadingThreadTableContentProvider;
-
-import com.nokia.cpp.internal.api.utils.core.FileUtils;
-
-/**
- * Content and label provider for table that shows available Maemo SDK virtual
- * images.
- * 
- * @author raulherbster
- * 
- */
-public class MaemoSDKVMInstallerContentLabelProvider extends
-		LazyLoadingThreadTableContentProvider {
-
-	/**
-	 * Thread to access information about available Maemo SDK virtual images on
-	 * website.
-	 * 
-	 * @author raulherbster
-	 * 
-	 */
-	protected class MaemoVMInstallScriptFetcherThread extends Thread {
-		protected Object newInput;
-
-		/**
-		 * Construtor.
-		 * 
-		 * @param newInput
-		 */
-		public MaemoVMInstallScriptFetcherThread(Object newInput) {
-			this.newInput = newInput;
-		}
-
-		/*
-		 * (non-Javadoc)
-		 * 
-		 * @see java.lang.Thread#run()
-		 */
-		public void run() {
-			doFetchScripts();
-
-			contents.remove(LOADING_LABEL);
-			doFireContentChanged();
-		}
-
-		/**
-		 * Implement by querying the input and/or calling fetchScriptsFromUrl()
-		 * and adding them to contents.
-		 */
-		protected void doFetchScripts() {
-			List<MaemoSDKVMDescription> virtualImagesNames = fetchVMNamesFromUrl("http://tablets-dev.nokia.com/maemo-dev-env-downloads.php");
-			for (MaemoSDKVMDescription maemoSDKVM : virtualImagesNames) {
-				MaemoSDKVMInfo downloadFile = new MaemoSDKVMInfo();
-				downloadFile.setDescriptor(maemoSDKVM);
-				if (!contents.contains(downloadFile))
-					contents.add(downloadFile);
-				else {
-					int indexOfExistingDownloadFile = contents
-							.indexOf(downloadFile);
-					((MaemoSDKVMInfo) contents.get(indexOfExistingDownloadFile))
-							.setHasMoreParts(true);
-				}
-			}
-		}
-
-		/**
-		 * Get available Maemo SDK virtual image from given URL.
-		 * 
-		 * @param urlString
-		 *            the url of website that contains information about
-		 *            available Maemo SDK virtual images.
-		 * @return a list with the names of available Maemo SDK virtual images.
-		 */
-		protected List<MaemoSDKVMDescription> fetchVMNamesFromUrl(String urlString) {
-			URL url;
-			try {
-				url = new URL(urlString);
-			} catch (MalformedURLException e) {
-				Activator.getErrorLogger().logAndShowError(
-						"Invalid URL: " + urlString, e);
-				return Collections.emptyList();
-			}
-
-			List<MaemoSDKVMDescription> virtualImagesDescriptors = new ArrayList<MaemoSDKVMDescription>();
-			try {
-
-				URLConnection connection = url.openConnection();
-				connection.setConnectTimeout(1000 * 10);
-				connection.connect();
-
-				// apparently this fetches the HTML...
-				String content = new String(FileUtils.readInputStreamContents(
-						connection.getInputStream(), "UTF-8"));
-
-				/*
-				 * The names of virtual images are on
-				 * http://tablets-dev.nokia.com/maemo-dev-env-downloads.php
-				 * (front-page). Basically, they list have the following format:
-				 * Maemo ANY_WORD Virtual ANY_WORD Image ANY_WORD Also, we
-				 * filter duplicated entries, for example, files split into two
-				 * parts.
-				 */
-				String license = getLicense(content);
-				
-				Pattern maemoVMPattern = Pattern
-						.compile("Maemo(\\s)+SDK(\\s)+Virtual(\\s)+Image(\\s)+with(\\s)+Ubuntu(\\s)+(\\w)+(\\s)+([\\d]*\\.[\\d]*)(\\s)+(Server|Desktop)(\\s\\-(Part)\\s\\d)?");
-				Matcher matcher = maemoVMPattern.matcher(content);
-				while (matcher.find()) {
-					String virtualImageName = matcher.group(0);
-					String version = matcher.group(9);
-					virtualImageName = processVirtualImageName(virtualImageName);
-					boolean isServer = virtualImageName.toLowerCase().contains("server");
-					String virtualImageDescription = isServer ? MaemoSDKVMDescription.SERVER_IMAGE_DESCRIPTION : MaemoSDKVMDescription.DESKTOP_IMAGE_DESCRIPTION;
-					virtualImagesDescriptors.add(new MaemoSDKVMDescription(isServer,virtualImageName,version,virtualImageDescription,license));
-				}
-			} catch (Exception e) {
-				if (e instanceof InterruptedException)
-					return virtualImagesDescriptors;
-
-				if (!isInterrupted())
-					Activator.getErrorLogger().logAndShowError(
-							"Could not fetch listing from " + url, e);
-			}
-
-			return virtualImagesDescriptors;
-		}
-
-		/**
-		 * Process the description of Maemo SDK virtual image and only returns
-		 * the main description.
-		 * 
-		 * @param virtualImageName
-		 *            the complete description of a certain Maemo SDK virtual
-		 *            image.
-		 * @return the main description of a certain Maemo SDK virtual image.
-		 */
-		private String processVirtualImageName(String virtualImageName) {
-			int indexOfPar = virtualImageName.indexOf("(");
-			if (indexOfPar < 0)
-				return virtualImageName;
-			return virtualImageName.substring(0, indexOfPar).trim();
-		}
-		
-		/**
-		 * Get license from virtual images website.
-		 * @param content
-		 * @return
-		 */
-		private String getLicense(String content) {
-			final String LICENSE_PATTERN = "IMPORTANT:\\s*READ\\s*CAREFULLY\\s*BEFORE\\s*INSTALLING,\\s*DOWNLOADING,\\s*OR\\s*USING\\s*THE\\s*SOFTWARE(.*?)PLEASE\\s*SUBMIT\\s*ANY\\s*ACCOMPANYING\\s*REGISTRATION\\s*FORMS\\s*TO\\s*RECEIVE\\s*REGISTRATION\\s*BENEFITS\\s*WHERE\\s*APPLICABLE";
-			Pattern licensePattern = Pattern.compile(LICENSE_PATTERN,Pattern.DOTALL | Pattern.UNIX_LINES);
-			Matcher matcher = licensePattern.matcher(content);
-			String license = "";
-			while (matcher.find()) {
-				license = matcher.group(0);				
-			}
-			return license;
-		}
-	}
-
-	private Image vmImage;
-
-	/**
-	 * Construtor.
-	 */
-	public MaemoSDKVMInstallerContentLabelProvider() {
-		super();
-		vmImage = Activator.MAEMO_VM_DESCRIPTOR.createImage();
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see
-	 * org.maemo.mica.common.ui.common.LazyLoadingThreadTableContentProvider
-	 * #createContentFetchThread(java.lang.Object)
-	 */
-	@Override
-	protected Thread createContentFetchThread(Object newInput) {
-		return new MaemoVMInstallScriptFetcherThread(newInput);
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see
-	 * org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.
-	 * Object)
-	 */
-	public Object[] getChildren(Object parentElement) {
-		return null;
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see
-	 * org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object
-	 * )
-	 */
-	public Object getParent(Object element) {
-		return null;
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see
-	 * org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.
-	 * Object)
-	 */
-	public boolean hasChildren(Object element) {
-		return false;
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
-	 */
-	public String getColumnText(Object element, int column) {
-		if (element == LOADING_LABEL)
-			return super.getColumnText(element, column);
-
-		if (element instanceof MaemoSDKVMInfo) {
-			MaemoSDKVMInfo data = (MaemoSDKVMInfo) element;
-			if (column == 0)
-				return data.getDescriptor().getName();
-		}
-		return "";
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
-	 */
-	public Image getColumnImage(Object element, int column) {
-		if (element instanceof MaemoSDKVMInfo) {
-			if (column == 0)
-				return vmImage;
-		}
-		return null;
-	}
-
-}
+/*******************************************************************************
+ * Copyright (c) 2009 INdT, (c) 2009 Nokia Corporation
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Raul Herbster (INdT) - initial API and implementation
+ *******************************************************************************/
+package org.maemo.esbox.internal.vm.vmware.ui.wizards;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.swt.graphics.Image;
+import org.maemo.esbox.internal.api.vm.vmware.MaemoSDKVMDescription;
+import org.maemo.esbox.internal.api.vm.vmware.MaemoSDKVMInfo;
+import org.maemo.esbox.internal.vm.vmware.Activator;
+import org.maemo.mica.internal.api.common.ui.LazyLoadingThreadTableContentProvider;
+
+import com.nokia.cpp.internal.api.utils.core.FileUtils;
+
+/**
+ * Content and label provider for table that shows available Maemo SDK virtual
+ * images.
+ * 
+ * @author raulherbster
+ * 
+ */
+public class MaemoSDKVMInstallerContentLabelProvider extends
+		LazyLoadingThreadTableContentProvider {
+
+	/**
+	 * Thread to access information about available Maemo SDK virtual images on
+	 * website.
+	 * 
+	 * @author raulherbster
+	 * 
+	 */
+	protected class MaemoVMInstallScriptFetcherThread extends Thread {
+		protected Object newInput;
+
+		/**
+		 * Construtor.
+		 * 
+		 * @param newInput
+		 */
+		public MaemoVMInstallScriptFetcherThread(Object newInput) {
+			this.newInput = newInput;
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see java.lang.Thread#run()
+		 */
+		public void run() {
+			doFetchScripts();
+
+			contents.remove(LOADING_LABEL);
+			doFireContentChanged();
+		}
+
+		/**
+		 * Implement by querying the input and/or calling fetchScriptsFromUrl()
+		 * and adding them to contents.
+		 */
+		protected void doFetchScripts() {
+			List<MaemoSDKVMDescription> virtualImagesNames = fetchVMNamesFromUrl(MaemoSDKVMInfo.DOWNLOAD_PAGE);
+			for (MaemoSDKVMDescription maemoSDKVM : virtualImagesNames) {
+				MaemoSDKVMInfo downloadFile = new MaemoSDKVMInfo();
+				downloadFile.setDescriptor(maemoSDKVM);
+				if (!contents.contains(downloadFile))
+					contents.add(downloadFile);
+				else {
+					int indexOfExistingDownloadFile = contents
+							.indexOf(downloadFile);
+					MaemoSDKVMInfo info = ((MaemoSDKVMInfo) contents.get(indexOfExistingDownloadFile));
+					info.setNumberOfParts(info.getNumParts() +1);
+				}
+			}
+		}
+
+		/**
+		 * Get available Maemo SDK virtual image from given URL.
+		 * 
+		 * @param urlString
+		 *            the url of website that contains information about
+		 *            available Maemo SDK virtual images.
+		 * @return a list with the names of available Maemo SDK virtual images.
+		 */
+		protected List<MaemoSDKVMDescription> fetchVMNamesFromUrl(String urlString) {
+			URL url;
+			try {
+				url = new URL(urlString);
+			} catch (MalformedURLException e) {
+				Activator.getErrorLogger().logAndShowError(
+						"Invalid URL: " + urlString, e);
+				return Collections.emptyList();
+			}
+
+			List<MaemoSDKVMDescription> virtualImagesDescriptors = new ArrayList<MaemoSDKVMDescription>();
+			try {
+
+				URLConnection connection = url.openConnection();
+				connection.setConnectTimeout(1000 * 10);
+				connection.connect();
+
+				// apparently this fetches the HTML...
+				String content = new String(FileUtils.readInputStreamContents(
+						connection.getInputStream(), "UTF-8"));
+
+				/*
+				 * The names of virtual images are on
+				 * http://tablets-dev.nokia.com/maemo-dev-env-downloads.php
+				 * (front-page). Basically, they list have the following format:
+				 * Maemo ANY_WORD Virtual ANY_WORD Image ANY_WORD Also, we
+				 * filter duplicated entries, for example, files split into two
+				 * parts.
+				 */
+				String license = getLicense(content);
+				
+				Pattern maemoVMPattern = Pattern
+						.compile("Maemo(\\s)+SDK(\\s)+Virtual(\\s)+Image(\\s)+with(\\s)+Ubuntu(\\s)+(\\w)+(\\s)+([\\d]*\\.[\\d]*)(\\s)+(Server|Desktop)(\\s\\-(Part)\\s\\d)?");
+				Matcher matcher = maemoVMPattern.matcher(content);
+				while (matcher.find()) {
+					String virtualImageName = matcher.group(0);
+					String version = matcher.group(9);
+					virtualImageName = processVirtualImageName(virtualImageName);
+					boolean isServer = virtualImageName.toLowerCase().contains("server");
+					String virtualImageDescription = isServer ? MaemoSDKVMDescription.SERVER_IMAGE_DESCRIPTION : MaemoSDKVMDescription.DESKTOP_IMAGE_DESCRIPTION;
+					virtualImagesDescriptors.add(new MaemoSDKVMDescription(isServer,virtualImageName,version,virtualImageDescription,license));
+				}
+			} catch (Exception e) {
+				if (e instanceof InterruptedException)
+					return virtualImagesDescriptors;
+
+				if (!isInterrupted())
+					Activator.getErrorLogger().logAndShowError(
+							"Could not fetch listing from " + url, e);
+			}
+
+			return virtualImagesDescriptors;
+		}
+
+		/**
+		 * Process the description of Maemo SDK virtual image and only returns
+		 * the main description.
+		 * 
+		 * @param virtualImageName
+		 *            the complete description of a certain Maemo SDK virtual
+		 *            image.
+		 * @return the main description of a certain Maemo SDK virtual image.
+		 */
+		private String processVirtualImageName(String virtualImageName) {
+			int indexOfPar = virtualImageName.indexOf("(");
+			if (indexOfPar < 0)
+				return virtualImageName;
+			return virtualImageName.substring(0, indexOfPar).trim();
+		}
+		
+		/**
+		 * Get license from virtual images website.
+		 * @param content
+		 * @return
+		 */
+		private String getLicense(String content) {
+			final String LICENSE_PATTERN = "IMPORTANT:\\s*READ\\s*CAREFULLY\\s*BEFORE\\s*INSTALLING,\\s*DOWNLOADING,\\s*OR\\s*USING\\s*THE\\s*SOFTWARE(.*?)PLEASE\\s*SUBMIT\\s*ANY\\s*ACCOMPANYING\\s*REGISTRATION\\s*FORMS\\s*TO\\s*RECEIVE\\s*REGISTRATION\\s*BENEFITS\\s*WHERE\\s*APPLICABLE";
+			Pattern licensePattern = Pattern.compile(LICENSE_PATTERN,Pattern.DOTALL | Pattern.UNIX_LINES);
+			Matcher matcher = licensePattern.matcher(content);
+			String license = "";
+			while (matcher.find()) {
+				license = matcher.group(0);				
+			}
+			return license;
+		}
+	}
+
+	private Image vmImage;
+
+	/**
+	 * Construtor.
+	 */
+	public MaemoSDKVMInstallerContentLabelProvider() {
+		super();
+		vmImage = Activator.MAEMO_VM_DESCRIPTOR.createImage();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.maemo.mica.common.ui.common.LazyLoadingThreadTableContentProvider
+	 * #createContentFetchThread(java.lang.Object)
+	 */
+	@Override
+	protected Thread createContentFetchThread(Object newInput) {
+		return new MaemoVMInstallScriptFetcherThread(newInput);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.
+	 * Object)
+	 */
+	public Object[] getChildren(Object parentElement) {
+		return null;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object
+	 * )
+	 */
+	public Object getParent(Object element) {
+		return null;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.
+	 * Object)
+	 */
+	public boolean hasChildren(Object element) {
+		return false;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
+	 */
+	public String getColumnText(Object element, int column) {
+		if (element == LOADING_LABEL)
+			return super.getColumnText(element, column);
+
+		if (element instanceof MaemoSDKVMInfo) {
+			MaemoSDKVMInfo data = (MaemoSDKVMInfo) element;
+			if (column == 0)
+				return data.getDescriptor().getName();
+		}
+		return "";
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
+	 */
+	public Image getColumnImage(Object element, int column) {
+		if (element instanceof MaemoSDKVMInfo) {
+			if (column == 0)
+				return vmImage;
+		}
+		return null;
+	}
+
+}

Modified: branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMSelectionWizardPage.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMSelectionWizardPage.java	2009-09-09 20:34:40 UTC (rev 2132)
+++ branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMSelectionWizardPage.java	2009-09-09 21:34:59 UTC (rev 2133)
@@ -533,6 +533,8 @@
 	private MaemoSDKVMInfo getLatestVMInstallData(LabelProviderChangedEvent event) {
 		LazyLoadingThreadTableContentProvider provider = (LazyLoadingThreadTableContentProvider)event.getSource();
 		Object[] elements = provider.getElements(new Object[0]);
+		if (elements.length == 0)
+			return null;
 		Arrays.sort(elements);
 		return (MaemoSDKVMInfo) elements[0];
 	}

Added: branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMUncompressInfoWizardPage.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMUncompressInfoWizardPage.java	                        (rev 0)
+++ branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMUncompressInfoWizardPage.java	2009-09-09 21:34:59 UTC (rev 2133)
@@ -0,0 +1,186 @@
+/*******************************************************************************
+ * Copyright (c) 2009 INdT, (c) 2009 Nokia Corporation
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Raul Herbster (INdT) - initial API and implementation
+ *******************************************************************************/
+package org.maemo.esbox.internal.vm.vmware.ui.wizards;
+
+import java.io.File;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Text;
+import org.maemo.esbox.internal.vm.vmware.Activator;
+import org.maemo.mica.common.core.machine.IMachine;
+import org.maemo.mica.common.core.machine.MachineRegistry;
+import org.maemo.mica.common.core.machine.MachineUtils;
+import org.maemo.mica.common.ui.dialogs.DialogUtils;
+
+/**
+ * This page displays information about Maemo SDK virtual machine configuration.
+ * 
+ * @author raulherbster
+ * 
+ */
+public class MaemoSDKVMUncompressInfoWizardPage extends WizardPage {
+
+	// options for uncompress tool
+	private Text uncompressToolTextField;
+	
+	/**
+	 * Constructor.
+	 * 
+	 * @param wizard
+	 *            parent wizard.
+	 */
+	protected MaemoSDKVMUncompressInfoWizardPage(NewMaemoSDKVMWizard wizard) {
+		super("maemovm_uncompresstool", "Uncompress tool specification",
+				Activator.MAEMO_VM_WIZBAN_DESCRIPTOR);
+		setDescription("Specify the tool used to uncompress Maemo SDK Virtual Image.");
+		setWizard(wizard);
+		setPageComplete(false);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
+	 * .Composite)
+	 */
+	public void createControl(Composite parent) {
+		Composite composite = new Composite(parent, SWT.NONE);
+		GridLayoutFactory.fillDefaults().numColumns(4).applyTo(composite);
+		GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);
+		setControl(composite);
+		
+		Label mainMessage = new Label(composite, SWT.WRAP);
+		mainMessage.setText("Maemo SDK Virtual Image wizard also uncompress the virtual machine for you. " +
+							"However, since Maemo SDK Virtual Images are considerable large, most of existing tools cannot uncompress them.\n" +
+							"This wizard uses 7zip tool for uncompression, please specify a valid path for 7zip tool bellow.");
+		
+		GridData labelData = new GridData();
+		labelData.horizontalSpan = 4;
+	    labelData.horizontalAlignment = SWT.FILL;
+	    Rectangle rect = getShell().getMonitor().getClientArea();
+	    labelData.widthHint = rect.width / 4;
+	    mainMessage.setLayoutData(labelData);
+
+		Label separator = new Label(composite, SWT.NONE);
+		GridDataFactory.swtDefaults().span(4, 1).align(SWT.LEFT, SWT.CENTER)
+				.applyTo(separator);
+		
+		
+		Label uncompressToollabel = new Label(composite, SWT.NONE);
+		uncompressToollabel.setText("Uncompress tool path:");
+		GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER)
+				.applyTo(uncompressToollabel);
+	
+		uncompressToolTextField = new Text(composite, SWT.BORDER);
+		uncompressToolTextField.setText(getDefault7zPath());
+		uncompressToolTextField.setToolTipText("Specify the path of tool to uncompress Maemo SDK Virtual Image.");
+		GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(
+				uncompressToolTextField);
+		
+		Listener textFieldValidator = new Listener() {
+				public void handleEvent(Event event) {
+					validatePage();
+				}
+		};
+		
+		uncompressToolTextField.addListener(SWT.SELECTED, textFieldValidator);
+		uncompressToolTextField.addListener(SWT.KeyDown, textFieldValidator);
+		uncompressToolTextField.addListener(SWT.KeyUp, textFieldValidator);
+	
+		Button browserButton = new Button(composite, SWT.PUSH);
+		browserButton.setText("Browse...");
+		GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(
+				browserButton);
+		browserButton.addSelectionListener(new SelectionAdapter() {
+	
+			public void widgetSelected(SelectionEvent evt) {
+				FileDialog dialog = new FileDialog(DialogUtils.getShell(),
+						SWT.OPEN);
+				
+				String currentFile = uncompressToolTextField.getText();
+				if (currentFile.length() > 0) {
+					File current = new File(currentFile);
+					dialog.setFilterPath(current.getParent());
+					dialog.setFileName(current.getName());
+				}
+				dialog.setText("Select the path of uncompress tool");
+				String pathDirectory = dialog.open();
+				if (pathDirectory != null) {
+					uncompressToolTextField.setText(pathDirectory);
+					validatePage();
+				}
+			}
+		});
+		
+		validatePage();
+	}
+	
+	/**
+	 * Validate the wizard page.
+	 */
+	public void validatePage() {
+		String errorMessage = null;
+		
+		String uncompressToolPath = uncompressToolTextField.getText().trim();
+        if (uncompressToolPath.equals("")){
+			errorMessage = "You must specify the path of tool to uncompress the Maemo SDK Virtual Image.";
+		} else {
+			File file = new File(uncompressToolPath);
+			if (!file.exists() || file.isDirectory()){
+				errorMessage = "Invalid path for uncompress tool. Please, select a valid directory.";
+			} else {
+				((NewMaemoSDKVMWizard) getWizard()).getInstallData().setUncompressToolPath(uncompressToolPath);
+			}
+		}
+        
+		setErrorMessage(errorMessage);
+		setPageComplete(errorMessage == null);
+	}
+
+	
+	public static String getDefault7zPath(){
+		String path = "/usr/bin/7z";
+		
+		IMachine machine = MachineRegistry.getInstance().getLocalMachine();
+		IPath defaultPath = MachineUtils.findProgramOnPath(machine, "7z");
+		
+		if(defaultPath !=null)
+			return defaultPath.toOSString();
+		
+		if (machine.getOS().equals(Platform.OS_WIN32)) 
+			return "C:/Program Files/7-Zip/7z.exe";
+			
+		if (machine.getOS().equals(Platform.OS_LINUX)) {
+			return "/usr/bin/7z";
+		}
+		if (machine.getOS().equals(Platform.OS_MACOSX)) {
+			return "/usr/bin/7z";
+		}
+		return path;
+		
+	}
+}


Property changes on: branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMUncompressInfoWizardPage.java
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the Esbox-commits mailing list