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

raul at garage.maemo.org raul at garage.maemo.org
Sun Jul 19 07:16:44 EEST 2009


Author: raul
Date: 2009-07-19 07:16:42 +0300 (Sun, 19 Jul 2009)
New Revision: 1880

Added:
   branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/
   branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/
   branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/
   branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DownloadExecution.java
   branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DownloadProgressMonitor.java
   branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DownloadUtility.java
   branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/FileDownload.java
   branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInstaller.java
   branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/RandomFileOutputStream.java
   branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/ui/
Removed:
   branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/DownloadExecution.java
   branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/DownloadProgressMonitor.java
   branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/DownloadUtility.java
   branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/FileDownload.java
   branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstaller.java
   branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/RandomFileOutputStream.java
Modified:
   branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMConfigurationWizardPage.java
   branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallData.java
   branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMSelectionWizardPage.java
   branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoVMInstallerContentLabelProvider.java
   branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/NewMaemoSDKVMWizard.java
Log:
Refactoring download manager for images. Threads are used from flasher download.

Copied: branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DownloadExecution.java (from rev 1877, branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/DownloadExecution.java)
===================================================================
--- branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DownloadExecution.java	                        (rev 0)
+++ branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DownloadExecution.java	2009-07-19 04:16:42 UTC (rev 1880)
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * 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 org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.maemo.esbox.internal.api.vm.vmware.FileDownload.Status;
+import org.maemo.esbox.internal.vm.vmware.Activator;
+import org.maemo.mica.common.core.MicaException;
+
+/**
+ * This class wraps that download process of any Maemo SDK virtual image. If the
+ * file has more than 1 part, it will properly downloaded by this executor.
+ * 
+ * @author raulherbster
+ * 
+ */
+public class DownloadExecution implements IRunnableWithProgress {
+
+	// File to download
+	private FileDownload downloadFile;
+
+	// progress monitor to download process
+	private IProgressMonitor progressMonitor;
+
+	private static final int DOWNLOAD_TRIES = 3;
+	private static final int DOWNLOAD_WAIT = 3000; // 3 sec
+	
+	/**
+	 * Construtor.
+	 * 
+	 * @param downloadFile
+	 *            the file to download
+	 */
+	public DownloadExecution(FileDownload downloadFile) {
+		this.downloadFile = downloadFile;
+	}
+
+	/**
+	 * Resume the download process. If the download process was previously
+	 * paused, it will be restart from the point it has stopped.
+	 */
+	public void resumeDownload() {
+		synchronized (this) {
+			this.notify();
+		}
+		downloadFile.resume();
+	}
+
+	/**
+	 * Pause download process.
+	 */
+	public void pauseDonwload() {
+		downloadFile.pause();
+	}
+
+	/**
+	 * Cancel download process.
+	 */
+	public void cancelDonwload() {
+		synchronized (this) {
+			if (downloadFile.getStatus() == Status.PAUSED)
+				this.notify();
+		}
+		downloadFile.cancel();
+	}
+	
+	/**
+	 * Download the file. The process to download the file is implemented by
+	 * this method. Basically, it gets the links from download webpage. Once the
+	 * links are properly saved, the download process started. If the download
+	 * has begun, it continous from the previous state.
+	 * @throws MicaException 
+	 */
+	public void downloadFile() throws MicaException {
+		
+		MicaException error = null;
+		for (int i = 1; i <= DOWNLOAD_TRIES; i++) {
+			try {
+				Thread.sleep(i * DOWNLOAD_WAIT);
+			} catch (InterruptedException e) {
+
+			}
+			
+			IStatus status = null;
+			try {
+				status = DownloadUtility.downloadMaemoSDKImageTool(downloadFile, progressMonitor);
+			} catch (MicaException e) {
+				error = e;
+			}
+			
+			// If user cancels donwload, it does not tries anymore.
+			if ((status != null && status.matches(IStatus.CANCEL)) ||
+					downloadFile.getStatus() == Status.CANCELLED || downloadFile.getStatus() == Status.ERROR)
+				break;
+		}
+		
+		if (error != null) {
+			throw error;
+		} else {
+			// Should not come here.
+			throw new MicaException("Download of Maemo SDK virtual image was cancelled.");
+		}
+	}
+
+	/**
+	 * Run download process. The process continuous until the download file has
+	 * its state changed to Status.CANCELLED, Status.ERROR or STATUS.COMPLETE
+	 */
+	public void run(IProgressMonitor monitor) {
+		progressMonitor = monitor;
+
+		try {
+			downloadFile();
+		} catch (MicaException exception) {
+			Activator.getErrorLogger().logAndShowError("Cannot download Maemo SDK virtual image", exception);
+		}
+			
+	}
+
+}

