core: use std::string for hashfile_name

One more free() removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-06-11 17:06:27 +02:00 committed by bstoeger
parent ec92cff92c
commit 5805b14734
3 changed files with 6 additions and 13 deletions

View file

@ -1011,9 +1011,9 @@ std::string get_current_date()
static QMutex hashOfMutex; static QMutex hashOfMutex;
static QHash<QString, QString> localFilenameOf; static QHash<QString, QString> localFilenameOf;
static const QString hashfile_name() std::string hashfile_name()
{ {
return QString(system_default_directory()).append("/hashes"); return std::string(system_default_directory()) + "/hashes";
} }
static QString thumbnailDir() static QString thumbnailDir()
@ -1031,11 +1031,6 @@ QString thumbnailFileName(const QString &filename)
return thumbnailDir() + hash.result().toHex(); return thumbnailDir() + hash.result().toHex();
} }
char *hashfile_name_string()
{
return copy_qstring(hashfile_name());
}
// TODO: This is a temporary helper struct. Remove in due course with convertLocalFilename(). // TODO: This is a temporary helper struct. Remove in due course with convertLocalFilename().
struct HashToFile { struct HashToFile {
QByteArray hash; QByteArray hash;
@ -1078,7 +1073,7 @@ static void convertLocalFilename(const QHash<QString, QByteArray> &hashOf, const
void read_hashes() void read_hashes()
{ {
QFile hashfile(hashfile_name()); QFile hashfile(QString::fromStdString(hashfile_name()));
if (hashfile.open(QIODevice::ReadOnly)) { if (hashfile.open(QIODevice::ReadOnly)) {
QDataStream stream(&hashfile); QDataStream stream(&hashfile);
QHash<QByteArray, QString> localFilenameByHash; QHash<QByteArray, QString> localFilenameByHash;
@ -1102,7 +1097,7 @@ void read_hashes()
void write_hashes() void write_hashes()
{ {
QSaveFile hashfile(hashfile_name()); QSaveFile hashfile(QString::fromStdString(hashfile_name()));
QMutexLocker locker(&hashOfMutex); QMutexLocker locker(&hashOfMutex);
if (hashfile.open(QIODevice::WriteOnly)) { if (hashfile.open(QIODevice::WriteOnly)) {

View file

@ -111,7 +111,7 @@ bool canReachCloudServer(struct git_info *);
void updateWindowTitle(); void updateWindowTitle();
void subsurface_mkdir(const char *dir); void subsurface_mkdir(const char *dir);
std::string local_file_path(const struct picture &picture); std::string local_file_path(const struct picture &picture);
char *hashfile_name_string(); std::string hashfile_name();
enum deco_mode decoMode(bool in_planner); enum deco_mode decoMode(bool in_planner);
void parse_seabear_header(const char *filename, struct xml_params *params); void parse_seabear_header(const char *filename, struct xml_params *params);
time_t get_dive_datetime_from_isostring(char *when); time_t get_dive_datetime_from_isostring(char *when);

View file

@ -63,9 +63,7 @@ void print_files()
printf("Unable to get local git directory\n"); printf("Unable to get local git directory\n");
} }
printf("Cloud URL: %s\n", filename->c_str()); printf("Cloud URL: %s\n", filename->c_str());
char *tmp = hashfile_name_string(); printf("Image filename table: %s\n", hashfile_name().c_str());
printf("Image filename table: %s\n", tmp);
free(tmp);
} }
static void print_help() static void print_help()