daily pastebin goal
81%
SHARE
TWEET

main.py

a guest May 7th, 2016 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -*- coding: utf-8 -*-
  2.  
  3. from PyQt4 import QtCore, QtGui
  4.  
  5. import os, easygui, urllib.request, CreateFiles, zipfile, GetAccessToken, base64
  6.  
  7. try:
  8.     _fromUtf8 = QtCore.QString.fromUtf8
  9. except AttributeError:
  10.     def _fromUtf8(s):
  11.         return s
  12.  
  13. try:
  14.     _encoding = QtGui.QApplication.UnicodeUTF8
  15.     def _translate(context, text, disambig):
  16.         return QtGui.QApplication.translate(context, text, disambig, _encoding)
  17. except AttributeError:
  18.     def _translate(context, text, disambig):
  19.         return QtGui.QApplication.translate(context, text, disambig)
  20.  
  21. class Ui_widget(object):
  22.     def setupUi(self, widget):
  23.         widget.setObjectName(_fromUtf8("widget"))
  24.         widget.resize(825, 593)
  25.         font = QtGui.QFont()
  26.         font.setPointSize(11)
  27.         widget.setFont(font)
  28.         icon = QtGui.QIcon()
  29.         icon.addPixmap(QtGui.QPixmap(_fromUtf8("./favicon.ico")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
  30.         widget.setWindowIcon(icon)
  31.         self.gridLayout_4 = QtGui.QGridLayout(widget)
  32.         self.gridLayout_4.setObjectName(_fromUtf8("gridLayout_4"))
  33.         self.progressBar = QtGui.QProgressBar(widget)
  34.         self.progressBar.setCursor(QtGui.QCursor(QtCore.Qt.IBeamCursor))
  35.         self.progressBar.setProperty("value", 0)
  36.         self.progressBar.setAlignment(QtCore.Qt.AlignBottom|QtCore.Qt.AlignHCenter)
  37.         self.progressBar.setTextVisible(True)
  38.         self.progressBar.setOrientation(QtCore.Qt.Horizontal)
  39.         self.progressBar.setInvertedAppearance(False)
  40.         self.progressBar.setObjectName(_fromUtf8("progressBar"))
  41.         self.gridLayout_4.addWidget(self.progressBar, 1, 0, 1, 1)
  42.         self.gridLayout_3 = QtGui.QGridLayout()
  43.         self.gridLayout_3.setObjectName(_fromUtf8("gridLayout_3"))
  44.         self.password = QtGui.QLineEdit(widget)
  45.         sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
  46.         sizePolicy.setHorizontalStretch(0)
  47.         sizePolicy.setVerticalStretch(0)
  48.         sizePolicy.setHeightForWidth(self.password.sizePolicy().hasHeightForWidth())
  49.         self.password.setSizePolicy(sizePolicy)
  50.         self.password.setEchoMode(QtGui.QLineEdit.Password)
  51.         self.password.setObjectName(_fromUtf8("password"))
  52.         self.gridLayout_3.addWidget(self.password, 1, 0, 1, 1)
  53.         self.play = QtGui.QPushButton(widget)
  54.         sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Expanding)
  55.         sizePolicy.setHorizontalStretch(0)
  56.         sizePolicy.setVerticalStretch(0)
  57.         sizePolicy.setHeightForWidth(self.play.sizePolicy().hasHeightForWidth())
  58.         self.play.setSizePolicy(sizePolicy)
  59.         self.play.setMinimumSize(QtCore.QSize(250, 0))
  60.         font = QtGui.QFont()
  61.         font.setPointSize(20)
  62.         font.setBold(True)
  63.         font.setWeight(75)
  64.         self.play.setFont(font)
  65.         self.play.setObjectName(_fromUtf8("play"))
  66.         self.gridLayout_3.addWidget(self.play, 0, 2, 2, 1)
  67.         self.email = QtGui.QLineEdit(widget)
  68.         sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
  69.         sizePolicy.setHorizontalStretch(0)
  70.         sizePolicy.setVerticalStretch(0)
  71.         sizePolicy.setHeightForWidth(self.email.sizePolicy().hasHeightForWidth())
  72.         self.email.setSizePolicy(sizePolicy)
  73.         self.email.setObjectName(_fromUtf8("email"))
  74.         self.gridLayout_3.addWidget(self.email, 0, 0, 1, 1)
  75.         self.line = QtGui.QFrame(widget)
  76.         self.line.setMinimumSize(QtCore.QSize(20, 100))
  77.         self.line.setFrameShape(QtGui.QFrame.VLine)
  78.         self.line.setFrameShadow(QtGui.QFrame.Sunken)
  79.         self.line.setObjectName(_fromUtf8("line"))
  80.         self.gridLayout_3.addWidget(self.line, 0, 1, 2, 1)
  81.         self.gridLayout_4.addLayout(self.gridLayout_3, 2, 0, 1, 1)
  82.         self.tabWidget = QtGui.QTabWidget(widget)
  83.         self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
  84.         self.tab = QtGui.QWidget()
  85.         self.tab.setObjectName(_fromUtf8("tab"))
  86.         self.gridLayout = QtGui.QGridLayout(self.tab)
  87.         self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
  88.         self.webView = QtWebKit.QWebView(self.tab)
  89.         self.webView.setUrl(QtCore.QUrl(_fromUtf8("http://mcupdate.tumblr.com/")))
  90.         self.webView.setObjectName(_fromUtf8("webView"))
  91.         self.gridLayout.addWidget(self.webView, 0, 0, 1, 1)
  92.         self.tabWidget.addTab(self.tab, _fromUtf8(""))
  93.         self.tab_2 = QtGui.QWidget()
  94.         self.tab_2.setObjectName(_fromUtf8("tab_2"))
  95.         self.gridLayout_2 = QtGui.QGridLayout(self.tab_2)
  96.         self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2"))
  97.         self.webView_2 = QtWebKit.QWebView(self.tab_2)
  98.         self.webView_2.setUrl(QtCore.QUrl(_fromUtf8("http://www.pixelmining.de/lauchner/index.html")))
  99.         self.webView_2.setZoomFactor(1.0)
  100.         self.webView_2.setObjectName(_fromUtf8("webView_2"))
  101.         self.gridLayout_2.addWidget(self.webView_2, 0, 0, 1, 1)
  102.         self.tabWidget.addTab(self.tab_2, _fromUtf8(""))
  103.         self.tab_4 = QtGui.QWidget()
  104.         self.tab_4.setObjectName(_fromUtf8("tab_4"))
  105.         self.gridLayout_9 = QtGui.QGridLayout(self.tab_4)
  106.         self.gridLayout_9.setObjectName(_fromUtf8("gridLayout_9"))
  107.         self.webView_3 = QtWebKit.QWebView(self.tab_4)
  108.         self.webView_3.setUrl(QtCore.QUrl(_fromUtf8("http://www.pixelmining.de/teamspeak3/index.html")))
  109.         self.webView_3.setObjectName(_fromUtf8("webView_3"))
  110.         self.gridLayout_9.addWidget(self.webView_3, 0, 0, 1, 1)
  111.         self.tabWidget.addTab(self.tab_4, _fromUtf8(""))
  112.         self.tab_3 = QtGui.QWidget()
  113.         self.tab_3.setObjectName(_fromUtf8("tab_3"))
  114.         self.gridLayout_8 = QtGui.QGridLayout(self.tab_3)
  115.         self.gridLayout_8.setObjectName(_fromUtf8("gridLayout_8"))
  116.         self.gridLayout_5 = QtGui.QGridLayout()
  117.         self.gridLayout_5.setObjectName(_fromUtf8("gridLayout_5"))
  118.         self.groupBox = QtGui.QGroupBox(self.tab_3)
  119.         self.groupBox.setMaximumSize(QtCore.QSize(16777215, 100))
  120.         self.groupBox.setObjectName(_fromUtf8("groupBox"))
  121.         self.gridLayout_6 = QtGui.QGridLayout(self.groupBox)
  122.         self.gridLayout_6.setObjectName(_fromUtf8("gridLayout_6"))
  123.         self.version = QtGui.QComboBox(self.groupBox)
  124.         self.version.setObjectName(_fromUtf8("version"))
  125.         self.gridLayout_6.addWidget(self.version, 0, 0, 1, 1)
  126.         self.gridLayout_5.addWidget(self.groupBox, 0, 0, 1, 1)
  127.         self.gridLayout_8.addLayout(self.gridLayout_5, 0, 0, 1, 1)
  128.         self.groupBox_2 = QtGui.QGroupBox(self.tab_3)
  129.         self.groupBox_2.setMaximumSize(QtCore.QSize(16777215, 100))
  130.         self.groupBox_2.setObjectName(_fromUtf8("groupBox_2"))
  131.         self.gridLayout_7 = QtGui.QGridLayout(self.groupBox_2)
  132.         self.gridLayout_7.setObjectName(_fromUtf8("gridLayout_7"))
  133.         self.offlineMode = QtGui.QCheckBox(self.groupBox_2)
  134.         self.offlineMode.setObjectName(_fromUtf8("offlineMode"))
  135.         self.gridLayout_7.addWidget(self.offlineMode, 0, 0, 1, 1)
  136.         self.offlineUsername = QtGui.QLineEdit(self.groupBox_2)
  137.         self.offlineUsername.setEnabled(False)
  138.         self.offlineUsername.setObjectName(_fromUtf8("offlineUsername"))
  139.         self.gridLayout_7.addWidget(self.offlineUsername, 0, 1, 1, 1)
  140.         self.gridLayout_8.addWidget(self.groupBox_2, 0, 1, 1, 1)
  141.         self.launcherVisible = QtGui.QCheckBox(self.tab_3)
  142.         self.launcherVisible.setObjectName(_fromUtf8("launcherVisible"))
  143.         self.gridLayout_8.addWidget(self.launcherVisible, 1, 0, 1, 2)
  144.         self.tabWidget.addTab(self.tab_3, _fromUtf8(""))
  145.         self.gridLayout_4.addWidget(self.tabWidget, 0, 0, 1, 1)
  146.  
  147.         self.play.clicked.connect(self.Play)
  148.  
  149.         self.retranslateUi(widget)
  150.         self.tabWidget.setCurrentIndex(3)
  151.         QtCore.QObject.connect(self.offlineMode, QtCore.SIGNAL(_fromUtf8("clicked(bool)")), self.offlineUsername.setEnabled)
  152.         QtCore.QMetaObject.connectSlotsByName(widget)
  153.  
  154.     def retranslateUi(self, widget):
  155.         widget.setWindowTitle(_translate("widget", "PixelMining - Launcher", None))
  156.         self.progressBar.setFormat(_translate("widget", "%p% heruntergeladen", None))
  157.         self.password.setPlaceholderText(_translate("widget", "Passwort", None))
  158.         self.play.setText(_translate("widget", "Play", None))
  159.         self.email.setPlaceholderText(_translate("widget", "Benutzername / E-Mail Adresse", None))
  160.         self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("widget", "Minecraft Updates", None))
  161.         self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("widget", "PixelMining Updates", None))
  162.         self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_4), _translate("widget", "TeamSpeak3", None))
  163.         self.groupBox.setTitle(_translate("widget", "Version", None))
  164.         self.groupBox_2.setTitle(_translate("widget", "Offline Einstellungen", None))
  165.         self.offlineMode.setText(_translate("widget", "Offline Mode", None))
  166.         self.launcherVisible.setText(_translate("widget", "Launcher beim Start geöffnet lassen", None))
  167.         self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_3), _translate("widget", "Einstellungen", None))
  168.  
  169.     def Reporthook1(self, blocknum, blocksize, totalsize):
  170.         versionIndex = self.version.currentIndex()
  171.         currentVersion = versions[versionIndex].split("|")
  172.  
  173.         #totalsize Fix
  174.         totalsize =  int(currentVersion[3])
  175.         readsofar = blocknum * blocksize
  176.         percent = (readsofar * 1e2 / totalsize) / 2
  177.  
  178.         self.progressBar.setValue(percent)
  179.         app.processEvents()
  180.  
  181.     def Reporthook2(self, blocknum, blocksize, totalsize):
  182.         file = open("./data/.minecraftVersion.mcv", "r")
  183.         minecraftVersion = file.read().split("|")
  184.         file.close()
  185.  
  186.         #totalsize Fix
  187.         totalsize =  int(minecraftVersion[2])
  188.         readsofar = blocknum * blocksize
  189.         percent = ((readsofar * 1e2 / totalsize) / 2) + 50
  190.  
  191.         self.progressBar.setValue(percent)
  192.         app.processEvents()        
  193.  
  194.     def Play(self, o):
  195.         self.play.setEnabled(False)
  196.         self.progressBar.setValue(0)
  197.         app.processEvents()
  198.         versionIndex = self.version.currentIndex()
  199.         currentVersion = versions[versionIndex].split("|")
  200.         try:
  201.             urllib.request.urlretrieve(currentVersion[1], "./data/" + currentVersion[0] + ".mcs")
  202.         except:
  203.             easygui.msgbox("Startdatei konnte nicht hertuntergeladen werden. Bitte überprüfe deine Verbindung zum Server.")
  204.             self.play.setEnabled(True)
  205.             self.progressBar.setValue(0)
  206.             return
  207.  
  208.         if os.path.isdir("./data/.minecraft/versions/" + currentVersion[0]):
  209.             self.progressBar.setValue(50)
  210.             app.processEvents()
  211.         else:
  212.             try:
  213.                 urllib.request.urlretrieve(currentVersion[2], "./data/" + currentVersion[0] + ".zip", self.Reporthook1)
  214.             except:
  215.                 easygui.msgbox("Version konnte nicht hertuntergeladen werden. Bitte überprüfe deine Verbindung zum Server.")
  216.                 self.play.setEnabled(True)
  217.                 self.progressBar.setValue(0)                
  218.                 return
  219.             # Zipfile entpacken
  220.             file = zipfile.ZipFile("./data/" + currentVersion[0] + ".zip", "r")
  221.             file.extractall("./data/")
  222.             file.close()
  223.         # Check .minecraft Version
  224.         try:
  225.             urllib.request.urlretrieve("http://www.pixelmining.de/Launcher/.minecraftVersion.txt", "./data/.minecraftVersion.mcv")
  226.         except:
  227.             easygui.msgbox("Minecraft konnte nicht heruntergeladen werden. Bitte überprüfe deine Verbindung zum Server.")
  228.             self.play.setEnabled(True)
  229.             self.progressBar.setValue(0)
  230.             return
  231.  
  232.         file = open("./data/.minecraftVersion.mcv", "r")
  233.         minecraftVersion = file.read().split("|")
  234.         file.close()
  235.  
  236.         file = open("./data/.minecraft/.minecraftVersion.mcv")
  237.         currentMinecraftVersion = file.read()
  238.         file.close()
  239.  
  240.         if minecraftVersion[0] == currentMinecraftVersion:
  241.             self.progressBar.setValue(100)
  242.             app.processEvents()
  243.         else:
  244.             try:
  245.                 urllib.request.urlretrieve(minecraftVersion[1], "./data/.minecraft.zip", self.Reporthook2)
  246.                 file = zipfile.ZipFile("./data/.minecraft.zip", "r")
  247.                 file.extractall("./data/")
  248.                 file.close()                
  249.             except:
  250.                 easygui.msgbox("Minecraft konnte nicht hertuntergeladen werden. Bitte überprüfe deine Verbindung zum Server.")
  251.                 self.play.setEnabled(True)
  252.                 self.progressBar.setValue(0)                
  253.                 return
  254.  
  255.  
  256.  
  257.         file = open("./data/.minecraft/.minecraftVersion.mcv", "w")
  258.         file.write(minecraftVersion[0])
  259.         file.close()
  260.  
  261.         # Minecraft starten
  262.         accessToken, uuid, username = GetAccessToken.GetToken(self.email.text(), self.password.text())
  263.  
  264.         if uuid == False:
  265.             easygui.msgbox("Benutzername oder Passwort falsch!")
  266.             self.play.setEnabled(True)
  267.             self.progressBar.setValue(0)
  268.             return
  269.        
  270.         file = open("./data/" + currentVersion[0] + ".mcs", "r")
  271.         startCommand = file.read()
  272.         file.close()
  273.  
  274.         path = os.path.realpath(".") + "/data/"
  275.        
  276.         # replace placeholder
  277.         if self.offlineMode.isChecked():
  278.             startCommand = startCommand.replace("[username]", self.offlineUsername.text())
  279.         else:  
  280.             startCommand = startCommand.replace("[username]", username)
  281.         startCommand = startCommand.replace("[uuid]", uuid)        
  282.         startCommand = startCommand.replace("[accessToken]", accessToken)
  283.         startCommand = startCommand.replace("[path]", path)
  284.  
  285.         #save options
  286.         file = open("./data/options.mcl", "wb")
  287.         file.write(base64.b64encode(str(self.email.text()+"|"+self.password.text()+"|"+str(self.offlineMode.isChecked())+"|"+self.offlineUsername.text()+"|"+str(self.launcherVisible.isChecked())).encode()))
  288.         file.close()
  289.  
  290.  
  291.         # start Minecraft
  292.         if self.launcherVisible.isChecked():
  293.             pass
  294.         else:
  295.             widget.hide()
  296.         app.processEvents()    
  297.         os.system(startCommand)
  298.         if self.launcherVisible.isChecked():
  299.             pass
  300.         else:
  301.             widget.show()
  302.         self.play.setEnabled(True)    
  303.            
  304.  
  305. from PyQt4 import QtWebKit
  306.  
  307. if __name__ == "__main__":
  308.     import sys
  309.     app = QtGui.QApplication(sys.argv)
  310.     widget = QtGui.QWidget()
  311.     ui = Ui_widget()
  312.     ui.setupUi(widget)
  313.     widget.show()
  314.  
  315.     #Create Files
  316.     CreateFiles.Create()        
  317.     #VersionList download
  318.     try:
  319.         urllib.request.urlretrieve("http://www.pixelmining.de/Launcher/VersionList.txt", "./data/versionList.mcv")      
  320.     except:
  321.         easygui.msgbox("Keine Verbindung zum Server.")
  322.         sys.exit()
  323.  
  324.     file = open("./data/versionList.mcv")
  325.     versions = file.read()
  326.     file.close()
  327.  
  328.     versions = versions.split("\n")
  329.     versionNames = []
  330.  
  331.     for i in versions:
  332.         versionNames.append(i.split("|")[0])
  333.  
  334.  
  335.     ui.version.addItems(versionNames)
  336.  
  337.     #load options
  338.     file = open("./data/options.mcl", "rb")
  339.     options = base64.b64decode(file.read()).decode().split("|")
  340.     file.close()
  341.  
  342.     ui.email.setText(options[0])
  343.     ui.password.setText(options[1])    
  344.     ui.offlineUsername.setText(options[3])
  345.    
  346.     if options[2] == "True":
  347.         ui.offlineMode.setChecked(True)
  348.         ui.offlineUsername.setEnabled(True)
  349.     else:
  350.         ui.offlineMode.setChecked(False)
  351.  
  352.     if options[4] == "True":
  353.         ui.launcherVisible.setChecked(True)
  354.     else:
  355.         ui.launcherVisible.setChecked(False)        
  356.    
  357.     sys.exit(app.exec_())
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top