Make autosave create a temporary backup of the current autosave file before saving so that an error while saving is less likely to cause data loss.
Originally committed to SVN as r3353.
This commit is contained in:
parent
5ccf95b9df
commit
cca0de98cb
1 changed files with 24 additions and 10 deletions
|
@ -1726,8 +1726,8 @@ void FrameMain::OnOpenStylingAssistant (wxCommandEvent &event) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// @brief Auto backup
|
/// @brief Autosave the currently open file, if any
|
||||||
/// @param event
|
/// @param event Unused
|
||||||
///
|
///
|
||||||
void FrameMain::OnAutoSave(wxTimerEvent &event) {
|
void FrameMain::OnAutoSave(wxTimerEvent &event) {
|
||||||
// Auto Save
|
// Auto Save
|
||||||
|
@ -1739,19 +1739,33 @@ void FrameMain::OnAutoSave(wxTimerEvent &event) {
|
||||||
if (path.IsEmpty()) path = origfile.GetPath();
|
if (path.IsEmpty()) path = origfile.GetPath();
|
||||||
wxFileName dstpath(path);
|
wxFileName dstpath(path);
|
||||||
if (!dstpath.IsAbsolute()) path = StandardPaths::DecodePathMaybeRelative(path, _T("?user/"));
|
if (!dstpath.IsAbsolute()) path = StandardPaths::DecodePathMaybeRelative(path, _T("?user/"));
|
||||||
path += _T("/");
|
dstpath.AssignDir(path);
|
||||||
dstpath.Assign(path);
|
|
||||||
if (!dstpath.DirExists()) wxMkdir(path);
|
if (!dstpath.DirExists()) wxMkdir(path);
|
||||||
|
|
||||||
// Save
|
|
||||||
wxString name = origfile.GetName();
|
wxString name = origfile.GetName();
|
||||||
wxString backup = path;
|
if (name.IsEmpty()) {
|
||||||
if (name.IsEmpty()) backup += _T("Untitled.AUTOSAVE.ass");
|
dstpath.SetFullName("Untitled.AUTOSAVE.ass");
|
||||||
else backup += origfile.GetName() + _T(".AUTOSAVE.ass");
|
}
|
||||||
AssFile::top->Save(backup,false,false);
|
else {
|
||||||
|
dstpath.SetFullName(name + L".AUTOSAVE.ass");
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the autosave file already exists, make a temporary copy of it in case the autosave fails
|
||||||
|
wxFileName backup;
|
||||||
|
if (dstpath.FileExists()) {
|
||||||
|
backup = dstpath;
|
||||||
|
backup.SetName(backup.GetName() + ".backup");
|
||||||
|
wxRenameFile(dstpath.GetFullPath(), backup.GetFullPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
AssFile::top->Save(dstpath.GetFullPath(),false,false);
|
||||||
|
|
||||||
|
if (backup.FileExists()) {
|
||||||
|
wxRemoveFile(backup.GetFullPath());
|
||||||
|
}
|
||||||
|
|
||||||
// Set status bar
|
// Set status bar
|
||||||
StatusTimeout(_("File backup saved as \"") + backup + _T("\"."));
|
StatusTimeout(_("File backup saved as \"") + dstpath.GetFullPath() + _T("\"."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (wxString err) {
|
catch (wxString err) {
|
||||||
|
|
Loading…
Reference in a new issue