[Esbox-commits] r2125 - 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
Wed Sep 9 17:30:19 EEST 2009
Author: fabricioepa
Date: 2009-09-09 17:30:18 +0300 (Wed, 09 Sep 2009)
New Revision: 2125
Modified:
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/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
branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/Tool7zip.java
Log:
VM installer - decompressed size warn
Modified: 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 2009-09-09 13:09:50 UTC (rev 2124)
+++ branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DefaultVMZipExtractor.java 2009-09-09 14:30:18 UTC (rev 2125)
@@ -16,6 +16,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
+import java.text.DecimalFormat;
import java.util.Locale;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -36,7 +37,8 @@
*
*/
final class DefaultVMZipExtractor {
-
+ public static int SINGLE_FILE_PART = 1;
+
/**
* Extracts the compressed VM file on local machine
* @param fileName
@@ -107,8 +109,46 @@
static float getProgress(long total, long read) {
return ((float) read / total) * 100;
}
+
+
+ /**
+ * Return the array of files if this file is a multipart file
+ * @param fileName
+ * @param numParts
+ * @return
+ */
+ public static File[] getMultipartFiles(String fileName, int numParts){
+ if(numParts <= SINGLE_FILE_PART)
+ return new File[]{new File(fileName)};
+
+ File[] files = new File[numParts];
+ for(int i =0; i < numParts; i++){
+ String name = getFilePartName(fileName,i+1);
+ files[i] = new File(name);
+ }
+
+ return files;
+ }
+ /**
+ * The name of file part
+ * @param fileName
+ * @param nPart
+ * @return
+ */
+ public static String getFilePartName(String fileName, int nPart) {
+ String name = fileName;
+ int i = name.lastIndexOf('.');
+ if(i != -1)
+ name = name.substring(0,i);
+ DecimalFormat df = new DecimalFormat( "000");
+ String part = df.format(nPart);
+ name= name + '.' + part;
+ return name;
+ }
+
+
static final class ZipExtractor implements Runnable {
private final IStatus[] status;
private final Shell shell;
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-09 13:09:50 UTC (rev 2124)
+++ branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMDownloader.java 2009-09-09 14:30:18 UTC (rev 2125)
@@ -21,7 +21,6 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.text.DecimalFormat;
-import java.util.Formatter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
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-09 13:09:50 UTC (rev 2124)
+++ branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInfo.java 2009-09-09 14:30:18 UTC (rev 2125)
@@ -46,7 +46,6 @@
private String fileName;
private int numParts;
- public static int SINGLE_FILE_PART = 1;
/**
* Constructor.
@@ -66,7 +65,7 @@
downloaded = 0;
descriptor = null;
status = Status.DOWNLOADING;
- numParts = SINGLE_FILE_PART;
+ numParts = DefaultVMZipExtractor.SINGLE_FILE_PART;
}
/**
@@ -118,12 +117,17 @@
* @return returns the local downloaded file name, it can be null
*/
public File resolveLocalFile() {
+ return internalResolveLocalFile(getFileName());
+ }
+
+ private File internalResolveLocalFile(String fileName) {
try {
- return new File(getInstallLocation().toURI().resolve(getFileName()));
+ return new File(getInstallLocation().toURI().resolve(fileName));
} catch (URISyntaxException e) {
return null;
}
}
+
/**
* @param fileName the fileName to set
*/
@@ -236,7 +240,7 @@
* @return true, if the file has more than one part; false, otherwise.
*/
public boolean isMultipart() {
- return this.numParts > SINGLE_FILE_PART;
+ return this.numParts > DefaultVMZipExtractor.SINGLE_FILE_PART;
}
/**
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-09 13:09:50 UTC (rev 2124)
+++ branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInstaller.java 2009-09-09 14:30:18 UTC (rev 2125)
@@ -37,6 +37,7 @@
import org.maemo.mica.common.core.sdk.ISDKTarget;
import org.maemo.mica.common.core.sdk.SDKManager;
import org.maemo.mica.common.core.ui.IProgressReporter;
+import org.maemo.mica.common.ui.dialogs.DialogUtils;
import org.maemo.mica.internal.api.common.core.sdk.SDKManagerInternal;
import org.maemo.mica.internal.api.linux.packages.core.aptinstall.AptInstallerHelper;
@@ -154,24 +155,45 @@
monitor.subTask("Uncompressing image...");
reporter.logInfo("Uncompressing Maemo SDK virtual image...");
- final String fileName = installData.getPathOfExistentVM() == null ? installData.getFileToDownload().resolveLocalFile().getAbsolutePath() :
- installData.getPathOfExistentVM();
+ String fileName = null;
+ MaemoSDKVMInfo fileToDownload = installData.getFileToDownload();
+
+ if(installData.getPathOfExistentVM() == null){
+ File resolvedLocalFile = fileToDownload.resolveLocalFile();
+ if (resolvedLocalFile == null ) {
+ return Activator.createStatus(IStatus.ERROR,"Cannot retrieve information about zipped Maemo SDK virtual image.");
+ }
+ fileName = resolvedLocalFile.getAbsolutePath();
+ }else{
+ fileName = installData.getPathOfExistentVM();
+ }
+
+ if (fileName == null ) {
+ return Activator.createStatus(IStatus.ERROR,"Cannot retrieve information about zipped Maemo SDK virtual image.");
+ }
+
final String destinationPath = installData.getInstallationPath();
IStatus status = Activator.createStatus(IStatus.OK, "File " + fileName
+ " was properly uncompressed into " + destinationPath) ;
- IMachine machine = MachineRegistry.getInstance().getLocalMachine();
if(installData.getUncompressToolPath() == null){
- if (fileName == null || !DefaultVMZipExtractor.haveEnoughFreeSpace(fileName,destinationPath) ) {
- return Activator.createStatus(IStatus.ERROR,"Cannot retrieve information about zipped Maemo SDK virtual image.");
+ if (!DefaultVMZipExtractor.haveEnoughFreeSpace(fileName,destinationPath) ) {
+ return Activator.createStatus(IStatus.ERROR,"There is not enough free space to uncompress the Maemo SDK virtual image files.");
}
status = DefaultVMZipExtractor.extract(fileName, shell, destinationPath, reporter);
}else{
- Tool7zip tool = new Tool7zip(installData.getUncompressToolPath(),machine);
- if (fileName == null || !tool.haveEnoughFreeSpace(fileName,destinationPath) ) {
- return Activator.createStatus(IStatus.ERROR,"Cannot retrieve information about zipped Maemo SDK virtual image.");
+ Tool7zip tool = new Tool7zip(installData.getUncompressToolPath());
+ if (!tool.haveEnoughFreeSpaceUsingEstimatedRatio(fileName, fileToDownload.getNumParts(),destinationPath) ) {
+ reporter.log(Activator.createStatus(IStatus.WARNING, "Low disk space warning, perform a disk cleanup."));
+ if(!DialogUtils
+ .showQuestionDialog(
+ DialogUtils.getShell(),
+ "Low Disk Space Warning",
+ "The disk can not have enough free space to uncompress the Maemo SDK virtual image files. Do you want to proceed anyway?") ) {
+ return Activator.createStatus(IStatus.ERROR,"There is not enough free space to uncompress the Maemo SDK virtual image files.");
+ }
}
status = tool.extractAndGetStatus(fileName, destinationPath, reporter, monitor);
}
Modified: branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/Tool7zip.java
===================================================================
--- branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/Tool7zip.java 2009-09-09 13:09:50 UTC (rev 2124)
+++ branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/Tool7zip.java 2009-09-09 14:30:18 UTC (rev 2125)
@@ -1,6 +1,7 @@
package org.maemo.esbox.internal.api.vm.vmware;
import java.io.File;
+import java.io.IOException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -9,6 +10,7 @@
import org.maemo.esbox.internal.vm.vmware.Activator;
import org.maemo.mica.common.core.MicaException;
import org.maemo.mica.common.core.machine.IMachine;
+import org.maemo.mica.common.core.machine.MachineRegistry;
import org.maemo.mica.common.core.machine.MachineUtils;
import org.maemo.mica.common.core.process.CommandLineArguments;
import org.maemo.mica.common.core.process.IProcessLauncher;
@@ -18,6 +20,7 @@
import org.maemo.mica.common.core.process.ProcessLauncherUtils;
import org.maemo.mica.common.core.ui.IProgressReporter;
import org.maemo.mica.common.core.ui.ProgressReporterStreamTextMonitor;
+import org.maemo.mica.internal.api.common.core.filesystem.FilesystemUtils;
/**
* @author Fabrício S Epaminondas
@@ -51,42 +54,63 @@
private String path;
private final IMachine machine;
+ private final static double RATIO = 4;
- public Tool7zip(IMachine machine) {
+ /**
+ * Creates a 7z tool reference using default path
+ */
+ public Tool7zip() {
super();
+ this.machine = MachineRegistry.getInstance().getLocalMachine();
IPath path = MachineUtils.findProgramOnPath(machine, "7z");
if(path ==null)
throw new IllegalArgumentException("7zip could not be found on machine.");
this.path = path.toOSString();
- this.machine = machine;
}
/**
+ * Creates a 7z tool reference using the passed path
* @param path
* @param machine
* @throws MicaException
*/
- public Tool7zip(String path, IMachine machine) {
+ public Tool7zip(String path) {
super();
+ this.machine = MachineRegistry.getInstance().getLocalMachine();
if(!machine.getFileSystemAccess().getFileStore(new Path(path)).fetchInfo().exists())
throw new IllegalArgumentException("7zip could not be found on machine.");
this.path = path;
- this.machine = machine;
}
- /**
- * @param machine
- * @param fileName
- * @param destinationPath
- * @return
- */
- public boolean haveEnoughFreeSpace(String fileName,
- String destinationPath) {
- //TODO Estimate required space
- return true;
+ public boolean haveEnoughFreeSpaceUsingEstimatedRatio(String fileName,
+ int numParts, String destinationPath) {
+ File localFile = new File(fileName);
+ long totalSize = 0L;
+ long freeSpace = 0L;
+
+ if(numParts > DefaultVMZipExtractor.SINGLE_FILE_PART){
+ for(File f: DefaultVMZipExtractor.getMultipartFiles(fileName, numParts)){
+ totalSize += f.length();
+ }
+ }else{
+ totalSize = localFile.length();
+ }
+
+ try {
+ freeSpace = FilesystemUtils.freeSpaceOS(new Path(localFile.getAbsolutePath()),true);
+ } catch (IOException e) {
+ Activator
+ .getErrorLogger()
+ .logError(
+ "Cannot retrieve information about zipped Maemo SDK virtual image. I/O error",
+ e);
+ return false;
+ }
+ totalSize = totalSize/1024; //Kb
+ return false &&freeSpace > totalSize * RATIO ;
}
@@ -145,5 +169,4 @@
return status;
}
-
}
More information about the Esbox-commits
mailing list