+
+static gboolean
+is_in_command_line (GFile *file,
+ const gchar **files)
+{
+ gint i;
+
+ if (!files)
+ return FALSE;
+
+ for (i = 0; files[i]; i++) {
+ GFile *cfile;
+
+ cfile = g_file_new_for_commandline_arg (files[i]);
+ if (g_file_equal (cfile, file)) {
+ g_object_unref (cfile);
+ return TRUE;
+ }
+ g_object_unref (cfile);
+ }
+
+ return FALSE;
+}
+
+static GKeyFile *
+ev_application_get_files_to_recover (EvApplication *application,
+ const gchar **files)
+{
+ GKeyFile *state_file;
+ gchar **uri_list;
+ gchar **dest_list = NULL;
+ gint i, j;
+
+ state_file = g_key_file_new ();
+ g_key_file_load_from_file (state_file,
+ application->crashed_file,
+ G_KEY_FILE_NONE,
+ NULL);
+
+ uri_list = g_key_file_get_string_list (state_file,
+ "Evince",
+ "documents",
+ NULL, NULL);
+ if (!uri_list) {
+ g_key_file_free (state_file);
+ return NULL;
+ }
+
+ for (i = 0, j = 0; uri_list[i]; i++) {
+ GFile *file = g_file_new_for_uri (uri_list[i]);
+
+ if (!g_file_query_exists (file, NULL) ||
+ is_in_command_line (file, files)) {
+ g_object_unref (file);
+ continue;
+ }
+
+ if (!dest_list)
+ dest_list = g_new (gchar *, g_strv_length (uri_list) - i);
+ dest_list[j++] = uri_list[i];
+ }
+
+ if (j > 0) {
+ g_key_file_set_string_list (state_file,
+ "Evince",
+ "documents",
+ (const gchar **)dest_list,
+ j);
+ } else {
+ g_key_file_free (state_file);
+ state_file = NULL;
+ }
+
+ g_free (dest_list);
+ g_strfreev (uri_list);
+
+ return state_file;
+}