Compare commits

..

No commits in common. "de2ba9ce7ffb2e5fe32d88d86e3a7c8865ebbec9" and "a1c17b713829bcdfa7752b0e38b6b95b1d440168" have entirely different histories.

6 changed files with 39 additions and 37 deletions

View file

@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cstring>
#include <algorithm>
#include <Corrade/Containers/Array.h>
@ -912,18 +914,12 @@ auto Mass::updateAccount(const std::string& new_account) -> bool {
auto account = _mass->at<StringProperty>("Account");
if(!account) {
_state = State::Invalid;
_lastError = "Couldn't find the account property.";
return false;
}
account->value = new_account;
if(!_mass->saveToFile()) {
_lastError = _mass->lastError();
return false;
}
return true;
return _mass->saveToFile();
}
void Mass::getCustomStyles(Containers::ArrayView<CustomStyle> styles, ArrayProperty* style_array) {

View file

@ -49,11 +49,11 @@ auto MassManager::lastError() -> std::string const& {
return _lastError;
}
auto MassManager::hangar(Int hangar) -> Mass& {
auto MassManager::hangar(int hangar) -> Mass& {
return _hangars[hangar];
}
void MassManager::refreshHangar(Int hangar) {
void MassManager::refreshHangar(int hangar) {
if(hangar < 0 || hangar >= 32) {
return;
}
@ -63,7 +63,7 @@ void MassManager::refreshHangar(Int hangar) {
_hangars[hangar] = Mass{mass_filename};
}
auto MassManager::importMass(const std::string& staged_fn, Int hangar) -> bool {
auto MassManager::importMass(const std::string& staged_fn, int hangar) -> bool {
if(hangar < 0 || hangar >= 32) {
_lastError = "Hangar out of range in MassManager::importMass()";
return false;
@ -79,22 +79,18 @@ auto MassManager::importMass(const std::string& staged_fn, Int hangar) -> bool {
std::string source = Utility::Directory::join(_stagingAreaDirectory, staged_fn);
Utility::Directory::copy(source, source + ".tmp");
if(!Mass{source + ".tmp"}.updateAccount(_steamId))
{
Mass mass{source + ".tmp"};
if(!mass.updateAccount(_steamId)) {
_lastError = mass.lastError();
_lastError = "The M.A.S.S. file at " + source + " seems to be corrupt.";
Utility::Directory::rm(source + ".tmp");
return false;
}
if(Utility::Directory::exists(Utility::Directory::join(_saveDirectory, _hangars[hangar].filename()))) {
Utility::Directory::rm(Utility::Directory::join(_saveDirectory, _hangars[hangar].filename()));
}
std::string dest = Utility::Directory::join(_saveDirectory, _hangars[hangar].filename());
if(Utility::Directory::exists(dest)) {
Utility::Directory::rm(dest);
}
if(!Utility::Directory::move(source + ".tmp", dest)) {
if(!Utility::Directory::move(source + ".tmp", Utility::Directory::join(_saveDirectory, _hangars[hangar].filename()))) {
_lastError = Utility::formatString("Couldn't move {} to hangar {:.2d}", staged_fn, hangar + 1);
return false;
}
@ -102,7 +98,7 @@ auto MassManager::importMass(const std::string& staged_fn, Int hangar) -> bool {
return true;
}
auto MassManager::exportMass(Int hangar) -> bool {
auto MassManager::exportMass(int hangar) -> bool {
if(hangar < 0 || hangar >= 32) {
_lastError = "Hangar out of range in MassManager::exportMass()";
return false;
@ -125,7 +121,7 @@ auto MassManager::exportMass(Int hangar) -> bool {
return true;
}
auto MassManager::moveMass(Int source, Int destination) -> bool {
auto MassManager::moveMass(int source, int destination) -> bool {
if(source < 0 || source >= 32) {
_lastError = "Source hangar out of range.";
return false;
@ -160,14 +156,14 @@ auto MassManager::moveMass(Int source, Int destination) -> bool {
return true;
}
auto MassManager::deleteMass(Int hangar) -> bool {
auto MassManager::deleteMass(int hangar) -> bool {
if(hangar < 0 || hangar >= 32) {
_lastError = "Hangar out of range.";
_lastError = "Hangar out of bounds";
return false;
}
if(!Utility::Directory::rm(Utility::Directory::join(_saveDirectory, _hangars[hangar].filename()))) {
_lastError = Utility::formatString("Deletion failed: {}", std::strerror(errno));
_lastError = "Deletion failed. Maybe the file was already deleted, or it's locked by another application.";
return false;
}
@ -206,7 +202,7 @@ auto MassManager::deleteStagedMass(const std::string& filename) -> bool {
}
if(!Utility::Directory::rm(Utility::Directory::join(_stagingAreaDirectory, filename))) {
_lastError = Utility::formatString("{} couldn't be deleted: {}", filename, std::strerror(errno));
_lastError = "The file " + filename + " couldn't be deleted for unknown reasons.";
return false;
}

View file

@ -27,6 +27,8 @@
#include "../UESaveFile/Types/IntProperty.h"
#include "../UESaveFile/Types/StringProperty.h"
#include "ResourceIDs.h"
#include "Profile.h"
using namespace Corrade;

View file

@ -22,8 +22,6 @@
#include "../UESaveFile/UESaveFile.h"
#include "ResourceIDs.h"
using namespace Magnum;
enum class ProfileType : UnsignedByte {

View file

@ -445,7 +445,8 @@ void SaveTool::drawMassManager() {
std::string file = *(static_cast<std::string*>(payload->Data));
if(!_massManager->importMass(file, i)) {
_queue.addToast(Toast::Type::Error, _massManager->lastError());
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error importing M.A.S.S.",
_massManager->lastError().c_str(), window());
}
}
else if((payload = ImGui::AcceptDragDropPayload("Mass"))) {
@ -459,7 +460,9 @@ void SaveTool::drawMassManager() {
int index = *(static_cast<int*>(payload->Data));
if(!_massManager->moveMass(index, i)) {
_queue.addToast(Toast::Type::Error, _massManager->lastError());
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error",
_massManager->lastError().c_str(),
window());
}
}
@ -572,7 +575,9 @@ void SaveTool::drawMassManager() {
int index = *(static_cast<int*>(payload->Data));
if(!_massManager->exportMass(index)) {
_queue.addToast(Toast::Type::Error, _massManager->lastError());
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error",
_massManager->lastError().c_str(),
window());
}
}
@ -621,7 +626,8 @@ auto SaveTool::drawDeleteMassPopup(int mass_index) -> ImGuiID {
ImGui::TableSetColumnIndex(1);
if(ImGui::Button("Yes")) {
if(!_massManager->deleteMass(mass_index)) {
_queue.addToast(Toast::Type::Error, _massManager->lastError());
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error when deleting M.A.S.S.",
_massManager->lastError().c_str(), window());
}
ImGui::CloseCurrentPopup();
}
@ -659,7 +665,8 @@ auto SaveTool::drawDeleteStagedMassPopup(const std::string& filename) -> ImGuiID
ImGui::TableSetColumnIndex(1);
if(ImGui::Button("Yes")) {
if(!_massManager->deleteStagedMass(filename)) {
_queue.addToast(Toast::Type::Error, _massManager->lastError());
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error when deleting M.A.S.S.",
_massManager->lastError().c_str(), window());
}
ImGui::CloseCurrentPopup();
}

View file

@ -150,7 +150,8 @@ auto SaveTool::drawBackupListPopup() -> ImGuiID {
ImGui::TableSetColumnIndex(1);
if(ImGui::Button("Yes")) {
if(!_profileManager->restoreBackup(backup_index)) {
_queue.addToast(Toast::Type::Error, _profileManager->lastError());
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error when restoring backup",
_profileManager->lastError().c_str(), window());
}
_profileManager->refreshProfiles();
ImGui::CloseCurrentPopup();
@ -189,7 +190,8 @@ auto SaveTool::drawBackupListPopup() -> ImGuiID {
ImGui::TableSetColumnIndex(1);
if(ImGui::Button("Yes")) {
if(!_profileManager->deleteBackup(backup_index)) {
_queue.addToast(Toast::Type::Error, _profileManager->lastError());
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error when deleting backup",
_profileManager->lastError().c_str(), window());
}
ImGui::CloseCurrentPopup();
}
@ -376,7 +378,8 @@ auto SaveTool::drawDeleteProfilePopup(std::size_t profile_index) -> ImGuiID {
ImGui::TableSetColumnIndex(1);
if(ImGui::Button("Yes")) {
if(!_profileManager->deleteProfile(profile_index, delete_builds)) {
_queue.addToast(Toast::Type::Error, _profileManager->lastError());
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error when deleting profile",
_profileManager->lastError().c_str(), window());
}
ImGui::CloseCurrentPopup();
}