diff --git a/.gmclcore/env/aria2c64.exe b/.gmclcore/env/aria2c64.exe new file mode 100644 index 0000000..18b2b7b Binary files /dev/null and b/.gmclcore/env/aria2c64.exe differ diff --git a/.gmclcore/logs/2022-01-09.logs b/.gmclcore/logs/2022-01-09.logs new file mode 100644 index 0000000..deb0cdb --- /dev/null +++ b/.gmclcore/logs/2022-01-09.logs @@ -0,0 +1,6 @@ +[2022-01-09 12:32:21] [INFO] Initing running env... +[2022-01-09 12:32:24] [INFO] Creating daemon thread... +[2022-01-09 12:39:35] [INFO] Initing running env... +[2022-01-09 12:39:36] [INFO] Creating daemon thread... +[2022-01-09 12:43:55] [INFO] Initing running env... +[2022-01-09 12:43:56] [INFO] Creating daemon thread... diff --git a/Example.py b/Example.py deleted file mode 100644 index 78e59a5..0000000 --- a/Example.py +++ /dev/null @@ -1,3 +0,0 @@ -from GMCLCore import * -launcher=GMCLCore() -launcher.PrintAllLog() \ No newline at end of file diff --git a/GMCLCore/__init__.py b/GMCLCore/__init__.py new file mode 100644 index 0000000..0bafdf4 --- /dev/null +++ b/GMCLCore/__init__.py @@ -0,0 +1,78 @@ +# -*- coding: utf-8 -*- +# +# ________ _____ _________ .____ _________ +# / _____/ / \ \_ ___ \| | \_ ___ \ ___________ ____ +# / \ ___ / \ / \/ \ \/| | / \ \/ / _ \_ __ _/ __ \ +# \ \_\ / Y \ \___| |__\ \___( <_> | | \\ ___/ +# \______ \____|__ /\______ |_______ \______ /\____/|__| \___ > +# \/ \/ \/ \/ \/ \/ +# +# Ghink Minecraft Launcher +# Copyleft Ghink Network Studio +# Bigsk (https://www.xiaxinzhe.cn) +# See the LICENSE +# + +import os, platform +import urllib.request + +def networkTest(source = r"https://www.baidu.com", retry = 3): + flag = False + for i in range(retry): + try: + fp = urllib.request.urlopen(source) + fp.read(100).decode() + fp.close() + except: + pass + else: + flag = True + return flag + +modules = ( + "psutil", + "requests" +) + +retry = 3 +mirrors = "https://pypi.tuna.tsinghua.edu.cn/simple" +for m in modules: + try: + exec("import {}".format(m)) + except Exception as e: + print(e) + if networkTest(): + for i in range(retry): + if platform.system == "Windows": + os.system("pip install -i {} {}".format(mirrors, m)) + else: + os.system("pip3 install -i {} {}".format(mirrors, m)) + try: + exec("import {}".format(m)) + except: + if i == retry - 1: + raise ImportError("Failed to import modules {}! ".format(m)) + else: + break + else: + raise ImportError("Failed to import modules {}! ".format(m)) + +from GMCLCore.config import * + +__version__ = "{} {}".format(VERSION[0], ".".join(str(c) for c in VERSION[1])) +__name__ = "GMCLCore" +__all__ = [] + +from GMCLCore.main import * + +print("Welcome to GMCLCore {}!".format(__version__)) +print( + ''' + ________ _____ _________ .____ _________ + / _____/ / \ \_ ___ \| | \_ ___ \ ___________ ____ +/ \ ___ / \ / \/ \ \/| | / \ \/ / _ \_ __ _/ __ \ +\ \_\ / Y \ \___| |__\ \___( <_> | | \\ ___/ + \______ \____|__ /\______ |_______ \______ /\____/|__| \___ > + \/ \/ \/ \/ \/ \/ + ''' +) \ No newline at end of file diff --git a/GMCLCore/__main__.py b/GMCLCore/__main__.py new file mode 100644 index 0000000..05c5749 --- /dev/null +++ b/GMCLCore/__main__.py @@ -0,0 +1 @@ +# Silence is gold \ No newline at end of file diff --git a/GMCLCore/__pycache__/__init__.cpython-37.pyc b/GMCLCore/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..495a1eb Binary files /dev/null and b/GMCLCore/__pycache__/__init__.cpython-37.pyc differ diff --git a/GMCLCore/__pycache__/config.cpython-37.pyc b/GMCLCore/__pycache__/config.cpython-37.pyc new file mode 100644 index 0000000..7e96f89 Binary files /dev/null and b/GMCLCore/__pycache__/config.cpython-37.pyc differ diff --git a/GMCLCore/__pycache__/gaming.cpython-37.pyc b/GMCLCore/__pycache__/gaming.cpython-37.pyc new file mode 100644 index 0000000..52b9eb4 Binary files /dev/null and b/GMCLCore/__pycache__/gaming.cpython-37.pyc differ diff --git a/GMCLCore/__pycache__/log4py.cpython-37.pyc b/GMCLCore/__pycache__/log4py.cpython-37.pyc new file mode 100644 index 0000000..2c5d293 Binary files /dev/null and b/GMCLCore/__pycache__/log4py.cpython-37.pyc differ diff --git a/GMCLCore/__pycache__/main.cpython-37.pyc b/GMCLCore/__pycache__/main.cpython-37.pyc new file mode 100644 index 0000000..193ef84 Binary files /dev/null and b/GMCLCore/__pycache__/main.cpython-37.pyc differ diff --git a/GMCLCore/config.py b/GMCLCore/config.py new file mode 100644 index 0000000..7063136 --- /dev/null +++ b/GMCLCore/config.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# +# Ghink Minecraft Launcher +# Copyleft Ghink Network Studio +# Bigsk (https://www.xiaxinzhe.cn) +# See the LICENSE +# + +VERSION = ( + "Alpha", + (1, 0, 0) +) \ No newline at end of file diff --git a/GMCLCore/log4py.py b/GMCLCore/log4py.py new file mode 100644 index 0000000..cffe108 --- /dev/null +++ b/GMCLCore/log4py.py @@ -0,0 +1,162 @@ +import os, time, shutil +from threading import Thread + +class log(object): + def __init__(self, workdir): + ''' + Init vars and threads. + ''' + self.FATAL = "FATAL" + self.ERROR = "ERROR" + self.WARN = "WARN" + self.INFO = "INFO" + self.__levelMap = { + 'FATAL': self.FATAL, + 'ERROR': self.ERROR, + 'WARN': self.WARN, + 'INFO': self.INFO + } + if type(workdir) != str: + raise TypeError("Wrong type for param @workdir") + self.workdir = workdir + self.__logs = [] + if os.path.exists("{}\\logs".format(workdir)) and os.path.isfile("{}\\logs".format(workdir)): + guard = Thread(target = self.__daemon) + guard.start() + else: + try: + os.makedirs("{}\\logs".format(workdir), exist_ok = True) + daemon = Thread(target = self.__daemon) + daemon.daemon = True + daemon.start() + except: + raise PermissionError("Failed to operate the log file! ") + def __daemon(self): + ''' + Guard thread for recording logs and archiving. + ''' + workdir = "{}\\logs".format(self.workdir) + self.__suicide = False + def archive(workdir): + timeStamp = time.time() + logsList = [] + for fname in os.listdir(workdir): + if os.path.isfile("{}\\{}".format(workdir, fname)): + logsList.append("{}\\{}".format(workdir, fname)) + archiveList = [] + today = time.strftime("%Y-%m-%d", time.localtime(timeStamp)) + # yesterday = time.strftime("%Y-%m-%d", time.localtime(timeStamp - 86400)) + flag = False + for fname in logsList: + if os.path.basename(fname) != "{}.logs".format(today) and os.path.splitext(fname)[-1] == ".logs": + archiveList.append(fname) + flag = True + if flag: + self.info("Archiving logs.") + ''' + #Archive all logs before today in a single zip file + os.makedirs("{}\\{}".format(workdir,yesterday),exist_ok=True) + for fname in archiveList: + shutil.move(fname,"{}\\{}".format(workdir,yesterday)) + shutil.make_archive("{}\\{}".format(workdir,yesterday),"zip",workdir,yesterday) + shutil.rmtree("{}\\{}".format(workdir,yesterday)) + ''' + # Archive each log in independence zip file + for fname in archiveList: + basename = os.path.basename(fname) + shutil.make_archive("{}\\{}".format(workdir, os.path.splitext(basename)[0]), "zip", workdir, basename) + try: + os.remove("{}\\{}".format(workdir, basename)) + except: + pass + + Thread(target = archive, args = (workdir,)).start() + while True: + timeStamp = time.time() + today = time.strftime("%Y-%m-%d", time.localtime(timeStamp)) + while True: + with open("{}\\{}.logs".format(workdir,today),"a+") as fb: + data, self.__logs = self.__logs, [] + for log in data: + fb.write("[{}] [{}] {}\n".format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(log[0])), log[1], log[2])) + if self.__suicide or today != time.strftime("%Y-%m-%d", time.localtime()): + break + archive(workdir) + if self.__suicide: + break + def suicide(self): + ''' + Suicide the guard thread. + Before close the program, You have to exec this function. + ''' + self.__suicide = True + def record(self, level = "INFO", *content, split = " ", output = True): + ''' + Record logs. + @*content: The content for your log + @split: The split text for your each log + @level: The level for your log level + @output: Print the log or not + ''' + temp = [] + for con in content: + temp.append(str(con)) + content = split.join(temp) + if type(level) != str or level not in self.__levelMap.values(): + raise TypeError("Wrong type for param @level") + if type(output) != bool: + raise TypeError("Wrong type for param @output") + timeStamp = time.time() + self.__logs.append((timeStamp, level.upper(), content)) + if output: + print("[{}] [{}] {}".format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timeStamp)), level.upper(), content)) + def info(self, *content, split = " ", output = True): + ''' + Record logs for info level. + @*content: The content for your log + @split: The split text for your each log + @output: Print the log or not + ''' + temp = [] + for con in content: + temp.append(str(con)) + content = split.join(temp) + self.record("INFO", content, split = split, output = output) + def warn(self, *content, split = " ", output = True): + ''' + Record logs for warn level. + @*content: The content for your log + @split: The split text for your each log + @output: Print the log or not + ''' + temp = [] + for con in content: + temp.append(str(con)) + content = split.join(temp) + self.record("WARN", content, split = split, output = output) + def error(self, *content, split = " ", output = True): + ''' + Record logs for error level. + @*content: The content for your log + @split: The split text for your each log + @output: Print the log or not + ''' + temp = [] + for con in content: + temp.append(str(con)) + content = split.join(temp) + self.record("ERROR", content, split = split, output = output) + def fatal(self, *content, split = " ", output = True): + ''' + Record logs for fatal level. + @*content: The content for your log + @split: The split text for your each log + @output: Print the log or not + ''' + temp = [] + for con in content: + temp.append(str(con)) + content = split.join(temp) + self.record("FATAL", content, split = split, output = output) + self.__suicide = True + raise Exception(content) \ No newline at end of file diff --git a/GMCLCore/main.py b/GMCLCore/main.py new file mode 100644 index 0000000..f1dfea5 --- /dev/null +++ b/GMCLCore/main.py @@ -0,0 +1,161 @@ +# -*- coding: utf-8 -*- +# +# ________ _____ _________ .____ _________ +# / _____/ / \ \_ ___ \| | \_ ___ \ ___________ ____ +# / \ ___ / \ / \/ \ \/| | / \ \/ / _ \_ __ _/ __ \ +# \ \_\ / Y \ \___| |__\ \___( <_> | | \\ ___/ +# \______ \____|__ /\______ |_______ \______ /\____/|__| \___ > +# \/ \/ \/ \/ \/ \/ +# +# Ghink Minecraft Launcher +# Copyleft Ghink Network Studio +# Bigsk (https://www.xiaxinzhe.cn) +# See the LICENSE +# + +# Standard +import os, platform, hashlib, requests +import urllib.request, urllib.parse +from threading import Thread +# Extend +import psutil +# Self +import GMCLCore.log4py as log4py +from GMCLCore.config import * + +class Core(object): + + # Define constant + ARIA = "ARIA" + + OFFICIAL = "OFFICIAL" + BMCLAPI = "BMCLAPI" + + OFFLINE = "OFFLINE" + MOJANG = "MOJANG" + MICROSOFT = "MICROSOFT" + + def __init__(self, workDir = ".gmclcore"): + # Define constant + self.ENV_SOURCE = "https://resource.ghink.net/application/rely" + + # Define launcher vars + self.__name= "GMCLCore" + self.__version = "{} {}".format(VERSION[0], ".".join(str(c) for c in VERSION[1])) + self.__workDir = workDir + self.__system = platform.system() + self.parallel = psutil.cpu_count() + self.parallelType = self.ARIA + self.useragent = "{}/{}".format(self.__name, self.__version) + + # Create workdir + os.makedirs(self.__workDir, exist_ok = True) + if self.__system == "Windows": + import win32api, win32con + win32api.SetFileAttributes(self.__workDir, win32con.FILE_ATTRIBUTE_HIDDEN) + + # Init log object + self.l = log4py.log(self.__workDir) + + # Define default game vars + self.gameDir = os.path.join(os.path.dirname(__file__), ".minecraft") + self.javaPath = self.searchJava() + self.gameMem = self.autoMemory() + self.authType = self.OFFLINE + self.id = "Steve" + self.uuid = self.generateUUID(self.id) + + # Prepare running env + self.l.info("Initing running env...") + self.initEnv() + + # Create daemon thread + self.l.info("Creating daemon thread...") + self.__daemonThread = Thread(target = self.__daemon) + self.__daemonThread.daemon = True + self.__daemonThread.start() + + def initEnv(self): + os.makedirs(os.path.join(self.__workDir, "env"), exist_ok = True) + if self.networkTest(): + source = self.urljoin(self.ENV_SOURCE, "aria2c") + if self.__system == "Windows": + if "64" in platform.machine(): + self.__ariaPath = os.path.join(self.__workDir, "env", "aria2c64.exe") + source = self.urljoin(source, "win64") + elif "32" in platform.machine() or "86" in platform.machine(): + self.__ariaPath = os.path.join(self.__workDir, "env", "aria2c32.exe") + source = self.urljoin(source, "win32") + else: + self.l.fatal("Unsupported processor architecture! ") + if not os.path.exists(self.__ariaPath): + with open(self.__ariaPath, "wb") as fb: + try: + content = requests.get(self.urljoin(source, "aria2c.exe"), headers = {"user-agent": self.useragent}).content + fb.write(content) + except Exception as e: + self.l.warn("Failed to install running env aria2c! System return: {}".format(e)) + elif self.__system == "Linux": + self.__ariaPath = self.urljoin(self.__workDir, "env", "aria2c") + source = self.urljoin(source, "linux") + if not os.path.exists(self.__ariaPath): + with open(self.__ariaPath, "wb") as fb: + try: + content = requests.get(self.urljoin(source, "aria2c"), headers = {"user-agent": self.useragent}).content + fb.write(content) + except Exception as e: + self.l.warn("Failed to install running env aria2c! System return: {}".format(e)) + elif self.__system == "Darwin": + self.__ariaPath = self.urljoin(self.__workDir, "env", "aria2c") + source = self.urljoin(source, "darwin") + if not os.path.exists(self.__ariaPath): + with open(self.__ariaPath, "wb") as fb: + try: + content = requests.get(self.urljoin(source, "aria2c"), headers = {"user-agent": self.useragent}).content + fb.write(content) + except Exception as e: + self.l.warn("Failed to install running env aria2c! System return: {}".format(e)) + + def __daemon(self): + while True: + pass + + def urljoin(self, *args: str): + result = os.path.join(*args) + for i in range(result.count("\\")): + result = result.replace("\\", "/") + return result + + def networkTest(self, source = r"https://www.baidu.com", retry = 3): + flag = False + for i in range(retry): + try: + fp = urllib.request.urlopen(source) + fp.read(100).decode() + fp.close() + except: + pass + else: + flag = True + return flag + + def searchJava(self): + javaEnv = os.environ.get("Path", None) if self.__system == "Windows" else os.environ.get("PATH", None) + if javaEnv: + javaEnv = javaEnv.split(";") if self.__system == "Windows" else javaEnv.split(":") + for j in javaEnv: + for name in ("Java", "java", "JAVA", "Jre", "jre", "JRE"): + if name in j: + java = j + merge = os.path.join(java, "javaw.exe" if self.__system == "Windows" else "java") + if os.path.exists(merge): + return merge + + def autoMemory(self): + return 0.8 * (psutil.virtual_memory().free / 1024 ** 2) + + def generateUUID(self, id): + result = hashlib.md5() + result.update("".join(('OfflinePlayer:', id)).encode()) + result = result.hexdigest() + return result \ No newline at end of file diff --git a/LICENSE b/LICENSE index b14ca0a..553ac20 100644 --- a/LICENSE +++ b/LICENSE @@ -1,165 +1,21 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 +The MIT License (MIT) - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. +Copyright (c) 2014-present Ghink Network Studio +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 1afc793..7dda28f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -# Ghink Minecraft Launcher Core - -#### 介绍 -开源的我的世界Java Edition Python 启动器核心 - -#### 帮助 +# Ghink Minecraft Launcher Core + +#### 介绍 +开源的我的世界Java Edition Python 启动器核心 + +#### 帮助 帮助文档正在准备中 \ No newline at end of file diff --git a/Test.py b/Test.py index b9b7b33..b299800 100644 --- a/Test.py +++ b/Test.py @@ -1,8 +1,5 @@ -from GMCLCore import * -launcher=GMCLCore() - -launcher.EnableAriaDownload() -launcher.EnableAutoLogPrint() -launcher.Download("http://mirrors.163.com/kali-images/kali-weekly/kali-linux-2020-W47-installer-netinst-i386.iso","test.iso") - -launcher.PrintAllLog() \ No newline at end of file + +import platform, subprocess, urllib.parse, os, requests +import GMCLCore + +Core = GMCLCore.Core() \ No newline at end of file diff --git a/old/0.1.0/config.json b/old/0.1.0/config.json index 5a60e07..7ec86f7 100644 --- a/old/0.1.0/config.json +++ b/old/0.1.0/config.json @@ -1,8 +1,8 @@ -{ - "name":"Ghink Minecraft Launcher Core", - "default_launcher_name":"GMCLCore", - "version":"0.1.0", - "useragent":" (GMCL Core Alpha 0.1.0;Alpha)", - "logs_path":"logs", - "return_mode":"directly" +{ + "name":"Ghink Minecraft Launcher Core", + "default_launcher_name":"GMCLCore", + "version":"0.1.0", + "useragent":" (GMCL Core Alpha 0.1.0;Alpha)", + "logs_path":"logs", + "return_mode":"directly" } \ No newline at end of file diff --git a/old/0.1.0/gmclc.py b/old/0.1.0/gmclc.py index 24bb67f..c71fb47 100644 --- a/old/0.1.0/gmclc.py +++ b/old/0.1.0/gmclc.py @@ -1,731 +1,731 @@ -import os,requests,json,time,sys,argparse,psutil,string,platform,glob,getpass,shutil,hashlib,random,subprocess,math,zipfile - -#-------------------------------------------------------# - -#Environment Setup Area. - -#Set Global Var. -Log='[Logs Output]' -number=0 -source=json.loads('["https://bmclapi2.bangbang93.com","https://download.mcbbs.net","https://gemcapi.ghink.net/?path=","https://download.minebbs.com/?path="]') -#Read Config File. -config_open=open("config.json", mode='r') -config_json=config_open.read() -config_open.close() -try: - config=json.loads(config_json) - config_status=True -except: - config_status=False -Log=Log + '\n' + "[Program]" + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]Starting to read config file.' -if(config_status==True): - Log=Log + '\n' + "[" + config['name'] + "]" + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]Read config successfully.' -else: - Log=Log + '\n' + "[Program]" + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[ERROR]Read config failed.' - Log=Log + '\n' + "[Program]" + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[WARN]There is a deadly error,the program will stop soon.' - Log=Log + '\n' + "[Program]" + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]Starting to save log.' - if os.path.exists('logs'): - Log=Log + '\n' + "[Program]" + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]The dir logs has already existed.Nothing to do.' - else: - Log=Log + '\n' + "[Program]" + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]The dir logs does not exist.The program will create one.' - os.makedirs('logs') - logs_output=open('logs/' + str(time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.txt'),mode='w') - logs_output.write(Log + '\n' + "[Program]" + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]Save logs successfully.' + '\n' + "[Program]" + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[WARN]Please check if the json is right.') - logs_output.close() - sys.exit(0) -#Get Parameter. -parser=argparse.ArgumentParser() -parser.add_argument("--launcher_name", help="The name of the launcher.") -parser.add_argument("--launcher_version", help="The version of the launcher.") -parser.add_argument("--type", help="The type of task,{\"launcher_game\",\"search_file\",\"get_game_version_list\",\"get_java_path\",\"get_system_memory\",\"get_online_source_list\",\"install_online_source\",\"get_uuid\",\"download_file\",\"clean_logs\",\"clean_temp\",\"clean\",\"clean_logs_without_output\",\"clean_without_output\"}") -parser.add_argument("--copyright", help="The copyright of the game,true of false.The default is false.") -#Launcher Game Parameter Area. -#Search File Area. -parser.add_argument("--file_name", help="The name of file which you want to search.") -parser.add_argument("--file_dir", help="The dir of file which you want to search.") -#True Copyright. -parser.add_argument("--email", help="The email of game account.(If your game is genuine,you have to input this parameter.)") -parser.add_argument("--password", help="The password of game account.(If your game is genuine,you have to input this parameter.") -#False Copyright. -parser.add_argument("--id", help="The id of game.(If your game is not genuine,you have to input this parameter.)") -#Get Game Version List Area. -parser.add_argument("--game_dir", help="The dir of your game.If you not input this parameter,the GMCL Core will use the Mojang's Launcher's game dir.") -#Get System Memory Area. -parser.add_argument("--memory_data_type", help="The data type of memory that will return.{\"free\",\"used\",\"total\",\"auto\"}") -parser.add_argument("--memory_data_unit", help="The data unit of memory that will return,the default unit is B.{\"MB\",\"KB\",\"GB\",\"B\",\"TB\"}") -#Get Online Resources List Area. -parser.add_argument("--online_resources_list_type", help="The online resources type of list,you have to input a json there.{\"tree_number\":int,") -parser.add_argument("--online_resources_list_return_type", help="The return data type of return data of online resources,the default is json.{\"json\"}") -#Install online Source Area. -parser.add_argument("--install_online_resources_type", help="The online resources type of which resources you want to install,you have to input a json there.") -parser.add_argument("--install_online_resources_id", help="The online resources id of which resources you want to install.") -parser.add_argument("--install_online_resources_dir", help="The game dir which you want to install to.") -#Download Resources Area. -parser.add_argument("--download_url", help="The file url of resources which you want download.If you want to download multi files,you have to input json like:{\"number\":10,\"url\":[\"example1.com\",\"example2.com\"]} and {\"number\":10,\"path\":[\"\\usr\\root\\home\\Desktop\\1\",\"\\usr\\root\\home\\Desktop\\2\"]}") -parser.add_argument("--download_path", help="The save path of resources which you want download.") -#Get System Java Path Area. -parser.add_argument("--number_of_java", help="How many java path(s) you want to return.Do not set the number too big,it will cost a lot of time and system performance.") -#Global Parameter Area. -parser.add_argument("--source", help="The source of online resources.If you want to use mix mode,you have to input a json like:{\"mode\":\"mix\",\"source\":{\"number\":number,\"source\":[\"source_1\",\"source_2\"]}}or not input anything.{\"bmclapi\",\"gemcapi\",\"minebbs\",\"mojang\",\"mix\"}") -parser.add_argument("--memory", help="The memory that could be used by game.You should input with unit,if you send a null parameter,the core will get java path automatically.") -parser.add_argument("--java", help="The java path of the system,if you send a null parameter,the core will get java path automatically.") -parser.add_argument("--parameter", help="The excess parameter that launcher game need.") -parser.add_argument("--dir", help="The game dir,if you send a null parameter,the core will use Mojang's Launcher's game dir.") -parser.add_argument("--version", help="The game version.") -parser.add_argument("--uuid", help="Your UUID,you can input your UUID by your self,this parameter isn't must,the core will generate one automatically.There's two mode you can use to generate UUID.The default mode is gmclc.If you want to use other mode,for example:hmcl mode,just input \"hmcl\" there.{\"hmcl\",\"gmclc\"}") -parser=parser.parse_args() -#Set Parameter into Var. -if(parser.launcher_name==None): - launcher_name=config['default_launcher_name'] -else: - launcher_name=parser.launcher_name -if(parser.launcher_version==None): - launcher_version=config['version'] -else: - launcher_version=parser.launcher_version -if(parser.number_of_java==None): - number_of_java=1 -else: - try: - number_of_java=int(parser.number_of_java) - except: - number_of_java="" -if(parser.game_dir==None): - game_dir='C:\\Users\\' + str(getpass.getuser()) + '\\AppData\\Roaming\\.minecraft' -else: - game_dir=parser.game_dir - -#Set Config Into Var. -UA={'User-Agent':launcher_name + '/' + launcher_version + config['useragent']} -name=config['name'] -logs_head="[" + config['name'] + "]" - -#-------------------------------------------------------# - -#Sub_Program Area. -def log(log_type,logvar): - global Log - global name - global logs_head - if(log_type=="info"): - log_type="INFO" - elif(log_type=="warn"): - log_type="WARN" - elif(log_type=="error"): - log_type="ERROR" - Log=Log + '\n' + logs_head + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[' + log_type + ']' + logvar -def return_data(return_d): - if(config['return_mode']=='directly'): - print(return_d) - elif(config['return_mode']=='json'): - if(check_json(return_d)): - print('{"return":' + return_d + ',"logs":"' + Log.replace('\n','\\n') + '"}') - else: - print('{"return":"' + return_d + '","logs":"' + Log.replace('\n','\\n') + '"}') -def launcher_true(email,password,memory,java,parameter,dir,version): - pass -def launcher_false(id,memory,java,parameter,dir,version): - pass -def download_resources(type,assembly,version): - pass -def check_json(input_str): - try: - json.loads(input_str) - return True - except: - return False -def download(url, dirpath): - global Log - global UA - global name - log("info",'The ' + name + ' is downloading the file ' + dirpath + '.') - try: - download=requests.get(url, headers=UA) - with open(dirpath,"wb") as code: - code.write(download.content) - except: - log("error",'There has a error in task while downloading the file ' + dirpath + ' from ' + url + '.') - else: - log("info",'The file ' + dirpath + ' has been downloaded successfully.') -def make_dir_exist(dirpath): - global Log - global name - if os.path.exists(dirpath): - log("info",'The dir ' + dirpath + ' has already existed.Nothing to do.') - else: - log("info",'The dir ' + dirpath + ' does not exist.The ' + name + ' will create one.') - os.makedirs(dirpath) -def memory(return_type): - if(return_type=="free"): - return psutil.virtual_memory().free - elif(return_type=="used"): - return psutil.virtual_memory().used - elif(return_type=="total"): - return psutil.virtual_memory().total - elif(return_type=="auto"): - return 0.8 * psutil.virtual_memory().free -def error_output_log(logpath): - global Log - global logs_head - logs_output=open(logpath + '/' + str(time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.txt'),mode='w') - logs_output.write(Log + '\n' + logs_head + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]Save logs successfully.' + '\n' + logs_head + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[WARN]Please check if the parameter is right.') - logs_output.close() -def deadly_error(): - log("warn","There is a deadly error,the program will stop soon.") - make_dir_exist('logs') - error_output_log('logs') - sys.exit(0) -def search_java_windows_temp(path,tagfile): - global number - for ipath in os.listdir(path): - fulldir = os.path.join(path,ipath) - if(os.path.isfile(fulldir)): - if(tagfile in os.path.split(fulldir)[1]): - print(fulldir) - number=number+1 - if(os.path.isdir(fulldir)): - try: - search_java_windows_temp(fulldir,tagfile) - except: - pass - if(parser.number_of_java=="all"): - pass - elif(number==number_of_java): - break -def search_files(path,tagfile): - global number - for ipath in os.listdir(path): - fulldir = os.path.join(path,ipath) - if(os.path.isfile(fulldir)): - if(tagfile in os.path.split(fulldir)[1]): - print(fulldir) - number=number+1 - if(os.path.isdir(fulldir)): - try: - search_files(fulldir,tagfile) - except: - pass -def get_uuid(id,g_type): - if(g_type=='hmcl'): - return_i='OfflinePlayer:' + id - md5=hashlib.md5() - md5.update(return_i.encode(encoding='utf-8')) - return md5.hexdigest() - elif(g_type=='gmclc'): - result=id - for i in range(0,len(id)): - md5=hashlib.md5() - md5.update(result.encode(encoding='utf-8')) - result=md5.hexdigest() - return result -def make_file_exist(file,url): - if(parser.source==None): - num=random.randint(0,3) - domain=source[num] - if(num==0): - source_type=0 - elif(num==1): - source_type=0 - elif(num==2): - source_type=1 - elif(num==3): - source_type=1 - elif(parser.source=='mix'): - num=random.randint(0,3) - domain=source[num] - if(num==0): - source_type=0 - elif(num==1): - source_type=0 - elif(num==2): - source_type=1 - elif(num==3): - source_type=1 - elif(parser.source=='bmclapi'): - domain=source[0] - source_type=0 - elif(parser.source=='mcbbs'): - domain=source[1] - source_type=0 - elif(parser.source=='gemcapi'): - domain=source[2] - source_type=1 - elif(parser.source=='minebbs'): - domain=source[3] - source_type=1 - elif(parser.source=='mojang'): - source_type=2 - try: - f=open(file) - f.close() - except: - if(source_type==2): - os.system("python gmclc.py --type download_file --download_url " + url + " --download_path " + file) - return_data('Downloading ' + url + ' to ' + file + '.') - elif(source_type==0): - url=url.replace('https://libraries.minecraft.net','https://gemcapi.ghink.net/?path=minecraft/libraries') - os.system("python gmclc.py --type download_file --download_url " + url + " --download_path " + file) - return_data('Downloading ' + url + ' to ' + file + '.') - elif(source_type==1): - url=url.replace('https://libraries.minecraft.net','https://gemcapi.ghink.net/?path=minecraft/libraries') - os.system("python gmclc.py --type download_file --download_url " + url + " --download_path " + file) - return_data('Downloading ' + url + ' to ' + file + '.') -def unzip(src,dir): - uz=zipfile.ZipFile(src,'r') - for file in uz.namelist(): - try: - uz.extract(file,dir) - except: - pass - -#-------------------------------------------------------# - -#Make Dir Area. -make_dir_exist("temp") - -#-------------------------------------------------------# - -#Use Statistics Area. -open_s=requests.get('https://open.gmclc.statistics.ghink.net', headers=UA) - -#-------------------------------------------------------# - -log("info","Start to deal the tasks that need to do.") -if(parser.type=="download_file"): - log("info","Download file(s) mode.") - try: - try: - urljson=json.loads(parser.download_url) - pathjson=json.loads(parser.download_path) - if(urljson['number']==pathjson['number']): - count=0 - for i in range(0,urljson['number']): - try: - filepath=pathjson['path'][count] - dirpath=filepath.replace(os.path.basename(filepath),"") - make_dir_exist(dirpath) - download(urljson['url'][count],filepath) - except: - log("error","Some errors happened while downloading files,please check and try again.") - count=count+1 - else: - log("error","The file(s) number is not same!We can't download the file(s).") - deadly_error() - except: - try: - dirpath=parser.download_path.replace(os.path.basename(parser.download_path),"") - make_dir_exist(dirpath) - download(parser.download_url,parser.download_path) - except: - log("error","Some errors happened while downloading files,please check and try again.") - deadly_error() - except: - log("error","Some errors happened.We can't download the file(s),please check if the parameter you input is correct.") - deadly_error() -elif(parser.type=="get_system_memory"): - log("info","Get system memory mode.") - try: - if(parser.memory_data_type=="free"): - memory_data=memory("free") - elif(parser.memory_data_type=="used"): - memory_data=memory("used") - elif(parser.memory_data_type=="total"): - memory_data=memory("total") - elif(parser.memory_data_type=="auto"): - memory_data=memory("auto") - else: - log("error","We can't get the memory data,please check if the parameter you input is coreect.") - deadly_error() - if(parser.memory_data_unit==None): - log("info","Return:" + str(memory_data) + '.') - return_data(str(memory_data)) - elif(parser.memory_data_unit=="B"): - log("info","Return:" + str(memory_data) + '.') - return_data(str(memory_data)) - elif(parser.memory_data_unit=="KB"): - log("info","Return:" + str(memory_data / 1024) + '.') - return_data(str(memory_data / 1024)) - elif(parser.memory_data_unit=="MB"): - log("info","Return:" + str(memory_data / 1024 / 1024) + '.') - return_data(str(memory_data / 1024 / 1024)) - elif(parser.memory_data_unit=="GB"): - log("info","Return:" + str(memory_data / 1024 / 1024 / 1024) + '.') - return_data(str(memory_data / 1024 / 1024 / 1024)) - elif(parser.memory_data_unit=="TB"): - log("info","Return:" + str(memory_data / 1024 / 1024 / 1024 / 1024) + '.') - return_data(str(memory_data / 1024 / 1024 / 1024 / 1024)) - except: - log("error","Some errors happened.We can't get the memory data,please check if the parameter you input is correct.") - deadly_error() -elif(parser.type=="search_file"): - log("info","Search file mode.") - if(parser.file_name==None): - log("error","There has a error while search file,you can't let the parameter \"file_name\" be \"None\",please check is the parameter input correct.") - else: - search_files(parser.file_dir,parser.file_name) -elif(parser.type=="get_uuid"): - log("info","Get UUID mode.") - if(parser.id==None): - return_data('There has a error in parameters you input,please check if the parameter "id" is correct.') - log('error','There has a error in parameters you input,please check if the parameter "id" is correct.') - deadly_error() - else: - if(parser.uuid==None): - uuid=get_uuid(parser.id,'gmclc') - elif(parser.uuid=='gmclc'): - uuid=get_uuid(parser.id,'gmclc') - elif(parser.uuid=='hmcl'): - uuid=get_uuid(parser.id,'hmcl') - else: - return_data('There has a error in parameters you input,please check if the parameter "uuid" is correct.') - log('error','There has a error in parameters you input,please check if the parameter "uuid" is correct.') - deadly_error() - print(uuid) -elif(parser.type=="get_java_path"): - log("info","Get system java environment path mode.") - if(platform.system()=='Windows'): - return_info=os.popen('python gmclc.py --type temp_1 --number_of_java ' + str(number_of_java)) - return_i=return_info.read() - return_info.close() - with open('temp/temp-3.gmclc', 'w') as file_object: - file_object.write(return_i) - number=0 - count = len(open('temp/temp-3.gmclc', 'r').readlines()) - for line in open("temp/temp-3.gmclc"): - number=number+1 - with open('temp/temp-4.gmclc', 'a') as file_object: - if(number==count): - if(count==1): - file_object.write(line.replace("\n","")) - else: - file_object.write(line.replace("\n","") + '"]') - elif(number==1): - file_object.write('["' + line.replace("\n","") + '","') - else: - file_object.write(line.replace("\n","") + '","') - return_data(open("temp/temp-4.gmclc",'r').read()) - os.remove('temp/temp-3.gmclc') - os.remove('temp/temp-4.gmclc') - else: - return_data('java') -elif(parser.type=="get_game_version_list"): - log("info","Get game versions list mode.") - if(platform.system()=='Windows'): - return_info=os.popen('python gmclc.py --type search_file --file_name ".json" --file_dir "' + game_dir + '\\versions"') - return_i=return_info.read() - return_info.close() - with open('temp/temp-1.gmclc', 'w') as file_object: - file_object.write(return_i) - number=0 - count = len(open('temp/temp-1.gmclc', 'r').readlines()) - for line in open("temp/temp-1.gmclc"): - number=number+1 - with open('temp/temp-2.gmclc', 'a') as file_object: - if(number==count): - if(count==1): - file_object.write('"' + line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n','') + '"') - else: - file_object.write(line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n','') + '"]') - elif(number==1): - file_object.write('["' + line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n','') + '","') - else: - file_object.write(line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n','') + '","') - return_data(open("temp/temp-2.gmclc",'r').read()) - os.remove('temp/temp-1.gmclc') - os.remove('temp/temp-2.gmclc') - else: - if(parser.game_dir==None): - log('Your system is UNIX or Linux,we can\'t use the Mojang\'s Launcher\'s game dir,please enter your game path and try again.') - else: - return_info=os.popen('python gmclc.py --type search_file --file_name ".json" --file_dir "' + game_dir + '\\versions"') - return_i=return_info.read() - return_info.close() - with open('temp/temp-1.gmclc', 'w') as file_object: - file_object.write(return_i) - number=0 - count = len(open('temp/temp-1.gmclc', 'r').readlines()) - for line in open("temp/temp-1.gmclc"): - number=number+1 - with open('temp/temp-2.gmclc', 'a+') as file_object: - if(number==count): - file_object.write(line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n','') + '"]') - elif(number==1): - file_object.write('["' + line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n','') + '","') - else: - file_object.write(line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n','') + '","') - return_data(open("temp/temp-2.gmclc",'r').read()) - os.remove('temp/temp-1.gmclc') - os.remove('temp/temp-2.gmclc') -elif(parser.type=="clean_logs"): - log("info","Clean logs mode.") - log("info","Cleaning logs......") - try: - shutil.rmtree("logs") - except: - log("error","Cleaning logs error.") -elif(parser.type=="clean_temp"): - log("info","Clean temp mode.") - log("info","Cleaning temp......") - try: - shutil.rmtree("temp") - except: - log("error","Cleaning temp error.") -elif(parser.type=="clean"): - log("info","Clean file mode.") - log("info","Cleaning file......") - try: - shutil.rmtree("logs") - except: - log("error","Cleaning logs error.") - try: - shutil.rmtree("temp") - except: - log("error","Cleaning temp error.") -elif(parser.type=="clean_without_output"): - log("info","Clean file mode.") - log("info","Cleaning file......") - try: - shutil.rmtree("logs") - except: - pass - try: - shutil.rmtree("temp") - except: - pass - sys.exit(0) -elif(parser.type=="clean_logs_without_output"): - log("info","Clean logs mode.") - log("info","Cleaning logs......") - try: - shutil.rmtree("logs") - except: - pass - sys.exit(0) -elif(parser.type=="launcher_game"): - log("info","Launcher game mode.") - return_data('Checking game dir.') - log('info','Checking game dir.') - if(parser.dir==None): - if(platform.system()=='Windows'): - dir_i='C:\\Users\\' + str(getpass.getuser()) + '\\AppData\\Roaming\\.minecraft' - else: - return_data('Your system is UNIX or Linux,we can\'t use the Mojang\'s Launcher\'s game dir,please enter your game path and try again.') - log('error','Your system is UNIX or Linux,we can\'t use the Mojang\'s Launcher\'s game dir,please enter your game path and try again.') - deadly_error() - else: - dir_i=parser.dir - return_data('Checking game copyright.') - log('info','Checking game copyright.') - if(parser.copyright==None): - if(parser.id==None): - return_data('There has a error in parameters you input,please check if the parameter "id" is correct.') - log('error','There has a error in parameters you input,please check if the parameter "id" is correct.') - deadly_error() - else: - return_data('Checking player uuid.') - log('info','Checking player uuid.') - if(parser.uuid==None): - uuid=get_uuid(parser.id,'gmclc') - elif(parser.uuid=='gmclc'): - uuid=get_uuid(parser.id,'gmclc') - elif(parser.uuid=='hmcl'): - uuid=get_uuid(parser.id,'hmcl') - elif(len(parser.uuid)==32): - uuid=parser.uuid - else: - return_data('There has a error in parameters you input,please check if the parameter "uuid" is correct.') - log('error','There has a error in parameters you input,please check if the parameter "uuid" is correct.') - deadly_error() - access_token=uuid - id_i=parser.id - elif(parser.copyright=='false'): - if(parser.id==None): - return_data('There has a error in parameters you input,please check if the parameter "id" is correct.') - log('error','There has a error in parameters you input,please check if the parameter "id" is correct.') - deadly_error() - else: - return_data('Checking player uuid.') - log('info','Checking player uuid.') - if(parser.uuid==None): - uuid=get_uuid(parser.id,'gmclc') - elif(parser.uuid=='gmclc'): - uuid=get_uuid(parser.id,'gmclc') - elif(parser.uuid=='hmcl'): - uuid=get_uuid(parser.id,'hmcl') - elif(len(parser.uuid)==32): - uuid=parser.uuid - else: - return_data('There has a error in parameters you input,please check if the parameter "uuid" is correct.') - log('error','There has a error in parameters you input,please check if the parameter "uuid" is correct.') - deadly_error() - access_token=uuid - id_i=parser.id - elif(parser.copyright=='true'): - if(parser.email==None): - return_data('There has a error in parameters you input,please check if the parameter "email" is correct.') - log('error','There has a error in parameters you input,please check if the parameter "email" is correct.') - deadly_error() - elif(parser.email.count('@')==1): - email=parser.email - else: - return_data('There has a error in parameters you input,please check if the parameter "email" is correct.') - log('error','There has a error in parameters you input,please check if the parameter "email" is correct.') - deadly_error() - if(parser.password==None): - return_data('There has a error in parameters you input,please check if the parameter "password" is correct.') - log('error','There has a error in parameters you input,please check if the parameter "password" is correct.') - deadly_error() - else: - password=parser.password - if(json.loads(requests.get('https://authserver.mojang.com/', headers=UA).text)['Status']=='OK'): - rq_r=json.loads(requests.post('https://authserver.mojang.com/authenticate', '{"agent": {"name": "Minecraft","version": 1},"username": "' + parser.email + '","password": "' + parser.password + '"}', headers=UA).text) - access_token=rq_r['accessToken'] - id_i=rq_r['selectedProfile']['name'] - uuid=rq_r['selectedProfile']['id'] - else: - return_data('There has a error while login to mojang account,the auth server has failed.') - log('error','There has a error while login to mojang account,the auth server has failed.') - deadly_error() - return_data('Checking game version(s).') - log('info','Checking game version(s).') - if(parser.version==None): - return_data('There has a error in parameters you input,please check if the parameter "version" is correct.') - log('error','There has a error in parameters you input,please check if the parameter "version" is correct.') - deadly_error() - else: - return_info=os.popen('python gmclc.py --type get_game_version_list --game_dir "' + dir_i) - return_i=return_info.read() - if(return_i.count('"' + parser.version + '"')!=0): - game_config_open=open(dir_i + '\\versions\\' + parser.version + '\\' + parser.version + '.json',encoding='UTF-8') - game_config_json=game_config_open.read() - game_config_open.close() - game_config=json.loads(game_config_json) - return_data('Checking game files.') - log('info','Checking game files.') - number=0 - for i in range(0,game_config_json.count('"path"')): - try: - make_file_exist(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['artifact']['path'].replace('/','\\'),game_config['libraries'][number]['downloads']['artifact']['url']) - if(platform.system()=='Windows'): - try: - make_file_exist(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['classifiers']['natives-windows']['path'].replace('/','\\'),game_config['libraries'][number]['downloads']['classifiers']['natives-windows']['url']) - except: - try: - make_file_exist(dir_i + '\\libraries\\' + game_config['patches'][0]['libraries'][number]['downloads']['classifiers']['natives-windows']['path'].replace('/','\\'),game_config['patches'][0]['libraries'][number]['downloads']['classifiers']['natives-windows']['url']) - except: - pass - elif(platform.system()=='Linux'): - try: - make_file_exist(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['classifiers']['natives-linux']['path'].replace('/','\\'),game_config['libraries'][number]['downloads']['classifiers']['natives-linux']['url']) - except: - try: - make_file_exist(dir_i + '\\libraries\\' + game_config['patches'][0]['libraries'][number]['downloads']['classifiers']['natives-linux']['path'].replace('/','\\'),game_config['patches'][0]['libraries'][number]['downloads']['classifiers']['natives-linux']['url']) - except: - pass - else: - try: - make_file_exist(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['classifiers']['natives-macos']['path'].replace('/','\\'),game_config['libraries'][number]['downloads']['classifiers']['natives-macos']['url']) - except: - try: - make_file_exist(dir_i + '\\libraries\\' + game_config['patches'][0]['libraries'][number]['downloads']['classifiers']['natives-macos']['path'].replace('/','\\'),game_config['patches'][0]['libraries'][number]['downloads']['classifiers']['natives-macos']['url']) - except: - pass - except: - pass - number=number+1 - if(os.path.isdir(dir_i + '\\versions\\' + parser.version + '\\natives')): - pass - else: - make_dir_exist(dir_i + '\\versions\\' + parser.version + '\\natives') - number=0 - for i in range(0,game_config_json.count('"path"')): - if(platform.system()=='Windows'): - try: - unzip(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['classifiers']['natives-windows']['path'].replace('/','\\'),dir_i + '\\versions\\' + parser.version + '\\natives') - except: - try: - unzip(dir_i + '\\libraries\\' + game_config['patches'][0]['libraries'][number]['downloads']['classifiers']['natives-windows']['path'].replace('/','\\'),dir_i + '\\versions\\' + parser.version + '\\natives') - except: - pass - elif(platform.system()=='Linux'): - try: - unzip(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['classifiers']['natives-linux']['path'].replace('/','\\'),dir_i + '\\versions\\' + parser.version + '\\natives') - except: - try: - unzip(dir_i + '\\libraries\\' + game_config['patches'][0]['libraries'][number]['downloads']['classifiers']['natives-linux']['path'].replace('/','\\'),dir_i + '\\versions\\' + parser.version + '\\natives') - except: - pass - else: - try: - unzip(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['classifiers']['natives-macos']['path'].replace('/','\\'),dir_i + '\\versions\\' + parser.version + '\\natives') - except: - try: - unzip(dir_i + '\\libraries\\' + game_config['patches'][0]['libraries'][number]['downloads']['classifiers']['natives-macos']['path'].replace('/','\\'),dir_i + '\\versions\\' + parser.version + '\\natives') - except: - pass - number=number+1 - cp="" - number=0 - for i in range(0,game_config_json.count('"path"')): - try: - cp=cp + dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['artifact']['path'].replace('/','\\') + ';' - except: - try: - cp=cp + dir_i + '\\libraries\\' + game_config['patches'][0]['libraries'][number]['downloads']['artifact']['path'].replace('/','\\') + ';' - except: - pass - number=number+1 - cp=cp + dir_i + '\\versions\\' + parser.version + '\\' + parser.version + '.jar' - return_data('Checking java environment.') - log('info','Checking java environment.') - if(parser.java==None): - return_info=os.popen('python gmclc.py --type get_java_path') - java=return_info.read() - return_info.close() - elif(os.path.exists(parser.java)): - java=parser.java - else: - return_data('The java program you input is not exist!Please check if the parameter you input is correct!') - log('error','The java program you input is not exist!Please check if the parameter you input is correct!') - deadly_error() - return_data('Checking memory parameter.') - log('info','Checking memory parameter.') - if(parser.memory==None): - return_info=os.popen('python gmclc.py --type get_system_memory --memory_data_type auto --memory_data_unit MB') - memory=str(math.ceil(float(return_info.read().replace("\n","")))) + "m" - return_info.close() - else: - memory=parser.memory - try: - asset_index=game_config['assetIndex']['id'] - except: - asset_index=game_config['patches'][0]['assetIndex']['id'] - command='\"' + java.replace('\n','') + '\" -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=16M -XX:-UseAdaptiveSizePolicy -XX:-OmitStackTraceInFastThrow -Xmn128m -Xmx' + memory + ' -Dfml.ignoreInvalidMinecraftCertificates=true -Dfml.ignorePatchDiscrepancies=true -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Djava.library.path=' + dir_i + '\\versions\\' + parser.version + '\\natives -Dminecraft.launcher.brand=' + config['default_launcher_name'] + ' -Dminecraft.launcher.version=' + config['version'] + ' -cp ' + cp + ' net.minecraft.client.main.Main --username ' + id_i + ' --version "' + config['default_launcher_name'] + ' ' + config['version'] + '" --gameDir ' + dir_i + ' --assetsDir ' + dir_i + '\\assets --assetIndex ' + asset_index + ' --uuid ' + uuid + ' --accessToken ' + access_token + ' --userProperties {} --userType mojang --versionType "' + config['default_launcher_name'] + ' ' + config['version'] + '" --tweakClass cpw.mods.fml.common.launcher.FMLTweaker' - subprocess.Popen(command, shell=True) - open_s=requests.get('https://launch.gmclc.statistics.ghink.net', headers=UA) - #print(command) - else: - return_data('The version you input is not exist!Please check if the parameter you input is correct!') - log('error','The vversion you input is not exist!Please check if the parameter you input is correct!') - deadly_error() - -#-------------------------------------------------------# - - -#-------------------------------------------------------# - -#Temp Mode Area. -elif(parser.type=="temp_1"):#Get java mode temp - search_java_windows_temp('C:\\Program Files\\Java\\','javaw.exe') - -#-------------------------------------------------------# - -#Starting To Save Logs. -log("info",'Starting to save logs.') -try: - make_dir_exist("logs") -except: - pass -logs_output=open('logs/' + str(time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.txt'),mode='w') -logs_output.write(Log + '\n' + logs_head + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]Save logs successfully.' + '\n' + logs_head + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]The task has done successfully.') -logs_output.close() +import os,requests,json,time,sys,argparse,psutil,string,platform,glob,getpass,shutil,hashlib,random,subprocess,math,zipfile + +#-------------------------------------------------------# + +#Environment Setup Area. + +#Set Global Var. +Log='[Logs Output]' +number=0 +source=json.loads('["https://bmclapi2.bangbang93.com","https://download.mcbbs.net","https://gemcapi.ghink.net/?path=","https://download.minebbs.com/?path="]') +#Read Config File. +config_open=open("config.json", mode='r') +config_json=config_open.read() +config_open.close() +try: + config=json.loads(config_json) + config_status=True +except: + config_status=False +Log=Log + '\n' + "[Program]" + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]Starting to read config file.' +if(config_status==True): + Log=Log + '\n' + "[" + config['name'] + "]" + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]Read config successfully.' +else: + Log=Log + '\n' + "[Program]" + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[ERROR]Read config failed.' + Log=Log + '\n' + "[Program]" + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[WARN]There is a deadly error,the program will stop soon.' + Log=Log + '\n' + "[Program]" + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]Starting to save log.' + if os.path.exists('logs'): + Log=Log + '\n' + "[Program]" + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]The dir logs has already existed.Nothing to do.' + else: + Log=Log + '\n' + "[Program]" + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]The dir logs does not exist.The program will create one.' + os.makedirs('logs') + logs_output=open('logs/' + str(time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.txt'),mode='w') + logs_output.write(Log + '\n' + "[Program]" + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]Save logs successfully.' + '\n' + "[Program]" + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[WARN]Please check if the json is right.') + logs_output.close() + sys.exit(0) +#Get Parameter. +parser=argparse.ArgumentParser() +parser.add_argument("--launcher_name", help="The name of the launcher.") +parser.add_argument("--launcher_version", help="The version of the launcher.") +parser.add_argument("--type", help="The type of task,{\"launcher_game\",\"search_file\",\"get_game_version_list\",\"get_java_path\",\"get_system_memory\",\"get_online_source_list\",\"install_online_source\",\"get_uuid\",\"download_file\",\"clean_logs\",\"clean_temp\",\"clean\",\"clean_logs_without_output\",\"clean_without_output\"}") +parser.add_argument("--copyright", help="The copyright of the game,true of false.The default is false.") +#Launcher Game Parameter Area. +#Search File Area. +parser.add_argument("--file_name", help="The name of file which you want to search.") +parser.add_argument("--file_dir", help="The dir of file which you want to search.") +#True Copyright. +parser.add_argument("--email", help="The email of game account.(If your game is genuine,you have to input this parameter.)") +parser.add_argument("--password", help="The password of game account.(If your game is genuine,you have to input this parameter.") +#False Copyright. +parser.add_argument("--id", help="The id of game.(If your game is not genuine,you have to input this parameter.)") +#Get Game Version List Area. +parser.add_argument("--game_dir", help="The dir of your game.If you not input this parameter,the GMCL Core will use the Mojang's Launcher's game dir.") +#Get System Memory Area. +parser.add_argument("--memory_data_type", help="The data type of memory that will return.{\"free\",\"used\",\"total\",\"auto\"}") +parser.add_argument("--memory_data_unit", help="The data unit of memory that will return,the default unit is B.{\"MB\",\"KB\",\"GB\",\"B\",\"TB\"}") +#Get Online Resources List Area. +parser.add_argument("--online_resources_list_type", help="The online resources type of list,you have to input a json there.{\"tree_number\":int,") +parser.add_argument("--online_resources_list_return_type", help="The return data type of return data of online resources,the default is json.{\"json\"}") +#Install online Source Area. +parser.add_argument("--install_online_resources_type", help="The online resources type of which resources you want to install,you have to input a json there.") +parser.add_argument("--install_online_resources_id", help="The online resources id of which resources you want to install.") +parser.add_argument("--install_online_resources_dir", help="The game dir which you want to install to.") +#Download Resources Area. +parser.add_argument("--download_url", help="The file url of resources which you want download.If you want to download multi files,you have to input json like:{\"number\":10,\"url\":[\"example1.com\",\"example2.com\"]} and {\"number\":10,\"path\":[\"\\usr\\root\\home\\Desktop\\1\",\"\\usr\\root\\home\\Desktop\\2\"]}") +parser.add_argument("--download_path", help="The save path of resources which you want download.") +#Get System Java Path Area. +parser.add_argument("--number_of_java", help="How many java path(s) you want to return.Do not set the number too big,it will cost a lot of time and system performance.") +#Global Parameter Area. +parser.add_argument("--source", help="The source of online resources.If you want to use mix mode,you have to input a json like:{\"mode\":\"mix\",\"source\":{\"number\":number,\"source\":[\"source_1\",\"source_2\"]}}or not input anything.{\"bmclapi\",\"gemcapi\",\"minebbs\",\"mojang\",\"mix\"}") +parser.add_argument("--memory", help="The memory that could be used by game.You should input with unit,if you send a null parameter,the core will get java path automatically.") +parser.add_argument("--java", help="The java path of the system,if you send a null parameter,the core will get java path automatically.") +parser.add_argument("--parameter", help="The excess parameter that launcher game need.") +parser.add_argument("--dir", help="The game dir,if you send a null parameter,the core will use Mojang's Launcher's game dir.") +parser.add_argument("--version", help="The game version.") +parser.add_argument("--uuid", help="Your UUID,you can input your UUID by your self,this parameter isn't must,the core will generate one automatically.There's two mode you can use to generate UUID.The default mode is gmclc.If you want to use other mode,for example:hmcl mode,just input \"hmcl\" there.{\"hmcl\",\"gmclc\"}") +parser=parser.parse_args() +#Set Parameter into Var. +if(parser.launcher_name==None): + launcher_name=config['default_launcher_name'] +else: + launcher_name=parser.launcher_name +if(parser.launcher_version==None): + launcher_version=config['version'] +else: + launcher_version=parser.launcher_version +if(parser.number_of_java==None): + number_of_java=1 +else: + try: + number_of_java=int(parser.number_of_java) + except: + number_of_java="" +if(parser.game_dir==None): + game_dir='C:\\Users\\' + str(getpass.getuser()) + '\\AppData\\Roaming\\.minecraft' +else: + game_dir=parser.game_dir + +#Set Config Into Var. +UA={'User-Agent':launcher_name + '/' + launcher_version + config['useragent']} +name=config['name'] +logs_head="[" + config['name'] + "]" + +#-------------------------------------------------------# + +#Sub_Program Area. +def log(log_type,logvar): + global Log + global name + global logs_head + if(log_type=="info"): + log_type="INFO" + elif(log_type=="warn"): + log_type="WARN" + elif(log_type=="error"): + log_type="ERROR" + Log=Log + '\n' + logs_head + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[' + log_type + ']' + logvar +def return_data(return_d): + if(config['return_mode']=='directly'): + print(return_d) + elif(config['return_mode']=='json'): + if(check_json(return_d)): + print('{"return":' + return_d + ',"logs":"' + Log.replace('\n','\\n') + '"}') + else: + print('{"return":"' + return_d + '","logs":"' + Log.replace('\n','\\n') + '"}') +def launcher_true(email,password,memory,java,parameter,dir,version): + pass +def launcher_false(id,memory,java,parameter,dir,version): + pass +def download_resources(type,assembly,version): + pass +def check_json(input_str): + try: + json.loads(input_str) + return True + except: + return False +def download(url, dirpath): + global Log + global UA + global name + log("info",'The ' + name + ' is downloading the file ' + dirpath + '.') + try: + download=requests.get(url, headers=UA) + with open(dirpath,"wb") as code: + code.write(download.content) + except: + log("error",'There has a error in task while downloading the file ' + dirpath + ' from ' + url + '.') + else: + log("info",'The file ' + dirpath + ' has been downloaded successfully.') +def make_dir_exist(dirpath): + global Log + global name + if os.path.exists(dirpath): + log("info",'The dir ' + dirpath + ' has already existed.Nothing to do.') + else: + log("info",'The dir ' + dirpath + ' does not exist.The ' + name + ' will create one.') + os.makedirs(dirpath) +def memory(return_type): + if(return_type=="free"): + return psutil.virtual_memory().free + elif(return_type=="used"): + return psutil.virtual_memory().used + elif(return_type=="total"): + return psutil.virtual_memory().total + elif(return_type=="auto"): + return 0.8 * psutil.virtual_memory().free +def error_output_log(logpath): + global Log + global logs_head + logs_output=open(logpath + '/' + str(time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.txt'),mode='w') + logs_output.write(Log + '\n' + logs_head + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]Save logs successfully.' + '\n' + logs_head + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[WARN]Please check if the parameter is right.') + logs_output.close() +def deadly_error(): + log("warn","There is a deadly error,the program will stop soon.") + make_dir_exist('logs') + error_output_log('logs') + sys.exit(0) +def search_java_windows_temp(path,tagfile): + global number + for ipath in os.listdir(path): + fulldir = os.path.join(path,ipath) + if(os.path.isfile(fulldir)): + if(tagfile in os.path.split(fulldir)[1]): + print(fulldir) + number=number+1 + if(os.path.isdir(fulldir)): + try: + search_java_windows_temp(fulldir,tagfile) + except: + pass + if(parser.number_of_java=="all"): + pass + elif(number==number_of_java): + break +def search_files(path,tagfile): + global number + for ipath in os.listdir(path): + fulldir = os.path.join(path,ipath) + if(os.path.isfile(fulldir)): + if(tagfile in os.path.split(fulldir)[1]): + print(fulldir) + number=number+1 + if(os.path.isdir(fulldir)): + try: + search_files(fulldir,tagfile) + except: + pass +def get_uuid(id,g_type): + if(g_type=='hmcl'): + return_i='OfflinePlayer:' + id + md5=hashlib.md5() + md5.update(return_i.encode(encoding='utf-8')) + return md5.hexdigest() + elif(g_type=='gmclc'): + result=id + for i in range(0,len(id)): + md5=hashlib.md5() + md5.update(result.encode(encoding='utf-8')) + result=md5.hexdigest() + return result +def make_file_exist(file,url): + if(parser.source==None): + num=random.randint(0,3) + domain=source[num] + if(num==0): + source_type=0 + elif(num==1): + source_type=0 + elif(num==2): + source_type=1 + elif(num==3): + source_type=1 + elif(parser.source=='mix'): + num=random.randint(0,3) + domain=source[num] + if(num==0): + source_type=0 + elif(num==1): + source_type=0 + elif(num==2): + source_type=1 + elif(num==3): + source_type=1 + elif(parser.source=='bmclapi'): + domain=source[0] + source_type=0 + elif(parser.source=='mcbbs'): + domain=source[1] + source_type=0 + elif(parser.source=='gemcapi'): + domain=source[2] + source_type=1 + elif(parser.source=='minebbs'): + domain=source[3] + source_type=1 + elif(parser.source=='mojang'): + source_type=2 + try: + f=open(file) + f.close() + except: + if(source_type==2): + os.system("python gmclc.py --type download_file --download_url " + url + " --download_path " + file) + return_data('Downloading ' + url + ' to ' + file + '.') + elif(source_type==0): + url=url.replace('https://libraries.minecraft.net','https://gemcapi.ghink.net/?path=minecraft/libraries') + os.system("python gmclc.py --type download_file --download_url " + url + " --download_path " + file) + return_data('Downloading ' + url + ' to ' + file + '.') + elif(source_type==1): + url=url.replace('https://libraries.minecraft.net','https://gemcapi.ghink.net/?path=minecraft/libraries') + os.system("python gmclc.py --type download_file --download_url " + url + " --download_path " + file) + return_data('Downloading ' + url + ' to ' + file + '.') +def unzip(src,dir): + uz=zipfile.ZipFile(src,'r') + for file in uz.namelist(): + try: + uz.extract(file,dir) + except: + pass + +#-------------------------------------------------------# + +#Make Dir Area. +make_dir_exist("temp") + +#-------------------------------------------------------# + +#Use Statistics Area. +open_s=requests.get('https://open.gmclc.statistics.ghink.net', headers=UA) + +#-------------------------------------------------------# + +log("info","Start to deal the tasks that need to do.") +if(parser.type=="download_file"): + log("info","Download file(s) mode.") + try: + try: + urljson=json.loads(parser.download_url) + pathjson=json.loads(parser.download_path) + if(urljson['number']==pathjson['number']): + count=0 + for i in range(0,urljson['number']): + try: + filepath=pathjson['path'][count] + dirpath=filepath.replace(os.path.basename(filepath),"") + make_dir_exist(dirpath) + download(urljson['url'][count],filepath) + except: + log("error","Some errors happened while downloading files,please check and try again.") + count=count+1 + else: + log("error","The file(s) number is not same!We can't download the file(s).") + deadly_error() + except: + try: + dirpath=parser.download_path.replace(os.path.basename(parser.download_path),"") + make_dir_exist(dirpath) + download(parser.download_url,parser.download_path) + except: + log("error","Some errors happened while downloading files,please check and try again.") + deadly_error() + except: + log("error","Some errors happened.We can't download the file(s),please check if the parameter you input is correct.") + deadly_error() +elif(parser.type=="get_system_memory"): + log("info","Get system memory mode.") + try: + if(parser.memory_data_type=="free"): + memory_data=memory("free") + elif(parser.memory_data_type=="used"): + memory_data=memory("used") + elif(parser.memory_data_type=="total"): + memory_data=memory("total") + elif(parser.memory_data_type=="auto"): + memory_data=memory("auto") + else: + log("error","We can't get the memory data,please check if the parameter you input is coreect.") + deadly_error() + if(parser.memory_data_unit==None): + log("info","Return:" + str(memory_data) + '.') + return_data(str(memory_data)) + elif(parser.memory_data_unit=="B"): + log("info","Return:" + str(memory_data) + '.') + return_data(str(memory_data)) + elif(parser.memory_data_unit=="KB"): + log("info","Return:" + str(memory_data / 1024) + '.') + return_data(str(memory_data / 1024)) + elif(parser.memory_data_unit=="MB"): + log("info","Return:" + str(memory_data / 1024 / 1024) + '.') + return_data(str(memory_data / 1024 / 1024)) + elif(parser.memory_data_unit=="GB"): + log("info","Return:" + str(memory_data / 1024 / 1024 / 1024) + '.') + return_data(str(memory_data / 1024 / 1024 / 1024)) + elif(parser.memory_data_unit=="TB"): + log("info","Return:" + str(memory_data / 1024 / 1024 / 1024 / 1024) + '.') + return_data(str(memory_data / 1024 / 1024 / 1024 / 1024)) + except: + log("error","Some errors happened.We can't get the memory data,please check if the parameter you input is correct.") + deadly_error() +elif(parser.type=="search_file"): + log("info","Search file mode.") + if(parser.file_name==None): + log("error","There has a error while search file,you can't let the parameter \"file_name\" be \"None\",please check is the parameter input correct.") + else: + search_files(parser.file_dir,parser.file_name) +elif(parser.type=="get_uuid"): + log("info","Get UUID mode.") + if(parser.id==None): + return_data('There has a error in parameters you input,please check if the parameter "id" is correct.') + log('error','There has a error in parameters you input,please check if the parameter "id" is correct.') + deadly_error() + else: + if(parser.uuid==None): + uuid=get_uuid(parser.id,'gmclc') + elif(parser.uuid=='gmclc'): + uuid=get_uuid(parser.id,'gmclc') + elif(parser.uuid=='hmcl'): + uuid=get_uuid(parser.id,'hmcl') + else: + return_data('There has a error in parameters you input,please check if the parameter "uuid" is correct.') + log('error','There has a error in parameters you input,please check if the parameter "uuid" is correct.') + deadly_error() + print(uuid) +elif(parser.type=="get_java_path"): + log("info","Get system java environment path mode.") + if(platform.system()=='Windows'): + return_info=os.popen('python gmclc.py --type temp_1 --number_of_java ' + str(number_of_java)) + return_i=return_info.read() + return_info.close() + with open('temp/temp-3.gmclc', 'w') as file_object: + file_object.write(return_i) + number=0 + count = len(open('temp/temp-3.gmclc', 'r').readlines()) + for line in open("temp/temp-3.gmclc"): + number=number+1 + with open('temp/temp-4.gmclc', 'a') as file_object: + if(number==count): + if(count==1): + file_object.write(line.replace("\n","")) + else: + file_object.write(line.replace("\n","") + '"]') + elif(number==1): + file_object.write('["' + line.replace("\n","") + '","') + else: + file_object.write(line.replace("\n","") + '","') + return_data(open("temp/temp-4.gmclc",'r').read()) + os.remove('temp/temp-3.gmclc') + os.remove('temp/temp-4.gmclc') + else: + return_data('java') +elif(parser.type=="get_game_version_list"): + log("info","Get game versions list mode.") + if(platform.system()=='Windows'): + return_info=os.popen('python gmclc.py --type search_file --file_name ".json" --file_dir "' + game_dir + '\\versions"') + return_i=return_info.read() + return_info.close() + with open('temp/temp-1.gmclc', 'w') as file_object: + file_object.write(return_i) + number=0 + count = len(open('temp/temp-1.gmclc', 'r').readlines()) + for line in open("temp/temp-1.gmclc"): + number=number+1 + with open('temp/temp-2.gmclc', 'a') as file_object: + if(number==count): + if(count==1): + file_object.write('"' + line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n','') + '"') + else: + file_object.write(line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n','') + '"]') + elif(number==1): + file_object.write('["' + line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n','') + '","') + else: + file_object.write(line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n','') + '","') + return_data(open("temp/temp-2.gmclc",'r').read()) + os.remove('temp/temp-1.gmclc') + os.remove('temp/temp-2.gmclc') + else: + if(parser.game_dir==None): + log('Your system is UNIX or Linux,we can\'t use the Mojang\'s Launcher\'s game dir,please enter your game path and try again.') + else: + return_info=os.popen('python gmclc.py --type search_file --file_name ".json" --file_dir "' + game_dir + '\\versions"') + return_i=return_info.read() + return_info.close() + with open('temp/temp-1.gmclc', 'w') as file_object: + file_object.write(return_i) + number=0 + count = len(open('temp/temp-1.gmclc', 'r').readlines()) + for line in open("temp/temp-1.gmclc"): + number=number+1 + with open('temp/temp-2.gmclc', 'a+') as file_object: + if(number==count): + file_object.write(line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n','') + '"]') + elif(number==1): + file_object.write('["' + line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n','') + '","') + else: + file_object.write(line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n','') + '","') + return_data(open("temp/temp-2.gmclc",'r').read()) + os.remove('temp/temp-1.gmclc') + os.remove('temp/temp-2.gmclc') +elif(parser.type=="clean_logs"): + log("info","Clean logs mode.") + log("info","Cleaning logs......") + try: + shutil.rmtree("logs") + except: + log("error","Cleaning logs error.") +elif(parser.type=="clean_temp"): + log("info","Clean temp mode.") + log("info","Cleaning temp......") + try: + shutil.rmtree("temp") + except: + log("error","Cleaning temp error.") +elif(parser.type=="clean"): + log("info","Clean file mode.") + log("info","Cleaning file......") + try: + shutil.rmtree("logs") + except: + log("error","Cleaning logs error.") + try: + shutil.rmtree("temp") + except: + log("error","Cleaning temp error.") +elif(parser.type=="clean_without_output"): + log("info","Clean file mode.") + log("info","Cleaning file......") + try: + shutil.rmtree("logs") + except: + pass + try: + shutil.rmtree("temp") + except: + pass + sys.exit(0) +elif(parser.type=="clean_logs_without_output"): + log("info","Clean logs mode.") + log("info","Cleaning logs......") + try: + shutil.rmtree("logs") + except: + pass + sys.exit(0) +elif(parser.type=="launcher_game"): + log("info","Launcher game mode.") + return_data('Checking game dir.') + log('info','Checking game dir.') + if(parser.dir==None): + if(platform.system()=='Windows'): + dir_i='C:\\Users\\' + str(getpass.getuser()) + '\\AppData\\Roaming\\.minecraft' + else: + return_data('Your system is UNIX or Linux,we can\'t use the Mojang\'s Launcher\'s game dir,please enter your game path and try again.') + log('error','Your system is UNIX or Linux,we can\'t use the Mojang\'s Launcher\'s game dir,please enter your game path and try again.') + deadly_error() + else: + dir_i=parser.dir + return_data('Checking game copyright.') + log('info','Checking game copyright.') + if(parser.copyright==None): + if(parser.id==None): + return_data('There has a error in parameters you input,please check if the parameter "id" is correct.') + log('error','There has a error in parameters you input,please check if the parameter "id" is correct.') + deadly_error() + else: + return_data('Checking player uuid.') + log('info','Checking player uuid.') + if(parser.uuid==None): + uuid=get_uuid(parser.id,'gmclc') + elif(parser.uuid=='gmclc'): + uuid=get_uuid(parser.id,'gmclc') + elif(parser.uuid=='hmcl'): + uuid=get_uuid(parser.id,'hmcl') + elif(len(parser.uuid)==32): + uuid=parser.uuid + else: + return_data('There has a error in parameters you input,please check if the parameter "uuid" is correct.') + log('error','There has a error in parameters you input,please check if the parameter "uuid" is correct.') + deadly_error() + access_token=uuid + id_i=parser.id + elif(parser.copyright=='false'): + if(parser.id==None): + return_data('There has a error in parameters you input,please check if the parameter "id" is correct.') + log('error','There has a error in parameters you input,please check if the parameter "id" is correct.') + deadly_error() + else: + return_data('Checking player uuid.') + log('info','Checking player uuid.') + if(parser.uuid==None): + uuid=get_uuid(parser.id,'gmclc') + elif(parser.uuid=='gmclc'): + uuid=get_uuid(parser.id,'gmclc') + elif(parser.uuid=='hmcl'): + uuid=get_uuid(parser.id,'hmcl') + elif(len(parser.uuid)==32): + uuid=parser.uuid + else: + return_data('There has a error in parameters you input,please check if the parameter "uuid" is correct.') + log('error','There has a error in parameters you input,please check if the parameter "uuid" is correct.') + deadly_error() + access_token=uuid + id_i=parser.id + elif(parser.copyright=='true'): + if(parser.email==None): + return_data('There has a error in parameters you input,please check if the parameter "email" is correct.') + log('error','There has a error in parameters you input,please check if the parameter "email" is correct.') + deadly_error() + elif(parser.email.count('@')==1): + email=parser.email + else: + return_data('There has a error in parameters you input,please check if the parameter "email" is correct.') + log('error','There has a error in parameters you input,please check if the parameter "email" is correct.') + deadly_error() + if(parser.password==None): + return_data('There has a error in parameters you input,please check if the parameter "password" is correct.') + log('error','There has a error in parameters you input,please check if the parameter "password" is correct.') + deadly_error() + else: + password=parser.password + if(json.loads(requests.get('https://authserver.mojang.com/', headers=UA).text)['Status']=='OK'): + rq_r=json.loads(requests.post('https://authserver.mojang.com/authenticate', '{"agent": {"name": "Minecraft","version": 1},"username": "' + parser.email + '","password": "' + parser.password + '"}', headers=UA).text) + access_token=rq_r['accessToken'] + id_i=rq_r['selectedProfile']['name'] + uuid=rq_r['selectedProfile']['id'] + else: + return_data('There has a error while login to mojang account,the auth server has failed.') + log('error','There has a error while login to mojang account,the auth server has failed.') + deadly_error() + return_data('Checking game version(s).') + log('info','Checking game version(s).') + if(parser.version==None): + return_data('There has a error in parameters you input,please check if the parameter "version" is correct.') + log('error','There has a error in parameters you input,please check if the parameter "version" is correct.') + deadly_error() + else: + return_info=os.popen('python gmclc.py --type get_game_version_list --game_dir "' + dir_i) + return_i=return_info.read() + if(return_i.count('"' + parser.version + '"')!=0): + game_config_open=open(dir_i + '\\versions\\' + parser.version + '\\' + parser.version + '.json',encoding='UTF-8') + game_config_json=game_config_open.read() + game_config_open.close() + game_config=json.loads(game_config_json) + return_data('Checking game files.') + log('info','Checking game files.') + number=0 + for i in range(0,game_config_json.count('"path"')): + try: + make_file_exist(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['artifact']['path'].replace('/','\\'),game_config['libraries'][number]['downloads']['artifact']['url']) + if(platform.system()=='Windows'): + try: + make_file_exist(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['classifiers']['natives-windows']['path'].replace('/','\\'),game_config['libraries'][number]['downloads']['classifiers']['natives-windows']['url']) + except: + try: + make_file_exist(dir_i + '\\libraries\\' + game_config['patches'][0]['libraries'][number]['downloads']['classifiers']['natives-windows']['path'].replace('/','\\'),game_config['patches'][0]['libraries'][number]['downloads']['classifiers']['natives-windows']['url']) + except: + pass + elif(platform.system()=='Linux'): + try: + make_file_exist(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['classifiers']['natives-linux']['path'].replace('/','\\'),game_config['libraries'][number]['downloads']['classifiers']['natives-linux']['url']) + except: + try: + make_file_exist(dir_i + '\\libraries\\' + game_config['patches'][0]['libraries'][number]['downloads']['classifiers']['natives-linux']['path'].replace('/','\\'),game_config['patches'][0]['libraries'][number]['downloads']['classifiers']['natives-linux']['url']) + except: + pass + else: + try: + make_file_exist(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['classifiers']['natives-macos']['path'].replace('/','\\'),game_config['libraries'][number]['downloads']['classifiers']['natives-macos']['url']) + except: + try: + make_file_exist(dir_i + '\\libraries\\' + game_config['patches'][0]['libraries'][number]['downloads']['classifiers']['natives-macos']['path'].replace('/','\\'),game_config['patches'][0]['libraries'][number]['downloads']['classifiers']['natives-macos']['url']) + except: + pass + except: + pass + number=number+1 + if(os.path.isdir(dir_i + '\\versions\\' + parser.version + '\\natives')): + pass + else: + make_dir_exist(dir_i + '\\versions\\' + parser.version + '\\natives') + number=0 + for i in range(0,game_config_json.count('"path"')): + if(platform.system()=='Windows'): + try: + unzip(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['classifiers']['natives-windows']['path'].replace('/','\\'),dir_i + '\\versions\\' + parser.version + '\\natives') + except: + try: + unzip(dir_i + '\\libraries\\' + game_config['patches'][0]['libraries'][number]['downloads']['classifiers']['natives-windows']['path'].replace('/','\\'),dir_i + '\\versions\\' + parser.version + '\\natives') + except: + pass + elif(platform.system()=='Linux'): + try: + unzip(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['classifiers']['natives-linux']['path'].replace('/','\\'),dir_i + '\\versions\\' + parser.version + '\\natives') + except: + try: + unzip(dir_i + '\\libraries\\' + game_config['patches'][0]['libraries'][number]['downloads']['classifiers']['natives-linux']['path'].replace('/','\\'),dir_i + '\\versions\\' + parser.version + '\\natives') + except: + pass + else: + try: + unzip(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['classifiers']['natives-macos']['path'].replace('/','\\'),dir_i + '\\versions\\' + parser.version + '\\natives') + except: + try: + unzip(dir_i + '\\libraries\\' + game_config['patches'][0]['libraries'][number]['downloads']['classifiers']['natives-macos']['path'].replace('/','\\'),dir_i + '\\versions\\' + parser.version + '\\natives') + except: + pass + number=number+1 + cp="" + number=0 + for i in range(0,game_config_json.count('"path"')): + try: + cp=cp + dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['artifact']['path'].replace('/','\\') + ';' + except: + try: + cp=cp + dir_i + '\\libraries\\' + game_config['patches'][0]['libraries'][number]['downloads']['artifact']['path'].replace('/','\\') + ';' + except: + pass + number=number+1 + cp=cp + dir_i + '\\versions\\' + parser.version + '\\' + parser.version + '.jar' + return_data('Checking java environment.') + log('info','Checking java environment.') + if(parser.java==None): + return_info=os.popen('python gmclc.py --type get_java_path') + java=return_info.read() + return_info.close() + elif(os.path.exists(parser.java)): + java=parser.java + else: + return_data('The java program you input is not exist!Please check if the parameter you input is correct!') + log('error','The java program you input is not exist!Please check if the parameter you input is correct!') + deadly_error() + return_data('Checking memory parameter.') + log('info','Checking memory parameter.') + if(parser.memory==None): + return_info=os.popen('python gmclc.py --type get_system_memory --memory_data_type auto --memory_data_unit MB') + memory=str(math.ceil(float(return_info.read().replace("\n","")))) + "m" + return_info.close() + else: + memory=parser.memory + try: + asset_index=game_config['assetIndex']['id'] + except: + asset_index=game_config['patches'][0]['assetIndex']['id'] + command='\"' + java.replace('\n','') + '\" -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=16M -XX:-UseAdaptiveSizePolicy -XX:-OmitStackTraceInFastThrow -Xmn128m -Xmx' + memory + ' -Dfml.ignoreInvalidMinecraftCertificates=true -Dfml.ignorePatchDiscrepancies=true -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Djava.library.path=' + dir_i + '\\versions\\' + parser.version + '\\natives -Dminecraft.launcher.brand=' + config['default_launcher_name'] + ' -Dminecraft.launcher.version=' + config['version'] + ' -cp ' + cp + ' net.minecraft.client.main.Main --username ' + id_i + ' --version "' + config['default_launcher_name'] + ' ' + config['version'] + '" --gameDir ' + dir_i + ' --assetsDir ' + dir_i + '\\assets --assetIndex ' + asset_index + ' --uuid ' + uuid + ' --accessToken ' + access_token + ' --userProperties {} --userType mojang --versionType "' + config['default_launcher_name'] + ' ' + config['version'] + '" --tweakClass cpw.mods.fml.common.launcher.FMLTweaker' + subprocess.Popen(command, shell=True) + open_s=requests.get('https://launch.gmclc.statistics.ghink.net', headers=UA) + #print(command) + else: + return_data('The version you input is not exist!Please check if the parameter you input is correct!') + log('error','The vversion you input is not exist!Please check if the parameter you input is correct!') + deadly_error() + +#-------------------------------------------------------# + + +#-------------------------------------------------------# + +#Temp Mode Area. +elif(parser.type=="temp_1"):#Get java mode temp + search_java_windows_temp('C:\\Program Files\\Java\\','javaw.exe') + +#-------------------------------------------------------# + +#Starting To Save Logs. +log("info",'Starting to save logs.') +try: + make_dir_exist("logs") +except: + pass +logs_output=open('logs/' + str(time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.txt'),mode='w') +logs_output.write(Log + '\n' + logs_head + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]Save logs successfully.' + '\n' + logs_head + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]The task has done successfully.') +logs_output.close() diff --git a/GMCLCore.py b/old/other/GMCLCore.py similarity index 98% rename from GMCLCore.py rename to old/other/GMCLCore.py index a1a12f2..f21fc4d 100644 --- a/GMCLCore.py +++ b/old/other/GMCLCore.py @@ -1,271 +1,271 @@ -#------------------# -import os,requests,json,time,sys,psutil,string,platform,glob,getpass,shutil,hashlib,random,subprocess,math,zipfile,threading -#------------------# -class GMCLCore(object): - '''The Main Class of the Launcher Core''' - #-----------------------------------------------------------------------# - #Class Functions - def __init__(self,LauncherName=None,LauncherVersion=None,LauncherConfig=None): - '''The global variable set function''' - ''':LauncherName The name of your launcher,the default value is "GMCLCore"''' - ''':LauncherVersion The version of your launcher,the default value is the version of core''' - ''':LauncherConfig The custom config you want to post in''' - CoreName="GMCLCore" - CoreVersion=("A0.2.0","Alpha") - LauncherName=CoreName if(LauncherName==None) else LauncherName - LauncherVersion=CoreVersion if(LauncherVersion==None) else LauncherVersion - LauncherConfig={} if(LauncherConfig==None) else LauncherConfig - self.__SystemConfig={ - "Core":{ - "Name":CoreName, - "Version":CoreVersion, - "Header":{'User-Agent':LauncherName+'/'+LauncherVersion[0]+' (('+CoreName+' '+CoreVersion[0]+';'+CoreVersion[1]+'))'}, - "Functions":{ - "Log":{ - "AutoPrint":False, - "ErrorOutput":False - }, - "Debug":False, - "Aria":False - }, - "Users":[] - }, - "Launcher":{ - "Name":LauncherName, - "Version":LauncherVersion, - "Config":LauncherConfig, - } - } - self.__Log=[] - self.__AuthWay="" - self.Log("info","Successful.","__init__") - #-----------------------------------------------------------------------# - #Log Functions - def Log(self,Type,Text,Function="Anonymous Function",ErrorType="TypeError"): - '''The function which was used to manager the log output system''' - ''':Type Type of the log info''' - ''':Text The main text of log info''' - ''':Function The function that cause the log,the default value is "Anonymous Function"''' - ''':Type The type of the error,the default value is "TypeError",Support "TypeError","ValueError","UserWarning"''' - if(Text!=""): - if(Type=="deadly"): - self.__Log.append(("DEADLY_ERROR",time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()),Function,Text,ErrorType)) - if(self.__SystemConfig["Core"]["Functions"]["Log"]["ErrorOutput"]): - self.MakeDir('.'+self.__SystemConfig["Launcher"]["Name"]+"\\logs") - self.OutputLog('.'+self.__SystemConfig["Launcher"]["Name"]+"\\logs\\"+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+".txt") - if(ErrorType=="TypeError"): - raise TypeError(Text) - elif(ErrorType=="ValueError"): - raise ValueError(Text) - else: - raise UserWarning(Text) - elif(Type=="info" or "warn" or "error"): - self.__Log.append((Type.upper(),time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()),Function,Text)) - if(self.__SystemConfig["Core"]["Functions"]["Log"]["AutoPrint"]==True): - print("["+Type.upper()+"]["+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+"]["+Function+"]"+Text) - return (Type.upper(),Text) - else: - self.__Log.append(("OTHER",time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()),Function,Text)) - if(self.__SystemConfig["Core"]["Functions"]["Log"]["AutoPrint"]==True): - print("[OTHER]["+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+"]["+Function+"]"+Text) - return ("OTHER",Text) - def OutputLog(self,Path): - '''The function which was used to output text file of program logs''' - if(os.path.isdir(Path)): - return self.Log("warn","Exist duplication name dir.","OutputLog") - else: - self.Log("info","Successful.","OutputLog") - with open(Path,"w+") as FileObject: - FileObject.write(self.__SystemConfig["Launcher"]["Name"]+"/"+self.__SystemConfig["Launcher"]["Version"][0]+" "+self.__SystemConfig["Launcher"]["Version"][1]+" | "+self.__CoreName+"/"+self.__CoreVersion[0]+" "+self.__CoreVersion[1]+" Logs "+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+"\n") - for text in self.__Log: - FileObject.write("["+text[0]+"]["+text[1]+"]["+text[2]+"]"+text[3]+"\n") - def ReturnLog(self): - '''The function which was used to return the list of program logs''' - self.Log("info","Successful.","ReturnLog") - return self.__Log - def PrintLastLog(self): - '''The function which was used to print the last logs of program''' - self.Log("info","Successful.","PrintLastLog") - print("["+self.__Log[-1][0]+"]["+self.__Log[-1][1]+"]["+self.__Log[-1][2]+"]"+self.__Log[-1][3]) - def PrintAllLog(self): - '''The function which was used to print all logs of program''' - self.Log("info","Successful.","PrintAllLog") - for text in self.__Log: - print("["+text[0]+"]["+text[1]+"]["+text[2]+"]"+text[3]) - def EnableAutoLogPrint(self): - '''The function which was used to enable the function of log auto print''' - self.__SystemConfig["Core"]["Functions"]["Log"]["AutoPrint"]=True - self.Log("info","Successful.","EnableAutoLogPrint") - def DisableAutoLogPrint(self): - '''The function which was used to disable the function of log auto print''' - self.__SystemConfig["Core"]["Functions"]["Log"]["AutoPrint"]=False - self.Log("info","Successful.","DisableAutoLogPrint") - def EnableErrorLogOutput(self): - '''The function which was used to enable the function of error log output''' - self.__SystemConfig["Core"]["Functions"]["Log"]["ErrorOutput"]=True - self.Log("info","Successful.","EnableErrorLogOutput") - def DisableErrorLogOutput(self): - '''The function which was used to disable the function of error log output''' - self.__SystemConfig["Core"]["Functions"]["Log"]["ErrorOutput"]=False - self.Log("info","Successful.","DisableErrorLogOutput") - #-----------------------------------------------------------------------# - #Download Functions - def Download(self,DownloadFrom,DownloadTo): - '''The multi-thread download function''' - ''':DownloadFrom The online url for the file''' - ''':DownloadTo The local path for the file''' - if(DownloadFrom=="" or DownloadTo==""): - self.Log("warn","Wrong online address or local address for download.","Download") - else: - StartTime=time.time() - FileSize=int(requests.head(DownloadFrom,headers=self.__SystemConfig["Core"]["Header"]).headers['Content-Length']) - if(self.__SystemConfig["Core"]["Functions"]["Aria"]==True): - if(platform.system()=="Windows"): - if(os.path.isfile('.'+self.__SystemConfig["Launcher"]["Name"]+"\\rely\\"+"aria2c.exe")): - os.system('.'+self.__SystemConfig["Launcher"]["Name"]+"\\rely\\"+"aria2c.exe -o "+DownloadTo+" "+DownloadFrom+" -U \""+self.__SystemConfig["Core"]["Header"]['User-Agent']+"\"") - else: - self.Log("warn","Missed Aria.","Download") - self.DownloadAriaWin() - os.system('.'+self.__SystemConfig["Launcher"]["Name"]+"\\rely\\"+"aria2c.exe -o "+DownloadTo+" "+DownloadFrom+" -U \""+self.__SystemConfig["Core"]["Header"]['User-Agent']+"\"") - else: - os.system('.'+self.__SystemConfig["Launcher"]["Name"]+"\\rely\\"+"aria2c.exe -o "+DownloadTo+" "+DownloadFrom+" -U \""+self.__SystemConfig["Core"]["Header"]['User-Agent']+"\"") - else: - with open(DownloadTo,"wb") as FileObject: - FileObject.write(requests.get(DownloadFrom).content) - self.Log("info","Success.","Download") - return (str(time.time()-StartTime),FileSize // (time.time()-StartTime)) - def DownloadAriaWin(self): - '''The function which was used to download Aria environment for windows''' - if(not os.path.isdir('.'+self.__SystemConfig["Launcher"]["Name"]+"\\rely")): - self.MakeDir('.'+self.__SystemConfig["Launcher"]["Name"]+"\\rely") - if(os.path.isdir("C:\\Program Files (x86)")): - with open('.'+self.__SystemConfig["Launcher"]["Name"]+"\\rely\\"+"aria2c.exe","wb") as FileObject: - FileObject.write(requests.get("https://resource.ghink.net/aria2c/win64/aria2c.exe",headers=self.__SystemConfig["Core"]["Header"]).content) - else: - with open('.'+self.__SystemConfig["Launcher"]["Name"]+"\\rely\\"+"aria2c.exe","wb") as FileObject: - FileObject.write(requests.get("https://resource.ghink.net/aria2c/win32/aria2c.exe",headers=self.__SystemConfig["Core"]["Header"]).content) - self.Log("info","Success.","DownloadAriaWin") - def EnableAria(self): - '''The function which was used to enable the function of Aria''' - self.__SystemConfig["Core"]["Functions"]["Aria"]=True - self.Log("info","Successful.","EnableAria") - def DisableAria(self): - '''The function which was used to disable the function of Aria''' - self.__SystemConfig["Core"]["Functions"]["Aria"]=False - self.Log("info","Successful.","DisbleAria") - #-----------------------------------------------------------------------# - #File and Dir Functions - def MakeDir(self,Path): - '''The function which was used to create a dir with determination''' - ''':Path The path of the dir you want to create''' - if(not os.path.isdir(Path)): - os.makedirs(Path) - self.Log("info","Successful.","MakeDir") - else: - return self.Log("warn","Exist.","MakeDir") - def SearchFile(self,Path,Tag,Depth=1): - '''The function which was used to search files''' - ''':Path The root path you want to search''' - ''':Tag The name keyword of the file you want to search''' - ''':Depth The depth of dir you want to search,you should set as "all" if you want to search all dirs,the default value is 1''' - List=[] - i=0 - for root,dirs,files in os.walk(Path,topdown=True): - if Tag in files: - i+=1 - List.append(root+'\\'+Tag) - if(i==Depth): - break - else: - pass - self.Log("info","Success.","SearchFile") - return List - #-----------------------------------------------------------------------# - #Game Environment Set Functions - def GetUUID(self,Account="Steve"): - '''The function which was used to generate UUID''' - ''':Account Your account,the default value is "Steve"''' - if(self.__AuthWay=="offline"): - result="OfflinePlayer:"+Account - md5=hashlib.md5() - md5.update(result.encode(encoding='utf-8')) - self.Log("info","Success.","GetUUID") - return md5.hexdigest() - else: - return self.Log("warn","Wrong auth way","GetUUID") - def GetJavaPath(self,Depth=1): - '''The function which was used to search java''' - ''':Depth The depth of dir you want to search,you should set as "all" if you want to search all dirs,the default value is 1''' - if(platform.system()=="Windows"): - self.Log("info","Success.","GetJavaPath") - return self.SearchFile('C:\\','javaw.exe',Depth) - elif(platform.system()=="Linux"): - self.Log("info","Success.","GetJavaPath") - return self.SearchFile('\\','java',Depth) - else: - self.Log("info","Success.","GetJavaPath") - return self.SearchFile('\\','java',Depth) - def SetAccount(self,Account="Steve",Password=""): - '''The function which was used to set game account data''' - ''':Account Your account,the default value is "Steve"''' - ''':Password Your password''' - if(self.__AuthWay=="online_mojang"): - if(Account.count("@")==1): - if(json.loads(requests.get("https://authserver.mojang.com/",headers=self.__SystemConfig["Core"]["Header"]).text)['status']=="OK"): - result=json.loads(requests.post("https://authserver.mojang.com/authenticate",'{"agent":{"name":"Minecraft","Version":1},"username":"'+Account+'","password":"'+Password+'"}',headers=self.__SystemConfig["Core"]["Header"]).text) - self.__Token=result['accessToken'] - self.__UUID=result['selectedProfile']['id'] - self.__ID=result['selectedProfile']['name'] - self.Log("info","Success.","GetAccount") - else: - return self.Log("warn","Fail to request Mojang\'s auth server.","SetAccount") - else: - return self.Log("warn","Wrong Account.","SetAccount") - elif(self.__AuthWay=="offline"): - if(Account.count("@")==1): - return self.Log("warn","Wrong Account.","SetAccount") - else: - self.__ID=Account - self.__UUID=self.GetUUID(Account) - self.__Token="" - self.Log("info","Success.","GetAccount") - else: - pass - def SetAuthWay(self,AuthWay): - '''The auth way set function''' - ''':AuthWay Your auth way,must be "offline" or "online"''' - if(AuthWay=="offline"): - self.__AuthWay="offline" - self.Log("info","Success.","SetAuthWay") - elif(AuthWay=="online"): - self.__AuthWay="online" - self.Log("info","Success.","SetAuthWay") - else: - return self.Log("warn","Wrong Auth Way.","SetAccount") - def SetRecomMem(self): - '''The recommendation memory value set function''' - self.__Memory = float(psutil.virtual_memory().free / 1024 ** 3) * 0.8 - self.Log("info","Success.","SetRecomMem") - def SetJavaPath(self,path): - '''The java path set function''' - ''':Path Your java path''' - if(path==None): - return self.Log("warn","Wrong local address for java.","SetJavaPath") - else: - if(os.path.exists(path)): - self.__JAVA=path - self.Log("info","Success.","SetJavaPath") - else: - return self.Log("warn","Wrong local address for java.","SetJavaPath") - def SetGameMem(self,Memory): - '''The game memory value set function''' - ''':Memory The memory of the game,the unit is GiBytes''' - try: - self.__Memory=float(Memory) - self.Log("info","Success.","SetGameMem") - except: - return self.Log("warn","Wrong parameter for game memory.","SetGameMem") - #-----------------------------------------------------------------------# - #Game Resouces Functions - #-----------------------------------------------------------------------# +#------------------# +import os,requests,json,time,sys,psutil,string,platform,glob,getpass,shutil,hashlib,random,subprocess,math,zipfile,threading +#------------------# +class GMCLCore(object): + '''The Main Class of the Launcher Core''' + #-----------------------------------------------------------------------# + #Class Functions + def __init__(self,LauncherName=None,LauncherVersion=None,LauncherConfig=None): + '''The global variable set function''' + ''':LauncherName The name of your launcher,the default value is "GMCLCore"''' + ''':LauncherVersion The version of your launcher,the default value is the version of core''' + ''':LauncherConfig The custom config you want to post in''' + CoreName="GMCLCore" + CoreVersion=("A0.2.0","Alpha") + LauncherName=CoreName if(LauncherName==None) else LauncherName + LauncherVersion=CoreVersion if(LauncherVersion==None) else LauncherVersion + LauncherConfig={} if(LauncherConfig==None) else LauncherConfig + self.__SystemConfig={ + "Core":{ + "Name":CoreName, + "Version":CoreVersion, + "Header":{'User-Agent':LauncherName+'/'+LauncherVersion[0]+' (('+CoreName+' '+CoreVersion[0]+';'+CoreVersion[1]+'))'}, + "Functions":{ + "Log":{ + "AutoPrint":False, + "ErrorOutput":False + }, + "Debug":False, + "Aria":False + }, + "Users":[] + }, + "Launcher":{ + "Name":LauncherName, + "Version":LauncherVersion, + "Config":LauncherConfig, + } + } + self.__Log=[] + self.__AuthWay="" + self.Log("info","Successful.","__init__") + #-----------------------------------------------------------------------# + #Log Functions + def Log(self,Type,Text,Function="Anonymous Function",ErrorType="TypeError"): + '''The function which was used to manager the log output system''' + ''':Type Type of the log info''' + ''':Text The main text of log info''' + ''':Function The function that cause the log,the default value is "Anonymous Function"''' + ''':Type The type of the error,the default value is "TypeError",Support "TypeError","ValueError","UserWarning"''' + if(Text!=""): + if(Type=="deadly"): + self.__Log.append(("DEADLY_ERROR",time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()),Function,Text,ErrorType)) + if(self.__SystemConfig["Core"]["Functions"]["Log"]["ErrorOutput"]): + self.MakeDir('.'+self.__SystemConfig["Launcher"]["Name"]+"\\logs") + self.OutputLog('.'+self.__SystemConfig["Launcher"]["Name"]+"\\logs\\"+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+".txt") + if(ErrorType=="TypeError"): + raise TypeError(Text) + elif(ErrorType=="ValueError"): + raise ValueError(Text) + else: + raise UserWarning(Text) + elif(Type=="info" or "warn" or "error"): + self.__Log.append((Type.upper(),time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()),Function,Text)) + if(self.__SystemConfig["Core"]["Functions"]["Log"]["AutoPrint"]==True): + print("["+Type.upper()+"]["+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+"]["+Function+"]"+Text) + return (Type.upper(),Text) + else: + self.__Log.append(("OTHER",time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()),Function,Text)) + if(self.__SystemConfig["Core"]["Functions"]["Log"]["AutoPrint"]==True): + print("[OTHER]["+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+"]["+Function+"]"+Text) + return ("OTHER",Text) + def OutputLog(self,Path): + '''The function which was used to output text file of program logs''' + if(os.path.isdir(Path)): + return self.Log("warn","Exist duplication name dir.","OutputLog") + else: + self.Log("info","Successful.","OutputLog") + with open(Path,"w+") as FileObject: + FileObject.write(self.__SystemConfig["Launcher"]["Name"]+"/"+self.__SystemConfig["Launcher"]["Version"][0]+" "+self.__SystemConfig["Launcher"]["Version"][1]+" | "+self.__CoreName+"/"+self.__CoreVersion[0]+" "+self.__CoreVersion[1]+" Logs "+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+"\n") + for text in self.__Log: + FileObject.write("["+text[0]+"]["+text[1]+"]["+text[2]+"]"+text[3]+"\n") + def ReturnLog(self): + '''The function which was used to return the list of program logs''' + self.Log("info","Successful.","ReturnLog") + return self.__Log + def PrintLastLog(self): + '''The function which was used to print the last logs of program''' + self.Log("info","Successful.","PrintLastLog") + print("["+self.__Log[-1][0]+"]["+self.__Log[-1][1]+"]["+self.__Log[-1][2]+"]"+self.__Log[-1][3]) + def PrintAllLog(self): + '''The function which was used to print all logs of program''' + self.Log("info","Successful.","PrintAllLog") + for text in self.__Log: + print("["+text[0]+"]["+text[1]+"]["+text[2]+"]"+text[3]) + def EnableAutoLogPrint(self): + '''The function which was used to enable the function of log auto print''' + self.__SystemConfig["Core"]["Functions"]["Log"]["AutoPrint"]=True + self.Log("info","Successful.","EnableAutoLogPrint") + def DisableAutoLogPrint(self): + '''The function which was used to disable the function of log auto print''' + self.__SystemConfig["Core"]["Functions"]["Log"]["AutoPrint"]=False + self.Log("info","Successful.","DisableAutoLogPrint") + def EnableErrorLogOutput(self): + '''The function which was used to enable the function of error log output''' + self.__SystemConfig["Core"]["Functions"]["Log"]["ErrorOutput"]=True + self.Log("info","Successful.","EnableErrorLogOutput") + def DisableErrorLogOutput(self): + '''The function which was used to disable the function of error log output''' + self.__SystemConfig["Core"]["Functions"]["Log"]["ErrorOutput"]=False + self.Log("info","Successful.","DisableErrorLogOutput") + #-----------------------------------------------------------------------# + #Download Functions + def Download(self,DownloadFrom,DownloadTo): + '''The multi-thread download function''' + ''':DownloadFrom The online url for the file''' + ''':DownloadTo The local path for the file''' + if(DownloadFrom=="" or DownloadTo==""): + self.Log("warn","Wrong online address or local address for download.","Download") + else: + StartTime=time.time() + FileSize=int(requests.head(DownloadFrom,headers=self.__SystemConfig["Core"]["Header"]).headers['Content-Length']) + if(self.__SystemConfig["Core"]["Functions"]["Aria"]==True): + if(platform.system()=="Windows"): + if(os.path.isfile('.'+self.__SystemConfig["Launcher"]["Name"]+"\\rely\\"+"aria2c.exe")): + os.system('.'+self.__SystemConfig["Launcher"]["Name"]+"\\rely\\"+"aria2c.exe -o "+DownloadTo+" "+DownloadFrom+" -U \""+self.__SystemConfig["Core"]["Header"]['User-Agent']+"\"") + else: + self.Log("warn","Missed Aria.","Download") + self.DownloadAriaWin() + os.system('.'+self.__SystemConfig["Launcher"]["Name"]+"\\rely\\"+"aria2c.exe -o "+DownloadTo+" "+DownloadFrom+" -U \""+self.__SystemConfig["Core"]["Header"]['User-Agent']+"\"") + else: + os.system('.'+self.__SystemConfig["Launcher"]["Name"]+"\\rely\\"+"aria2c.exe -o "+DownloadTo+" "+DownloadFrom+" -U \""+self.__SystemConfig["Core"]["Header"]['User-Agent']+"\"") + else: + with open(DownloadTo,"wb") as FileObject: + FileObject.write(requests.get(DownloadFrom).content) + self.Log("info","Success.","Download") + return (str(time.time()-StartTime),FileSize // (time.time()-StartTime)) + def DownloadAriaWin(self): + '''The function which was used to download Aria environment for windows''' + if(not os.path.isdir('.'+self.__SystemConfig["Launcher"]["Name"]+"\\rely")): + self.MakeDir('.'+self.__SystemConfig["Launcher"]["Name"]+"\\rely") + if(os.path.isdir("C:\\Program Files (x86)")): + with open('.'+self.__SystemConfig["Launcher"]["Name"]+"\\rely\\"+"aria2c.exe","wb") as FileObject: + FileObject.write(requests.get("https://resource.ghink.net/aria2c/win64/aria2c.exe",headers=self.__SystemConfig["Core"]["Header"]).content) + else: + with open('.'+self.__SystemConfig["Launcher"]["Name"]+"\\rely\\"+"aria2c.exe","wb") as FileObject: + FileObject.write(requests.get("https://resource.ghink.net/aria2c/win32/aria2c.exe",headers=self.__SystemConfig["Core"]["Header"]).content) + self.Log("info","Success.","DownloadAriaWin") + def EnableAria(self): + '''The function which was used to enable the function of Aria''' + self.__SystemConfig["Core"]["Functions"]["Aria"]=True + self.Log("info","Successful.","EnableAria") + def DisableAria(self): + '''The function which was used to disable the function of Aria''' + self.__SystemConfig["Core"]["Functions"]["Aria"]=False + self.Log("info","Successful.","DisbleAria") + #-----------------------------------------------------------------------# + #File and Dir Functions + def MakeDir(self,Path): + '''The function which was used to create a dir with determination''' + ''':Path The path of the dir you want to create''' + if(not os.path.isdir(Path)): + os.makedirs(Path) + self.Log("info","Successful.","MakeDir") + else: + return self.Log("warn","Exist.","MakeDir") + def SearchFile(self,Path,Tag,Depth=1): + '''The function which was used to search files''' + ''':Path The root path you want to search''' + ''':Tag The name keyword of the file you want to search''' + ''':Depth The depth of dir you want to search,you should set as "all" if you want to search all dirs,the default value is 1''' + List=[] + i=0 + for root,dirs,files in os.walk(Path,topdown=True): + if Tag in files: + i+=1 + List.append(root+'\\'+Tag) + if(i==Depth): + break + else: + pass + self.Log("info","Success.","SearchFile") + return List + #-----------------------------------------------------------------------# + #Game Environment Set Functions + def GetUUID(self,Account="Steve"): + '''The function which was used to generate UUID''' + ''':Account Your account,the default value is "Steve"''' + if(self.__AuthWay=="offline"): + result="OfflinePlayer:"+Account + md5=hashlib.md5() + md5.update(result.encode(encoding='utf-8')) + self.Log("info","Success.","GetUUID") + return md5.hexdigest() + else: + return self.Log("warn","Wrong auth way","GetUUID") + def GetJavaPath(self,Depth=1): + '''The function which was used to search java''' + ''':Depth The depth of dir you want to search,you should set as "all" if you want to search all dirs,the default value is 1''' + if(platform.system()=="Windows"): + self.Log("info","Success.","GetJavaPath") + return self.SearchFile('C:\\','javaw.exe',Depth) + elif(platform.system()=="Linux"): + self.Log("info","Success.","GetJavaPath") + return self.SearchFile('\\','java',Depth) + else: + self.Log("info","Success.","GetJavaPath") + return self.SearchFile('\\','java',Depth) + def SetAccount(self,Account="Steve",Password=""): + '''The function which was used to set game account data''' + ''':Account Your account,the default value is "Steve"''' + ''':Password Your password''' + if(self.__AuthWay=="online_mojang"): + if(Account.count("@")==1): + if(json.loads(requests.get("https://authserver.mojang.com/",headers=self.__SystemConfig["Core"]["Header"]).text)['status']=="OK"): + result=json.loads(requests.post("https://authserver.mojang.com/authenticate",'{"agent":{"name":"Minecraft","Version":1},"username":"'+Account+'","password":"'+Password+'"}',headers=self.__SystemConfig["Core"]["Header"]).text) + self.__Token=result['accessToken'] + self.__UUID=result['selectedProfile']['id'] + self.__ID=result['selectedProfile']['name'] + self.Log("info","Success.","GetAccount") + else: + return self.Log("warn","Fail to request Mojang\'s auth server.","SetAccount") + else: + return self.Log("warn","Wrong Account.","SetAccount") + elif(self.__AuthWay=="offline"): + if(Account.count("@")==1): + return self.Log("warn","Wrong Account.","SetAccount") + else: + self.__ID=Account + self.__UUID=self.GetUUID(Account) + self.__Token="" + self.Log("info","Success.","GetAccount") + else: + pass + def SetAuthWay(self,AuthWay): + '''The auth way set function''' + ''':AuthWay Your auth way,must be "offline" or "online"''' + if(AuthWay=="offline"): + self.__AuthWay="offline" + self.Log("info","Success.","SetAuthWay") + elif(AuthWay=="online"): + self.__AuthWay="online" + self.Log("info","Success.","SetAuthWay") + else: + return self.Log("warn","Wrong Auth Way.","SetAccount") + def SetRecomMem(self): + '''The recommendation memory value set function''' + self.__Memory = float(psutil.virtual_memory().free / 1024 ** 3) * 0.8 + self.Log("info","Success.","SetRecomMem") + def SetJavaPath(self,path): + '''The java path set function''' + ''':Path Your java path''' + if(path==None): + return self.Log("warn","Wrong local address for java.","SetJavaPath") + else: + if(os.path.exists(path)): + self.__JAVA=path + self.Log("info","Success.","SetJavaPath") + else: + return self.Log("warn","Wrong local address for java.","SetJavaPath") + def SetGameMem(self,Memory): + '''The game memory value set function''' + ''':Memory The memory of the game,the unit is GiBytes''' + try: + self.__Memory=float(Memory) + self.Log("info","Success.","SetGameMem") + except: + return self.Log("warn","Wrong parameter for game memory.","SetGameMem") + #-----------------------------------------------------------------------# + #Game Resouces Functions + #-----------------------------------------------------------------------# #Game Launch Function \ No newline at end of file diff --git a/requirement.txt b/old/other/requirement.txt similarity index 75% rename from requirement.txt rename to old/other/requirement.txt index 5909e2e..43b8c04 100644 --- a/requirement.txt +++ b/old/other/requirement.txt @@ -1,7 +1,7 @@ -requests -psutil -random -subprocess -math -zipfile +requests +psutil +random +subprocess +math +zipfile threading \ No newline at end of file