diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2005-12-25 10:40:52 +0000 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2005-12-25 10:40:52 +0000 |
commit | 18e47000f473035a0cf785c708975d1fa1335256 (patch) | |
tree | eba1b5a91821ca509ae8889f935a8859fe20594f /src | |
parent | ac8c68bd68e148868437b758bcfb525c87c2d389 (diff) | |
download | weechat-18e47000f473035a0cf785c708975d1fa1335256.zip |
Added uptime save in session file (for /upgrade command)
Diffstat (limited to 'src')
-rw-r--r-- | src/common/session.c | 62 | ||||
-rw-r--r-- | src/common/session.h | 9 |
2 files changed, 70 insertions, 1 deletions
diff --git a/src/common/session.c b/src/common/session.c index e86ce4f9b..9373c06db 100644 --- a/src/common/session.c +++ b/src/common/session.c @@ -405,6 +405,23 @@ session_save_buffers (FILE *file) } /* + * session_save_uptime: save uptime into session file + */ + +int +session_save_uptime (FILE *file) +{ + int rc; + + rc = 1; + + rc = rc && (session_write_id (file, SESSION_OBJ_UPTIME)); + rc = rc && (session_write_buf (file, SESSION_UPT_START_TIME, &weechat_start_time, sizeof (time_t))); + rc = rc && (session_write_id (file, SESSION_UPT_END)); + return rc; +} + +/* * session_save: save current session */ @@ -423,6 +440,7 @@ session_save (char *filename) rc = rc && (session_save_dcc (file)); rc = rc && (session_save_history (file, history_global_last)); rc = rc && (session_save_buffers (file)); + rc = rc && (session_save_uptime (file)); fclose (file); @@ -1471,6 +1489,43 @@ session_load_line (FILE *file) } /* + * session_load_uptime: load uptime from file + */ + +int +session_load_uptime (FILE *file) +{ + int object_id, rc; + + /* read uptime values */ + rc = 1; + while (rc) + { + if (feof (file)) + { + session_crash (file, _("unexpected end of file (reading uptime)")); + return 0; + } + if (fread ((void *)(&object_id), sizeof (int), 1, file) == 0) + return 0; + switch (object_id) + { + case SESSION_UPT_END: + return 1; + case SESSION_UPT_START_TIME: + rc = rc && (session_read_buf (file, &weechat_start_time, sizeof (time_t))); + break; + default: + weechat_log_printf (_("session: warning: ignoring value from " + "uptime (object id: %d)\n")); + rc = rc && (session_read_ignore_value (file)); + break; + } + } + return 0; +} + +/* * session_load: load session from file */ @@ -1568,6 +1623,13 @@ session_load (char *filename) return 0; } break; + case SESSION_OBJ_UPTIME: + if (!session_load_uptime (file)) + { + session_crash (file, _("failed to load uptime")); + return 0; + } + break; default: weechat_log_printf (_("ignoring object (id: %d)\n"), object_id); diff --git a/src/common/session.h b/src/common/session.h index befbd85da..9f406894f 100644 --- a/src/common/session.h +++ b/src/common/session.h @@ -44,6 +44,7 @@ enum t_session_object SESSION_OBJ_HISTORY, SESSION_OBJ_BUFFER, SESSION_OBJ_LINE, + SESSION_OBJ_UPTIME }; enum t_session_server @@ -87,7 +88,7 @@ enum t_session_server SESSION_SERV_LAG_NEXT_CHECK, SESSION_SERV_CHARSET_DECODE_ISO, SESSION_SERV_CHARSET_DECODE_UTF, - SESSION_SERV_CHARSET_ENCODE, + SESSION_SERV_CHARSET_ENCODE }; enum t_session_channel @@ -166,6 +167,12 @@ enum t_session_line SESSION_LINE_OFS_AFTER_DATE }; +enum t_session_uptime +{ + SESSION_UPT_END = 0, + SESSION_UPT_START_TIME +}; + int session_save (char *filename); int session_load (char *filename); |