diff --git a/._Test.py b/._Test.py new file mode 100755 index 0000000..d852a4f Binary files /dev/null and b/._Test.py differ diff --git a/._requirement.txt b/._requirement.txt new file mode 100755 index 0000000..e663ac3 Binary files /dev/null and b/._requirement.txt differ diff --git a/.gmclcore/env/aria2c64.exe b/.gmclcore/env/aria2c64.exe old mode 100644 new mode 100755 diff --git a/.gmclcore/env/aria2cdarwin b/.gmclcore/env/aria2cdarwin new file mode 100755 index 0000000..a1e1a4b Binary files /dev/null and b/.gmclcore/env/aria2cdarwin differ diff --git a/.gmclcore/logs/2022-01-09.logs b/.gmclcore/logs/2022-01-09.logs deleted file mode 100644 index deb0cdb..0000000 --- a/.gmclcore/logs/2022-01-09.logs +++ /dev/null @@ -1,6 +0,0 @@ -[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/.gmclcore/logs/2022-02-04.zip b/.gmclcore/logs/2022-02-04.zip new file mode 100755 index 0000000..15cb0ec Binary files /dev/null and b/.gmclcore/logs/2022-02-04.zip differ diff --git a/.gmclcore/logs/2022-02-05.logs b/.gmclcore/logs/2022-02-05.logs new file mode 100755 index 0000000..c12cf83 --- /dev/null +++ b/.gmclcore/logs/2022-02-05.logs @@ -0,0 +1,53 @@ +[2022-02-05 22:40:51] [INFO] Initing running env... +[2022-02-05 22:40:51] [INFO] Archiving logs. +[2022-02-05 22:41:22] [INFO] Initing running env... +[2022-02-05 22:41:22] [INFO] Archiving logs. +[2022-02-05 22:41:34] [INFO] Initing running env... +[2022-02-05 22:41:34] [INFO] Archiving logs. +[2022-02-05 22:42:40] [INFO] Initing running env... +[2022-02-05 22:42:40] [INFO] Archiving logs. +[2022-02-05 22:42:59] [INFO] Initing running env... +[2022-02-05 22:42:59] [INFO] Archiving logs. +[2022-02-05 22:44:35] [INFO] Initing running env... +[2022-02-05 22:44:35] [INFO] Creating daemon thread... +[2022-02-05 22:46:59] [INFO] Initing running env... +[2022-02-05 22:46:59] [INFO] Creating daemon thread... +[2022-02-05 22:47:17] [INFO] Initing running env... +[2022-02-05 22:47:17] [INFO] Creating daemon thread... +[2022-02-05 22:47:48] [INFO] Initing running env... +[2022-02-05 22:47:48] [INFO] Creating daemon thread... +[2022-02-05 22:47:58] [INFO] Initing running env... +[2022-02-05 22:47:58] [INFO] Creating daemon thread... +[2022-02-05 22:48:36] [INFO] Initing running env... +[2022-02-05 22:48:36] [INFO] Creating daemon thread... +[2022-02-05 22:49:11] [INFO] Initing running env... +[2022-02-05 22:49:11] [INFO] Creating daemon thread... +[2022-02-05 22:50:17] [INFO] Initing running env... +[2022-02-05 22:50:17] [INFO] Creating daemon thread... +[2022-02-05 22:50:31] [INFO] Initing running env... +[2022-02-05 22:50:31] [INFO] Creating daemon thread... +[2022-02-05 22:55:18] [INFO] Initing running env... +[2022-02-05 22:55:18] [INFO] Creating daemon thread... +[2022-02-05 23:03:44] [INFO] Initing running env... +[2022-02-05 23:03:46] [INFO] Creating daemon thread... +[2022-02-05 23:04:35] [INFO] Initing running env... +[2022-02-05 23:04:35] [INFO] Creating daemon thread... +[2022-02-05 23:04:39] [INFO] Initing running env... +[2022-02-05 23:04:39] [INFO] Creating daemon thread... +[2022-02-05 23:04:52] [INFO] Initing running env... +[2022-02-05 23:05:13] [INFO] Initing running env... +[2022-02-05 23:05:13] [INFO] Creating daemon thread... +[2022-02-05 23:05:23] [INFO] Initing running env... +[2022-02-05 23:05:23] [INFO] Creating daemon thread... +[2022-02-05 23:08:12] [INFO] Initing running env... +[2022-02-05 23:08:12] [INFO] Creating daemon thread... +[2022-02-05 23:08:20] [INFO] Initing running env... +[2022-02-05 23:08:20] [INFO] Creating daemon thread... +[2022-02-05 23:09:55] [INFO] Initing running env... +[2022-02-05 23:09:55] [INFO] Creating daemon thread... +[2022-02-05 23:10:30] [INFO] Initing running env... +[2022-02-05 23:10:30] [INFO] Creating daemon thread... +[2022-02-05 23:11:14] [INFO] Initing running env... +[2022-02-05 23:11:14] [INFO] Creating daemon thread... +[2022-02-05 23:17:36] [INFO] Initing running env... +[2022-02-05 23:17:36] [INFO] Creating daemon thread... diff --git a/GMCLCore/__init__.py b/GMCLCore/__init__.py old mode 100644 new mode 100755 diff --git a/GMCLCore/__main__.py b/GMCLCore/__main__.py old mode 100644 new mode 100755 diff --git a/GMCLCore/__pycache__/__init__.cpython-37.pyc b/GMCLCore/__pycache__/__init__.cpython-37.pyc old mode 100644 new mode 100755 index 495a1eb..0cce916 Binary files a/GMCLCore/__pycache__/__init__.cpython-37.pyc and b/GMCLCore/__pycache__/__init__.cpython-37.pyc differ diff --git a/GMCLCore/__pycache__/__init__.cpython-38.pyc b/GMCLCore/__pycache__/__init__.cpython-38.pyc new file mode 100755 index 0000000..c2039b4 Binary files /dev/null and b/GMCLCore/__pycache__/__init__.cpython-38.pyc differ diff --git a/GMCLCore/__pycache__/config.cpython-37.pyc b/GMCLCore/__pycache__/config.cpython-37.pyc old mode 100644 new mode 100755 diff --git a/GMCLCore/__pycache__/config.cpython-38.pyc b/GMCLCore/__pycache__/config.cpython-38.pyc new file mode 100755 index 0000000..2906c84 Binary files /dev/null and b/GMCLCore/__pycache__/config.cpython-38.pyc differ diff --git a/GMCLCore/__pycache__/gaming.cpython-37.pyc b/GMCLCore/__pycache__/gaming.cpython-37.pyc old mode 100644 new mode 100755 diff --git a/GMCLCore/__pycache__/log4py.cpython-37.pyc b/GMCLCore/__pycache__/log4py.cpython-37.pyc old mode 100644 new mode 100755 diff --git a/GMCLCore/__pycache__/log4py.cpython-38.pyc b/GMCLCore/__pycache__/log4py.cpython-38.pyc new file mode 100755 index 0000000..8339a7a Binary files /dev/null and b/GMCLCore/__pycache__/log4py.cpython-38.pyc differ diff --git a/GMCLCore/__pycache__/main.cpython-37.pyc b/GMCLCore/__pycache__/main.cpython-37.pyc old mode 100644 new mode 100755 diff --git a/GMCLCore/__pycache__/main.cpython-38.pyc b/GMCLCore/__pycache__/main.cpython-38.pyc new file mode 100755 index 0000000..5625104 Binary files /dev/null and b/GMCLCore/__pycache__/main.cpython-38.pyc differ diff --git a/GMCLCore/config.py b/GMCLCore/config.py old mode 100644 new mode 100755 diff --git a/GMCLCore/libs/._log4py.py b/GMCLCore/libs/._log4py.py new file mode 100755 index 0000000..ef75e1b Binary files /dev/null and b/GMCLCore/libs/._log4py.py differ diff --git a/GMCLCore/libs/__pycache__/ariaAdapter.cpython-38.pyc b/GMCLCore/libs/__pycache__/ariaAdapter.cpython-38.pyc new file mode 100755 index 0000000..e70f72e Binary files /dev/null and b/GMCLCore/libs/__pycache__/ariaAdapter.cpython-38.pyc differ diff --git a/GMCLCore/libs/__pycache__/log4py.cpython-38.pyc b/GMCLCore/libs/__pycache__/log4py.cpython-38.pyc new file mode 100755 index 0000000..4b30949 Binary files /dev/null and b/GMCLCore/libs/__pycache__/log4py.cpython-38.pyc differ diff --git a/GMCLCore/libs/ariaAdapter.py b/GMCLCore/libs/ariaAdapter.py new file mode 100755 index 0000000..aca1128 --- /dev/null +++ b/GMCLCore/libs/ariaAdapter.py @@ -0,0 +1,13 @@ +from asyncio import subprocess +from matplotlib.pyplot import subplot + + +import os, subprocess + +class adapter(object): + def __init__(self, path : str): + if not os.path.exists(path): + raise FileNotFoundError + if not os.path.isfile(path): + raise TypeError + self.__path = path diff --git a/GMCLCore/log4py.py b/GMCLCore/libs/log4py.py old mode 100644 new mode 100755 similarity index 77% rename from GMCLCore/log4py.py rename to GMCLCore/libs/log4py.py index cffe108..0f32881 --- a/GMCLCore/log4py.py +++ b/GMCLCore/libs/log4py.py @@ -20,13 +20,14 @@ class log(object): 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() + if os.path.exists(os.path.join(workdir, "logs")) and os.path.isdir(os.path.join(workdir, "logs")): + daemon = Thread(target = self.__daemon, name = "log4py-daemon") + daemon.daemon = True + daemon.start() else: try: - os.makedirs("{}\\logs".format(workdir), exist_ok = True) - daemon = Thread(target = self.__daemon) + os.makedirs(os.path.join(workdir, "logs"), exist_ok = True) + daemon = Thread(target = self.__daemon, name = "log4py-daemon") daemon.daemon = True daemon.start() except: @@ -35,14 +36,14 @@ class log(object): ''' Guard thread for recording logs and archiving. ''' - workdir = "{}\\logs".format(self.workdir) + workdir = os.path.abspath(os.path.join(self.workdir, "logs")) 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)) + if os.path.isfile(os.path.join(workdir, fname)): + logsList.append(os.path.join(workdir, fname)) archiveList = [] today = time.strftime("%Y-%m-%d", time.localtime(timeStamp)) # yesterday = time.strftime("%Y-%m-%d", time.localtime(timeStamp - 86400)) @@ -53,29 +54,21 @@ class log(object): 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) + shutil.make_archive(os.path.join(workdir, os.path.splitext(basename)[0]), "zip", workdir, basename) try: - os.remove("{}\\{}".format(workdir, basename)) + os.remove(os.path.join(workdir, basename)) except: pass - Thread(target = archive, args = (workdir,)).start() + Thread(target = archive, args = (workdir,), name = "log4py-archive").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: + with open(os.path.join(workdir, "{}.logs".format(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])) diff --git a/GMCLCore/main.py b/GMCLCore/main.py old mode 100644 new mode 100755 index f1dfea5..797346f --- a/GMCLCore/main.py +++ b/GMCLCore/main.py @@ -14,23 +14,32 @@ # # Standard -import os, platform, hashlib, requests +import os, platform, hashlib, requests, json, time import urllib.request, urllib.parse from threading import Thread +from subprocess import Popen, PIPE # Extend import psutil # Self -import GMCLCore.log4py as log4py +import GMCLCore.libs.log4py as log4py +import GMCLCore.libs.ariaAdapter as aria from GMCLCore.config import * class Core(object): # Define constant + + # Debug logs output switcher + DEBUG = True + + # Downloader Mode ARIA = "ARIA" + # Source Mode OFFICIAL = "OFFICIAL" BMCLAPI = "BMCLAPI" + # Auth Mode OFFLINE = "OFFLINE" MOJANG = "MOJANG" MICROSOFT = "MICROSOFT" @@ -59,7 +68,7 @@ class Core(object): # Define default game vars self.gameDir = os.path.join(os.path.dirname(__file__), ".minecraft") - self.javaPath = self.searchJava() + self.java = [[], None] self.gameMem = self.autoMemory() self.authType = self.OFFLINE self.id = "Steve" @@ -67,16 +76,19 @@ class Core(object): # Prepare running env self.l.info("Initing running env...") + os.makedirs(os.path.join(self.__workDir, "env"), exist_ok = True) + os.makedirs(os.path.join(self.__workDir, "config"), exist_ok = True) self.initEnv() # Create daemon thread self.l.info("Creating daemon thread...") - self.__daemonThread = Thread(target = self.__daemon) + self.__daemonThread = Thread(target = self.__daemon, name = "Daemon") self.__daemonThread.daemon = True self.__daemonThread.start() + # Prepare the launcher runnning env def initEnv(self): - os.makedirs(os.path.join(self.__workDir, "env"), exist_ok = True) + # Aria2c if self.networkTest(): source = self.urljoin(self.ENV_SOURCE, "aria2c") if self.__system == "Windows": @@ -96,7 +108,7 @@ class Core(object): 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") + self.__ariaPath = self.urljoin(self.__workDir, "env", "aria2clinux") source = self.urljoin(source, "linux") if not os.path.exists(self.__ariaPath): with open(self.__ariaPath, "wb") as fb: @@ -106,7 +118,7 @@ class Core(object): 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") + self.__ariaPath = self.urljoin(self.__workDir, "env", "aria2cdarwin") source = self.urljoin(source, "darwin") if not os.path.exists(self.__ariaPath): with open(self.__ariaPath, "wb") as fb: @@ -115,47 +127,124 @@ class Core(object): fb.write(content) except Exception as e: self.l.warn("Failed to install running env aria2c! System return: {}".format(e)) + try: + self.aria = aria.adapter(self.__ariaPath) + except FileNotFoundError as e: + self.l.warn("Failed to find running env aria2c! System return: {}".format(e)) + except TypeError as e: + self.l.warn("Failed to find running env aria2c! System return: {}".format(e)) + else: + self.aria = False + # The daemon thread function def __daemon(self): - while True: - pass - def urljoin(self, *args: str): + # Start some sub-daemon-thread + threadPool = [] + for t in threadPool: + t.daemon = True + t.start() + + while True: ... + + # Debug logs output + def __debug(self, *args) -> None : + self.l.info(*args) + + # Determin wheather the @content is a legal json + def isJson(self, content: str) -> bool: + try: + json.loads(content) + except json.decoder.JSONDecodeError: + return False + else: + return True + + # Merge the url + def urljoin(self, *args: str) -> str: result = os.path.join(*args) - for i in range(result.count("\\")): + for _ in range(result.count("\\")): result = result.replace("\\", "/") return result - def networkTest(self, source = r"https://www.baidu.com", retry = 3): + # Test the network working + def networkTest(self, source : str = r"http://www.baidu.com", retry : int = 3) -> bool: flag = False - for i in range(retry): + for _ in range(retry): try: fp = urllib.request.urlopen(source) fp.read(100).decode() fp.close() - except: - pass + except Exception as e: + self.__debug("networkTest Error:", str(e)) else: flag = True + break return flag + + # Scan java in the Path and whole disk + def searchJava(self) -> None: + keywords = ("javaw", "java", "javaw.exe", "java.exe") + # Search in Env Vars + def env() -> None : + while True: + 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 keywords: + if name == os.path.basename(j) and "jdk" not in j: + if os.path.exists(j): + version = self.javaVersion(j) + if not version: + self.java[0].append((j, version)) + time.sleep(0.5) + # Scan in whole disk + def disk() -> None: + while True: + disks = [] + if self.__system == "Windows": + partitions = psutil.disk_partitions() + for p in partitions: + disks.append(p.mountpoint) + else: + disks.append("/") + for d in disks: + for root, _, file in os.walk(d): + for f in file: + filePath = os.path.join(root, f) + for name in keywords: + if name == os.path.basename(filePath) and "jdk" not in filePath: + if os.path.exists(filePath): + version = self.javaVersion(filePath) + if not version: + self.java[0].append((filePath, version)) + time.sleep(0.5) + envThread = Thread(target = env, name = "scanJavaEnv") + diskThread = Thread(target = disk, name = "scanJavaDisk") + envThread.daemon = True + diskThread.daemon = True + envThread.start() + diskThread.start() - 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 + # Read the version of the java + def javaVersion(self, path : str): + p = Popen((path, "--version"), shell = True, stdout = PIPE) + out = p.communicate()[0] + try: + result = int(out.splitlines()[0].decode().split()[1].split(".")[0]) + except (UnicodeDecodeError, ValueError): + return False + else: + return result - def autoMemory(self): + # Return a auto-determined memory value for game + def autoMemory(self) -> float: return 0.8 * (psutil.virtual_memory().free / 1024 ** 2) - def generateUUID(self, id): + # Generate a offline player UUID + def generateUUID(self, id : str) -> str: result = hashlib.md5() result.update("".join(('OfflinePlayer:', id)).encode()) result = result.hexdigest() - return result \ No newline at end of file + return result diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/Test.py b/Test.py old mode 100644 new mode 100755 index b299800..ac625cd --- a/Test.py +++ b/Test.py @@ -1,5 +1,8 @@ -import platform, subprocess, urllib.parse, os, requests +import platform, subprocess, urllib.parse, os, requests, asyncio, time import GMCLCore -Core = GMCLCore.Core() \ No newline at end of file +Core = GMCLCore.Core() + +while True: + exec(input()) \ No newline at end of file diff --git a/icon.ico b/icon.ico old mode 100644 new mode 100755 diff --git a/old/0.1.0/config.json b/old/0.1.0/config.json old mode 100644 new mode 100755 diff --git a/old/0.1.0/gmclc.py b/old/0.1.0/gmclc.py old mode 100644 new mode 100755 diff --git a/old/other/GMCLCore.py b/old/other/GMCLCore.py old mode 100644 new mode 100755 diff --git a/old/other/requirement.txt b/old/other/requirement.txt old mode 100644 new mode 100755 diff --git a/requirement.txt b/requirement.txt new file mode 100755 index 0000000..17ad915 --- /dev/null +++ b/requirement.txt @@ -0,0 +1,3 @@ +psutil +tencentcloud-sdk-python +pywin32; platform_system == "Windows" \ No newline at end of file