mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-06-05 21:59:24 +02:00
Merge pull request #293 from jojorne/jojorne-patch-save-load-story-with-UTF-8-encoding
Save/Load Story with UTF-8 encoding.
This commit is contained in:
@@ -7273,7 +7273,7 @@ def save():
|
|||||||
save_name = koboldai_vars.story_name if koboldai_vars.story_name != "" else "untitled"
|
save_name = koboldai_vars.story_name if koboldai_vars.story_name != "" else "untitled"
|
||||||
same_story = True
|
same_story = True
|
||||||
if os.path.exists("stories/{}".format(save_name)):
|
if os.path.exists("stories/{}".format(save_name)):
|
||||||
with open("stories/{}/story.json".format(save_name), "r") as settings_file:
|
with open("stories/{}/story.json".format(save_name), "r", encoding="utf-8") as settings_file:
|
||||||
json_data = json.load(settings_file)
|
json_data = json.load(settings_file)
|
||||||
if 'story_id' in json_data:
|
if 'story_id' in json_data:
|
||||||
same_story = json_data['story_id'] == koboldai_vars.story_id
|
same_story = json_data['story_id'] == koboldai_vars.story_id
|
||||||
@@ -7334,7 +7334,7 @@ def saveRequest(savpath, savepins=True):
|
|||||||
|
|
||||||
# Write it
|
# Write it
|
||||||
try:
|
try:
|
||||||
file = open(savpath, "w")
|
file = open(savpath, "w", encoding="utf-8")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return e
|
return e
|
||||||
try:
|
try:
|
||||||
@@ -7345,7 +7345,7 @@ def saveRequest(savpath, savepins=True):
|
|||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
file = open(txtpath, "w")
|
file = open(txtpath, "w", encoding="utf-8")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return e
|
return e
|
||||||
try:
|
try:
|
||||||
@@ -7429,7 +7429,7 @@ def loadRequest(loadpath, filename=None):
|
|||||||
# Read file contents into JSON object
|
# Read file contents into JSON object
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
if(isinstance(loadpath, str)):
|
if(isinstance(loadpath, str)):
|
||||||
with open(loadpath, "r") as file:
|
with open(loadpath, "r", encoding="utf-8") as file:
|
||||||
js = json.load(file)
|
js = json.load(file)
|
||||||
from_file=loadpath
|
from_file=loadpath
|
||||||
if(filename is None):
|
if(filename is None):
|
||||||
|
@@ -938,7 +938,7 @@ class story_settings(settings):
|
|||||||
while os.path.exists(self.save_paths.base):
|
while os.path.exists(self.save_paths.base):
|
||||||
try:
|
try:
|
||||||
# If the stories share a story id, overwrite the existing one.
|
# If the stories share a story id, overwrite the existing one.
|
||||||
with open(self.save_paths.story, "r") as file:
|
with open(self.save_paths.story, "r", encoding="utf-8") as file:
|
||||||
j = json.load(file)
|
j = json.load(file)
|
||||||
if self.story_id == j["story_id"]:
|
if self.story_id == j["story_id"]:
|
||||||
break
|
break
|
||||||
@@ -960,7 +960,7 @@ class story_settings(settings):
|
|||||||
v2_path = os.path.join("stories", f"{self.story_name}_v2.json")
|
v2_path = os.path.join("stories", f"{self.story_name}_v2.json")
|
||||||
if os.path.exists(v2_path):
|
if os.path.exists(v2_path):
|
||||||
logger.info("Migrating v2 save")
|
logger.info("Migrating v2 save")
|
||||||
with open(v2_path, "r") as file:
|
with open(v2_path, "r", encoding="utf-8") as file:
|
||||||
v2j = json.load(file)
|
v2j = json.load(file)
|
||||||
|
|
||||||
if v2j["story_id"] == self.story_id:
|
if v2j["story_id"] == self.story_id:
|
||||||
@@ -968,7 +968,7 @@ class story_settings(settings):
|
|||||||
else:
|
else:
|
||||||
logger.warning(f"Story mismatch in v2 migration. Existing file had story id {v2j['story_id']} but we have {self.story_id}")
|
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", encoding="utf-8") as file:
|
||||||
file.write(self.to_json())
|
file.write(self.to_json())
|
||||||
self.gamesaved = True
|
self.gamesaved = True
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user