Commit fb06055b authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

Window: Fix save for windows version.

Showing with 21 additions and 6 deletions
+21 -6
......@@ -4,6 +4,8 @@ import os
import shutil
from datetime import datetime
from tools import timer, timestamp
from Model.DB import SQLModel
from Model.Saved import SavedStatus
from Model.Serializable import Serializable
......@@ -69,11 +71,15 @@ class Study(SQLModel):
fdir, fname = os.path.split(self.filename)
if self._old_save_id == 0:
old_dir = os.path.join(fdir, "__old__")
if os.name == "nt":
old_dir = old_dir.replace("/", "\\")
try:
os.makedirs(os.path.join(fdir, "__old__"))
os.makedirs(old_dir)
except FileExistsError as e:
shutil.rmtree(os.path.join(fdir, "__old__"))
os.makedirs(os.path.join(fdir, "__old__"))
shutil.rmtree(old_dir)
os.makedirs(old_dir)
except Exception as e:
print(e)
......@@ -227,9 +233,9 @@ class Study(SQLModel):
self.execute(f"UPDATE info SET value='{self._sql_format(self.name)}' WHERE key='name'")
self.execute(f"UPDATE info SET value='{self._sql_format(self.description)}' WHERE key='description'")
self.execute(f"UPDATE info SET value='{self._time_system}' WHERE key='time_system'")
self.execute(f"UPDATE info SET value='{self._date.timestamp()}' WHERE key='date'")
self.execute(f"UPDATE info SET value='{self.creation_date.timestamp()}' WHERE key='creation_date'")
self.execute(f"UPDATE info SET value='{self.last_save_date.timestamp()}' WHERE key='last_save_date'")
self.execute(f"UPDATE info SET value='{timestamp(self._date)}' WHERE key='date'")
self.execute(f"UPDATE info SET value='{timestamp(self.creation_date)}' WHERE key='creation_date'")
self.execute(f"UPDATE info SET value='{timestamp(self.last_save_date)}' WHERE key='last_save_date'")
self._save_submodel([self._river])
self.commit()
# -*- coding: utf-8 -*-
import os
import time
import sqlite3
import traceback
from datetime import datetime
from pathlib import Path
from colorama import Fore
......@@ -135,6 +137,13 @@ def flatten(lst):
return reduce(list.__add__, lst)
def timestamp(dt:datetime):
# Fix timestamp for some windows version.
# - Issue : (https://bugs.python.org/issue29097)
if os.name == 'nt':
return (dt - datetime(1970, 1, 1)).total_seconds()
return dt.timestamp()
def old_pamhyr_date_to_timestamp(date:str):
v = date.split(":")
if len(v) != 4:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment