diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-05-02 10:03:48 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-05-02 10:03:48 -0700 |
commit | 725e4582d9c7174b70fe197bb27345960457549e (patch) | |
tree | b51b3ebd8867e5577ef460602af2b880b4d5ec17 | |
parent | 2d1a316d848441a7d1137cb51b1ee0b8222aaa74 (diff) | |
download | subsurface-725e4582d9c7174b70fe197bb27345960457549e.tar.gz |
Don't close config file when changing preferences
On Linux and MacOS the subsurface_close_conf() doesn't really close the
config file (it flushes writes on MacOS), but on Windows it does
actually close the registry hkey.
Which is bad, if you change the settings multiple times - we assume that
the config file is open the whole time.
So add a "subsurface_flush_conf()" function, and call *that* when
changing configuration parameters. And call the close function only at
the very end.
Alternatively, maybe we should just open the config file separately
every time. I don't much care, maybe somebody else does.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | display-gtk.h | 1 | ||||
-rw-r--r-- | dive.h | 1 | ||||
-rw-r--r-- | gtk-gui.c | 9 | ||||
-rw-r--r-- | linux.c | 5 | ||||
-rw-r--r-- | macos.c | 7 | ||||
-rw-r--r-- | main.c | 1 | ||||
-rw-r--r-- | windows.c | 7 |
7 files changed, 28 insertions, 3 deletions
diff --git a/display-gtk.h b/display-gtk.h index f12e42996..5a76edce2 100644 --- a/display-gtk.h +++ b/display-gtk.h @@ -38,6 +38,7 @@ typedef enum { extern void subsurface_open_conf(void); extern void subsurface_set_conf(char *name, pref_type_t type, const void *value); extern const void *subsurface_get_conf(char *name, pref_type_t type); +extern void subsurface_flush_conf(void); extern void subsurface_close_conf(void); extern const char *subsurface_USB_name(void); @@ -317,6 +317,7 @@ extern void add_event(struct dive *dive, int time, int type, int flags, int valu extern void init_ui(int *argcp, char ***argvp); extern void run_ui(void); +extern void exit_ui(void); extern void report_error(GError* error); @@ -423,7 +423,9 @@ static void preferences_dialog(GtkWidget *w, gpointer data) subsurface_set_conf("SAC", PREF_BOOL, BOOL_TO_PTR(visible_cols.sac)); subsurface_set_conf("OTU", PREF_BOOL, BOOL_TO_PTR(visible_cols.otu)); subsurface_set_conf("divelist_font", PREF_STRING, divelist_font); - subsurface_close_conf(); + + /* Flush the changes out to the system */ + subsurface_flush_conf(); } gtk_widget_destroy(dialog); } @@ -769,6 +771,11 @@ void run_ui(void) gtk_main(); } +void exit_ui(void) +{ + subsurface_close_conf(); +} + typedef struct { cairo_rectangle_int_t rect; const char *text; @@ -43,6 +43,11 @@ const void *subsurface_get_conf(char *name, pref_type_t type) return NULL; } +void subsurface_flush_conf(void) +{ + /* this is a no-op */ +} + void subsurface_close_conf(void) { /* this is a no-op */ @@ -59,13 +59,18 @@ const void *subsurface_get_conf(char *name, pref_type_t type) return NULL; } -void subsurface_close_conf(void) +void subsurface_flush_conf(void) { int ok = CFPreferencesAppSynchronize(SUBSURFACE_PREFERENCES); if (!ok) fprintf(stderr,"Could not save preferences\n"); } +void subsurface_close_conf(void) +{ + /* Nothing */ +} + const char *subsurface_USB_name() { return "/dev/tty.SLAB_USBtoUART"; @@ -239,5 +239,6 @@ int main(int argc, char **argv) report_dives(imported); run_ui(); + exit_ui(); return 0; } @@ -73,10 +73,15 @@ const void *subsurface_get_conf(char *name, pref_type_t type) return NULL; } -void subsurface_close_conf(void) +void subsurface_flush_conf(void) { + /* I wonder if we should even do this - it's apparently very expensive */ if (RegFlushKey(hkey) != ERROR_SUCCESS) printf("RegFlushKey failed \n"); +} + +void subsurface_close_conf(void) +{ RegCloseKey(hkey); } |