From 5b7cacb96494600a73dcd8e25edd151b740b208d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sun, 30 Oct 2022 21:06:55 +0100 Subject: [PATCH] Added #1845 Show warning on opening file in Read only mode (binary search, unknown extensions, etc.) Added #1845 Show error message on saving in Read only mode, "Save As" must be used --- CHANGELOG.md | 3 +++ .../flash/configuration/Configuration.java | 3 +++ src/com/jpexs/decompiler/flash/gui/Main.java | 8 ++++++++ .../jpexs/decompiler/flash/gui/MainFrameMenu.java | 12 ++++++++++-- .../gui/locales/AdvancedSettingsDialog.properties | 3 +++ .../flash/gui/locales/MainFrame.properties | 12 +++++++++++- .../flash/gui/locales/MainFrame_cs.properties | 13 ++++++++++++- 7 files changed, 50 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ed8ca57a..dfb6a74e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ All notable changes to this project will be documented in this file. - [#1825], [#1737] Adding new frames - Context menu icons - Icon of tag in raw editor +- [#1845] Show warning on opening file in Read only mode (binary search, unknown extensions, etc.) +- [#1845] Show error message on saving in Read only mode, "Save As" must be used ### Fixed - [#1834] PlaceObject4 tags appear as Unresolved inside of DefineSprite @@ -2406,6 +2408,7 @@ All notable changes to this project will be documented in this file. [#1731]: https://www.free-decompiler.com/flash/issues/1731 [#1825]: https://www.free-decompiler.com/flash/issues/1825 [#1737]: https://www.free-decompiler.com/flash/issues/1737 +[#1845]: https://www.free-decompiler.com/flash/issues/1845 [#1834]: https://www.free-decompiler.com/flash/issues/1834 [#1839]: https://www.free-decompiler.com/flash/issues/1839 [#1838]: https://www.free-decompiler.com/flash/issues/1838 diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java index 4c2207244..a571d9432 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java @@ -159,6 +159,9 @@ public final class Configuration { @ConfigurationDefaultBoolean(false) public static ConfigurationItem useDetailedLogging = null; + + @ConfigurationDefaultBoolean(true) + public static ConfigurationItem warningOpeningReadOnly = null; /** * Debug mode = throwing an error when comparing original file and diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index 2bca689a0..32749bc4e 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -839,6 +839,14 @@ public class Main { Stopwatch sw = Stopwatch.startNew(); if (bundle != null) { + if (bundle.isReadOnly()) { + View.execInEventDispatchLater(new Runnable() { + @Override + public void run() { + ViewMessages.showMessageDialog(getMainFrame().getWindow(), AppStrings.translate("warning.readonly").replace("%file%", sourceInfo.getFileTitleOrName()), AppStrings.translate("message.warning"), JOptionPane.WARNING_MESSAGE, Configuration.warningOpeningReadOnly); + } + }); + } result.bundle = bundle; result.name = new File(sourceInfo.getFileTitleOrName()).getName(); for (Entry streamEntry : bundle.getAll().entrySet()) { diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java index 12e9fd983..ab246e883 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java @@ -140,6 +140,8 @@ public abstract class MainFrameMenu implements MenuBuilder { } catch (IOException ex) { Logger.getLogger(MainFrameMenu.class.getName()).log(Level.SEVERE, "Cannot save SWF", ex); } + } else { + ViewMessages.showMessageDialog(mainFrame.getWindow(), translate("error.readonly.cannotSave"), translate("error"), JOptionPane.ERROR_MESSAGE); } Main.stopSaving(savedFile); } else if (swf.binaryData != null) { @@ -184,8 +186,10 @@ public abstract class MainFrameMenu implements MenuBuilder { if (swf != null) { if (saveAs(swf, SaveFileMode.SAVEAS)) { - if (swf.swfList != null) { //binarydata won't clear modified on saveas - swf.clearModified(); + if (swf.swfList != null) { //binarydata won't clear modified on saveas + if (!isSwfReadOnly(swf)) { + swf.clearModified(); + } } } @@ -195,6 +199,10 @@ public abstract class MainFrameMenu implements MenuBuilder { return false; } + private boolean isSwfReadOnly(SWF swf) { + return swf.swfList != null && swf.swfList.bundle != null && swf.swfList.bundle.isReadOnly(); + } + private boolean saveAs(SWF swf, SaveFileMode mode) { View.checkAccess(); diff --git a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties index e3bb0ffb0..13a7f7102 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties @@ -564,3 +564,6 @@ config.description.lastView = Last displayed view mode config.name.swfSpecificCustomConfigs = SWF specific custom configurations config.description.swfSpecificCustomConfigs = Contains the SWF specific configurations in custom format + +config.name.warningOpeningReadOnly = Warn on opening readonly SWF +config.description.warningOpeningReadOnly = Show warning when opening SWF from readonly source diff --git a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties index 25c3248e1..583b838a9 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties @@ -875,4 +875,14 @@ message.input.addFrames.howmany = How many frames to add contextmenu.addFramesBefore = Add frames before contextmenu.addFramesAfter = Add frames after -contextmenu.addFrames = Add frames \ No newline at end of file +contextmenu.addFrames = Add frames + +error.readonly.cannotSave = File will NOT be saved. This SWF file source does not allow to save changes.\r\n\ +This is usually caused by loading binary data file or file with unknown extension in binary mode.\r\n\ +Please use the "Save As" command to export particular SWF file. + +warning.readonly = The file "%file%" is loaded in READONLY mode. \r\n\ +Changes you make won't be saved unless you use the "Save as" button.\r\n\ +This is usually caused by opening file in binary search mode,\r\n\ +the file has probably unknown extension and then saving cannot be done because\r\n\ +the file format is unknown. 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 b772c38cd..3d7f8527b 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_cs.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_cs.properties @@ -851,4 +851,15 @@ message.input.addFrames.howmany = Kolik sn\u00edmk\u016f p\u0159idat contextmenu.addFramesBefore = P\u0159idat sn\u00edmky p\u0159ed contextmenu.addFramesAfter = P\u0159idat sn\u00edmky po -contextmenu.addFrames = P\u0159idat sn\u00edmky \ No newline at end of file +contextmenu.addFrames = P\u0159idat sn\u00edmky + + +error.readonly.cannotSave = Soubor NEBUDE ulo\u017een. Zdroj tohoto SWF souboru nedovoluje ukl\u00e1dat zm\u011bny.\r\n\ +Toto je obvykle zp\u016fsobeno na\u010dten\u00edm bin\u00e1rn\u00edho datov\u00e9ho souboru nebo souboru s nezn\u00e1mou p\u0159\u00edponou v bin\u00e1rn\u00edm m\u00f3du.\r\n\ +Pros\u00edm pou\u017eijte p\u0159\u00edkaz "Ulo\u017eit jako" pro export jednotliv\u00fdch SWF soubor\u016f. + +warning.readonly = Soubor "%file%" je na\u010dten\u00fd v re\u017eimu JEN KE \u010cTEN\u00cd. \r\n\ +Zm\u011bny kter\u00e9 provedete nebudou ulo\u017eeny dokud nepou\u017eijete tla\u010d\u00edtko "Ulo\u017eit jako".\r\n\ +Toto je obvykle zp\u016fsobeno otev\u00edr\u00e1n\u00edm souboru v re\u017eimu bin\u00e1rn\u00edho vyhled\u00e1v\u00e1n\u00ed,\r\n\ +soubor m\u00e1 pravd\u011bpodobn\u011b nezn\u00e1mou p\u0159\u00edponu a tak ulo\u017een\u00ed nen\u00ed mo\u017en\u00e9 proto\u017ee\r\n\ +form\u00e1t souboru nen\u00ed zn\u00e1m. \ No newline at end of file