From 804b657dc2ceef1fb59fe9a9a348990f79db7d86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=B5=E3=81=81?= Date: Sat, 7 Jan 2023 14:15:45 +0900 Subject: [PATCH] restore cache MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ふぁ --- DMMGamePlayerFastLauncher.py | 99 ++++++++++++++++++++++++++++++----- requirements.txt | Bin 864 -> 924 bytes setup.iss | 2 +- 3 files changed, 88 insertions(+), 13 deletions(-) diff --git a/DMMGamePlayerFastLauncher.py b/DMMGamePlayerFastLauncher.py index c179795..030c032 100644 --- a/DMMGamePlayerFastLauncher.py +++ b/DMMGamePlayerFastLauncher.py @@ -3,6 +3,7 @@ import argparse import json import glob +import win32crypt import ctypes import random import hashlib @@ -84,6 +85,41 @@ def read(self): requests.cookies.create_cookie(**cookie_data) ) + def write_cache(self, file: str = "cookie.bytes"): + contents = [] + for cookie in self.session.cookies: + cookie_dict = dict( + version=cookie.version, + name=cookie.name, + value=cookie.value, + port=cookie.port, + domain=cookie.domain, + path=cookie.path, + secure=cookie.secure, + expires=cookie.expires, + discard=cookie.discard, + comment=cookie.comment, + comment_url=cookie.comment_url, + rfc2109=cookie.rfc2109, + rest=cookie._rest, + ) + contents.append(cookie_dict) + data = win32crypt.CryptProtectData( + json.dumps(contents).encode(), "DMMGamePlayerFastLauncher" + ) + with open(file, "wb") as f: + f.write(data) + + def read_cache(self, file: str = "cookie.bytes"): + open(file, "a+") + with open(file, "rb") as f: + data = f.read() + _, contents = win32crypt.CryptUnprotectData(data) + for cookie in json.loads(contents): + self.session.cookies.set_cookie( + requests.cookies.create_cookie(**cookie) + ) + def get(self, url: str) -> requests.Response: return self.session.get(url, headers=self.HEADERS, proxies=self.PROXY) @@ -123,33 +159,72 @@ def close(self): argpar.add_argument("product_id", default=None) argpar.add_argument("--game-path", default=None) argpar.add_argument("--game-args", default=None) +argpar.add_argument("--login-force", action="store_true") argpar.add_argument("--skip-exception", action="store_true") argpar.add_argument("--https-proxy-uri", default=None) argpar.add_argument("--non-request-admin", action="store_true") -arg = argpar.parse_args() +try: + arg = argpar.parse_args() +except: + raise Exception( + "\n".join( + [ + "Could not parse argument.", + "Is the product_id specified correctly?", + "https://github.com/fa0311/DMMGamePlayerFastLauncher/blob/master/docs/README-advance.md#%E5%BC%95%E6%95%B0", + ] + ) + ) session = DgpSession(arg.https_proxy_uri) -session.read() -url = session.get("https://apidgp-gameplayer.games.dmm.com/v5/loginurl").json()["data"][ - "url" -] -token = urlparse(url).path.split("path=")[-1] +try: + session.read() +except: + print("Read Error") + try: + session.read_cache() + except: + print("Read Cache Error") +if session.cookies.get("login_session_id") == None or arg.login_force: + response = session.get("https://apidgp-gameplayer.games.dmm.com/v5/loginurl") + url = response.json()["data"]["url"] + token = urlparse(url).path.split("path=")[-1] + session.get(url) + res = session.get( + f"https://accounts.dmm.com/service/login/token/=/path={token}/is_app=false" + ) -session.get(url) -res = session.get( - f"https://accounts.dmm.com/service/login/token/=/path={token}/is_app=false" -) +if session.cookies.get("login_session_id") == None: + try: + session.read_cache() + except: + print("Read Cache Error") if session.cookies.get("login_session_id") == None: if not arg.skip_exception: raise Exception( - "\n".join(["Login failed.", "Please start DMMGamePlayer and login again."]) + "\n".join( + [ + "Login failed.", + "If DMMGamePlayer is running, exit it or Please start DMMGamePlayer and login again.", + ] + ) ) -session.write() +try: + session.write() +except: + print("Write Error") + + +try: + session.write_cache() +except: + print("Write Cache Error") + session.close() dpg5_config = session.get_config() diff --git a/requirements.txt b/requirements.txt index 99cd73dfe2302a8bddb6dc8b18278af4399c6ede..f8c0f21504f37c24f7cd3e608520772dcdb874ef 100644 GIT binary patch delta 49 ycmaFBHivyf4wHBRLncEx5a%%%GZ-=00-+HQ8c$AUisuCJj2R3VOee2r+6Vv|3kt&k delta 15 XcmbQk{(x;m4%6fwrm)HXnC1ZhF(n32 diff --git a/setup.iss b/setup.iss index fc9c721..a36338c 100644 --- a/setup.iss +++ b/setup.iss @@ -2,7 +2,7 @@ ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! #define MyAppName "DMMGamePlayerFastLauncher" -#define MyAppVersion "4.5.0" +#define MyAppVersion "4.5.1" #define MyAppPublisher "yuki" #define MyAppURL "https://github.com/fa0311/DMMGamePlayerFastLauncher" #define MyAppExeName "DMMGamePlayerFastLauncher.exe"