Skip to content

Commit 06331dd

Browse files
committed
Various small improvements
1 parent 3c098c5 commit 06331dd

File tree

13 files changed

+67
-160
lines changed

13 files changed

+67
-160
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +0,0 @@
1-
import os
2-
3-
BASE_DIR: str = os.path.join(
4-
os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
5-
)

d2rloader/core/platform_linux/lutris.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
cd '{GAME_PATH}'
3838
3939
# Command
40-
gamemoderun {LUTRIS_UMU_LAUNCHER} '{GAME_PATH}/D2R.exe' -w -username {USERNAME} -password {PASSWORD} -address {REGION}
40+
gamemoderun {LUTRIS_UMU_LAUNCHER} '{GAME_PATH}/D2R.exe' -w -username {USERNAME} -password {PASSWORD} -address {REGION} {PARAMS}
4141
"""
4242

4343
_punct_re = re.compile(r'[\t !"#$%&\'()*\-/<=>?@\[\\\]^_`{|},.+]+')
@@ -79,9 +79,10 @@ def render_start_script(self):
7979
GAME_PATH=self.settings.game_path,
8080
LUTRIS_PATH=self.lutris_home,
8181
LUTRIS_UMU_LAUNCHER=self.lutris_umu_launcher,
82-
USERNAME=self.account.username,
82+
USERNAME=self.account.email,
8383
PASSWORD=self.account.password,
8484
REGION=self.account.region.value,
85+
PARAMS=self.account.params
8586
)
8687

8788
def save_start_script(self, force: bool = True):
@@ -102,7 +103,7 @@ def save_start_script(self, force: bool = True):
102103
return True
103104

104105
def normalize_username_name(self, delim: str = "-"):
105-
text = unidecode.unidecode(self.account.username)
106+
text = unidecode.unidecode(self.account.email)
106107
result: list[str] = []
107108
for word in _punct_re.split(text.lower()):
108109
if word:

d2rloader/core/platform_linux/process.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ def _validate_start(self, account: Account):
7373
)
7474

7575
if (
76-
len(account.username) == 0
76+
len(account.email) == 0
7777
or account.password is None
7878
or len(account.password) == 0
7979
):
80-
raise ProcessingError("No username/password provided")
80+
raise ProcessingError("No email/password provided")
Original file line numberDiff line numberDiff line change
@@ -1,5 +0,0 @@
1-
import os
2-
3-
BASE_DIR: str = os.path.join(
4-
os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
5-
)

d2rloader/core/platform_windows/process.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def _process_auth_password(self, account: Account, params: list[str]):
102102
"Password-based authentication is selected but no password was provided."
103103
)
104104

105-
params.extend(["-username", account.username, "-password", account.password,"-adress", account.region.value])
105+
params.extend(["-username", account.email, "-password", account.password,"-adress", account.region.value])
106106

107107
def _handle_instance_start(self, account: Account, pid: int):
108108
logger.trace(f"process id: {pid}")

d2rloader/core/platform_windows/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def window_title_callback(hwnd: int, account: Account):
1818

1919
if title == D2R_PROCESS_TITLE:
2020
window_title = WINDOW_TITLE_FORMAT.format(
21-
account.username, account.region.value
21+
account.displayname, account.region.value
2222
)
2323
logger.debug(f"Setting Window Handle '{hwnd}' to '{window_title}'")
2424
win32gui.SetWindowText(hwnd, window_title) # pyright: ignore

d2rloader/models/account.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ def from_name(cls, name: str):
3838

3939

4040
class Account(BaseModel):
41-
username: str
41+
profile_name: str | None = Field(default=None)
42+
email: str
4243
auth_method: AuthMethod
4344
token: str | None
4445
token_protected: bytes | None = Field(default=None)
@@ -47,6 +48,12 @@ class Account(BaseModel):
4748
params: str | None
4849
runtime: float | None = Field(default=0)
4950

51+
@property
52+
def displayname(self):
53+
if self.profile_name is None or self.profile_name == "":
54+
return self.email
55+
return self.profile_name
56+
5057

5158
# TODO: Unused at the moment - switch to QTableView first
5259
class AccountModel(QAbstractItemModel):

d2rloader/ui/account_dialog.py

+24-18
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class AccountDialogWidget(QDialog):
2727

2828
def __init__(self, parent: QWidget | None = None, account: Account | None = None):
2929
super().__init__(parent)
30-
self.setFixedHeight(200)
30+
self.setFixedHeight(230)
3131
self.setFixedWidth(700)
3232
main_layout = QVBoxLayout()
3333
options_group_box = QGroupBox("Options")
@@ -39,16 +39,13 @@ def __init__(self, parent: QWidget | None = None, account: Account | None = None
3939
left_layout = QFormLayout()
4040
right_layout = QFormLayout()
4141

42-
username_label: Final = QLabel("Account:", self)
43-
self.username: Final = QLineEdit()
44-
left_layout.addRow(username_label, self.username)
42+
profile_name_label: Final = QLabel("Profile Name:", self)
43+
self.profile_name: Final = QLineEdit()
44+
left_layout.addRow(profile_name_label, self.profile_name)
4545

46-
region_label: Final = QLabel("Region:", self)
47-
self.region_combobox: Final = QComboBox()
48-
self.region_combobox.addItem(Region.Europe.name, Region.Europe)
49-
self.region_combobox.addItem(Region.Americas.name, Region.Americas)
50-
self.region_combobox.addItem(Region.Asia.name, Region.Asia)
51-
right_layout.addRow(region_label, self.region_combobox)
46+
email_label: Final = QLabel("Account:", self)
47+
self.email: Final = QLineEdit()
48+
left_layout.addRow(email_label, self.email)
5249

5350
auth_label: Final = QLabel("Auth Method:", self)
5451
self.auth_combobox: Final = QComboBox()
@@ -57,11 +54,22 @@ def __init__(self, parent: QWidget | None = None, account: Account | None = None
5754
self.auth_combobox.currentTextChanged.connect(self.change_password_token_widget)
5855
left_layout.addRow(auth_label, self.auth_combobox)
5956

57+
region_label: Final = QLabel("Region:", self)
58+
self.region_combobox: Final = QComboBox()
59+
self.region_combobox.addItem(Region.Europe.name, Region.Europe)
60+
self.region_combobox.addItem(Region.Americas.name, Region.Americas)
61+
self.region_combobox.addItem(Region.Asia.name, Region.Asia)
62+
right_layout.addRow(region_label, self.region_combobox)
63+
6064
self.password_label: Final = QLabel("Password:", self)
6165
# self.password: Final = QLineEdit()
6266
# right_layout.addRow(self.password_label, self.password)
6367
self.password: PasswordWidget = PasswordWidget("")
64-
right_layout.addRow(self.password_label, self.password)
68+
left_layout.addRow(self.password_label, self.password)
69+
70+
params_label: Final = QLabel("Start Parameters:", self)
71+
self.params: Final = QLineEdit()
72+
right_layout.addRow(params_label, self.params)
6573

6674
self.token_label: Final = QLabel("Token:", self)
6775
self.token: Final = QTextEdit()
@@ -70,12 +78,9 @@ def __init__(self, parent: QWidget | None = None, account: Account | None = None
7078
)
7179
right_layout.addRow(self.token_label, self.token)
7280

73-
params_label: Final = QLabel("Start Parameters:", self)
74-
self.params: Final = QLineEdit()
75-
left_layout.addRow(params_label, self.params)
76-
7781
if account is not None:
78-
self.username.setText(account.username)
82+
self.profile_name.setText(account.profile_name or "")
83+
self.email.setText(account.email)
7984
account_idx = self.auth_combobox.findData(account.auth_method)
8085
self.auth_combobox.setCurrentIndex(account_idx)
8186
region_idx = self.region_combobox.findData(account.region)
@@ -104,7 +109,7 @@ def __init__(self, parent: QWidget | None = None, account: Account | None = None
104109
if account is None:
105110
self.setWindowTitle("Add a new Account")
106111
else:
107-
self.setWindowTitle(f"Edit Account - Username: {account.username}")
112+
self.setWindowTitle(f"Edit Account - email: {account.email}")
108113

109114
button_box.accepted.connect(self.accept)
110115
button_box.rejected.connect(self.reject)
@@ -115,7 +120,8 @@ def __init__(self, parent: QWidget | None = None, account: Account | None = None
115120
@property
116121
def data(self):
117122
return Account(
118-
username=self.username.text(),
123+
profile_name=self.profile_name.text(),
124+
email=self.email.text(),
119125
auth_method=cast(
120126
AuthMethod,
121127
self.auth_combobox.itemData(self.auth_combobox.currentIndex()),

d2rloader/ui/main.py

+2
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ def open_about(self):
169169
<b>Python: </b> {python_version}, <b>Qt: </b> {qt_version}<br />
170170
<b>Source Code: </b> <a href="https://github.com/sh4nks/d2r-loader">Link</a><br />
171171
<b>License: </b> MIT<br />
172+
<br />
173+
<b>TZ Info and DClone Info provided by <a href="https://d2emu.com">D2Emu.com</a>
172174
</center>
173175
"""
174176

