MassManager: use Logger.
This commit is contained in:
parent
44656b32d5
commit
9de62db449
1 changed files with 28 additions and 9 deletions
|
@ -19,16 +19,20 @@
|
||||||
#include <Corrade/Utility/Format.h>
|
#include <Corrade/Utility/Format.h>
|
||||||
#include <Corrade/Utility/Path.h>
|
#include <Corrade/Utility/Path.h>
|
||||||
|
|
||||||
|
#include "../Logger/Logger.h"
|
||||||
|
|
||||||
#include "MassManager.h"
|
#include "MassManager.h"
|
||||||
|
|
||||||
using namespace Containers::Literals;
|
using namespace Containers::Literals;
|
||||||
|
|
||||||
MassManager::MassManager(Containers::StringView save_path, Containers::StringView account, bool demo, Containers::StringView staging_dir):
|
MassManager::MassManager(Containers::StringView save_path, Containers::StringView account, bool demo,
|
||||||
|
Containers::StringView staging_dir):
|
||||||
_saveDirectory{save_path}, _account{account}, _demo{demo}, _stagingAreaDirectory{staging_dir}
|
_saveDirectory{save_path}, _account{account}, _demo{demo}, _stagingAreaDirectory{staging_dir}
|
||||||
{
|
{
|
||||||
Containers::String mass_filename = "";
|
Containers::String mass_filename = "";
|
||||||
for(UnsignedInt i = 0; i < _hangars.size(); i++) {
|
for(UnsignedInt i = 0; i < _hangars.size(); i++) {
|
||||||
mass_filename = Utility::Path::join(_saveDirectory, Utility::format("{}Unit{:.2d}{}.sav", demo ? "Demo"_s : ""_s, i, _account));
|
mass_filename = Utility::Path::join(_saveDirectory,
|
||||||
|
Utility::format("{}Unit{:.2d}{}.sav", demo ? "Demo"_s : ""_s, i, _account));
|
||||||
new(&_hangars[i]) Mass{mass_filename};
|
new(&_hangars[i]) Mass{mass_filename};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,6 +49,8 @@ auto MassManager::hangar(Int hangar) -> Mass& {
|
||||||
|
|
||||||
void MassManager::refreshHangar(Int hangar) {
|
void MassManager::refreshHangar(Int hangar) {
|
||||||
if(hangar < 0 || hangar >= 32) {
|
if(hangar < 0 || hangar >= 32) {
|
||||||
|
_lastError = "Hangar index out of range.";
|
||||||
|
LOG_ERROR(_lastError);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +62,8 @@ void MassManager::refreshHangar(Int hangar) {
|
||||||
|
|
||||||
auto MassManager::importMass(Containers::StringView staged_fn, Int hangar) -> bool {
|
auto MassManager::importMass(Containers::StringView staged_fn, Int hangar) -> bool {
|
||||||
if(hangar < 0 || hangar >= 32) {
|
if(hangar < 0 || hangar >= 32) {
|
||||||
_lastError = "Hangar out of range in MassManager::importMass()"_s;
|
_lastError = "Hangar index out of range.";
|
||||||
|
LOG_ERROR(_lastError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,6 +71,7 @@ auto MassManager::importMass(Containers::StringView staged_fn, Int hangar) -> bo
|
||||||
|
|
||||||
if(it == _stagedMasses.end()) {
|
if(it == _stagedMasses.end()) {
|
||||||
_lastError = "Couldn't find "_s + staged_fn + " in the staged M.A.S.S.es."_s;
|
_lastError = "Couldn't find "_s + staged_fn + " in the staged M.A.S.S.es."_s;
|
||||||
|
LOG_ERROR(_lastError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,6 +95,7 @@ auto MassManager::importMass(Containers::StringView staged_fn, Int hangar) -> bo
|
||||||
|
|
||||||
if(!Utility::Path::move(source + ".tmp"_s, dest)) {
|
if(!Utility::Path::move(source + ".tmp"_s, dest)) {
|
||||||
_lastError = Utility::format("Couldn't move {} to hangar {:.2d}", staged_fn, hangar + 1);
|
_lastError = Utility::format("Couldn't move {} to hangar {:.2d}", staged_fn, hangar + 1);
|
||||||
|
LOG_ERROR(_lastError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,12 +104,14 @@ auto MassManager::importMass(Containers::StringView staged_fn, Int hangar) -> bo
|
||||||
|
|
||||||
auto MassManager::exportMass(Int hangar) -> bool {
|
auto MassManager::exportMass(Int hangar) -> bool {
|
||||||
if(hangar < 0 || hangar >= 32) {
|
if(hangar < 0 || hangar >= 32) {
|
||||||
_lastError = "Hangar out of range in MassManager::exportMass()"_s;
|
_lastError = "Hangar index out of range."_s;
|
||||||
|
LOG_ERROR(_lastError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_hangars[hangar].state() != Mass::State::Valid) {
|
if(_hangars[hangar].state() != Mass::State::Valid) {
|
||||||
_lastError = Utility::format("There is no valid data to export in hangar {:.2d}", hangar + 1);
|
_lastError = Utility::format("There is no valid data to export in hangar {:.2d}", hangar + 1);
|
||||||
|
LOG_ERROR(_lastError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,6 +121,7 @@ auto MassManager::exportMass(Int hangar) -> bool {
|
||||||
|
|
||||||
if(!Utility::Path::copy(source, dest)) {
|
if(!Utility::Path::copy(source, dest)) {
|
||||||
_lastError = Utility::format("Couldn't export data from hangar {:.2d} to {}", hangar, dest);
|
_lastError = Utility::format("Couldn't export data from hangar {:.2d} to {}", hangar, dest);
|
||||||
|
LOG_ERROR(_lastError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,12 +130,14 @@ auto MassManager::exportMass(Int hangar) -> bool {
|
||||||
|
|
||||||
auto MassManager::moveMass(Int source, Int destination) -> bool {
|
auto MassManager::moveMass(Int source, Int destination) -> bool {
|
||||||
if(source < 0 || source >= 32) {
|
if(source < 0 || source >= 32) {
|
||||||
_lastError = "Source hangar out of range."_s;
|
_lastError = "Source hangar index out of range."_s;
|
||||||
|
LOG_ERROR(_lastError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(destination < 0 || destination >= 32) {
|
if(destination < 0 || destination >= 32) {
|
||||||
_lastError = "Destination hangar out of range."_s;
|
_lastError = "Destination hangar index out of range."_s;
|
||||||
|
LOG_ERROR(_lastError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,12 +167,14 @@ auto MassManager::moveMass(Int source, Int destination) -> bool {
|
||||||
|
|
||||||
auto MassManager::deleteMass(Int hangar) -> bool {
|
auto MassManager::deleteMass(Int hangar) -> bool {
|
||||||
if(hangar < 0 || hangar >= 32) {
|
if(hangar < 0 || hangar >= 32) {
|
||||||
_lastError = "Hangar out of range."_s;
|
_lastError = "Hangar index out of range."_s;
|
||||||
|
LOG_ERROR(_lastError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Utility::Path::remove(Utility::Path::join(_saveDirectory, _hangars[hangar].filename()))) {
|
if(!Utility::Path::remove(Utility::Path::join(_saveDirectory, _hangars[hangar].filename()))) {
|
||||||
_lastError = Utility::format("Deletion failed: {}", std::strerror(errno));
|
_lastError = Utility::format("Deletion failed: {}", std::strerror(errno));
|
||||||
|
LOG_ERROR(_lastError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,10 +189,11 @@ void MassManager::refreshStagedMasses() {
|
||||||
_stagedMasses.clear();
|
_stagedMasses.clear();
|
||||||
|
|
||||||
using Utility::Path::ListFlag;
|
using Utility::Path::ListFlag;
|
||||||
auto file_list = Utility::Path::list(_stagingAreaDirectory, ListFlag::SkipSpecial|ListFlag::SkipDirectories|ListFlag::SkipDotAndDotDot);
|
auto file_list = Utility::Path::list(_stagingAreaDirectory,
|
||||||
|
ListFlag::SkipSpecial|ListFlag::SkipDirectories|ListFlag::SkipDotAndDotDot);
|
||||||
|
|
||||||
if(!file_list) {
|
if(!file_list) {
|
||||||
Utility::Error{} << _stagingAreaDirectory << "couldn't be opened";
|
LOG_ERROR_FORMAT("{} couldn't be opened.", _stagingAreaDirectory);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,11 +240,13 @@ void MassManager::refreshStagedMass(Containers::StringView filename) {
|
||||||
auto MassManager::deleteStagedMass(Containers::StringView filename) -> bool {
|
auto MassManager::deleteStagedMass(Containers::StringView filename) -> bool {
|
||||||
if(_stagedMasses.find(filename) == _stagedMasses.cend()) {
|
if(_stagedMasses.find(filename) == _stagedMasses.cend()) {
|
||||||
_lastError = "The file "_s + filename + " couldn't be found in the list of staged M.A.S.S.es."_s;
|
_lastError = "The file "_s + filename + " couldn't be found in the list of staged M.A.S.S.es."_s;
|
||||||
|
LOG_ERROR(_lastError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Utility::Path::remove(Utility::Path::join(_stagingAreaDirectory, filename))) {
|
if(!Utility::Path::remove(Utility::Path::join(_stagingAreaDirectory, filename))) {
|
||||||
_lastError = filename + " couldn't be deleted: " + std::strerror(errno);
|
_lastError = filename + " couldn't be deleted: " + std::strerror(errno);
|
||||||
|
LOG_ERROR(_lastError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue