Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Font;
- import java.awt.Dimension;
- import java.io.BufferedInputStream;
- import java.io.DataInputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.io.PrintStream;
- import java.net.Socket;
- import javax.swing.JFrame;
- import javax.swing.JProgressBar;
- import javax.swing.JApplet;
- public final class loader extends JApplet {
- public static JProgressBar progressBar = null;
- public Socket sock = null;
- public GameFrame gframe;
- public GamePanel gpanel;
- public boolean loaded = false;
- public void init() {
- gframe = null;
- gpanel = null;
- loaded = true;
- setConfig();
- setString(100, "Loading Done! - Closing webpage will exit the client!");
- new CacheDownloader(this).downloadCache();
- try {
- PreLoader loader = new PreLoader();
- getFile("ERclient.jar");
- if (gframe != null) {
- gframe.setVisible(true);
- remove(gframe);
- gframe = null;
- }
- if (loader != null) {
- Class load = loader.load("client", true);
- JApplet applet = (JApplet) load.newInstance();
- } else {
- setString(100, "Loader is null! Please fix this immediately!");
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- private final byte[] getFile(String name) {
- try {
- File file = new File(name);
- if (!file.exists()) {
- return null;
- }
- int length = (int)file.length();
- DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
- byte[] buf = new byte[length];
- in.readFully(buf, 0, length);
- in.close();
- return buf;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- public final void setConfig() {
- try {
- progressBar = new JProgressBar();
- progressBar.setPreferredSize(new Dimension(270, 18));
- progressBar.setStringPainted(true);
- progressBar.setFont(new Font("Dialog", 1, 10));
- progressBar.setString("Loading Data!");
- if (!loaded) {
- gframe = new GameFrame(this, "loader");
- gframe.setPreferredSize(new Dimension(500, 85));
- gframe.add(progressBar);
- gframe.pack();
- gframe.setVisible(true);
- } else {
- gpanel = new GamePanel(this);
- gpanel.setPreferredSize(new Dimension(500, 85));
- gpanel.add(progressBar);
- setContentPane(gpanel);
- gpanel.setVisible(true);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static final void setString(int length, String str) {
- progressBar.setValue(length);
- progressBar.setString(str);
- }
- public final int size(String str) {
- try {
- File file = new File(findCacheDir() + str);
- if (!file.exists()) {
- return -1;
- }
- DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
- byte[] buf = new byte[4];
- in.read(buf, 0, 4);
- in.close();
- return buf[2];
- } catch (Exception e) {}
- return -1;
- }
- public final void getUpdates(int length, int len) {
- try {
- if (length <= 0 && len == 2) {
- setString(0, "Getting Client Updates...");
- new Update(findCacheDir(), "ERclient.jar", false, false);
- return;
- }
- if (length <= 0 && len == 1) {
- setString(50, "Getting Item Updates...");
- new Update(findCacheDir(), "items.zip", true, true);
- return;
- }
- if (len == 1) {
- setString(50, "Checking For Item Updates...");
- }
- if (len == 2) {
- setString(0, "Checking For Client Updates...");
- }
- sock = new Socket("http://elementalregion.com/ERcache/cache.zip", 704);
- sock.setSoTimeout(1000);
- OutputStream out = sock.getOutputStream();
- InputStream in = sock.getInputStream();
- out.write(len);
- int i = -1;
- while (in.available() <= 0);
- i = in.read();
- if (length != i && i != -1) {
- if (len == 1) {
- setString(50, "Getting Item Updates...");
- //new Update(findCacheDir(), "items.zip", true, true);
- return;
- }
- if (len == 2) {
- setString(0, "Getting Client Updates...");
- new Update(findCacheDir(), "client.dat", false, false);
- return;
- }
- }
- } catch (Exception e) {
- return;
- }
- }
- public static String findCacheDir() {
- try {
- String cache = "C:/.ER_file_store_32";
- String text = "";
- File file = new File((new StringBuilder()).append(text).append(cache).toString());
- if (file.exists() || file.mkdir()) {
- return (new StringBuilder()).append(text).append(cache).append("/").toString();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- public final int dataStream(String str) {
- try {
- File file = new File(findCacheDir() + str);
- if (!file.exists()) {
- return -1;
- }
- DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
- byte[] buf = new byte[1];
- in.read(buf, 0, 1);
- in.close();
- return buf[0];
- } catch (Exception e) {}
- return -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement