优化配置文件的编码方式

This commit is contained in:
JoeamAmier 2023-12-10 21:42:52 +08:00
parent 9fd803ac09
commit 5f1e4a6657
6 changed files with 7 additions and 5 deletions

View File

@ -1,6 +1,7 @@
from json import dump
from json import load
from pathlib import Path
from platform import system
__all__ = ['Settings']
@ -16,6 +17,7 @@ class Settings:
"chunk": 1024 * 1024,
"max_retry": 5,
}
encode = "UTF-8-SIG" if system() == "Windows" else "UTF-8"
def __init__(self, root: Path):
self.file = root.joinpath("./settings.json")
@ -24,14 +26,14 @@ class Settings:
return self.read() if self.file.is_file() else self.create()
def read(self) -> dict:
with self.file.open("r", encoding="utf-8") as f:
with self.file.open("r", encoding=self.encode) as f:
return load(f)
def create(self) -> dict:
with self.file.open("w", encoding="utf-8") as f:
with self.file.open("w", encoding=self.encode) as f:
dump(self.default, f, indent=4)
return self.default
def update(self, data: dict):
with self.file.open("w", encoding="utf-8") as f:
with self.file.open("w", encoding=self.encode) as f:
dump(data, f, indent=4, ensure_ascii=False)

View File

@ -14,7 +14,7 @@ from textual.widgets import Footer
from textual.widgets import Header
from textual.widgets import Input
from textual.widgets import Label
from textual.widgets import ProgressBar
# from textual.widgets import ProgressBar
from textual.widgets import RichLog
from .Downloader import Download
@ -209,7 +209,7 @@ class XHSDownloader(App):
return
self.url = self.query_one(Input)
self.log_ = self.query_one(RichLog)
self.bar = self.query_one(ProgressBar)
# self.bar = self.query_one(ProgressBar)
async def action_check_update(self):
self.__init_objects()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 132 KiB

After

Width:  |  Height:  |  Size: 125 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 158 KiB

After

Width:  |  Height:  |  Size: 157 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 14 KiB