From 03751c5ff9db4a764256d831f3ca5a7b38d62248 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Wed, 27 May 2020 20:31:09 +0200 Subject: [PATCH] No more document .bak files, .nwd~ works just fine. --- nw/core/document.py | 14 +++++++------ sample/data_b/8136a5a774a0_main.nwd | 2 +- sample/data_e/dca4be2fcaf8_main.nwd | 2 +- sample/nwProject.nwx | 32 ++++++++++++++--------------- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/nw/core/document.py b/nw/core/document.py index 4c502bea..4cfd09a3 100644 --- a/nw/core/document.py +++ b/nw/core/document.py @@ -147,12 +147,10 @@ class NWDoc(): mkdir(dataPath) logger.debug("Created folder %s" % dataPath) - docTemp = path.join(dataPath, docFile+"~") - docBack = path.join(dataPath, docFile[:-3]+"bak") - itemPath = self.theProject.projTree.getItemPath(self.docHandle) docMeta = "%%~ "+":".join(itemPath)+":"+self.theItem.itemName+"\n" + docTemp = path.join(dataPath, docFile+"~") try: with open(docTemp,mode="w",encoding="utf8") as outFile: outFile.write(docMeta) @@ -161,12 +159,16 @@ class NWDoc(): self.makeAlert(["Could not save document.",str(e)], nwAlert.ERROR) return False - # If we're here, the file was successfully saved, - # so let's sort out the temps and backups + # Remove bak files from old file save method, if one exists + # This part can eventually be removed + docBack = path.join(dataPath, docFile[:-3]+"bak") if path.isfile(docBack): unlink(docBack) + + # If we're here, the file was successfully saved, so we can + # replace the temp file with the actual file if path.isfile(docPath): - rename(docPath, docBack) + unlink(docPath) rename(docTemp, docPath) self.theParent.statusBar.setStatus("Saved Document: %s" % self.theItem.itemName) diff --git a/sample/data_b/8136a5a774a0_main.nwd b/sample/data_b/8136a5a774a0_main.nwd index 4e63373d..a304cb35 100644 --- a/sample/data_b/8136a5a774a0_main.nwd +++ b/sample/data_b/8136a5a774a0_main.nwd @@ -1,4 +1,4 @@ -%%~ b8136a5a774a0:98acd8c76c93a:Delete Me! +%%~ b8136a5a774a0:7031beac91f75:Delete Me! ### Delete Me! This scene is trash. \ No newline at end of file diff --git a/sample/data_e/dca4be2fcaf8_main.nwd b/sample/data_e/dca4be2fcaf8_main.nwd index 679e4e27..5fef1f34 100644 --- a/sample/data_e/dca4be2fcaf8_main.nwd +++ b/sample/data_e/dca4be2fcaf8_main.nwd @@ -1,4 +1,4 @@ -%%~ edca4be2fcaf8:7031beac91f75:Part 1 +%%~ edca4be2fcaf8:7031beac91f75:Part One # Part One The first part. \ No newline at end of file diff --git a/sample/nwProject.nwx b/sample/nwProject.nwx index ad832035..e114568a 100644 --- a/sample/nwProject.nwx +++ b/sample/nwProject.nwx @@ -1,5 +1,5 @@ - + Sample Project Sample Project @@ -12,7 +12,7 @@ True 636b6aa9b697b ba8a28a246524 - 914 + 920 B E @@ -73,7 +73,7 @@ False True PAGE - 208 + 210 40 2 213 @@ -89,7 +89,7 @@ 23 5 1 - 0 + 27 A Folder @@ -122,7 +122,7 @@ 1199 216 7 - 527 + 825 Another Scene @@ -135,7 +135,7 @@ 476 93 3 - 551 + 428 Interlude @@ -148,7 +148,7 @@ 633 101 3 - 1238 + 752 A Note on Structure @@ -161,7 +161,7 @@ 1692 313 6 - 1721 + 551 Chapter Two @@ -174,7 +174,7 @@ 139 28 1 - 343 + 242 We Found John! @@ -214,7 +214,7 @@ 49 9 1 - 24 + 65 Jane Smith @@ -227,7 +227,7 @@ 55 9 1 - 25 + 71 Locations @@ -247,7 +247,7 @@ 76 15 1 - 20 + 93 Space @@ -260,7 +260,7 @@ 115 24 1 - 133 + 135 Mars @@ -290,9 +290,9 @@ False True SCENE - 0 - 0 - 0 + 30 + 6 + 1 36