Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a check that a non-new project actually exists #1301

Merged
merged 2 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 38 additions & 33 deletions i18n/nw_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3777,163 +3777,168 @@
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="288" />
<location filename="../novelwriter/core/project.py" line="254" />
<source>Could not open project with path: {0}</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="291" />
<source>Unknown</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="292" />
<location filename="../novelwriter/core/project.py" line="295" />
<source>Project file does not appear to be a novelWriterXML file.</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="296" />
<location filename="../novelwriter/core/project.py" line="299" />
<source>Unknown or unsupported novelWriter project file format. The project cannot be opened by this version of novelWriter. The file was saved with novelWriter version {0}.</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="302" />
<location filename="../novelwriter/core/project.py" line="305" />
<source>Failed to parse project xml.</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="314" />
<location filename="../novelwriter/core/project.py" line="317" />
<source>File Version</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="315" />
<location filename="../novelwriter/core/project.py" line="318" />
<source>The file format of your project is about to be updated. If you proceed, older versions of novelWriter will no longer be able to open this project. Continue?</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="330" />
<location filename="../novelwriter/core/project.py" line="333" />
<source>Version Conflict</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="331" />
<location filename="../novelwriter/core/project.py" line="334" />
<source>This project was saved by a newer version of novelWriter, version {0}. This is version {1}. If you continue to open the project, some attributes and settings may not be preserved, but the overall project should be fine. Continue opening the project?</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="375" />
<location filename="../novelwriter/core/project.py" line="378" />
<source>Opened Project: {0}</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="386" />
<location filename="../novelwriter/core/project.py" line="389" />
<source>There is no project open.</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="411" />
<location filename="../novelwriter/core/project.py" line="414" />
<source>Failed to save project.</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="427" />
<location filename="../novelwriter/core/project.py" line="430" />
<source>Saved Project: {0}</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="453" />
<location filename="../novelwriter/core/project.py" line="456" />
<source>Backing up project ...</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="457" />
<location filename="../novelwriter/core/project.py" line="460" />
<source>Cannot backup project because no valid backup path is set. Please set a valid backup location in Preferences.</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="464" />
<location filename="../novelwriter/core/project.py" line="467" />
<source>Cannot backup project because no project name is set. Please set a Project Name in Project Settings.</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="475" />
<location filename="../novelwriter/core/project.py" line="478" />
<source>Could not create backup folder.</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="480" />
<location filename="../novelwriter/core/project.py" line="483" />
<source>Backup from {0}</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="485" />
<location filename="../novelwriter/core/project.py" line="488" />
<source>Backup archive file written to: {0}</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="489" />
<location filename="../novelwriter/core/project.py" line="492" />
<source>Could not write backup archive.</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="494" />
<location filename="../novelwriter/core/project.py" line="497" />
<source>Project backed up to '{0}'</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="511" />
<location filename="../novelwriter/core/project.py" line="507" />
<location filename="../novelwriter/core/project.py" line="514" />
<location filename="../novelwriter/core/project.py" line="510" />
<source>New</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="508" />
<location filename="../novelwriter/core/project.py" line="511" />
<source>Note</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="509" />
<location filename="../novelwriter/core/project.py" line="512" />
<source>Draft</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="510" />
<location filename="../novelwriter/core/project.py" line="513" />
<source>Finished</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="512" />
<location filename="../novelwriter/core/project.py" line="515" />
<source>Minor</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="513" />
<location filename="../novelwriter/core/project.py" line="516" />
<source>Major</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="514" />
<location filename="../novelwriter/core/project.py" line="517" />
<source>Main</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="735" />
<location filename="../novelwriter/core/project.py" line="738" />
<source>Found {0} orphaned file(s) in project folder.</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="745" />
<location filename="../novelwriter/core/project.py" line="748" />
<source>Recovered</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="759" />
<location filename="../novelwriter/core/project.py" line="762" />
<source>[{0}] {1}</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="764" />
<location filename="../novelwriter/core/project.py" line="767" />
<source>Recovered File {0}</source>
<translation type="unfinished" />
</message>
<message>
<location filename="../novelwriter/core/project.py" line="792" />
<location filename="../novelwriter/core/project.py" line="795" />
<source>One or more orphaned files could not be added back into the project. Make sure at least a Novel root folder exists.</source>
<translation type="unfinished" />
</message>
Expand Down
3 changes: 3 additions & 0 deletions novelwriter/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ def openProject(self, projPath, overrideLock=False):
"""
self.clearProject()
if not self._storage.openProjectInPlace(projPath):
self.mainGui.makeAlert(self.tr(
"Could not open project with path: {0}"
).format(projPath), nwAlert.ERROR)
return False

logger.info("Opening project: %s", projPath)
Expand Down
8 changes: 7 additions & 1 deletion novelwriter/core/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ def openProjectInPlace(self, path, newProject=False):
# but it can point to a folder containing files
inPath = inPath.parent

if not (inPath.is_dir() or newProject):
# If the project is not new, the folder must already exist.
return False

self._storagePath = inPath
self._runtimePath = inPath
self._lockFilePath = inPath / nwFiles.PROJ_LOCK
Expand All @@ -114,7 +118,9 @@ def openProjectInPlace(self, path, newProject=False):
return True

def openProjectArchive(self, path): # pragma: no cover
pass
"""Placeholder for later implementation. See #977.
"""
return False

def runPostSaveTasks(self, autoSave=False): # pragma: no cover
"""Run tasks after the project has been saved.
Expand Down
5 changes: 4 additions & 1 deletion tests/test_core/test_core_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,15 @@ def testCoreStorage_OpenProjectInPlace(mockGUI, fncPath, mockRnd):
# Open project as a new project should fail
assert storage.openProjectInPlace(fncPath, newProject=True) is False

# Opening as a no-new project is fine
# Opening as a non-new project is fine
assert storage.openProjectInPlace(fncPath, newProject=False) is True

# Opening the project file is also fine
assert storage.openProjectInPlace(fncPath / nwFiles.PROJ_FILE, newProject=False) is True

# Opening as a non-new project on a non-existing folder should fail
assert storage.openProjectInPlace(fncPath / "foobar", newProject=False) is False

# Check settings
assert storage.storagePath == fncPath
assert storage.runtimePath == fncPath
Expand Down