Skip to content

Commit

Permalink
Merge pull request #119 from fa0311/develop-v5
Browse files Browse the repository at this point in the history
5.4.0
  • Loading branch information
fa0311 authored Feb 7, 2024
2 parents 50b69dd + 740313b commit 7df3386
Show file tree
Hide file tree
Showing 22 changed files with 105 additions and 89 deletions.
10 changes: 10 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"recommendations": [
"ms-python.vscode-pylance",
"ms-python.python",
"ms-python.debugpy",
"charliermarsh.ruff",
"davidanson.vscode-markdownlint",
"esbenp.prettier-vscode"
]
}
8 changes: 4 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
"configurations": [
{
"name": "Python: 現在のファイル",
"type": "python",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true
},
{
"name": "DMMGamePlayerFastLauncher",
"type": "python",
"type": "debugpy",
"request": "launch",
"program": "DMMGamePlayerFastLauncher/DMMGamePlayerFastLauncher.py",
"console": "integratedTerminal",
Expand All @@ -25,7 +25,7 @@
},
{
"name": "GameLauncher",
"type": "python",
"type": "debugpy",
"request": "launch",
"program": "DMMGamePlayerFastLauncher/DMMGamePlayerFastLauncher.py",
"console": "integratedTerminal",
Expand All @@ -37,7 +37,7 @@
},
{
"name": "LaunchLauncher",
"type": "python",
"type": "debugpy",
"request": "launch",
"program": "DMMGamePlayerFastLauncher/DMMGamePlayerFastLauncher.py",
"console": "integratedTerminal",
Expand Down
11 changes: 3 additions & 8 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
{
"flake8.args": ["--ignore=E501,E731"],
"markdownlint.config": {
"MD033": false
},
"python.analysis.typeCheckingMode": "basic",
"editor.codeActionsOnSave": {
"source.organizeImports": true
"source.organizeImports": "explicit",
"source.fixAll": "explicit",
},
"black-formatter.args": ["--line-length=180"],
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},

"files.exclude": {
"**/__pycache__": true,
"**/build": true,
Expand All @@ -20,4 +15,4 @@
"**/*.spec": true,
"**/.venv": true
}
}
}
6 changes: 3 additions & 3 deletions DMMGamePlayerFastLauncher/DMMGamePlayerFastLauncher.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import i18n
from app import App
from coloredlogs import ColoredFormatter
from component.logger import StyleScheme, TkinkerLogger
from component.logger import LoggingHandlerMask, StyleScheme, TkinkerLogger
from launch import GameLauncher, LanchLauncher
from lib.DGPSessionV2 import DgpSessionV2
from models.setting_data import AppConfig
Expand Down Expand Up @@ -36,7 +36,8 @@ def loder(master: LanchLauncher):
handlers.append(handler)

if AppConfig.DATA.debug_window.get() and not any([isinstance(x, LoggingHandler) for x in logging.getLogger().handlers]):
handler = LoggingHandler(TkinkerLogger(master).create().box, scheme=StyleScheme)
handle = LoggingHandlerMask if AppConfig.DATA.mask_token.get() else LoggingHandler
handler = handle(TkinkerLogger(master).create().box, scheme=StyleScheme)
handler.setFormatter(ColoredFormatter("[%(levelname)s] [%(asctime)s] %(message)s"))
handlers.append(handler)

Expand Down Expand Up @@ -114,4 +115,3 @@ def loder(master: LanchLauncher):
lanch.mainloop()
else:
raise Exception("type error")
raise Exception("type error")
3 changes: 1 addition & 2 deletions DMMGamePlayerFastLauncher/component/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
import customtkinter as ctk
import i18n
from component.var import PathVar
from customtkinter import CTkBaseClass, CTkButton, CTkCheckBox, CTkEntry, CTkFrame, CTkLabel, CTkOptionMenu, CTkProgressBar, CTkToplevel
from customtkinter import CTkBaseClass, CTkButton, CTkCheckBox, CTkEntry, CTkFrame, CTkLabel, CTkOptionMenu, CTkProgressBar, CTkToplevel, Variable
from customtkinter import ThemeManager as CTkm
from customtkinter import Variable


class LabelComponent(CTkFrame):
Expand Down
11 changes: 10 additions & 1 deletion DMMGamePlayerFastLauncher/component/logger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import re

import customtkinter as ctk
from customtkinter import CTkTextbox, CTkToplevel
from tkinter_colored_logging_handlers.main import ColorSchemeLight, StyleSchemeBase
from tkinter_colored_logging_handlers import ColorSchemeLight, LoggingHandler, StyleSchemeBase


class StyleScheme(StyleSchemeBase, ColorSchemeLight):
Expand All @@ -23,3 +25,10 @@ def __init__(self, master):
def create(self):
self.box.pack(fill=ctk.BOTH, padx=10, pady=(0, 10), expand=True)
return self


