Originally Posted by
Supertje
no you just need one, can u drop the full code of the cache loader/downloader?
yes sure, here:
Code:
package com.client.update;
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.BufferedReader;
import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URLConnection;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import com.client.Client;
import com.client.config.Configuration;
import com.client.sign.Signlink;
public class CacheDownloader {
private Client client;
private final int BUFFER = 8192;
private String CACHE_LINK = Configuration.CACHELINK;
private String BETA_CACHE_LINK = "http://beta.valius.net/cache.zip";
private static String VERSION_FILE_URL = "http://server.valius.net/cache/317/version.txt";
private static String BETA_VERSION_FILE_URL = "http://beta.valius.net/version.txt";
private Path FILE_LOCATION = Paths.get(getCacheDir(), getArchivedName());
public CacheDownloader(Client client) {
this.client = client;
}
private void drawLoadingText(String text) {
client.drawLoadingText(99, text);
System.out.println(text);
}
private void drawLoadingText(int amount, String text) {
client.drawLoadingText(amount, text);
}
private String getCacheDir() {
return Signlink.getCacheDirectory();
}
private String getCacheLink() {
return Configuration.betaClient ? BETA_CACHE_LINK : CACHE_LINK;
}
public CacheDownloader downloadCache() {
try {
double expectedVersion = this.getExpectedVersion();
double currentVersion = this.getExistingVersion();
if(expectedVersion > currentVersion) {
downloadFile(getCacheLink(), getArchivedName());
unZip();
writeVersion(expectedVersion);
}
} catch (Exception e) {
e.printStackTrace();
}
return this;
}
private void writeVersion(double version) throws IOException {
FileWriter fileWriter = new FileWriter(getCacheDir() + "/cacheVersion.dat");
fileWriter.write(String.valueOf(version));
fileWriter.close();
}
private double getExpectedVersion() {
try {
URL versionFile = new URL(Configuration.betaClient ? BETA_VERSION_FILE_URL : VERSION_FILE_URL);
BufferedReader in = new BufferedReader(new InputStreamReader(versionFile.openStream()));
String line = in.readLine();
in.close();
return Double.parseDouble(line);
} catch(Exception ex) {
ex.printStackTrace();
}
return 0.0;
}
private double getExistingVersion() {
try {
BufferedReader in = new BufferedReader(new FileReader(getCacheDir() + "/cacheVersion.dat"));
String line = in.readLine();
in.close();
return Double.parseDouble(line);
} catch(Exception ex) {
ex.printStackTrace();
}
return 0.0;
}
private void downloadFile(String adress, String localFileName) {
client.resetBackgroundImages();
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 fileSize = conn.getContentLength();
while ((numRead = in.read(data)) != -1) {
out.write(data, 0, numRead);
numWritten += numRead;
int percentage = (int) (((double) numWritten / (double) fileSize) * 100D);
drawLoadingText((int)percentage, "Valius - Downloading Cache " + percentage + "%");
}
System.out.println(localFileName + "\t" + numWritten);
drawLoadingText("Valius - Unzipping...");
} catch (Exception exception) {
exception.printStackTrace();
} finally {
try {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
private String getArchivedName() {
int lastSlashIndex = getCacheLink().lastIndexOf('/');
if (lastSlashIndex >= 0 && lastSlashIndex < getCacheLink().length() - 1) {
String u = getCacheLink().substring(lastSlashIndex + 1);
String Name = u.replace("?dl=1", "");
return Name;
} else {
System.err.println("error retrieving archived name.");
}
return "";
}
private void unZip() throws IOException {
InputStream in = new BufferedInputStream(new FileInputStream(FILE_LOCATION.toString()));
ZipInputStream zin = new ZipInputStream(in);
ZipEntry e;
while ((e = zin.getNextEntry()) != null) {
String fileName = e.getName();
File newFile = new File(getCacheDir() + File.separator + fileName);
if (e.isDirectory()) {
newFile.mkdirs();
} else {
newFile.getParentFile().mkdirs();
if(newFile.exists())
newFile.delete();
unzip(zin, getCacheDir() + e.getName());
}
System.out.println("unzipping2 " + e.getName());
}
zin.close();
Files.deleteIfExists(FILE_LOCATION);
}
private 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();
}
}
and configuration.java
Code:
package com.client.config;
import com.jcabi.manifests.Manifests;
public class Configuration {
public static boolean betaClient;
public static void checkMode() {
try {
String modeString = Manifests.read("Mode");
if(modeString.equalsIgnoreCase("beta")) {
betaClient = true;
LIVE_SERVER = false;
IP = "beta.valius.net";
}
} catch(Exception ex) {
}
}
public static boolean newFonts = false;
/**
* Attack option priorities 0 -> Depends on combat level 1 -> Always right-click
* 2 -> Left-click where available 3 -> Hidden
*/
public static int playerAttackOptionPriority = 0;
public static int npcAttackOptionPriority = 2;
public static boolean debug = false;
public static final boolean DUMP_SPRITES = false;
public static int xpSize = 0;
public static int xpSpeed = 0;
public static int xpDuration = 0;
public static int xpColour = 0;
public static int xpGroup = 0;
public static boolean renderLoginScene = true;
public static final int LOGIN_SCREEN_WORLD_X = 3050;
public static final int LOGIN_SCREEN_WORLD_Y = 9950;
public static boolean enableSmoothShading = true;
public static boolean enableTileBlending = true;
public static boolean enableAntiAliasing = false;
public static boolean enableFogRendering = false;
public static boolean enableRainbowFog = false;
public static boolean bountyHunter = true;
public static boolean playerNames = false;
public static boolean staffIcons = true;
public static int chatColor = 0;
public static int fogColor = 0xDCDBDF;
public static long fogDelay = 500;
public static final String CLIENT_TITLE = "Valius | Your #1 Custom OSRS Experience";
public static final String SHORT_CLIENT_TITLE = "Valius";
public static final int CLIENT_VERSION = 5;
public static Boolean LIVE_SERVER = false;
public static String IP = "192.99.145.49";
public static final int PORT = 43594;
public static final boolean THREADED_RENDERING = false;
public static Boolean DUMP_DATA = false;
public static int dumpID = 149;
public static Boolean DUMP_OTHER = false;
public static Boolean DUMP_ITEM_LIST = false;
public static Boolean DUMP_NPC_DATA = false;
public static final boolean DUMP_ITEM_DATA = false;
//The one in libs is unobfuscated, the one in deploy is obfuscated alright so i just run the jar in gradle tasks (do i have to clean it each time before?) No need to clean every time but if you run into any issues, try leaning and jarring alright awesome , thanks man :)
/**
* Used to repack indexes Index 1 = Models Index 2 = Animations Index 3 =
* Sounds/Music Index 4 = Maps You can only do up to 300 files at a time
*/
public static boolean repackIndexOne = false,
repackIndexTwo = false,
repackIndexThree = false,
repackIndexFour = false,
repackIndexFive = false;
public static final String CACHE_NAME = "ValiusCache1";
public static final String CACHELINK = "http://www.dropbox.com/s/srcy32cr8g8n13e/cache.zip"; // cache link
public static int CACHE_VERSION_LOADER = 1;
/*
* Discord Rich Presence Settings
*/
/**
* Seasonal Events
*/
public static boolean HALLOWEEN = false;
public static boolean CHRISTMAS = false;
public static boolean CHRISTMAS_EVENT = false;
public static boolean EASTER = false;
public static boolean osbuddyGameframe = false;
public static boolean oldGameframe = false;
public static int gameWorld = 1;
public static int xpPosition;
public static boolean escapeCloseInterface = false;
public static boolean inventoryContextMenu = true;
public static int statMenuColor = 0xBABABA;
public static boolean alwaysLeftClickAttack;
public static boolean hideCombatOverlay;
public static boolean displayEntityOverlaySpriteText = true;
public static boolean displayObjectOverlaySpriteText = true;
public static boolean enableTweening = true;
public static boolean hidePetOptions = false;
}