1. import ui, wndMgr, chat, uiCommon, pack, os
  2. class FileExtractor(ui.ScriptWindow):
  3. Gui = []
  4. Errortype = "none"
  5. def __init__(self):
  6. self.Gui = []
  7. ui.ScriptWindow.__init__(self)
  8. self.AddGui()
  9. def __del__(self):
  10. self.Gui[0].Hide()
  11. ui.ScriptWindow.__del__(self)
  12. def AddGui(self):
  13. Gui = [
  14. [[ui.ThinBoard, ""], [255, 40], [50, wndMgr.GetScreenHeight()-100], [], ["float"]],
  15. [[ui.Button, 0], [0, 0], [230, 13], [['SetUpVisual', ["d:/ymir work/ui/public/close_button_01.sub"]],['SetOverVisual', ["d:/ymir work/ui/public/close_button_02.sub"]], ['SetDownVisual', ["d:/ymir work/ui/public/close_button_03.sub"]], ['SetToolTipText', ["Close", 0, - 23]], ['SetEvent', [lambda : self.__del__()]]], []],
  16. [[ui.Button, 0], [0, 0], [120, 10], [['SetUpVisual', ["d:/ymir work/ui/public/Large_button_01.sub"]],['SetOverVisual', ["d:/ymir work/ui/public/Large_button_02.sub"]], ['SetDownVisual', ["d:/ymir work/ui/public/Large_button_03.sub"]], ["SetText", ["Cikart"]], ['SetEvent', [lambda : self.ExtractFile()]]], []],
  17. [[ui.SlotBar, 0], [87, 18], [15, 10], [], []],
  18. [[ui.EditLine, 3], [87, 17], [6, 2], [["SetMax", [15]], ["SetFocus", [""]]], []],
  19. ]
  20. GuiParser(Gui, self.Gui)
  21. def ExtractFile(self):
  22. script = self.Gui[4].GetText()
  23. if len(script) == 0:
  24. return
  25. add = ""
  26. if str(script).find("d:/") != -1:
  27. script = str(script).replace("d:/", "")
  28. add = "d:/"
  29. if pack.Exist(add + script):
  30. if not os.path.exists("Source/" + script):
  31. os.makedirs("Source/" + script)
  32. if os.path.exists("Source/" + script):
  33. if os.path.isfile("Source/" + script):
  34. os.remove("Source/" + script)
  35. else:
  36. os.rmdir("Source/" + script)
  37. if self.IsBinary(script) == 0:
  38. lines = pack_open(add + script, "r").readlines()
  39. f = open("Source/" + script, "a+")
  40. for line in lines:
  41. tokens = line
  42. f.write(str(tokens))
  43. f.close()
  44. else:
  45. Binary = pack_open(add + script, 'rb')
  46. Bytes = Binary.read()
  47. if len(Bytes) == 0:
  48. if self.Errortype != "ending":
  49. self.Errortype = "read"
  50. return
  51. else:
  52. f = open("Source/" + script, "wb")
  53. f.write(str(Bytes))
  54. f.close()
  55. else:
  56. self.Errortype = "exist"
  57. return
  58. def IsBinary(self, script):
  59. if str(script).count(".") == 0:
  60. self.Errortype = "ending"
  61. self.ErrorScreen(str(script)+" .")
  62. script = script + ".binary"
  63. Split = script.split(".")
  64. end = str(Split[1])
  65. end = end.lower()
  66. if end == ".py":
  67. return 0
  68. else:
  69. return 1
  70. def ErrorScreen(self, error=""):
  71. ErrorDialog = uiCommon.PopupDialog()
  72. ErrorDialog.SetText(error)
  73. ErrorDialog.SetAcceptEvent(self.__OnCloseErrorDialog)
  74. ErrorDialog.Open()
  75. self.ErrorDialog = ErrorDialog
  76. def __OnCloseErrorDialog(self):
  77. self.pop = None
  78. def GuiParser(guiobjects, list):
  79. for object in guiobjects:
  80. Object = object[0][0]()
  81. if object[0][1] != "":
  82. Object.SetParent(list[object[0][1]])
  83. if object[1][0] + object[1][1] != 0:
  84. Object.SetSize(object[1][0], object[1][1])
  85. if object[2][0] + object[2][1] != 0:
  86. Object.SetPosition(object[2][0], object[2][1])
  87. for command in object[3]:
  88. cmd = command[0]
  89. attr = getattr(Object,cmd)
  90. if callable(attr):
  91. argument = command[1]
  92. lenght = len(argument)
  93. if lenght == 1:
  94. if argument[0] == "":
  95. attr()
  96. else:
  97. attr(argument[0])
  98. elif lenght == 2:
  99. attr(argument[0], argument[1])
  100. elif lenght == 3:
  101. attr(argument[0], argument[1], argument[2])
  102. elif lenght == 4:
  103. attr(argument[0], argument[1], argument[2], argument[3])
  104. for flag in object[4]:
  105. Object.AddFlag(str(flag))
  106. Object.Show()
  107. list.append(Object)
  108. FileExtractor().Show()