diff --git a/src/AutoProcess.py b/src/AutoProcess.py index 3d7ea82..62bd22a 100644 --- a/src/AutoProcess.py +++ b/src/AutoProcess.py @@ -5,7 +5,9 @@ @Contact : Hatanezumi@chunshengserver.cn ''' import os +import winreg import requests +import ctypes.wintypes def get_mods(base_path:str) -> tuple[bool,str|list[str]]: if os.path.exists(base_path) is False: @@ -45,4 +47,32 @@ def get_cloud(path:str, target, arg): res = req.content target(arg,True,res) except Exception as err: - target(arg,False,err) \ No newline at end of file + target(arg,False,err) +def get_ra3_path(base_reg_path:str = None) -> tuple[bool,str]: + try: + if base_reg_path is None: + base_reg_path = 'SOFTWARE\\WOW6432Node' + key = winreg.OpenKeyEx(winreg.HKEY_LOCAL_MACHINE,base_reg_path + '\\Electronic Arts\\Electronic Arts\\Red Alert 3') + dir = winreg.QueryValueEx(key,'Install Dir') + return (True,dir[0]) + except FileNotFoundError: + if base_reg_path == 'SOFTWARE\\WOW6432Node': + return get_ra3_path('SOFTWARE\\') + else: + return (False,'未找到RA3根目录,你确定安装了吗?或尝试修复注册表') + except Exception as err: + return (False,err) +def get_mod_path() -> tuple[str,str]: + ''' + 返回文档路径和mod路径 + ''' + try: + buf = ctypes.create_unicode_buffer(ctypes.wintypes.MAX_PATH) + ctypes.windll.shell32.SHGetFolderPathW(None, 5, None, 0, buf) + if buf == '': + raise Exception('目录获取失败') + documents_path = buf.value + except: + documents_path = os.path.join(os.path.splitdrive(os.environ['systemroot'])[0],os.environ['homepath'],'Documents') + base_mod_path = os.path.join(documents_path,'Red Alert 3','Mods') + return (documents_path,base_mod_path) \ No newline at end of file diff --git a/src/__pycache__/AutoProcess.cpython-310.pyc b/src/__pycache__/AutoProcess.cpython-310.pyc index 82e1e83..8037a57 100644 Binary files a/src/__pycache__/AutoProcess.cpython-310.pyc and b/src/__pycache__/AutoProcess.cpython-310.pyc differ diff --git a/src/__pycache__/main.cpython-310.pyc b/src/__pycache__/main.cpython-310.pyc index c8b3667..58e854f 100644 Binary files a/src/__pycache__/main.cpython-310.pyc and b/src/__pycache__/main.cpython-310.pyc differ diff --git a/src/main.py b/src/main.py index 757a9de..705f889 100644 --- a/src/main.py +++ b/src/main.py @@ -15,7 +15,6 @@ from PySide6.QtCore import Qt, QStringListModel, Signal, QObject from PySide6.QtGui import QColor,QIcon, QTextCursor from ui.MainWindow import Ui_MainWindow from threading import Thread -import ctypes.wintypes from src import AutoProcess #常量 @@ -116,7 +115,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): if os.path.exists(os.path.join(os.getcwd(),'ui','ra3.ico')): self.icon = QIcon(os.path.join(os.getcwd(),'ui','ra3.ico')) self.setWindowIcon(self.icon) - self.version = '1.0.2' + self.version = '1.0.3' #-------------------------- #连接信号 self.comboBox_mods.currentIndexChanged.connect(self.__comboBox_mods_changed)#下拉框内容改变 @@ -132,6 +131,9 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.pushButton_refresh.clicked.connect(self.__on_pushButton_refresh_clicked)#刷新按钮被按下 self.pushButton_Download.clicked.connect(self.__on_pushButton_Download_clicked)#下载按钮被按下 self.pushButton_release.clicked.connect(self.__on_pushButton_release_clicked)#发布页按钮被按下 + self.pushButton_changeDir_RA3.clicked.connect(self.__on_pushButton_changeDir_RA3_clicked)#切换到RA3目录按钮被按下 + self.pushButton_changeDir_mod.clicked.connect(self.__on_pushButton_changeDir_mod_clicked)#切换到mod目录被按下 + self.pushButton_localRefresh.clicked.connect(self.__on_pushButton_localRefresh_clicked)#本地刷新按钮被按下 #-------------------------- #变量注册(全局变量) self.select_mod = '' @@ -139,19 +141,17 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.listView_local_qsl = QStringListModel() self.listView_Network_qsl = QStringListModel() self.fileDialog = QFileDialog(self) - try: - buf = ctypes.create_unicode_buffer(ctypes.wintypes.MAX_PATH) - ctypes.windll.shell32.SHGetFolderPathW(None, 5, None, 0, buf) - if buf == '': - raise Exception('目录获取失败') - self.documents_path = buf.value - except: - self.base_mod_path = os.path.join(os.path.splitdrive(os.environ['systemroot'])[0],os.environ['homepath'],'Documents','Red Alert 3','Mods') - else: - self.base_mod_path = os.path.join(self.documents_path,'Red Alert 3','Mods') + self.documents_path, self.base_mod_path = AutoProcess.get_mod_path() self.cloud_mods = {} self.cloud_mod_source = (None,{}) self.isdownloading = False + self.ra3_path = AutoProcess.get_ra3_path() + if self.ra3_path[0] is False: + self.ra3_path = '' + self.pushButton_changeDir_RA3.setEnabled(False) + QMessageBox.warning(self,'获取RA3目录失败','无法获取RA3目录,原因:{}'.format(self.ra3_path[1]),QMessageBox.StandardButton.Ok,QMessageBox.StandardButton.Ok) + else: + self.ra3_path = self.ra3_path[1] #-------------------------- #初始化内容 self.mods = AutoProcess.get_mods(self.base_mod_path) @@ -352,6 +352,48 @@ class MainWindow(QMainWindow, Ui_MainWindow): webbrowser.open('https://cloud.armorrush.com/Hatanezumi/RA3_affiliated_mod_downloader/releases') def set_plainTextEdit_updatelog(self,text:str): self.plainTextEdit_updatelog.setPlainText(text) + def __on_pushButton_changeDir_RA3_clicked(self): + if self.ra3_path == '': + self.pushButton_changeDir_RA3.setEnabled(False) + return + mods = AutoProcess.get_mods(self.ra3_path) + if mods[0] is False: + QMessageBox.warning(self,'获取mod列表失败',mods[1],QMessageBox.Ok,QMessageBox.Ok) + else: + self.base_mod_path = self.ra3_path + self.mods = mods + Process.set_comboBox(self.comboBox_mods,[os.path.splitext(os.path.split(mod_name)[1])[0] for mod_name in mods[1]]) + #显示当前目录 + self.lineEdit_nowpath.setText(self.ra3_path) + def __on_pushButton_changeDir_mod_clicked(self): + self.documents_path, self.base_mod_path = AutoProcess.get_mod_path() + mods = AutoProcess.get_mods(self.base_mod_path) + if mods[0] is False: + QMessageBox.warning(self,'获取mod列表失败',mods[1],QMessageBox.Ok,QMessageBox.Ok) + else: + self.mods = mods + Process.set_comboBox(self.comboBox_mods,[os.path.splitext(os.path.split(mod_name)[1])[0] for mod_name in mods[1]]) + #显示当前目录 + self.lineEdit_nowpath.setText(self.base_mod_path) + def __on_pushButton_localRefresh_clicked(self): + currentIndex = self.comboBox_mods.currentIndex() + now_path = self.lineEdit_nowpath.text() + if os.path.exists(now_path) is False: + self.__on_pushButton_changeDir_mod_clicked() + return + mods = AutoProcess.get_mods(now_path) + if mods[0] is False: + QMessageBox.warning(self,'获取mod列表失败',mods[1],QMessageBox.Ok,QMessageBox.Ok) + else: + self.base_mod_path = now_path + self.mods = mods + Process.set_comboBox(self.comboBox_mods,[os.path.splitext(os.path.split(mod_name)[1])[0] for mod_name in mods[1]]) + #显示当前目录 + self.lineEdit_nowpath.setText(now_path) + if currentIndex + 1 > self.comboBox_mods.count(): + return + else: + self.comboBox_mods.setCurrentIndex(currentIndex) def init(): app = QApplication(sys.argv) main_window = MainWindow() diff --git a/ui/MainWindow.py b/ui/MainWindow.py index a13eadb..a0a7e69 100644 --- a/ui/MainWindow.py +++ b/ui/MainWindow.py @@ -126,6 +126,21 @@ class Ui_MainWindow(object): self.verticalLayout_4.addLayout(self.horizontalLayout_6) + self.horizontalLayout_8 = QHBoxLayout() + self.horizontalLayout_8.setObjectName(u"horizontalLayout_8") + self.pushButton_changeDir_RA3 = QPushButton(self.tab_local) + self.pushButton_changeDir_RA3.setObjectName(u"pushButton_changeDir_RA3") + + self.horizontalLayout_8.addWidget(self.pushButton_changeDir_RA3) + + self.pushButton_changeDir_mod = QPushButton(self.tab_local) + self.pushButton_changeDir_mod.setObjectName(u"pushButton_changeDir_mod") + + self.horizontalLayout_8.addWidget(self.pushButton_changeDir_mod) + + + self.verticalLayout_4.addLayout(self.horizontalLayout_8) + self.comboBox_mods = QComboBox(self.tab_local) self.comboBox_mods.setObjectName(u"comboBox_mods") @@ -140,6 +155,11 @@ class Ui_MainWindow(object): self.verticalLayout_4.addItem(self.verticalSpacer) + self.pushButton_localRefresh = QPushButton(self.tab_local) + self.pushButton_localRefresh.setObjectName(u"pushButton_localRefresh") + + self.verticalLayout_4.addWidget(self.pushButton_localRefresh) + self.pushButton_save = QPushButton(self.tab_local) self.pushButton_save.setObjectName(u"pushButton_save") @@ -364,7 +384,10 @@ class Ui_MainWindow(object): self.pushButton_L.setText(QCoreApplication.translate("MainWindow", u"-", None)) self.label_nowpath.setText(QCoreApplication.translate("MainWindow", u"\u5f53\u524d\u76ee\u5f55:", None)) self.pushButton_nowpath.setText(QCoreApplication.translate("MainWindow", u"...", None)) + self.pushButton_changeDir_RA3.setText(QCoreApplication.translate("MainWindow", u"\u5207\u6362\u5230RA3\u76ee\u5f55", None)) + self.pushButton_changeDir_mod.setText(QCoreApplication.translate("MainWindow", u"\u5207\u6362\u5230mod\u76ee\u5f55", None)) self.label_nowdir.setText(QCoreApplication.translate("MainWindow", u"\u5f53\u524d\u6587\u4ef6\u5939:", None)) + self.pushButton_localRefresh.setText(QCoreApplication.translate("MainWindow", u"\u5237\u65b0", None)) self.pushButton_save.setText(QCoreApplication.translate("MainWindow", u"\u4fdd\u5b58", None)) self.tabWidget_Main.setTabText(self.tabWidget_Main.indexOf(self.tab_local), QCoreApplication.translate("MainWindow", u"\u672c\u5730", None)) self.pushButton_refresh.setText(QCoreApplication.translate("MainWindow", u"\u5237\u65b0", None)) diff --git a/ui/MainWindow.ui b/ui/MainWindow.ui index caab5f8..3b18ca3 100644 --- a/ui/MainWindow.ui +++ b/ui/MainWindow.ui @@ -134,6 +134,24 @@ + + + + + + 切换到RA3目录 + + + + + + + 切换到mod目录 + + + + + @@ -157,6 +175,13 @@ + + + + 刷新 + + + diff --git a/ui/__pycache__/MainWindow.cpython-310.pyc b/ui/__pycache__/MainWindow.cpython-310.pyc index e79f536..6fbd21b 100644 Binary files a/ui/__pycache__/MainWindow.cpython-310.pyc and b/ui/__pycache__/MainWindow.cpython-310.pyc differ diff --git a/ui/格式转换.txt b/ui/格式转换.txt index 83824a1..dcfaa57 100644 --- a/ui/格式转换.txt +++ b/ui/格式转换.txt @@ -1,2 +1,2 @@ -pyside2-uic [你保存的文件名].ui > ***.py +pyside6-uic [你保存的文件名].ui > ***.py 另外别忘了将生成的文件另存为utf-8 \ No newline at end of file