Commit 812cfdac authored by Daniel Dreibrodt's avatar Daniel Dreibrodt

Update unzip fix & preparation for update from 0.7 to 0.8

parent 74cb02d3
......@@ -26,9 +26,13 @@ import java.awt.Component;
import java.awt.Desktop;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.channels.FileChannel;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.swing.JOptionPane;
/**
......@@ -96,4 +100,33 @@ public class Helper {
if (outChannel != null) outChannel.close();
}
}
/**
* Unzips a ZIP file in the current working directory
* @param zip The ZIP file
* @throws java.io.FileNotFoundException
* @throws java.io.IOException
*/
public static void unzip(File zip) throws FileNotFoundException, IOException {
ZipInputStream zin = new ZipInputStream(new FileInputStream(zip));
ZipEntry entry;
while( (entry=zin.getNextEntry()) !=null ) {
if(!(System.getProperty("os.name").indexOf("Windows")==-1 && (entry.getName().endsWith("exe")||entry.getName().endsWith("dll")))){
File outf = new File(entry.getName());
System.out.println(outf.getAbsoluteFile());
if(entry.isDirectory()) outf.mkdirs();
else {
outf.createNewFile();
OutputStream out = new FileOutputStream(outf);
byte[] buf = new byte[1024];
int len;
while ((len = zin.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.close();
}
}
}
}
}
......@@ -1727,22 +1727,7 @@ public class Main extends javax.swing.JFrame implements ActionListener, TreeSele
pwin.dispose();
pwin = null;
ZipInputStream zin = new ZipInputStream(new FileInputStream(tempfile));
ZipEntry entry;
while( (entry=zin.getNextEntry()) !=null ) {
if(!(System.getProperty("os.name").indexOf("Windows")==-1 && (entry.getName().endsWith("exe")||entry.getName().endsWith("dll")))){
File outf = new File(entry.getName());
System.out.println(outf.getAbsoluteFile());
if(outf.exists()) outf.delete();
OutputStream out = new FileOutputStream(outf);
byte[] buf = new byte[1024];
int len;
while ((len = zin.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.close();
}
}
Helper.unzip(tempfile);
JOptionPane.showMessageDialog(this, Language.get("UPDATE_SUCCESS_MSG"),Language.get("UPDATE_SUCCESS_TITLE"), JOptionPane.INFORMATION_MESSAGE);
......@@ -1859,6 +1844,17 @@ public class Main extends javax.swing.JFrame implements ActionListener, TreeSele
e.printStackTrace();
}
}
//Unpack languages
File lang_zip = new File("lang.zip");
if(lang_zip.exists()) {
try {
Helper.unzip(lang_zip);
lang_zip.delete();
} catch(Exception ex) {
ex.printStackTrace();
}
}
new File(".updated").delete();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment