Fixed that crash

This commit is contained in:
Aidan C. Brady 2014-01-11 22:19:51 -05:00
parent 873363f372
commit 282c6fc07a
4 changed files with 160 additions and 85 deletions

View file

@ -304,11 +304,6 @@ public class ClientProxy extends CommonProxy
{ {
TileEntity tileEntity = world.getBlockTileEntity(x, y, z); TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if(tileEntity == null)
{
return null;
}
switch(ID) switch(ID)
{ {
case 0: case 0:

View file

@ -1,15 +1,23 @@
package mekanism.client; package mekanism.client;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import mekanism.api.EnumColor;
import mekanism.client.gui.GuiCredits;
import mekanism.common.IModule;
import mekanism.common.Mekanism;
import mekanism.common.Version;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import mekanism.client.gui.GuiCredits;
import mekanism.common.Mekanism;
/** /**
* Thread that downloads the latest release of Mekanism. The older file is deleted and the newly downloaded file takes it's place. * Thread that downloads the latest release of Mekanism. The older file is deleted and the newly downloaded file takes it's place.
@ -22,34 +30,35 @@ public class ThreadClientUpdate extends Thread
private int bytesDownloaded; private int bytesDownloaded;
private int lastBytesDownloaded; private int lastBytesDownloaded;
private byte[] buffer = new byte[10240]; private byte[] buffer = new byte[10240];
private URL url;
public String moduleName;
public static int modulesBeingDownloaded; private static File modsDir = new File(Mekanism.proxy.getMinecraftDir(), "mods");
private static File tempDir = new File(modsDir, "temp");
private static URL zipUrl = createURL();
public static boolean hasUpdated; public static boolean hasUpdated;
public ThreadClientUpdate(String location, String name) public ThreadClientUpdate()
{ {
moduleName = name; setDaemon(false);
modulesBeingDownloaded++; start();
try {
url = new URL(location);
setDaemon(false);
start();
} catch (MalformedURLException e) {
e.printStackTrace();
}
} }
@Override @Override
public void run() public void run()
{ {
File download = new File(new StringBuilder().append(Mekanism.proxy.getMinecraftDir()).append(File.separator + "mods" + File.separator + "Mekanism" + moduleName + "-v" + Mekanism.latestVersionNumber + ".jar").toString());
try { try {
deleteTemp();
createTemp();
File download = new File(tempDir, "builds.zip");
prepareForDownload(); prepareForDownload();
download.createNewFile(); download.createNewFile();
GuiCredits.updateInfo("Downloading...");
FileOutputStream outputStream = new FileOutputStream(download.getAbsolutePath()); FileOutputStream outputStream = new FileOutputStream(download.getAbsolutePath());
InputStream stream = url.openStream(); InputStream stream = zipUrl.openStream();
while((lastBytesDownloaded = stream.read(buffer)) > 0) while((lastBytesDownloaded = stream.read(buffer)) > 0)
{ {
@ -61,34 +70,143 @@ public class ThreadClientUpdate extends Thread
outputStream.close(); outputStream.close();
stream.close(); stream.close();
modulesBeingDownloaded--; if(Mekanism.versionNumber.comparedState(Version.get(Mekanism.latestVersionNumber)) != 0)
{
ZipInputStream zip = new ZipInputStream(new FileInputStream(download));
deployEntry(zip, "Mekanism-");
zip.close();
}
for(IModule module : Mekanism.modulesLoaded)
{
if(module.getVersion().comparedState(Version.get(Mekanism.latestVersionNumber)) != 0)
{
ZipInputStream zip = new ZipInputStream(new FileInputStream(download));
deployEntry(zip, "Mekanism" + module.getName());
zip.close();
}
}
deleteTemp();
hasUpdated = true;
GuiCredits.updateInfo("Update installed, reboot Minecraft for changes.");
System.out.println("[Mekanism] Successfully updated to latest version (" + Mekanism.latestVersionNumber + ").");
finalize(); finalize();
} catch(Throwable t) { } catch(Throwable t) {
GuiCredits.onErrorDownloading(); GuiCredits.updateInfo(EnumColor.DARK_RED + "Error updating.");
hasUpdated = true;
System.err.println("[Mekanism] Error while finishing update thread: " + t.getMessage()); System.err.println("[Mekanism] Error while finishing update thread: " + t.getMessage());
t.printStackTrace();
try {
modulesBeingDownloaded--;
finalize();
} catch (Throwable t1) {}
} }
} }
/** private void deployEntry(ZipInputStream zip, String filePrefix) throws IOException
* Prepares to update to the latest version of Mekanism by removing the old files. {
*/ byte[] zipBuffer = new byte[1024];
public void prepareForDownload() ZipEntry entry = zip.getNextEntry();
while(entry != null)
{
if(entry.isDirectory())
{
continue;
}
if(entry.getName().contains(filePrefix))
{
File modFile = new File(modsDir, entry.getName().replace("output/", ""));
if(modFile.exists())
{
modFile.delete();
}
modFile.createNewFile();
FileOutputStream outStream = new FileOutputStream(modFile);
int len;
while((len = zip.read(zipBuffer)) > 0)
{
outStream.write(zipBuffer, 0, len);
}
zip.closeEntry();
outStream.close();
break;
}
entry = zip.getNextEntry();
}
}
private void createTemp() throws IOException
{
if(!tempDir.exists())
{
tempDir.mkdir();
}
}
private void deleteTemp() throws IOException
{
if(tempDir.exists())
{
clearFiles(tempDir);
}
}
private void clearFiles(File file)
{
if(file.isDirectory())
{
for(File sub : file.listFiles())
{
clearFiles(sub);
}
}
file.delete();
}
private void prepareForDownload()
{ {
File[] modsList = new File(new StringBuilder().append(Mekanism.proxy.getMinecraftDir()).append(File.separator + "mods").toString()).listFiles(); File[] modsList = new File(new StringBuilder().append(Mekanism.proxy.getMinecraftDir()).append(File.separator + "mods").toString()).listFiles();
for(File file : modsList) if(Mekanism.versionNumber.comparedState(Version.get(Mekanism.latestVersionNumber)) == -1)
{ {
if(file.getName().startsWith("Mekanism" + moduleName) && file.getName().endsWith(".jar") && !file.getName().contains(Mekanism.latestVersionNumber)) for(File file : modsList)
{ {
file.delete(); if(file.getName().startsWith("Mekanism-") && file.getName().endsWith(".jar") && !file.getName().contains(Mekanism.latestVersionNumber))
{
file.delete();
}
}
}
for(IModule module : Mekanism.modulesLoaded)
{
for(File file : modsList)
{
if(file.getName().startsWith("Mekanism" + module.getName()) && file.getName().endsWith(".jar") && !file.getName().contains(Mekanism.latestVersionNumber))
{
file.delete();
}
} }
} }
System.out.println("[Mekanism] Preparing to update..."); System.out.println("[Mekanism] Preparing to update...");
} }
private static URL createURL()
{
try {
return new URL("http://ci.aidancbrady.com/job/Mekanism/Recommended/artifact/*zip*/archive.zip");
} catch(Exception e) {}
return null;
}
} }

View file

@ -15,8 +15,6 @@ import cpw.mods.fml.relauncher.SideOnly;
public class GuiCredits extends GuiScreen public class GuiCredits extends GuiScreen
{ {
private static String updateProgress = ""; private static String updateProgress = "";
private boolean updatedRecently;
private boolean notified = false;
@Override @Override
public void initGui() public void initGui()
@ -24,54 +22,31 @@ public class GuiCredits extends GuiScreen
buttonList.clear(); buttonList.clear();
buttonList.add(new GuiButton(0, width / 2 - 100, height / 4 + 72 + 12, "Update")); buttonList.add(new GuiButton(0, width / 2 - 100, height / 4 + 72 + 12, "Update"));
buttonList.add(new GuiButton(1, width / 2 - 100, height / 4 + 96 + 12, "Cancel")); buttonList.add(new GuiButton(1, width / 2 - 100, height / 4 + 96 + 12, "Cancel"));
((GuiButton)buttonList.get(0)).enabled = !MekanismUtils.noUpdates() && !ThreadClientUpdate.hasUpdated; ((GuiButton)buttonList.get(0)).enabled = /*!MekanismUtils.noUpdates() &&*/ !ThreadClientUpdate.hasUpdated;
} }
public static void onFinishedDownloading() public static void updateInfo(String info)
{ {
updateProgress = "Successfully updated. Restart Minecraft to load."; updateProgress = info;
System.out.println("[Mekanism] Successfully updated to latest version (" + Mekanism.latestVersionNumber + ").");
ThreadClientUpdate.hasUpdated = true;
}
public static void onErrorDownloading()
{
updateProgress = EnumColor.DARK_RED + "Error updating.";
} }
@Override @Override
protected void actionPerformed(GuiButton guibutton) protected void actionPerformed(GuiButton guibutton)
{ {
if(!guibutton.enabled)
{
return;
}
if(guibutton.id == 0) if(guibutton.id == 0)
{ {
if(!MekanismUtils.noUpdates()) if(true)//!MekanismUtils.noUpdates())
{ {
updatedRecently = true; updateProgress = "Preparing to update...";
updateProgress = "Downloading latest version...";
guibutton.enabled = false; guibutton.enabled = false;
if(Mekanism.versionNumber.comparedState(Version.get(Mekanism.latestVersionNumber)) == -1) new ThreadClientUpdate();
{
new ThreadClientUpdate("http://dl.dropbox.com/u/90411166/Mekanism-v" + Mekanism.latestVersionNumber + ".jar", "");
}
for(IModule module : Mekanism.modulesLoaded)
{
if(module.getVersion().comparedState(Version.get(Mekanism.latestVersionNumber)) == -1)
{
new ThreadClientUpdate("http://dl.dropbox.com/u/90411166/Mekanism" + module.getName() + "-v" + Mekanism.latestVersionNumber + ".jar", module.getName());
}
}
} }
else { else {
updateProgress = "You already have the latest version."; updateProgress = "You already have the latest version.";
} }
} }
if(guibutton.id == 1) else if(guibutton.id == 1)
{ {
mc.displayGuiScreen(null); mc.displayGuiScreen(null);
} }
@ -91,19 +66,6 @@ public class GuiCredits extends GuiScreen
@Override @Override
public void drawScreen(int mouseX, int mouseY, float partialTick) public void drawScreen(int mouseX, int mouseY, float partialTick)
{ {
if(updatedRecently && ThreadClientUpdate.modulesBeingDownloaded == 0 && !updateProgress.contains("Error"))
{
if(!notified)
{
onFinishedDownloading();
notified = true;
}
}
else if(ThreadClientUpdate.hasUpdated && !notified)
{
updateProgress = "You have already downloaded the update. Restart MC!";
}
drawDefaultBackground(); drawDefaultBackground();
drawCenteredString(fontRenderer, EnumColor.DARK_BLUE + "Mekanism" + EnumColor.GREY + " by aidancbrady", width / 2, (height / 4 - 60) + 20, 0xffffff); drawCenteredString(fontRenderer, EnumColor.DARK_BLUE + "Mekanism" + EnumColor.GREY + " by aidancbrady", width / 2, (height / 4 - 60) + 20, 0xffffff);

View file

@ -442,14 +442,14 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
if(nowPowered != redstonePowered) if(nowPowered != redstonePowered)
{ {
redstonePowered = nowPowered;
if(nowPowered) if(nowPowered)
{ {
onRedstoneSplit(); onRedstoneSplit();
} }
tile().notifyPartChange(this); tile().notifyPartChange(this);
redstonePowered = nowPowered;
} }
} }