mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-07-31 07:18:25 +02:00
Compare last saved date before saving to prevent overwrite
This commit is contained in:
parent
bc139d13e7
commit
e63c2df2a8
3 changed files with 56 additions and 1 deletions
|
@ -223,6 +223,7 @@ class Graph(BaseObject):
|
|||
self._compatibilityNodes = DictModel(keyAttrName='name', parent=self)
|
||||
self.cacheDir = meshroom.core.defaultCacheFolder
|
||||
self._filepath = ''
|
||||
self._fileDateVersion = 0
|
||||
self.header = {}
|
||||
|
||||
def clear(self):
|
||||
|
@ -268,6 +269,8 @@ class Graph(BaseObject):
|
|||
if not isinstance(graphData, dict):
|
||||
raise RuntimeError('loadGraph error: Graph is not a dict. File: {}'.format(filepath))
|
||||
|
||||
self._fileDateVersion = os.path.getmtime(filepath)
|
||||
|
||||
self.header = fileData.get(Graph.IO.Keys.Header, {})
|
||||
nodesVersions = self.header.get(Graph.IO.Keys.NodesVersions, {})
|
||||
|
||||
|
@ -1539,6 +1542,18 @@ class Graph(BaseObject):
|
|||
self.updateStatusFromCache(force=True)
|
||||
self.cacheDirChanged.emit()
|
||||
|
||||
@property
|
||||
def fileDateVersion(self):
|
||||
return self._fileDateVersion
|
||||
|
||||
@fileDateVersion.setter
|
||||
def fileDateVersion(self, value):
|
||||
self._fileDateVersion = value
|
||||
|
||||
@Slot(str, result=float)
|
||||
def getFileDateVersionFromPath(self, value):
|
||||
return os.path.getmtime(value)
|
||||
|
||||
def setVerbose(self, v):
|
||||
with GraphModification(self):
|
||||
for node in self._nodes:
|
||||
|
@ -1553,6 +1568,7 @@ class Graph(BaseObject):
|
|||
filepathChanged = Signal()
|
||||
filepath = Property(str, lambda self: self._filepath, notify=filepathChanged)
|
||||
fileReleaseVersion = Property(str, lambda self: self.header.get(Graph.IO.Keys.ReleaseVersion, "0.0"), notify=filepathChanged)
|
||||
fileDateVersion = Property(float, fileDateVersion.fget, fileDateVersion.fset, notify=filepathChanged)
|
||||
cacheDirChanged = Signal()
|
||||
cacheDir = Property(str, cacheDir.fget, cacheDir.fset, notify=cacheDirChanged)
|
||||
updated = Signal()
|
||||
|
|
|
@ -368,6 +368,36 @@ ApplicationWindow {
|
|||
onDiscarded: close()
|
||||
onAccepted: saveAsAction.trigger()
|
||||
}
|
||||
|
||||
MessageDialog {
|
||||
id: fileModifiedDialog
|
||||
|
||||
canCopy: false
|
||||
icon.text: MaterialIcons.warning
|
||||
parent: Overlay.overlay
|
||||
preset: "Warning"
|
||||
title: "File Modified"
|
||||
text: "The file has been modified by another instance."
|
||||
detailedText: "Do you want to overwrite the file?"
|
||||
|
||||
// Add a reload file button next to the save button
|
||||
footer: DialogButtonBox {
|
||||
position: DialogButtonBox.Footer
|
||||
standardButtons: Dialog.Save | Dialog.Cancel
|
||||
|
||||
Button {
|
||||
text: "Reload File"
|
||||
|
||||
onClicked: {
|
||||
_reconstruction.loadUrl(_reconstruction.graph.filepath)
|
||||
fileModifiedDialog.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onAccepted: _reconstruction.save()
|
||||
onDiscarded: close()
|
||||
}
|
||||
}
|
||||
|
||||
FileDialog {
|
||||
|
@ -715,7 +745,14 @@ ApplicationWindow {
|
|||
enabled: _reconstruction ? (_reconstruction.graph && !_reconstruction.graph.filepath) || !_reconstruction.undoStack.clean : false
|
||||
onTriggered: {
|
||||
if (_reconstruction.graph.filepath) {
|
||||
_reconstruction.save()
|
||||
// get current time date
|
||||
var date = _reconstruction.graph.getFileDateVersionFromPath(_reconstruction.graph.filepath)
|
||||
|
||||
// check if the file has been modified by another instance
|
||||
if (_reconstruction.graph.fileDateVersion !== date) {
|
||||
fileModifiedDialog.open()
|
||||
} else
|
||||
_reconstruction.save()
|
||||
} else {
|
||||
initFileDialogFolder(saveFileDialog)
|
||||
saveFileDialog.open()
|
||||
|
|
|
@ -509,6 +509,8 @@ class Reconstruction(UIGraph):
|
|||
"Data might have been lost in the process.",
|
||||
"Open it with the corresponding version of Meshroom to recover your data."
|
||||
))
|
||||
|
||||
self.graph.fileDateVersion = os.path.getmtime(filepath)
|
||||
return status
|
||||
except FileNotFoundError as e:
|
||||
self.error.emit(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue