def main(): app = QApplication(sys.argv) env = Enviroment() env.mainWindow = MainWindow(env) env.loginWindow = LoginWindow(env) if hasattr(env,"account"): if hasInternetConnection(): response = minecraft_launcher_lib.account.validate_access_token(env.account["accessToken"]) if response: env.mainWindow.updateAccountInformation() env.mainWindow.show() elif env.account.get("mail","") in env.saved_passwords: login_with_saved_passwords(env,env.account) env.mainWindow.show() else: env.loginWindow.show() else: env.offlineMode = True env.loadVersions() env.mainWindow.updateAccountInformation() env.mainWindow.show() else: if hasInternetConnection(): env.loginWindow.show() else: showMessageBox("messagebox.nointernet.title","messagebox.nointernet.text",self.env,lambda: sys.exit(0)) env.mainWindow.profileWindow.close() env.mainWindow.close() env.loginWindow.close() #w = MainWindow() #w.setup(env) #w.show() #w.setFocus() sys.exit(app.exec_())
def removeProfile(self): if len(self.env.profiles) == 1: showMessageBox("profiletab.removeError.title", "profiletab.removeError.text", self.env) else: del self.env.profiles[self.currentRow()] self.env.selectedProfile = 0 self.mainWindow.updateProfilList()
def resetButtonClicked(self): if self.env.offlineMode: showMessageBox("messagebox.needinternet.title", "messagebox.needinternet.text", self.env) return minecraft_launcher_lib.account.reset_skin( self.env.account["uuid"], self.env.account["accessToken"]) self.updateSkin() showMessageBox("skintab.reset.title", "skintab.reset.text", self.env)
def playButtonClicked(self): profile = self.env.profiles[self.profileComboBox.currentIndex()] if self.env.offlineMode: if os.path.isdir( os.path.join(self.env.dataPath, "versions", profile.getVersionID())): self.startMinecraft(profile) else: showMessageBox("messagebox.installinternet.title", "messagebox.installinternet.text", self.env) else: self.installVersion(profile)
def logoutButtonClicked(self): if self.env.offlineMode: showMessageBox("messagebox.needinternet.title", "messagebox.needinternet.text", self.env) return minecraft_launcher_lib.account.invalidate_access_token( self.env.account["accessToken"], self.env.account["clientToken"]) del self.env.accountList[self.env.selectedAccount] if len(self.env.accountList) == 0: self.hide() self.env.loginWindow.show() self.env.loginWindow.setFocus() else: self.env.account = self.env.accountList[0] self.updateAccountInformation()
def loginButtonClicked(self): loginInformation = minecraft_launcher_lib.account.login_user( self.usernameInput.text(), self.passwordInput.text()) if "errorMessage" in loginInformation: if loginInformation[ "errorMessage"] == "Invalid credentials. Invalid username or password.": showMessageBox("loginwindow.loginfailed.title", "loginwindow.loginfailed.text", self.env) return else: showMessageBox(loginInformation["error"], loginInformation["errorMessage"], self.env) return self.env.accountData = loginInformation self.env.accountString = str(loginInformation) self.env.account = {} self.env.account["name"] = loginInformation["selectedProfile"]["name"] self.env.account["accessToken"] = loginInformation["accessToken"] self.env.account["clientToken"] = loginInformation["clientToken"] self.env.account["uuid"] = loginInformation["selectedProfile"]["id"] accountData = { "name": loginInformation["selectedProfile"]["name"], "accessToken": loginInformation["accessToken"], "clientToken": loginInformation["clientToken"], "uuid": loginInformation["selectedProfile"]["id"], "mail": self.usernameInput.text() } if not self.saveLogin.checkState(): self.env.disableAccountSave.append(accountData["name"]) if self.env.settings.enablePasswordSave: self.env.saved_passwords[ self.usernameInput.text()] = self.passwordInput.text() self.close() self.usernameInput.setText("") self.passwordInput.setText("") self.env.mainWindow.show() self.env.mainWindow.setFocus() for count, i in enumerate(self.env.accountList): if i["name"] == accountData["name"]: self.env.accountList[count] = accountData self.env.selectedAccount = count self.env.mainWindow.updateAccountInformation() return self.env.accountList.append(accountData) self.env.selectedAccount = len(self.env.accountList) - 1 self.env.mainWindow.updateAccountInformation()
def downloadButtonClicked(self): if self.env.offlineMode: showMessageBox("messagebox.needinternet.title", "messagebox.needinternet.text", self.env) return path = QFileDialog.getSaveFileName( self, self.env.translate("skintab.filepicker.download.title"), os.path.join(QDir.homePath(), "Skin.png"), self.env.translate("skintab.filepicker.filetype.png")) if path[0]: if os.path.isfile(path[0]): os.remove(path[0]) urllib.request.urlretrieve( "https://minotar.net/skin/" + self.env.account["uuid"], path[0])
def uploadButtonClicked(self): if self.env.offlineMode: showMessageBox("messagebox.needinternet.title", "messagebox.needinternet.text", self.env) return path = QFileDialog.getOpenFileName( self, self.env.translate("skintab.filepicker.upload.title"), self.env.translate("skintab.filepicker.filetype.png")) if path[0]: minecraft_launcher_lib.account.upload_skin( self.env.account["uuid"], self.env.account["accessToken"], path[0]) self.updateSkin() showMessageBox("skintab.upload.title", "skintab.upload.text", self.env)
def __init__(self): self.launcherVersion = "2.4" self.offlineMode = False self.currentDir = os.path.dirname(os.path.realpath(__file__)) if len(sys.argv) == 2: self.dataPath = sys.argv[1] else: self.dataPath = minecraft_launcher_lib.utils.get_minecraft_directory( ) if not os.path.exists( os.path.join(self.dataPath, "jdMinecraftLauncher")): os.makedirs(os.path.join(self.dataPath, "jdMinecraftLauncher")) self.settings = Settings(self) if self.settings.language == "default": self.translations = jdTranslationHelper( lang=QLocale.system().name()) else: self.translations = jdTranslationHelper( lang=self.settings.language) self.translations.loadDirectory( os.path.join(self.currentDir, "translation")) self.accountList = [] self.selectedAccount = 0 self.disableAccountSave = [] if os.path.isfile( os.path.join(self.dataPath, "jdMinecraftLauncher", "account.json")): with open( os.path.join(self.dataPath, "jdMinecraftLauncher", "account.json")) as f: data = json.load(f) self.accountList = data.get("accountList", []) self.selectedAccount = data.get("selectedAccount", 0) try: self.account = copy.copy( self.accountList[self.selectedAccount]) except IndexError: self.account = copy.copy(self.accountList[0]) self.selectedAccount = 0 self.saved_passwords = {} self.encrypt_password = "" if os.path.isfile( os.path.join(self.dataPath, "jdMinecraftLauncher", "saved_passwords.json")): with open( os.path.join(self.dataPath, "jdMinecraftLauncher", "saved_passwords.json"), "rb") as f: self.encrypt_password, ok = QInputDialog.getText( QWidget(), self.translate("inputdialog.enterPassword.title"), self.translate("inputdialog.enterPassword.text")) if ok: key = Crypto.get_key(self.encrypt_password) try: password_str = Crypto.decrypt(f.read(), key) self.saved_passwords = json.loads(password_str) except InvalidToken: showMessageBox("messagebox.wrongEncryptPassword.title", "messagebox.wrongEncryptPassword.text", self) sys.exit(0) self.loadVersions() self.profiles = [] self.selectedProfile = 0 if os.path.isfile( os.path.join(self.dataPath, "jdMinecraftLauncher", "profiles.json")): with open( os.path.join(self.dataPath, "jdMinecraftLauncher", "profiles.json")) as f: data = json.load(f) if isinstance(data, list): profileList = data else: profileList = data["profileList"] self.selectedProfile = data["selectedProfile"] for i in profileList: p = Profile(i["name"], self) p.load(i) self.profiles.append(p) else: self.profiles.append(Profile("Default", self))