core/file: Rename struct file -> struct data_file

I'm going to create a unified struct file that should be able to share
code between data and cache files.  The first step is to push the old
structure to the side so it can still be used in other places.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2018-02-16 09:34:06 -05:00
parent 48f79bdb49
commit 82280edfa2
29 changed files with 298 additions and 297 deletions

View File

@ -13,7 +13,7 @@
static const char *SETTINGS_TRACK = "core.audio.cur";
static const char *SETTINGS_VOLUME = "core.audio.volume";
static struct file audio_file = FILE_INIT("cur_track", 0);
static struct data_file audio_file = DATA_FILE_INIT("cur_track", 0);
static struct track *audio_track = NULL;
static int audio_pause_count = -1;
@ -131,10 +131,10 @@ static bool __audio_init_idle(void *data)
if (settings_has(SETTINGS_TRACK)) {
track = settings_get(SETTINGS_TRACK);
__audio_load(track_get(track), LOAD_HISTORY);
} else if (file_open(&audio_file, OPEN_READ)) {
file_readf(&audio_file, "%u", &track);
file_close(&audio_file);
file_remove(&audio_file);
} else if (data_file_open(&audio_file, OPEN_READ)) {
data_file_readf(&audio_file, "%u", &track);
data_file_close(&audio_file);
data_file_remove(&audio_file);
__audio_load(track_get(track), LOAD_HISTORY);
}

View File

@ -38,7 +38,7 @@ static struct db_entry *__dbe_read(struct database *db, unsigned int index)
struct db_entry *dbe = NULL;
int valid;
file_readf(&db->db_file, "%d", &valid);
data_file_readf(&db->db_file, "%d", &valid);
if (valid)
dbe = db->db_ops->dbe_read(&db->db_file, index);
@ -61,11 +61,11 @@ static void __dbe_setup(struct database *db, unsigned int index)
static void __dbe_write(struct database *db, struct db_entry *dbe)
{
if (dbe) {
file_writef(&db->db_file, "%u ", true);
data_file_writef(&db->db_file, "%u ", true);
db->db_ops->dbe_write(&db->db_file, dbe);
} else
file_writef(&db->db_file, "%u", false);
file_writef(&db->db_file, "\n");
data_file_writef(&db->db_file, "%u", false);
data_file_writef(&db->db_file, "\n");
}
void db_init(struct database *db, const char *filepath, bool autosave,
@ -76,7 +76,7 @@ void db_init(struct database *db, const char *filepath, bool autosave,
db->db_autosave = autosave;
db->db_entries = g_ptr_array_new();
db->db_keys = g_hash_table_new(g_str_hash, g_str_equal);
file_init(&db->db_file, filepath, fmin);
data_file_init(&db->db_file, filepath, fmin);
}
void db_deinit(struct database *db)
@ -94,14 +94,14 @@ void db_deinit(struct database *db)
void db_save(struct database *db)
{
if (file_open(&db->db_file, OPEN_WRITE) == false)
if (data_file_open(&db->db_file, OPEN_WRITE) == false)
return;
file_writef(&db->db_file, "%u\n", db_actual_size(db));
data_file_writef(&db->db_file, "%u\n", db_actual_size(db));
for (unsigned int i = 0; i < db_actual_size(db); i++)
__dbe_write(db, DB_ENTRY_AT(db, i));
file_close(&db->db_file);
data_file_close(&db->db_file);
}
void db_autosave(struct database *db)
@ -115,18 +115,18 @@ void db_load(struct database *db)
unsigned int size;
bool save;
if (file_open(&db->db_file, OPEN_READ) == false)
if (data_file_open(&db->db_file, OPEN_READ) == false)
return;
file_readf(&db->db_file, "%u", &size);
data_file_readf(&db->db_file, "%u", &size);
g_ptr_array_set_size(db->db_entries, size);
for (unsigned int i = 0; i < size; i++) {
if (__dbe_read(db, i))
__dbe_setup(db, i);
}
save = file_version(&db->db_file) != OCARINA_MINOR_VERSION;
file_close(&db->db_file);
save = data_file_version(&db->db_file) != OCARINA_MINOR_VERSION;
data_file_close(&db->db_file);
if (save)
db_autosave(db);

View File

@ -24,26 +24,26 @@ void date_today(struct date *date)
date_set(date, now->tm_year + 1900, now->tm_mon + 1, now->tm_mday);
}
void date_read(struct file *f, struct date *date)
void date_read(struct data_file *f, struct date *date)
{
file_readf(f, "%u %u %u", &date->d_year, &date->d_month, &date->d_day);
data_file_readf(f, "%u %u %u", &date->d_year, &date->d_month, &date->d_day);
}
void date_read_stamp(struct file *f, struct date *date)
void date_read_stamp(struct data_file *f, struct date *date)
{
uint32_t stamp;
file_readf(f, "%u", &stamp);
data_file_readf(f, "%u", &stamp);
date->d_stamp = be32toh(stamp);
}
void date_write(struct file *f, struct date *date)
void date_write(struct data_file *f, struct date *date)
{
file_writef(f, "%u %u %u", date->d_year, date->d_month, date->d_day);
data_file_writef(f, "%u %u %u", date->d_year, date->d_month, date->d_day);
}
void date_write_stamp(struct file *f, struct date *date)
void date_write_stamp(struct data_file *f, struct date *date)
{
file_writef(f, "%u", htobe32(date->d_stamp));
data_file_writef(f, "%u", htobe32(date->d_stamp));
}
gchar *date_string(const struct date *date)

View File

@ -81,9 +81,9 @@ static bool __file_mkdir(const gchar *basedir, const gchar *subdir)
return ret == 0;
}
static bool __file_can_write(struct file *file)
static bool __file_can_write(struct data_file *file)
{
gchar *path = file_path(file);
gchar *path = data_file_path(file);
bool ret = true;
if (g_access(path, F_OK) == 0 && g_access(path, W_OK) < 0)
@ -94,7 +94,7 @@ static bool __file_can_write(struct file *file)
}
void file_init(struct file *file, const gchar *name, unsigned int min)
void data_file_init(struct data_file *file, const gchar *name, unsigned int min)
{
file->f_mode = OPEN_READ;
file->f_version = OCARINA_MINOR_VERSION;
@ -111,7 +111,7 @@ void cache_file_init(struct cache_file *file, const gchar *subdir, const gchar *
file->cf_subdir = subdir;
}
gchar *file_path(struct file *file)
gchar *data_file_path(struct data_file *file)
{
return __file_build_path(g_get_user_data_dir(), NULL, file->f_name);
}
@ -122,7 +122,7 @@ gchar *cache_file_path(struct cache_file *file)
file->cf_name);
}
gchar *file_write_path(struct file *file)
gchar *data_file_write_path(struct data_file *file)
{
return __file_build_tmp(g_get_user_data_dir(), NULL, file->f_name);
}
@ -133,16 +133,16 @@ gchar *cache_file_write_path(struct cache_file *file)
file->cf_name);
}
const unsigned int file_version(struct file *file)
const unsigned int data_file_version(struct data_file *file)
{
if (file->f_file && (file->f_mode == OPEN_READ))
return file->f_prev;
return file->f_version;
}
bool file_exists(struct file *file)
bool data_file_exists(struct data_file *file)
{
return __file_exists(file_path(file));
return __file_exists(data_file_path(file));
}
bool cache_file_exists(struct cache_file *file)
@ -150,47 +150,47 @@ bool cache_file_exists(struct cache_file *file)
return __file_exists(cache_file_path(file));
}
static bool __file_open_read(struct file *file)
static bool __file_open_read(struct data_file *file)
{
if (!file_exists(file))
if (!data_file_exists(file))
return false;
file->f_file = __file_open(file_path(file), "r");
file->f_file = __file_open(data_file_path(file), "r");
if (!file->f_file)
return false;
file->f_mode = OPEN_READ;
if (file_readf(file, "%u\n", &file->f_prev) != 1)
if (data_file_readf(file, "%u\n", &file->f_prev) != 1)
return false;
if (file->f_prev < file->f_min) {
REPORT_ERROR(file->f_name, "File too old to be upgraded.");
file_close(file);
data_file_close(file);
exit(1);
}
if (file->f_prev > file->f_version) {
REPORT_ERROR(file->f_name, "File too new to be opened.");
file_close(file);
data_file_close(file);
exit(1);
}
return true;
}
static bool __file_open_write(struct file *file)
static bool __file_open_write(struct data_file *file)
{
if (!__file_mkdir(g_get_user_data_dir(), NULL))
return false;
if (!__file_can_write(file))
return false;
file->f_file = __file_open(file_write_path(file), "w");
file->f_file = __file_open(data_file_write_path(file), "w");
if (!file->f_file)
return false;
file->f_mode = OPEN_WRITE;
return file_writef(file, "%d\n", file->f_version) > 0;
return data_file_writef(file, "%d\n", file->f_version) > 0;
}
bool file_open(struct file *file, enum open_mode mode)
bool data_file_open(struct data_file *file, enum open_mode mode)
{
if ((string_length(file->f_name) == 0) || (file->f_file != NULL))
return false;
@ -213,11 +213,11 @@ bool cache_file_open(struct cache_file *file, enum open_mode mode)
return file->cf_file != NULL;
}
void file_close(struct file *file)
void data_file_close(struct data_file *file)
{
__file_close(file->f_file,
file->f_mode == OPEN_WRITE ? file_path(file) : NULL,
file->f_mode == OPEN_WRITE ? file_write_path(file) : NULL);
file->f_mode == OPEN_WRITE ? data_file_path(file) : NULL,
file->f_mode == OPEN_WRITE ? data_file_write_path(file) : NULL);
file->f_file = NULL;
}
@ -229,7 +229,7 @@ void cache_file_close(struct cache_file *file)
file->cf_file = NULL;
}
int file_readf(struct file *file, const char *fmt, ...)
int data_file_readf(struct data_file *file, const char *fmt, ...)
{
va_list argp;
int ret;
@ -241,18 +241,18 @@ int file_readf(struct file *file, const char *fmt, ...)
return ret;
}
gchar *file_readl(struct file *file)
gchar *data_file_readl(struct data_file *file)
{
gchar *res;
if (file_readf(file, "%m[^\n]\n", &res) == 0)
if (data_file_readf(file, "%m[^\n]\n", &res) == 0)
return g_strdup("");
g_strstrip(res);
return res;
}
int file_writef(struct file *file, const char *fmt, ...)
int data_file_writef(struct data_file *file, const char *fmt, ...)
{
va_list argp;
int ret;
@ -287,13 +287,13 @@ bool cache_file_import(struct cache_file *file, const gchar *srcpath)
return true;
}
bool file_remove(struct file *file)
bool data_file_remove(struct data_file *file)
{
int ret = -1;
gchar *path;
if (!file->f_file) {
path = file_path(file);
path = data_file_path(file);
ret = g_unlink(path);
g_free(path);
}

View File

@ -5,7 +5,7 @@
#include <core/playlists/artist.h>
#include <core/string.h>
static struct file artist_file = FILE_INIT("playlist.artist", 0);
static struct data_file artist_file = DATA_FILE_INIT("playlist.artist", 0);
static struct playlist_ops pl_artist_ops = {
.pl_can_select = playlist_generic_can_select,
@ -47,12 +47,12 @@ static bool __artist_pl_load(void *data)
unsigned int i, n;
gchar *name;
if (!file_open(&artist_file, OPEN_READ))
if (!data_file_open(&artist_file, OPEN_READ))
return true;
file_readf(&artist_file, "%u\n", &n);
data_file_readf(&artist_file, "%u\n", &n);
for (i = 0; i < n; i++) {
name = file_readl(&artist_file);
name = data_file_readl(&artist_file);
playlist = __artist_pl_lookup(name);
if (playlist)
playlist_generic_load(playlist, &artist_file,
@ -60,7 +60,7 @@ static bool __artist_pl_load(void *data)
g_free(name);
}
file_close(&artist_file);
data_file_close(&artist_file);
return true;
}
@ -70,17 +70,17 @@ static void pl_artist_save(void)
struct db_entry *dbe, *next;
struct playlist *playlist;
if (!file_open(&artist_file, OPEN_WRITE))
if (!data_file_open(&artist_file, OPEN_WRITE))
return;
file_writef(&artist_file, "%u\n", artist_db_get()->db_size);
data_file_writef(&artist_file, "%u\n", artist_db_get()->db_size);
db_for_each(dbe, next, artist_db_get()) {
playlist = ARTIST(dbe)->ar_playlist;
file_writef(&artist_file, "%s\n", playlist->pl_name);
data_file_writef(&artist_file, "%s\n", playlist->pl_name);
playlist_generic_save(playlist, &artist_file, PL_SAVE_METADATA);
}
file_close(&artist_file);
data_file_close(&artist_file);
}
static struct playlist *pl_artist_lookup(const gchar *name)

View File

@ -95,7 +95,7 @@ void playlist_generic_free(struct playlist *playlist)
}
}
void playlist_generic_save(struct playlist *playlist, struct file *file,
void playlist_generic_save(struct playlist *playlist, struct data_file *file,
unsigned int flags)
{
playlist_iter it;
@ -106,30 +106,30 @@ void playlist_generic_save(struct playlist *playlist, struct file *file,
return;
if (flags & PL_SAVE_ITER)
file_writef(file, "%u ", playlist_current_index(playlist));
data_file_writef(file, "%u ", playlist_current_index(playlist));
if (flags & PL_SAVE_FLAGS) {
sort = playlist->pl_sort;
file_writef(file, "%u ", playlist->pl_random ? PL_RANDOM : 0);
file_writef(file, "%u", g_slist_length(sort));
data_file_writef(file, "%u ", playlist->pl_random ? PL_RANDOM : 0);
data_file_writef(file, "%u", g_slist_length(sort));
while (sort) {
field = GPOINTER_TO_INT(sort->data);
file_writef(file, " %u %d", abs(field) - 1, field > 0);
data_file_writef(file, " %u %d", abs(field) - 1, field > 0);
sort = g_slist_next(sort);
}
file_writef(file, "\n");
data_file_writef(file, "\n");
}
if (flags & PL_SAVE_TRACKS) {
file_writef(file, "%u", playlist_size(playlist));
data_file_writef(file, "%u", playlist_size(playlist));
playlist_for_each(playlist, it)
file_writef(file, " %u",
data_file_writef(file, " %u",
track_index(playlist_iter_track(it)));
file_writef(file, "\n");
data_file_writef(file, "\n");
}
}
void playlist_generic_load(struct playlist *playlist, struct file *file,
void playlist_generic_load(struct playlist *playlist, struct data_file *file,
unsigned int flags)
{
unsigned int f, n, i, t, it = 0;
@ -140,13 +140,13 @@ void playlist_generic_load(struct playlist *playlist, struct file *file,
return;
if (flags & PL_SAVE_ITER)
file_readf(file, "%u", &it);
data_file_readf(file, "%u", &it);
if (flags & PL_SAVE_FLAGS) {
file_readf(file, "%u %u", &f, &n);
data_file_readf(file, "%u %u", &f, &n);
playlist_clear_sort(playlist);
for (i = 0; i < n; i++) {
file_readf(file, "%u %d", &field, &ascending);
data_file_readf(file, "%u %d", &field, &ascending);
field += 1;
if (!ascending)
field = -field;
@ -155,17 +155,17 @@ void playlist_generic_load(struct playlist *playlist, struct file *file,
}
playlist_generic_resort(playlist);
if (file_readf(file, "%m\n", &line))
if (data_file_readf(file, "%m\n", &line))
g_free(line);
}
if (flags & PL_SAVE_TRACKS) {
file_readf(file, "%u ", &n);
data_file_readf(file, "%u ", &n);
for (i = 0; i < n; i++) {
file_readf(file, "%u", &t);
data_file_readf(file, "%u", &t);
playlist_generic_add(playlist, track_get(t));
}
if (file_readf(file, "%m\n", &line))
if (data_file_readf(file, "%m\n", &line))
g_free(line);
}

View File

@ -14,7 +14,7 @@ struct scan_data {
};
static bool __lib_pl_scan_dir(void *);
static struct file lib_file = FILE_INIT("playlist.library", 0);
static struct data_file lib_file = DATA_FILE_INIT("playlist.library", 0);
static struct playlist_ops pl_library_ops;
@ -52,12 +52,12 @@ static bool __lib_pl_load(void *data)
unsigned int i, n;
gchar *name;
if (!file_open(&lib_file, OPEN_READ))
if (!data_file_open(&lib_file, OPEN_READ))
return true;
file_readf(&lib_file, "%u\n", &n);
data_file_readf(&lib_file, "%u\n", &n);
for (i = 0; i < n; i++) {
name = file_readl(&lib_file);
name = data_file_readl(&lib_file);
playlist = __lib_pl_lookup(name);
if (playlist)
playlist_generic_load(playlist, &lib_file,
@ -65,7 +65,7 @@ static bool __lib_pl_load(void *data)
g_free(name);
}
file_close(&lib_file);
data_file_close(&lib_file);
return true;
}
@ -187,17 +187,17 @@ static void pl_library_save(void)
struct db_entry *dbe, *next;
struct playlist *playlist;
if (!file_open(&lib_file, OPEN_WRITE))
if (!data_file_open(&lib_file, OPEN_WRITE))
return;
file_writef(&lib_file, "%u\n", library_db_get()->db_size);
data_file_writef(&lib_file, "%u\n", library_db_get()->db_size);
db_for_each(dbe, next, library_db_get()) {
playlist = LIBRARY(dbe)->li_playlist;
file_writef(&lib_file, "%s\n", playlist->pl_name);
data_file_writef(&lib_file, "%s\n", playlist->pl_name);
playlist_generic_save(playlist, &lib_file, PL_SAVE_METADATA);
}
file_close(&lib_file);
data_file_close(&lib_file);
}
static struct playlist *pl_library_lookup(const gchar *name)

View File

@ -9,10 +9,10 @@ static struct playlist *pl_system_lookup(const gchar *);
static struct playlist *pl_system_get(unsigned int);
static void pl_system_save();
static struct file sys_file = FILE_INIT("playlist.db", 0);
static struct file sys_deck_f = FILE_INIT("deck", 1);
static struct file sys_collection_f = FILE_INIT("library.q", 0);
static struct file sys_pl_file = FILE_INIT("playlist.system", 0);
static struct data_file sys_file = DATA_FILE_INIT("playlist.db", 0);
static struct data_file sys_deck_f = DATA_FILE_INIT("deck", 1);
static struct data_file sys_collection_f = DATA_FILE_INIT("library.q", 0);
static struct data_file sys_pl_file = DATA_FILE_INIT("playlist.system", 0);
/*
@ -143,12 +143,12 @@ static bool sys_pl_queued_load()
struct playlist *playlist = pl_system_get(SYS_PL_QUEUED);
unsigned int num, i, flags = 0;
if (!file_open(&sys_deck_f, OPEN_READ))
if (!data_file_open(&sys_deck_f, OPEN_READ))
return true;
file_readf(&sys_deck_f, "%u", &num);
data_file_readf(&sys_deck_f, "%u", &num);
for (i = 0; i < num; i++) {
file_readf(&sys_deck_f, "%u", &flags);
data_file_readf(&sys_deck_f, "%u", &flags);
flags &= PL_RANDOM;
if (i == 0)
playlist_generic_set_random(playlist,
@ -156,8 +156,8 @@ static bool sys_pl_queued_load()
playlist_generic_load(playlist, &sys_deck_f, PL_SAVE_TRACKS);
}
file_close(&sys_deck_f);
file_remove(&sys_deck_f);
data_file_close(&sys_deck_f);
data_file_remove(&sys_deck_f);
return true;
}
@ -193,10 +193,10 @@ static bool sys_pl_collection_load()
{
struct playlist *playlist = pl_system_get(SYS_PL_COLLECTION);
if (file_open(&sys_collection_f, OPEN_READ)) {
if (data_file_open(&sys_collection_f, OPEN_READ)) {
playlist_generic_load(playlist, &sys_collection_f, PL_SAVE_FLAGS);
file_close(&sys_collection_f);
file_remove(&sys_collection_f);
data_file_close(&sys_collection_f);
data_file_remove(&sys_collection_f);
}
return true;
@ -261,12 +261,12 @@ static bool __sys_pl_load()
unsigned int i, n;
gchar *name;
if (!file_open(&sys_file, OPEN_READ))
if (!data_file_open(&sys_file, OPEN_READ))
return true;
file_readf(&sys_file, "%u\n", &n);
data_file_readf(&sys_file, "%u\n", &n);
for (i = 0; i < n; i++) {
file_readf(&sys_file, "%*u %m[^\n]\n", &name);
data_file_readf(&sys_file, "%*u %m[^\n]\n", &name);
if (string_match(name, "Banned")) {
g_free(name);
name = g_strdup("Hidden");
@ -278,8 +278,8 @@ static bool __sys_pl_load()
playlist_generic_load(playlist, &sys_file, PL_SAVE_TRACKS);
}
file_close(&sys_file);
file_remove(&sys_file);
data_file_close(&sys_file);
data_file_remove(&sys_file);
return true;
}
@ -289,7 +289,7 @@ static bool __sys_pl_load_new()
unsigned int i, n, load;
gchar *name;
if (!file_open(&sys_pl_file, OPEN_READ)) {
if (!data_file_open(&sys_pl_file, OPEN_READ)) {
__sys_pl_load();
sys_pl_collection_load();
sys_pl_queued_load();
@ -297,10 +297,10 @@ static bool __sys_pl_load_new()
return true;
}
file_readf(&sys_pl_file, "%u\n", &n);
data_file_readf(&sys_pl_file, "%u\n", &n);
for (i = 0; i < n; i++) {
load = PL_SAVE_METADATA;
name = file_readl(&sys_pl_file);
name = data_file_readl(&sys_pl_file);
if (string_match(name, "Banned")) {
g_free(name);
@ -320,7 +320,7 @@ static bool __sys_pl_load_new()
playlist_generic_load(playlist, &sys_pl_file, load);
}
file_close(&sys_pl_file);
data_file_close(&sys_pl_file);
return true;
}
@ -330,10 +330,10 @@ static void pl_system_save(void)
struct playlist *playlist;
unsigned int i, save;
if (!file_open(&sys_pl_file, OPEN_WRITE))
if (!data_file_open(&sys_pl_file, OPEN_WRITE))
return;
file_writef(&sys_pl_file, "%u\n", SYS_PL_NUM_PLAYLISTS);
data_file_writef(&sys_pl_file, "%u\n", SYS_PL_NUM_PLAYLISTS);
for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) {
save = PL_SAVE_METADATA;
playlist = pl_system_get(i);
@ -345,12 +345,12 @@ static void pl_system_save(void)
save = PL_SAVE_ALL;
}
file_writef(&sys_pl_file, "%s\n", playlist->pl_name);
data_file_writef(&sys_pl_file, "%s\n", playlist->pl_name);
playlist_generic_save(playlist, &sys_pl_file, save);
}
file_close(&sys_pl_file);
data_file_close(&sys_pl_file);
}
static struct playlist *pl_system_lookup(const gchar *name)

View File

@ -37,20 +37,20 @@ static gchar *user_db_key(struct db_entry *dbe)
return g_strdup(USER_PLAYLIST(dbe)->pl_playlist.pl_name);
}
static struct db_entry *user_db_read(struct file *file, unsigned int index)
static struct db_entry *user_db_read(struct data_file *file, unsigned int index)
{
gchar *name = file_readl(file);
gchar *name = data_file_readl(file);
struct user_playlist *playlist = __user_db_alloc(name, index);
playlist_generic_load(&playlist->pl_playlist, file, PL_SAVE_ALL);
return &playlist->pl_dbe;
}
static void user_db_write(struct file *file, struct db_entry *dbe)
static void user_db_write(struct data_file *file, struct db_entry *dbe)
{
struct playlist *playlist = &USER_PLAYLIST(dbe)->pl_playlist;
file_writef(file, "%s\n", playlist->pl_name);
data_file_writef(file, "%s\n", playlist->pl_name);
playlist_generic_save(playlist, file, PL_SAVE_ALL);
}

View File

@ -5,23 +5,23 @@
#include <core/settings.h>
static GHashTable *gui_settings = NULL;
static struct file gui_settings_file = FILE_INIT("settings", 0);
static struct data_file gui_settings_file = DATA_FILE_INIT("settings", 0);
static void __settings_save_item(gpointer key, gpointer value, gpointer data)
{
file_writef(&gui_settings_file, "%s %u\n", (const gchar *)key,
data_file_writef(&gui_settings_file, "%s %u\n", (const gchar *)key,
GPOINTER_TO_UINT(value));
}
static void __settings_save()
{
file_open(&gui_settings_file, OPEN_WRITE);
data_file_open(&gui_settings_file, OPEN_WRITE);
file_writef(&gui_settings_file, "%u\n", g_hash_table_size(gui_settings));
data_file_writef(&gui_settings_file, "%u\n", g_hash_table_size(gui_settings));
g_hash_table_foreach(gui_settings, __settings_save_item, NULL);
file_close(&gui_settings_file);
data_file_close(&gui_settings_file);
}
static void __settings_read()
@ -29,9 +29,10 @@ static void __settings_read()
unsigned int num, i, value;
gchar *key;
file_readf(&gui_settings_file, "%u\n", &num);
data_file_readf(&gui_settings_file, "%u\n", &num);
for (i = 0; i < num; i++) {
file_readf(&gui_settings_file, "%m[^ ] %u\n", &key, &value);
data_file_readf(&gui_settings_file, "%m[^ ] %u\n", &key, &value);
g_hash_table_insert(gui_settings, key, GUINT_TO_POINTER(value));
}
}
@ -41,9 +42,9 @@ void settings_init()
gui_settings = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, NULL);
if (file_open(&gui_settings_file, OPEN_READ))
if (data_file_open(&gui_settings_file, OPEN_READ))
__settings_read();
file_close(&gui_settings_file);
data_file_close(&gui_settings_file);
}
void settings_deinit()

View File

@ -252,14 +252,14 @@ static struct album *__album_parse_v0(gchar *line)
return __album_alloc(NULL, NULL, name, year);
}
static struct db_entry *album_read(struct file *file, unsigned int index)
static struct db_entry *album_read(struct data_file *file, unsigned int index)
{
unsigned int year, artist_id, genre_id, n;
struct album *album;
gchar *line, *name;
line = file_readl(file);
if (file_version(file) == 0) {
line = data_file_readl(file);
if (data_file_version(file) == 0) {
album = __album_parse_v0(line);
album_db_upgraded = true;
goto out;
@ -276,13 +276,13 @@ out:
return &album->al_dbe;
}
static void album_write(struct file *file, struct db_entry *dbe)
static void album_write(struct data_file *file, struct db_entry *dbe)
{
struct album *album = ALBUM(dbe);
struct artist *artist = album->al_artist;
struct genre *genre = album->al_genre;
file_writef(file, "%u %u %u %s", artist ? artist_index(artist) : 0,
data_file_writef(file, "%u %u %u %s", artist ? artist_index(artist) : 0,
genre ? genre_index(genre) : 0,
album->al_year, album->al_name);
}

View File

@ -37,14 +37,14 @@ static gchar *artist_key(struct db_entry *dbe)
return ARTIST(dbe)->ar_name;
}
struct db_entry *artist_read(struct file *file, unsigned int index)
struct db_entry *artist_read(struct data_file *file, unsigned int index)
{
return &__artist_alloc(file_readl(file))->ar_dbe;
return &__artist_alloc(data_file_readl(file))->ar_dbe;
}
static void artist_write(struct file *file, struct db_entry *dbe)
static void artist_write(struct data_file *file, struct db_entry *dbe)
{
file_writef(file, "%s", ARTIST(dbe)->ar_name);
data_file_writef(file, "%s", ARTIST(dbe)->ar_name);
}

View File

@ -35,14 +35,14 @@ static gchar *genre_key(struct db_entry *dbe)
return GENRE(dbe)->ge_name;
}
static struct db_entry *genre_read(struct file *file, unsigned int index)
static struct db_entry *genre_read(struct data_file *file, unsigned int index)
{
return &__genre_alloc(file_readl(file))->ge_dbe;
return &__genre_alloc(data_file_readl(file))->ge_dbe;
}
static void genre_write(struct file *file, struct db_entry *dbe)
static void genre_write(struct data_file *file, struct db_entry *dbe)
{
file_writef(file, "%s", GENRE(dbe)->ge_name);
data_file_writef(file, "%s", GENRE(dbe)->ge_name);
}

View File

@ -33,21 +33,21 @@ static gchar *library_key(struct db_entry *dbe)
return LIBRARY(dbe)->li_path;
}
static struct db_entry *library_read(struct file *file, unsigned int index)
static struct db_entry *library_read(struct data_file *file, unsigned int index)
{
int enabled;
gchar *path;
if (file_version(file) == 0)
file_readf(file, "%d", &enabled);
if (data_file_version(file) == 0)
data_file_readf(file, "%d", &enabled);
file_readf(file, " %m[^\n]", &path);
data_file_readf(file, " %m[^\n]", &path);
return &__library_alloc(path)->li_dbe;
}
static void library_write(struct file *file, struct db_entry *dbe)
static void library_write(struct data_file *file, struct db_entry *dbe)
{
file_writef(file, "%s", LIBRARY(dbe)->li_path);
data_file_writef(file, "%s", LIBRARY(dbe)->li_path);
}

View File

@ -126,14 +126,14 @@ static gchar *track_key(struct db_entry *dbe)
return TRACK(dbe)->tr_path;
}
static void track_read_v0(struct file *file, struct track *track)
static void track_read_v0(struct data_file *file, struct track *track)
{
unsigned int artist_id, album_id, genre_id;
struct artist *artist;
struct genre *genre;
struct album *album;
file_readf(file, "%u %u %u %hu", &artist_id, &album_id, &genre_id,
data_file_readf(file, "%u %u %u %hu", &artist_id, &album_id, &genre_id,
&track->tr_track);
date_read(file, &track->tr_date);
@ -147,46 +147,46 @@ static void track_read_v0(struct file *file, struct track *track)
track->tr_album = album;
}
static struct db_entry *track_read(struct file *file, unsigned int index)
static struct db_entry *track_read(struct data_file *file, unsigned int index)
{
struct track *track = __track_alloc();
unsigned int library_id, album_id;
file_readf(file, "%u", &library_id);
data_file_readf(file, "%u", &library_id);
track->tr_library = library_get(library_id);
if (file_version(file) == 0)
if (data_file_version(file) == 0)
track_read_v0(file, track);
else {
file_readf(file, "%u %hu", &album_id, &track->tr_track);
data_file_readf(file, "%u %hu", &album_id, &track->tr_track);
track->tr_album = album_get(album_id);
date_read_stamp(file, &track->tr_date);
}
file_readf(file, "%hu %hu", &track->tr_count, &track->tr_length);
data_file_readf(file, "%hu %hu", &track->tr_count, &track->tr_length);
play_count += track->tr_count;
if (track->tr_count == 0)
unplayed_count++;
track->tr_title = file_readl(file);
track->tr_title = data_file_readl(file);
track->tr_tokens = g_str_tokenize_and_fold(track->tr_title, NULL,
&track->tr_alts);
track->tr_path = __track_key(track->tr_library, file_readl(file));
track->tr_path = __track_key(track->tr_library, data_file_readl(file));
return &track->tr_dbe;
}
static void track_write(struct file *file, struct db_entry *dbe)
static void track_write(struct data_file *file, struct db_entry *dbe)
{
struct track *track = TRACK(dbe);
gchar *path = __track_path(track);
file_writef(file, "%u %u %hu ", library_index(track->tr_library),
data_file_writef(file, "%u %u %hu ", library_index(track->tr_library),
album_index(track->tr_album),
track->tr_track);
date_write_stamp(file, &track->tr_date);
file_writef(file, " %hu %hu %s\n%s", track->tr_count,
data_file_writef(file, " %hu %hu %s\n%s", track->tr_count,
track->tr_length,
track->tr_title,
path);

View File

@ -57,17 +57,17 @@ struct db_ops {
gchar *(*dbe_key)(struct db_entry *);
/* Read a single struct db_entry from disk. */
struct db_entry *(*dbe_read)(struct file *, unsigned int);
struct db_entry *(*dbe_read)(struct data_file *, unsigned int);
/* Write a single struct db_entry to disk. */
void (*dbe_write)(struct file *, struct db_entry *);
void (*dbe_write)(struct data_file *, struct db_entry *);
};
struct database {
unsigned int db_size; /* The database's count of valid entries. */
bool db_autosave; /* The database's automatic save setting. */
struct file db_file; /* The database's associated file object. */
struct data_file db_file; /* The database's associated file object. */
GPtrArray *db_entries; /* The database's backing array. */
GHashTable *db_keys; /* The database's mapping of key -> value. */
@ -78,7 +78,7 @@ struct database {
{ \
.db_size = 0, \
.db_autosave = autosave, \
.db_file = FILE_INIT(fname, fmin), \
.db_file = DATA_FILE_INIT(fname, fmin), \
.db_entries = g_ptr_array_new(), \
.db_keys = g_hash_table_new(g_str_hash, g_str_equal), \
.db_ops = ops, \

View File

@ -27,12 +27,12 @@ void date_set(struct date *, unsigned int, unsigned int, unsigned int);
void date_today(struct date *);
/* Read the date from file. */
void date_read(struct file *, struct date *);
void date_read_stamp(struct file *, struct date *);
void date_read(struct data_file *, struct date *);
void date_read_stamp(struct data_file *, struct date *);
/* Write the date to file. */
void date_write(struct file *, struct date *);
void date_write_stamp(struct file *, struct date *);
void date_write(struct data_file *, struct date *);
void date_write_stamp(struct data_file *, struct date *);
/*
* Convert the date into a string.

View File

@ -34,7 +34,7 @@ enum open_mode {
OPEN_WRITE,
};
struct file {
struct data_file {
enum open_mode f_mode; /* The file's current open mode. */
unsigned int f_version; /* The file's current data version. */
unsigned int f_prev; /* The file's on-disk data version. */
@ -43,7 +43,7 @@ struct file {
const gchar *f_name; /* The file's basename. */
};
#define FILE_INIT(fname, min) \
#define DATA_FILE_INIT(fname, min) \
{ \
.f_mode = OPEN_READ, \
.f_version = OCARINA_MINOR_VERSION, \
@ -61,28 +61,28 @@ struct cache_file {
};
/* Initialize a new file object. */
void file_init(struct file *, const gchar *, unsigned int);
void data_file_init(struct data_file *, const gchar *, unsigned int);
void cache_file_init(struct cache_file *, const gchar *, const gchar *);
/*
* Returns the full path of the file or an empty string if filename is not set.
* These functions allocates a new string that MUST be freed with g_free().
*/
gchar *file_path(struct file *);
gchar *data_file_path(struct data_file *);
gchar *cache_file_path(struct cache_file *);
/*
* Returns the path to the temporary file used for writes.
* This function allocates a new string that MUST be freed with g_free().
*/
gchar *file_write_path(struct file *);
gchar *data_file_write_path(struct data_file *);
gchar *cache_file_write_path(struct cache_file *);
/* Returns the version number of the file. */
const unsigned int file_version(struct file *);
const unsigned int data_file_version(struct data_file *);
/* Returns true if the file exists on disk and false otherwise. */
bool file_exists(struct file *);
bool data_file_exists(struct data_file *);
bool cache_file_exists(struct cache_file *);
/*
@ -101,33 +101,33 @@ bool cache_file_exists(struct cache_file *);
* Returns true if the open was successful and false otherwise.
* Oening a cache file with OPEN_READ is currently unsupported.
*/
bool file_open(struct file *, enum open_mode);
bool data_file_open(struct data_file *, enum open_mode);
bool cache_file_open(struct cache_file *, enum open_mode);
/*
* Closes an open file, setting file->{f|cf}_file to NULL. If the file was opened
* with OPEN_WRITE, then rename the temporary file to file_path().
*/
void file_close(struct file *);
void data_file_close(struct data_file *);
void cache_file_close(struct cache_file *);
/*
* Read an entire line from the file and return it to the caller.
* This function allocates a new string that MUST be freed with g_free().
*/
gchar *file_readl(struct file *);
gchar *data_file_readl(struct data_file *);
/*
* Read from a file with an fscanf(3) style format string.
* Returns the number of items matched.
*/
int file_readf(struct file *, const char *, ...);
int data_file_readf(struct data_file *, const char *, ...);
/*
* Write to a file with an fprintf(3) style format string.
* Returns the number of bytes successfully written.
*/
int file_writef(struct file *, const char *, ...);
int data_file_writef(struct data_file *, const char *, ...);
/*
* Write binary data to a cache file similar to fwrite(3).
@ -139,6 +139,6 @@ int cache_file_write(struct cache_file *, const void *, size_t);
bool cache_file_import(struct cache_file *, const gchar *);
/* Removes a closed file from disk. */
bool file_remove(struct file *);
bool data_file_remove(struct data_file *);
#endif /* OCARINA_CORE_FILE_H */

View File

@ -54,10 +54,10 @@ struct playlist *playlist_generic_alloc(gchar *, enum playlist_type_t,
void playlist_generic_free(struct playlist *);
/* Generic playlist save function. */
void playlist_generic_save(struct playlist *, struct file *, unsigned int);
void playlist_generic_save(struct playlist *, struct data_file *, unsigned int);
/* Generic playlist load function. */
void playlist_generic_load(struct playlist *, struct file *, unsigned int);
void playlist_generic_load(struct playlist *, struct data_file *, unsigned int);
/* Generic playlist can-select function. */
bool playlist_generic_can_select(struct playlist *);

View File

@ -44,16 +44,16 @@ static gchar *int_key(struct db_entry *dbe)
return g_strdup_printf("%u", INT_ENTRY(dbe)->ie_val);
}
static struct db_entry *int_read(struct file *f, unsigned int index)
static struct db_entry *int_read(struct data_file *f, unsigned int index)
{
unsigned int val;
file_readf(f, "%u", &val);
data_file_readf(f, "%u", &val);
return &__int_alloc(val)->ie_dbe;
}
static void int_write(struct file *file, struct db_entry *dbe)
static void int_write(struct data_file *file, struct db_entry *dbe)
{
file_writef(file, "%u", INT_ENTRY(dbe)->ie_val);
data_file_writef(file, "%u", INT_ENTRY(dbe)->ie_val);
}
static const struct db_ops int_ops = {
@ -68,7 +68,7 @@ static const struct db_ops int_ops = {
static void test_db_entry()
{
struct int_entry *ent;
struct file f;
struct data_file f;
ent = INT_ENTRY(int_ops.dbe_alloc("1", 0));
g_assert_cmpuint(ent->ie_dbe.dbe_index, ==, 0);
@ -76,17 +76,17 @@ static void test_db_entry()
g_assert_cmpuint(ent->ie_val, ==, 1);
g_assert_cmpstr_free(int_ops.dbe_key(&ent->ie_dbe), ==, "1");
file_init(&f, "test_db_entry", 0);
file_open(&f, OPEN_WRITE);
data_file_init(&f, "test_db_entry", 0);
data_file_open(&f, OPEN_WRITE);
int_ops.dbe_write(&f, &ent->ie_dbe);
file_close(&f);
data_file_close(&f);
int_ops.dbe_free(&ent->ie_dbe);
g_assert_cmpuint(test_free_count, ==, 1);
file_open(&f, OPEN_READ);
data_file_open(&f, OPEN_READ);
ent = INT_ENTRY(int_ops.dbe_read(&f, 0));
file_close(&f);
data_file_close(&f);
g_assert(ent->ie_dbe.dbe_data == ent);
g_assert_cmpuint(ent->ie_val, ==, 1);

View File

@ -16,11 +16,11 @@ void test_date()
.d_month = 0,
.d_day = 0,
};
struct file f = FILE_INIT("date", 0);
struct data_file f = DATA_FILE_INIT("date", 0);
date_today(NULL);
date_set(NULL, 0, 0, 0);
file_open(&f, OPEN_WRITE);
data_file_open(&f, OPEN_WRITE);
date_set(&date, 1988, 6, 17);
g_assert_cmpuint(date.d_year, ==, 1988);
@ -28,21 +28,21 @@ void test_date()
g_assert_cmpuint(date.d_day, ==, 17);
g_assert_cmpuint(date.d_stamp, ==, 285607876);
date_write(&f, &date);
file_writef(&f, "\n");
data_file_writef(&f, "\n");
date_today(&date);
g_assert_cmpuint(date.d_year, ==, today->tm_year + 1900);
g_assert_cmpuint(date.d_month, ==, today->tm_mon + 1);
g_assert_cmpuint(date.d_day, ==, today->tm_mday);
date_write(&f, &date);
file_writef(&f, "\n");
data_file_writef(&f, "\n");
date_set(&date, 1992, 10, 05);
g_assert_cmpuint(date.d_stamp, ==, 84543432);
date_write_stamp(&f, &date);
file_close(&f);
file_open(&f, OPEN_READ);
data_file_close(&f);
data_file_open(&f, OPEN_READ);
date_read(&f, &date);
g_assert_cmpuint(date.d_year, ==, 1988);
@ -61,7 +61,7 @@ void test_date()
g_assert_cmpuint(date.d_year, ==, 1992);
g_assert_cmpuint(date.d_month, ==, 10);
g_assert_cmpuint(date.d_day, ==, 5);
file_close(&f);
data_file_close(&f);
}
void test_compare()

View File

@ -7,34 +7,34 @@
#include <stdlib.h>
static void test_verify_constructor(struct file *file, gchar *fpath, gchar *ftmp)
static void test_verify_constructor(struct data_file *file, gchar *fpath, gchar *ftmp)
{
g_assert_null(file->f_file);
g_assert_cmpuint(file_version(file), ==, OCARINA_MINOR_VERSION);
g_assert_cmpuint(data_file_version(file), ==, OCARINA_MINOR_VERSION);
g_assert_cmpuint(file->f_mode, ==, OPEN_READ);
g_assert_cmpstr_free(file_path(file), ==, fpath);
g_assert_cmpstr_free(file_write_path(file), ==, ftmp);
g_assert_cmpstr_free(data_file_path(file), ==, fpath);
g_assert_cmpstr_free(data_file_write_path(file), ==, ftmp);
}
static void test_invalid_file(gconstpointer path)
{
struct file file;
struct data_file file;
file_init(&file, (gchar *)path, 0);
data_file_init(&file, (gchar *)path, 0);
test_verify_constructor(&file, "", "");
g_assert_false(file_open(&file, OPEN_READ));
g_assert_false(data_file_open(&file, OPEN_READ));
g_assert_null(file.f_file);
g_assert_false(file_open(&file, OPEN_WRITE));
g_assert_false(data_file_open(&file, OPEN_WRITE));
g_assert_null(file.f_file);
g_assert_cmpuint(file.f_mode, ==, OPEN_READ);
g_assert_false(file_exists(&file));
g_assert_false(data_file_exists(&file));
}
static void __test_file_subprocess()
{
struct file file = FILE_INIT("file.txt", 0);
struct data_file file = DATA_FILE_INIT("file.txt", 0);
gchar *basepath, *filepath, *realpath;
basepath = g_strjoin("/", g_get_user_data_dir(), OCARINA_NAME, NULL);
@ -42,36 +42,36 @@ static void __test_file_subprocess()
realpath = g_strjoin("/", basepath, ".file.txt.tmp", NULL);
test_verify_constructor(&file, filepath, realpath);
g_assert_false(file_exists(&file));
g_assert_false(data_file_exists(&file));
g_assert_false(file_open(&file, OPEN_READ));
g_assert_true(file_open(&file, OPEN_WRITE));
g_assert_false(data_file_open(&file, OPEN_READ));
g_assert_true(data_file_open(&file, OPEN_WRITE));
g_assert_nonnull(file.f_file);
g_assert_cmpuint(file.f_mode, ==, OPEN_WRITE);
g_assert_false(file_open(&file, OPEN_WRITE));
g_assert_false(data_file_open(&file, OPEN_WRITE));
g_assert_false(file_exists(&file));
file_close(&file);
g_assert_false(data_file_exists(&file));
data_file_close(&file);
g_assert_null(file.f_file);
g_assert_cmpuint(file.f_mode, ==, OPEN_WRITE);
g_assert_true(file_exists(&file));
g_assert_true(data_file_exists(&file));
g_chmod(filepath, 0444);
g_assert_false(file_open(&file, OPEN_WRITE));
g_assert_false(data_file_open(&file, OPEN_WRITE));
g_chmod(filepath, 0200);
g_assert_false(file_open(&file, OPEN_READ));
g_assert_false(data_file_open(&file, OPEN_READ));
g_chmod(filepath, 0644);
g_assert_true(file_open(&file, OPEN_READ));
g_assert_true(data_file_open(&file, OPEN_READ));
g_assert_nonnull(file.f_file);
g_assert_cmpuint(file.f_mode, ==, OPEN_READ);
g_assert_false(file_open(&file, OPEN_READ));
g_assert_false(data_file_open(&file, OPEN_READ));
g_assert_false(file_remove(&file));
g_assert_true(file_exists(&file));
file_close(&file);
g_assert_true(file_remove(&file));
g_assert_false(file_exists(&file));
g_assert_false(data_file_remove(&file));
g_assert_true(data_file_exists(&file));
data_file_close(&file);
g_assert_true(data_file_remove(&file));
g_assert_false(data_file_exists(&file));
g_free(filepath);
}
@ -90,58 +90,58 @@ static void test_file()
static void test_io()
{
struct file fout = FILE_INIT("file.txt", 0);
struct file fin = FILE_INIT("file.txt", 1);
struct data_file fout = DATA_FILE_INIT("file.txt", 0);
struct data_file fin = DATA_FILE_INIT("file.txt", 1);
char *res = NULL;
unsigned int i;
fout.f_version = 1;
g_assert_true(file_open(&fout, OPEN_WRITE));
file_writef(&fout, "1 ABCDE\n");
file_writef(&fout, "2 FGHIJ KLMNO\n");
file_writef(&fout, "3 \n");
file_writef(&fout, "4 5 PQRST\n");
file_close(&fout);
g_assert_true(file_exists(&fout));
g_assert_true(data_file_open(&fout, OPEN_WRITE));
data_file_writef(&fout, "1 ABCDE\n");
data_file_writef(&fout, "2 FGHIJ KLMNO\n");
data_file_writef(&fout, "3 \n");
data_file_writef(&fout, "4 5 PQRST\n");
data_file_close(&fout);
g_assert_true(data_file_exists(&fout));
g_assert_true(file_open(&fin, OPEN_READ));
g_assert_cmpuint(file_version(&fin), ==, 1);
g_assert_true(data_file_open(&fin, OPEN_READ));
g_assert_cmpuint(data_file_version(&fin), ==, 1);
g_assert_cmpuint(file_readf(&fin, "%u %ms\n", &i, &res), ==, 2);
g_assert_cmpuint(data_file_readf(&fin, "%u %ms\n", &i, &res), ==, 2);
g_assert_cmpuint(i, ==, 1);
g_assert_cmpstr_free(res, ==, "ABCDE");
g_assert_cmpuint(file_readf(&fin, "%u %m[^\n]\n", &i, &res), ==, 2);
g_assert_cmpuint(data_file_readf(&fin, "%u %m[^\n]\n", &i, &res), ==, 2);
g_assert_cmpuint(i, ==, 2);
g_assert_cmpstr_free(res, ==, "FGHIJ KLMNO");
g_assert_cmpuint(file_readf(&fin, "%u", &i), ==, 1);
res = file_readl(&fin);
g_assert_cmpuint(data_file_readf(&fin, "%u", &i), ==, 1);
res = data_file_readl(&fin);
g_assert_cmpuint(i, ==, 3);
g_assert_cmpstr_free(res, ==, "");
g_assert_cmpuint(file_readf(&fin, "%u %m[^\n]", &i, &res), ==, 2);
g_assert_cmpuint(data_file_readf(&fin, "%u %m[^\n]", &i, &res), ==, 2);
g_assert_cmpuint(i, ==, 4);
g_assert_cmpstr_free(res, ==, "5 PQRST");
file_close(&fin);
g_assert_cmpuint(file_version(&fin), ==, OCARINA_MINOR_VERSION);
data_file_close(&fin);
g_assert_cmpuint(data_file_version(&fin), ==, OCARINA_MINOR_VERSION);
}
static void __test_versioning_subprocess(unsigned int out, unsigned int in)
{
struct file fout = FILE_INIT("file.txt", out);
struct file fin = FILE_INIT("file.txt", in);
struct data_file fout = DATA_FILE_INIT("file.txt", out);
struct data_file fin = DATA_FILE_INIT("file.txt", in);
fout.f_version = out;
fin.f_version = in;
g_assert_true(file_open(&fout, OPEN_WRITE));
file_writef(&fout, "abcdefghijklmnopqrstuvwxyz");
file_close(&fout);
g_assert_true(file_exists(&fout));
g_assert_true(data_file_open(&fout, OPEN_WRITE));
data_file_writef(&fout, "abcdefghijklmnopqrstuvwxyz");
data_file_close(&fout);
g_assert_true(data_file_exists(&fout));
g_assert_false(file_open(&fin, OPEN_READ));
g_assert_false(data_file_open(&fin, OPEN_READ));
g_assert_null(fin.f_file);
}

View File

@ -329,7 +329,7 @@ static void test_save_load()
struct playlist q = DEFINE_PLAYLIST(PL_MAX_TYPE, "Test 2", 0, NULL);
struct playlist r = DEFINE_PLAYLIST(PL_MAX_TYPE, "Test", 0, &test_ops);
struct playlist s = DEFINE_PLAYLIST(PL_MAX_TYPE, "Test 2", 0, NULL);
struct file f = FILE_INIT("test.playlist", 0);
struct data_file f = DATA_FILE_INIT("test.playlist", 0);
unsigned int i;
for (i = 0; i < 13; i++) {
@ -343,16 +343,16 @@ static void test_save_load()
playlist_current_set(&p, 3);
playlist_current_set(&q, 4);
g_assert_false(file_exists(&f));
g_assert_true( file_open(&f, OPEN_WRITE));
g_assert_false(data_file_exists(&f));
g_assert_true( data_file_open(&f, OPEN_WRITE));
playlist_generic_save(&p, &f, PL_SAVE_METADATA);
playlist_generic_save(&q, &f, PL_SAVE_ALL);
file_close(&f);
data_file_close(&f);
g_assert_true(file_open(&f, OPEN_READ));
g_assert_true(data_file_open(&f, OPEN_READ));
playlist_generic_load(&r, &f, PL_SAVE_METADATA);
playlist_generic_load(&s, &f, PL_SAVE_ALL);
file_close(&f);
data_file_close(&f);
g_assert_true(r.pl_random);
g_assert_cmpuint(playlist_current_index(&r), ==, 3);

View File

@ -7,7 +7,7 @@
static void test_settings()
{
struct file f = FILE_INIT("settings", 0);
struct data_file f = DATA_FILE_INIT("settings", 0);
settings_set(NULL, 0);
g_assert_cmpuint(settings_get(NULL), ==, 0);
@ -19,7 +19,7 @@ static void test_settings()
g_assert_false(settings_has("test.value1"));
g_assert_cmpuint(settings_get("test.value1"), ==, 0);
g_assert_cmpuint(settings_get("test.value2"), ==, 0);
g_assert_false(file_exists(&f));
g_assert_false(data_file_exists(&f));
settings_init();
g_assert_nonnull(test_get_settings());
@ -27,7 +27,7 @@ static void test_settings()
settings_set("test.value1", 42);
g_assert_true(settings_has("test.value1"));
g_assert_false(settings_has("test.value2"));
g_assert_true(file_exists(&f));
g_assert_true(data_file_exists(&f));
settings_set("test.value2", 84);
g_assert_true(settings_has("test.value2"));
g_assert_cmpuint(settings_get("test.value1"), ==, 42);
@ -41,7 +41,7 @@ static void test_settings()
g_assert_cmpuint(settings_get("test.value2"), ==, 0);
g_assert_false(settings_has("test.value1"));
g_assert_false(settings_has("test.value2"));
g_assert_true(file_exists(&f));
g_assert_true(data_file_exists(&f));
settings_init();
g_assert_nonnull(test_get_settings());

View File

@ -46,7 +46,7 @@ static void test_album()
struct album *album;
struct artist *koji;
struct genre *genre;
struct file f;
struct data_file f;
idle_init(IDLE_SYNC);
@ -58,20 +58,20 @@ static void test_album()
g_assert_true( album_match_token(album, "symphony"));
g_assert_false(album_match_token(album, "skyward"));
file_init(&f, "album_tag", 1);
file_open(&f, OPEN_WRITE);
file_writef(&f, "0 0 0 \n");
data_file_init(&f, "album_tag", 1);
data_file_open(&f, OPEN_WRITE);
data_file_writef(&f, "0 0 0 \n");
album_ops->dbe_write(&f, &album->al_dbe);
file_close(&f);
data_file_close(&f);
album_ops->dbe_free(&album->al_dbe);
file_open(&f, OPEN_READ);
data_file_open(&f, OPEN_READ);
album = ALBUM(album_ops->dbe_read(&f, 0));
test_verify_empty(album);
album_ops->dbe_free(&album->al_dbe);
album = ALBUM(album_ops->dbe_read(&f, 0));
file_close(&f);
data_file_close(&f);
test_verify_hyrule(album, koji, genre);
album_ops->dbe_free(&album->al_dbe);
}

View File

@ -31,7 +31,7 @@ static void test_artist()
const struct db_ops *artist_ops = test_artist_ops();
struct artist *artist;
unsigned int i;
struct file f;
struct data_file f;
artist = ARTIST(artist_ops->dbe_alloc("Koji Kondo", 0));
@ -40,24 +40,24 @@ static void test_artist()
g_assert_true( artist_match_token(artist, "kondo"));
g_assert_false(artist_match_token(artist, "hajime"));
file_init(&f, "artist_tag", 0);
file_open(&f, OPEN_WRITE);
file_writef(&f, "1 \n2 ");
data_file_init(&f, "artist_tag", 0);
data_file_open(&f, OPEN_WRITE);
data_file_writef(&f, "1 \n2 ");
artist_ops->dbe_write(&f, &artist->ar_dbe);
file_close(&f);
data_file_close(&f);
g_free(artist->ar_name);
artist_ops->dbe_free(&artist->ar_dbe);
file_open(&f, OPEN_READ);
file_readf(&f, "%u", &i);
data_file_open(&f, OPEN_READ);
data_file_readf(&f, "%u", &i);
artist = ARTIST(artist_ops->dbe_read(&f, 0));
test_verify_empty(artist);
g_free(artist->ar_name);
artist_ops->dbe_free(&artist->ar_dbe);
file_readf(&f, "%u", &i);
data_file_readf(&f, "%u", &i);
artist = ARTIST(artist_ops->dbe_read(&f, 0));
file_close(&f);
data_file_close(&f);
test_verify_koji(artist);
g_free(artist->ar_name);
artist_ops->dbe_free(&artist->ar_dbe);

View File

@ -30,7 +30,7 @@ static void test_genre()
const struct db_ops *genre_ops = test_genre_ops();
struct genre *genre;
unsigned int i;
struct file f;
struct data_file f;
genre = GENRE(genre_ops->dbe_alloc("Video Game Music", 0));
test_verify_vg(genre);
@ -38,24 +38,24 @@ static void test_genre()
g_assert_true( genre_match_token(genre, "music"));
g_assert_false(genre_match_token(genre, "rock"));
file_init(&f, "genre_tag", 0);
file_open(&f, OPEN_WRITE);
file_writef(&f, "1 \n1 ");
data_file_init(&f, "genre_tag", 0);
data_file_open(&f, OPEN_WRITE);
data_file_writef(&f, "1 \n1 ");
genre_ops->dbe_write(&f, &genre->ge_dbe);
file_close(&f);
data_file_close(&f);
g_free(genre->ge_name);
genre_ops->dbe_free(&genre->ge_dbe);
file_open(&f, OPEN_READ);
file_readf(&f, "%u", &i);
data_file_open(&f, OPEN_READ);
data_file_readf(&f, "%u", &i);
genre = GENRE(genre_ops->dbe_read(&f, 0));
test_verify_empty(genre);
g_free(genre->ge_name);
genre_ops->dbe_free(&genre->ge_dbe);
file_readf(&f, "%u", &i);
data_file_readf(&f, "%u", &i);
genre = GENRE(genre_ops->dbe_read(&f, 0));
file_close(&f);
data_file_close(&f);
test_verify_vg(genre);
g_free(genre->ge_name);
genre_ops->dbe_free(&genre->ge_dbe);

View File

@ -22,7 +22,7 @@ static void test_library()
{
const struct db_ops *library_ops = test_library_ops();
struct library *link, *zelda, *library;
struct file f;
struct data_file f;
link = LIBRARY(library_ops->dbe_alloc("/home/Link/Music", 0));
zelda = LIBRARY(library_ops->dbe_alloc("/home/Zelda/Music", 0));
@ -30,14 +30,14 @@ static void test_library()
test_verify_link(link);
test_verify_zelda(zelda);
file_init(&f, "library_tag", 0);
file_open(&f, OPEN_WRITE);
data_file_init(&f, "library_tag", 0);
data_file_open(&f, OPEN_WRITE);
library_ops->dbe_write(&f, &link->li_dbe);
file_writef(&f, "\n");
data_file_writef(&f, "\n");
library_ops->dbe_write(&f, &zelda->li_dbe);
file_close(&f);
data_file_close(&f);
file_open(&f, OPEN_READ);
data_file_open(&f, OPEN_READ);
library = LIBRARY(library_ops->dbe_read(&f, 0));
test_verify_link(library);
g_assert_cmpstr_free(library_file(library, "navi.mp3"), ==,
@ -46,7 +46,7 @@ static void test_library()
library_ops->dbe_free(&library->li_dbe);
library = LIBRARY(library_ops->dbe_read(&f, 0));
file_close(&f);
data_file_close(&f);
test_verify_zelda(library);
g_assert_cmpstr_free(library_file(library, "impa.ogg"), ==,
"/home/Zelda/Music/impa.ogg");

View File

@ -83,10 +83,10 @@ static void test_track()
time_t rawtime = time(NULL);
struct tm *now = localtime(&rawtime);
struct track *track;
struct file f;
struct data_file f;
gchar *date;
file_init(&f, "track_tag", 1);
data_file_init(&f, "track_tag", 1);
g_assert_nonnull(library_find("tests/Music"));
date = string_tm2str(now);
@ -99,16 +99,16 @@ static void test_track()
g_assert_true( track_match_token(track, "theme"));
g_assert_false(track_match_token(track, "hyrule"));
file_open(&f, OPEN_WRITE);
file_writef(&f, "0 0 0 0 0 0 \n");
file_writef(&f, "Hyrule Symphony/00 - No Track.ogg\n");
data_file_open(&f, OPEN_WRITE);
data_file_writef(&f, "0 0 0 0 0 0 \n");
data_file_writef(&f, "Hyrule Symphony/00 - No Track.ogg\n");
track_ops->dbe_write(&f, &track->tr_dbe);
file_close(&f);
data_file_close(&f);
g_free(track->tr_path);
track_ops->dbe_free(&track->tr_dbe);
file_open(&f, OPEN_READ);
data_file_open(&f, OPEN_READ);
track = TRACK(track_ops->dbe_read(&f, 0));
track->tr_dbe.dbe_index = 0;
test_verify_notrack(track);
@ -119,7 +119,7 @@ static void test_track()
track = TRACK(track_ops->dbe_read(&f, 0));
track->tr_dbe.dbe_index = 0;
test_verify_track(track, false);
file_close(&f);
data_file_close(&f);
track_played(track);
g_assert_cmpuint(track->tr_count, ==, 1);