mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-19 20:32:28 +12:00
Fix crash on open with locked files (fixex olivierkes#950)
This commit is contained in:
parent
f63acafe4e
commit
5a6d68e139
|
@ -429,13 +429,14 @@ def saveProject(zip=None):
|
||||||
LOGGER.error("Cannot open file " + project + " for writing: " + e.strerror)
|
LOGGER.error("Cannot open file " + project + " for writing: " + e.strerror)
|
||||||
filesWithPermissionErrors.append(project)
|
filesWithPermissionErrors.append(project)
|
||||||
|
|
||||||
dlg = ListDialog()
|
if len(filesWithPermissionErrors) > 0:
|
||||||
dlg.setModal(True)
|
dlg = ListDialog()
|
||||||
dlg.setWindowTitle(dlg.tr("Files not saved"))
|
dlg.setModal(True)
|
||||||
dlg.label.setText(dlg.tr("The following files were not saved and appear to be open in another program"))
|
dlg.setWindowTitle(dlg.tr("Files not saved"))
|
||||||
for f in filesWithPermissionErrors:
|
dlg.label.setText(dlg.tr("The following files were not saved and appear to be open in another program"))
|
||||||
QListWidgetItem(f, dlg.listWidget)
|
for f in filesWithPermissionErrors:
|
||||||
dlg.exec()
|
QListWidgetItem(f, dlg.listWidget)
|
||||||
|
dlg.exec()
|
||||||
|
|
||||||
if project in filesWithPermissionErrors:
|
if project in filesWithPermissionErrors:
|
||||||
return False
|
return False
|
||||||
|
@ -646,7 +647,8 @@ def loadProject(project, zip=None):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
mw = mainWindow()
|
mw = mainWindow()
|
||||||
errors = []
|
errors = list()
|
||||||
|
filesWithPermissionErrors = list()
|
||||||
|
|
||||||
####################################################################################################################
|
####################################################################################################################
|
||||||
# Read and store everything in a dict
|
# Read and store everything in a dict
|
||||||
|
@ -685,8 +687,14 @@ def loadProject(project, zip=None):
|
||||||
with open(os.path.join(dirpath, f), "rb") as fo:
|
with open(os.path.join(dirpath, f), "rb") as fo:
|
||||||
files[os.path.join(p, f)] = fo.read()
|
files[os.path.join(p, f)] = fo.read()
|
||||||
else:
|
else:
|
||||||
with open(os.path.join(dirpath, f), "r", encoding="utf8") as fo:
|
try:
|
||||||
files[os.path.join(p, f)] = fo.read()
|
filename = os.path.join(dirpath, f)
|
||||||
|
with open(filename, "r", encoding="utf8") as fo:
|
||||||
|
files[os.path.join(p, f)] = fo.read()
|
||||||
|
except PermissionError as e:
|
||||||
|
LOGGER.error("Cannot open file " + filename + ": " + e.strerror)
|
||||||
|
errors.append(fo)
|
||||||
|
filesWithPermissionErrors.append(filename)
|
||||||
|
|
||||||
# Saves to cache (only if we loaded from disk and not zip)
|
# Saves to cache (only if we loaded from disk and not zip)
|
||||||
global cache
|
global cache
|
||||||
|
@ -911,6 +919,15 @@ def loadProject(project, zip=None):
|
||||||
# Check IDS
|
# Check IDS
|
||||||
mdl.rootItem.checkIDs()
|
mdl.rootItem.checkIDs()
|
||||||
|
|
||||||
|
if len(filesWithPermissionErrors) > 0:
|
||||||
|
dlg = ListDialog()
|
||||||
|
dlg.setModal(True)
|
||||||
|
dlg.setWindowTitle(dlg.tr("Files not loaded"))
|
||||||
|
dlg.label.setText(dlg.tr("The following files were not loaded and appear to be open in another program"))
|
||||||
|
for f in filesWithPermissionErrors:
|
||||||
|
QListWidgetItem(f, dlg.listWidget)
|
||||||
|
dlg.exec()
|
||||||
|
|
||||||
return errors
|
return errors
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue