# -*- coding:utf-8 -*- from pyec.wx模块 import * import wx import configparser import re import psutil import time from subprocess import Popen import sys import mainui from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox # 界面文件为 FirstMainWin.py from mainui import * import requests import os configFile = 'config.ini' # 创建配置文件对象 config = configparser.ConfigParser() # 读取文件 config.read(configFile, encoding='utf-8') class MainWindow(QMainWindow, Ui_MainWindow): def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.setupUi(self) # 初始赋值 self.nowIpLabel.setText(config['DEFAULT']['now_ip']) self.newIpInput.setText(config['DEFAULT']['new_ip']) self.nowGameLabel.setText(config['DEFAULT']['game_name']) self.newGameInput.setText(config['DEFAULT']['game_name']) if isinstance(checkprocess("nginx.exe"), int): # self.启动Nginx.Label = '关闭Nginx' self.nginxButton.setText("关闭Nginx") else: # self.启动Nginx.Label = '启动Nginx' self.nginxButton.setText("启动Nginx") def saveSet(self, event): print('保存设置,按钮被单击') message = QMessageBox.information(self, "提示信息", "确定要保存设置吗?", QMessageBox.Ok | QMessageBox.No, QMessageBox.No); if message == QMessageBox.No: return now_ip = config['DEFAULT']['now_ip'] new_ip = self.newIpInput.text() now_game = config['DEFAULT']['game_name'] new_game = self.newGameInput.text() compile_ip = re.compile('^(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|[1-9])\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)$') # 验证IP地址格式 if (new_ip == "") or new_game == "" or not (compile_ip.match(new_ip)): QMessageBox.information(self, "提示信息", "IP地址、游戏名称为空或有误,请正确填写IPv4地址或游戏名称!", QMessageBox.Ok, QMessageBox.Ok); return dirname = config['MODFILE']['dirname'] print(dirname.split("|")[1]) # filedir = dirname.split("|") sum = 0 for filedir in dirname.split("|"): # fileencoding = filedir.split(",") # 执行文本替换 if len(filedir.split(",")) < 2: isencoding = config['DEFAULT']['file_encoding'] else: isencoding = filedir.split(",")[1] filename = config['DEFAULT']['dir'] + filedir.split(",")[0] try: with open(filename, 'rt+', encoding=isencoding) as f: t = f.read() t = t.replace(now_ip, new_ip) t = t.replace(now_game, new_game) # 读写偏移位置移到最开始处 f.seek(0, 0) f.write(t) # 设置文件结尾 EOF f.truncate() sum = sum + 1 except: QMessageBox.information(self, "提示信息", "替换“" + filename + "”出错,可能文件不存在或编码不对,请检查需要替换的文件编码与配置文件编码是否相符!", QMessageBox.Ok, QMessageBox.Ok) return # 写入配置文件 config.set('DEFAULT', 'game_name', new_game) config.set('DEFAULT', 'now_ip', new_ip) config.set('DEFAULT', 'new_ip', new_ip) saveconfig = open(configFile, 'wt', encoding=config['DEFAULT']['file_encoding']) config.write(saveconfig) # 把要修改的节点的内容写到文件中 saveconfig.close() # 设置界面显示 self.nowGameLabel.setText(new_game) self.nowIpLabel.setText(new_ip) # 成功提示 QMessageBox.information(self, "提示信息", "游戏名称和IP修改成功!", QMessageBox.Ok, QMessageBox.Ok) print('修改完成:' + new_game + ':' + new_ip) return def nginx(self, event): if self.nginxButton.text() == '启动Nginx': nginx_process = Popen('start .\\nginx.exe', shell=True, cwd=config['DEFAULT']['dir'] + 'phpstudy_pro\\Extensions\\Nginx1.15.11', # encoding='utf-8' ) php_process = Popen('.\\COM\\php-cgi-spawner.exe "Extensions\\php\\php5.6.9nts\\php-cgi.exe -c Extensions\\php\\php5.6.9nts\\php.ini" 9001 1+16', shell=True, cwd=config['DEFAULT']['dir'] + 'phpstudy_pro', # encoding='utf-8' ) self.nginxButton.setText("关闭Nginx") else: nginx_process = Popen('.\\nginx.exe -s stop', shell=True, cwd=config['DEFAULT']['dir'] + 'phpstudy_pro\\Extensions\\Nginx1.15.11', # encoding='utf-8' ) PHP_process = Popen('taskkill /f /t /im php-cgi.exe', shell=True, # encoding='utf-8' ) spawner_process = Popen('taskkill /f /t /im php-cgi-spawner.exe', shell=True, # encoding='utf-8' ) self.nginxButton.setText("启动Nginx") # print(process) # os.chdir("D:\\LYserver\\phpstudy_pro\\Extensions\\Nginx1.15.11") # nginxtype = os.system('start .\\nginx.exe') # 不弹出界面 # if nginxtype # os.system('start .\\nginx.exe') #弹出界面 print('启动Nginx,按钮被单击') def mysql(self, event): if self.启动MySql.Label == '启动MySql': php_process = Popen('.\\mysqld.exe', shell=True, cwd=config['DEFAULT']['dir'] + 'phpstudy_pro\\Extensions\\MySQL5.7.26\\bin', # encoding='utf-8' ) self.启动MySql.Label = '关闭MySql' else: kill_process = Popen('taskkill /f /t /im mysqld.exe', shell=True, # encoding='utf-8' ) self.启动MySql.Label = '启动MySql' print('启动MySql,按钮被单击') def game(self, event): if self.启动服务端.Label == '启动服务端': AMServer64_R = Popen('start .\\AMServer64_R.exe', shell=True, cwd=config['DEFAULT']['dir'] + 'build_pub\\Common\\AMServer\\x64', # encoding='utf-8' ) LocalLogServer64_R = Popen('start .\\LocalLogServer64_R.exe', shell=True, cwd=config['DEFAULT']['dir'] + 'build_pub\\Common\\LocalLogServer\\x64', # encoding='utf-8' ) LoggerServer64_R = Popen('start .\\LoggerServer64_R.exe', shell=True, cwd=config['DEFAULT']['dir'] + 'build_pub\\Common\\LoggerServer\\x64', # encoding='utf-8' ) NameServer64_R = Popen('start .\\SessionServer64_R.exe', shell=True, cwd=config['DEFAULT']['dir'] + 'build_pub\\Common\\SessionServer\\x64', # encoding='utf-8' ) NameServer64_R = Popen('start .\\NameServer64_R.exe', shell=True, cwd=config['DEFAULT']['dir'] + 'build_pub\\Common\\NameServer\\x64', # encoding='utf-8' ) BackStageServer64_R = Popen('start .\\BackStageServer64_R.exe', shell=True, cwd=config['DEFAULT']['dir'] + 'build_pub\\Common\\BackStageServer\\x64', # encoding='utf-8' ) time.sleep(5) # 延迟5秒 # 一区 DBServer64_R = Popen('start .\\DBServer64_R.exe', shell=True, cwd=config['DEFAULT']['dir'] + 'build_pub\\Server\\DBServer\\x64', # encoding='utf-8' ) GateServer64_R = Popen('start .\\GateServer64_R.exe', shell=True, cwd=config['DEFAULT']['dir'] + 'build_pub\\Server\\GateServer\\x64', # encoding='utf-8' ) LogicServerCQ64_R = Popen('start .\\LogicServerCQ64_R.exe', shell=True, cwd=config['DEFAULT']['dir'] + 'build_pub\\Server\\LogicServer\\x64', # encoding='utf-8' ) # 二区 DBServer64_R = Popen('start .\\DBServer64_R.exe', shell=True, cwd=config['DEFAULT']['dir'] + 'build_pub\\Server2\\DBServer\\x64', # encoding='utf-8' ) GateServer64_R = Popen('start .\\GateServer64_R.exe', shell=True, cwd=config['DEFAULT']['dir'] + 'build_pub\\Server2\\GateServer\\x64', # encoding='utf-8' ) LogicServerCQ64_R = Popen('start .\\LogicServerCQ64_R.exe', shell=True, cwd=config['DEFAULT']['dir'] + 'build_pub\\Server2\\LogicServer\\x64', # encoding='utf-8' ) # 跨服 DBServer64_R = Popen('start .\\DBServer64_R.exe', shell=True, cwd=config['DEFAULT']['dir'] + 'build_pub\\Server跨服\\DBServer\\x64', # encoding='utf-8' ) GateServer64_R = Popen('start .\\GateServer64_R.exe', shell=True, cwd=config['DEFAULT']['dir'] + 'build_pub\\Server跨服\\GateServer\\x64', # encoding='utf-8' ) LogicServerCQ64_R = Popen('start .\\LogicServerCQ64_R.exe', shell=True, cwd=config['DEFAULT']['dir'] + 'build_pub\\Server跨服\\LogicServer\\x64', # encoding='utf-8' ) self.启动服务端.Label = '关闭服务端' else: kill_process = Popen( 'taskkill /f /t /im LocalLogServer64_R.exe & taskkill /f /t /im LoggerServer64_R.exe & taskkill /f /t /im SessionServer64_R.exe & taskkill /f /t /im NameServer64_R.exe & taskkill /f /t /im LogicServerCQ64_R.exe & taskkill /f /t /im GateServer64_R.exe & taskkill /f /t /im DBCenterServer64_R.exe & taskkill /f /t /im DBServer64_R.exe & taskkill /f /t /im BackStageServer64_R.exe & taskkill /f /t /im AMServer64_R.exe', shell=True, # encoding='utf-8' ) self.启动服务端.Label = '启动服务端' print('启动服务端,按钮被单击') def fanbianyi(self, event): apktool = Popen('apktool d game.apk', shell=True, cwd=config['DEFAULT']['dir'] + 'apk', # encoding='utf-8' ) print('反编译APK,按钮被单击') def shengcheng(self, event): apktool = Popen('apktool b game', shell=True, cwd=config['DEFAULT']['dir'] + 'apk', # encoding='utf-8' ) print('生成APK,按钮被单击') def qianming(self, event): apktool = Popen('jarsigner -verbose -keystore key.keystore -storepass 123456 -signedjar game-signed.apk game/dist/game.apk key.keystore', shell=True, cwd=config['DEFAULT']['dir'] + 'apk', # encoding='utf-8' ) print('APK签名,按钮被单击') # 进程判断,返回进程ID def checkprocess(processname): pl = psutil.pids() for pid in pl: if psutil.Process(pid).name() == processname: return pid if __name__ == '__main__': app = QApplication(sys.argv) myWin = MainWindow() myWin.show() sys.exit(app.exec_())