Copied: branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DownloadProgressMonitor.java (from rev 1877, branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/DownloadProgressMonitor.java)
===================================================================
--- branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DownloadProgressMonitor.java	                        (rev 0)
+++ branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DownloadProgressMonitor.java	2009-07-19 04:16:42 UTC (rev 1880)
@@ -0,0 +1,123 @@
+/*******************************************************************************
+ * 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 org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * 
+ * Progress monitor to download the file.
+ * 
+ * @author raulherbster
+ * 
+ */
+public class DownloadProgressMonitor extends ProgressMonitorDialog {
+
+	private Button pauseButton;
+	private Button resumeButton;
+
+	private DownloadExecution downloadWrapper;
+
+	public static final int PAUSE_ID = 22;
+	public static final int RESUME_ID = 23;
+
+	public static final String PAUSE_LABEL = "Pause";
+	public static final String RESUME_LABEL = "Resume";
+
+	/**
+	 * Constructor
+	 * 
+	 * @param parent
+	 *            parent shell
+	 */
+	public DownloadProgressMonitor(Shell parent,
+			DownloadExecution downloadWrapper) {
+		super(parent);
+		this.downloadWrapper = downloadWrapper;
+
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.eclipse.jface.dialogs.ProgressMonitorDialog#createButtonsForButtonBar
+	 * (org.eclipse.swt.widgets.Composite)
+	 */
+	@Override
+	protected void createButtonsForButtonBar(Composite parent) {
+		pauseButton = createButton(parent, PAUSE_ID, PAUSE_LABEL, true);
+		pauseButton.setEnabled(true);
+		pauseButton.addSelectionListener(new SelectionListener() {
+			public void widgetDefaultSelected(SelectionEvent arg0) {
+				// do nothing
+			}
+
+			public void widgetSelected(SelectionEvent arg0) {
+				resumeButton.setEnabled(true);
+				pauseButton.setEnabled(false);
+				pauseDownload();
+			}
+		});
+
+		resumeButton = createButton(parent, RESUME_ID, RESUME_LABEL, true);
+		resumeButton.setEnabled(false);
+		resumeButton.addSelectionListener(new SelectionListener() {
+			public void widgetDefaultSelected(SelectionEvent arg0) {
+				// do nothing
+			}
+
+			public void widgetSelected(SelectionEvent arg0) {
+				pauseButton.setEnabled(true);
+				resumeButton.setEnabled(false);
+				resumeDownload();
+			}
+		});
+
+		super.createButtonsForButtonBar(parent);
+		setOperationCancelButtonEnabled(true);
+	}
+
+	/**
+	 * Cancel download.
+	 */
+	protected void cancelPressed() {
+		super.cancelPressed();
+		cancelDownload();
+	}
+
+	/**
+	 * Resume download.
+	 */
+	protected void resumeDownload() {
+		downloadWrapper.resumeDownload();
+	}
+
+	/**
+	 * Pause download.
+	 */
+	protected void pauseDownload() {
+		downloadWrapper.pauseDonwload();
+	}
+
+	/**
+	 * Cancel download.
+	 */
+	protected void cancelDownload() {
+		downloadWrapper.cancelDonwload();
+	}
+
+}

Copied: branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DownloadUtility.java (from rev 1877, branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/DownloadUtility.java)
===================================================================
--- branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DownloadUtility.java	                        (rev 0)
+++ branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DownloadUtility.java	2009-07-19 04:16:42 UTC (rev 1880)
@@ -0,0 +1,359 @@
+/*******************************************************************************
+ * 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.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.net.CookieHandler;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+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.maemo.esbox.internal.vm.vmware.Activator;
+import org.maemo.mica.common.core.MicaException;
+import org.maemo.mica.common.core.Policy;
+import org.maemo.mica.common.ui.dialogs.DialogUtils;
+import org.maemo.mica.internal.api.common.core.filesystem.FilesystemUtils;
+import org.maemo.mica.internal.maemosdk.flasher.httpconnection.CopyProgressMonitor;
+import org.maemo.mica.internal.maemosdk.flasher.httpconnection.DownloadingThread;
+import org.maemo.mica.internal.maemosdk.flasher.httpconnection.SessionHandler;
+
+/**
+ * @author raulherbster
+ *
+ */
+public class DownloadUtility {
+
+	private static URL getRemoteFileURL(FileDownload downloadFile, IProgressMonitor progressMonitor) throws MicaException {
+		URL connectionURL = null;
+		try {
+			connectionURL = new URL(FileDownload.DOWNLOAD_PAGE);
+		} catch (MalformedURLException e1) {
+			throw new MicaException("Cannot define URL for Maemo SDK virtual image");
+		}
+		
+		progressMonitor.subTask("Retrieving  information from " + connectionURL.getHost());
+		
+		// Get the download page so links can be properly obtained
+		String downloadPage = openDownloadPage();
+		URL remoteURL;
+		try {
+			remoteURL = getLinkFor(downloadPage, downloadFile.getDescription());
+		} catch (MalformedURLException e) {
+			Activator.getErrorLogger().logAndShowError("Invalid file URL", e);
+			return null;
+		}
+				
+		return remoteURL;
+	}
+	
+	/**
+	 * Return the download page.
+	 * 
+	 * @return the download page.
+	 */
+	private static String openDownloadPage() {
+		String responsePage = null;
+		HttpURLConnection connection = null;
+				
+		try {
+			connection = connectWithPostMethod(new URL(
+					FileDownload.DOWNLOAD_PAGE));
+			responsePage = getResponse(connection);
+			if (responsePage == null) {
+				throw new MicaException("Response page is empty"); //$NON-NLS-1$
+			}
+		} catch (Exception e) {
+			Activator.getErrorLogger().logAndShowError(
+					"Cannot connect with " + FileDownload.DOWNLOAD_PAGE, e);
+			return null;
+		} finally {
+
+			if (connection != null)
+				connection.disconnect();
+
+		}
+		return responsePage;
+	}
+	
+	/**
+	 * Connect with post method on download page.
+	 * 
+	 * @param connectionUrl
+	 * @return
+	 * @throws MicaException
+	 */
+	private static HttpURLConnection connectWithPostMethod(URL connectionUrl) throws MicaException {
+		// TODO refactor flasher on Mica so methods can be reused here.
+		OutputStreamWriter out = null;
+		HttpURLConnection conn = null;
+		try {
+			conn = (HttpURLConnection) connectionUrl.openConnection();
+			conn.setRequestMethod("POST"); //$NON-NLS-1$
+			conn.setDoOutput(true);
+			conn.setDoInput(true);
+			conn.setRequestProperty("Content-Type",
+			"application/x-www-form-urlencoded");
+			out = new OutputStreamWriter(conn.getOutputStream());
+			out.write("agree=I accept");
+			out.flush();
+			return conn;
+		} catch (MalformedURLException e) {
+			throw new MicaException("Malformed URL", e); //$NON-NLS-1$
+		} catch (IOException e) {
+			throw new MicaException("Cannot connect to " + connectionUrl, e);
+		} finally {
+			Policy.close(out);
+		}
+	}
+	
+	private static String getResponse(HttpURLConnection conn) throws MicaException {
+		// TODO refactor flasher on Mica so methods can be reused here.
+		if (conn == null) {
+			throw new MicaException(new IllegalArgumentException(
+			"Connection cannot be null"));
+		}
+		BufferedReader bufReader = null;
+		try {
+			bufReader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
+		} catch (Exception e) {
+			throw new MicaException("Cannot get input from server", e);
+		}
+		StringBuffer buffer = new StringBuffer();
+		if (bufReader != null) {
+			String inputLine;
+			try {
+				while ((inputLine = bufReader.readLine()) != null) {
+					buffer.append(inputLine);
+					buffer.append("\n"); //$NON-NLS-1$
+				}
+			} catch (IOException e) {
+				throw new MicaException("Cannot read data from server", e);
+			}
+		}
+		if (buffer.length() > 0) {
+			return buffer.toString();
+		} else {
+			return null;
+		}
+	}
+
+	
+	
+	/**
+	 * Get the links for a certain download file. It the file consists of more
+	 * than 1 file, its parts will be properly obtained.
+	 * 
+	 * @param htmlPage
+	 * @param downloadFileDescription
+	 * @return
+	 * @throws MalformedURLException
+	 */
+	private static URL getLinkFor(String htmlPage, String downloadFileDescription) throws MalformedURLException {
+		final String DOWNLOAD_FILE_PATTERN = "<tr>\\s*<td class=\"filename\">(.*?)</td>\\s*</tr>";
+		final String LINK_PATTERN = "<a href=\"(.*?)\">";
+		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 hrefPattern = Pattern.compile(LINK_PATTERN,
+						Pattern.DOTALL | Pattern.UNIX_LINES);
+				Matcher matcherLink = hrefPattern.matcher(fileInfo);
+				if (matcherLink.find()) {
+					String link = matcherLink.group(1);
+					return (new URL(FileDownload.DOWNLOAD_PAGE
+							+ link.substring(link.indexOf("?"))));
+				}
+			}
+
+		}
+		return null;
+	}
+	
+	/**
+	 * Get file name of download file to be saved locally
+	 * 
+	 * @param remoteURL
+	 * @param localPath
+	 * @return the name of file to be saved locally
+	 */
+	private static String getFileName(URL remoteURL, URL localPath) {
+		String fileName = (new Path(remoteURL.getFile())).lastSegment();
+		fileName = fileName.substring(fileName.lastIndexOf("=") + 1);
+		return (new Path(localPath.getFile())).append(fileName).toOSString();
+	}
+	
+	private static long getPreviousDownloadSize(String localFileName) {
+		File previousFile = new File(localFileName);
+		if (previousFile.exists()) {
+			boolean canResumeDownload = DialogUtils.showQuestionDialog(DialogUtils.getShell(), 
+					"Previous download file founded", "The file " + localFileName + " already exists. Would you like to resume download?");
+			if (canResumeDownload) {
+				return previousFile.length();
+			} else {
+				previousFile.delete();
+				return 0L;
+			}			
+		}
+		return 0L;
+	}
+	
+	private static IStatus fileDownloader(FileDownload downloadFile, URL remoteURL, IProgressMonitor monitor) throws IOException, MicaException {
+		// Check if file was downloaded before
+		monitor.subTask("Checking information about file to be downloaded ...");
+		String fileName = getFileName(remoteURL, downloadFile.getLocalURL());
+		
+		downloadFile.setDownloadedSize(getPreviousDownloadSize(fileName));			
+		
+		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 (!checkAvailableFreeSpace(contentLength,downloadFile.getLocalURL())) {
+				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",contentLength, monitor);
+			progressMonitor.addProgress(downloadFile.getDownloadedSize());
+			progressMonitor.start();
+	
+			out = new RandomFileOutputStream(fileName,true);
+			out.setFilePointer(downloadFile.getDownloadedSize());	
+			in = connection.getInputStream();
+			
+			// create and start to download
+			monitor.beginTask(remoteURL.getFile(), contentLength != 1 ? contentLength : IProgressMonitor.UNKNOWN);
+			DownloadingThread thread = new DownloadingThread(in, out, progressMonitor, monitor);
+			thread.start();
+	
+			while (!thread.isInterrupted()) {
+				try {
+					Thread.sleep(1000);
+				} catch (InterruptedException e) {
+					continue;
+				}
+				if (monitor.isCanceled()) {
+					thread.stopDownloading();
+					downloadFile.cancel();
+					throw new MicaException("Maemo SDK virtual image download was cancelled by user.");
+				}
+				if (!thread.isAlive()) {
+					// Downloading is done
+					downloadFile.complete();
+					break;
+				}
+			}
+			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;
+	}
+	
+	private static IStatus errorStatus(String message) {
+		return Activator.createStatus(IStatus.ERROR, message);
+	}
+	
+	private static void cancelDownload(FileDownload fileDownload, IProgressMonitor monitor) {
+		fileDownload.error();
+		monitor.setCanceled(true);
+		monitor.done();
+	}
+	
+	private static boolean checkAvailableFreeSpace(int fileSize, URL localURL) throws IOException {
+		long freeSpace = FilesystemUtils.freeSpaceOS(new Path(localURL.getPath()),false);
+		return freeSpace <= fileSize;
+	}
+	
+	private static IStatus validateConnection(HttpURLConnection connection) throws IOException {
+		// Make sure response code is in the 200 range
+		if (connection.getResponseCode() / 100 != 2) {
+			return errorStatus("Invalid response from connection.");			
+		}
+
+		// Check for valid content length
+		if (connection.getContentLength() < 1) {
+			return errorStatus("Invalid content length.");
+		}
+
+		return Status.OK_STATUS;
+	}
+	
+	public static IStatus downloadMaemoSDKImageTool(FileDownload downloadFile, IProgressMonitor progressMonitor) throws MicaException {
+		try {
+			CookieHandler.setDefault(new SessionHandler());
+			
+			// Get link of remote file
+			URL remoteFileURL = getRemoteFileURL(downloadFile, progressMonitor);
+
+			try {
+				return fileDownloader(downloadFile,remoteFileURL,progressMonitor);
+			} catch (IOException e) {
+				throw new MicaException("Cannot download Maemo SDK virtual image", e);
+			}
+			
+	    } finally {
+			CookieHandler.setDefault(null);
+		}
+		
+	}
+
+}

