From 05fc58fa585b5988bef20c8a9364006a23974d9d Mon Sep 17 00:00:00 2001 From: Stephan Schwär Date: Thu, 4 Feb 2021 12:37:16 +0900 Subject: [client] Improve error handling for vmwarevm Also includes English and German translations Issue #3771 --- .../dozmod/gui/wizard/page/ImageUploadPage.java | 45 ++++++++++++++++------ 1 file changed, 33 insertions(+), 12 deletions(-) (limited to 'dozentenmodul/src/main/java') diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadPage.java index a23a62ac..ad1cd40d 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadPage.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadPage.java @@ -127,17 +127,40 @@ public class ImageUploadPage extends ImageUploadPageLayout { int action = fc.showOpenDialog(getDialog()); File file = fc.getSelectedFile(); - // If the vm was exported via vmware fusion on macos it might be - // a vmwarevm which is a directory containing the vm files within. - if (file != null && file.isDirectory()) { - File[] vmxfiles = file.listFiles(new FilenameFilter() { - public boolean accept(File dir, String filename) { - return filename.endsWith(".vmx"); + if (action == JFileChooser.APPROVE_OPTION) { + // If the vm was exported via vmware fusion on macos it might be + // a vmwarevm which is a directory containing the vm files within. + if (file != null && file.isDirectory()) { + try { + File[] vmxfiles = file.listFiles(new FilenameFilter() { + public boolean accept(File dir, String filename) { + return filename.endsWith(".vmx"); + } + }); + + // There should be only one vmx file in the directory + if (vmxfiles.length < 1) { + // TODO translate + Gui.showMessageBox(this, + I18n.PAGE.getString("ImageUpload.WizardPage.errorMessage.noVmxInDir"), + MessageType.ERROR, LOGGER, null); + return; + } else if (vmxfiles.length >= 2) { + Gui.showMessageBox(this, + I18n.PAGE.getString( + "ImageUpload.WizardPage.errorMessage.multipleVmxInDirFound"), + MessageType.ERROR, LOGGER, null); + } + if (vmxfiles[0] != null && vmxfiles[0].isFile()) + file = vmxfiles[0]; + } catch (Exception e) { + Gui.showMessageBox(this, + I18n.PAGE.getString( + "ImageUpload.WizardPage.errorMessage.errorWhileSearchingForVmx"), + MessageType.ERROR, LOGGER, e); + return; } - }); - // There should be only one vmx file in the directory - if (vmxfiles[0] != null && vmxfiles[0].isFile()) - file = vmxfiles[0]; + } } if (action != JFileChooser.APPROVE_OPTION || file == null) @@ -151,8 +174,6 @@ public class ImageUploadPage extends ImageUploadPageLayout { I18n.PAGE.getString("ImageUpload.WizardPage.dialog.OvfOvaDetected"), I18n.PAGE.getString("ImageUpload.WizardPage.dialog.title"), dialogButton); if (dialogResult == 0) { - // txtImageFile.setText(file.getAbsolutePath()); - // txtImageName.setText(state.meta.getDisplayName()); state.descriptionFile = file; setErrorMessage(null); setDescription("Bitte starten Sie die Konvertierung."); -- cgit v1.2.3-55-g7522