diff --git a/core/audio.c b/core/audio.c index 0d7a08c5..edcbe2f6 100644 --- a/core/audio.c +++ b/core/audio.c @@ -8,7 +8,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, 0); +static struct file audio_file = FILE_INIT("cur_track", 0); static struct track *audio_track = NULL; static GstElement *audio_player = NULL; static struct audio_ops *audio_ops = NULL; diff --git a/core/database.c b/core/database.c index 20fe3474..b0ee8d4a 100644 --- a/core/database.c +++ b/core/database.c @@ -71,14 +71,14 @@ static void __dbe_write(struct database *db, struct db_entry *dbe) } void db_init(struct database *db, const char *filepath, bool autosave, - const struct db_ops *ops, unsigned int fmin, unsigned int fcur) + const struct db_ops *ops, unsigned int fmin) { db->db_ops = ops; db->db_size = 0; 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, fcur, fmin); + file_init(&db->db_file, filepath, fmin); } void db_deinit(struct database *db) diff --git a/core/file.c b/core/file.c index f23b8f66..19c5dd2e 100644 --- a/core/file.c +++ b/core/file.c @@ -94,11 +94,10 @@ static bool __file_can_write(struct file *file) } -void file_init(struct file *file, const gchar *name, - unsigned int version, unsigned int min) +void file_init(struct file *file, const gchar *name, unsigned int min) { file->f_mode = OPEN_READ; - file->f_version = version; + file->f_version = OCARINA_MINOR_VERSION; file->f_prev = 0; file->f_min = min; file->f_file = NULL; diff --git a/core/playlists/artist.c b/core/playlists/artist.c index dd1edafc..3ba1c303 100644 --- a/core/playlists/artist.c +++ b/core/playlists/artist.c @@ -6,7 +6,7 @@ #include static struct queue_ops *artist_ops = NULL; -static struct file artist_file = FILE_INIT("playlist.artist", 0, 0); +static struct file artist_file = FILE_INIT("playlist.artist", 0); static struct playlist *__artist_pl_alloc(gchar *name) diff --git a/core/playlists/library.c b/core/playlists/library.c index 3a3bc4f0..515ac4c6 100644 --- a/core/playlists/library.c +++ b/core/playlists/library.c @@ -14,7 +14,7 @@ struct scan_data { static bool __lib_pl_scan_dir(void *); static struct queue_ops *lib_ops = NULL; -static struct file lib_file = FILE_INIT("playlist.library", 0, 0); +static struct file lib_file = FILE_INIT("playlist.library", 0); static struct playlist *__lib_pl_alloc(struct library *library) diff --git a/core/playlists/system.c b/core/playlists/system.c index 0e836626..5a94721c 100644 --- a/core/playlists/system.c +++ b/core/playlists/system.c @@ -12,10 +12,10 @@ static inline struct queue *__sys_pl_queue(enum sys_playlist_t); static void __sys_pl_save(); static bool __sys_pl_load(); -static struct file sys_file = FILE_INIT("playlist.db", 0, 0); -static struct file sys_deck_f = FILE_INIT("deck", 1, 1); -static struct file sys_collection_f = FILE_INIT("library.q", 0, 0); -static struct file sys_pl_file = FILE_INIT("playlist.system", 0, 0); +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 sys_playlist *sys_playlists[SYS_PL_NUM_PLAYLISTS]; diff --git a/core/playlists/user.c b/core/playlists/user.c index a3927125..8d6d3ba8 100644 --- a/core/playlists/user.c +++ b/core/playlists/user.c @@ -195,7 +195,7 @@ struct playlist_type pl_user = { void pl_user_init(struct queue_ops *ops) { user_pl_ops = ops; - db_init(&user_db, "playlist.user", true, &user_db_ops, 0, 0); + db_init(&user_db, "playlist.user", true, &user_db_ops, 0); db_load_idle(&user_db); } diff --git a/core/settings.c b/core/settings.c index 0d5504d2..5c542ff2 100644 --- a/core/settings.c +++ b/core/settings.c @@ -5,7 +5,7 @@ #include static GHashTable *gui_settings = NULL; -static struct file gui_settings_file = FILE_INIT("settings", 0, 0); +static struct file gui_settings_file = FILE_INIT("settings", 0); static void __settings_save_item(gpointer key, gpointer value, gpointer data) diff --git a/core/tags/album.c b/core/tags/album.c index 86742de9..6eeb909f 100644 --- a/core/tags/album.c +++ b/core/tags/album.c @@ -16,7 +16,6 @@ #endif #define ALBUM_DB_MIN 0 /* Ocarina 6.0 */ -#define ALBUM_DB_CUR 1 /* Ocarina 6.5 */ static struct database album_db; static bool album_db_upgraded = false; @@ -290,8 +289,7 @@ static const struct db_ops album_ops = { void album_db_init() { - db_init(&album_db, "album.db", true, &album_ops, ALBUM_DB_MIN, - ALBUM_DB_CUR); + db_init(&album_db, "album.db", true, &album_ops, ALBUM_DB_MIN); db_load_idle(&album_db); } diff --git a/core/tags/artist.c b/core/tags/artist.c index 838e2695..3ac0d4d0 100644 --- a/core/tags/artist.c +++ b/core/tags/artist.c @@ -60,7 +60,7 @@ static const struct db_ops artist_ops = { void artist_db_init() { - db_init(&artist_db, "artist.db", true, &artist_ops, 0, 0); + db_init(&artist_db, "artist.db", true, &artist_ops, 0); db_load_idle(&artist_db); } diff --git a/core/tags/genre.c b/core/tags/genre.c index 2d689ba6..08ea1cd3 100644 --- a/core/tags/genre.c +++ b/core/tags/genre.c @@ -58,7 +58,7 @@ static const struct db_ops genre_ops = { void genre_db_init() { - db_init(&genre_db, "genre.db", true, &genre_ops, 0, 0); + db_init(&genre_db, "genre.db", true, &genre_ops, 0); db_load_idle(&genre_db); } diff --git a/core/tags/library.c b/core/tags/library.c index f755a88f..54608459 100644 --- a/core/tags/library.c +++ b/core/tags/library.c @@ -4,7 +4,6 @@ #include #define LIBRARY_DB_MIN 0 /* Ocarina 6.0 */ -#define LIBRARY_DB_CUR 1 /* Ocarina 6.5 */ static struct database library_db; static struct library *__library_alloc(gchar *path) @@ -63,8 +62,7 @@ static const struct db_ops library_ops = { void library_db_init() { - db_init(&library_db, "library.db", true, &library_ops, LIBRARY_DB_MIN, - LIBRARY_DB_CUR); + db_init(&library_db, "library.db", true, &library_ops, LIBRARY_DB_MIN); db_load_idle(&library_db); } diff --git a/core/tags/track.c b/core/tags/track.c index 3528817d..50ddaa9b 100644 --- a/core/tags/track.c +++ b/core/tags/track.c @@ -8,7 +8,6 @@ #include #define TRACK_DB_MIN 0 /* Ocarina 6.0 */ -#define TRACK_DB_CUR 1 /* Ocarina 6.5 */ static struct database track_db; static unsigned int unplayed_count = 0; static unsigned int play_count = 0; @@ -197,8 +196,7 @@ static const struct db_ops track_ops = { void track_db_init() { - db_init(&track_db, "track.db", false, &track_ops, TRACK_DB_MIN, - TRACK_DB_CUR); + db_init(&track_db, "track.db", false, &track_ops, TRACK_DB_MIN); db_load_idle(&track_db); } diff --git a/include/core/database.h b/include/core/database.h index 0672bc1f..3b43c42c 100644 --- a/include/core/database.h +++ b/include/core/database.h @@ -77,11 +77,11 @@ struct database { const struct db_ops *db_ops; /* The database's operations vector. */ }; -#define DB_INIT(fname, autosave, ops, fmin, fcur) \ +#define DB_INIT(fname, autosave, ops, fmin) \ { \ .db_size = 0, \ .db_autosave = autosave, \ - .db_file = FILE_INIT(fname, fcur, fmin), \ + .db_file = 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, \ @@ -93,7 +93,7 @@ struct database { * and autosave as a hint for if this database should be automatically saved. */ void db_init(struct database *, const char *, bool, const struct db_ops *, - unsigned int, unsigned int); + unsigned int); /* Called to prevent memory leaks by freeing all remaining database entries. */ void db_deinit(struct database *); diff --git a/include/core/file.h b/include/core/file.h index 4b327e14..2aa61051 100644 --- a/include/core/file.h +++ b/include/core/file.h @@ -23,6 +23,7 @@ #ifndef OCARINA_CORE_FILE_H #define OCARINA_CORE_FILE_H +#include #include #include #include @@ -42,14 +43,14 @@ struct file { const gchar *f_name; /* The file's basename. */ }; -#define FILE_INIT(fname, version, min) \ - { \ - .f_mode = OPEN_READ, \ - .f_version = version, \ - .f_prev = 0, \ - .f_min = min, \ - .f_file = NULL, \ - .f_name = fname, \ +#define FILE_INIT(fname, min) \ + { \ + .f_mode = OPEN_READ, \ + .f_version = OCARINA_MINOR_VERSION, \ + .f_prev = 0, \ + .f_min = min, \ + .f_file = NULL, \ + .f_name = fname, \ } @@ -67,7 +68,7 @@ struct cache_file { } /* Initialize a new file object. */ -void file_init(struct file *, const gchar *, unsigned int, unsigned int); +void file_init(struct file *, const gchar *, unsigned int); void cache_file_init(struct cache_file *, gchar *, gchar *); /* diff --git a/tests/core/database.c b/tests/core/database.c index 691674b2..9a107866 100644 --- a/tests/core/database.c +++ b/tests/core/database.c @@ -83,7 +83,7 @@ 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, 0); + file_init(&f, "test_db_entry", 0); file_open(&f, OPEN_WRITE); int_ops.dbe_write(&f, &ent->ie_dbe); file_close(&f); @@ -107,14 +107,14 @@ static void test_db_entry() static void test_init() { - struct database db = DB_INIT("init.db", false, &int_ops, 0, 0); + struct database db = DB_INIT("init.db", false, &int_ops, 0); /* Check initial sizes. */ g_assert_cmpuint(db.db_entries->len, ==, 0); g_assert_cmpuint(g_hash_table_size(db.db_keys), ==, 0); g_assert_cmpuint(db.db_size, ==, 0); g_assert_false(db.db_autosave); - g_assert_cmpuint(db.db_file.f_version, ==, 0); + g_assert_cmpuint(db.db_file.f_version, ==, OCARINA_MINOR_VERSION); g_assert_cmpstr(db.db_file.f_name, ==, "init.db"); db_deinit(&db); @@ -123,7 +123,7 @@ static void test_init() static void test_database(gconstpointer arg) { unsigned int N = GPOINTER_TO_UINT(arg); - struct database db = DB_INIT("stress.db", false, &int_ops, 0, 0); + struct database db = DB_INIT("stress.db", false, &int_ops, 0); struct db_entry *dbe, *next; struct int_entry rmv; unsigned int i; @@ -241,8 +241,8 @@ static void test_database(gconstpointer arg) static void test_save_load() { - struct database db1 = DB_INIT("save_load.db", true, &int_ops, 0, 0); - struct database db2 = DB_INIT("save_load.db", false, &int_ops, 0, 0); + struct database db1 = DB_INIT("save_load.db", true, &int_ops, 0); + struct database db2 = DB_INIT("save_load.db", false, &int_ops, 0); struct db_entry *dbe, *next; const unsigned int N = 10; unsigned int i; diff --git a/tests/core/date.c b/tests/core/date.c index 332115a3..3b830f78 100644 --- a/tests/core/date.c +++ b/tests/core/date.c @@ -16,7 +16,7 @@ void test_date() .d_month = 0, .d_day = 0, }; - struct file f = FILE_INIT("date", 0, 0); + struct file f = FILE_INIT("date", 0); date_today(NULL); date_set(NULL, 0, 0, 0); diff --git a/tests/core/file.c b/tests/core/file.c index 659550cb..7f653096 100644 --- a/tests/core/file.c +++ b/tests/core/file.c @@ -10,7 +10,7 @@ static void test_verify_constructor(struct file *file, gchar *fpath, gchar *ftmp) { g_assert_null(file->f_file); - g_assert_cmpuint(file_version(file), ==, 0); + g_assert_cmpuint(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); @@ -20,7 +20,7 @@ static void test_invalid_file(gconstpointer path) { struct file file; - file_init(&file, (gchar *)path, 0, 0); + file_init(&file, (gchar *)path, 0); test_verify_constructor(&file, "", ""); g_assert_false(file_open(&file, OPEN_READ)); @@ -34,7 +34,7 @@ static void test_invalid_file(gconstpointer path) static void __test_file_subprocess() { - struct file file = FILE_INIT("file.txt", 0, 0); + struct file file = FILE_INIT("file.txt", 0); gchar *basepath, *filepath, *realpath; basepath = g_strjoin("/", g_get_user_data_dir(), OCARINA_NAME, NULL); @@ -90,11 +90,12 @@ static void test_file() static void test_io() { - struct file fout = FILE_INIT("file.txt", 1, 1); - struct file fin = FILE_INIT("file.txt", 2, 1); + struct file fout = FILE_INIT("file.txt", 0); + struct file fin = 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"); @@ -124,13 +125,16 @@ static void test_io() g_assert_cmpstr_free(res, ==, "5 PQRST"); file_close(&fin); - g_assert_cmpuint(file_version(&fin), ==, 2); + g_assert_cmpuint(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, out); - struct file fin = FILE_INIT("file.txt", in, in); + struct file fout = FILE_INIT("file.txt", out); + struct file fin = 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"); diff --git a/tests/core/queue.c b/tests/core/queue.c index de446728..695163b6 100644 --- a/tests/core/queue.c +++ b/tests/core/queue.c @@ -455,7 +455,7 @@ static void test_sorting() static void test_save_load() { - struct file f = FILE_INIT("queue.q", 0, 0); + struct file f = FILE_INIT("queue.q", 0); struct queue q, r; unsigned int i; diff --git a/tests/core/settings.c b/tests/core/settings.c index 9f4d5d49..cc6cf551 100644 --- a/tests/core/settings.c +++ b/tests/core/settings.c @@ -7,7 +7,7 @@ static void test_settings() { - struct file f = FILE_INIT("settings", 0, 0); + struct file f = FILE_INIT("settings", 0); g_assert_null(test_get_settings()); settings_set("test.value1", 42); diff --git a/tests/core/tags/album.c b/tests/core/tags/album.c index 687c4bf1..226c47f0 100644 --- a/tests/core/tags/album.c +++ b/tests/core/tags/album.c @@ -58,7 +58,7 @@ 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, 1); + file_init(&f, "album_tag", 1); file_open(&f, OPEN_WRITE); file_writef(&f, "0 0 0 \n"); album_ops->dbe_write(&f, &album->al_dbe); @@ -117,7 +117,7 @@ static void test_album_db() g_assert(album_get(0) == album); g_assert_null(album_get(1)); - db_init(&album_db, "album.db", false, album_ops, 1, 1); + db_init(&album_db, "album.db", false, album_ops, 0); db_load(&album_db); g_assert_cmpuint(album_db.db_size, ==, 1); diff --git a/tests/core/tags/artist.c b/tests/core/tags/artist.c index 983ffb22..53b6f9a6 100644 --- a/tests/core/tags/artist.c +++ b/tests/core/tags/artist.c @@ -40,7 +40,7 @@ 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, 0); + file_init(&f, "artist_tag", 0); file_open(&f, OPEN_WRITE); file_writef(&f, "1 \n2 "); artist_ops->dbe_write(&f, &artist->ar_dbe); @@ -102,7 +102,7 @@ static void test_artist_db() g_assert(artist_get(0) == artist); g_assert_null(artist_get(1)); - db_init(&artist_db, "artist.db", false, artist_ops, 0, 0); + db_init(&artist_db, "artist.db", false, artist_ops, 0); db_load(&artist_db); g_assert_cmpuint(artist_db.db_size, ==, 1); diff --git a/tests/core/tags/genre.c b/tests/core/tags/genre.c index 79a7304d..59d6f72b 100644 --- a/tests/core/tags/genre.c +++ b/tests/core/tags/genre.c @@ -38,7 +38,7 @@ 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, 0); + file_init(&f, "genre_tag", 0); file_open(&f, OPEN_WRITE); file_writef(&f, "1 \n1 "); genre_ops->dbe_write(&f, &genre->ge_dbe); @@ -92,7 +92,7 @@ static void test_genere_db() g_assert(genre_get(0) == genre); g_assert_null(genre_get(1)); - db_init(&genre_db, "genre.db", false, genre_ops, 0, 0); + db_init(&genre_db, "genre.db", false, genre_ops, 0); db_load(&genre_db); g_assert_cmpint(genre_db.db_size, ==, 1); diff --git a/tests/core/tags/library.c b/tests/core/tags/library.c index 692d2f55..26324233 100644 --- a/tests/core/tags/library.c +++ b/tests/core/tags/library.c @@ -30,7 +30,7 @@ static void test_library() test_verify_link(link); test_verify_zelda(zelda); - file_init(&f, "library_tag", 0, 0); + file_init(&f, "library_tag", 0); file_open(&f, OPEN_WRITE); library_ops->dbe_write(&f, &link->li_dbe); file_writef(&f, "\n"); @@ -80,7 +80,7 @@ static void test_library_db() g_assert(library_get(0) == library); g_assert_null(library_get(1)); - db_init(&library_db, "library.db", false, library_ops, 1, 1); + db_init(&library_db, "library.db", false, library_ops, 1); db_load(&library_db); g_assert_cmpuint(library_db.db_size, ==, 1); g_assert_cmpuint(db_actual_size(&library_db), ==, 1); diff --git a/tests/core/tags/track.c b/tests/core/tags/track.c index be2e7bb6..f1b53deb 100644 --- a/tests/core/tags/track.c +++ b/tests/core/tags/track.c @@ -75,7 +75,7 @@ static void test_track() struct file f; gchar *date; - file_init(&f, "track_tag", 1, 1); + file_init(&f, "track_tag", 1); g_assert_nonnull(library_find("tests/Music")); date = string_tm2str(now); @@ -222,7 +222,7 @@ static void __test_track_db_subprocess() g_assert_cmpuint(track_db_get()->db_size, ==, 1); g_assert_cmpuint(track_db_count_unplayed(), ==, 1); - db_init(&track_db, "track.db", false, track_ops, 1, 1); + db_init(&track_db, "track.db", false, track_ops, 0); db_load(&track_db); g_assert_cmpuint(track_db.db_size, ==, 0);