Copied: branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/FileDownload.java (from rev 1877, branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/FileDownload.java)
===================================================================
--- branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/FileDownload.java	                        (rev 0)
+++ branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/FileDownload.java	2009-07-19 04:16:42 UTC (rev 1880)
@@ -0,0 +1,229 @@
+/*******************************************************************************
+ * 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 FileDownload {
+
+	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 String description;
+	private long size;
+	private long downloaded;
+	private Status status;
+
+	// urls for download and storage
+	private URL localPathURL;
+
+	private boolean hasMoreParts;
+
+	/**
+	 * Constructor.
+	 */
+	public FileDownload() {
+		this(null);
+	}
+
+	/**
+	 * Constructor.
+	 * 
+	 * @param url
+	 */
+	public FileDownload(URL localURL) {
+		this.localPathURL = localURL;
+		size = -1;
+		downloaded = 0;
+		description = "";
+		status = Status.DOWNLOADING;
+	}
+
+	/**
+	 * Get the description of this file.
+	 * 
+	 * @return the description of this file.
+	 */
+	public String getDescription() {
+		return description;
+	}
+
+	/**
+	 * Set the description of this file.
+	 * 
+	 * @param description
+	 *            the new description.
+	 */
+	public void setDescription(String description) {
+		this.description = description;
+	}
+
+	/**
+	 * 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;
+		FileDownload downloadFile = (FileDownload) obj;
+		return description.equals(downloadFile.getDescription());
+
+	}
+
+	/**
+	 * 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);
+	}
+}

Copied: branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInstaller.java (from rev 1877, branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstaller.java)
===================================================================
--- branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInstaller.java	                        (rev 0)
+++ branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInstaller.java	2009-07-19 04:16:42 UTC (rev 1880)
@@ -0,0 +1,420 @@
+/*******************************************************************************
+ * 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.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+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.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Shell;
+import org.maemo.esbox.internal.api.vm.vmware.FileDownload.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.ui.SelectVirtualMachineDialog;
+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.ui.IProgressReporter;
+
+import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils;
+
+/**
+ * This class wraps the main methods used during installation of Maemo SDK
+ * virtual image.
+ * 
+ * @author raulherbster
+ * 
+ */
+public class MaemoSDKVMInstaller {
+
+	private MaemoSDKVMInstallData installData;
+	private IProgressReporter reporter;
+
+	/**
+	 * Constructor.
+	 * 
+	 * @param installData
+	 *            the installation data
+	 * @param reporter
+	 *            the progress reporter
+	 */
+	public MaemoSDKVMInstaller(MaemoSDKVMInstallData installData,
+			IProgressReporter reporter) {
+		this.installData = installData;
+		this.reporter = reporter;
+	}
+	
+	/**
+	 * Install component into virtual image based on installer data information
+	 * @param timeout
+	 * @param shell
+	 * @param monitor
+	 * @return
+	 */
+	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);
+		}
+		
+		status = this.uncompressVM(shell, monitor);
+		
+		if (canProceed(status) && installData.canInstallSbox()) {
+			promptPreferencesDialog(shell);
+			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(timeout, shell, monitor);
+		}
+		
+		return status;
+	}
+
+	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.logInfo("Downloading Maemo SDK virtual image...");
+		
+		shell.getDisplay().syncExec(new Runnable() {
+
+			public void run() {
+				FileDownload fileDownload = installData.getFileToDownload();
+				DownloadExecution downloadWrapper = (DownloadExecution) fileDownload.downloadFile();
+				try {
+					DownloadProgressMonitor progressMonitor = new DownloadProgressMonitor(shell, downloadWrapper);
+					progressMonitor.run(true, true, downloadWrapper);
+				} catch (Exception e) {
+					fileDownload.cancel();
+				}
+			}
+
+		});
+		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.logInfo("Uncompressing Maemo SDK virtual image...");
+		
+		final String fileName = installData.getPathOfExistentVM();
+		final String destinationPath = installData.getInstallationPath();
+		
+		final IStatus[] statuses = { Activator.createStatus(IStatus.OK, "File " + fileName
+				+ " was properly uncompressed into " + destinationPath) } ;
+		
+		shell.getDisplay().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);
+										}
+										monitor.subTask("Uncompressing " + zipEntry
+												+ "\t\t"
+												+ String.format(Locale.US, "%.2f", getProgress(lenght,totalRead)) + "%");
+									}
+									fileOutputStream.close();
+									zipInputStream.closeEntry();
+									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];
+	}
+	
+	private IStatus installScratchbox(final Shell shell, IProgressMonitor monitor) {
+		monitor.subTask("Installing Scratchbox 1...");
+		reporter.logInfo("Installing Scratchbox 1 on Maemo SDK virtual image. This operation may take several minutes.");
+		
+		final IStatus[] statuses = { Activator.createStatus(IStatus.OK, "Scratchbox was properly installed on Maemo SDK virtual image.") } ;
+		
+		shell.getDisplay().syncExec(new Runnable() {
+			
+			public void run() {
+				statuses[0] = NewScratchbox1SDKWizard.startWizard();					
+			}
+			
+		});	
+		
+		return statuses[0];
+	}
+	
+	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 may take several minutes.");
+		
+		final IStatus[] statuses = { Activator.createStatus(IStatus.OK, "Scratchbox targets was properly installed on Maemo SDK virtual image.") } ;
+		
+		shell.getDisplay().syncExec(new Runnable() {
+			
+			public void run() {
+				statuses[0] = NewScratchbox1TargetWizard.startWizard();					
+			}
+			
+		});	
+		
+		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) {
+		configureInitialVMSettings();
+		
+		final IStatus statuses[] = new IStatus[] {Policy.getCancelStatus(Activator.getDefault())};
+		
+		shell.getDisplay().syncExec(new Runnable() {
+
+			public void run() {
+				SelectVirtualMachineDialog dialog = new SelectVirtualMachineDialog(
+						WorkbenchUtils.getActiveShell());
+				int result = dialog.open();
+				if (result != Window.OK)
+					statuses[0] = Activator.createErrorStatus("Virtual image was not properly configured.", null);
+				else
+					statuses[0] = Activator.createStatus(IStatus.OK, "Virtual image configured.");
+			}			
+			
+		});
+		
+		return statuses[0];
+	}
+	
+	/**
+	 * Configure initial VM settings, such as vmx file path.
+	 */
+	public void configureInitialVMSettings() {
+		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;
+			}
+		}
+				
+		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);
+	}
+	
+	/**
+	 * 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++)
+	 * @param timeout
+	 * @param shell
+	 * @param monitor
+	 * @return
+	 */
+	private IStatus installPackages(int timeout, 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());
+		
+		Set<String> packagesToInstall = new HashSet<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");
+			else
+				packagesToInstall.add("maemo-python-env");
+		}	
+		
+		return status;
+	}
+	
+	/**
+	 * Get current build machine.
+	 * @return
+	 */
+	private IMachine getBuildMachine() {
+		IBuildMachine buildMachines[] =
+			MachineRegistry.getInstance().getBuildMachines();
+		IBuildMachine machine = null;
+		for (IBuildMachine buildMachine : buildMachines) {
+			if (buildMachine.isAlive()) {
+				machine = buildMachine;
+				break;
+			}
+		}		
+		return machine;
+	}
+	
+}

Copied: branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/RandomFileOutputStream.java (from rev 1877, branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/RandomFileOutputStream.java)
===================================================================
--- branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/RandomFileOutputStream.java	                        (rev 0)
+++ branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/RandomFileOutputStream.java	2009-07-19 04:16:42 UTC (rev 1880)
@@ -0,0 +1,102 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * @author raulherbster
+ *
+ */
+import java.io.*;
+
+public class RandomFileOutputStream extends OutputStream {
+
+	protected RandomAccessFile randomFile; 
+	protected boolean sync;
+
+	public RandomFileOutputStream(String fnm) throws IOException {
+		this(fnm, false);
+	}
+
+	public RandomFileOutputStream(String fnm, boolean syn) throws IOException {
+		this(new File(fnm), syn);
+	}
+
+	public RandomFileOutputStream(File fil) throws IOException {
+		this(fil, false);
+	}
+
+	public RandomFileOutputStream(File fil, boolean syn) throws IOException {
+		super();
+
+		fil = fil.getAbsoluteFile();
+		
+		File par; // parent file
+		
+		if ((par = fil.getParentFile()) != null) {
+			par.mkdir();
+		}
+		
+		randomFile = new RandomAccessFile(fil, "rw");
+		sync = syn;
+	}
+
+	public void write(int val) throws IOException {
+		randomFile.write(val);
+		if (sync) {
+			randomFile.getFD().sync();
+		}
+	}
+
+	public void write(byte[] val) throws IOException {
+		randomFile.write(val);
+		if (sync) {
+			randomFile.getFD().sync();
+		}
+	}
+
+	public void write(byte[] val, int off, int len) throws IOException {
+		randomFile.write(val, off, len);
+		if (sync) {
+			randomFile.getFD().sync();
+		}
+	}
+
+	public void flush() throws IOException {
+		if (sync) {
+			randomFile.getFD().sync();
+		}
+	}
+
+	public void close() throws IOException {
+		randomFile.close();
+	}
+
+	public long getFilePointer() throws IOException {
+		return randomFile.getFilePointer();
+	}
+
+	public void setFilePointer(long pos) throws IOException {
+		randomFile.seek(pos);
+	}
+
+	public long getFileSize() throws IOException {
+		return randomFile.length();
+	}
+
+	public void setFileSize(long len) throws IOException {
+		randomFile.setLength(len);
+	}
+
+	public FileDescriptor getFD() throws IOException {
+		return randomFile.getFD();
+	}
+
+} // END PUBLIC CLASS
\ No newline at end of file