class LoggingHandlerMask(LoggingHandler):
def format(self, record):
formated = super().format(record)
formated = re.sub(r"(?<=\=)[0-9a-zA-Z]{32,}", lambda x: f"\033[31m[CENSORED {len(x.group())}]\033[0m", formated)
return formated
4 changes: 3 additions & 1 deletion DMMGamePlayerFastLauncher/models/setting_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from component.variable_base import VariableBase
from lib.DGPSessionV2 import DgpSessionV2
from static.env import Env
from utils.utils import get_default_locale


@dataclass
Expand All @@ -17,12 +18,13 @@ class SettingData(VariableBase):
dmm_proxy_http: StringVar = field(default_factory=StringVar)
dmm_proxy_https: StringVar = field(default_factory=StringVar)
dmm_proxy_socks: StringVar = field(default_factory=StringVar)
lang: StringVar = field(default_factory=lambda: StringVar(value="ja"))
lang: StringVar = field(default_factory=lambda: StringVar(value=get_default_locale()[0]))
theme: StringVar = field(default_factory=lambda: StringVar(value="blue"))
appearance_mode: StringVar = field(default_factory=lambda: StringVar(value="dark"))
window_scaling: DoubleVar = field(default_factory=lambda: DoubleVar(value=1.0))
debug_window: BooleanVar = field(default_factory=lambda: BooleanVar(value=False))
output_logfile: BooleanVar = field(default_factory=lambda: BooleanVar(value=False))
mask_token: BooleanVar = field(default_factory=lambda: BooleanVar(value=True))

def update(self):
DgpSessionV2.DGP5_PATH = self.dmm_game_player_program_folder.get_path()
Expand Down
2 changes: 1 addition & 1 deletion DMMGamePlayerFastLauncher/static/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


class Env(Dump):
VERSION = "v5.3.0"
VERSION = "v5.4.0"
RELEASE_VERSION = requests.get(UrlConfig.RELEASE_API).json().get("tag_name", VERSION)

DEVELOP: bool = os.environ.get("ENV") == "DEVELOP"
Expand Down
4 changes: 4 additions & 0 deletions DMMGamePlayerFastLauncher/static/loder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from models.setting_data import AppConfig, DeviceData, SettingData
from static.config import DataPathConfig
from utils.utils import get_supported_lang


def config_loder():
Expand All @@ -19,5 +20,8 @@ def config_loder():
with open(DataPathConfig.DEVICE, "w+", encoding="utf-8") as f:
json.dump(AppConfig.DEVICE.to_dict(), f)

if AppConfig.DATA.lang.get() not in [x[0] for x in get_supported_lang()]:
AppConfig.DATA.lang.set("en_US")

AppConfig.DATA.update()
AppConfig.DEVICE.update()
4 changes: 3 additions & 1 deletion DMMGamePlayerFastLauncher/tab/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ def create(self):
for key, value in hardware.items():
EntryComponent(self, text=key, variable=StringVar(value=value), state=ctk.DISABLED).create()

command = lambda id=hardware["hardware_manage_id"]: self.delete_callback(id)
def command(id=hardware["hardware_manage_id"]):
return self.delete_callback(id)

CTkButton(self, text=i18n.t("app.account.delete"), command=command).pack(fill=ctk.X, pady=10)
PaddingComponent(self, height=20).create()

Expand Down
4 changes: 3 additions & 1 deletion DMMGamePlayerFastLauncher/tab/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from lib.toast import ToastController, error_toast
from models.setting_data import AppConfig, DeviceData, SettingData
from static.config import AssetsPathConfig, DataPathConfig
from utils.utils import get_supported_lang


class SettingTab(CTkFrame):
Expand Down Expand Up @@ -46,7 +47,7 @@ def __init__(self, master: CTkBaseClass):
super().__init__(master, fg_color="transparent")
self.toast = ToastController(self)
self.data = AppConfig.DATA
self.lang = [(y, i18n.t("app.language", locale=y)) for y in [x.suffixes[0][1:] for x in AssetsPathConfig.I18N.iterdir()]]
self.lang = get_supported_lang()

self.theme = [x.stem for x in AssetsPathConfig.THEMES.iterdir()]

Expand All @@ -72,6 +73,7 @@ def create(self):
PaddingComponent(self, height=5).create()
CheckBoxComponent(self, text=i18n.t("app.setting.debug_window"), variable=self.data.debug_window).create()
CheckBoxComponent(self, text=i18n.t("app.setting.output_logfile"), variable=self.data.output_logfile).create()
CheckBoxComponent(self, text=i18n.t("app.setting.mask_token"), variable=self.data.mask_token).create()

PaddingComponent(self, height=5).create()
CTkButton(self, text=i18n.t("app.setting.save"), command=self.save_callback).pack(fill=ctk.X, pady=10)
Expand Down
12 changes: 10 additions & 2 deletions DMMGamePlayerFastLauncher/tab/shortcut.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from models.shortcut_data import LauncherShortcutData, ShortcutData
from static.config import DataPathConfig
from static.env import Env
from utils.utils import children_destroy, file_create
from utils.utils import children_destroy, file_create, get_default_locale

# ===== Shortcut Sub Menu =====

Expand Down Expand Up @@ -160,7 +160,15 @@ def get_game_info(self) -> tuple[str, Path, bool]:
title = title.replace(":", "").replace("*", "").replace("?", "")
title = title.replace('"', "").replace("<", "").replace(">", "").replace("|", "")

return title, game_path.joinpath(data["exec_file_name"]), data["is_administrator"]
file = game_path.joinpath(data["exec_file_name"])

if get_default_locale()[1] == "cp932":
return (title, file, data["is_administrator"])

if all(ord(c) < 128 for c in title):
return (title, file, data["is_administrator"])

return (self.filename.get(), file, data["is_administrator"])


class ShortcutCreate(ShortcutBase):
Expand Down
17 changes: 16 additions & 1 deletion DMMGamePlayerFastLauncher/utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import locale
from pathlib import Path
from tkinter import Misc
from typing import Optional, TypeVar
from typing import Optional, Tuple, TypeVar

import i18n
from static.config import AssetsPathConfig

T = TypeVar("T")

Expand All @@ -28,3 +30,16 @@ def file_create(path: Path, name: str):
raise FileExistsError(i18n.t("app.utils.file_exists", name=name))
else:
path.touch()


def get_supported_lang() -> list[tuple[str, str]]:
return [(y, i18n.t("app.language", locale=y)) for y in [x.suffixes[0][1:] for x in AssetsPathConfig.I18N.iterdir()]]


def get_default_locale() -> Tuple[str, str]:
lang, encoding = locale.getdefaultlocale()
if lang not in [x[0] for x in get_supported_lang()]:
lang = "en"
if encoding is None:
encoding = "utf-8"
return lang, encoding
49 changes: 0 additions & 49 deletions a.py

This file was deleted.

11 changes: 8 additions & 3 deletions assets/i18n/app.en.yml → assets/i18n/app.en_US.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
en:
en_US:
title: DMMGamePlayer Fast Launcher
language: English

Expand All @@ -22,7 +22,9 @@ en:

shortcut:
filename: File Name
filename_tooltip: Please provide any name for this shortcut.
filename_tooltip: |-
Please provide any name for this shortcut.
Using non-alphanumeric characters may cause problems.
product_id: Select product_id
product_id_tooltip: |
Expand Down Expand Up @@ -73,7 +75,9 @@ en:
Importing will log you out of DMMGamePlayer 5.
Do not log in directly with an imported account in DMMGamePlayer 5.
filename_tooltip: Please provide any name for this account.
filename_tooltip: |-
Please provide any name for this account.
Using non-alphanumeric characters may cause problems.
import: Import
filename: File Name
filename_not_entered: File name is not entered.
Expand Down Expand Up @@ -130,6 +134,7 @@ en:
window_scaling: Window Scaling
debug_window: Show Debug Window
output_logfile: Log to File
mask_token: Hide tokens on the log

device_detail: |-
Configure device information for device authentication.
Expand Down
11 changes: 8 additions & 3 deletions assets/i18n/app.ja.yml → assets/i18n/app.ja_JP.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ja:
ja_JP:
title: DMMGamePlayer Fast Launcher
language: 日本語

Expand All @@ -22,7 +22,9 @@ ja:

shortcut:
filename: ファイル名
filename_tooltip: このショートカットに任意の名前を付けてください。
filename_tooltip: |-
このショートカットに任意の名前を付けてください。
半角英数字以外を使用すると問題が発生する可能性があります。
product_id: product_idの選択
product_id_tooltip: |-
Expand Down Expand Up @@ -75,7 +77,9 @@ ja:
インポートをするとDMMGamePlayer5からログアウトされます。
インポート済みのアカウントで直接起動した DMMGamePlayer5 でログインをしないでください。
filename_tooltip: このアカウントに任意の名前を付けてください。
filename_tooltip: |-
このアカウントに任意の名前を付けてください。
半角英数字以外を使用すると問題が発生する可能性があります。
import: インポート
filename: ファイル名
filename_not_entered: ファイル名が入力されていません。
Expand Down Expand Up @@ -131,6 +135,7 @@ ja:
window_scaling: ウィンドウの拡大率
debug_window: デバッグウィンドウを表示する
output_logfile: ログをファイルで出力する
mask_token: ログ上のトークンを隠す

device_detail: |-
デバイス認証に使用するデバイス情報を設定します。
Expand Down
Loading

0 comments on commit 7df3386

Please sign in to comment.