summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
Diffstat (limited to 'shell')
-rw-r--r--shell/callbacks.c2
-rw-r--r--shell/shell.c2
-rw-r--r--shell/syncmanager.c100
3 files changed, 74 insertions, 30 deletions
diff --git a/shell/callbacks.c b/shell/callbacks.c
index b9c6252b..e7808471 100644
--- a/shell/callbacks.c
+++ b/shell/callbacks.c
@@ -66,7 +66,7 @@ void cb_sync_on_startup()
GKeyFile *key_file = g_key_file_new();
g_mkdir(g_get_user_config_dir(),0755);
- g_mkdir(g_build_filename(g_get_user_config_dir(), "hardinfo", NULL),0755);
+ g_mkdir(g_build_filename(g_get_user_config_dir(), "hardinfo2", NULL),0755);
gchar *conf_path = g_build_filename(g_get_user_config_dir(), "hardinfo2",
"settings.ini", NULL);
diff --git a/shell/shell.c b/shell/shell.c
index 22b1003f..e74486f2 100644
--- a/shell/shell.c
+++ b/shell/shell.c
@@ -1065,7 +1065,7 @@ static void set_view_type(ShellViewType viewtype, gboolean reload)
if (viewtype != shell->view_type)
type_changed = TRUE;
- if (viewtype < SHELL_VIEW_NORMAL || viewtype >= SHELL_VIEW_N_VIEWS)
+ if (viewtype >= SHELL_VIEW_N_VIEWS)
viewtype = SHELL_VIEW_NORMAL;
shell->normalize_percentage = TRUE;
diff --git a/shell/syncmanager.c b/shell/syncmanager.c
index 9f135ab3..17fdc421 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,25 @@ static void sync_dialog_start_sync(SyncDialog *sd)
{
gint nactions;
SyncNetAction *actions;
+ gchar *path;
+ int fd=-1;
+ 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<0) {
+ free(path);
+ path = g_build_filename(params.path_data,"blobs-update-version.json", NULL);
+ fd = open(path,O_RDONLY);
+ }
+ if(fd>=0){
+ read(fd,buf,100);
+ sscanf(buf,"{\"update-version\":\"%u\",",&our_blobs_update_version);
+ close(fd);
+ }
+ free(path);
+ DEBUG("OUR2_BLOBS_UPDATE_VERSION=%u",our_blobs_update_version);
ensure_soup_session();
@@ -246,6 +270,9 @@ static void got_response(SoupSession *source, SoupMessage *res, gpointer user_da
{
SyncNetAction *sna = user_data;
GInputStream *is;
+ gchar *path;
+ int fd,updateversion=0;
+ gchar buffer[101];
#if SOUP_CHECK_VERSION(2,42,0)
#else
const guint8 *buf=NULL;
@@ -265,8 +292,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 +320,16 @@ static void got_response(SoupSession *source, SoupMessage *res, gpointer user_da
#endif
}
+ if(updateversion){
+ fd = open(path,O_RDONLY);
+ if(fd){
+ read(fd,buffer,100);
+ sscanf(buffer,"{\"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 +347,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 +390,7 @@ static gboolean send_request_for_net_action(SyncNetAction *sna)
sna->error = NULL;
return FALSE;
}
-
+ }
return TRUE;
}
@@ -365,7 +408,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 +432,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 +462,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 +533,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 +550,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(strncmp(se->name,N_("Send benchmark results"),10)==0) //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 +738,30 @@ 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=-1;
+ 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<0) {
+ free(path);
+ path = g_build_filename(params.path_data,"blobs-update-version.json", NULL);
+ fd = open(path,O_RDONLY);
+ }
+ if(fd>=0){
+ read(fd,buf,100);
+ sscanf(buf,"{\"update-version\":\"%u\",",&our_blobs_update_version);
+ close(fd);
+ }
+ free(path);
+ DEBUG("OUR1_BLOBS_UPDATE_VERSION=%u",our_blobs_update_version);
ensure_soup_session();