Deleted: branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/DownloadExecution.java
===================================================================
--- branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/DownloadExecution.java	2009-07-17 19:10:18 UTC (rev 1879)
+++ branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/DownloadExecution.java	2009-07-19 04:16:42 UTC (rev 1880)
@@ -1,465 +0,0 @@
-/*******************************************************************************
- * 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.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.maemo.esbox.internal.vm.vmware.Activator;
-import org.maemo.esbox.internal.vm.vmware.ui.wizards.FileDownload.Status;
-import org.maemo.mica.common.core.MicaException;
-import org.maemo.mica.common.core.Policy;
-
-/**
- * This class wraps that download process of any Maemo SDK virtual image. If the
- * file has more than 1 part, it will properly downloaded by this executor.
- * 
- * @author raulherbster
- * 
- */
-public class DownloadExecution implements IRunnableWithProgress {
-
-	// File to download
-	private FileDownload downloadFile;
-
-	// progress monitor to download process
-	private IProgressMonitor progressMonitor;
-
-	private static final int DOWNLOAD_TRIES = 3;
-	private static final int DOWNLOAD_WAIT = 3000; // 3 sec
-	
-	/**
-	 * Construtor.
-	 * 
-	 * @param downloadFile
-	 *            the file to download
-	 */
-	public DownloadExecution(FileDownload downloadFile) {
-		this.downloadFile = downloadFile;
-	}
-
-	/**
-	 * Resume the download process. If the download process was previously
-	 * paused, it will be restart from the point it has stopped.
-	 */
-	public void resumeDownload() {
-		synchronized (this) {
-			this.notify();
-		}
-		downloadFile.resume();
-	}
-
-	/**
-	 * Pause download process.
-	 */
-	public void pauseDonwload() {
-		downloadFile.pause();
-	}
-
-	/**
-	 * Cancel download process.
-	 */
-	public void cancelDonwload() {
-		synchronized (this) {
-			if (downloadFile.getStatus() == Status.PAUSED)
-				this.notify();
-		}
-		downloadFile.cancel();
-	}
-
-//	private URL getRemoteFileURL() {
-//		// Get the download page so links can be properly obtained
-//		String downloadPage = openDownloadPage();
-//		URL remoteURL;
-//		try {
-//			remoteURL = getLinkFor(downloadPage, downloadFile.getDescription());
-//		} catch (MalformedURLException e) {
-//			Activator.getErrorLogger().logAndShowError("Invalid file URL", e);
-//			return null;
-//		}
-//				
-//		return remoteURL;
-//	}
-//	
-
-//	
-//	private int updateDownloadProgress(int previousProgressValue) {
-//		int progressValue = ((int) downloadFile.getProgress());
-//		if (previousProgressValue < progressValue) {
-//			previousProgressValue = progressValue;
-//			progressMonitor.worked(1);
-//		}
-//		return progressValue;
-//	}
-//	
-//	private String getTimeToFinish(double connectionSpeed) {
-//		final int MINUTE = 60;
-//		final int HOUR = 3600;
-//		int timeToFinish = (int)((downloadFile.getSize() - downloadFile.getDownloadedSize()) / connectionSpeed);
-//		String result = "";
-//		if (timeToFinish >= HOUR ) {
-//			result = ((int)timeToFinish/HOUR) + " hours and " + (timeToFinish % HOUR) + " minutes to finish";
-//		} else if (timeToFinish >= MINUTE ) {
-//			result = ((int)timeToFinish/MINUTE) + " minutes to finish";
-//		} else {
-//			result = timeToFinish + " seconds to finish";
-//		}
-//		return result;
-//	}
-	
-//	private String getDownloadStatistics(String fileName, double connectionSpeed) {
-//		final int KBYTE = 1024;
-//		return "Downloading file "
-//				+ fileName
-//				+ "\n\n"
-//				+ getTimeToFinish(connectionSpeed)
-//				+ "\t"
-//				+ String.format(Locale.US, "%.2f", ((double)downloadFile.getDownloadedSize()/KBYTE))
-//				+ " KBs of " 
-//				+ String.format(Locale.US, "%.2f", ((double)downloadFile.getSize()/KBYTE)) 
-//				+ " KBs "
-//				+ String.format(Locale.US, "%.2f", connectionSpeed) + "KBs/sec"
-//				+ "\t\t"
-//				+ String.format(Locale.US, "%.2f", downloadFile.getProgress()) + "%";
-//	}
-//	
-//	private byte[] createByteBuffer() {
-//		byte[] buffer;
-//		if (downloadFile.getSize() - downloadFile.getDownloadedSize() > MAX_BUFFER_SIZE) {
-//			buffer = new byte[MAX_BUFFER_SIZE];
-//		} else {
-//			buffer = new byte[(int) (downloadFile.getSize() - downloadFile
-//					.getDownloadedSize())];
-//		}
-//		return buffer;
-//	}
-//	
-//	private double getConnectionSpeed(long time, int bytesRead) {
-//		double bytesPerMiliSeconds = (double)(bytesRead/time);
-//		return bytesPerMiliSeconds * 1000.0f;
-//	}
-	
-	/**
-	 * Download the file. The process to download the file is implemented by
-	 * this method. Basically, it gets the links from download webpage. Once the
-	 * links are properly saved, the download process started. If the download
-	 * has begun, it continous from the previous state.
-	 * @throws MicaException 
-	 */
-	public void downloadFile() throws MicaException {
-		
-		MicaException error = null;
-		for (int i = 1; i <= DOWNLOAD_TRIES; i++) {
-			try {
-				Thread.sleep(i * DOWNLOAD_WAIT);
-			} catch (InterruptedException e) {
-
-			}
-			try {
-				DownloadUtility.downloadMaemoSDKImageTool(downloadFile, progressMonitor);
-			} catch (MicaException e) {
-				error = e;
-			}
-		}
-		if (error != null) {
-			throw error;
-		} else {
-			// Should not come here.
-			throw new MicaException("Cannot download Maemo SDK virtual image."); //$NON-NLS-1$
-		}
-		
-		
-//		RandomAccessFile file = null;
-//		InputStream stream = null;
-//		HttpURLConnection connection = null;
-//
-//		try {
-//			// Start cookie section from here
-//			CookieHandler.setDefault(new SessionHandler());
-//			
-//			URL connectionURL = new URL(FileDownload.DOWNLOAD_PAGE);
-//			progressMonitor.subTask("Retrieving  information from " + connectionURL.getHost());
-//
-//			// Get link of remote file
-//			URL remoteFileURL = getRemoteFileURL();
-//
-//			// Check if file was downloaded before
-//			progressMonitor.subTask("Checking information about file to be downloaded ...");
-//			String fileName = getFileName(remoteFileURL, downloadFile.getLocalURL());
-//			checkPreviousDownload(fileName);			
-//			
-//			// Open connection to URL.
-//			progressMonitor.subTask("Establishing connection with " + remoteFileURL.getHost());
-//			connection = (HttpURLConnection) remoteFileURL.openConnection();
-//
-//			// Specify what portion of file to download
-//			connection.setRequestProperty("Range", "bytes=" + downloadFile.getDownloadedSize() + "-");
-//
-//			// Connect to server
-//			connection.connect();
-//			progressMonitor.subTask("Connected with " + remoteFileURL.getHost());
-//
-//			// Make sure response code is in the 200 range
-//			if (connection.getResponseCode() / 100 != 2) {
-//				downloadFile.error();
-//				progressMonitor.setCanceled(true);
-//				progressMonitor.done();
-//			}
-//
-//			// Check for valid content length
-//			int contentLength = connection.getContentLength();
-//			if (contentLength < 1) {
-//				downloadFile.error();
-//				progressMonitor.setCanceled(true);
-//				progressMonitor.done();
-//			}
-//
-//			progressMonitor.beginTask("File to download: "
-//					+ remoteFileURL.getFile(), 100);
-//
-//			// Set the size for this download if it hasn't been already set.
-//			if (downloadFile.getSize() == -1) {
-//				downloadFile.setSize(contentLength);
-//			}
-//
-//			// Create the local file
-//			file = new RandomAccessFile(fileName, "rw");
-//			file.seek(downloadFile.getDownloadedSize());
-//
-//			stream = connection.getInputStream();
-//
-//			int progressValue = 0;
-//			double connectionSpeed = 0;
-//			while (downloadFile.getStatus() == Status.DOWNLOADING) {
-//				// Size buffer according to how much of the file is left to download
-//				byte buffer[] = createByteBuffer();
-//
-//				long initialTime = System.currentTimeMillis();
-//				int read = stream.read(buffer);
-//				long finalTime = System.currentTimeMillis();
-//				connectionSpeed = getConnectionSpeed(finalTime - initialTime, read);
-//				if (read == -1)
-//					break;
-//				
-//				// Write buffer to file
-//				file.write(buffer, 0, read);
-//				downloadFile.setDownloadedSize(downloadFile.getDownloadedSize() + read);
-//				
-//				// Update statistics
-//				progressValue = updateDownloadProgress(progressValue);				
-//				progressMonitor.subTask(getDownloadStatistics(remoteFileURL.getFile(), connectionSpeed));
-//			}
-//
-//			// Change status to complete if this point was reached because
-//			// downloading has finished.
-//			if (downloadFile.getStatus() == Status.DOWNLOADING) {
-//				downloadFile.complete();
-//				progressMonitor.done();
-//			}
-//		} catch (Exception e) {
-//			downloadFile.error();
-//			progressMonitor.setCanceled(true);
-//			progressMonitor.done();
-//		} finally {
-//			// Close file.
-//			if (file != null) {
-//				try {
-//					file.close();
-//				} catch (Exception e) {
-//				}
-//			}
-//
-//			// Close connection to server.
-//			if (stream != null) {
-//				try {
-//					stream.close();
-//				} catch (Exception e) {
-//				}
-//			}
-//
-//			// Close cookied section
-//			CookieHandler.setDefault(null);
-//
-//			if (connection != null)
-//				connection.disconnect();
-//		}
-	}
-
-	/**
-	 * Run download process. The process continuous until the download file has
-	 * its state changed to Status.CANCELLED, Status.ERROR or STATUS.COMPLETE
-	 */
-	public void run(IProgressMonitor monitor) {
-		progressMonitor = monitor;
-		while (downloadFile.getStatus() != Status.CANCELLED
-				&& downloadFile.getStatus() != Status.ERROR
-				&& downloadFile.getStatus() != Status.COMPLETE) {
-			try {
-				downloadFile();
-			} catch (MicaException exception) {
-				Activator.getErrorLogger().logAndShowError("Cannot download Maemo SDK virtual image", exception);
-			}
-			if (downloadFile.getStatus() == Status.PAUSED) {
-				synchronized (this) {
-					try {
-						this.wait();
-					} catch (InterruptedException e) {
-						Activator.getErrorLogger().logAndShowError(
-								"Problems during file download", e);
-					}
-				}
-			}
-			// continue or stop download
-		}
-		monitor.done();
-	}
-
-
-//
-//	/**
-//	 * Return the download page.
-//	 * 
-//	 * @return the download page.
-//	 */
-//	private String openDownloadPage() {
-//		String responsePage = null;
-//		HttpURLConnection connection = null;
-//		
-//		
-//		try {
-//			connection = connectWithPostMethod(new URL(
-//					FileDownload.DOWNLOAD_PAGE));
-//			responsePage = getResponse(connection);
-//			if (responsePage == null) {
-//				throw new MicaException("Response page is empty"); //$NON-NLS-1$
-//			}
-//		} catch (Exception e) {
-//			Activator.getErrorLogger().logAndShowError(
-//					"Cannot connect with " + FileDownload.DOWNLOAD_PAGE, e);
-//			return null;
-//		} finally {
-//
-//			if (connection != null)
-//				connection.disconnect();
-//
-//		}
-//		return responsePage;
-//	}
-
-	/**
-	 * Connect with post method on download page.
-	 * 
-	 * @param connectionUrl
-	 * @return
-	 * @throws MicaException
-	 */
-	private HttpURLConnection connectWithPostMethod(URL connectionUrl)
-	throws MicaException {
-		// TODO refactor flasher on Mica so methods can be reused here.
-		OutputStreamWriter out = null;
-		HttpURLConnection conn = null;
-		try {
-			conn = (HttpURLConnection) connectionUrl.openConnection();
-			conn.setRequestMethod("POST"); //$NON-NLS-1$
-			conn.setDoOutput(true);
-			conn.setDoInput(true);
-			conn.setRequestProperty("Content-Type",
-			"application/x-www-form-urlencoded");
-			out = new OutputStreamWriter(conn.getOutputStream());
-			out.write("agree=I accept");
-			out.flush();
-			return conn;
-		} catch (MalformedURLException e) {
-			throw new MicaException("Malformed URL", e); //$NON-NLS-1$
-		} catch (IOException e) {
-			throw new MicaException("Cannot connect to " + connectionUrl, e);
-		} finally {
-			Policy.close(out);
-		}
-	}
-//
-//	private static String getResponse(HttpURLConnection conn)
-//	throws MicaException {
-//		// TODO refactor flasher on Mica so methods can be reused here.
-//		if (conn == null) {
-//			throw new MicaException(new IllegalArgumentException(
-//			"Connection cannot be null"));
-//		}
-//		BufferedReader bufReader = null;
-//		try {
-//			bufReader = new BufferedReader(new InputStreamReader(conn
-//					.getInputStream()));
-//		} catch (Exception e) {
-//			throw new MicaException("Cannot get input from server", e);
-//		}
-//		StringBuffer buffer = new StringBuffer();
-//		if (bufReader != null) {
-//			String inputLine;
-//			try {
-//				while ((inputLine = bufReader.readLine()) != null) {
-//					buffer.append(inputLine);
-//					buffer.append("\n"); //$NON-NLS-1$
-//				}
-//			} catch (IOException e) {
-//				throw new MicaException("Cannot read data from server", e);
-//			}
-//		}
-//		if (buffer.length() > 0) {
-//			return buffer.toString();
-//		} else {
-//			return null;
-//		}
-//	}
-//
-	/**
-	 * Get the links for a certain download file. It the file consists of more
-	 * than 1 file, its parts will be properly obtained.
-	 * 
-	 * @param htmlPage
-	 * @param downloadFileDescription
-	 * @return
-	 * @throws MalformedURLException
-	 */
-	private URL getLinkFor(String htmlPage, String downloadFileDescription)
-	throws MalformedURLException {
-		final String DOWNLOAD_FILE_PATTERN = "<tr>\\s*<td class=\"filename\">(.*?)</td>\\s*</tr>";
-		final String LINK_PATTERN = "<a href=\"(.*?)\">";
-		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 hrefPattern = Pattern.compile(LINK_PATTERN,
-						Pattern.DOTALL | Pattern.UNIX_LINES);
-				Matcher matcherLink = hrefPattern.matcher(fileInfo);
-				if (matcherLink.find()) {
-					String link = matcherLink.group(1);
-					return (new URL(FileDownload.DOWNLOAD_PAGE
-							+ link.substring(link.indexOf("?"))));
-				}
-			}
-
-		}
-		return null;
-	}
-
-}

