daily pastebin goal
62%
SHARE
TWEET

main.py

a guest May 7th, 2016 68 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
  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("../../Minecraft Launcher/Scripts/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.         app.processEvents()
  197.         versionIndex = self.version.currentIndex()
  198.         currentVersion = versions[versionIndex].split("|")
  199.         try:
  200.             urllib.request.urlretrieve(currentVersion[1], "./data/" + currentVersion[0] + ".mcs")
  201.         except:
  202.             easygui.msgbox("Startdatei konnte nicht hertuntergeladen werden. Bitte überprüfe deine Verbindung zum Server.")
  203.             self.play.setEnabled(True)
  204.             self.progressBar.setValue(0)
  205.             return
  206.  
  207.         if os.path.isdir("./data/.minecraft/versions/" + currentVersion[0]):
  208.             self.progressBar.setValue(50)
  209.         else:
  210.             try:
  211.                 urllib.request.urlretrieve(currentVersion[2], "./data/" + currentVersion[0] + ".zip", self.Reporthook1)
  212.             except:
  213.                 easygui.msgbox("Version konnte nicht hertuntergeladen werden. Bitte überprüfe deine Verbindung zum Server.")
  214.                 self.play.setEnabled(True)
  215.                 self.progressBar.setValue(0)                
  216.                 return
  217.             # Zipfile entpacken
  218.             file = zipfile.ZipFile("./data/" + currentVersion[0] + ".zip", "r")
  219.             file.extractall("./data/")
  220.             file.close()
  221.         # Check .minecraft Version
  222.         try:
  223.             urllib.request.urlretrieve("http://www.pixelmining.de/Launcher/.minecraftVersion.txt", "./data/.minecraftVersion.mcv")
  224.         except:
  225.             easygui.msgbox("Minecraft konnte nicht heruntergeladen werden. Bitte überprüfe deine Verbindung zum Server.")
  226.             self.play.setEnabled(True)
  227.             self.progressBar.setValue(0)
  228.             return
  229.  
  230.         file = open("./data/.minecraftVersion.mcv", "r")
  231.         minecraftVersion = file.read().split("|")
  232.         file.close()
  233.  
  234.         file = open("./data/.minecraft/.minecraftVersion.mcv")
  235.         currentMinecraftVersion = file.read()
  236.         file.close()
  237.  
  238.         if minecraftVersion[0] == currentMinecraftVersion:
  239.             self.progressBar.setValue(100)
  240.         else:
  241.             try:
  242.                 urllib.request.urlretrieve(minecraftVersion[1], "./data/.minecraft.zip", self.Reporthook2)
  243.                 file = zipfile.ZipFile("./data/.minecraft.zip", "r")
  244.                 file.extractall("./data/")
  245.                 file.close()                
  246.             except:
  247.                 easygui.msgbox("Minecraft konnte nicht hertuntergeladen werden. Bitte überprüfe deine Verbindung zum Server.")
  248.                 self.play.setEnabled(True)
  249.                 self.progressBar.setValue(0)                
  250.                 return
  251.  
  252.  
  253.  
  254.         file = open("./data/.minecraft/.minecraftVersion.mcv", "w")
  255.         file.write(minecraftVersion[0])
  256.         file.close()
  257.  
  258.         # Minecraft starten
  259.         accessToken, uuid, username = GetAccessToken.GetToken(self.email.text(), self.password.text())
  260.  
  261.         if uuid == False:
  262.             easygui.msgbox("Benutzername oder Passwort falsch!")
  263.             self.play.setEnabled(True)
  264.             self.progressBar.setValue(0)
  265.             return
  266.        
  267.         file = open("./data/" + currentVersion[0] + ".mcs", "r")
  268.         startCommand = file.read()
  269.         file.close()
  270.  
  271.         path = os.path.realpath(".") + "/data/"
  272.  
  273.         # replace placeholder
  274.         startCommand = startCommand.replace("[username]", username)
  275.         startCommand = startCommand.replace("[uuid]", uuid)        
  276.         startCommand = startCommand.replace("[accessToken]", accessToken)
  277.         startCommand = startCommand.replace("[path]", path)
  278.  
  279.         # start Minecraft
  280.         os.popen(startCommand)
  281.        
  282.            
  283.  
  284. from PyQt4 import QtWebKit
  285.  
  286. if __name__ == "__main__":
  287.     import sys
  288.     app = QtGui.QApplication(sys.argv)
  289.     widget = QtGui.QWidget()
  290.     ui = Ui_widget()
  291.     ui.setupUi(widget)
  292.     widget.show()
  293.    
  294.     #Run as admin
  295.     import win32com.shell.shell as shell
  296.     ASADMIN = 'asadmin'
  297.     if sys.argv[-1] !=ASADMIN:
  298.         script = os.path.abspath(sys.argv[0])
  299.         params = ' '.join([script] + sys.argv[1:] + [ASADMIN])
  300.         try:
  301.             shell.ShellExecuteEx(lpVerb='runas', lpFile=sys.executable, lpParameters=params)
  302.         except:
  303.             easygui.msgbox("Du musst diesen Launcher als Administrator ausführen.", "Error")
  304.             sys.exit()
  305.  
  306.     #Create Files
  307.     CreateFiles.Create()        
  308.     #VersionList download
  309.     try:
  310.         urllib.request.urlretrieve("http://www.pixelmining.de/Launcher/VersionList.txt", "./data/versionList.mcv")      
  311.     except:
  312.         easygui.msgbox("Keine Verbindung zum Server.")
  313.         sys.exit()
  314.  
  315.     file = open("./data/versionList.mcv")
  316.     versions = file.read()
  317.     file.close()
  318.  
  319.     versions = versions.split("\n")
  320.     versionNames = []
  321.  
  322.     for i in versions:
  323.         versionNames.append(i.split("|")[0])
  324.  
  325.  
  326.     ui.version.addItems(versionNames)    
  327.        
  328.     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