I'm currently working on a application that installs mods into Minecraft and I have almost finished version 3.1DEV, the only thing that is stoping me is that my code just won't remove the META-INF, here is my code
ZipInputStream modZip = new ZipInputStream(new FileInputStream(mod.getDir()));
ZipInputStream minecraftZip = new ZipInputStream(new FileInputStream(new File(mcDir + "\\bin\\", "minecraft.jar")));
ZipOutputStream tmpZip = new ZipOutputStream(new FileOutputStream(new File("temp\\tmp.jar")));
byte[] buffer = new byte[1024];
for(ZipEntry ze = modZip.getNextEntry(); ze != null; ze = modZip.getNextEntry())
{
tmpZip.putNextEntry(ze);
for(int read = modZip.read(buffer); read != -1; read = modZip.read(buffer))
{
tmpZip.write(buffer, 0, read);
}
tmpZip.closeEntry();
}
modZip.close();
for(ZipEntry ze = minecraftZip.getNextEntry(); ze != null; ze = minecraftZip.getNextEntry())
{
try
{
boolean isMetaInf = false;
if(ze.getName().contains("META-INF"))
{
isMetaInf = true;
}
if(!isMetaInf)
{
tmpZip.putNextEntry(ze);
for(int read = minecraftZip.read(buffer); read != -1; read = minecraftZip.read(buffer))
{
tmpZip.write(buffer, 0, read);
}
tmpZip.closeEntry();
}
}
catch(Exception e)
{
continue;
}
}
minecraftZip.close();
tmpZip.flush();
tmpZip.close();
File tmp = new File("temp//tmp.jar");
tmp.renameTo(new File("temp//minecraft.jar"));
File minecraft = new File(mcDir + "\\bin\\minecraft.jar");
minecraft.delete();
FileUtils.copyFile(new File("temp\\minecraft.jar"), minecraft);
tmp.delete();
Any links or examples are welcome
- Liam, Hachi Software CEO