Deleted: branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/DownloadProgressMonitor.java
===================================================================
--- branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/DownloadProgressMonitor.java	2009-07-17 19:10:18 UTC (rev 1879)
+++ branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/DownloadProgressMonitor.java	2009-07-19 04:16:42 UTC (rev 1880)
@@ -1,123 +0,0 @@
-/*******************************************************************************
- * 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 org.eclipse.jface.dialogs.ProgressMonitorDialog;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Shell;
-
-/**
- * 
- * Progress monitor to download the file.
- * 
- * @author raulherbster
- * 
- */
-public class DownloadProgressMonitor extends ProgressMonitorDialog {
-
-	private Button pauseButton;
-	private Button resumeButton;
-
-	private DownloadExecution downloadWrapper;
-
-	public static final int PAUSE_ID = 22;
-	public static final int RESUME_ID = 23;
-
-	public static final String PAUSE_LABEL = "Pause";
-	public static final String RESUME_LABEL = "Resume";
-
-	/**
-	 * Constructor
-	 * 
-	 * @param parent
-	 *            parent shell
-	 */
-	public DownloadProgressMonitor(Shell parent,
-			DownloadExecution downloadWrapper) {
-		super(parent);
-		this.downloadWrapper = downloadWrapper;
-
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see
-	 * org.eclipse.jface.dialogs.ProgressMonitorDialog#createButtonsForButtonBar
-	 * (org.eclipse.swt.widgets.Composite)
-	 */
-	@Override
-	protected void createButtonsForButtonBar(Composite parent) {
-		pauseButton = createButton(parent, PAUSE_ID, PAUSE_LABEL, true);
-		pauseButton.setEnabled(true);
-		pauseButton.addSelectionListener(new SelectionListener() {
-			public void widgetDefaultSelected(SelectionEvent arg0) {
-				// do nothing
-			}
-
-			public void widgetSelected(SelectionEvent arg0) {
-				resumeButton.setEnabled(true);
-				pauseButton.setEnabled(false);
-				pauseDownload();
-			}
-		});
-
-		resumeButton = createButton(parent, RESUME_ID, RESUME_LABEL, true);
-		resumeButton.setEnabled(false);
-		resumeButton.addSelectionListener(new SelectionListener() {
-			public void widgetDefaultSelected(SelectionEvent arg0) {
-				// do nothing
-			}
-
-			public void widgetSelected(SelectionEvent arg0) {
-				pauseButton.setEnabled(true);
-				resumeButton.setEnabled(false);
-				resumeDownload();
-			}
-		});
-
-		super.createButtonsForButtonBar(parent);
-		setOperationCancelButtonEnabled(true);
-	}
-
-	/**
-	 * Cancel download.
-	 */
-	protected void cancelPressed() {
-		super.cancelPressed();
-		cancelDownload();
-	}
-
-	/**
-	 * Resume download.
-	 */
-	protected void resumeDownload() {
-		downloadWrapper.resumeDownload();
-	}
-
-	/**
-	 * Pause download.
-	 */
-	protected void pauseDownload() {
-		downloadWrapper.pauseDonwload();
-	}
-
-	/**
-	 * Cancel download.
-	 */
-	protected void cancelDownload() {
-		downloadWrapper.cancelDonwload();
-	}
-
-}

Deleted: branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/DownloadUtility.java
===================================================================
--- branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/DownloadUtility.java	2009-07-17 19:10:18 UTC (rev 1879)
+++ branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/DownloadUtility.java	2009-07-19 04:16:42 UTC (rev 1880)
@@ -1,327 +0,0 @@
-/*******************************************************************************
- * 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.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.net.CookieHandler;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.URL;
-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.NullProgressMonitor;
-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.Policy;
-import org.maemo.mica.common.ui.dialogs.DialogUtils;
-import org.maemo.mica.internal.maemosdk.flasher.httpconnection.CopyProgressMonitor;
-import org.maemo.mica.internal.maemosdk.flasher.httpconnection.DownloadingThread;
-import org.maemo.mica.internal.maemosdk.flasher.httpconnection.SessionHandler;
-
-/**
- * @author raulherbster
- *
- */
-public class DownloadUtility {
-
-	private static URL getRemoteFileURL(FileDownload downloadFile, IProgressMonitor progressMonitor) throws MicaException {
-		URL connectionURL = null;
-		try {
-			connectionURL = new URL(FileDownload.DOWNLOAD_PAGE);
-		} catch (MalformedURLException e1) {
-			throw new MicaException("Cannot define URL for Maemo SDK virtual image");
-		}
-		
-		progressMonitor.subTask("Retrieving  information from " + connectionURL.getHost());
-		
-		// Get the download page so links can be properly obtained
-		String downloadPage = openDownloadPage();
-		URL remoteURL;
-		try {
-			remoteURL = getLinkFor(downloadPage, downloadFile.getDescription());
-		} catch (MalformedURLException e) {
-			Activator.getErrorLogger().logAndShowError("Invalid file URL", e);
-			return null;
-		}
-				
-		return remoteURL;
-	}
-	
-	/**
-	 * Return the download page.
-	 * 
-	 * @return the download page.
-	 */
-	private static String openDownloadPage() {
-		String responsePage = null;
-		HttpURLConnection connection = null;
-				
-		try {
-			connection = connectWithPostMethod(new URL(
-					FileDownload.DOWNLOAD_PAGE));
-			responsePage = getResponse(connection);
-			if (responsePage == null) {
-				throw new MicaException("Response page is empty"); //$NON-NLS-1$
-			}
-		} catch (Exception e) {
-			Activator.getErrorLogger().logAndShowError(
-					"Cannot connect with " + FileDownload.DOWNLOAD_PAGE, e);
-			return null;
-		} finally {
-
-			if (connection != null)
-				connection.disconnect();
-
-		}
-		return responsePage;
-	}
-	
-	/**
-	 * Connect with post method on download page.
-	 * 
-	 * @param connectionUrl
-	 * @return
-	 * @throws MicaException
-	 */
-	private static HttpURLConnection connectWithPostMethod(URL connectionUrl) throws MicaException {
-		// TODO refactor flasher on Mica so methods can be reused here.
-		OutputStreamWriter out = null;
-		HttpURLConnection conn = null;
-		try {
-			conn = (HttpURLConnection) connectionUrl.openConnection();
-			conn.setRequestMethod("POST"); //$NON-NLS-1$
-			conn.setDoOutput(true);
-			conn.setDoInput(true);
-			conn.setRequestProperty("Content-Type",
-			"application/x-www-form-urlencoded");
-			out = new OutputStreamWriter(conn.getOutputStream());
-			out.write("agree=I accept");
-			out.flush();
-			return conn;
-		} catch (MalformedURLException e) {
-			throw new MicaException("Malformed URL", e); //$NON-NLS-1$
-		} catch (IOException e) {
-			throw new MicaException("Cannot connect to " + connectionUrl, e);
-		} finally {
-			Policy.close(out);
-		}
-	}
-	
-	private static String getResponse(HttpURLConnection conn) throws MicaException {
-		// TODO refactor flasher on Mica so methods can be reused here.
-		if (conn == null) {
-			throw new MicaException(new IllegalArgumentException(
-			"Connection cannot be null"));
-		}
-		BufferedReader bufReader = null;
-		try {
-			bufReader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
-		} catch (Exception e) {
-			throw new MicaException("Cannot get input from server", e);
-		}
-		StringBuffer buffer = new StringBuffer();
-		if (bufReader != null) {
-			String inputLine;
-			try {
-				while ((inputLine = bufReader.readLine()) != null) {
-					buffer.append(inputLine);
-					buffer.append("\n"); //$NON-NLS-1$
-				}
-			} catch (IOException e) {
-				throw new MicaException("Cannot read data from server", e);
-			}
-		}
-		if (buffer.length() > 0) {
-			return buffer.toString();
-		} else {
-			return null;
-		}
-	}
-
-	
-	
-	/**
-	 * Get the links for a certain download file. It the file consists of more
-	 * than 1 file, its parts will be properly obtained.
-	 * 
-	 * @param htmlPage
-	 * @param downloadFileDescription
-	 * @return
-	 * @throws MalformedURLException
-	 */
-	private static URL getLinkFor(String htmlPage, String downloadFileDescription) throws MalformedURLException {
-		final String DOWNLOAD_FILE_PATTERN = "<tr>\\s*<td class=\"filename\">(.*?)</td>\\s*</tr>";
-		final String LINK_PATTERN = "<a href=\"(.*?)\">";
-		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 hrefPattern = Pattern.compile(LINK_PATTERN,
-						Pattern.DOTALL | Pattern.UNIX_LINES);
-				Matcher matcherLink = hrefPattern.matcher(fileInfo);
-				if (matcherLink.find()) {
-					String link = matcherLink.group(1);
-					return (new URL(FileDownload.DOWNLOAD_PAGE
-							+ link.substring(link.indexOf("?"))));
-				}
-			}
-
-		}
-		return null;
-	}
-	
-	/**
-	 * Get file name of download file to be saved locally
-	 * 
-	 * @param remoteURL
-	 * @param localPath
-	 * @return the name of file to be saved locally
-	 */
-	private static String getFileName(URL remoteURL, URL localPath) {
-		String fileName = (new Path(remoteURL.getFile())).lastSegment();
-		fileName = fileName.substring(fileName.lastIndexOf("=") + 1);
-		return (new Path(localPath.getFile())).append(fileName).toOSString();
-	}
-	
-	/**
-	 * Get path for the image file saved locally.
-	 * @param downloadFile
-	 * @return The path for the image file saved locally.
-	 * @throws MicaException 
-	 */
-	public static IPath getFilePath(FileDownload downloadFile) throws MicaException {
-		CookieHandler.setDefault(new SessionHandler());
-		URL remoteURL = getRemoteFileURL(downloadFile, new NullProgressMonitor());
-		URL localURL = downloadFile.getLocalURL();
-		if (remoteURL == null || localURL == null)
-			throw new MicaException("Cannot recover file path.");
-		
-		return new Path(getFileName(remoteURL, localURL));
-	}
-	
-	private static long getPreviousDownload(String localFileName) {
-		File previousFile = new File(localFileName);
-		if (previousFile.exists()) {
-			boolean canResumeDownload = DialogUtils.showQuestionDialog(DialogUtils.getShell(), 
-					"Previous download file founded", "The file " + localFileName + " already exists. Would you like to resume download?");
-			if (canResumeDownload) {
-				return previousFile.length();
-			} else {
-				previousFile.delete();
-				return 0L;
-			}			
-		}
-		return 0L;
-	}
-	
-	private static void fileDownloader(FileDownload downloadFile, URL remoteURL, IProgressMonitor monitor) throws IOException, MicaException {
-		// Check if file was downloaded before
-		monitor.subTask("Checking information about file to be downloaded ...");
-		String fileName = getFileName(remoteURL, downloadFile.getLocalURL());
-		
-		downloadFile.setDownloadedSize(getPreviousDownload(fileName));			
-		
-		// Open connection to URL.
-		monitor.subTask("Establishing connection with " + remoteURL.getHost());
-		HttpURLConnection 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());
-
-		// Make sure response code is in the 200 range
-		if (connection.getResponseCode() / 100 != 2) {
-			downloadFile.error();
-			monitor.setCanceled(true);
-			monitor.done();
-		}
-
-		// Check for valid content length
-		int contentLength = connection.getContentLength();
-		if (contentLength < 1) {
-			downloadFile.error();
-			monitor.setCanceled(true);
-			monitor.done();
-		}
-
-		monitor.beginTask("File to download: " + remoteURL.getFile(), 100);
-
-		// 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",contentLength, monitor);
-		progressMonitor.start();
-
-		RandomFileOutputStream bos = new RandomFileOutputStream(fileName,true);
-		bos.setFilePointer(downloadFile.getDownloadedSize());
-
-		InputStream in = connection.getInputStream();
-		
-		// create and start to download
-		DownloadingThread thread = new DownloadingThread(in, bos, progressMonitor, monitor);
-		thread.start();
-
-		while (!thread.isInterrupted()) {
-			try {
-				Thread.sleep(1000);
-			} catch (InterruptedException e) {
-				continue;
-			}
-			if (monitor.isCanceled()) {
-				thread.stopDownloading();
-				throw new MicaException("Cannot continue"); //$NON-NLS-1$
-			}
-			if (!thread.isAlive()) {
-				// Downloading is done
-				break;
-			}
-		}
-		if (thread.getErrorMessage() != null) {
-			throw new IOException(thread.getErrorMessage());
-		}
-	}
-	
-	public static void downloadMaemoSDKImageTool(FileDownload downloadFile, IProgressMonitor progressMonitor) throws MicaException {
-		try {
-			CookieHandler.setDefault(new SessionHandler());
-			
-			// Get link of remote file
-			URL remoteFileURL = getRemoteFileURL(downloadFile, progressMonitor);
-
-			try {
-				fileDownloader(downloadFile,remoteFileURL,progressMonitor);
-			} catch (IOException e) {
-				throw new MicaException("Cannot dowload Maemo SDK virtual image", e);
-			}
-			
-	    } finally {
-			CookieHandler.setDefault(null);
-		}
-		
-	}
-
-}

