|
|
@@ -0,0 +1,38 @@ |
|
|
|
#include "IZ_repo.h" |
|
|
|
|
|
|
|
void IZ_RepoLoadConfig(IZ_RepoState* state, const char* config_path) { |
|
|
|
char buffer[64]; |
|
|
|
|
|
|
|
ini_gets("Database", "Path", IZ_REPO_DEFAULT_STATE.config.path, buffer, 64, config_path); |
|
|
|
memcpy_s(state->config.path, 64, buffer, 64); |
|
|
|
} |
|
|
|
|
|
|
|
IZ_ProcedureResult IZ_RepoSaveConfig(IZ_RepoState* state, const char* config_path) { |
|
|
|
if (!ini_puts("Database", "Path", state->config.path, config_path)) { |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
void IZ_RepoOverrideConfig(IZ_RepoState* state, u8 argc, const char* argv[]) { |
|
|
|
const char* cmdline_buffer; |
|
|
|
if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-n"))) { |
|
|
|
memcpy_s(state->config.path, 64, cmdline_buffer, 64); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
IZ_ProcedureResult IZ_RepoInitialize(IZ_RepoState* state, const char* config_path, u8 argc, const char* argv[]) { |
|
|
|
memcpy_s(state, sizeof(IZ_RepoState), &IZ_REPO_DEFAULT_STATE, sizeof(IZ_RepoState)); |
|
|
|
IZ_RepoLoadConfig(state, config_path); |
|
|
|
if (IZ_RepoSaveConfig(state, config_path)) { |
|
|
|
return -1; |
|
|
|
} |
|
|
|
IZ_RepoOverrideConfig(state, argc, argv); |
|
|
|
sqlite3_open_v2(state->config.path, &state->db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
void IZ_RepoTeardown(IZ_RepoState* state) { |
|
|
|
sqlite3_close_v2(state->db); |
|
|
|
} |