Browse Source

更新V4.4 完善部分异常的处理,增加程序健壮性

剑断了 2 years ago
parent
commit
a0f7fc75ce
2 changed files with 22 additions and 9 deletions
  1. 2 0
      FileOperator.py
  2. 20 9
      main.py

+ 2 - 0
FileOperator.py

@@ -255,6 +255,7 @@ FileOperator 新增
 # 创建记忆文件
 # 创建记忆文件
 def SaveForOutput(path, fileName):
 def SaveForOutput(path, fileName):
     # fileName = "localPath.config"
     # fileName = "localPath.config"
+    file = None
     fullpath = os.path.join(path, fileName)
     fullpath = os.path.join(path, fileName)
     if not os.path.exists(fullpath):  # 如果路径不存在,创建路径,写入文件,返回False
     if not os.path.exists(fullpath):  # 如果路径不存在,创建路径,写入文件,返回False
         try:
         try:
@@ -281,6 +282,7 @@ def ReadForOutput(path):
 
 
 # 写入首行的内容
 # 写入首行的内容
 def WriteForOutput(path, downloadPath, outputPath):
 def WriteForOutput(path, downloadPath, outputPath):
+    f = None
     try:
     try:
         f = open(path, "w", encoding="utf-8")
         f = open(path, "w", encoding="utf-8")
         f.write(downloadPath + '\n')
         f.write(downloadPath + '\n')

+ 20 - 9
main.py

@@ -12,7 +12,7 @@ from MainWindow import Ui_MainWindow
 from icon import img
 from icon import img
 import TitleSpider
 import TitleSpider
 
 
-
+global canRun
 def GetSeries(dataList):
 def GetSeries(dataList):
     return int(dataList.split('_')[1])
     return int(dataList.split('_')[1])
 
 
@@ -20,13 +20,18 @@ def GetSeries(dataList):
 class MainApp(QMainWindow, Ui_MainWindow):
 class MainApp(QMainWindow, Ui_MainWindow):
 
 
     def __init__(self):
     def __init__(self):
+        global canRun
         QMainWindow.__init__(self)
         QMainWindow.__init__(self)
+        if not self.SetUI():
+            canRun = False
+            return
+        else:
+            canRun = True
         self.setupUi(self)
         self.setupUi(self)
 
 
         self.SetBaseInfo()
         self.SetBaseInfo()
         self.InitMenuBar()
         self.InitMenuBar()
         self.HandleButtons()
         self.HandleButtons()
-        self.SetUI()
         self.setFixedSize(self.width(), self.height())
         self.setFixedSize(self.width(), self.height())
         self.SetLogText()
         self.SetLogText()
         self.progressBar.setValue(0)
         self.progressBar.setValue(0)
@@ -39,6 +44,7 @@ class MainApp(QMainWindow, Ui_MainWindow):
         self.isTextSecondColumnHaveContent = False
         self.isTextSecondColumnHaveContent = False
         self.InitOutPutPath() # 发布绿色版时注释
         self.InitOutPutPath() # 发布绿色版时注释
 
 
+
     def InitOutPutPath(self):
     def InitOutPutPath(self):
         self.isTextFileExists = FileOperator.SaveForOutput(self.path, self.saveName)
         self.isTextFileExists = FileOperator.SaveForOutput(self.path, self.saveName)
         if self.isTextFileExists is False:  # 如果没有文件,在已经创建文件的前提下,等待用户输入手动填入OutputText. 相关事件在button事件实现
         if self.isTextFileExists is False:  # 如果没有文件,在已经创建文件的前提下,等待用户输入手动填入OutputText. 相关事件在button事件实现
@@ -171,17 +177,20 @@ class MainApp(QMainWindow, Ui_MainWindow):
 
 
     # 设置UI
     # 设置UI
     def SetUI(self):
     def SetUI(self):
-        tmp = open('tmp.png', "wb+")
+        tmp = None
         try:
         try:
+            tmp = open('tmp.png', "wb+")
             tmp.write(base64.b64decode(img))
             tmp.write(base64.b64decode(img))
         except Exception as e:
         except Exception as e:
-            QMessageBox.critical(self, "错误", "请关闭本程序并使用管理员权限运行本软件!或卸载本软件再重新安装至其它非系统盘 比如:D盘、E盘!" + str(e))
-            return
-
-        tmp.close()
+            QMessageBox.critical(self, "错误", "您当前安装在了C盘,软件权限不足:\n解决方案一:请关闭本程序并每次使用管理员权限运行本软件 \n解决方案二:卸载本软件再重新安装至其它非系统盘 比如:D盘、E盘!")
+            return False
+        finally:
+            if tmp:
+                tmp.close()
         icon = QIcon('tmp.png')
         icon = QIcon('tmp.png')
         os.remove("tmp.png")
         os.remove("tmp.png")
         self.setWindowIcon(icon)
         self.setWindowIcon(icon)
+        return True
 
 
     def ShowAboutDialog(self):
     def ShowAboutDialog(self):
         about_text = "<p>描述:这是一款致力于解决BiliBili UWP版下载后的视频加密、命名信息丢失和存放位置不合理等痛点的软件</p><p>版本:4.4</p><p>@Author:LZY</p><p>@github:love" \
         about_text = "<p>描述:这是一款致力于解决BiliBili UWP版下载后的视频加密、命名信息丢失和存放位置不合理等痛点的软件</p><p>版本:4.4</p><p>@Author:LZY</p><p>@github:love" \
@@ -330,5 +339,7 @@ if __name__ == '__main__':
 
 
     app = QApplication([])
     app = QApplication([])
     window = MainApp()
     window = MainApp()
-    window.show()
-    app.exec_()
+    if canRun:
+        window.show()
+        app.exec_()
+