6 Commits

Author SHA1 Message Date
e3140f656f v1.0.3 2023-04-05 18:22:17 +08:00
f9a09d1d87 v1.0.2 2023-03-25 00:33:17 +08:00
23ea5d0dc6 v1.0.2 2023-03-25 00:22:37 +08:00
2c0b265698 v1.0.2 2023-03-25 00:17:22 +08:00
e04718f830 v1.0.1 2023-03-24 00:46:02 +08:00
185efc1f96 v1.0.1 2023-03-24 00:44:41 +08:00
8 changed files with 190 additions and 22 deletions

View File

@@ -5,8 +5,9 @@
@Contact : Hatanezumi@chunshengserver.cn
'''
import os
import json
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:
@@ -43,7 +44,35 @@ def get_cloud(path:str, target, arg):
if req.status_code != 200:
target(arg,False,"返回值为:{}".format(req.status_code))
return
res = json.loads(req.content)
res = req.content
target(arg,True,res)
except Exception as err:
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)

Binary file not shown.

View File

@@ -6,6 +6,7 @@
'''
import os
import sys
import json
import py7zr
import requests
import webbrowser
@@ -22,6 +23,7 @@ REFRESH = 101
GETMODS = 200
GETMODINFO = 201
GETNEWVERSION = 202
GETUPDATELOG = 203
GETOTHER = 210
INFO = 300
WARNING = 301
@@ -37,6 +39,7 @@ class CustomizeSingals(QObject):
download_err = Signal(Exception)
set_new_version = Signal(str)
get_new_version_err = Signal(str)
set_plainTextEdit_updatelog = Signal(str)
class Process():
@staticmethod
def set_comboBox(comboBox:QComboBox, texts:list):
@@ -56,12 +59,15 @@ class Process():
singals.set_Status_Tip.connect(window.set_Status_Tip)
singals.set_new_version.connect(window.set_new_version)
singals.get_new_version_err.connect(window.get_new_version_err)
singals.set_plainTextEdit_updatelog.connect(window.set_plainTextEdit_updatelog)
if not state:
if mode == INIT:
if source == GETMODS:
singals.set_Status_Tip.emit('获取云AR信息失败:{}'.format(res))
elif source == GETNEWVERSION:
singals.get_new_version_err.emit(res)
elif source == GETUPDATELOG:
singals.set_plainTextEdit_updatelog.emit('获取更新日志失败:{}'.format(res))
return
elif mode == REFRESH:
if source == GETMODS:
@@ -69,11 +75,13 @@ class Process():
elif source == GETMODINFO:
singals.message_box.emit(WARNING,'出现错误',"获取mod信息失败:{}".format(res),QMessageBox.Ok,QMessageBox.Ok)
if source == GETMODS:
singals.set_listView_Network.emit(res)
singals.set_listView_Network.emit(json.loads(res))
elif source == GETMODINFO:
singals.set_network_page.emit(res)
singals.set_network_page.emit(json.loads(res))
elif source == GETNEWVERSION:
singals.set_new_version.emit(res['version'])
singals.set_new_version.emit(json.loads(res)['version'])
elif source == GETUPDATELOG:
singals.set_plainTextEdit_updatelog.emit(res.decode())
except Exception as err:
singals.message_box.emit((WARNING,'出现错误',"获取信息失败:{}".format(err),QMessageBox.Ok,QMessageBox.Ok))
@staticmethod
@@ -107,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.0'
self.version = '1.0.3'
#--------------------------
#连接信号
self.comboBox_mods.currentIndexChanged.connect(self.__comboBox_mods_changed)#下拉框内容改变
@@ -123,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 = ''
@@ -130,10 +141,17 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.listView_local_qsl = QStringListModel()
self.listView_Network_qsl = QStringListModel()
self.fileDialog = QFileDialog(self)
self.base_mod_path = os.path.join(os.path.splitdrive(os.environ['systemroot'])[0],os.environ['homepath'],'Documents','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)
@@ -154,18 +172,12 @@ class MainWindow(QMainWindow, Ui_MainWindow):
#获取更新信息
t = Thread(target=AutoProcess.get_cloud,args=('https://www.chunshengserver.cn/files/RA3mods/RA3_affiliated_mod_downloader.json',Process.get_cloud_data,(self,INIT,GETNEWVERSION)),daemon=True)
t.start()
#获取更新日志
t = Thread(target=AutoProcess.get_cloud,args=('https://www.chunshengserver.cn/files/RA3mods/更新日志.txt',Process.get_cloud_data,(self,INIT,GETUPDATELOG)),daemon=True)
t.start()
def __comboBox_mods_changed(self):
if self.mods[0] is False:
return
# currentText = self.comboBox_mods.currentText()#为了保证数据安全采用字符串匹配的方式
# find = False
# for mod_path in self.mods[1]:
# if os.path.split(mod_path)[1].removesuffix('.skudef') == currentText:
# self.select_mod = mod_path
# find = True
# break
# if find is False:
# return
#显示本地列表内容
currentIndex = self.comboBox_mods.currentIndex()#因为有重复的名称,所以采用索引匹配
mod_path = self.mods[1][currentIndex]
@@ -313,8 +325,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.progressBar_Download.setValue(value)
def download_finished(self,path:str):
self.isdownloading = False
self.progressBar_Download.value(0)
select = QMessageBox.information(self,'下载成功','下载成功,是否自动解压?',QMessageBox.Ok|QMessageBox.Cancel,QMessageBox.Cancel)
self.progressBar_Download.setValue(0)
select = QMessageBox.question(self,'下载成功','下载成功,是否自动解压?',QMessageBox.Ok|QMessageBox.Cancel,QMessageBox.Cancel)
if select == QMessageBox.Ok:
try:
with py7zr.SevenZipFile(file=path,mode='r') as file:
@@ -323,7 +335,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
QMessageBox.warning(self,'解压失败','解压失败,原因:{}'.format(err),QMessageBox.Ok,QMessageBox.Ok)
return
else:
QMessageBox.warning(self,'解压成功','解压成功',QMessageBox.Ok,QMessageBox.Ok)
QMessageBox.information(self,'解压成功','解压成功',QMessageBox.Ok,QMessageBox.Ok)
def download_err(self,err:Exception):
self.isdownloading = False
QMessageBox.warning(self,'下载失败','下载失败,原因:{}'.format(err),QMessageBox.Ok,QMessageBox.Ok)
@@ -333,10 +345,55 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self_version = int(self.version.replace('.',''))
if version_int > self_version:
self.label_about_newverison.setText("<font color=red>最新版本:"+version+"(有更新!请点击发布页下载)</font>")
self.setStatusTip('有新版本!({})'.format(version))
def get_new_version_err(self,err:str):
self.label_about_newverison.setText("<font color=red>最新版本:连接到纯世蜉生失败,原因:{}</font>".format(err))
def __on_pushButton_release_clicked(self):
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()

View File

@@ -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")
@@ -200,6 +220,7 @@ class Ui_MainWindow(object):
self.plainTextEdit_introduce = QPlainTextEdit(self.tab_Network)
self.plainTextEdit_introduce.setObjectName(u"plainTextEdit_introduce")
self.plainTextEdit_introduce.setLineWrapMode(QPlainTextEdit.NoWrap)
self.plainTextEdit_introduce.setReadOnly(True)
self.horizontalLayout_3.addWidget(self.plainTextEdit_introduce)
@@ -312,6 +333,18 @@ class Ui_MainWindow(object):
self.verticalLayout_10.addWidget(self.label_about_newverison)
self.label_updatelog = QLabel(self.tab_about)
self.label_updatelog.setObjectName(u"label_updatelog")
self.verticalLayout_10.addWidget(self.label_updatelog)
self.plainTextEdit_updatelog = QPlainTextEdit(self.tab_about)
self.plainTextEdit_updatelog.setObjectName(u"plainTextEdit_updatelog")
self.plainTextEdit_updatelog.setLineWrapMode(QPlainTextEdit.NoWrap)
self.plainTextEdit_updatelog.setReadOnly(True)
self.verticalLayout_10.addWidget(self.plainTextEdit_updatelog)
self.pushButton_release = QPushButton(self.tab_about)
self.pushButton_release.setObjectName(u"pushButton_release")
@@ -351,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))
@@ -368,6 +404,7 @@ class Ui_MainWindow(object):
self.label_about_contact.setText(QCoreApplication.translate("MainWindow", u"\u8054\u7cfb:Hatanezumi@chunshengserver.cn", None))
self.label_about_verison.setText(QCoreApplication.translate("MainWindow", u"\u5f53\u524d\u7248\u672c:", None))
self.label_about_newverison.setText(QCoreApplication.translate("MainWindow", u"\u6700\u65b0\u7248\u672c:", None))
self.label_updatelog.setText(QCoreApplication.translate("MainWindow", u"\u66f4\u65b0\u65e5\u5fd7:", None))
self.pushButton_release.setText(QCoreApplication.translate("MainWindow", u"\u53d1\u5e03\u9875", None))
self.tabWidget_Main.setTabText(self.tabWidget_Main.indexOf(self.tab_about), QCoreApplication.translate("MainWindow", u"\u5173\u4e8e", None))
#if QT_CONFIG(statustip)

View File

@@ -134,6 +134,24 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QPushButton" name="pushButton_changeDir_RA3">
<property name="text">
<string>切换到RA3目录</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_changeDir_mod">
<property name="text">
<string>切换到mod目录</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QComboBox" name="comboBox_mods"/>
</item>
@@ -157,6 +175,13 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_localRefresh">
<property name="text">
<string>刷新</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_save">
<property name="text">
@@ -241,6 +266,9 @@
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
@@ -372,6 +400,23 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_updatelog">
<property name="text">
<string>更新日志:</string>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="plainTextEdit_updatelog">
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_release">
<property name="text">

View File

@@ -1,2 +1,2 @@
pyside2-uic [你保存的文件名].ui > ***.py
pyside6-uic [你保存的文件名].ui > ***.py
另外别忘了将生成的文件另存为utf-8