[Esbox-commits] r2277 - in branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal: api/vm/vmware vm/vmware/ui/wizards
fabricioepa at garage.maemo.org
fabricioepa at garage.maemo.org
Wed Oct 7 22:15:10 EEST 2009
Author: fabricioepa
Date: 2009-10-07 22:15:06 +0300 (Wed, 07 Oct 2009)
New Revision: 2277
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/vm/vmware/ui/wizards/MaemoSDKVMInstallerContentLabelProvider.java
branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMSelectionWizardPage.java
branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMUncompressInfoWizardPage.java
branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/NewMaemoSDKVMWizard.java
Log:
Fixing #4629
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-10-07 16:56:05 UTC (rev 2276)
+++ branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DefaultVMZipExtractor.java 2009-10-07 19:15:06 UTC (rev 2277)
@@ -38,7 +38,7 @@
* @author Fabrício S Epaminondas
*
*/
-final class DefaultVMZipExtractor {
+public final class DefaultVMZipExtractor {
public static int SINGLE_FILE_PART = 1;
public final static int DECOMPRESS_FACTOR = 4;
@@ -164,6 +164,20 @@
}
+ /**
+ * Returns true this file is a multipart file
+ * @param fileName
+ * @return
+ */
+ public static boolean isMultipartFile(String fileName){
+ File[] files = getMultipartFiles(fileName, 2);//should have at least 2 parts
+ for (File f: files) {
+ if(!f.exists())
+ return false;
+ }
+ return true;
+ }
+
/**
* Return the array of files if this file is a multipart file
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-10-07 16:56:05 UTC (rev 2276)
+++ branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMDownloader.java 2009-10-07 19:15:06 UTC (rev 2277)
@@ -27,6 +27,7 @@
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.core.runtime.Status;
import org.maemo.esbox.internal.vm.vmware.Activator;
@@ -61,12 +62,17 @@
/**
* Get URL and size of remote file.
- * @param nPart the number of the part to get info, null if it not is a multipart file
+ * @param downloadFile
+ * @param nPart the number of the part to get info, null if it is not a multipart file
+ * @param monitor
* @return URL and size of remote file.
* @throws MicaException
* @throws IOException
*/
- private Tuple getRemoteFileInfo(Integer nPart) throws MicaException, IOException {
+ public static Tuple getRemoteFileInfo(MaemoSDKVMInfo downloadFile, Integer nPart, IProgressMonitor monitor) throws MicaException {
+ if(monitor ==null)
+ monitor = new NullProgressMonitor();
+
URL connectionURL = null;
try {
connectionURL = new URL(MaemoSDKVMInfo.DOWNLOAD_PAGE);
@@ -100,8 +106,8 @@
HttpURLConnection conn = (HttpURLConnection) remoteURL.openConnection();
fileSize = conn.getContentLength();
- } catch (MalformedURLException e) {
- throw new MicaException("Invalid file URL on " + MaemoSDKVMInfo.DOWNLOAD_PAGE, e);
+ } catch (Exception e) {
+ throw new MicaException("Cannot get remote file information.", e);
}
return new Tuple(remoteURL, fileSize);
@@ -112,7 +118,7 @@
*
* @return the download page.
*/
- private String openDownloadPage() {
+ private static String openDownloadPage() {
String responsePage = null;
HttpURLConnection connection = null;
@@ -143,7 +149,7 @@
* @return
* @throws MicaException
*/
- private HttpURLConnection connectWithPostMethod(URL connectionUrl) 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;
@@ -173,7 +179,7 @@
* @return
* @throws MicaException
*/
- private String getResponse(HttpURLConnection conn) throws MicaException {
+ 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(
@@ -215,7 +221,7 @@
* @return
* @throws MalformedURLException
*/
- private URL getLinkFor(String htmlPage, String downloadFileDescription) 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,
@@ -299,7 +305,7 @@
protected IStatus downloadMultiple() throws MicaException, IOException {
for(int nPart = 1; nPart <= downloadFile.getNumParts(); nPart++){
- Tuple remoteFileInfo = getRemoteFileInfo(nPart);
+ Tuple remoteFileInfo = getRemoteFileInfo(downloadFile, nPart, monitor);
URL remoteURL = (URL) remoteFileInfo.get(0);
// Get link of remote file
@@ -415,7 +421,7 @@
}
protected IStatus downloadSingle() throws MicaException, IOException {
- Tuple remoteFileInfo = getRemoteFileInfo(null);
+ Tuple remoteFileInfo = getRemoteFileInfo(downloadFile,null, monitor);
URL remoteURL = (URL) remoteFileInfo.get(0);
// Get link of remote file
@@ -606,4 +612,36 @@
}
}
+
+ /**
+ * @param downloadFile2
+ * @throws IOException
+ * @throws MicaException
+ */
+ public static void fillRemoteFileInfo(MaemoSDKVMInfo downloadFile) {
+ try {
+ CookieHandler.setDefault(new SessionHandler());
+
+ Tuple t = null;
+ if(downloadFile.isMultipart()){
+ try {
+ t = getRemoteFileInfo(downloadFile, 1, null);
+ } catch (MicaException e) {
+ e.printStackTrace();
+ }
+ }else{
+ try {
+ t = getRemoteFileInfo(downloadFile, null, null);
+ } catch (MicaException e) {
+ e.printStackTrace();
+ }
+ }
+ if(t != null){
+ int size = (Integer) t.get(1);
+ downloadFile.setSize(size);
+ }
+ } finally {
+ CookieHandler.setDefault(null);
+ }
+ }
}
Modified: branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallerContentLabelProvider.java
===================================================================
--- branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallerContentLabelProvider.java 2009-10-07 16:56:05 UTC (rev 2276)
+++ branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallerContentLabelProvider.java 2009-10-07 19:15:06 UTC (rev 2277)
@@ -21,6 +21,7 @@
import org.eclipse.swt.graphics.Image;
import org.maemo.esbox.internal.api.vm.vmware.MaemoSDKVMDescription;
+import org.maemo.esbox.internal.api.vm.vmware.MaemoSDKVMDownloader;
import org.maemo.esbox.internal.api.vm.vmware.MaemoSDKVMInfo;
import org.maemo.esbox.internal.vm.vmware.Activator;
import org.maemo.mica.internal.api.common.ui.LazyLoadingThreadTableContentProvider;
@@ -86,6 +87,11 @@
info.setNumberOfParts(info.getNumParts() +1);
}
}
+ for(Object obj: contents){
+ if(MaemoSDKVMInfo.class.isAssignableFrom(obj.getClass())){
+ MaemoSDKVMDownloader.fillRemoteFileInfo((MaemoSDKVMInfo) obj);
+ }
+ }
}
/**
Modified: branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMSelectionWizardPage.java
===================================================================
--- branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMSelectionWizardPage.java 2009-10-07 16:56:05 UTC (rev 2276)
+++ branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMSelectionWizardPage.java 2009-10-07 19:15:06 UTC (rev 2277)
@@ -23,6 +23,7 @@
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
@@ -40,6 +41,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.DefaultVMZipExtractor;
import org.maemo.esbox.internal.api.vm.vmware.MaemoSDKVMInfo;
import org.maemo.esbox.internal.vm.vmware.Activator;
import org.maemo.mica.common.core.machine.MachineRegistry;
@@ -326,7 +328,7 @@
public void widgetSelected(SelectionEvent evt) {
FileDialog dialog = new FileDialog(DialogUtils.getShell(),
SWT.OPEN);
- dialog.setFilterExtensions(new String[] { "*.zip" });
+ dialog.setFilterExtensions(new String[] { "*.zip", "*.zip.*" });
dialog.setText("Select the location of compressed virtual image");
String pathDirectory = dialog.open();
if (pathDirectory != null) {
@@ -523,5 +525,24 @@
Arrays.sort(elements);
return (MaemoSDKVMInfo) elements[0];
}
+
+
+ @Override
+ public IWizardPage getNextPage() {
+ NewMaemoSDKVMWizard wizard = (NewMaemoSDKVMWizard) getWizard();
+ MaemoSDKVMInstallData installData = wizard.getInstallData();
+ MaemoSDKVMUncompressInfoWizardPage uncompressToolPage = wizard.getUncompressToolPage();
+ if(!usePreviousDownloadButton.getSelection()){
+ MaemoSDKVMInfo fileToDownload = installData.getFileToDownload();
+ if(uncompressToolPage.shouldShowThisPage(fileToDownload.isMultipart(), fileToDownload.getSize()))
+ return uncompressToolPage;
+ }else{
+ File f = new File(installData.getPathOfExistentVM());
+ if(uncompressToolPage.shouldShowThisPage(DefaultVMZipExtractor.isMultipartFile(installData.getPathOfExistentVM()), f.length()))
+ return uncompressToolPage;
+ }
+ return super.getNextPage();
+ }
+
}
Modified: branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMUncompressInfoWizardPage.java
===================================================================
--- branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMUncompressInfoWizardPage.java 2009-10-07 16:56:05 UTC (rev 2276)
+++ branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMUncompressInfoWizardPage.java 2009-10-07 19:15:06 UTC (rev 2277)
@@ -17,6 +17,7 @@
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
@@ -49,21 +50,27 @@
// options for uncompress tool
private Text uncompressToolTextField;
-
+ private WizardPage next;
/**
* Constructor.
*
* @param wizard
* parent wizard.
+ * @param configurationPage
*/
- protected MaemoSDKVMUncompressInfoWizardPage(NewMaemoSDKVMWizard wizard) {
+ protected MaemoSDKVMUncompressInfoWizardPage(NewMaemoSDKVMWizard wizard, MaemoSDKVMConfigurationWizardPage configurationPage) {
super("maemovm_uncompresstool", "Uncompress tool specification",
Activator.MAEMO_VM_WIZBAN_DESCRIPTOR);
setDescription("Specify the tool used to uncompress Maemo SDK Virtual Image.");
setWizard(wizard);
setPageComplete(false);
+ this.next = configurationPage;
}
+ @Override
+ public IWizardPage getNextPage() {
+ return next;
+ }
/*
* (non-Javadoc)
*
@@ -100,7 +107,6 @@
.applyTo(uncompressToollabel);
uncompressToolTextField = new Text(composite, SWT.BORDER);
- uncompressToolTextField.setText(getDefault7zPath());
uncompressToolTextField.setToolTipText("Specify the path of tool to uncompress Maemo SDK Virtual Image.");
GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(
uncompressToolTextField);
@@ -164,6 +170,19 @@
validatePage();
}
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
+ */
+ @Override
+ public void setVisible(boolean visible) {
+ super.setVisible(visible);
+ //set Defaults
+ if(uncompressToolTextField.getText().isEmpty()){
+ uncompressToolTextField.setText(getDefault7zPath());
+ validatePage();
+ }
+
+ }
/**
* Validate the wizard page.
@@ -209,4 +228,19 @@
return path;
}
+
+ /**
+ * Returns true if this page should be visible. Files bigger than 4Gb and multipart files cannot be
+ * uncompressed by common Java/Uzip tools, so this page provide a 7zip tool path selection
+ * @param isMultipartFile
+ * @param fileSize
+ * @return
+ */
+ public boolean shouldShowThisPage(boolean isMultipartFile, long fileSize) {
+ long sizeLimit = 4294967296L; // file sizer >4Gb
+ if (isMultipartFile || fileSize > sizeLimit) {
+ return true;
+ }
+ return false;
+ }
}
Modified: branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/NewMaemoSDKVMWizard.java
===================================================================
--- branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/NewMaemoSDKVMWizard.java 2009-10-07 16:56:05 UTC (rev 2276)
+++ branches/work_Fabricio/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/NewMaemoSDKVMWizard.java 2009-10-07 19:15:06 UTC (rev 2277)
@@ -73,15 +73,18 @@
public void addPages() {
targetPage = new MaemoSDKVMSelectionWizardPage(this);
addPage(targetPage);
- uncompressToolPage = new MaemoSDKVMUncompressInfoWizardPage(this);
- addPage(uncompressToolPage);
configurationPage = new MaemoSDKVMConfigurationWizardPage(this);
addPage(configurationPage);
+ uncompressToolPage = new MaemoSDKVMUncompressInfoWizardPage(this, configurationPage);
licensePage = new MaemoSDKVMLicenseWizardPage(this);
addPage(licensePage);
downloadUncompressWorkPage = new MaemoSDKVMInstallationWorkPage(this);
addPage(downloadUncompressWorkPage);
}
+
+ public MaemoSDKVMUncompressInfoWizardPage getUncompressToolPage() {
+ return uncompressToolPage;
+ }
/*
* (non-Javadoc)
More information about the Esbox-commits
mailing list