Deleted: branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/FileDownload.java
===================================================================
--- branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/FileDownload.java	2009-07-17 19:10:18 UTC (rev 1879)
+++ branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/FileDownload.java	2009-07-19 04:16:42 UTC (rev 1880)
@@ -1,229 +0,0 @@
-/*******************************************************************************
- * 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.URL;
-
-import org.eclipse.jface.operation.IRunnableWithProgress;
-
-/**
- * 
- * @author raulherbster
- * 
- */
-public class FileDownload {
-
-	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 String description;
-	private long size;
-	private long downloaded;
-	private Status status;
-
-	// urls for download and storage
-	private URL localPathURL;
-
-	private boolean hasMoreParts;
-
-	/**
-	 * Constructor.
-	 */
-	public FileDownload() {
-		this(null);
-	}
-
-	/**
-	 * Constructor.
-	 * 
-	 * @param url
-	 */
-	public FileDownload(URL localURL) {
-		this.localPathURL = localURL;
-		size = -1;
-		downloaded = 0;
-		description = "";
-		status = Status.DOWNLOADING;
-	}
-
-	/**
-	 * Get the description of this file.
-	 * 
-	 * @return the description of this file.
-	 */
-	public String getDescription() {
-		return description;
-	}
-
-	/**
-	 * Set the description of this file.
-	 * 
-	 * @param description
-	 *            the new description.
-	 */
-	public void setDescription(String description) {
-		this.description = description;
-	}
-
-	/**
-	 * 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;
-		FileDownload downloadFile = (FileDownload) obj;
-		return description.equals(downloadFile.getDescription());
-
-	}
-
-	/**
-	 * 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);
-	}
-}

Modified: branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMConfigurationWizardPage.java
===================================================================
--- branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMConfigurationWizardPage.java	2009-07-17 19:10:18 UTC (rev 1879)
+++ branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMConfigurationWizardPage.java	2009-07-19 04:16:42 UTC (rev 1880)
@@ -185,7 +185,8 @@
 
 			@Override
 			public void widgetSelected(SelectionEvent e) {
-				updateInstallData();
+				setButtonsForProgrammingEnvSelection(installCPPEnv.getSelection() || installPythonEnv.getSelection());
+				updateInstallData();				
 			}
 
 		});
@@ -200,6 +201,7 @@
 
 			@Override
 			public void widgetSelected(SelectionEvent e) {
+				setButtonsForProgrammingEnvSelection(installCPPEnv.getSelection() || installPythonEnv.getSelection());
 				updateInstallData();
 			}
 
@@ -247,6 +249,16 @@
 	}
 
 	/**
+	 * Set select of installation details group if programming env is goind to be installed.
+	 * 
+	 * @param isSelected
+	 */
+	private void setButtonsForProgrammingEnvSelection(boolean isSelected) {
+		setInstallationDetailsGroupEnabled(!isSelected);
+		setInstallationDetailsButtonsSelection(isSelected);
+	}
+	
+	/**
 	 * Set enablement of all buttons of details area.
 	 * 
 	 * @param isEnabled
@@ -272,8 +284,9 @@
 				.getInstallData();
 			installData.setInstallCppEnv(installCPPEnv.getSelection());
 			installData.setInstallPythonEnv(installPythonEnv.getSelection());
+			installData.setInstallTargets(installScratchboxTargets.getSelection() || installCPPEnv.getSelection() || 
+					installPythonEnv.getSelection());
 			installData.setInstallSbox(installScratchbox.getSelection() || installScratchboxTargets.getSelection());
-			installData.setInstallTargets(installScratchboxTargets.getSelection());
 	}
 
 }

Modified: branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallData.java
===================================================================
--- branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallData.java	2009-07-17 19:10:18 UTC (rev 1879)
+++ branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallData.java	2009-07-19 04:16:42 UTC (rev 1880)
@@ -13,6 +13,7 @@
 import java.io.File;
 import java.net.MalformedURLException;
 
+import org.maemo.esbox.internal.api.vm.vmware.FileDownload;
 import org.maemo.esbox.internal.vm.vmware.Activator;
 
 /**

Deleted: branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstaller.java
===================================================================
--- branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstaller.java	2009-07-17 19:10:18 UTC (rev 1879)
+++ branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstaller.java	2009-07-19 04:16:42 UTC (rev 1880)
@@ -1,492 +0,0 @@
-/*******************************************************************************
- * 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.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.HashSet;
-import java.util.List;
-import java.util.Locale;
-import java.util.Set;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jface.dialogs.ProgressMonitorDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.widgets.Shell;
-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.FileDownload.Status;
-import org.maemo.esbox.vm.core.IVirtualMachine;
-import org.maemo.esbox.vm.core.IVirtualMachineConfiguration;
-import org.maemo.esbox.vm.ui.SelectVirtualMachineDialog;
-import org.maemo.esbox.vm.vmware.IVMwareConfiguration;
-import org.maemo.mica.common.core.EFSFileUtils;
-import org.maemo.mica.common.core.MicaException;
-import org.maemo.mica.common.core.Policy;
-import org.maemo.mica.common.core.filesystem.IFileSystemAccess;
-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 com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils;
-
-/**
- * This class wraps the main methods used during installation of Maemo SDK
- * virtual image.
- * 
- * @author raulherbster
- * 
- */
-public class MaemoSDKVMInstaller {
-
-	private MaemoSDKVMInstallData installData;
-	private IProgressReporter reporter;
-
-	/**
-	 * Constructor.
-	 * 
-	 * @param installData
-	 *            the installation data
-	 * @param reporter
-	 *            the progress reporter
-	 */
-	public MaemoSDKVMInstaller(MaemoSDKVMInstallData installData,
-			IProgressReporter reporter) {
-		this.installData = installData;
-		this.reporter = reporter;
-	}
-	
-	/**
-	 * Install component into virtual image based on installer data information
-	 * @param timeout
-	 * @param shell
-	 * @param monitor
-	 * @return
-	 */
-	public IStatus installVirtualImage(int timeout, Shell shell, IProgressMonitor monitor) {
-		IStatus status = null;
-		
-		if (!installData.canUsePreviousInstallation()) {
-			monitor.subTask("Downloading image...");
-			status = this.downloadVM(shell, monitor);
-			if (cannotProceed(status))
-				return status;
-		}
-		
-		monitor.subTask("Uncompressing image...");
-		status = this.uncompressVM(shell, monitor);
-		
-		if (cannotProceed(status))
-			return status;
-		
-		promptPreferencesDialog(shell);
-		
-		final IStatus[] statuses = new IStatus[] { Activator.createErrorStatus(
-				"The installation was canceled. Cannot proceed", null) };
-		
-		if (installData.canInstallSbox()) {
-			monitor.subTask("Installing Scratchbox 1...");
-			reporter.logInfo("Installing Scratchbox 1 on Maemo SDK virtual image. This operation may take several minutes.");
-			
-			shell.getDisplay().syncExec(new Runnable() {
-				
-				public void run() {
-					statuses[0] = NewScratchbox1SDKWizard.startWizard();					
-				}
-				
-			});	
-		}
-		
-		if (cannotProceed(statuses[0]))
-			return statuses[0];
-		
-		if (installData.canInstallTargets()) {
-			monitor.subTask("Installing Scratchbox 1 targets...");
-			reporter.logInfo("Installing Scratchbox 1 Targets on Maemo SDK virtual image. This operation may take several minutes.");
-			
-			shell.getDisplay().syncExec(new Runnable() {
-				
-				public void run() {
-					statuses[0] = NewScratchbox1TargetWizard.startWizard();					
-				}
-				
-			});			
-			
-		}
-		
-		if (cannotProceed(statuses[0]))
-			return statuses[0];
-		
-		if (installData.canInstallCppEnv() || installData.canInstallPythonEnv()) {
-			monitor.subTask("Installing programming environment...");
-			reporter.logInfo("Installing Python/C++ programming environment on Maemo SDK virtual image. This operation may take several minutes.");
-			status = this.installPackages(timeout, shell, monitor);
-			if (cannotProceed(status))
-				return status;
-		}
-		removeImageFiles();
-		return Activator.createStatus(IStatus.OK, "Maemo SDK Virtual Image was properly installed.");
-	}
-
-	private boolean cannotProceed(IStatus status) {
-		return status.matches(IStatus.CANCEL) || status.matches(IStatus.ERROR);
-	}
-	
-	
-	/**
-	 * Remove downloaded Maemo SDK virtual image file.
-	 */
-	public void removeImageFiles() {
-		reporter.logInfo("Removing Maemo SDK virtual image files...");
-		FileDownload downloadFile = installData.getFileToDownload();
-		IPath path;
-		try {
-			path = DownloadUtility.getFilePath(downloadFile);
-		} catch (MicaException e) {
-			reporter.logInfo("Maemo SDK virtual image files were not sucessfuly removed.");
-			return;
-		}
-		IFileSystemAccess fileSystemAccess = MachineRegistry.getInstance().getLocalMachine().getFileSystemAccess(); 
-		EFSFileUtils.deleteQuietly(path, fileSystemAccess, new NullProgressMonitor());
-	}
-	
-	/**
-	 * 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) {
-		reporter.logInfo("Downloading Maemo SDK virtual image...");
-		shell.getDisplay().syncExec(new Runnable() {
-
-			public void run() {
-				FileDownload fileDownload = installData.getFileToDownload();
-				DownloadExecution downloadWrapper = (DownloadExecution) fileDownload.downloadFile();
-				try {
-					DownloadProgressMonitor progressMonitor = new DownloadProgressMonitor(shell, downloadWrapper);
-					progressMonitor.run(true, true, downloadWrapper);
-				} catch (Exception e) {
-					fileDownload.cancel();
-				}
-			}
-
-		});
-		IStatus result = Policy.getCancelStatus(Activator.getDefault());
-		Status downloadStatus = installData.getFileToDownload().getStatus();
-		if (downloadStatus.equals(Status.CANCELLED))
-			result = Activator.createErrorStatus(
-					"The download was canceled. Cannot proceed", null);
-		else if (downloadStatus.equals(Status.ERROR))
-			result = Activator.createErrorStatus(
-					"An error occured during file 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) {
-		reporter.logInfo("Uncompressing Maemo SDK virtual image...");
-		
-		final String fileName = installData.getPathOfExistentVM();
-		final String destinationPath = installData.getInstallationPath();
-		
-		final IStatus[] statuses = { Activator.createStatus(IStatus.OK, "File " + fileName
-				+ " was properly uncompressed into " + destinationPath) } ;
-		
-		shell.getDisplay().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);
-										}
-										monitor.subTask("Uncompressing " + zipEntry
-												+ "\t\t"
-												+ String.format(Locale.US, "%.2f", getProgress(lenght,totalRead)) + "%");
-									}
-									fileOutputStream.close();
-									zipInputStream.closeEntry();
-									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];
-	}
-	
-	/**
-	 * 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) {
-		configureInitialVMSettings();
-		
-		final IStatus statuses[] = new IStatus[] {Policy.getCancelStatus(Activator.getDefault())};
-		
-		shell.getDisplay().syncExec(new Runnable() {
-
-			public void run() {
-				SelectVirtualMachineDialog dialog = new SelectVirtualMachineDialog(
-						WorkbenchUtils.getActiveShell());
-				int result = dialog.open();
-				if (result != Window.OK)
-					statuses[0] = Activator.createErrorStatus("Virtual image was not properly configured.", null);
-				else
-					statuses[0] = Activator.createStatus(IStatus.OK, "Virtual image configured.");
-			}			
-			
-		});
-		
-		return statuses[0];
-	}
-	
-	/**
-	 * Configure initial VM settings, such as vmx file path.
-	 */
-	public void configureInitialVMSettings() {
-		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;
-			}
-		}
-				
-		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);
-	}
-	
-	/**
-	 * 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++)
-	 * @param timeout
-	 * @param shell
-	 * @param monitor
-	 * @return
-	 */
-	private IStatus installPackages(int timeout, Shell shell, IProgressMonitor monitor) {
-		IStatus status = Policy.getCancelStatus(Activator.getDefault());
-		
-		Set<String> packagesToInstall = new HashSet<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");
-			else
-				packagesToInstall.add("maemo-python-env");
-		}	
-		
-		if(packagesToInstall.size() > 0) {
-			ISDKTarget[] targets = getBuildMachineTargets();
-			if (targets.length != 0) {				
-				monitor.subTask("Gathering package managers...");				
-				
-//				TargetPackageInstaller packageInstaller = new TargetPackageInstaller(
-//						packagesToInstall,
-//						new String[] {"deb http://repository.maemo.org/extras-devel/ fremantle free non-free"},
-//						getBuildMachine(),
-//						getBuildMachineTargets(),
-//						true,
-//						true,
-//						true,
-//						timeout,
-//						reporter);
-//				status = packageInstaller.ensureInstalledPackages(shell,monitor);
-				
-				if (status.matches(IStatus.CANCEL)) {
-					status = Activator.createErrorStatus("The package installation was canceled.", null);
-				}
-				
-			} else {
-				Activator.createErrorStatus("Invalid targets.", null);
-			}	
-		}
-		
-		return status;
-	}
-	
-	/**
-	 * Get current build machine.
-	 * @return
-	 */
-	private IBuildMachine getBuildMachine() {
-		IBuildMachine buildMachines[] =
-			MachineRegistry.getInstance().getBuildMachines();
-		IBuildMachine machine = null;
-		for (IBuildMachine buildMachine : buildMachines) {
-			if (buildMachine.isAlive()) {
-				machine = buildMachine;
-				break;
-			}
-		}		
-		return machine;
-	}
-	
-	/**
-	 * Get targets of current build machine.
-	 * @return
-	 */
-	private ISDKTarget[] getBuildMachineTargets() {
-		IBuildMachine 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()]);
-	}
-	
-}

