Use driver settings API for the MIDI settings
Suggested by Adrien, to make the MIDI settings more future proof when more settings will be added, and to make manual editing less error prone. Moved the settings from B_USER_SETTINGS_DIRECTORY/midi to B_USER_SETTINGS_DIRECTORY/Media/midi_settings.
This commit is contained in:
parent
02d8a059f0
commit
97a5f78d9f
@ -9,11 +9,13 @@
|
||||
#include <FindDirectory.h>
|
||||
#include <Path.h>
|
||||
|
||||
#include <driver_settings.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define SETTINGS_FILE "midi"
|
||||
#define SETTINGS_FILE "Media/midi_settings"
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
@ -23,21 +25,24 @@ read_midi_settings(struct midi_settings* settings)
|
||||
if (settings == NULL)
|
||||
return B_ERROR;
|
||||
|
||||
char buffer[B_FILE_NAME_LENGTH + 128];
|
||||
BPath path;
|
||||
status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
|
||||
path.Append("midi");
|
||||
BFile file(path.Path(), B_READ_ONLY);
|
||||
if (file.InitCheck() != B_OK
|
||||
|| file.Read(buffer, sizeof(buffer)) <= 0)
|
||||
path.Append(SETTINGS_FILE);
|
||||
void* handle = load_driver_settings(path.Path());
|
||||
if (handle == NULL)
|
||||
return B_ERROR;
|
||||
|
||||
sscanf(buffer, "# Midi Settings\n soundfont = %[^\n]\n",
|
||||
settings->soundfont_file);
|
||||
const char* soundfont = get_driver_parameter(handle, "soundfont", NULL,
|
||||
NULL);
|
||||
if (soundfont == NULL)
|
||||
return B_ERROR;
|
||||
strlcpy(settings->soundfont_file, soundfont,
|
||||
sizeof(settings->soundfont_file));
|
||||
|
||||
unload_driver_settings(handle);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@ -45,17 +50,21 @@ read_midi_settings(struct midi_settings* settings)
|
||||
status_t
|
||||
write_midi_settings(struct midi_settings settings)
|
||||
{
|
||||
char buffer[B_FILE_NAME_LENGTH + 128];
|
||||
snprintf(buffer, sizeof(buffer), "# Midi Settings\n soundfont = %s\n",
|
||||
settings.soundfont_file);
|
||||
|
||||
BPath path;
|
||||
status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
|
||||
path.Append(SETTINGS_FILE);
|
||||
BFile file(path.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
|
||||
|
||||
BFile file;
|
||||
if (file.SetTo(path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE)
|
||||
!= B_OK)
|
||||
return B_ERROR;
|
||||
|
||||
char buffer[B_FILE_NAME_LENGTH + 128];
|
||||
snprintf(buffer, sizeof(buffer), "# Midi\n\tsoundfont \"%s\"\n",
|
||||
settings.soundfont_file);
|
||||
|
||||
size_t bufferSize = strlen(buffer);
|
||||
if (file.InitCheck() != B_OK
|
||||
|
Loading…
x
Reference in New Issue
Block a user