From 03f9547517600e273727143ff554c0f84be8421a Mon Sep 17 00:00:00 2001 From: "Bail(OnePlus PJF110)" <2915289604@qq.com> Date: Wed, 26 Jun 2024 21:37:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E4=B8=8B=E8=BD=BDwi?= =?UTF-8?q?ne=E6=97=B6=E7=94=B1=E4=BA=8E=E5=A4=A7=E5=B0=8F=E6=9C=AA?= =?UTF-8?q?=E7=9F=A5=E5=BC=95=E8=B5=B7=E7=9A=84=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wine/installwine | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/wine/installwine b/wine/installwine index 1b4eb74..d0fb32e 100755 --- a/wine/installwine +++ b/wine/installwine @@ -230,7 +230,11 @@ class DownloadThread(QtCore.QThread): # 文件下载 timeout = 0 f = requests.get(self.fileUrl, stream=True) - allSize = int(f.headers["content-length"]) # 文件总大小 + if "content-length" in f.headers: + progressable = True # 大小已知,可使用进度条 + allSize = int(f.headers["content-length"]) # 文件总大小 + else: + progressable = False bytesRead = 0 with open(savePath, "wb") as filePart: for chunk in f.iter_content(chunk_size=1024): @@ -238,7 +242,8 @@ class DownloadThread(QtCore.QThread): #progressbar.update(int(part / show)) filePart.write(chunk) bytesRead += 1024 - self.ChangeDialog.emit(self.dialog, int(bytesRead / allSize * 100), int(bytesRead / 1024 / 1024), int(allSize / 1024 / 1024)) + if progressable: + self.ChangeDialog.emit(self.dialog, int(bytesRead / allSize * 100), int(bytesRead / 1024 / 1024), int(allSize / 1024 / 1024)) # 写入配置文件 rfile = open(f"{programPath}/winelist.json", "r") list = json.loads(rfile.read()) @@ -413,4 +418,4 @@ if __name__ == "__main__": # 图标 ui.centralWidget.setWindowIcon(QtGui.QIcon(f"{programPath}/../deepin-wine-runner.svg")) - app.exec_() \ No newline at end of file + app.exec_() -- Gitee