Modified: branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMSelectionWizardPage.java
===================================================================
--- branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMSelectionWizardPage.java	2009-07-17 19:10:18 UTC (rev 1879)
+++ branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMSelectionWizardPage.java	2009-07-19 04:16:42 UTC (rev 1880)
@@ -35,6 +35,7 @@
 import org.eclipse.swt.widgets.Table;
 import org.eclipse.swt.widgets.TableColumn;
 import org.eclipse.swt.widgets.Text;
+import org.maemo.esbox.internal.api.vm.vmware.FileDownload;
 import org.maemo.esbox.internal.vm.vmware.Activator;
 import org.maemo.mica.common.ui.NetworkSettingsUI;
 import org.maemo.mica.common.ui.dialogs.DialogUtils;

Modified: branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoVMInstallerContentLabelProvider.java
===================================================================
--- branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoVMInstallerContentLabelProvider.java	2009-07-17 19:10:18 UTC (rev 1879)
+++ branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoVMInstallerContentLabelProvider.java	2009-07-19 04:16:42 UTC (rev 1880)
@@ -20,6 +20,7 @@
 import java.util.regex.Pattern;
 
 import org.eclipse.swt.graphics.Image;
+import org.maemo.esbox.internal.api.vm.vmware.FileDownload;
 import org.maemo.esbox.internal.vm.vmware.Activator;
 import org.maemo.mica.internal.api.common.ui.LazyLoadingThreadTableContentProvider;
 

