diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b63e1f3e..1c4f7e26c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Change Log All notable changes to this project will be documented in this file. +## [Unreleased] +### Added +- [#1015], [#1466], [#1513] Better error messages during saving, display message on out of memory + ## [14.3.1] - 2021-03-25 ### Fixed - "protected", "const", "namespace", "package" are not reserved keywords in AS1/2 @@ -2035,7 +2039,8 @@ All notable changes to this project will be documented in this file. ### Added - Initial public release -[Unreleased]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version14.3.0...Unreleased +[Unreleased]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version14.3.1...Unreleased +[14.3.1]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version14.3.0...version14.3.1 [14.3.0]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version14.2.1...version14.3.0 [14.2.1]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version14.2.0...version14.2.1 [14.2.0]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version14.1.0...version14.2.0 @@ -2147,6 +2152,9 @@ All notable changes to this project will be documented in this file. [alpha 9]: https://github.com/jindrapetrik/jpexs-decompiler/compare/alpha8...alpha9 [alpha 8]: https://github.com/jindrapetrik/jpexs-decompiler/compare/alpha7...alpha8 [alpha 7]: https://github.com/jindrapetrik/jpexs-decompiler/releases/tag/alpha7 +[#1015]: https://www.free-decompiler.com/flash/issues/1015 +[#1466]: https://www.free-decompiler.com/flash/issues/1466 +[#1513]: https://www.free-decompiler.com/flash/issues/1513 [#1665]: https://www.free-decompiler.com/flash/issues/1665 [#1660]: https://www.free-decompiler.com/flash/issues/1660 [#1661]: https://www.free-decompiler.com/flash/issues/1661 diff --git a/resources/ffdec.bat b/resources/ffdec.bat index 251b40c29..b7d5743c5 100644 --- a/resources/ffdec.bat +++ b/resources/ffdec.bat @@ -1,2 +1,5 @@ @echo off -java -Xmx1024m -Djna.nosys=true -Dsun.java2d.uiScale=1.0 -jar "%~dp0\ffdec.jar" %* \ No newline at end of file +rem Set following to higher value if you want more memory: +rem You need 64 bit OS and 64 bit java to set it to higher values +set MEMORY=1024m +java -Xmx%MEMORY% -Djna.nosys=true -Dsun.java2d.uiScale=1.0 -jar "%~dp0\ffdec.jar" %* \ No newline at end of file diff --git a/resources/ffdec.sh b/resources/ffdec.sh index 11ea7e8c0..1c27256f9 100644 --- a/resources/ffdec.sh +++ b/resources/ffdec.sh @@ -1,4 +1,9 @@ #!/usr/bin/env bash + +# Set following to higher value if you want more memory +# You need 64 bit OS and 64 bit java to set it to higher values +MEMORY=1024m + # Based on Freerapid Downloader startup script - created by Petris 2009 # FFDec requires Oracle Java 8 @@ -9,7 +14,6 @@ REQ_JVER1=1 REQ_JVER2=8 REQ_JVER3=0 REQ_JVER4=0 -MEMORY=1024m search_jar_file() { JAR_FILE_CANDIDATES='./ffdec.jar ../dist/ffdec.jar /usr/share/java/ffdec.jar /usr/share/java/ffdec/ffdec.jar /usr/share/java/jpexs-decompiler/ffdec.jar' diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index 84899c4da..55ebe321f 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -1072,6 +1072,12 @@ public class Main { bos.write((swfSize >> 24) & 0xff); } } + } catch (Throwable t) { + stopSaving(savedFile); + if (tmpFile.exists()) { + tmpFile.delete(); + } + throw t; } if (tmpFile.exists()) { if (tmpFile.length() > 0) { @@ -1534,13 +1540,36 @@ public class Main { Main.saveFile(swf, fileName, mode, exeExportMode); Configuration.lastSaveDir.set(file.getParentFile().getAbsolutePath()); return true; - } catch (IOException ex) { - View.showMessageDialog(null, AppStrings.translate("error.file.write")); + } catch (Exception | OutOfMemoryError | StackOverflowError ex) { + handleSaveError(ex); } } return false; } + public static void handleSaveError(Throwable ex) { + Logger.getLogger(Main.class.getName()).log(Level.SEVERE, "Error saving file", ex); + if (ex instanceof OutOfMemoryError) { + String errorMessage = AppStrings.translate("error.file.save") + "."; + errorMessage += " "; + long heapMaxSize = Runtime.getRuntime().maxMemory(); + long heapMaxSizeMb = heapMaxSize / 1024 / 1024; + String currentMaxHeap = "" + heapMaxSizeMb + "m"; + errorMessage += AppStrings.translate("error.outOfMemory").replace("%maxheap%", currentMaxHeap); + errorMessage += "\n"; + if (Platform.isWindows()) { + errorMessage += AppStrings.translate("error.outOfMemory.windows"); + } else { + errorMessage += AppStrings.translate("error.outOfMemory.unixmac"); + } + errorMessage += "\n"; + errorMessage += AppStrings.translate("error.outOfMemory.64bit"); + View.showMessageDialog(null, errorMessage, AppStrings.translate("error.outOfMemory.title"), JOptionPane.ERROR_MESSAGE); + } else { + View.showMessageDialog(null, AppStrings.translate("error.file.save") + ": " + ex.getLocalizedMessage(), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE); + } + } + public static boolean openFileDialog() { View.checkAccess(); diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java index 91f6064b6..871d940c1 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java @@ -159,9 +159,8 @@ public abstract class MainFrameMenu implements MenuBuilder { try { Main.saveFile(swf, swf.getFile()); saved = true; - } catch (IOException ex) { - Logger.getLogger(MainFrameMenu.class.getName()).log(Level.SEVERE, null, ex); - View.showMessageDialog(null, translate("error.file.save"), translate("error"), JOptionPane.ERROR_MESSAGE); + } catch (Exception | OutOfMemoryError | StackOverflowError ex) { + Main.handleSaveError(ex); } } if (saved) { diff --git a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties index f6fb7bb75..750674189 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties @@ -807,4 +807,11 @@ message.character.notfound = Character %characterid% not found. FileChooser.preview = Preview FileChooser.previewNotAvailable = (preview not available) -button.freetransform = Free transform \ No newline at end of file +button.freetransform = Free transform + +error.outOfMemory.title = Error - out of memory +error.outOfMemory = The decompiler ran out of memory. Current maximum size of Java Heap is set to %maxheap%. +error.outOfMemory.windows = You can increase this maximum by editing "ffdec.bat" file and then running the app via this file instead of "ffdec.exe". +error.outOfMemory.unixmac = You can increase this maximum by editing "ffdec.sh" file. +error.outOfMemory.64bit = You need 64 bit OS and 64 bit Java to use more than cca 1GB. + diff --git a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_cs.properties b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_cs.properties index d064a1c38..b875baea3 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_cs.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_cs.properties @@ -783,4 +783,10 @@ message.character.notfound = Charakter %characterid% nenalezen. FileChooser.preview = N\u00e1hled FileChooser.previewNotAvailable = (n\u00e1hled nen\u00ed dostupn\u00fd) -button.freetransform = Voln\u00e1 transformace \ No newline at end of file +button.freetransform = Voln\u00e1 transformace + +error.outOfMemory.title = Chyba - do\u0161la pam\u011b\u0165 +error.outOfMemory = Dekompil\u00e1toru do\u0161la pam\u011b\u0165. Aktu\u00e1ln\u00ed maxim\u00e1ln\u00ed velikost Java Heapu je nastavena na %maxheap%. +error.outOfMemory.windows = Toto maximum m\u016f\u017eete nav\u00fd\u0161it upraven\u00edm souboru "ffdec.bat" a pak spou\u0161t\u011bn\u00edm aplikace p\u0159es tento soubor m\u00edsto "ffdec.exe". +error.outOfMemory.unixmac = Toto maximum m\u016f\u017eete nav\u00fd\u0161it upraven\u00edm souboru "ffdec.sh". +error.outOfMemory.64bit = Pro pou\u017eit\u00ed v\u00edc jak zhruba 1GB budete pot\u0159ebovat 64bitov\u00fd opera\u010dn\u00ed syst\u00e9m a 64bitovou Javu. \ No newline at end of file