mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Log the time it takes to save the game.
This commit is contained in:
parent
e80851b0a1
commit
32dd0f543a
@ -1,12 +1,13 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
import pickle
|
import pickle
|
||||||
import shutil
|
import shutil
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional, TYPE_CHECKING
|
from typing import Optional, TYPE_CHECKING
|
||||||
|
|
||||||
|
from game.profiling import logged_duration
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from game import Game
|
from game import Game
|
||||||
|
|
||||||
@ -54,14 +55,15 @@ def load_game(path: str) -> Optional[Game]:
|
|||||||
|
|
||||||
|
|
||||||
def save_game(game: Game) -> bool:
|
def save_game(game: Game) -> bool:
|
||||||
try:
|
with logged_duration("Saving game"):
|
||||||
with open(_temporary_save_file(), "wb") as f:
|
try:
|
||||||
pickle.dump(game, f)
|
with open(_temporary_save_file(), "wb") as f:
|
||||||
shutil.copy(_temporary_save_file(), game.savepath)
|
pickle.dump(game, f)
|
||||||
return True
|
shutil.copy(_temporary_save_file(), game.savepath)
|
||||||
except Exception:
|
return True
|
||||||
logging.exception("Could not save game")
|
except Exception:
|
||||||
return False
|
logging.exception("Could not save game")
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def autosave(game: Game) -> bool:
|
def autosave(game: Game) -> bool:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user