Skip to content

Commit

Permalink
Copy default database containing JMDict if none existing
Browse files Browse the repository at this point in the history
Also use proper location for extra files
  • Loading branch information
btrkeks committed Jun 11, 2024
1 parent 935f21c commit 2b713a8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} -fsanitize=address,undefined -fsanitize-undefined-trap-on-error -fstack-protector-strong")
else ()
add_compile_options(-Ofast -flto -march=native -g)
add_compile_options(-Ofast -flto -march=native -mtune=native -g)
endif ()

add_definitions(${GTK3_CFLAGS_OTHER} ${NOTIFY_CFLAGS_OTHER}
Expand Down Expand Up @@ -117,7 +117,8 @@ endif ()
# Install
# ##############################################################################
install(TARGETS dictpopup dictpopup-create DESTINATION bin)
install(FILES config.ini DESTINATION share)
install(FILES config.ini DESTINATION share/dictpopup)
install(FILES data.mdb DESTINATION share/dictpopup)
install(
DIRECTORY man1/
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1
Expand Down
Binary file modified data.mdb
Binary file not shown.
25 changes: 25 additions & 0 deletions src/dictpopup.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "settings.h"
#include "util.h"

#include <gio/gio.h>

// This only applies for substring search
// 60 are 20 Japanese characters
#define MAX_LOOKUP_LEN 60 // in bytes
Expand Down Expand Up @@ -180,11 +182,34 @@ static s8 convert_to_utf8(char *str) {
return ret;
}

static void copy_default_database(char *dbdir) {
// TODO: Make default loc OS independent
const char *default_database_location = "/usr/local/share/dictpopup/data.mdb";
die_on(!check_file_exists(default_database_location),
"Could not access the default database either. You need to create your own with"
"dictpopup-create or download data.mdb from the repository.");

_drop_(frees8) s8 dbpath = buildpath(fromcstr_(dbdir), S("data.mdb"));
createdir(dbdir);

GFile *source = g_file_new_for_path(default_database_location);
GFile *dest = g_file_new_for_path((char*)dbpath.s);
g_file_copy(source, dest, G_FILE_COPY_NONE, NULL, NULL, NULL, NULL);
g_object_unref(source);
g_object_unref(dest);
}

dictpopup_t dictpopup_init(int argc, char **argv) {
setlocale(LC_ALL, "");
read_user_settings(POSSIBLE_ENTRIES_S_NMEMB);
int nextarg = parse_cmd_line_opts(argc, argv); // Should be second to overwrite settings

if(!db_check_exists(fromcstr_(cfg.general.dbpth))) {
msg("No database found. We recommend creating your own database with dictpopup-create, but "
"copying default dictionary for now..");
copy_default_database(cfg.general.dbpth);
}

possible_entries_s p = {0};

p.windowname = get_windowname();
Expand Down

0 comments on commit 2b713a8

Please sign in to comment.