Implemented snapshot deletion function

This commit is contained in:
Nav
2023-04-15 12:34:55 +01:00
parent c49a792c53
commit f1daa9066d
5 changed files with 157 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
#include "DeleteMemorySnapshot.hpp"
#include <QFile>
#include "src/Services/PathService.hpp"
#include "src/Helpers/EnumToStringMappings.hpp"
#include "src/Logger/Logger.hpp"
namespace Bloom
{
using Services::TargetControllerService;
DeleteMemorySnapshot::DeleteMemorySnapshot(
const QString& snapshotId,
Targets::TargetMemoryType memoryType
)
: snapshotId(snapshotId)
, memoryType(memoryType)
{}
void DeleteMemorySnapshot::run(TargetControllerService&) {
using Targets::TargetMemorySize;
Logger::info("Deleting snapshot " + this->snapshotId.toStdString());
const auto snapshotFilePath = QString::fromStdString(Services::PathService::projectSettingsDirPath())
+ "/memory_snapshots/" + EnumToStringMappings::targetMemoryTypes.at(this->memoryType) + "/"
+ this->snapshotId + ".json";
auto snapshotFile = QFile(snapshotFilePath);
if (!snapshotFile.exists()) {
Logger::warning(
"Could not find snapshot file for " + this->snapshotId.toStdString() + " - expected path: "
+ snapshotFilePath.toStdString()
);
return;
}
snapshotFile.remove();
}
}

View File

@@ -0,0 +1,29 @@
#pragma once
#include <QString>
#include "InsightWorkerTask.hpp"
#include "src/Targets/TargetMemory.hpp"
namespace Bloom
{
class DeleteMemorySnapshot: public InsightWorkerTask
{
Q_OBJECT
public:
DeleteMemorySnapshot(const QString& snapshotId, Targets::TargetMemoryType memoryType);
QString brief() const override {
return "Deleting memory snapshot " + this->snapshotId;
}
protected:
void run(Services::TargetControllerService& targetControllerService) override;
private:
QString snapshotId;
Targets::TargetMemoryType memoryType;
};
}