// MassBuilderSaveTool // Copyright (C) 2021-2024 Guillaume Jacquemin // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . #include #include #include #include "../Configuration/Configuration.h" #include "../Logger/Logger.h" #include "Temp.h" namespace mbst { namespace Utilities { Containers::String getTempPath(Containers::StringView filename) { return Utility::Path::join(conf().directories().temp, filename); } Containers::Optional copyToTemp(Containers::StringView path) { auto filename = Utility::Path::split(path).first(); auto dest = Utility::Path::join(conf().directories().temp, filename); if(!Utility::Path::copy(path, dest)) { LOG_ERROR_FORMAT("Couldn't copy {} to {}.", path, conf().directories().temp); return Containers::NullOpt; } return Utility::move(dest); } Containers::Optional moveToTemp(Containers::StringView path) { auto filename = Utility::Path::split(path).first(); auto dest = Utility::Path::join(conf().directories().temp, filename); if(!Utility::Path::move(path, dest)) { LOG_ERROR_FORMAT("Couldn't move {} to {}.", path, conf().directories().temp); return Containers::NullOpt; } return Utility::move(dest); } bool moveFromTemp(Containers::StringView filename, Containers::StringView destination) { auto source = Utility::Path::join(conf().directories().temp, filename); auto dest = Utility::Path::join(destination, filename); if(!Utility::Path::move(source, dest)) { LOG_ERROR_FORMAT("Couldn't move {} to {}.", filename, destination); return false; } return true; } bool deleteTempFile(Containers::StringView filename) { return Utility::Path::remove(Utility::Path::join(conf().directories().temp, filename)); } void emptyTempDir() { using Flag = Utility::Path::ListFlag; auto files = Utility::Path::list(conf().directories().temp, Flag::SkipDirectories|Flag::SkipSpecial); CORRADE_INTERNAL_ASSERT(files); for(auto& filename : *files) { deleteTempFile(filename); } } }}