Browse Source

V4.0【安装版】在选择文件夹时会记忆上一次的位置

剑断了 2 years ago
parent
commit
876bb693cc
2 changed files with 82 additions and 11 deletions
  1. 34 0
      FileOperator.py
  2. 48 11
      main.py

+ 34 - 0
FileOperator.py

@@ -234,3 +234,37 @@ def MakeDir(path, name):
         os.makedirs(dir)
 
     return dir
+
+
+'''
+FileOperator 新增
+'''
+
+
+# 创建记忆文件
+def SaveForOutput(path, fileName):
+    # fileName = "localPath.config"
+    fullpath = os.path.join(path, fileName)
+    if not os.path.exists(fullpath):  # 如果路径不存在,创建路径,写入文件,返回False
+        file = open(fileName, "w", encoding="utf-8")
+        file.close()
+        return False
+    else:
+        return True
+
+
+# 读文件的内容 这里的path是已经join过的
+def ReadForOutput(path):
+    lines = ['', '']
+    if os.path.isfile(path):
+        with open(path, encoding='UTF-8') as f:
+            lines = f.readlines()  # 新文件名按行保存
+            f.close()
+    return lines
+
+
+# 写入首行的内容
+def WriteForOutput(path, downloadPath, outputPath):
+    with open(path, "w", encoding="utf-8") as f:
+        f.write(downloadPath+'\n')
+        f.write(outputPath)

+ 48 - 11
main.py

@@ -29,6 +29,35 @@ class MainApp(QMainWindow, Ui_MainWindow):
         self.SetLogText()
         self.progressBar.setValue(0)
         self.InitCheckBox()
+        self.path = os.getcwd()
+        self.saveName = "set.ini"
+        self.joinedPath = os.path.join(self.path, self.saveName)  # 配置文件的位置
+        self.isTextFileExists = False
+        self.isTextFirstColumnHaveContent = False
+        self.isTextSecondColumnHaveContent = False
+        self.InitOutPutPath() # 发布绿色版时注释
+
+    def InitOutPutPath(self):
+        self.isTextFileExists = FileOperator.SaveForOutput(self.path, self.saveName)
+        if self.isTextFileExists is False:  # 如果没有文件,在已经创建文件的前提下,等待用户输入手动填入OutputText. 相关事件在button事件实现
+            # line = FileOperator.ReadForOutput() #
+            pass
+        else:  # 存在文件 则读取文件,并自动赋给文本框
+            self.lines = FileOperator.ReadForOutput(self.joinedPath)
+            if len(self.lines) >= 2:
+                if self.lines[0] != '':
+                    if os.path.isdir(self.lines[0].strip()):
+                        self.downloadDirEdit.setText(self.lines[0])
+                        self.isTextFirstColumnHaveContent = True
+                if self.lines[1] != '':
+                    if os.path.isdir(self.lines[1].strip()):
+                        self.outputDirEdit.setText(self.lines[1])
+                        self.isTextSecondColumnHaveContent = True
+
+            else:
+                pass
+                # self.Log("检测到配置文件set.ini 为空")
+                # QMessageBox.critical(self, "错误", "配置文件set.ini !")
 
     def InitCheckBox(self):
         # self.txtFileCheckBox.setChecked(True)  # 默认保存Txt
@@ -118,12 +147,12 @@ class MainApp(QMainWindow, Ui_MainWindow):
     def DisableSpiderMode(self):
         if self.spiderMode.isChecked():
             self.spiderMode.setChecked(False)
-        self.renameButton.setText("一键整理+重命名")
+        self.renameButton.setText("一键解密+整理+重命名")
 
     def DisableLocalMode(self):
         if self.localMode.isChecked():
             self.localMode.setChecked(False)
-        self.renameButton.setText("一键爬取+整理+重命名")
+        self.renameButton.setText("一键解密+爬取+整理+重命名")
 
     def InitMenuBar(self):
         # 添加menu“帮助”的事件
@@ -148,17 +177,25 @@ class MainApp(QMainWindow, Ui_MainWindow):
         self.setWindowIcon(icon)
 
     def ShowAboutDialog(self):
-        about_text = "<p>描述:这是一个致力于解决BiliBiLi UWP版下载视频的名称十分反人类的痛点的软件</p><p>版本:3.0</p><p>@Author:LZY</p><p>@github:love" \
+        about_text = "<p>描述:这是一款致力于解决BiliBili UWP版下载后的视频加密、命名信息丢失和存放位置不合理等痛点的软件</p><p>版本:4.0</p><p>@Author:LZY</p><p>@github:love" \
                      "-in-cpp</p> "
         QMessageBox.about(self, '说明', about_text)
 
     def OpenDownloadDir(self):
-        dName = QFileDialog.getExistingDirectory(self, '选择文件夹', '/')
-        self.downloadDirEdit.setText(dName)
+        if self.isTextFirstColumnHaveContent is False:
+            dName = QFileDialog.getExistingDirectory(self, '选择下载文件夹', '/')
+            self.downloadDirEdit.setText(dName)
+        else:
+            dName = QFileDialog.getExistingDirectory(self, '选择下载文件夹', self.lines[0].strip())
+            self.downloadDirEdit.setText(dName)
 
     def OpenOutputDir(self):
-        dName = QFileDialog.getExistingDirectory(self, '选择文件夹', '/')
-        self.outputDirEdit.setText(dName)
+        if self.isTextSecondColumnHaveContent is False:
+            dName = QFileDialog.getExistingDirectory(self, '选择输出文件夹', '/')
+            self.outputDirEdit.setText(dName)
+        else:
+            dName = QFileDialog.getExistingDirectory(self, '选择输出文件夹', self.lines[1].strip())
+            self.outputDirEdit.setText(dName)
 
     def SetBaseInfo(self):
         self.setWindowTitle('BiliBili UWP版视频下载整理工具')
@@ -174,7 +211,7 @@ class MainApp(QMainWindow, Ui_MainWindow):
         # 进入目录查找dvi文件
         downloadPath = self.downloadDirEdit.toPlainText()
         outputPath = self.outputDirEdit.toPlainText()
-        if os.path.isdir(downloadPath) is False:
+        if os.path.isdir(downloadPath) is False or os.path.isdir(self.downloadDirEdit.toPlainText().strip()) is False:
             self.Log('UWP下载目录的路径存在非法输入!')
 
         else:
@@ -220,11 +257,11 @@ class MainApp(QMainWindow, Ui_MainWindow):
                     s += (item + '\n')
                 self.Log(s)
 
-
-
-                if os.path.isdir(outputPath) is False:
+                if os.path.isdir(outputPath) is False or os.path.isdir(self.outputDirEdit.toPlainText().strip()) is False:
                     self.Log('输出目录的路径存在非法输入!')
                 else:
+                    # 记忆输出目录
+                    FileOperator.WriteForOutput(self.joinedPath, os.path.dirname(downloadPath), self.outputDirEdit.toPlainText()) # 发布绿色版时注释
                     # 解密
                     self.Log("开始解密...")
                     FileOperator.DecryptMp4(downloadPath, dviInfoList[2])