/**
* Разархивирует файл client.zip из папки bin в .minecraft
* @author ddark008
* @throws PrivilegedActionException
*/
protected void UnZip() throws PrivilegedActionException
{
String szZipFilePath;
String szExtractPath;
String path = (String)AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
public Object run() throws Exception {
return Util.getWorkingDirectory() + File.separator;
}
});
int i;
szZipFilePath = path + "bin" + File.separator + "client.zip";
File f = new File(szZipFilePath);
if(!f.exists())
{
System.out.println(
"\nNot found: " + szZipFilePath);
}
if(f.isDirectory())
{
System.out.println(
"\nNot file: " + szZipFilePath);
}
System.out.println(
"Enter path to extract files: ");
szExtractPath = path;
File f1 = new File(szExtractPath);
if(!f1.exists())
{
System.out.println(
"\nNot found: " + szExtractPath);
}
if(!f1.isDirectory())
{
System.out.println(
"\nNot directory: " + szExtractPath);
}
ZipFile zf;
Vector zipEntries = new Vector();
try
{
zf = new ZipFile(szZipFilePath);
Enumeration en = zf.entries();
while(en.hasMoreElements())
{
zipEntries.addElement(
(ZipEntry)en.nextElement());
}
for (i = 0; i < zipEntries.size(); i++)
{
ZipEntry ze =
(ZipEntry)zipEntries.elementAt(i);
extractFromZip(szZipFilePath, szExtractPath,
ze.getName(), zf, ze);
}
zf.close();
System.out.println("Done!");
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
f.delete();
}
// ============================================
// extractFromZip
// ============================================
static void extractFromZip(
String szZipFilePath, String szExtractPath,
String szName,
ZipFile zf, ZipEntry ze)
{
if(ze.isDirectory())
return;
String szDstName = slash2sep(szName);
String szEntryDir;
if(szDstName.lastIndexOf(File.separator) != -1)
{
szEntryDir =
szDstName.substring(
0, szDstName.lastIndexOf(File.separator));
}
else
szEntryDir = "";
System.out.print(szDstName);
long nSize = ze.getSize();
long nCompressedSize =
ze.getCompressedSize();
System.out.println(" " + nSize + " (" +
nCompressedSize + ")");
try
{
File newDir = new File(szExtractPath +
File.separator + szEntryDir);
newDir.mkdirs();
FileOutputStream fos =
new FileOutputStream(szExtractPath +
File.separator + szDstName);
InputStream is = zf.getInputStream(ze);
byte[] buf = new byte[1024];
int nLength;
while(true)
{
try
{
nLength = is.read(buf);
}
catch (EOFException ex)
{
break;
}
if(nLength < 0)
break;
fos.write(buf, 0, nLength);
}
is.close();
fos.close();
}
catch(Exception ex)
{
System.out.println(ex.toString());
//System.exit(0);
}
}
// ============================================
// slash2sep
// ============================================
static String slash2sep(String src)
{
int i;
char[] chDst = new char[src.length()];
String dst;
for(i = 0; i < src.length(); i++)
{
if(src.charAt(i) == '/')
chDst = File.separatorChar;
else
chDst = src.charAt(i);
}
dst = new String(chDst);
return dst;
}