From 8ac23ad7c7c318f3062a93190e3ba8f02014ed43 Mon Sep 17 00:00:00 2001 From: Fangjie Hu Date: Thu, 22 Sep 2016 16:02:14 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=8F=92=E4=BB=B6=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=E4=B8=AD=E6=96=87=E4=B9=B1=E7=A0=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DownLoadDependenceUI.java | 71 +++++++++++++++++-- 1 file changed, 64 insertions(+), 7 deletions(-) diff --git a/designer_base/src/com/fr/design/extra/plugindependence/DownLoadDependenceUI.java b/designer_base/src/com/fr/design/extra/plugindependence/DownLoadDependenceUI.java index 5b0de740c..67d3a0354 100644 --- a/designer_base/src/com/fr/design/extra/plugindependence/DownLoadDependenceUI.java +++ b/designer_base/src/com/fr/design/extra/plugindependence/DownLoadDependenceUI.java @@ -20,12 +20,14 @@ import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.image.BufferedImage; -import java.io.File; -import java.io.FileOutputStream; -import java.io.InputStream; +import java.io.*; import java.net.HttpURLConnection; -import java.util.ArrayList; +import java.util.Enumeration; import java.util.List; + +import org.apache.tools.zip.ZipEntry; +import org.apache.tools.zip.ZipFile; + /** * Created by hufan on 2016/9/5. */ @@ -198,7 +200,7 @@ public class DownLoadDependenceUI implements ActionListener { } //安装文件 - IOUtils.unzip(new File(temp), FRContext.getCurrentEnv().getPath() + dependenceUnit.getDependenceDir()); + unZipFiles(temp, FRContext.getCurrentEnv().getPath() + dependenceUnit.getDependenceDir()); } else { result = false; @@ -254,14 +256,12 @@ public class DownLoadDependenceUI implements ActionListener { int choose = JOptionPane.showConfirmDialog(null, Inter.getLocText("FR-Designer-Plugin_Plugin") + Inter.getLocText("FR-Designer-Need") + Inter.getLocText("FR-Designer-Dependence") + Inter.getLocText("FR-Designer-Support") + "," + Inter.getLocText("FR-Designer-Dependence_Need_Install") + "(" + showFileLength() + " m)?", "install tooltip", JOptionPane.YES_NO_OPTION); if (choose == 0) {//下载安装 if (!connectToServer()) { - //JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Dependence_Connect_Server_Error"), "alert", JOptionPane.ERROR_MESSAGE); throw new PluginDependenceException(Inter.getLocText("FR-Designer-Dependence_Connect_Server_Error")); } //安装依赖环境 if (install()) { JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Dependence_Install_Succeed") + "!!"); } else { - //JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Dependence_Install_Failed") + "!!", "alert", JOptionPane.ERROR_MESSAGE); throw new PluginDependenceException(Inter.getLocText("FR-Designer-Dependence_Install_Failed")); } }else {//不选择下载,则不安装图标插件 @@ -272,4 +272,61 @@ public class DownLoadDependenceUI implements ActionListener { private String showFileLength() { return totalSize == -1 ? "NAN" : totalSize / Math.pow(10, 6) + ""; } + + + @SuppressWarnings("unchecked") + public static boolean unZipFiles(String zipFileName, String extPlace) throws Exception { + System.setProperty("sun.zip.encoding", System.getProperty("sun.jnu.encoding")); + try { + (new File(extPlace)).mkdirs(); + File f = new File(zipFileName); + ZipFile zipFile = new ZipFile(zipFileName,"GBK"); //处理中文文件名乱码的问题 + if((!f.exists()) && (f.length() <= 0)) { + throw new Exception("no zip file!"); + } + String strPath, gbkPath, strtemp; + File tempFile = new File(extPlace); + strPath = tempFile.getAbsolutePath(); + Enumeration e = zipFile.getEntries(); + while(e.hasMoreElements()){ + ZipEntry zipEnt = (ZipEntry) e.nextElement(); + gbkPath=zipEnt.getName(); + if(zipEnt.isDirectory()){ + strtemp = strPath + File.separator + gbkPath; + File dir = new File(strtemp); + dir.mkdirs(); + continue; + } else { + //读写文件 + InputStream is = zipFile.getInputStream(zipEnt); + BufferedInputStream bis = new BufferedInputStream(is); + gbkPath=zipEnt.getName(); + strtemp = strPath + File.separator + gbkPath; + + //建目录 + String strsubdir = gbkPath; + for(int i = 0; i < strsubdir.length(); i++) { + if(strsubdir.substring(i, i + 1).equalsIgnoreCase("/")) { + String temp = strPath + File.separator + strsubdir.substring(0, i); + File subdir = new File(temp); + if(!subdir.exists()) + subdir.mkdir(); + } + } + FileOutputStream fos = new FileOutputStream(strtemp); + BufferedOutputStream bos = new BufferedOutputStream(fos); + int c; + while((c = bis.read()) != -1) { + bos.write((byte) c); + } + bos.close(); + fos.close(); + } + } + return true; + } catch(Exception e) { + FRContext.getLogger().info(e.getMessage()); + return false; + } + } } From 3ace747624f84006b0ff2d932e284160bdf87ab5 Mon Sep 17 00:00:00 2001 From: Fangjie Hu Date: Thu, 22 Sep 2016 16:18:23 +0800 Subject: [PATCH 2/3] update --- .../DownLoadDependenceUI.java | 59 +------------------ 1 file changed, 1 insertion(+), 58 deletions(-) diff --git a/designer_base/src/com/fr/design/extra/plugindependence/DownLoadDependenceUI.java b/designer_base/src/com/fr/design/extra/plugindependence/DownLoadDependenceUI.java index 67d3a0354..9edfc21fe 100644 --- a/designer_base/src/com/fr/design/extra/plugindependence/DownLoadDependenceUI.java +++ b/designer_base/src/com/fr/design/extra/plugindependence/DownLoadDependenceUI.java @@ -200,7 +200,7 @@ public class DownLoadDependenceUI implements ActionListener { } //安装文件 - unZipFiles(temp, FRContext.getCurrentEnv().getPath() + dependenceUnit.getDependenceDir()); + IOUtils.unZipFilesGBK(temp, FRContext.getCurrentEnv().getPath() + dependenceUnit.getDependenceDir()); } else { result = false; @@ -272,61 +272,4 @@ public class DownLoadDependenceUI implements ActionListener { private String showFileLength() { return totalSize == -1 ? "NAN" : totalSize / Math.pow(10, 6) + ""; } - - - @SuppressWarnings("unchecked") - public static boolean unZipFiles(String zipFileName, String extPlace) throws Exception { - System.setProperty("sun.zip.encoding", System.getProperty("sun.jnu.encoding")); - try { - (new File(extPlace)).mkdirs(); - File f = new File(zipFileName); - ZipFile zipFile = new ZipFile(zipFileName,"GBK"); //处理中文文件名乱码的问题 - if((!f.exists()) && (f.length() <= 0)) { - throw new Exception("no zip file!"); - } - String strPath, gbkPath, strtemp; - File tempFile = new File(extPlace); - strPath = tempFile.getAbsolutePath(); - Enumeration e = zipFile.getEntries(); - while(e.hasMoreElements()){ - ZipEntry zipEnt = (ZipEntry) e.nextElement(); - gbkPath=zipEnt.getName(); - if(zipEnt.isDirectory()){ - strtemp = strPath + File.separator + gbkPath; - File dir = new File(strtemp); - dir.mkdirs(); - continue; - } else { - //读写文件 - InputStream is = zipFile.getInputStream(zipEnt); - BufferedInputStream bis = new BufferedInputStream(is); - gbkPath=zipEnt.getName(); - strtemp = strPath + File.separator + gbkPath; - - //建目录 - String strsubdir = gbkPath; - for(int i = 0; i < strsubdir.length(); i++) { - if(strsubdir.substring(i, i + 1).equalsIgnoreCase("/")) { - String temp = strPath + File.separator + strsubdir.substring(0, i); - File subdir = new File(temp); - if(!subdir.exists()) - subdir.mkdir(); - } - } - FileOutputStream fos = new FileOutputStream(strtemp); - BufferedOutputStream bos = new BufferedOutputStream(fos); - int c; - while((c = bis.read()) != -1) { - bos.write((byte) c); - } - bos.close(); - fos.close(); - } - } - return true; - } catch(Exception e) { - FRContext.getLogger().info(e.getMessage()); - return false; - } - } } From b9e4c576f49232ef8d344cb25276be32239afa8e Mon Sep 17 00:00:00 2001 From: Fangjie Hu Date: Thu, 22 Sep 2016 16:19:16 +0800 Subject: [PATCH 3/3] update --- .../design/extra/plugindependence/DownLoadDependenceUI.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/designer_base/src/com/fr/design/extra/plugindependence/DownLoadDependenceUI.java b/designer_base/src/com/fr/design/extra/plugindependence/DownLoadDependenceUI.java index 9edfc21fe..eb7af116b 100644 --- a/designer_base/src/com/fr/design/extra/plugindependence/DownLoadDependenceUI.java +++ b/designer_base/src/com/fr/design/extra/plugindependence/DownLoadDependenceUI.java @@ -22,12 +22,8 @@ import java.awt.event.WindowEvent; import java.awt.image.BufferedImage; import java.io.*; import java.net.HttpURLConnection; -import java.util.Enumeration; import java.util.List; -import org.apache.tools.zip.ZipEntry; -import org.apache.tools.zip.ZipFile; - /** * Created by hufan on 2016/9/5. */