Advertisement
Guest User

Josh

a guest
Apr 18th, 2010
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.86 KB | None | 0 0
  1. import java.awt.Font;
  2. import java.awt.Dimension;
  3. import java.io.BufferedInputStream;
  4. import java.io.DataInputStream;
  5. import java.io.File;
  6. import java.io.FileInputStream;
  7. import java.io.InputStream;
  8. import java.io.OutputStream;
  9. import java.io.PrintStream;
  10. import java.net.Socket;
  11. import javax.swing.JFrame;
  12. import javax.swing.JProgressBar;
  13. import javax.swing.JApplet;
  14.  
  15. public final class loader extends JApplet {
  16.  
  17. public static JProgressBar progressBar = null;
  18. public Socket sock = null;
  19. public GameFrame gframe;
  20. public GamePanel gpanel;
  21. public boolean loaded = false;
  22.  
  23. public void init() {
  24. gframe = null;
  25. gpanel = null;
  26. loaded = true;
  27. setConfig();
  28. setString(100, "Loading Done! - Closing webpage will exit the client!");
  29. new CacheDownloader(this).downloadCache();
  30. try {
  31. PreLoader loader = new PreLoader();
  32. getFile("ERclient.jar");
  33. if (gframe != null) {
  34. gframe.setVisible(true);
  35. remove(gframe);
  36. gframe = null;
  37. }
  38. if (loader != null) {
  39. Class load = loader.load("client", true);
  40. JApplet applet = (JApplet) load.newInstance();
  41. } else {
  42. setString(100, "Loader is null! Please fix this immediately!");
  43. }
  44. } catch (Exception e) {
  45. e.printStackTrace();
  46. }
  47. }
  48.  
  49. private final byte[] getFile(String name) {
  50. try {
  51. File file = new File(name);
  52. if (!file.exists()) {
  53. return null;
  54. }
  55. int length = (int)file.length();
  56. DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
  57. byte[] buf = new byte[length];
  58. in.readFully(buf, 0, length);
  59. in.close();
  60. return buf;
  61. } catch (Exception e) {
  62. e.printStackTrace();
  63. }
  64. return null;
  65. }
  66.  
  67. public final void setConfig() {
  68. try {
  69. progressBar = new JProgressBar();
  70. progressBar.setPreferredSize(new Dimension(270, 18));
  71. progressBar.setStringPainted(true);
  72. progressBar.setFont(new Font("Dialog", 1, 10));
  73. progressBar.setString("Loading Data!");
  74. if (!loaded) {
  75. gframe = new GameFrame(this, "loader");
  76. gframe.setPreferredSize(new Dimension(500, 85));
  77. gframe.add(progressBar);
  78. gframe.pack();
  79. gframe.setVisible(true);
  80. } else {
  81. gpanel = new GamePanel(this);
  82. gpanel.setPreferredSize(new Dimension(500, 85));
  83. gpanel.add(progressBar);
  84. setContentPane(gpanel);
  85. gpanel.setVisible(true);
  86. }
  87. } catch (Exception e) {
  88. e.printStackTrace();
  89. }
  90. }
  91.  
  92. public static final void setString(int length, String str) {
  93. progressBar.setValue(length);
  94. progressBar.setString(str);
  95. }
  96.  
  97. public final int size(String str) {
  98. try {
  99. File file = new File(findCacheDir() + str);
  100. if (!file.exists()) {
  101. return -1;
  102. }
  103. DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
  104. byte[] buf = new byte[4];
  105. in.read(buf, 0, 4);
  106. in.close();
  107. return buf[2];
  108. } catch (Exception e) {}
  109. return -1;
  110. }
  111.  
  112. public final void getUpdates(int length, int len) {
  113. try {
  114. if (length <= 0 && len == 2) {
  115. setString(0, "Getting Client Updates...");
  116. new Update(findCacheDir(), "ERclient.jar", false, false);
  117. return;
  118. }
  119. if (length <= 0 && len == 1) {
  120. setString(50, "Getting Item Updates...");
  121. new Update(findCacheDir(), "items.zip", true, true);
  122. return;
  123. }
  124. if (len == 1) {
  125. setString(50, "Checking For Item Updates...");
  126. }
  127. if (len == 2) {
  128. setString(0, "Checking For Client Updates...");
  129. }
  130. sock = new Socket("http://elementalregion.com/ERcache/cache.zip", 704);
  131. sock.setSoTimeout(1000);
  132. OutputStream out = sock.getOutputStream();
  133. InputStream in = sock.getInputStream();
  134. out.write(len);
  135. int i = -1;
  136. while (in.available() <= 0);
  137. i = in.read();
  138. if (length != i && i != -1) {
  139. if (len == 1) {
  140. setString(50, "Getting Item Updates...");
  141. //new Update(findCacheDir(), "items.zip", true, true);
  142. return;
  143. }
  144. if (len == 2) {
  145. setString(0, "Getting Client Updates...");
  146. new Update(findCacheDir(), "client.dat", false, false);
  147. return;
  148. }
  149. }
  150. } catch (Exception e) {
  151. return;
  152. }
  153. }
  154.  
  155. public static String findCacheDir() {
  156. try {
  157. String cache = "C:/.ER_file_store_32";
  158. String text = "";
  159. File file = new File((new StringBuilder()).append(text).append(cache).toString());
  160. if (file.exists() || file.mkdir()) {
  161. return (new StringBuilder()).append(text).append(cache).append("/").toString();
  162. }
  163. } catch (Exception e) {
  164. e.printStackTrace();
  165. }
  166. return null;
  167. }
  168.  
  169. public final int dataStream(String str) {
  170. try {
  171. File file = new File(findCacheDir() + str);
  172. if (!file.exists()) {
  173. return -1;
  174. }
  175. DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
  176. byte[] buf = new byte[1];
  177. in.read(buf, 0, 1);
  178. in.close();
  179. return buf[0];
  180. } catch (Exception e) {}
  181. return -1;
  182. }
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement