← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/rolling_autosave into lp:widelands

 

Tino has proposed merging lp:~widelands-dev/widelands/rolling_autosave into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1407948 in widelands: "More autosave files would help debugging"
  https://bugs.launchpad.net/widelands/+bug/1407948

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/rolling_autosave/+merge/246061

Roll autosave files, wl_autosave_0 to wl_autosave_n
Allow setting of number of files (1-10) in advanced options dialog
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/rolling_autosave into lp:widelands.
=== modified file 'src/logic/save_handler.cc'
--- src/logic/save_handler.cc	2014-09-29 13:30:46 +0000
+++ src/logic/save_handler.cc	2015-01-11 15:14:31 +0000
@@ -21,6 +21,8 @@
 
 #include <memory>
 
+#include <boost/format.hpp>
+
 #include "base/log.h"
 #include "base/macros.h"
 #include "base/scoped_timer.h"
@@ -70,6 +72,24 @@
 		}
 
 		log("Autosave: interval elapsed (%d s), saving\n", elapsed);
+		//roll autosaves
+		int32_t number_of_rolls = g_options.pull_section("global").get_int("autosave_roll") - 1;
+		std::string next_file = (boost::format("%s_%i") % filename % number_of_rolls).str();
+		std::string filename_r = create_file_name(get_base_dir(), next_file);
+		if (number_of_rolls > 0 && g_fs->file_exists(filename_r)) {
+			g_fs->fs_unlink(filename_r);
+		}
+		number_of_rolls--;
+		while (number_of_rolls >= 0) {
+			next_file = (boost::format("%s_%i") % filename % number_of_rolls).str();
+			std::string filename_p = create_file_name(get_base_dir(), next_file);
+			if (g_fs->file_exists(filename_p)) {
+				g_fs->fs_rename(filename_p, filename_r);
+			}
+			filename_r = filename_p;
+			number_of_rolls--;
+		}
+		filename = next_file;
 	}
 
 	// TODO(unknown): defer saving to next tick so that this message is shown

=== modified file 'src/ui_fsmenu/options.cc'
--- src/ui_fsmenu/options.cc	2014-12-06 12:22:35 +0000
+++ src/ui_fsmenu/options.cc	2015-01-11 15:14:31 +0000
@@ -281,7 +281,6 @@
 		 m_dock_windows_to_edges.get_h(),
 		 _("Save game automatically every"), UI::Align_VCenter),
 
-
 	m_sb_remove_replays
 		(this,
 		 get_w() - m_hmargin - 240,
@@ -565,9 +564,23 @@
 			 opt.border_snap_distance, 0, 99, ngettext("pixel", "pixels", opt.border_snap_distance),
 			 g_gr->images().get("pics/but1.png")),
 
+	m_label_autosave_roll
+		(this,
+		 m_hmargin,
+		 m_label_snap_dis_border.get_y() + m_label_snap_dis_border.get_h() + 2 * m_padding,
+		 _("Number of files to use for autosave"), UI::Align_VCenter),
+
+	m_sb_autosave_roll
+		(this,
+			 get_w() - m_hmargin - (get_w() / 5), m_label_autosave_roll.get_y(),
+			 get_w() / 5, m_vbutw,
+			 opt.autosave_roll, 1, 10, ngettext("file", "files", opt.autosave_roll),
+			 g_gr->images().get("pics/but1.png")),
+
+
 	m_transparent_chat (this, Point(m_hmargin,
-											  m_label_snap_dis_border.get_y() +
-											  m_label_snap_dis_border.get_h() + m_space)),
+											  m_label_autosave_roll.get_y() +
+											  m_label_autosave_roll.get_h() + m_space)),
 	m_label_transparent_chat
 		(this,
 		 m_hmargin + m_transparent_chat.get_w() + m_padding, m_transparent_chat.get_y(),
@@ -620,6 +633,13 @@
 					 boost::ref(*this)));
 	}
 
+	for (UI::Button* temp_button : m_sb_autosave_roll.get_buttons()) {
+		temp_button->sigclicked.connect
+				(boost::bind
+					(&FullscreenMenuAdvancedOptions::update_sb_autosave_roll_unit,
+					 boost::ref(*this)));
+	}
+
 	m_cancel.sigclicked.connect
 		(boost::bind
 			(&FullscreenMenuAdvancedOptions::end_modal,
@@ -665,6 +685,9 @@
 	m_sb_dis_border.set_unit(ngettext("pixel", "pixels", m_sb_dis_border.get_value()));
 }
 
+void FullscreenMenuAdvancedOptions::update_sb_autosave_roll_unit() {
+	m_sb_autosave_roll.set_unit(ngettext("file", "files", m_sb_autosave_roll.get_value()));
+}
 
 OptionsCtrl::OptionsStruct FullscreenMenuAdvancedOptions::get_values() {
 	// Write all remaining data from UI elements
@@ -674,6 +697,7 @@
 	os.border_snap_distance = m_sb_dis_border.get_value();
 	os.remove_syncstreams   = m_remove_syncstreams.get_state();
 	os.transparent_chat     = m_transparent_chat.get_state();
+	os.autosave_roll        = m_sb_autosave_roll.get_value();
 	return os;
 }
 
@@ -719,6 +743,7 @@
 	opt.music = !m_opt_section.get_bool("disable_music", false);
 	opt.fx = !m_opt_section.get_bool("disable_fx", false);
 	opt.autosave = m_opt_section.get_int("autosave", DEFAULT_AUTOSAVE_INTERVAL * 60);
+	opt.autosave_roll = m_opt_section.get_int("autosave_roll", 5);
 	opt.maxfps = m_opt_section.get_int("maxfps", 25);
 
 	opt.message_sound = m_opt_section.get_bool("sound_at_message", true);
@@ -748,6 +773,7 @@
 	m_opt_section.set_bool("disable_fx",           !opt.fx);
 	m_opt_section.set_string("language",            opt.language);
 	m_opt_section.set_int("autosave",               opt.autosave * 60);
+	m_opt_section.set_int("autosave_roll",          opt.autosave_roll);
 	m_opt_section.set_int("maxfps",                 opt.maxfps);
 
 	m_opt_section.set_bool("sound_at_message",      opt.message_sound);

=== modified file 'src/ui_fsmenu/options.h'
--- src/ui_fsmenu/options.h	2014-11-27 19:13:30 +0000
+++ src/ui_fsmenu/options.h	2015-01-11 15:14:31 +0000
@@ -52,6 +52,7 @@
 		bool fx;
 		std::string language;
 		int32_t autosave; // autosave interval in minutes
+		int32_t autosave_roll;
 		uint32_t maxfps;
 		uint32_t remove_replays;
 		bool remove_syncstreams;
@@ -176,6 +177,7 @@
 private:
 	void update_sb_dis_panel_unit();
 	void update_sb_dis_border_unit();
+	void update_sb_autosave_roll_unit();
 
 	uint32_t const              m_vbutw;
 	uint32_t const              m_butw;
@@ -189,6 +191,8 @@
 
 	UI::Textarea                m_label_snap_dis_panel, m_label_snap_dis_border;
 	UI::SpinBox                 m_sb_dis_panel, m_sb_dis_border;
+	UI::Textarea                m_label_autosave_roll;
+	UI::SpinBox                 m_sb_autosave_roll;
 	UI::Checkbox                m_transparent_chat;
 	UI::MultilineTextarea       m_label_transparent_chat;
 	UI::Checkbox                m_message_sound;


Follow ups