diff options
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | data/blobs-update-version.json | 1 | ||||
-rw-r--r-- | hardinfo2/vendor.c | 11 | ||||
-rw-r--r-- | includes/syncmanager.h | 1 | ||||
-rw-r--r-- | modules/benchmark.c | 2 | ||||
-rw-r--r-- | modules/computer/modules.c | 1 | ||||
-rw-r--r-- | modules/devices.c | 6 | ||||
-rw-r--r-- | shell/syncmanager.c | 88 |
8 files changed, 81 insertions, 30 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 0dcec27e..1605819b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -231,6 +231,7 @@ set(HARDINFO2_MODULES set(HARDINFO2_RESOURCES "data/benchmark.data" "data/benchmark.json" + "data/blobs-update-version.json" "data/vendor.ids" "data/sdcard.ids" "data/usb.ids" diff --git a/data/blobs-update-version.json b/data/blobs-update-version.json new file mode 100644 index 00000000..5cf2609d --- /dev/null +++ b/data/blobs-update-version.json @@ -0,0 +1 @@ +{"update-version":"1","program-version":"0.0.0"} diff --git a/hardinfo2/vendor.c b/hardinfo2/vendor.c index fe4c1e59..2031ac44 100644 --- a/hardinfo2/vendor.c +++ b/hardinfo2/vendor.c @@ -207,16 +207,23 @@ static int read_from_vendor_ids(const char *path) { void vendor_init(void) { gchar *path; - static SyncEntry se = { + static SyncEntry se1; + static SyncEntry se2 = { .name = N_("Update vendor list"), .file_name = "vendor.ids", + .optional = TRUE, }; + se1.name = N_("Check Update Version"); + se1.file_name = g_strdup_printf("blobs-update-version.json"); + se1.optional=FALSE; + /* already initialized */ if (vendors) return; DEBUG("initializing vendor list"); - sync_manager_add_entry(&se); + sync_manager_add_entry(&se2); + sync_manager_add_entry(&se1); char *file_search_order[] = { g_build_filename(g_get_user_config_dir(), "hardinfo2", "vendor.ids", NULL), diff --git a/includes/syncmanager.h b/includes/syncmanager.h index 3b886b0f..c17601da 100644 --- a/includes/syncmanager.h +++ b/includes/syncmanager.h @@ -30,6 +30,7 @@ struct _SyncEntry { gchar *(*generate_contents_for_upload)(gsize *size); gboolean selected; + gboolean optional; }; void sync_manager_add_entry(SyncEntry *entry); diff --git a/modules/benchmark.c b/modules/benchmark.c index 018e30fe..69c6eebb 100644 --- a/modules/benchmark.c +++ b/modules/benchmark.c @@ -923,10 +923,12 @@ void hi_module_init(void) .name = N_("Send benchmark results"), .file_name = "benchmark.json", .generate_contents_for_upload = get_benchmark_results, + .optional = FALSE, }, { .name = N_("Receive benchmark results"), .file_name = "benchmark.json", + .optional = FALSE, }, }; diff --git a/modules/computer/modules.c b/modules/computer/modules.c index ae47947c..4c0c54ea 100644 --- a/modules/computer/modules.c +++ b/modules/computer/modules.c @@ -167,6 +167,7 @@ void kernel_module_icon_init(void) static SyncEntry sync_entry = { .name = N_("Update kernel module icon table"), .file_name = "kernel-module-icons.json", + .optional = TRUE, }; sync_manager_add_entry(&sync_entry); diff --git a/modules/devices.c b/modules/devices.c index dd51b482..7e9eef6d 100644 --- a/modules/devices.c +++ b/modules/devices.c @@ -840,28 +840,34 @@ void hi_module_init(void) { .name = N_("Update PCI ID listing"), .file_name = "pci.ids", + .optional = TRUE, }, { .name = N_("Update USB ID listing"), .file_name = "usb.ids", + .optional = TRUE, }, { .name = N_("Update EDID vendor codes"), .file_name = "edid.ids", + .optional = TRUE, }, { .name = N_("Update IEEE OUI vendor codes"), .file_name = "ieee_oui.ids", + .optional = TRUE, }, { .name = N_("Update SD card manufacturer information"), .file_name = "sdcard.ids", + .optional = TRUE, }, #ifdef ARCH_x86 #if JSON_CHECK_VERSION(0,20,0) { .name = N_("Update CPU flags database"), .file_name = "cpuflags.json", + .optional = TRUE, }, #endif #endif diff --git a/shell/syncmanager.c b/shell/syncmanager.c index 9f135ab3..72f3255c 100644 --- a/shell/syncmanager.c +++ b/shell/syncmanager.c @@ -25,6 +25,9 @@ #include <stdarg.h> #include <string.h> +#include <fcntl.h> +#include <stdio.h> + #ifndef SOUP_CHECK_VERSION #define SOUP_CHECK_VERSION(a,b,c) 0 @@ -63,6 +66,8 @@ static GSList *entries = NULL; static SoupSession *session = NULL; static GMainLoop *loop; static GQuark err_quark; +static guint server_blobs_update_version = 0; +static guint our_blobs_update_version = 0; //Note there are no personal information involved and very old //linux systems does not work with HTTPS so use HTTP for now @@ -163,7 +168,7 @@ static SyncNetAction *sync_manager_get_selected_actions(gint *n) for (entry = entries, i = 0; entry; entry = entry->next) { SyncEntry *e = (SyncEntry *)entry->data; - if (e->selected) { + if ((entry->next==NULL) || e->selected) {//Last is version SyncNetAction sna = {.entry = e}; actions[i++] = sna; } @@ -212,6 +217,19 @@ static void sync_dialog_start_sync(SyncDialog *sd) { gint nactions; SyncNetAction *actions; + gchar *path; + int fd,len; + gchar buf[101]; + + path = g_build_filename(g_get_user_config_dir(), "hardinfo2", + "blobs-update-version.json", NULL); + fd = open(path,O_RDONLY); + if(fd){ + read(fd,buf,100); + sscanf(buf,"{\"update-version\":\"%u\",",&our_blobs_update_version); + close(fd); + } + DEBUG("OUR2_BLOBS_UPDATE_VERSION=%u",our_blobs_update_version); ensure_soup_session(); @@ -246,6 +264,9 @@ static void got_response(SoupSession *source, SoupMessage *res, gpointer user_da { SyncNetAction *sna = user_data; GInputStream *is; + gchar *path; + int fd,len,updateversion=0; + gchar buf[101]; #if SOUP_CHECK_VERSION(2,42,0) #else const guint8 *buf=NULL; @@ -265,8 +286,10 @@ static void got_response(SoupSession *source, SoupMessage *res, gpointer user_da //check for missing config dirs g_mkdir(g_get_user_config_dir(), 0766); g_mkdir(g_build_filename(g_get_user_config_dir(),"hardinfo2",NULL), 0766); - // - gchar *path = g_build_filename(g_get_user_config_dir(), "hardinfo2", + if(strncmp(sna->entry->file_name,"blobs-update-version.json",25)==0){ + updateversion=1; + } + path = g_build_filename(g_get_user_config_dir(), "hardinfo2", sna->entry->file_name, NULL); GFile *file = g_file_new_for_path(path); GFileOutputStream *output = @@ -291,6 +314,16 @@ static void got_response(SoupSession *source, SoupMessage *res, gpointer user_da #endif } + if(updateversion){ + fd = open(path,O_RDONLY); + if(fd){ + read(fd,buf,100); + sscanf(buf,"{\"update-version\":\"%u\",",&server_blobs_update_version); + DEBUG("SERVER_BLOBS_UPDATE_VERSION=%u",server_blobs_update_version); + close(fd); + } + } + g_free(path); g_object_unref(file); } @@ -308,8 +341,12 @@ static gboolean send_request_for_net_action(SyncNetAction *sna) SoupMessage *msg; guint response_code; - uri = g_strdup_printf("%s/%s", API_SERVER_URI, sna->entry->file_name); - + if(!sna->entry->optional || (our_blobs_update_version<server_blobs_update_version)){ + if(strncmp(sna->entry->file_name,"blobs-update-version.json",25)==0){ + uri = g_strdup_printf("%s/%s?ver=%s&blobver=%d", API_SERVER_URI, sna->entry->file_name,VERSION,our_blobs_update_version); + }else{ + uri = g_strdup_printf("%s/%s", API_SERVER_URI, sna->entry->file_name); + } if (sna->entry->generate_contents_for_upload == NULL) { msg = soup_message_new("GET", uri); } else { @@ -347,7 +384,7 @@ static gboolean send_request_for_net_action(SyncNetAction *sna) sna->error = NULL; return FALSE; } - + } return TRUE; } @@ -365,7 +402,7 @@ sync_dialog_netarea_start_actions(SyncDialog *sd, SyncNetAction sna[], gint n) labels = g_new0(GtkWidget *, n); status_labels = g_new0(GtkWidget *, n); - for (i = 0; i < n; i++) { + for (i = n-1; i >0; i--) { GtkWidget *hbox; hbox = gtk_hbox_new(FALSE, 5); @@ -389,7 +426,7 @@ sync_dialog_netarea_start_actions(SyncDialog *sd, SyncNetAction sna[], gint n) while (gtk_events_pending()) gtk_main_iteration(); - for (i = 0; i < n; i++) { + for (i = n-1; i >0; i--) { gchar *markup; if (sd->flag_cancel) { @@ -419,24 +456,7 @@ sync_dialog_netarea_start_actions(SyncDialog *sd, SyncNetAction sna[], gint n) gtk_label_set_markup(GTK_LABEL(status_labels[i]), error_str); if (sna[i].error) { - /* if (sna[i].error->code != 1) { - // the user has not cancelled something... - g_warning(_("Failed while performing \"%s\". Please file a " - "bug report " - "if this problem persists. (Use the " - "Help\342\206\222Report" - " bug option.)\n\nDetails: %s"), - _(sna[i].entry->name), sna[i].error->message); - }*/ - g_error_free(sna[i].error); - } else { - /* g_warning(_("Failed while performing \"%s\". Please file a bug " - "report " - "if this problem persists. (Use the " - "Help\342\206\222Report" - " bug option.)"), - _(sna[i].entry->name));*/ } break; } @@ -507,7 +527,7 @@ static void populate_store(GtkListStore *store) e->selected = TRUE; - gtk_list_store_append(store, &iter); + gtk_list_store_prepend(store, &iter); gtk_list_store_set(store, &iter, 0, TRUE, 1, _(e->name), 2, e, -1); } } @@ -524,7 +544,8 @@ static void sel_toggle(GtkCellRendererToggle *cellrenderertoggle, gtk_tree_model_get_iter(model, &iter, path); gtk_tree_model_get(model, &iter, 0, &active, 2, &se, -1); - se->selected = !active; + if(path_str[0]==3+48) //only allow to disable sending benchmark results + se->selected = !active; gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, se->selected, -1); gtk_tree_path_free(path); @@ -711,13 +732,24 @@ static gboolean sync_one(gpointer data) out: g_main_loop_unref(loop); idle_free(sna); - return FALSE; } void sync_manager_update_on_startup(void) { GSList *entry; + gchar *path; + int fd; + gchar buf[101]; + path = g_build_filename(g_get_user_config_dir(), "hardinfo2", + "blobs-update-version.json", NULL); + fd = open(path,O_RDONLY); + if(fd){ + read(fd,buf,100); + sscanf(buf,"{\"update-version\":\"%u\",",&our_blobs_update_version); + close(fd); + } + DEBUG("OUR1_BLOBS_UPDATE_VERSION=%u",our_blobs_update_version); ensure_soup_session(); |