mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-17 19:34:13 +02:00
e8201abb8a
Saving replaced the project file with nothing kept of what it was: one
bad save -- a fault in QElectroTech, a full disk, a wrong edit saved by
mistake -- and the last good version was gone. AutoCAD keeps a .bak on
every save, KiCad several backups.
Before a project is saved over, the file as it was is now copied to a
folder beside it, "<name>-backups", named by the time that version was
saved ("industrial 2026-10-16 08-30-12.qetz"); only the newest are kept,
5 by default (Settings > General > Projects, 0 for none). A copy is
never a move, so a save that fails leaves the file in place; a copy that
fails only warns, the save goes on. The same bytes as the newest version
kept are not kept twice.
The prompt on opening ("Create a backup copy?"), which writes one dated
copy beside the project and never removes any, is left as it is.
New tst_previousversions (newest kept, same bytes once, same second,
nothing for a new file or a count of 0, a failed copy said); it fails
with the oldest never removed. Checked with the program: two scripted
saves of a .qetz leave the original and the first save in
industrial-backups, the project holds the second. ctest 107/107.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
50 lines
2.0 KiB
C++
50 lines
2.0 KiB
C++
/*
|
|
Copyright 2006-2026 The QElectroTech Team
|
|
This file is part of QElectroTech.
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#ifndef PREVIOUSVERSIONS_H
|
|
#define PREVIOUSVERSIONS_H
|
|
|
|
#include <QString>
|
|
#include <QStringList>
|
|
|
|
/**
|
|
@brief The PreviousVersions namespace
|
|
The versions of a project file kept before it is saved over, as KiCad
|
|
and AutoCAD keep theirs: a copy of the file as it was goes in a folder
|
|
beside it, "<name>-backups", named by the time that version was saved
|
|
("industrial 2026-10-16 08-30-12.qetz"), and only the newest are kept.
|
|
The file is copied, never moved: a save that fails leaves it in place.
|
|
*/
|
|
namespace PreviousVersions
|
|
{
|
|
/// How many versions to keep (Settings > General > Projects); 0 keeps none
|
|
int count();
|
|
void setCount(int count);
|
|
/// The folder the versions of @p file_path go in
|
|
QString folder(const QString &file_path);
|
|
/// The versions kept of @p file_path, newest first
|
|
QStringList kept(const QString &file_path);
|
|
/// Copy @p file_path, about to be saved over, among its versions and
|
|
/// keep only the @p count newest. Nothing is copied when the file does
|
|
/// not exist, when @p count is 0, or when the newest version kept
|
|
/// holds the same bytes. @return false, with @p error, when the copy
|
|
/// could not be made: the save goes on all the same.
|
|
bool keep(const QString &file_path, int count, QString *error = nullptr);
|
|
}
|
|
|
|
#endif // PREVIOUSVERSIONS_H
|