← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1548932-editor-save-zip into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1548932-editor-save-zip into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1548932 in widelands: "Editor fails on save with zip filesystem"
  https://bugs.launchpad.net/widelands/+bug/1548932

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1548932-editor-save-zip/+merge/287036

Not ready for merging, I just want to get an AppVeyor Windows build to see if this fixes the saving problem.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1548932-editor-save-zip into lp:widelands.
=== modified file 'src/editor/ui_menus/editor_main_menu_save_map.cc'
--- src/editor/ui_menus/editor_main_menu_save_map.cc	2016-02-22 10:23:14 +0000
+++ src/editor/ui_menus/editor_main_menu_save_map.cc	2016-02-24 15:08:41 +0000
@@ -223,21 +223,21 @@
  * returns true if dialog should close, false if it
  * should stay open
  */
-bool MainMenuSaveMap::save_map(std::string filename, bool binary) {
+bool MainMenuSaveMap::save_map(const std::string& filename, bool binary) {
 	//  Make sure that the current directory exists and is writeable.
 	g_fs->ensure_directory_exists(curdir_);
 
 	//  OK, first check if the extension matches (ignoring case).
-	if (!boost::iends_with(filename, WLMF_SUFFIX))
-		filename += WLMF_SUFFIX;
+	const std::string mapfilename =
+			boost::iends_with(filename, WLMF_SUFFIX) ? filename : filename + WLMF_SUFFIX;
 
 	//  append directory name
-	const std::string complete_filename = curdir_ + g_fs->file_separator() + filename;
+	const std::string complete_filename = curdir_ + g_fs->file_separator() + mapfilename;
 
 	//  Check if file exists. If so, show a warning.
 	if (g_fs->file_exists(complete_filename)) {
 		const std::string s = (boost::format(_("A file with the name ‘%s’ already exists. Overwrite?")) %
-		                 FileSystem::fs_filename(filename.c_str())).str();
+							  FileSystem::fs_filename(mapfilename.c_str())).str();
 		UI::WLMessageBox mbox
 				(&eia(), _("Error Saving Map!"), s, UI::WLMessageBox::MBoxType::kOkCancel);
 			if (mbox.run<UI::Panel::Returncodes>() == UI::Panel::Returncodes::kBack)
@@ -250,7 +250,7 @@
 	if (g_fs->file_exists(tmp_name)) {
 		const std::string s = (boost::format(_
 				("A file with the name ‘%s.tmp’ already exists. You have to remove it manually."))
-					% FileSystem::fs_filename(filename.c_str())).str();
+					% FileSystem::fs_filename(mapfilename.c_str())).str();
 		UI::WLMessageBox mbox
 			(&eia(), _("Error Saving Map!"), s, UI::WLMessageBox::MBoxType::kOk);
 		mbox.run<UI::Panel::Returncodes>();
@@ -281,7 +281,7 @@
 			Widelands::MapSaver* wms = new Widelands::MapSaver(*fs, egbase);
 			wms->save();
 			delete wms;
-			//reset filesystem to avoid file locks on saves
+			// Reset filesystem to avoid file locks on saves
 			fs.reset();
 			eia().set_need_save(false);
 			g_fs->fs_unlink(complete_filename);
@@ -290,7 +290,7 @@
 			fs.reset(g_fs->make_sub_file_system(complete_filename));
 			// set the filesystem of the map to the current save file / directory
 			map.swap_filesystem(fs);
-			// DONT use fs as of here, its garbage now!
+			// DON'T use fs as of here, its garbage now!
 
 		} catch (const std::exception & e) {
 			std::string s =
@@ -308,5 +308,13 @@
 	} // end fs scope, dont use it
 
 	die();
+
+	// Ensure that the map's filename hasn't changed, except for adding the WLMF_SUFFIX if it didn't have one.
+	map.set_filename(mapfilename);
+	log("NOCOM the map's filename is: %s\n", map.get_filename().c_str());
+	log("NOCOM the original filename was: %s\n", filename.c_str());
+	assert(map.get_filename() ==
+			 (boost::iends_with(filename, WLMF_SUFFIX) ? filename : filename + WLMF_SUFFIX));
+	assert(!boost::iends_with(map.get_filename(), ".tmp"));
 	return true;
 }

=== modified file 'src/editor/ui_menus/editor_main_menu_save_map.h'
--- src/editor/ui_menus/editor_main_menu_save_map.h	2015-10-02 07:02:00 +0000
+++ src/editor/ui_menus/editor_main_menu_save_map.h	2016-02-24 15:08:41 +0000
@@ -43,7 +43,7 @@
 	void double_clicked_item();
 	void edit_box_changed();
 
-	bool save_map(std::string, bool);
+	bool save_map(const std::string&, bool);
 
 	UI::Button make_directory_, edit_options_;
 


Follow ups