This commit is contained in:
Hatanezumi 2023-09-30 13:18:59 +08:00
parent e3140f656f
commit 2e2617627d
7 changed files with 114 additions and 24 deletions

View File

@ -76,3 +76,13 @@ def get_mod_path() -> tuple[str,str]:
documents_path = os.path.join(os.path.splitdrive(os.environ['systemroot'])[0],os.environ['homepath'],'Documents') 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') base_mod_path = os.path.join(documents_path,'Red Alert 3','Mods')
return (documents_path,base_mod_path) return (documents_path,base_mod_path)
def get_ARModLauncher_path() -> tuple[bool,str]:
try:
key = winreg.OpenKeyEx(winreg.HKEY_LOCAL_MACHINE,'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\ARModLauncher.exe')
dir = winreg.QueryValueEx(key,'')
dir = os.path.split(dir[0])[0]
return (True,dir)
except FileNotFoundError:
return (False,'未找到AR启动器目录')
except Exception as err:
return (False,err)

Binary file not shown.

View File

@ -35,7 +35,7 @@ class CustomizeSingals(QObject):
set_listView_Network = Signal(dict) set_listView_Network = Signal(dict)
set_Status_Tip = Signal(str) set_Status_Tip = Signal(str)
set_progressBar_Download = Signal(int) set_progressBar_Download = Signal(int)
download_finished = Signal(str) download_finished = Signal(str,dict)
download_err = Signal(Exception) download_err = Signal(Exception)
set_new_version = Signal(str) set_new_version = Signal(str)
get_new_version_err = Signal(str) get_new_version_err = Signal(str)
@ -85,7 +85,7 @@ class Process():
except Exception as err: except Exception as err:
singals.message_box.emit((WARNING,'出现错误',"获取信息失败:{}".format(err),QMessageBox.Ok,QMessageBox.Ok)) singals.message_box.emit((WARNING,'出现错误',"获取信息失败:{}".format(err),QMessageBox.Ok,QMessageBox.Ok))
@staticmethod @staticmethod
def download(window:QMainWindow,url:str,path:str): def download(window:QMainWindow,url:str,path:str,info:dict):
signals = CustomizeSingals() signals = CustomizeSingals()
signals.set_progressBar_Download.connect(window.set_progressBar_Download) signals.set_progressBar_Download.connect(window.set_progressBar_Download)
signals.download_finished.connect(window.download_finished) signals.download_finished.connect(window.download_finished)
@ -93,20 +93,35 @@ class Process():
if not os.path.exists(os.path.split(path)[0]): if not os.path.exists(os.path.split(path)[0]):
signals.download_err.emit('目录不存在:{}'.format(os.path.split(path)[0])) signals.download_err.emit('目录不存在:{}'.format(os.path.split(path)[0]))
return return
res = requests.get(url, stream=True,headers={"Accept-Encoding":"identity"})
size = 0#初始化已下载大小
chunk_size = 1024#单次下载量
content_size = int(res.headers['content-length'])#总大小
try: try:
res = requests.get(url, stream=True,headers={"Accept-Encoding":"identity"},timeout=10)
size = 0#初始化已下载大小
chunk_size = 1024#单次下载量
content_size = int(res.headers['content-length'])#总大小
if res.status_code == 200: if res.status_code == 200:
with open(path,'wb') as file: with open(path,'wb') as file:
for data in res.iter_content(chunk_size=chunk_size): for data in res.iter_content(chunk_size=chunk_size):
if window.isdownloading is False:
file.close()
os.remove(path)
signals.set_progressBar_Download.emit(0)
return
file.write(data) file.write(data)
size += len(data) size += len(data)
signals.set_progressBar_Download.emit(int(size / content_size * 100)) signals.set_progressBar_Download.emit(int(size / content_size * 100))
signals.download_finished.emit(path) signals.download_finished.emit(path,info)
except Exception as err: except Exception as err:
signals.download_err.emit(err) signals.download_err.emit(err)
@staticmethod
def clear_localPage_everything(window:QMainWindow):
'''
清除本地页面中能显示的所有的物体的内容
'''
window.comboBox_mods.clear()
window.listView_local_qsl.setStringList([])
window.listView_loaded_qsl.setStringList([])
window.lineEdit_nowpath.setText('')
window.label_nowdir.setText('')
class MainWindow(QMainWindow, Ui_MainWindow): class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None) -> None: def __init__(self, parent=None) -> None:
#基础设置 #基础设置
@ -115,7 +130,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
if os.path.exists(os.path.join(os.getcwd(),'ui','ra3.ico')): if os.path.exists(os.path.join(os.getcwd(),'ui','ra3.ico')):
self.icon = QIcon(os.path.join(os.getcwd(),'ui','ra3.ico')) self.icon = QIcon(os.path.join(os.getcwd(),'ui','ra3.ico'))
self.setWindowIcon(self.icon) self.setWindowIcon(self.icon)
self.version = '1.0.3' self.version = '1.1.0'
#-------------------------- #--------------------------
#连接信号 #连接信号
self.comboBox_mods.currentIndexChanged.connect(self.__comboBox_mods_changed)#下拉框内容改变 self.comboBox_mods.currentIndexChanged.connect(self.__comboBox_mods_changed)#下拉框内容改变
@ -134,6 +149,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.pushButton_changeDir_RA3.clicked.connect(self.__on_pushButton_changeDir_RA3_clicked)#切换到RA3目录按钮被按下 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_changeDir_mod.clicked.connect(self.__on_pushButton_changeDir_mod_clicked)#切换到mod目录被按下
self.pushButton_localRefresh.clicked.connect(self.__on_pushButton_localRefresh_clicked)#本地刷新按钮被按下 self.pushButton_localRefresh.clicked.connect(self.__on_pushButton_localRefresh_clicked)#本地刷新按钮被按下
self.pushButton_changeDir_ARModLauncher.clicked.connect(self.__on_pushButton_changeDir_ARModLauncher_clicked)#切换到AR启动器目录按钮被按下
#-------------------------- #--------------------------
#变量注册(全局变量) #变量注册(全局变量)
self.select_mod = '' self.select_mod = ''
@ -145,6 +161,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.cloud_mods = {} self.cloud_mods = {}
self.cloud_mod_source = (None,{}) self.cloud_mod_source = (None,{})
self.isdownloading = False self.isdownloading = False
self.selected_mod_info = {}
self.download_info = (None,None)#第一个参数为线程,第二个参数为保存地址
self.ra3_path = AutoProcess.get_ra3_path() self.ra3_path = AutoProcess.get_ra3_path()
if self.ra3_path[0] is False: if self.ra3_path[0] is False:
self.ra3_path = '' self.ra3_path = ''
@ -152,6 +170,12 @@ class MainWindow(QMainWindow, Ui_MainWindow):
QMessageBox.warning(self,'获取RA3目录失败','无法获取RA3目录,原因:{}'.format(self.ra3_path[1]),QMessageBox.StandardButton.Ok,QMessageBox.StandardButton.Ok) QMessageBox.warning(self,'获取RA3目录失败','无法获取RA3目录,原因:{}'.format(self.ra3_path[1]),QMessageBox.StandardButton.Ok,QMessageBox.StandardButton.Ok)
else: else:
self.ra3_path = self.ra3_path[1] self.ra3_path = self.ra3_path[1]
self.ARModLauncher_path = AutoProcess.get_ARModLauncher_path()
if self.ARModLauncher_path[0] is False:
self.ARModLauncher_path = ''
self.pushButton_changeDir_ARModLauncher.setEnabled(False)
else:
self.ARModLauncher_path = os.path.join(self.ARModLauncher_path[1],'Resources','CustomContent')
#-------------------------- #--------------------------
#初始化内容 #初始化内容
self.mods = AutoProcess.get_mods(self.base_mod_path) self.mods = AutoProcess.get_mods(self.base_mod_path)
@ -161,7 +185,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
Process.set_comboBox(self.comboBox_mods,[os.path.splitext(os.path.split(mod_name)[1])[0] for mod_name in self.mods[1]]) Process.set_comboBox(self.comboBox_mods,[os.path.splitext(os.path.split(mod_name)[1])[0] for mod_name in self.mods[1]])
self.label_about_verison.setText('当前版本:{}'.format(self.version)) self.label_about_verison.setText('当前版本:{}'.format(self.version))
#绑定模型 #绑定模型
self.listView_loacl.setModel(self.listView_local_qsl) self.listView_local.setModel(self.listView_local_qsl)
self.listView_loaded.setModel(self.listView_loaded_qsl) self.listView_loaded.setModel(self.listView_loaded_qsl)
self.listView_Network.setModel(self.listView_Network_qsl) self.listView_Network.setModel(self.listView_Network_qsl)
#显示当前目录 #显示当前目录
@ -197,7 +221,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
#显示保存到文件夹 #显示保存到文件夹
self.lineEdit_savedir.setText(os.path.split(mod_path)[0]) self.lineEdit_savedir.setText(os.path.split(mod_path)[0])
def __on_pushButton_R_clicked(self): def __on_pushButton_R_clicked(self):
currentIndex = self.listView_loacl.currentIndex().row() currentIndex = self.listView_local.currentIndex().row()
if currentIndex == -1: if currentIndex == -1:
return return
select_mod_name = self.listView_local_qsl.stringList()[currentIndex] select_mod_name = self.listView_local_qsl.stringList()[currentIndex]
@ -289,6 +313,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
elif mode == CRITICAL: elif mode == CRITICAL:
QMessageBox.Critical(self,title,text,Button,defaultButton) QMessageBox.Critical(self,title,text,Button,defaultButton)
def set_network_page(self,res:dict): def set_network_page(self,res:dict):
self.selected_mod_info = res
self.label_name.setText('名称:'+res['name']) self.label_name.setText('名称:'+res['name'])
self.label_author.setText('作者:'+res['author']) self.label_author.setText('作者:'+res['author'])
self.label_version.setText('版本:'+res['version']) self.label_version.setText('版本:'+res['version'])
@ -305,7 +330,10 @@ class MainWindow(QMainWindow, Ui_MainWindow):
t.start() t.start()
def __on_pushButton_Download_clicked(self): def __on_pushButton_Download_clicked(self):
if self.isdownloading: if self.isdownloading:
QMessageBox.information(self,'无法下载','当前有下载任务在进行',QMessageBox.Ok,QMessageBox.Ok) select = QMessageBox.question(self,'是否终止','确定要终止下载?已下载的进度不会被保存',QMessageBox.Yes|QMessageBox.Cancel,QMessageBox.Cancel)
if select == QMessageBox.Yes:
self.isdownloading = False
self.pushButton_Download.setText('下载')
return return
currentText = self.comboBox_download.currentText() currentText = self.comboBox_download.currentText()
if self.cloud_mod_source[0] != self.listView_Network_qsl.stringList()[self.listView_Network.currentIndex().row()]: if self.cloud_mod_source[0] != self.listView_Network_qsl.stringList()[self.listView_Network.currentIndex().row()]:
@ -319,25 +347,59 @@ class MainWindow(QMainWindow, Ui_MainWindow):
file_name = link.split('/')[-1] file_name = link.split('/')[-1]
save_path = self.lineEdit_savedir.text() save_path = self.lineEdit_savedir.text()
self.isdownloading = True self.isdownloading = True
t = Thread(target=Process.download,args=(self,link,os.path.join(save_path,file_name)),daemon=True) self.pushButton_Download.setText('终止')
t = Thread(target=Process.download,args=(self,link,os.path.join(save_path,file_name),self.selected_mod_info),daemon=True)
self.download_info = (t,os.path.join(save_path,file_name))
t.start() t.start()
def set_progressBar_Download(self,value:int): def set_progressBar_Download(self,value:int):
self.progressBar_Download.setValue(value) self.progressBar_Download.setValue(value)
def download_finished(self,path:str): def download_finished(self,path:str,info:dict):
self.isdownloading = False self.isdownloading = False
self.progressBar_Download.setValue(0) self.progressBar_Download.setValue(0)
select = QMessageBox.question(self,'下载成功','下载成功,是否自动解压?',QMessageBox.Ok|QMessageBox.Cancel,QMessageBox.Cancel) in_ARModLauncher_path = False
if select == QMessageBox.Ok: self.pushButton_Download.setText('下载')
outpath = os.path.split(path)[0]
if os.path.split(path)[0] == self.ARModLauncher_path:
in_ARModLauncher_path = True
outpath = os.path.join(outpath,os.path.split(path)[1].split('.')[0])
select = QMessageBox.question(self,'下载成功','下载成功,是否自动解压?',QMessageBox.Yes|QMessageBox.Cancel,QMessageBox.Yes)
if select == QMessageBox.Yes:
try: try:
if not os.path.exists(outpath):
os.mkdir(outpath)
with py7zr.SevenZipFile(file=path,mode='r') as file: with py7zr.SevenZipFile(file=path,mode='r') as file:
file.extractall(path=os.path.split(path)[0]) file.extractall(path=outpath)
except Exception as err: except Exception as err:
QMessageBox.warning(self,'解压失败','解压失败,原因:{}'.format(err),QMessageBox.Ok,QMessageBox.Ok) QMessageBox.warning(self,'解压失败','解压失败,原因:{}'.format(err),QMessageBox.Ok,QMessageBox.Ok)
return return
else: else:
QMessageBox.information(self,'解压成功','解压成功',QMessageBox.Ok,QMessageBox.Ok) QMessageBox.information(self,'解压成功','解压成功',QMessageBox.Ok,QMessageBox.Ok)
if in_ARModLauncher_path:
select = QMessageBox.question(self,'是否生成配置文件','检测到当前位于AR启动器的目录中,是否生成可以被AR启动器识别的附属mod配置文件?',QMessageBox.Yes|QMessageBox.Cancel,QMessageBox.Yes)
if select == QMessageBox.Yes:
try:
mods = [i for i in os.listdir(outpath) if os.path.splitext(i)[-1].lower() == '.skudef']
info_keys = info.keys()
mod_info = {}
mod_info['Id'] = os.path.split(path)[1].split('.')[0]
mod_info['Version'] = info['version'] if 'version' in info_keys else 'None'
mod_info['DisplayName_CN'] = info['name'] if 'name' in info_keys else 'None'
mod_info['DisplayName_EN'] = info['name_EN'] if 'name_EN' in info_keys else 'None'
mod_info['FilePath'] = os.path.join(os.path.split(path)[1].split('.')[0],mods[0])#仅添加第一个找到的skudef文件
mod_info['Desc_CN'] = info['introduce'] if 'introduce' in info_keys else 'None'
mod_info['Desc_EN'] = info['introduce_EN'] if 'introduce_EN' in info_keys else 'None'
with open(os.path.join(outpath,'config.json'),'w') as file:
json.dump(mod_info,file)
except Exception as err:
QMessageBox.warning(self,'生成失败','生成失败,原因:{}'.format(err),QMessageBox.Ok,QMessageBox.Ok)
return
else:
QMessageBox.information(self,'生成成功','生成成功',QMessageBox.Ok,QMessageBox.Ok)
def download_err(self,err:Exception): def download_err(self,err:Exception):
self.isdownloading = False self.isdownloading = False
os.remove(self.download_info[1])
self.progressBar_Download.setValue(0)
self.pushButton_Download.setText('下载')
QMessageBox.warning(self,'下载失败','下载失败,原因:{}'.format(err),QMessageBox.Ok,QMessageBox.Ok) QMessageBox.warning(self,'下载失败','下载失败,原因:{}'.format(err),QMessageBox.Ok,QMessageBox.Ok)
def set_new_version(self,version:str): def set_new_version(self,version:str):
self.label_about_newverison.setText("最新版本:"+version) self.label_about_newverison.setText("最新版本:"+version)
@ -394,6 +456,11 @@ class MainWindow(QMainWindow, Ui_MainWindow):
return return
else: else:
self.comboBox_mods.setCurrentIndex(currentIndex) self.comboBox_mods.setCurrentIndex(currentIndex)
def __on_pushButton_changeDir_ARModLauncher_clicked(self):
if self.ARModLauncher_path == '':
self.pushButton_changeDir_ARModLauncher.setEnabled(False)
return
self.lineEdit_savedir.setText(self.ARModLauncher_path)
def init(): def init():
app = QApplication(sys.argv) app = QApplication(sys.argv)
main_window = MainWindow() main_window = MainWindow()

