mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-06-05 21:59:24 +02:00
Merge pull request #333 from one-some/UI2
Be a little less paranoid when saving
This commit is contained in:
@@ -929,16 +929,22 @@ class story_settings(settings):
|
|||||||
if self.story_id == j["story_id"]:
|
if self.story_id == j["story_id"]:
|
||||||
break
|
break
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
raise FileNotFoundError("Malformed save file: Missing story.json")
|
logger.error(f"Malformed save file: Missing story.json in {self.save_paths.base}. Populating it with new data.")
|
||||||
|
break
|
||||||
|
|
||||||
disambiguator += 1
|
disambiguator += 1
|
||||||
self.save_paths.base = os.path.join("stories", save_name + (f" ({disambiguator})" if disambiguator else ""))
|
self.save_paths.base = os.path.join("stories", save_name + (f" ({disambiguator})" if disambiguator else ""))
|
||||||
|
|
||||||
if not os.path.exists(self.save_paths.base):
|
# Setup the directory structure.
|
||||||
# We are making the story for the first time. Setup the directory structure.
|
for path in [
|
||||||
os.mkdir(self.save_paths.base)
|
self.save_paths.base,
|
||||||
os.mkdir(self.save_paths.generated_audio)
|
self.save_paths.generated_audio,
|
||||||
os.mkdir(self.save_paths.generated_images)
|
self.save_paths.generated_images,
|
||||||
|
]:
|
||||||
|
try:
|
||||||
|
os.mkdir(path)
|
||||||
|
except FileExistsError:
|
||||||
|
pass
|
||||||
|
|
||||||
# Convert v2 if applicable
|
# Convert v2 if applicable
|
||||||
v2_path = os.path.join("stories", f"{self.story_name}_v2.json")
|
v2_path = os.path.join("stories", f"{self.story_name}_v2.json")
|
||||||
@@ -946,8 +952,11 @@ class story_settings(settings):
|
|||||||
logger.info("Migrating v2 save")
|
logger.info("Migrating v2 save")
|
||||||
with open(v2_path, "r") as file:
|
with open(v2_path, "r") as file:
|
||||||
v2j = json.load(file)
|
v2j = json.load(file)
|
||||||
assert v2j["story_id"] == self.story_id
|
|
||||||
shutil.move(v2_path, os.path.join(self.save_paths.base, ".v2_old.json"))
|
if v2j["story_id"] == self.story_id:
|
||||||
|
shutil.move(v2_path, os.path.join(self.save_paths.base, ".v2_old.json"))
|
||||||
|
else:
|
||||||
|
logger.warning(f"Story mismatch in v2 migration. Existing file had story id {v2j['story_id']} but we have {self.story_id}")
|
||||||
|
|
||||||
with open(self.save_paths.story, "w") as file:
|
with open(self.save_paths.story, "w") as file:
|
||||||
file.write(self.to_json())
|
file.write(self.to_json())
|
||||||
|
Reference in New Issue
Block a user