Advertisement
Guest User

Untitled

a guest
Apr 28th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. public class Parser
  2. {
  3.  
  4. public static void prepareJars()
  5. {
  6. try
  7. {
  8. URL xmlURL = new URL("http://minesquid.fr/Launcher/bin.xml");
  9. InputStream xml = xmlURL.openStream();
  10. DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  11. DocumentBuilder db = dbf.newDocumentBuilder();
  12. Document doc = db.parse(xml);
  13. Node node = doc.getFirstChild();
  14. for (int i = 0; i < node.getChildNodes().getLength(); i++)
  15. {
  16. Node parse = node.getChildNodes().item(i);
  17. if (parse.getNodeName().equals("Contents"))
  18. {
  19. String key = parse.getChildNodes().item(1).getTextContent();
  20. String md5 = parse.getChildNodes().item(3).getTextContent().replace("\"", "");
  21. double size = Double.parseDouble(parse.getChildNodes().item(5).getTextContent());
  22. File local = new File(Util.getWorkingDirectory(), key);
  23. if (!local.isDirectory())
  24. {
  25. boolean correct = true;
  26. if ((!local.exists()) || (!md5.equals(Hasheur.getMD5(local)))) {
  27. correct = false;
  28. }
  29. if (!correct) {
  30. System.out.println(local.getName() + " : " + correct + " : " + size + " : " + local.getAbsolutePath());
  31. }
  32. Updater.files.put(key, new Fichier(size, "http://minesquid.fr/Launcher" + key, local.getAbsolutePath(), correct));
  33. }
  34. }
  35. }
  36. xml.close();
  37. }
  38. catch (Exception e)
  39. {
  40. e.printStackTrace();
  41. }
  42. }
  43.  
  44. public static void prepareRessources()
  45. {
  46. try
  47. {
  48. URL xmlURL = new URL("http://minesquid.fr/Launcher/res.xml");
  49. InputStream xml = xmlURL.openStream();
  50. DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  51. DocumentBuilder db = dbf.newDocumentBuilder();
  52. Document doc = db.parse(xml);
  53. Node node = doc.getFirstChild();
  54. System.out.println("------------------ node lenght : " + node.getChildNodes().getLength());
  55. for (int i = 0; i < node.getChildNodes().getLength(); i++)
  56. {
  57. Node parse = node.getChildNodes().item(i);
  58. if (parse.getNodeName().equals("Contents"))
  59. {
  60. String key = parse.getChildNodes().item(1).getTextContent();
  61. String md5 = parse.getChildNodes().item(3).getTextContent().replace("\"", "");
  62. double size = Double.parseDouble(parse.getChildNodes().item(5).getTextContent());
  63. File local = new File(Util.getWorkingDirectory(), key);
  64. boolean correct = true;
  65. if ((!local.exists()) || (!md5.equals(Hasheur.getMD5(local)))) {
  66. correct = false;
  67. }
  68. if (!correct) {
  69. System.out.println(local.getName() + " : " + correct + " : " + size + " : " + local.getAbsolutePath());
  70. }
  71. Updater.files.put(key, new Fichier(size, "http://minesquid.fr/Launcher" + key, local.getAbsolutePath(), correct));
  72. }
  73. }
  74. xml.close();
  75. }
  76. catch (Exception e)
  77. {
  78. e.printStackTrace();
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement