🐛 修复当数据库文件不存在时的异常报错
@ -2,6 +2,7 @@ import math
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import aiosqlite
|
import aiosqlite
|
||||||
|
|
||||||
@ -12,10 +13,9 @@ from ..config import g_sDBFilePath, g_sDBPath
|
|||||||
|
|
||||||
class CSqlManager:
|
class CSqlManager:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
try:
|
dbPath = Path(g_sDBPath)
|
||||||
os.mkdir(g_sDBFilePath)
|
if dbPath and not dbPath.exists():
|
||||||
except FileExistsError:
|
os.makedirs(dbPath, exist_ok=True)
|
||||||
pass
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def cleanup(cls):
|
async def cleanup(cls):
|
||||||
@ -25,8 +25,7 @@ class CSqlManager:
|
|||||||
@classmethod
|
@classmethod
|
||||||
async def init(cls) -> bool:
|
async def init(cls) -> bool:
|
||||||
try:
|
try:
|
||||||
_ = os.path.exists(g_sDBFilePath)
|
cls.m_pDB = await aiosqlite.connect(g_sDBFilePath)
|
||||||
cls.m_pDB = await aiosqlite.connect(str(g_sDBFilePath))
|
|
||||||
cls.m_pDB.row_factory = aiosqlite.Row
|
cls.m_pDB.row_factory = aiosqlite.Row
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
BIN
resource/soil/浇水.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
resource/soil/浇水2.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
resource/soil/紫色土地.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
resource/soil/红土缺水.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
resource/soil/红色土地.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
resource/soil/肥沃土地.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
resource/soil/黄土 肥沃.png
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
resource/soil/黄土缺水.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
resource/soil/黑土.png
Normal file
|
After Width: | Height: | Size: 16 KiB |