Modified: branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/NewMaemoSDKVMWizard.java
===================================================================
--- branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/NewMaemoSDKVMWizard.java	2009-07-17 19:10:18 UTC (rev 1879)
+++ branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/NewMaemoSDKVMWizard.java	2009-07-19 04:16:42 UTC (rev 1880)
@@ -20,6 +20,7 @@
 import org.eclipse.jface.wizard.Wizard;
 import org.eclipse.ui.INewWizard;
 import org.eclipse.ui.IWorkbench;
+import org.maemo.esbox.internal.api.vm.vmware.MaemoSDKVMInstaller;
 import org.maemo.esbox.internal.vm.vmware.Activator;
 import org.maemo.mica.common.core.Policy;
 import org.maemo.mica.common.core.ui.IProgressReporter;
@@ -140,6 +141,9 @@
 					if (status.matches(IStatus.CANCEL))
 						status = Activator.createErrorStatus("The Maemo SDK virtual image installation was canceled.", null);
 
+					if (status.matches(IStatus.CANCEL) || status.matches(IStatus.ERROR))
+						reporter.appendStreamText(status.getMessage(), true);
+					
 					statuses[0] = status;
 				}
 
@@ -149,7 +153,7 @@
 					e.getCause());
 			statuses[0] = Activator.createErrorStatus("Maemo SDK virtual image installation failed unexpectedly",
 					e);
-		} 
+		}
 		return statuses[0];
 	}
 

Deleted: branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/RandomFileOutputStream.java
===================================================================
--- branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/RandomFileOutputStream.java	2009-07-17 19:10:18 UTC (rev 1879)
+++ branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/RandomFileOutputStream.java	2009-07-19 04:16:42 UTC (rev 1880)
@@ -1,102 +0,0 @@
-/*******************************************************************************
- * 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;
-
-/**
- * @author raulherbster
- *
- */
-import java.io.*;
-
-public class RandomFileOutputStream extends OutputStream {
-
-	protected RandomAccessFile randomFile; 
-	protected boolean sync;
-
-	public RandomFileOutputStream(String fnm) throws IOException {
-		this(fnm, false);
-	}
-
-	public RandomFileOutputStream(String fnm, boolean syn) throws IOException {
-		this(new File(fnm), syn);
-	}
-
-	public RandomFileOutputStream(File fil) throws IOException {
-		this(fil, false);
-	}
-
-	public RandomFileOutputStream(File fil, boolean syn) throws IOException {
-		super();
-
-		fil = fil.getAbsoluteFile();
-		
-		File par; // parent file
-		
-		if ((par = fil.getParentFile()) != null) {
-			par.mkdir();
-		}
-		
-		randomFile = new RandomAccessFile(fil, "rw");
-		sync = syn;
-	}
-
-	public void write(int val) throws IOException {
-		randomFile.write(val);
-		if (sync) {
-			randomFile.getFD().sync();
-		}
-	}
-
-	public void write(byte[] val) throws IOException {
-		randomFile.write(val);
-		if (sync) {
-			randomFile.getFD().sync();
-		}
-	}
-
-	public void write(byte[] val, int off, int len) throws IOException {
-		randomFile.write(val, off, len);
-		if (sync) {
-			randomFile.getFD().sync();
-		}
-	}
-
-	public void flush() throws IOException {
-		if (sync) {
-			randomFile.getFD().sync();
-		}
-	}
-
-	public void close() throws IOException {
-		randomFile.close();
-	}
-
-	public long getFilePointer() throws IOException {
-		return randomFile.getFilePointer();
-	}
-
-	public void setFilePointer(long pos) throws IOException {
-		randomFile.seek(pos);
-	}
-
-	public long getFileSize() throws IOException {
-		return randomFile.length();
-	}
-
-	public void setFileSize(long len) throws IOException {
-		randomFile.setLength(len);
-	}
-
-	public FileDescriptor getFD() throws IOException {
-		return randomFile.getFD();
-	}
-
-} // END PUBLIC CLASS
\ No newline at end of file



More information about the Esbox-commits mailing list