d2rloader/ui/table.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from d2rloader.core.core import D2RLoaderState
1818
from d2rloader.models.account import Account, AuthMethod, Region
1919
from d2rloader.ui.account_dialog import AccountDialogWidget
20+
from d2rloader.ui.utils.utils import show_error_dialog
2021

2122

2223
class D2RLoaderTableWidget(QTableWidget):
@@ -101,7 +102,7 @@ def create_row(self, row: int, item: Account | None = None):
101102
if item is None:
102103
return
103104

104-
account_item = QTableWidgetItem(item.username)
105+
account_item = QTableWidgetItem(item.email)
105106
account_item.setFlags(account_item.flags() & ~Qt.ItemFlag.ItemIsEditable)
106107

107108
auth_item = QTableWidgetItem()
@@ -237,7 +238,7 @@ def process_start(self, account: Account, button: QPushButton):
237238
button.setText("Starting...")
238239
button.setDisabled(True)
239240

240-
logger.info(f"Starting D2R.exe - {account.username} ({account.region.value})")
241+
logger.info(f"Starting D2R.exe - {account.displayname} ({account.region.value})")
241242
self._state.process_manager.process_finished.connect(
242243
functools.partial(self.process_finished, button)
243244
)
@@ -249,22 +250,22 @@ def process_start(self, account: Account, button: QPushButton):
249250
def process_kill(self, account: Account, button: QPushButton):
250251
pid = None
251252
try:
252-
pid = self._processes[account.username][1]
253+
pid = self._processes[account.email][1]
253254
except KeyError:
254255
pass
255256

256257
if pid is None or self._state.process_manager is None:
257258
logger.error("Stopping D2R.exe failed - PID not found!")
258259
else:
259260
logger.info(
260-
f"Stopping D2R.exe with PID {self._processes[account.username][1]} - {account.username} ({account.region})"
261+
f"Stopping D2R.exe with PID {self._processes[account.email][1]} - {account.displayname} ({account.region})"
261262
)
262263
try:
263264
self._state.process_manager.kill(pid)
264265
except Exception:
265266
logger.error(f"Couldn't kill pid {pid}")
266267

267-
del self._processes[account.username]
268+
del self._processes[account.email]
268269
self.change_buttons_state(button, "start")
269270

270271
@Slot() # pyright: ignore
@@ -277,13 +278,14 @@ def process_finished(
277278
self.change_buttons_state(button, "start")
278279
return
279280

280-
logger.info(f"Started account {account.username} with pid {pid}")
281+
logger.info(f"Started account {account.displayname} with pid {pid}")
281282
self.change_buttons_state(button, "start")
282283
button.setText("Running")
283284
button.setDisabled(False)
284285

285-
self._processes[account.username] = (logged_in, pid)
286+
self._processes[account.email] = (logged_in, pid)
286287

287288
@Slot() # pyright: ignore
288289
def process_error(self, button: QPushButton, account: Account, msg: str):
290+
show_error_dialog(self, msg)
289291
self.change_buttons_state(button, "start")

d2rloader/ui/utils/utils.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from PySide6.QtWidgets import QWidget
1+
from PySide6.QtWidgets import QMessageBox, QWidget
22

33

44
def class_name(o: QWidget):
@@ -10,3 +10,15 @@ def init_widget(w: QWidget, name: str) -> None:
1010
class name"""
1111
w.setObjectName(name)
1212
w.setToolTip(class_name(w))
13+
14+
def show_error_dialog(w: QWidget, msg: str) -> None:
15+
QMessageBox.critical(
16+
w,
17+
"Error",
18+
(
19+
"<center>"
20+
f"{msg}"
21+
"</center>"
22+
),
23+
QMessageBox.StandardButton.Ok,
24+
)

pyproject.toml

+1-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
name = "d2rloader"
33
version = "0.1.0"
44
dependencies = [
5-
"httpx>=0.28.1",
65
"loguru>=0.7.3",
76
"psutil>=6.1.1",
87
"pydantic>=2.10.6",
9-
"pyinstaller>=6.11.1",
108
"PySide6",
119
"pywin32>=308; platform_system == 'Windows'",
1210
"unidecode>=1.3.8",
@@ -31,9 +29,7 @@ classifiers = [
3129
[dependency-groups]
3230
dev = [
3331
"ruff",
34-
"ipython"
35-
]
36-
release = [
32+
"ipython",
3733
"pyinstaller"
3834
]
3935

0 commit comments

Comments
 (0)