/* * Copyright 2024, My Name * All rights reserved. Distributed under the terms of the MIT license. */ #include "Utils.h" #include #include #include #include #include #include status_t SaveMessageToFile(const BMessage& message, const char* fileName) { BPath path; if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) { return B_ERROR; } path.Append(fileName); BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE); if (file.InitCheck() != B_OK) { return file.InitCheck(); } return message.Flatten(&file); } BMessage LoadMessageFromFile(const char* fileName) { BPath path; if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) { return BMessage(B_ERROR); // Return a message indicating an error } path.Append(fileName); BFile file(path.Path(), B_READ_ONLY); if (file.InitCheck() != B_OK) { return BMessage(file.InitCheck()); // Return a message with the error status } BMessage message; status_t status = message.Unflatten(&file); if (status != B_OK) { return BMessage(status); // Return a message indicating unflattening error } return message; }