fix MT06785

This commit is contained in:
Vas Crabb 2017-12-07 10:52:38 +11:00
parent e57b4afa77
commit 46edbee6ed
4 changed files with 95 additions and 93 deletions

View File

@ -47,14 +47,14 @@ namespace ui {
menu_file_selector::menu_file_selector(mame_ui_manager &mui, render_container &container, device_image_interface *image, std::string &current_directory, std::string &current_file, bool has_empty, bool has_softlist, bool has_create, menu_file_selector::result &result) menu_file_selector::menu_file_selector(mame_ui_manager &mui, render_container &container, device_image_interface *image, std::string &current_directory, std::string &current_file, bool has_empty, bool has_softlist, bool has_create, menu_file_selector::result &result)
: menu(mui, container) : menu(mui, container)
, m_image(image)
, m_current_directory(current_directory) , m_current_directory(current_directory)
, m_current_file(current_file) , m_current_file(current_file)
, m_has_empty(has_empty)
, m_has_softlist(has_softlist)
, m_has_create(has_create)
, m_result(result) , m_result(result)
{ {
m_image = image;
m_has_empty = has_empty;
m_has_softlist = has_softlist;
m_has_create = has_create;
} }
@ -176,7 +176,9 @@ int menu_file_selector::compare_entries(const file_selector_entry *e1, const fil
//------------------------------------------------- //-------------------------------------------------
menu_file_selector::file_selector_entry &menu_file_selector::append_entry( menu_file_selector::file_selector_entry &menu_file_selector::append_entry(
file_selector_entry_type entry_type, const std::string &entry_basename, const std::string &entry_fullpath) file_selector_entry_type entry_type,
const std::string &entry_basename,
const std::string &entry_fullpath)
{ {
return append_entry(entry_type, std::string(entry_basename), std::string(entry_fullpath)); return append_entry(entry_type, std::string(entry_basename), std::string(entry_fullpath));
} }
@ -188,7 +190,9 @@ menu_file_selector::file_selector_entry &menu_file_selector::append_entry(
//------------------------------------------------- //-------------------------------------------------
menu_file_selector::file_selector_entry &menu_file_selector::append_entry( menu_file_selector::file_selector_entry &menu_file_selector::append_entry(
file_selector_entry_type entry_type, std::string &&entry_basename, std::string &&entry_fullpath) file_selector_entry_type entry_type,
std::string &&entry_basename,
std::string &&entry_fullpath)
{ {
// allocate a new entry // allocate a new entry
file_selector_entry entry; file_selector_entry entry;
@ -197,22 +201,18 @@ menu_file_selector::file_selector_entry &menu_file_selector::append_entry(
entry.fullpath = std::move(entry_fullpath); entry.fullpath = std::move(entry_fullpath);
// find the end of the list // find the end of the list
m_entrylist.emplace_back(std::move(entry)); return *m_entrylist.emplace(m_entrylist.end(), std::move(entry));
return m_entrylist[m_entrylist.size() - 1];
} }
//------------------------------------------------- //-------------------------------------------------
// append_entry_menu_item - appends // append_dirent_entry - appends
// a menu item for a file selector entry // a menu item for a file selector entry
//------------------------------------------------- //-------------------------------------------------
menu_file_selector::file_selector_entry *menu_file_selector::append_dirent_entry(const osd::directory::entry *dirent) menu_file_selector::file_selector_entry *menu_file_selector::append_dirent_entry(const osd::directory::entry *dirent)
{ {
std::string buffer;
file_selector_entry_type entry_type; file_selector_entry_type entry_type;
file_selector_entry *entry;
switch (dirent->type) switch (dirent->type)
{ {
case osd::directory::entry::entry_type::FILE: case osd::directory::entry::entry_type::FILE:
@ -229,15 +229,13 @@ menu_file_selector::file_selector_entry *menu_file_selector::append_dirent_entry
} }
// determine the full path // determine the full path
buffer = util::zippath_combine(m_current_directory, dirent->name); std::string buffer = util::zippath_combine(m_current_directory, dirent->name);
// create the file selector entry // create the file selector entry
entry = &append_entry( return &append_entry(
entry_type, entry_type,
dirent->name, dirent->name,
std::move(buffer)); std::move(buffer));
return entry;
} }
@ -290,64 +288,51 @@ void menu_file_selector::append_entry_menu_item(const file_selector_entry *entry
void menu_file_selector::populate(float &customtop, float &custombottom) void menu_file_selector::populate(float &customtop, float &custombottom)
{ {
util::zippath_directory *directory = nullptr;
osd_file::error err;
const osd::directory::entry *dirent;
const file_selector_entry *entry;
const file_selector_entry *selected_entry = nullptr; const file_selector_entry *selected_entry = nullptr;
int i;
const char *volume_name;
uint8_t first;
// open the directory
err = util::zippath_opendir(m_current_directory, &directory);
// clear out the menu entries // clear out the menu entries
m_entrylist.clear(); m_entrylist.clear();
// open the directory
util::zippath_directory *directory = nullptr;
osd_file::error const err = util::zippath_opendir(m_current_directory, &directory);
// add the "[empty slot]" entry if available
if (m_has_empty) if (m_has_empty)
{
// add the "[empty slot]" entry
append_entry(SELECTOR_ENTRY_TYPE_EMPTY, "", ""); append_entry(SELECTOR_ENTRY_TYPE_EMPTY, "", "");
}
if (m_has_create && !util::zippath_is_zip(directory))
{
// add the "[create]" entry // add the "[create]" entry
if (m_has_create && !util::zippath_is_zip(directory))
append_entry(SELECTOR_ENTRY_TYPE_CREATE, "", ""); append_entry(SELECTOR_ENTRY_TYPE_CREATE, "", "");
}
// add and select the "[software list]" entry if available
if (m_has_softlist) if (m_has_softlist)
{ selected_entry = &append_entry(SELECTOR_ENTRY_TYPE_SOFTWARE_LIST, "", "");
// add the "[software list]" entry
entry = &append_entry(SELECTOR_ENTRY_TYPE_SOFTWARE_LIST, "", "");
selected_entry = entry;
}
// add the drives // add the drives
i = 0; int i = 0;
while((volume_name = osd_get_volume_name(i))!=nullptr) for (char const *volume_name = osd_get_volume_name(i); volume_name; volume_name = osd_get_volume_name(++i))
{ append_entry(SELECTOR_ENTRY_TYPE_DRIVE, volume_name, volume_name);
append_entry(SELECTOR_ENTRY_TYPE_DRIVE,
volume_name, volume_name);
i++;
}
// mark first filename entry // mark first filename entry
first = m_entrylist.size() + 1; std::size_t const first = m_entrylist.size() + 1;
// build the menu for each item // build the menu for each item
if (err == osd_file::error::NONE) if (osd_file::error::NONE != err)
{ {
while((dirent = util::zippath_readdir(directory)) != nullptr) osd_printf_verbose("menu_file_selector::populate: error opening directory '%s' (%d)\n", m_current_directory.c_str(), int(err));
}
else
{
for (osd::directory::entry const *dirent = util::zippath_readdir(directory); dirent; dirent = util::zippath_readdir(directory))
{ {
// append a dirent entry // append a dirent entry
entry = append_dirent_entry(dirent); file_selector_entry const *entry = append_dirent_entry(dirent);
if (entry)
if (entry != nullptr)
{ {
// set the selected item to be the first non-parent directory or file // set the selected item to be the first non-parent directory or file
if ((selected_entry == nullptr) && strcmp(dirent->name, "..")) if (!selected_entry && strcmp(dirent->name, ".."))
selected_entry = entry; selected_entry = entry;
// do we have to select this file? // do we have to select this file?
@ -356,29 +341,31 @@ void menu_file_selector::populate(float &customtop, float &custombottom)
} }
} }
} }
if (directory)
util::zippath_closedir(directory);
// sort the menu entries // sort the menu entries
const std::collate<wchar_t> &coll = std::use_facet<std::collate<wchar_t>>(std::locale()); const std::collate<wchar_t> &coll = std::use_facet<std::collate<wchar_t>>(std::locale());
std::sort(m_entrylist.begin()+first, m_entrylist.end(), [&coll](file_selector_entry const &x, file_selector_entry const &y) std::sort(
m_entrylist.begin() + first,
m_entrylist.end(),
[&coll] (file_selector_entry const &x, file_selector_entry const &y)
{ {
std::wstring xstr = wstring_from_utf8(x.basename); std::wstring const xstr = wstring_from_utf8(x.basename);
std::wstring ystr = wstring_from_utf8(y.basename); std::wstring const ystr = wstring_from_utf8(y.basename);
return coll.compare(xstr.data(), xstr.data()+xstr.size(), ystr.data(), ystr.data()+ystr.size()) < 0; return coll.compare(xstr.data(), xstr.data()+xstr.size(), ystr.data(), ystr.data()+ystr.size()) < 0;
}); });
// append all of the menu entries // append all of the menu entries
for (auto &entry : m_entrylist) for (file_selector_entry const &entry : m_entrylist)
append_entry_menu_item(&entry); append_entry_menu_item(&entry);
// set the selection (if we have one) // set the selection (if we have one)
if (selected_entry != nullptr) if (selected_entry)
set_selection((void *)selected_entry); set_selection((void *)selected_entry);
// set up custom render proc // set up custom render proc
customtop = ui().get_line_height() + 3.0f * UI_BOX_TB_BORDER; customtop = ui().get_line_height() + 3.0f * UI_BOX_TB_BORDER;
if (directory != nullptr)
util::zippath_closedir(directory);
} }
@ -426,7 +413,7 @@ void menu_file_selector::handle()
if (err != osd_file::error::NONE) if (err != osd_file::error::NONE)
{ {
// this path is problematic; present the user with an error and bail // this path is problematic; present the user with an error and bail
ui().popup_time(1, "Error accessing %s", entry->fullpath); ui().popup_time(1, _("Error accessing %s"), entry->fullpath);
break; break;
} }
m_current_directory.assign(entry->fullpath); m_current_directory.assign(entry->fullpath);

View File

@ -16,6 +16,7 @@
#include "ui/menu.h" #include "ui/menu.h"
namespace ui { namespace ui {
// ======================> menu_file_selector // ======================> menu_file_selector
class menu_file_selector : public menu class menu_file_selector : public menu
@ -30,7 +31,16 @@ public:
FILE FILE
}; };
menu_file_selector(mame_ui_manager &mui, render_container &container, device_image_interface *image, std::string &current_directory, std::string &current_file, bool has_empty, bool has_softlist, bool has_create, result &result); menu_file_selector(
mame_ui_manager &mui,
render_container &container,
device_image_interface *image,
std::string &current_directory,
std::string &current_file,
bool has_empty,
bool has_softlist,
bool has_create,
result &result);
virtual ~menu_file_selector() override; virtual ~menu_file_selector() override;
protected: protected:
@ -59,12 +69,12 @@ private:
}; };
// internal state // internal state
device_image_interface * m_image; device_image_interface *const m_image;
std::string & m_current_directory; std::string & m_current_directory;
std::string & m_current_file; std::string & m_current_file;
bool m_has_empty; bool const m_has_empty;
bool m_has_softlist; bool const m_has_softlist;
bool m_has_create; bool const m_has_create;
result & m_result; result & m_result;
std::vector<file_selector_entry> m_entrylist; std::vector<file_selector_entry> m_entrylist;
std::string m_hover_directory; std::string m_hover_directory;
@ -95,16 +105,20 @@ public:
WRITE_OTHER, WRITE_OTHER,
WRITE_DIFF WRITE_DIFF
}; };
menu_select_rw(mame_ui_manager &mui, render_container &container, menu_select_rw(
bool can_in_place, result &result); mame_ui_manager &mui,
render_container &container,
bool can_in_place,
result &result);
virtual ~menu_select_rw() override; virtual ~menu_select_rw() override;
virtual void populate(float &customtop, float &custombottom) override;
virtual void handle() override;
static void *itemref_from_result(result result); static void *itemref_from_result(result result);
static result result_from_itemref(void *itemref); static result result_from_itemref(void *itemref);
private: private:
virtual void populate(float &customtop, float &custombottom) override;
virtual void handle() override;
// internal state // internal state
bool m_can_in_place; bool m_can_in_place;
result & m_result; result & m_result;

View File

@ -158,6 +158,7 @@ const osd::directory::entry *posix_directory::read()
case DT_REG: case DT_REG:
m_entry.type = entry::entry_type::FILE; m_entry.type = entry::entry_type::FILE;
break; break;
case DT_UNKNOWN:
case DT_LNK: case DT_LNK:
if (stat_err) if (stat_err)
m_entry.type = entry::entry_type::OTHER; m_entry.type = entry::entry_type::OTHER;

View File

@ -446,7 +446,7 @@ bool osd_is_absolute_path(std::string const &path)
if (!path.empty() && is_path_separator(path[0])) if (!path.empty() && is_path_separator(path[0]))
return true; return true;
#if !defined(WIN32) #if !defined(WIN32)
else if (!path.empty() && (path[0] == '.')) else if (!path.empty() && (path[0] == '.') && (!path[1] || is_path_separator(path[1]))) // FIXME: why is this even here? foo/./bar is a valid way to refer to foo/bar
return true; return true;
#elif !defined(UNDER_CE) #elif !defined(UNDER_CE)
else if ((path.length() > 1) && (path[1] == ':')) else if ((path.length() > 1) && (path[1] == ':'))