saves models to settings to avoid reload, with option to force from menu
This commit is contained in:
parent
dd033a7896
commit
177cdb925f
10 changed files with 269 additions and 42 deletions
52
Utils.cpp
Normal file
52
Utils.cpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright 2024, My Name <my@email.address>
|
||||
* All rights reserved. Distributed under the terms of the MIT license.
|
||||
*/
|
||||
|
||||
|
||||
#include "Utils.h"
|
||||
|
||||
#include <File.h>
|
||||
#include <Path.h>
|
||||
#include <Directory.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Message.h>
|
||||
#include <String.h>
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue