From 22eb4dbc450045d8bc4d793c04c26f020b3178fc Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 7 Jan 2015 23:09:58 -0800 Subject: [PATCH] Cache icon generation on all platforms --- tools/helpers/FileHelper.hx | 13 ++++++ tools/helpers/IconHelper.hx | 91 ++++++++++++++++++------------------- 2 files changed, 58 insertions(+), 46 deletions(-) diff --git a/tools/helpers/FileHelper.hx b/tools/helpers/FileHelper.hx index ad65b9265..435ddfa2a 100644 --- a/tools/helpers/FileHelper.hx +++ b/tools/helpers/FileHelper.hx @@ -263,6 +263,19 @@ class FileHelper { } + public static function getLastModified (source:String):Float { + + if (FileSystem.exists (source)) { + + return FileSystem.stat (source).mtime.getTime (); + + } + + return -1; + + } + + public static function linkFile (source:String, destination:String, symbolic:Bool = true, overwrite:Bool = false) { if (!isNewer (source, destination)) { diff --git a/tools/helpers/IconHelper.hx b/tools/helpers/IconHelper.hx index f15b7efbd..87cddc22e 100644 --- a/tools/helpers/IconHelper.hx +++ b/tools/helpers/IconHelper.hx @@ -26,18 +26,55 @@ import sys.FileSystem; class IconHelper { - public static function createIcon (icons:Array , width:Int, height:Int, targetPath:String):Bool { + private static function canUseCache (targetPath:String, icons:Array):Bool { + + if (FileSystem.exists (targetPath)) { + + var cacheTime = FileHelper.getLastModified (targetPath); + + for (icon in icons) { + + if (FileHelper.getLastModified (icon.path) > cacheTime) { + + return false; + + } + + } + + return true; + + } + + return false; + + } + + + public static function createIcon (icons:Array, width:Int, height:Int, targetPath:String):Bool { var icon = findMatch (icons, width, height); if (icon != null && icon.size > 0 && Path.extension (icon.path) == "png") { + if (canUseCache (targetPath, [ icon ])) { + + return true; + + } + PathHelper.mkdir (Path.directory (targetPath)); FileHelper.copyFile (icon.path, targetPath); return true; } else { + if (canUseCache (targetPath, icons)) { + + return true; + + } + var image = getIconImage (icons, width, height); if (image != null) { @@ -55,32 +92,13 @@ class IconHelper { } - public static function createMacIcon (icons:Array , targetPath:String):Bool { + public static function createMacIcon (icons:Array, targetPath:String):Bool { - try { + if (canUseCache (targetPath, icons)) { - var useCache = FileSystem.exists (targetPath); + return true; - if (useCache) { - - var iconTime = FileSystem.stat (targetPath).mtime.getTime (); - - for (icon in icons) { - - if (FileSystem.exists (icon.path) && FileSystem.stat (icon.path).mtime.getTime () > iconTime) { - - useCache = false; - break; - - } - - } - - if (useCache) return true; - - } - - } catch (e:Dynamic) {} + } var out = new BytesOutput (); out.bigEndian = true; @@ -164,30 +182,11 @@ class IconHelper { public static function createWindowsIcon (icons:Array , targetPath:String):Bool { - try { + if (canUseCache (targetPath, icons)) { - var useCache = FileSystem.exists (targetPath); + return true; - if (useCache) { - - var iconTime = FileSystem.stat (targetPath).mtime.getTime (); - - for (icon in icons) { - - if (FileSystem.exists (icon.path) && FileSystem.stat (icon.path).mtime.getTime () > iconTime) { - - useCache = false; - break; - - } - - } - - if (useCache) return true; - - } - - } catch (e:Dynamic) {} + } var sizes = [ 16, 24, 32, 40, 48, 64, 96, 128, 256 ];