master
王兵 6 years ago
parent 0e87d86d01
commit fd2e06076b

@ -5,10 +5,12 @@ import xyz.wbsite.dbtool.javafx.manger.ManagerFactory;
import xyz.wbsite.dbtool.javafx.po.AbstractDBmapper;
import xyz.wbsite.dbtool.javafx.po.VueOption;
import xyz.wbsite.dbtool.javafx.tool.Tool;
import xyz.wbsite.dbtool.javafx.tool.ZipUtil;
import javax.validation.constraints.NotNull;
import java.io.File;
import java.util.concurrent.Callable;
import java.util.zip.ZipFile;
import static xyz.wbsite.dbtool.javafx.tool.Tool.clear;
@ -38,6 +40,7 @@ public class VueCallable implements Callable {
switch (option.type) {
case "vue":
Tool.outputResource("Vue/vue-simple.zip", new File(path, "vue-simple.zip"));
new ZipUtil().unZip(new File(path, "vue-simple.zip"),app);
break;
case "vue-element-admin":
Tool.outputResource("Vue/vue-element-admin.zip", new File(path, "vue-element-admin.zip"));

@ -0,0 +1,67 @@
package xyz.wbsite.dbtool.javafx.tool;
import java.io.*;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class ZipUtil {
public boolean unZip(File zipFile, File descDir) {
return unZip(zipFile, descDir, new ArrayList<>());
}
/**
*
*
* @param zipFile
* @param descDir
* @param urlList
* @return
*/
public boolean unZip(File zipFile, File descDir, List<String> urlList) {
boolean flag = false;
if (!descDir.exists()) {
descDir.mkdirs();
}
ZipFile zip = null;
try {
//指定编码,否则压缩包里面不能有中文目录
zip = new ZipFile(zipFile, Charset.forName("gbk"));
for (Enumeration entries = zip.entries(); entries.hasMoreElements(); ) {
ZipEntry entry = (ZipEntry) entries.nextElement();
String zipEntryName = entry.getName();
InputStream in = zip.getInputStream(entry);
File outPath = new File(descDir, zipEntryName);
//判断路径是否存在,不存在则创建文件路径
if (!outPath.getParentFile().exists()) {
outPath.getParentFile().mkdirs();
}
//判断文件全路径是否为文件夹,如果是上面已经上传,不需要解压
if (outPath.isDirectory()) {
continue;
}
//保存文件路径信息
urlList.add(outPath.getAbsolutePath());
OutputStream out = new FileOutputStream(outPath);
byte[] buf1 = new byte[2048];
int len;
while ((len = in.read(buf1)) > 0) {
out.write(buf1, 0, len);
}
in.close();
out.close();
}
flag = true;
//必须关闭否则无法删除该zip文件
zip.close();
} catch (IOException e) {
e.printStackTrace();
}
return flag;
}
}

@ -32,7 +32,7 @@
<VBox prefHeight="100.0" prefWidth="300.0">
<children>
<RadioButton mnemonicParsing="false" text="vue" id="1">
<RadioButton mnemonicParsing="false" text="vue" id="1" selected="true">
<toggleGroup>
<ToggleGroup fx:id="type"/>
</toggleGroup>

Loading…
Cancel
Save

Powered by TurnKey Linux.