View File

@ -3,7 +3,7 @@
################################################################################ ################################################################################
## Form generated from reading UI file 'MainWindow.ui' ## Form generated from reading UI file 'MainWindow.ui'
## ##
## Created by: Qt User Interface Compiler version 6.4.2 ## Created by: Qt User Interface Compiler version 6.5.1
## ##
## WARNING! All changes made in this file will be lost when recompiling UI file! ## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################ ################################################################################
@ -43,11 +43,11 @@ class Ui_MainWindow(object):
self.verticalLayout_3.addWidget(self.label_local) self.verticalLayout_3.addWidget(self.label_local)
self.listView_loacl = QListView(self.tab_local) self.listView_local = QListView(self.tab_local)
self.listView_loacl.setObjectName(u"listView_loacl") self.listView_local.setObjectName(u"listView_local")
self.listView_loacl.setEditTriggers(QAbstractItemView.NoEditTriggers) self.listView_local.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.verticalLayout_3.addWidget(self.listView_loacl) self.verticalLayout_3.addWidget(self.listView_local)
self.horizontalLayout.addLayout(self.verticalLayout_3) self.horizontalLayout.addLayout(self.verticalLayout_3)
@ -276,6 +276,11 @@ class Ui_MainWindow(object):
self.verticalLayout_8.addLayout(self.horizontalLayout_7) self.verticalLayout_8.addLayout(self.horizontalLayout_7)
self.pushButton_changeDir_ARModLauncher = QPushButton(self.tab_Network)
self.pushButton_changeDir_ARModLauncher.setObjectName(u"pushButton_changeDir_ARModLauncher")
self.verticalLayout_8.addWidget(self.pushButton_changeDir_ARModLauncher)
self.verticalSpacer_3 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) self.verticalSpacer_3 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
self.verticalLayout_8.addItem(self.verticalSpacer_3) self.verticalLayout_8.addItem(self.verticalSpacer_3)
@ -398,6 +403,7 @@ class Ui_MainWindow(object):
self.label_savedir.setText(QCoreApplication.translate("MainWindow", u"\u4fdd\u5b58\u5230:", None)) self.label_savedir.setText(QCoreApplication.translate("MainWindow", u"\u4fdd\u5b58\u5230:", None))
self.pushButton_savedir.setText(QCoreApplication.translate("MainWindow", u"...", None)) self.pushButton_savedir.setText(QCoreApplication.translate("MainWindow", u"...", None))
self.label_source.setText(QCoreApplication.translate("MainWindow", u"\u4e0b\u8f7d\u6e90:", None)) self.label_source.setText(QCoreApplication.translate("MainWindow", u"\u4e0b\u8f7d\u6e90:", None))
self.pushButton_changeDir_ARModLauncher.setText(QCoreApplication.translate("MainWindow", u"\u5207\u6362\u5230AR\u542f\u52a8\u5668\u76ee\u5f55", None))
self.pushButton_Download.setText(QCoreApplication.translate("MainWindow", u"\u4e0b\u8f7d", None)) self.pushButton_Download.setText(QCoreApplication.translate("MainWindow", u"\u4e0b\u8f7d", None))
self.tabWidget_Main.setTabText(self.tabWidget_Main.indexOf(self.tab_Network), QCoreApplication.translate("MainWindow", u"\u7f51\u7edc", None)) self.tabWidget_Main.setTabText(self.tabWidget_Main.indexOf(self.tab_Network), QCoreApplication.translate("MainWindow", u"\u7f51\u7edc", None))
self.label_about_author.setText(QCoreApplication.translate("MainWindow", u"\u4f5c\u8005:\u7530\u9f20-Hatanezumi", None)) self.label_about_author.setText(QCoreApplication.translate("MainWindow", u"\u4f5c\u8005:\u7530\u9f20-Hatanezumi", None))

View File

@ -38,7 +38,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QListView" name="listView_loacl"> <widget class="QListView" name="listView_local">
<property name="editTriggers"> <property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set> <set>QAbstractItemView::NoEditTriggers</set>
</property> </property>
@ -323,6 +323,13 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="QPushButton" name="pushButton_changeDir_ARModLauncher">
<property name="text">
<string>切换到AR启动器目录</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="verticalSpacer_3"> <spacer name="verticalSpacer_3">
<property name="orientation"> <property name="orientation">