Skip to content

Commit

Permalink
AutoSaveFinder cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tedfelix committed Jul 31, 2024
1 parent 60afb34 commit ed8c5bb
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/gui/general/AutoSaveFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@
COPYING included with this distribution for more information.
*/

#define RG_MODULE_STRING "[AutoSaveFinder]"
#define RG_NO_DEBUG_PRINT

#include "AutoSaveFinder.h"

#include "ResourceFinder.h"
#include "misc/Debug.h"

#include <iostream>
#include <QCryptographicHash>
Expand All @@ -35,22 +40,23 @@ AutoSaveFinder::getAutoSaveDir()
QString
AutoSaveFinder::getAutoSavePath(QString filename)
{
QString dir = getAutoSaveDir();
if (dir == "") {
//RG_DEBUG << "getAutoSavePath(): " << filename;

const QString autoSaveDir = getAutoSaveDir();
if (autoSaveDir == "") {
std::cerr << "WARNING: AutoSaveFinder::getAutoSavePath: No auto-save location located!?" << std::endl;
return "";
}

// This is just a simple (in terms of code present here, and
// trustworthiness) way of ensuring there are no unwanted
// characters in the filename -- although there may be advantages
// to the filename being readable, so we might want to consider
// something more like the old way
QString hashed = QString::fromLocal8Bit
(QCryptographicHash::hash(filename.toLocal8Bit(),
QCryptographicHash::Sha1).toHex());
// Use a hash to make sure the filename has no slashes.
// The incoming filename has the complete path of the file. So we need
// to get rid of the slashes so we can save it here. This is important
// if you have multiple files with the same name in different directories.
const QString hashed = QString::fromLocal8Bit(
QCryptographicHash::hash(filename.toLocal8Bit(),
QCryptographicHash::Sha1).toHex());

return dir + "/" + hashed;
return autoSaveDir + "/" + hashed;
}

QString
Expand Down

0 comments on commit ed8c5bb

Please sign in to comment.