~widelands-dev/widelands/trunk

« back to all changes in this revision

Viewing changes to src/editor/ui_menus/main_menu_save_map_make_directory.cc

  • Committer: Wideland's Bunnybot
  • Date: 2018-11-23 08:20:36 UTC
  • mfrom: (8895.4.5 catching-fs-errors)
  • Revision ID: bunnybot@widelands.org-20181123082036-4nyz8m70wexsj1xq
Merged lp:~widelands-dev/widelands/handling-various-fs-errors:
Improved error handling for file save dialogs

In Load/Save menu for games/replays:
- All deletion errors are caught, player gets a message.
- When deleting multiplayer replays, also the corresponding syncstream file is deleted.
- After deleting replays, the table now respects the Show Filenames setting.

In Save menu for maps:
- Errors when trying to create a directory are now caught, player gets a message.
- Directory creation now doesn't allow names with map extensions, because the game would just trying to interpret them as maps and not show as directories. A tooltip is shown.
- Directory creation can now also be triggered by pressing Enter in the name edit box.

Other file errors are caught and logged:
- syncstream deletion in SyncWrapper destructor
- in Map::get_correct_loader
- file deletion/renaming in GameClient::handle_packet

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
#include "editor/ui_menus/main_menu_save_map_make_directory.h"
21
21
 
 
22
#include <boost/algorithm/string.hpp>
 
23
 
22
24
#include "base/i18n.h"
23
25
#include "graphic/font_handler.h"
24
26
#include "io/filesystem/layered_filesystem.h"
 
27
#include "logic/filesystem_constants.h"
25
28
 
26
29
MainMenuSaveMapMakeDirectory::MainMenuSaveMapMakeDirectory(UI::Panel* const parent,
27
30
                                                           char const* dirname)
64
67
 
65
68
        edit_.set_text(dirname_);
66
69
        edit_.changed.connect(boost::bind(&MainMenuSaveMapMakeDirectory::edit_changed, this));
67
 
        ok_button_.sigclicked.connect(
 
70
        edit_.ok.connect(boost::bind(&MainMenuSaveMapMakeDirectory::clicked_ok, this));
 
71
        edit_.cancel.connect(
68
72
           boost::bind(&MainMenuSaveMapMakeDirectory::end_modal<UI::Panel::Returncodes>,
69
 
                       boost::ref(*this), UI::Panel::Returncodes::kOk));
 
73
                       boost::ref(*this), UI::Panel::Returncodes::kBack));
 
74
        ok_button_.sigclicked.connect(boost::bind(&MainMenuSaveMapMakeDirectory::clicked_ok, this));
70
75
        ok_button_.set_enabled(!dirname_.empty());
71
76
        cancel_button_.sigclicked.connect(
72
77
           boost::bind(&MainMenuSaveMapMakeDirectory::end_modal<UI::Panel::Returncodes>,
73
78
                       boost::ref(*this), UI::Panel::Returncodes::kBack));
74
79
        center_to_parent();
 
80
}
 
81
 
 
82
void MainMenuSaveMapMakeDirectory::start() {
75
83
        edit_.focus();
76
84
}
77
85
 
82
90
        const std::string& text = edit_.text();
83
91
        // Prevent the user from creating nonsense directory names, like e.g. ".." or "...".
84
92
        const bool is_legal_filename = FileSystem::is_legal_filename(text);
85
 
        ok_button_.set_enabled(is_legal_filename);
86
 
        edit_.set_tooltip(is_legal_filename ? "" : illegal_filename_tooltip_);
 
93
        // Prevent the user from creating directory names that the game would
 
94
        // try to interpret as maps
 
95
        const bool has_map_extension = boost::iends_with(text, kWidelandsMapExtension) ||
 
96
                                       boost::iends_with(text, kS2MapExtension1) ||
 
97
                                       boost::iends_with(text, kS2MapExtension2);
 
98
        ok_button_.set_enabled(is_legal_filename && !has_map_extension);
 
99
        edit_.set_tooltip(is_legal_filename ?
 
100
                             (has_map_extension ? _("This extension is reserved!") : "") :
 
101
                             illegal_filename_tooltip_);
87
102
        dirname_ = text;
88
103
}
 
104
 
 
105
/**
 
106
 * Clicked OK button oder pressed Enter in edit box
 
107
 */
 
108
void MainMenuSaveMapMakeDirectory::clicked_ok() {
 
109
        if (!ok_button_.enabled()) {
 
110
                return;
 
111
        }
 
112
        end_modal<UI::Panel::Returncodes>(UI::Panel::Returncodes::kOk);
 
113
}