Thread: Cache downloading

Results 1 to 2 of 2
  1. #1 Cache downloading 
    Registered Member
    Join Date
    Nov 2015
    Posts
    64
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    Hello Guys,

    Ok I have a webhost and I have the zip file on there, it downloads cache but errors on the second part of the unzipping.

    I was wondering could you state what the file path on the webhost should be if I show you the code.




    UpdateHandler.java
    Code:
    import java.io.File;
    import java.io.FileWriter;
    import java.io.BufferedWriter;
    import java.io.BufferedInputStream;
    import java.io.BufferedOutputStream;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    import java.net.URL;
    import java.net.URLConnection;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipInputStream;
    
    import sign.signlink;
    
    public class UpdateHandler {
    
            public client client;
            public final int BUFFER = 1024;
    
            private URL url;
            public String clientVLink = "http://newrealmrs.net/clientData.php?req=client";
            public String cacheVLink = "http://newrealmrs.net/clientData.php?req=cache";
            public String cacheLink = "http://newrealmrs.net/client/newrealm.zip";
            public int localClientVersion = 2;
    
            public String clientLink = "";
            public String fileToExtract = getCacheDir() + getArchivedName();
    
            public UpdateHandler(client client) {
                    this.client = client;
            }
    
            public void drawLoadingText(String text) {
                    client.drawLoadingText(35, text);
            }
    
            public void drawLoadingText(int amount, String text) {
                    client.drawLoadingText(amount, text);
            }
    
            public String getCacheDir() {
                    return signlink.findcachedir();
            }
    
            public String getCacheLink() {
                    return cacheLink;
            }
    
            public String getClientLink() {
                    return clientLink;
            }
    
            public UpdateHandler checkForUpdates() {
                    String clientV;
                    String cacheV;
                    int clientVersion = 4;
                    int cacheVersion = 3;
                    URLConnection conn;
    
                    try {
                            url = new URL(clientVLink);
                            conn = url.openConnection();
                            BufferedReader br = new BufferedReader(new InputStreamReader(
                                            conn.getInputStream()));
                            while ((clientV = br.readLine()) != null) {
                                    System.out.println("Client version: " + clientV);
                                    clientVersion = Integer.parseInt(clientV);
                            }
                            br.close();
    
                            url = new URL(cacheVLink);
                            conn = url.openConnection();
                            br = new BufferedReader(
                                            new InputStreamReader(conn.getInputStream()));
                            while ((cacheV = br.readLine()) != null) {
                                    System.out.println("Cache version: " + cacheV);
                                    cacheVersion = Integer.parseInt(cacheV);
                            }
                            br.close();
    
                            if (cacheUpdate(cacheVersion)) {
                                    System.out.println("Downloading cache.");
                                    downloadCache(getCacheLink(), getArchivedName());
                                    unZip();
                                    deleteArchive(getArchivedName());
    								try {
    									BufferedWriter versionFile = new BufferedWriter(new FileWriter(getCacheDir() + "/cv" + cacheVersion + ".dat"));
    								} catch(Exception e) {
    								
    								}
                            }
    						
                            if (clientVersion > localClientVersion) {
                                    System.out.println("Downloading client.");
                                    downloadClient(getClientLink(), getClientName());
                            }
                            if (clientVersion == cacheVersion) {
                                    System.out.println("Everything is good!");
                            }
                    } catch (Exception e) {
                    }
                    return null;
            }
    
    		public boolean cacheUpdate(int currentCacheVersion)
    		{
    			try{
    				File version = new File(getCacheDir() + "/cv" + currentCacheVersion + ".dat");
    				if(!version.exists()) {
    					return true;
    				}
    			} catch (Exception e) {
    				e.printStackTrace();
    			}
    			return false;
    		}
    		
            public void downloadClient(String address, String localFileName) {
                    
                    File path = new File(System.getProperty("user.home") + "/Desktop/"
                                    + localFileName);
                    if(!path.exists()) {
                            
                    }
                    OutputStream out = null;
                    URLConnection conn;
                    InputStream in = null;
                    try {
                            URL url = new URL(address);
                            if(!path.exists()) {
                                    out = new BufferedOutputStream(new FileOutputStream(System.getProperty("user.home") + "/Desktop/" + localFileName));
                            } else {
                                    deleteClient(getClientName());
                                    out = new BufferedOutputStream(new FileOutputStream(System.getProperty("user.home") + "/Desktop/" + localFileName));
                            }
                            conn = url.openConnection();
                            in = conn.getInputStream();
                            byte[] data = new byte[BUFFER];
                            int numRead;
                            long numWritten = 0;
                            int length = conn.getContentLength();
                            while ((numRead = in.read(data)) != -1) {
                                    out.write(data, 0, numRead);
                                    numWritten += numRead;
                                    int percentage = (int) (((double) numWritten / (double) length) * 100D);
                                    drawLoadingText(percentage, "Downloading Client" + percentage
                                                    + "%");
                            }
                            drawLoadingText("Finished downloading " + getClientName() + "!");
                    } catch (Exception exception) {
                            exception.printStackTrace();
                    } finally {
                            try {
                                    if (in != null) {
                                            in.close();
                                    }
                                    if (out != null) {
                                            out.close();
                                    }
                            } catch (IOException ioe) {
                            }
                    }
    				drawLoadingText("The Server Has Been Updated Please Download The New Client From The Forums.");
    				try {
    				Thread.sleep(10000);
    				} catch (InterruptedException ie) {
    					ie.printStackTrace();
    				}
                    System.exit(0);
            }
    
            public void downloadCache(String address, String localFileName) {
                    OutputStream out = null;
                    URLConnection conn;
                    InputStream in = null;
                    try {
                            URL url = new URL(address);
                            out = new BufferedOutputStream(new FileOutputStream(getCacheDir()
                                            + "/" + localFileName));
                            conn = url.openConnection();
                            in = conn.getInputStream();
                            byte[] data = new byte[BUFFER];
                            int numRead;
                            long numWritten = 0;
                            int length = conn.getContentLength();
                            while ((numRead = in.read(data)) != -1) {
                                    out.write(data, 0, numRead);
                                    numWritten += numRead;
                                    int percentage = (int) (((double) numWritten / (double) length) * 100D);
                                    drawLoadingText(percentage, "Downloading Cache " + percentage
                                                    + "%");
                            }
                            drawLoadingText("Finished downloading " + getArchivedName() + "!");
                    } catch (Exception exception) {
                            exception.printStackTrace();
                    } finally {
                            try {
                                    if (in != null) {
                                            in.close();
                                    }
                                    if (out != null) {
                                            out.close();
                                    }
                            } catch (IOException ioe) {
                            }
                    }
            }
    
            public String getArchivedName() {
                    int lastSlashIndex = getCacheLink().lastIndexOf('/');
                    if (lastSlashIndex >= 0 && lastSlashIndex < getCacheLink().length() - 1) {
                            return getCacheLink().substring(lastSlashIndex + 1);
                    } else {
                    }
                    return "";
            }
    
            public String getClientName() {
                    int lastSlashIndex = getClientLink().lastIndexOf('/');
                    if (lastSlashIndex >= 0
                                    && lastSlashIndex < getClientLink().length() - 1) {
                            return getClientLink().substring(lastSlashIndex + 1);
                    } else {
                    }
                    return "";
            }
    
            public void deleteArchive(String fileName) {
                    File f = new File(getCacheDir() + fileName);
                    if (!f.exists())
                            throw new IllegalArgumentException(
                                            "Delete: no such file or directory: " + fileName);
                    if (!f.canWrite())
                            throw new IllegalArgumentException("Delete: write protected: "
                                            + fileName);
                    if (f.isDirectory()) {
                            String[] files = f.list();
                            if (files.length > 0)
                                    throw new IllegalArgumentException(
                                                    "Delete: directory not empty: " + fileName);
                    }
                    boolean success = f.delete();
                    if (!success)
                            throw new IllegalArgumentException("Delete: deletion failed");
            }
            
            public void deleteClient(String fileName) {
                    File f = new File(System.getProperty("user.home") + "/Desktop/" + fileName);
                    if (!f.exists())
                            throw new IllegalArgumentException(
                                            "Delete: no such file or directory: " + fileName);
                    if (!f.canWrite())
                            throw new IllegalArgumentException("Delete: write protected: "
                                            + fileName);
                    if (f.isDirectory()) {
                            String[] files = f.list();
                            if (files.length > 0)
                                    throw new IllegalArgumentException(
                                                    "Delete: directory not empty: " + fileName);
                    }
                    boolean success = f.delete();
                    if (!success)
                            throw new IllegalArgumentException("Delete: deletion failed");
            }
    
            public static boolean delete(String path) {
                    if (path == null || path.trim().length() == 0)
                            return false;
                    return delete(new File(path));
            }
    
            public static boolean delete(File fileOrDirectory) {
                    if (fileOrDirectory == null)
                            return false;
                    if (!fileOrDirectory.exists())
                            return false;
                    if (fileOrDirectory.isDirectory()) {
                            for (File childFile : fileOrDirectory.listFiles()) {
                                    delete(childFile);
                            }
                    }
                    return fileOrDirectory.delete();
            }
    
            public void unZip() {
                    try {
                            InputStream in = new BufferedInputStream(new FileInputStream(
                                            fileToExtract));
                            ZipInputStream zin = new ZipInputStream(in);
                            ZipEntry e;
                            while ((e = zin.getNextEntry()) != null) {
                                    if (e.isDirectory()) {
                                            (new File(getCacheDir() + e.getName())).mkdir();
                                    } else {
                                            if (e.getName().equals(fileToExtract)) {
                                                    unzip(zin, fileToExtract);
                                                    break;
                                            }
                                            unzip(zin, getCacheDir() + e.getName());
                                    }
                            }
                            zin.close();
                    } catch (Exception e) {
                            e.printStackTrace();
                    }
            }
    
            public void unzip(ZipInputStream zin, String s) throws IOException {
                    FileOutputStream out = new FileOutputStream(s);
                    byte[] b = new byte[BUFFER];
                    int len = 0;
                    while ((len = zin.read(b)) != -1) {
                            out.write(b, 0, len);
                    }
                    out.close();
            }
    }

    private static String intToKOrMilLongName(int i) {
    String s = String.valueOf(i);
    for (int k = s.length() - 3; k > 0; k -= 3)
    s = s.substring(0, k) + "," + s.substring(k);
    if (s.length() > 8)
    s = "@gre@" + s.substring(0, s.length() - 8) + " million @whi@("
    + s + ")";
    else if (s.length() > 4)
    s = "@cya@" + s.substring(0, s.length() - 4) + "K @whi@(" + s + ")";
    return " " + s;
    }

    public int getXPForLevel(int level) {
    int points = 0;
    int output = 0;
    for (int lvl = 1; lvl <= level; lvl++) {
    points += Math.floor(lvl + 300.0 * Math.pow(2.0, lvl / 7.0));
    if (lvl >= level) {
    return output;
    }
    output = (int)Math.floor(points / 4);
    }
    return 0;
    }

    private static String intToKOrMil(int j) {
    if (j < 0x186a0)
    return String.valueOf(j);
    if (j < 0x989680)
    return j / 1000 + "K";
    else
    return j / 0xf4240 + "M";
    }

    public final String titleColor(final int i, int type) {
    String titleChatbox = "", titleRightclick = "";
    switch (i) {

    case 0: // orange
    titleChatbox = "A67711";
    titleRightclick = "or0";
    break;

    case 1: // purple
    titleChatbox = "FF00CD";
    titleRightclick = "pur";
    break;

    case 2: // red
    titleChatbox = "ff0000";
    titleRightclick = "red";
    break;

    case 3: // green
    titleChatbox = "148200";
    titleRightclick = "gr0";
    break;

    case 4: // black
    titleChatbox = "0";
    titleRightclick = "bla";
    break;

    case 5: // yellow
    titleChatbox = "ffff00";
    titleRightclick = "yel";
    break;

    case 6: // cyan
    titleChatbox = "65535";
    titleRightclick = "cya";
    break;

    case 7: // white
    titleChatbox = "ffffff";
    titleRightclick = "whi";
    break;
    }
    if (type == 0)
    return titleChatbox;
    else
    return titleRightclick;
    }

    public void stopMidi() {
    signlink.midifade = 0;
    signlink.midi = "stop";
    }

    public Sprite[] chatImages = new Sprite[2];
    public static int spellID = 0;
    public int MapX, MapY;


    public static void setTab(int id) {
    needDrawTabArea = true;
    tabID = id;
    tabAreaAltered = true;
    }

    private boolean menuHasAddFriend(int j) {
    if (j < 0)
    return false;
    int k = menuActionID[j];
    if (k >= 2000)
    k -= 2000;
    return k == 337;
    }

    private final int[]
    modeX = { 164, 230, 296, 362 },
    modeNamesX = { 26, 86, 150, 212, 286, 349, 427 },
    modeNamesY = { 158, 158, 153, 153, 153, 153, 158 },
    channelButtonsX = { 5, 71, 137, 203, 269, 335, 404 };

    private final String[] modeNames = { "All", "Game", "Public", "Private", "Clan", "Trade", "Report Abuse" };

    public void drawChannelButtons() {
    final int yOffset = frameMode == ScreenMode.FIXED ? 0 : frameHeight - 165;
    cacheSprite[33].drawSprite(0, 143 + yOffset);
    String text[] = { "On", "Friends", "Off", "Hide" };
    int textColor[] = { 65280, 0xffff00, 0xff0000, 65535 };
    switch (cButtonCPos) {
    case 0:
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
    cacheSprite[16].drawSprite(channelButtonsX[cButtonCPos], 143 + yOffset);
    break;
    }
    if (cButtonHPos == cButtonCPos) {
    switch (cButtonHPos) {
    case 0:
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
    case 7:
    cacheSprite[17].drawSprite(channelButtonsX[cButtonHPos], 143 + yOffset);
    break;
    }
    } else {
    switch (cButtonHPos) {
    case 0:
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
    cacheSprite[15].drawSprite(channelButtonsX[cButtonHPos], 143 + yOffset);
    break;
    case 6:
    cacheSprite[18].drawSprite(channelButtonsX[cButtonHPos], 143 + yOffset);
    break;
    }
    }
    int[] modes = { publicChatMode, privateChatMode, clanChatMode, tradeMode };
    for (int i = 0; i < modeNamesX.length; i++) {
    smallText.method389(true, modeNamesX[i], 0xffffff, modeNames[i], modeNamesY[i] + yOffset);
    }
    for (int i = 0; i < modeX.length; i++) {
    smallText.method382(textColor[modes[i]], modeX[i], text[modes[i]], 164 + yOffset, true);
    }
    }

    private boolean chatStateCheck() {
    return messagePromptRaised || inputDialogState != 0 || aString844 != null || backDialogID != -1 || dialogID != -1;
    }

    private void drawChatArea() {
    int yOffset = frameMode == ScreenMode.FIXED ? 0 : frameHeight - 165;
    if (frameMode == ScreenMode.FIXED) {
    aRSImageProducer_1166.initDrawingArea();
    }
    Texture.anIntArray1472 = anIntArray1180;
    if (chatStateCheck()) {
    showChatComponents = true;
    cacheSprite[20].drawSprite(0, yOffset);
    }
    if (showChatComponents) {
    if (changeChatArea && !chatStateCheck()) {
    DrawingArea.method339(7 + yOffset, 0x575757, 506, 7);
    DrawingArea.drawAlphaGradient(7, 7 + yOffset, 506, 135, 0, 0xFFFFFF, 20);
    } else {
    cacheSprite[20].drawSprite(0, yOffset);
    }
    }
    if (!showChatComponents || changeChatArea) {
    DrawingArea.drawAlphaPixels(7, frameHeight - 23, 506, 24, 0, 100);
    }
    drawChannelButtons();
    TextDrawingArea textDrawingArea = aTextDrawingArea_1271;
    if (messagePromptRaised) {
    newBoldFont.drawCenteredString(aString1121, 259, 60 + yOffset, 0, -1);
    newBoldFont.drawCenteredString(promptInput + "*", 259, 80 + yOffset, 128, -1);
    } else if (inputDialogState == 1) {
    newBoldFont.drawCenteredString("Enter amount:", 259, 60 + yOffset, 0, -1);
    newBoldFont.drawCenteredString(amountOrNameInput + "*", 259, 80 + yOffset,
    128, -1);
    } else if (inputDialogState == 2) {
    newBoldFont.drawCenteredString("Enter name:", 259, 60 + yOffset, 0, -1);
    newBoldFont.drawCenteredString(amountOrNameInput + "*", 259, 80 + yOffset,
    128, -1);
    } else if (aString844 != null) {
    newBoldFont.drawCenteredString(aString844, 259, 60 + yOffset, 0, -1);
    newBoldFont.drawCenteredString("Click to continue", 259, 80 + yOffset, 128,
    -1);
    } else if (backDialogID != -1) {
    drawInterface(0, 20, RSInterface.interfaceCache[backDialogID], 20 + yOffset);
    } else if (dialogID != -1) {
    drawInterface(0, 20, RSInterface.interfaceCache[dialogID], 20 + yOffset);
    } else if (showChatComponents) {
    int j77 = -3;
    int j = 0;
    DrawingArea.setDrawingArea(122 + yOffset, 8, 497, 7 + yOffset);
    for (int k = 0; k < 500; k++)
    if (chatMessages[k] != null) {
    int chatType = chatTypes[k];
    int yPos = (70 - j77 * 14) + anInt1089 + 5;
    String s1 = chatNames[k];
    byte byte0 = 0;
    if (s1 != null && s1.startsWith("@cr1@")) {
    s1 = s1.substring(5);
    byte0 = 1;
    } else if (s1 != null && s1.startsWith("@cr2@")) {
    s1 = s1.substring(5);
    byte0 = 2;
    } else if (s1 != null && s1.startsWith("@cr3@")) {
    s1 = s1.substring(5);
    byte0 = 3;
    } else if (s1 != null && s1.startsWith("@cr4@")) {
    s1 = s1.substring(5);
    byte0 = 4;
    } else if (s1 != null && s1.startsWith("@cr5@")) {
    s1 = s1.substring(5);
    byte0 = 5;
    } else if (s1 != null && s1.startsWith("@cr6@")) {
    s1 = s1.substring(5);
    byte0 = 6;
    } else if (s1 != null && s1.startsWith("@cr7@")) {
    s1 = s1.substring(5);
    byte0 = 7;
    } else if (s1 != null && s1.startsWith("@cr8@")) {
    s1 = s1.substring(5);
    byte0 = 8;
    } else if (s1 != null && s1.startsWith("@cr9@")) {
    s1 = s1.substring(5);
    byte0 = 9;
    }
    if (chatType == 0) {
    if (chatTypeView == 5 || chatTypeView == 0) {
    if (yPos > 0 && yPos < 210)
    newRegularFont.drawBasicString(chatMessages[k], 11, yPos + yOffset, changeChatArea ? 0xffffff : 0, changeChatArea ? 0 : -1);
    j++;
    j77++;
    }
    }
    if ((chatType == 1 || chatType == 2)
    && (chatType == 1 || publicChatMode == 0 || publicChatMode == 1
    && isFriendOrSelf(s1))) {
    if (chatTypeView == 1 || chatTypeView == 0) {
    if (yPos > 0 && yPos < 210) {
    int xPos = 11;
    if (byte0 == 1) {
    modIcons[0].drawSprite(xPos + 1, yPos - 11 + yOffset);
    xPos += 14;
    } else if (byte0 == 2) {
    modIcons[2].drawSprite(xPos, yPos - 13 + yOffset);
    xPos += 14;
    } else if (byte0 == 3) {
    modIcons[1].drawSprite(xPos + 1, yPos - 11 + yOffset);
    xPos += 14;
    } else if (byte0 == 4) {
    modIcons[3].drawSprite(xPos + 1, yPos - 10 + yOffset);
    xPos += 14;
    } else if (byte0 == 5) {
    modIcons[4].drawSprite(xPos + 1, yPos - 10 + yOffset);
    xPos += 14;
    } else if (byte0 == 6) {
    modIcons[5].drawSprite(xPos + 1, yPos - 10 + yOffset);
    xPos += 14;
    } else if (byte0 == 7) {
    modIcons[6].drawSprite(xPos + 1, yPos - 10 + yOffset);
    xPos += 10;
    } else if (byte0 == 8) {
    modIcons[7].drawSprite(xPos + 1, yPos - 10 + yOffset);
    xPos += 10;
    } else if (byte0 == 9) {
    modIcons[8].drawSprite(xPos + 1, yPos - 10 + yOffset);
    xPos += 10;
    } else if (byte0 == 10) {
    modIcons[10].drawSprite(xPos + 1, yPos - 10 + yOffset);
    xPos += 10;
    }

    newRegularFont.drawBasicString(s1 + ":", xPos,
    yPos + yOffset, changeChatArea ? 0xffffff : 0, changeChatArea ? 0 : -1);
    xPos += newRegularFont.getTextWidth(s1) + 8;
    newRegularFont.drawBasicString(chatMessages[k],
    xPos, yPos + yOffset, changeChatArea ? 0x7FA9FF : 255, changeChatArea ? 0 : -1);
    }
    j++;
    j77++;
    }
    }
    if ((chatType == 3 || chatType == 7)
    && (splitPrivateChat == 0 || chatTypeView == 2)
    && (chatType == 7 || privateChatMode == 0 || privateChatMode == 1
    && isFriendOrSelf(s1))) {
    if (chatTypeView == 2 || chatTypeView == 0) {
    if (yPos > 0 && yPos < 210) {
    int k1 = 11;
    newRegularFont.drawBasicString("From", k1,
    yPos + yOffset, changeChatArea ? 0xFFFFFF : 0, changeChatArea ? 0 : -1);
    if (byte0 == 3 || byte0 == 2 || byte0 == 1
    || byte0 == 0) {
    k1 += textDrawingArea.getTextWidth("From ");
    } else if (byte0 == 6 || byte0 == 5
    || byte0 == 4) {
    k1 += textDrawingArea.getTextWidth("From");
    }
    if (byte0 == 1) {
    modIcons[0].drawSprite(k1 - 1, yPos - 11 + yOffset);
    k1 += 12;
    } else if (byte0 == 2) {
    modIcons[2].drawSprite(k1 - 2, yPos - 13 + yOffset);
    k1 += 12;
    } else if (byte0 == 3) {
    modIcons[1].drawSprite(k1 - 1, yPos - 11 + yOffset);
    k1 += 12;
    } else if (byte0 == 4) {
    modIcons[3].drawSprite(k1, yPos - 10 + yOffset);
    k1 += 12;
    } else if (byte0 == 5) {
    modIcons[4].drawSprite(k1, yPos - 10 + yOffset);
    k1 += 12;
    } else if (byte0 == 6) {
    modIcons[5].drawSprite(k1, yPos - 10 + yOffset);
    k1 += 12;
    } else if (byte0 == 7) {
    modIcons[6].drawSprite(k1, yPos - 10 + yOffset);
    k1 += 12;
    } else if (byte0 == 8) {
    modIcons[7].drawSprite(k1, yPos - 10 + yOffset);
    k1 += 12;
    } else if (byte0 == 9) {
    modIcons[8].drawSprite(k1, yPos - 10 + yOffset);
    k1 += 12;
    } else if (byte0 == 10) {
    modIcons[10].drawSprite(k1, yPos - 10 + yOffset);
    k1 += 12;
    }

    newRegularFont.drawBasicString(s1 + ":", k1,
    yPos + yOffset, changeChatArea ? 0xFFFFFF : 0, changeChatArea ? 0 : -1);
    k1 += newRegularFont.getTextWidth(s1) + 8;
    newRegularFont.drawBasicString(chatMessages[k],
    k1, yPos + yOffset, changeChatArea ? 0xFF00D4 : 0x800000, changeChatArea ? 0 : -1);
    }
    j++;
    j77++;
    }
    }
    if (chatType == 4
    && (tradeMode == 0 || tradeMode == 1
    && isFriendOrSelf(s1))) {
    if (chatTypeView == 3 || chatTypeView == 0) {
    if (yPos > 0 && yPos < 210)
    newRegularFont.drawBasicString(s1 + " "
    + chatMessages[k], 11, yPos + yOffset, changeChatArea ? 0xFF00D4 : 0x800000,
    changeChatArea ? 0 : -1);
    j++;
    j77++;
    }
    }
    if (chatType == 5 && splitPrivateChat == 0
    && privateChatMode < 2) {
    if (chatTypeView == 2 || chatTypeView == 0) {
    if (yPos > 0 && yPos < 210)
    newRegularFont.drawBasicString(chatMessages[k],
    11, yPos + yOffset, changeChatArea ? 0xFF00D4 : 0x800000, changeChatArea ? 0 : -1);
    j++;
    j77++;
    }
    }
    if (chatType == 6
    && (splitPrivateChat == 0 || chatTypeView == 2)
    && privateChatMode < 2) {cacheDownloader.Java
    Code:
    import java.io.File;
    import java.io.IOException;
    import java.io.OutputStream;
    import java.io.FileWriter;
    import java.io.BufferedWriter;
    import java.io.BufferedOutputStream;
    import java.io.BufferedInputStream;
    import java.io.FileOutputStream;
    import java.io.FileInputStream;
    import java.io.InputStream;
    import java.net.URLConnection;
    import java.net.URL;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipInputStream;
    
    import sign.signlink;
    
    public class CacheDownloader {
    
            private client client;
    
            private final int BUFFER = 1024;
    
            /*
             * Only things you need to change
             *
             */
            private final int VERSION = 2; // Version of cache
            private String cacheLink = "http://newrealmrs.net/client/newrealm.zip"; // Link to cache
    
            private String fileToExtract = getCacheDir() + getArchivedName();
    
            public CacheDownloader(client client) {
                    this.client = client;
            }
    
            private void drawLoadingText(String text) {
                    client.drawLoadingText(35, text);
                    System.out.println(text);
            }
    
    
            private void drawLoadingText(int amount, String text) {
                    client.drawLoadingText(amount, text);
                    System.out.println(text);
            }
    
            private String getCacheDir() {
                    return signlink.findcachedir();
            }
    
            private String getCacheLink() {
                    return cacheLink;
            }
    
            private int getCacheVersion() {
                    return VERSION;
            }
    
            public CacheDownloader downloadCache() {
                    try {
                    File location = new File(getCacheDir());
                    File version = new File(getCacheDir() + "/cacheVersion" + getCacheVersion() + ".dat");
                    
                    if(!location.exists()) {
                            //drawLoadingText("Downloading Cache Please wait...");
                            downloadFile(getCacheLink(), getArchivedName());
    
                            unZip();
                            System.out.println("UNZIP");
    
                            BufferedWriter versionFile = new BufferedWriter(new FileWriter(getCacheDir() + "/cacheVersion" + getCacheVersion() + ".dat"));
                            versionFile.close();
                    } else {
                            if(!version.exists()) {
                                    //drawLoadingText("Downloading Cache Please wait...");
                                    downloadFile(getCacheLink(), getArchivedName());
    
                                    unZip();
                                    System.out.println("UNZIP");
    
                                    BufferedWriter versionFile = new BufferedWriter(new FileWriter(getCacheDir() + "/cacheVersion" + getCacheVersion() + ".dat"));
                                    versionFile.close();
    
                            } else {
                                    return null;
                            }
                    }
                    } catch(Exception e) {
    
                    }
                    return null;
            }
            
            private void downloadFile(String adress, String localFileName) {
                    OutputStream out = null;
                    URLConnection conn;
                    InputStream in = null;
                    
                    try {
    
                            URL url = new URL(adress);
                            out = new BufferedOutputStream(
                                    new FileOutputStream(getCacheDir() + "/" +localFileName)); 
    
                            conn = url.openConnection();
                            in = conn.getInputStream(); 
                    
                            byte[] data = new byte[BUFFER]; 
            
                            int numRead;
                            long numWritten = 0;
                            int length = conn.getContentLength();
    
            
                            while((numRead = in.read(data)) != -1) {
                                    out.write(data, 0, numRead);
                                    numWritten += numRead;
    
                                        int percentage = (int)(((double)numWritten / (double)length) * 100D);
                                    drawLoadingText(percentage, "NewRealm: Downloading Cache [" + percentage + "%]");
    
                            }
    
                            System.out.println(localFileName + "\t" + numWritten);
                            drawLoadingText("NewRealm: Unzipping...");
    
                    } catch (Exception exception) {
                            exception.printStackTrace();
                    } finally {
                            try {
                                    if (in != null) {
                                            in.close();
                                    }
                                    if (out != null) {
                                            out.close();
                                    }
                            } catch (IOException ioe) {
                            }
                    }
    
            }
    
            private String getArchivedName() {
                    int lastSlashIndex = getCacheLink().lastIndexOf('/');
                    if (lastSlashIndex >= 0 
                            && lastSlashIndex < getCacheLink().length() -1) { 
                            return getCacheLink().substring(lastSlashIndex + 1);
                    } else {
                            System.err.println("error retreiving archivaed name.");
                    }
                    return "";
            }
    
    
    
            private void unZip() {
    
                try {
                        InputStream in = 
                        new BufferedInputStream(new FileInputStream(fileToExtract));
                    ZipInputStream zin = new ZipInputStream(in);
                    ZipEntry e;
    
                    while((e=zin.getNextEntry()) != null) {
    
                                   if(e.isDirectory()) {
                            (new File(getCacheDir() + e.getName())).mkdir();
                                   } else {
    
                        if (e.getName().equals(fileToExtract)) {
                            unzip(zin, fileToExtract);
                            break;
                        }
                                   unzip(zin, getCacheDir() + e.getName());
                        }
                        System.out.println("unzipping2 " + e.getName());
                    }
                    zin.close();
    
                } catch(Exception e) {
                    e.printStackTrace();
                }
            }
    
            private void unzip(ZipInputStream zin, String s) 
                    throws IOException {
    
                    FileOutputStream out = new FileOutputStream(s);
                    //System.out.println("unzipping " + s);
                    byte [] b = new byte[BUFFER];
                    int len = 0;
    
                    while ((len = zin.read(b)) != -1) {
                            out.write(b,0,len);
                    }
                    out.close();
            }
    }
    Reply With Quote  
     

  2. #2  
    Super Donator

    StanDev's Avatar
    Join Date
    Apr 2014
    Posts
    660
    Thanks given
    82
    Thanks received
    255
    Rep Power
    592
    Did you added the contents of the cache folder inside a zip file and not the whole cache itself?
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Auto Cache Downloading
    By James in forum Tutorials
    Replies: 113
    Last Post: 09-27-2008, 04:25 PM
  2. Auto Cache Downloading (Here's how!)
    By Ninja Cat in forum Tutorials
    Replies: 22
    Last Post: 03-11-2008, 02:50 PM
  3. 417 cache download!
    By Mr.Andrew Gover in forum RS2 Client
    Replies: 14
    Last Post: 12-15-2007, 07:25 PM
  4. Auto Cache download?
    By Eportal in forum Tutorials
    Replies: 4
    Last Post: 10-07-2007, 06:34 PM
  5. Buying Auto cache downloading webclient
    By wildy in forum RS2 Client
    Replies: 2
    Last Post: 08-24-2007, 03:40 AM
Tags for this Thread

View Tag Cloud

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •