[app] Delete orphaned marks files too
This commit is contained in:
parent
79753923cc
commit
34075dd73d
3 changed files with 33 additions and 19 deletions
|
@ -34,6 +34,7 @@
|
||||||
#include "BooksBookModel.h"
|
#include "BooksBookModel.h"
|
||||||
#include "BooksTextStyle.h"
|
#include "BooksTextStyle.h"
|
||||||
#include "BooksUtil.h"
|
#include "BooksUtil.h"
|
||||||
|
#include "BooksDefs.h"
|
||||||
|
|
||||||
#include "HarbourDebug.h"
|
#include "HarbourDebug.h"
|
||||||
#include "HarbourTask.h"
|
#include "HarbourTask.h"
|
||||||
|
@ -130,7 +131,7 @@ BooksBookModel::PagingTask::~PagingTask()
|
||||||
|
|
||||||
QString BooksBookModel::PagingTask::pageMarksFile(BooksBookModel* aModel)
|
QString BooksBookModel::PagingTask::pageMarksFile(BooksBookModel* aModel)
|
||||||
{
|
{
|
||||||
return aModel->book()->storageFile(QString(".%1x%2.marks").
|
return aModel->book()->storageFile(QString(".%1x%2" BOOKS_MARKS_FILE_SUFFIX).
|
||||||
arg(aModel->width()).arg(aModel->height()));
|
arg(aModel->width()).arg(aModel->height()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2015-2020 Jolla Ltd.
|
* Copyright (C) 2015-2021 Jolla Ltd.
|
||||||
* Copyright (C) 2015-2020 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2015-2021 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of the BSD license as follows:
|
* You may use this file under the terms of the BSD license as follows:
|
||||||
*
|
*
|
||||||
|
@ -66,6 +66,7 @@
|
||||||
BOOKS_QML_PLUGIN_V2, name, klass::createSingleton)
|
BOOKS_QML_PLUGIN_V2, name, klass::createSingleton)
|
||||||
|
|
||||||
#define BOOKS_STATE_FILE_SUFFIX ".state"
|
#define BOOKS_STATE_FILE_SUFFIX ".state"
|
||||||
|
#define BOOKS_MARKS_FILE_SUFFIX ".marks"
|
||||||
|
|
||||||
extern int booksPPI;
|
extern int booksPPI;
|
||||||
#define BOOKS_PPI booksPPI
|
#define BOOKS_PPI booksPPI
|
||||||
|
|
|
@ -100,7 +100,7 @@ public:
|
||||||
|
|
||||||
void performTask();
|
void performTask();
|
||||||
|
|
||||||
int findBook(QString aFileName) const;
|
int findBook(const QStringRef* aFileName) const;
|
||||||
static int find(QFileInfoList aList, QString aFileName, int aStart);
|
static int find(QFileInfoList aList, QString aFileName, int aStart);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -129,17 +129,16 @@ int BooksShelf::LoadTask::find(QFileInfoList aList, QString aName, int aStart)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BooksShelf::LoadTask::findBook(QString aFileName) const
|
int BooksShelf::LoadTask::findBook(const QStringRef* aFileName) const
|
||||||
{
|
{
|
||||||
if (!aFileName.isEmpty()) {
|
// Caller makes sure that aFileName is not empty
|
||||||
const int n = iItems.count();
|
const int n = iItems.count();
|
||||||
for (int i=0; i<n; i++) {
|
for (int i=0; i<n; i++) {
|
||||||
BooksItem* item = iItems.at(i);
|
BooksItem* item = iItems.at(i);
|
||||||
if (item->book() && item->fileName() == aFileName) {
|
if (item->book() && aFileName->compare(item->fileName()) == 0) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,19 +201,32 @@ void BooksShelf::LoadTask::performTask()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup the state files
|
// Delete orphaned state and marks files
|
||||||
if (!isCanceled()) {
|
if (!isCanceled()) {
|
||||||
|
static const QString stateSuffix(BOOKS_STATE_FILE_SUFFIX);
|
||||||
|
static const QString marksSuffix(BOOKS_MARKS_FILE_SUFFIX);
|
||||||
QStringList deleteMe;
|
QStringList deleteMe;
|
||||||
const QString suffix(BOOKS_STATE_FILE_SUFFIX);
|
|
||||||
QDirIterator configIt(iStorage.fullConfigPath(iRelativePath));
|
QDirIterator configIt(iStorage.fullConfigPath(iRelativePath));
|
||||||
while (configIt.hasNext() && !isCanceled()) {
|
while (configIt.hasNext() && !isCanceled()) {
|
||||||
QString path(configIt.next());
|
const QString path(configIt.next());
|
||||||
if (path.endsWith(suffix)) {
|
if (path.endsWith(stateSuffix)) {
|
||||||
QString fileName(configIt.fileName());
|
const QString fileName(configIt.fileName());
|
||||||
QString name(fileName.left(fileName.length() - suffix.length()));
|
// State file is named <BOOK>.state
|
||||||
if (!name.isEmpty() && findBook(name) < 0) {
|
QStringRef name(fileName.leftRef(fileName.length() - stateSuffix.length()));
|
||||||
|
if (!name.isEmpty() && findBook(&name) < 0) {
|
||||||
deleteMe.append(path);
|
deleteMe.append(path);
|
||||||
}
|
}
|
||||||
|
} else if (path.endsWith(marksSuffix)) {
|
||||||
|
const QString fileName(configIt.fileName());
|
||||||
|
// Marks file is named <BOOK>.<width>x<height>.marks
|
||||||
|
QStringRef name(fileName.leftRef(fileName.length() - stateSuffix.length()));
|
||||||
|
const int nextSeparator = name.lastIndexOf('.');
|
||||||
|
if (nextSeparator > 0) {
|
||||||
|
name = name.left(nextSeparator);
|
||||||
|
if (findBook(&name) < 0) {
|
||||||
|
deleteMe.append(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (!deleteMe.isEmpty() && !isCanceled()) {
|
while (!deleteMe.isEmpty() && !isCanceled()) {
|
||||||
|
|
Loading…
Reference in a new issue