1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-07 02:03:13 +02:00

Added uptime save in session file (for /upgrade command)

This commit is contained in:
Sebastien Helleu
2005-12-25 10:40:52 +00:00
parent ac8c68bd68
commit 18e47000f4
4 changed files with 140 additions and 2 deletions
+62
View File
@@ -404,6 +404,23 @@ session_save_buffers (FILE *file)
return 1;
}
/*
* 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);
@@ -1470,6 +1488,43 @@ session_load_line (FILE *file)
return 0;
}
/*
* 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);
+8 -1
View File
@@ -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);
+62
View File
@@ -404,6 +404,23 @@ session_save_buffers (FILE *file)
return 1;
}
/*
* 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);
@@ -1470,6 +1488,43 @@ session_load_line (FILE *file)
return 0;
}
/*
* 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);
+8 -1
View File
@@ -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);