Guest User

update

a guest
Apr 14th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. // Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
  2. // Jad home page: http://www.kpdus.com/jad.html
  3. // Decompiler options: packimports(3)
  4. // Source File Name: Update.java
  5.  
  6. import java.io.*;
  7. import java.net.HttpURLConnection;
  8. import java.net.URL;
  9. import java.util.Enumeration;
  10. import java.util.zip.ZipEntry;
  11. import java.util.zip.ZipFile;
  12.  
  13. public class Update extends Thread
  14. {
  15.  
  16. public static void main(String args[])
  17. {
  18. }
  19.  
  20. public Update(String s, String s1, String s2)
  21. {
  22. homeDir = s2;
  23. saveAs = (new StringBuilder()).append(s2).append(s1).toString();
  24. urlLoc = s;
  25. if(!(new File(s2)).exists())
  26. (new File(s2)).mkdir();
  27. if(downloadFile())
  28. {
  29. unZipFile();
  30. } else
  31. {
  32. System.out.println("error");
  33. deleteFile();
  34. }
  35. }
  36.  
  37. private void writeStream(InputStream inputstream, OutputStream outputstream)
  38. throws IOException
  39. {
  40. byte abyte0[] = new byte[1024];
  41. int i;
  42. while((i = inputstream.read(abyte0)) >= 0)
  43. outputstream.write(abyte0, 0, i);
  44. inputstream.close();
  45. outputstream.close();
  46. }
  47.  
  48. private void unZipFile()
  49. {
  50. try
  51. {
  52. ZipFile zipfile = new ZipFile(saveAs);
  53. for(Enumeration enumeration = zipfile.entries(); enumeration.hasMoreElements();)
  54. {
  55. ZipEntry zipentry = (ZipEntry)enumeration.nextElement();
  56. if(zipentry.isDirectory())
  57. {
  58. if(checkProgress)
  59. System.out.println((new StringBuilder()).append("Creating Directory: ").append(zipentry.getName()).toString());
  60. (new File((new StringBuilder()).append(homeDir).append(zipentry.getName()).toString())).mkdir();
  61. } else
  62. {
  63. if(checkProgress)
  64. System.out.println((new StringBuilder()).append("Extracting File: ").append(zipentry.getName()).toString());
  65. writeStream(zipfile.getInputStream(zipentry), new BufferedOutputStream(new FileOutputStream((new StringBuilder()).append(homeDir).append(zipentry.getName()).toString())));
  66. }
  67. }
  68.  
  69. zipfile.close();
  70. }
  71. catch(Exception exception)
  72. {
  73. exception.printStackTrace();
  74. }
  75. }
  76.  
  77. private void deleteFile()
  78. {
  79. try
  80. {
  81. File file = new File(saveAs);
  82. file.delete();
  83. }
  84. catch(Exception exception)
  85. {
  86. exception.printStackTrace();
  87. }
  88. }
  89.  
  90. private boolean downloadFile()
  91. {
  92. try
  93. {
  94.  
  95.  
  96. if(checkProgress)
  97. System.out.println((new StringBuilder()).append("Downloading ").append(saveAs).append("...").toString());
  98. HttpURLConnection httpurlconnection = (HttpURLConnection)(new URL(urlLoc)).openConnection();
  99.  
  100. HttpURLConnection.setFollowRedirects(true);
  101. httpurlconnection.setInstanceFollowRedirects(false);
  102. httpurlconnection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
  103. long l = httpurlconnection.getContentLength();
  104. new ProgressChecker(saveAs, l);
  105.  
  106. FileOutputStream fileoutputstream = new FileOutputStream(saveAs);
  107. BufferedOutputStream bufferedoutputstream = new BufferedOutputStream(fileoutputstream);
  108. writeStream(httpurlconnection.getInputStream(), bufferedoutputstream);
  109. fileoutputstream.close();
  110. bufferedoutputstream.close();
  111. File file = new File(saveAs);
  112.  
  113. if(checkProgress)
  114. System.out.println((new StringBuilder()).append(saveAs).append(" downloaded...").toString());
  115. return true;
  116. }
  117. catch(Exception exception)
  118. {
  119. exception.printStackTrace();
  120. }
  121. return false;
  122. }
  123.  
  124. private String homeDir;
  125. private String saveAs;
  126. private String urlLoc;
  127. private boolean checkProgress;
  128. }
Advertisement
Add Comment
Please, Sign In to add comment