[Esbox-commits] r2120 - branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware

fabricioepa at garage.maemo.org fabricioepa at garage.maemo.org
Tue Sep 8 22:32:24 EEST 2009


Author: fabricioepa
Date: 2009-09-08 22:32:20 +0300 (Tue, 08 Sep 2009)
New Revision: 2120

Added:
   branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DefaultVMZipExtractor.java
Modified:
   branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMDownloader.java
   branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInfo.java
   branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInstaller.java
Log:
fixing 4476 and 4477

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


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

Modified: branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMDownloader.java
===================================================================
--- branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMDownloader.java	2009-09-08 17:56:21 UTC (rev 2119)
+++ branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMDownloader.java	2009-09-08 19:32:20 UTC (rev 2120)
@@ -298,7 +298,8 @@
 			
 			// Get link of remote file
 			File localFile = getLocalFile(remoteURL, downloadFile.getInstallLocation());
-			downloadFile.setFileName(localFile.getName());
+			if(nPart ==1)
+				downloadFile.setFileName(localFile.getName());
 			
 			downloadFile.setDownloadedSize(getPreviousDownloadSize(localFile));			
 			Integer remoteFileSize = (Integer) remoteFileInfo.get(1);;

Modified: branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInfo.java
===================================================================
--- branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInfo.java	2009-09-08 17:56:21 UTC (rev 2119)
+++ branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInfo.java	2009-09-08 19:32:20 UTC (rev 2120)
@@ -23,7 +23,8 @@
  */
 public class MaemoSDKVMInfo implements Comparable<MaemoSDKVMInfo> {
 //XXX REMOVE ME	public static final String DOWNLOAD_PAGE = "http://localhost:8080/nokia/";
-	public static final String DOWNLOAD_PAGE = "http://tablets-dev.nokia.com/maemo-dev-env-downloads.php";
+	public static final String DOWNLOAD_PAGE = "http://localhost:8080/nokia/";
+//	public static final String DOWNLOAD_PAGE = "http://tablets-dev.nokia.com/maemo-dev-env-downloads.php";
 
 	// status for the file
 	public enum Status {


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

Modified: branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInstaller.java
===================================================================
--- branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInstaller.java	2009-09-08 17:56:21 UTC (rev 2119)
+++ branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInstaller.java	2009-09-08 19:32:20 UTC (rev 2120)
@@ -11,22 +11,12 @@
 package org.maemo.esbox.internal.api.vm.vmware;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
-import java.util.Locale;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
 
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jface.dialogs.ProgressMonitorDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.preference.PreferenceDialog;
 import org.eclipse.jface.window.Window;
 import org.eclipse.swt.widgets.Shell;
@@ -48,7 +38,6 @@
 import org.maemo.mica.common.core.sdk.SDKManager;
 import org.maemo.mica.common.core.ui.IProgressReporter;
 import org.maemo.mica.internal.api.common.core.compression.Tool7zip;
-import org.maemo.mica.internal.api.common.core.filesystem.FilesystemUtils;
 import org.maemo.mica.internal.api.common.core.sdk.SDKManagerInternal;
 import org.maemo.mica.internal.api.linux.packages.core.aptinstall.AptInstallerHelper;
 
@@ -170,110 +159,21 @@
 			installData.getPathOfExistentVM();
 		final String destinationPath = installData.getInstallationPath();
 		
-		final IStatus[] statuses = { Activator.createStatus(IStatus.OK, "File " + fileName
-				+ " was properly uncompressed into " + destinationPath) } ;
+		IStatus status =  Activator.createStatus(IStatus.OK, "File " + fileName
+				+ " was properly uncompressed into " + destinationPath)  ;
 		
-		if (fileName == null || !Tool7zip.haveEnoughFreeSpace(fileName,destinationPath) ) {
+		IMachine machine = MachineRegistry.getInstance().getLocalMachine();
+		
+		if (fileName == null || !Tool7zip.haveEnoughFreeSpace(machine,fileName,destinationPath) ) {
 			return Activator.createStatus(IStatus.ERROR,"Cannot retrieve information about zipped Maemo SDK virtual image.");
-		} 
+		}
 		
-		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();
-								
-								if(zipEntry == null){
-									statuses[0] = Activator.createErrorStatus("Cannot uncompress Maemo SDK virtual image, no zip entry was found.", null);
-								}
-									
-								while (zipEntry != null) {						
-									
-									// for each entry to be extracted
-									String entryName = zipEntry.getName();
-									
-									monitor.beginTask("Uncompressing Maemo SDK virtual image", 100);
-									
-									long lenght = zipEntry.getSize();
-									
-									File newFile = new File(entryName);
-									String directory = newFile.getParent();
-									if (directory == null) {
-										if (newFile.isDirectory())
-											break;
-									}
-
-									fileOutputStream = new FileOutputStream(destinationPath
-											+ File.separator + entryName);
-									int n;
-									long totalRead = 0;
-									int previousProgressValue = 0;
-									while ((n = zipInputStream.read(buf, 0, 1024)) > -1) {
-										// write on file
-										fileOutputStream.write(buf, 0, n);
-										
-										// update progress monitor bar
-										totalRead += n;
-										int progressValue = ((int) getProgress(lenght,totalRead));
-										if (previousProgressValue < progressValue) {
-											previousProgressValue = progressValue;
-											monitor.worked(1);
-										}
-										if (monitor.isCanceled())
-											break;
-										monitor.subTask("Uncompressing " + zipEntry
-												+ "\t\t"
-												+ String.format(Locale.US, "%.2f", getProgress(lenght,totalRead)) + "%");
-										
-									}
-									fileOutputStream.close();
-									zipInputStream.closeEntry();
-									
-									if (monitor.isCanceled()) {
-										statuses[0] = Activator.createErrorStatus("Installation was cancelled.", null);
-										return;
-									} else {
-										zipEntry = zipInputStream.getNextEntry();
-									}
-								}
-
-							} catch (IOException ioe) {
-								statuses[0] = Activator.createErrorStatus("Cannot uncompress Maemo SDK virtual image: I/O error", ioe);
-								reporter.appendStreamText("Cannot uncompress Maemo SDK virtual image.", true);
-							} finally {
-
-								Policy.close(zipInputStream);
-
-								Policy.close(fileOutputStream);
-
-							}
-							
-						}
-						
-					});
-				} catch (Exception e) {
-					statuses[0] = Activator.createErrorStatus("Cannot uncompress Maemo SDK virtual image.", e);
-					reporter.appendStreamText("Cannot procced with Maemo SDK virtual image uncompressing.",true);
-				}			
-			}
-		});				
-		
-		return statuses[0];
+		if(installData.getUncompressToolPath() == null)
+			status = DefaultVMZipExtractor.extract(fileName, shell, destinationPath, reporter);
+		else{
+			status = Tool7zip.extractAndGetStatus(machine, fileName, destinationPath, reporter);
+		}
+		return status;
 	}
 	
 	/**
@@ -323,16 +223,6 @@
 	}
 	
 	/**
-	 * 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
@@ -529,37 +419,4 @@
 		return packagesToInstall.toArray(new String[packagesToInstall.size()]);
 	}
 	
-	/**
-	 * Check if there is enough space to uncompress the Maemo SDK virtual image. 
-	 * @param fileName the name of Maemo SDK virtual image.
-	 * @param destinationPath the destination path to uncompress the Maemo SDK virtual image.
-	 * @return boolean if there is enough space to uncompress the Maemo SDK virtual image (if the free space
-	 * available on disk is bigger than the size of uncompressed Maemo SDK virtual image); false, otherwise.
-	 */
-	private static boolean haveEnoughFreeSpace(String fileName, String destinationPath) {
-		ZipInputStream zipInputStream = null;
-		ZipEntry zipEntry;
-		
-		try {
-			long fileSize = 0;
-			zipInputStream = new ZipInputStream(new FileInputStream(fileName));
-			
-			// check the total size of zip file. It is necessary to check the size of each zip file entry.
-			while ((zipEntry = zipInputStream.getNextEntry()) != null) {
-				fileSize += zipEntry.getSize();
-			}		
-			fileSize = fileSize / 1024; //Kb
-			long freeSpace = FilesystemUtils.freeSpaceOS(new Path(destinationPath),true);
-			return freeSpace > fileSize;
-		} catch (IOException e) {
-			Activator.getErrorLogger().logError("Cannot retrieve information about zipped Maemo SDK virtual image. I/O error", e);
-			return false;
-			
-		} finally {			
-			Policy.close(zipInputStream);			
-		}
-	}
-	
-	
-	
 }


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



More information about the Esbox-commits mailing list