From 3eb1fb9d4bfaff5d49d3f370865ebe4d7b8c975f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sat, 20 Nov 2021 19:23:52 +0100 Subject: [PATCH] Fixed #1750 Application won't start when cannot access font file --- CHANGELOG.md | 5 ++- .../decompiler/flash/helpers/FontHelper.java | 34 +++++++++++-------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0152a0eff..15d95711e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file. ### Fixed - AS1/2 handle declaration of registers in certain cases - AS1/2 setProperty, getProperty handling +- [#1750] Application won't start when cannot access font file ## [14.5.1] - 2021-11-20 ### Fixed @@ -2110,7 +2111,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.4.0...dev +[14.5.1]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version14.5.0...version14.5.1 +[14.5.0]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version14.4.0...version14.5.0 [14.4.0]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version14.3.1...version14.4.0 [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 @@ -2224,6 +2226,7 @@ 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 +[#1750]: https://www.free-decompiler.com/flash/issues/1750 [#1485]: https://www.free-decompiler.com/flash/issues/1485 [#1681]: https://www.free-decompiler.com/flash/issues/1681 [#1744]: https://www.free-decompiler.com/flash/issues/1744 diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/FontHelper.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/FontHelper.java index 8fb2b993f..2fd562302 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/FontHelper.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/FontHelper.java @@ -51,7 +51,6 @@ public class FontHelper { Class clFmFactory = Class.forName("sun.font.FontManagerFactory"); return clFmFactory.getDeclaredMethod("getInstance").invoke(null); }*/ - /** * Gets all available fonts in the system * @@ -89,7 +88,7 @@ public class FontHelper { } catch (Throwable ex) { // ignore } - */ + */ if (fonts == null) { fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts(); } @@ -312,23 +311,28 @@ public class FontHelper { return ret; } + private static List getTtfFilesRecursively(File dir) { + List ret = new ArrayList<>(); + try { + File files[] = dir.listFiles(); + for (File f : files) { + if (f.isDirectory()) { + ret.addAll(getTtfFilesRecursively(f)); + } else if (f.getAbsolutePath().endsWith(".ttf") || f.getAbsolutePath().endsWith(".TTF")) { + ret.add(f); + } + } + } catch (Exception ex) { + //ignore any access errors + } + return ret; + } + private static List getSystemFontFiles() { List dirs = getSystemFontDirectories(); List ret = new ArrayList<>(); for (File d : dirs) { - try { - Object[] paths = Files.find(d.toPath(), Integer.MAX_VALUE, new BiPredicate() { - @Override - public boolean test(Path t, BasicFileAttributes u) { - return u.isRegularFile() && (t.toString().endsWith(".ttf") || t.toString().endsWith(".TTF")); - } - }).toArray(); - for (Object o : paths) { - ret.add(((Path) o).toFile()); - } - } catch (IOException ex) { - //ignore - } + ret.addAll(getTtfFilesRecursively(d)); } return ret; }