From e50cbc5f4429e6034b9df74c4dcab6aa25d45850 Mon Sep 17 00:00:00 2001 From: "nor..67" Date: Fri, 26 Oct 2012 13:08:48 +0000 Subject: [PATCH] SDK: - allow asychronous installation with ZipExtensionTool git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9902 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../jme3/gde/core/util/ZipExtensionTool.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/sdk/jme3-core/src/com/jme3/gde/core/util/ZipExtensionTool.java b/sdk/jme3-core/src/com/jme3/gde/core/util/ZipExtensionTool.java index d673bbad7..f8bcb39ae 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/util/ZipExtensionTool.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/util/ZipExtensionTool.java @@ -40,6 +40,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; +import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; import java.util.logging.Logger; import java.util.zip.ZipEntry; @@ -62,6 +63,7 @@ import org.openide.util.Utilities; */ public class ZipExtensionTool { + static final ConcurrentHashMap installMap = new ConcurrentHashMap(); static final int BUFFER = 2048; private final String settingsFolder = System.getProperty("netbeans.user"); public String SUFFIX_WIN = "windows"; @@ -76,7 +78,7 @@ public class ZipExtensionTool { this.extensionName = extensionName; } - public void install() { + private void install() { if (new File(settingsFolder + File.separator + extensionName).exists()) { return; } @@ -92,6 +94,21 @@ public class ZipExtensionTool { progressHandle.finish(); } + public void install(boolean async) { + if (async && installMap.putIfAbsent(extensionName, true) == null) { + new Thread(new Runnable() { + @Override + public void run() { + install(); + installMap.remove(extensionName); + } + }).start(); + } else if (!async && installMap.putIfAbsent(extensionName, true) == null) { + install(); + installMap.remove(extensionName); + } + } + private boolean extractToolsShell(String zipPath, String extractionPath) { File path = new File(extractionPath); if (!path.exists()) { @@ -102,7 +119,6 @@ public class ZipExtensionTool { URL url = null; try { String tempFileName = extractionPath + "_tmp.zip"; - System.out.println("ZipPath: " + zipPath); url = new URL("nbres:" + zipPath); in = new BufferedInputStream(url.openStream()); out = new BufferedOutputStream(new FileOutputStream(tempFileName));