diff options
author | 2021-01-20 17:46:03 -0500 | |
---|---|---|
committer | 2021-01-20 18:06:15 -0500 | |
commit | 91921618c2e06bd0ed073b8efccd31a127c9012d (patch) | |
tree | d3958b32d8db82540cd31083766b22991eb8e8ae /src/emu/image.cpp | |
parent | c691b79cce315acdfabe1901cb2b5a1e39957bc1 (diff) |
Much more core std::string_view modernization
- Remove corestr.h from emu.h; update a few source files to not use it at all
- Change strtrimspace, strtrimrightspace and core_filename_extract_* to be pure functions taking a std::string_view by value and returning the same type
- Change strmakeupper and strmakelower to be pure functions taking a std::string_view and constructing a std::string
- Remove the string-modifying version of zippath_parent
- Change tag-based lookup functions in device_t to take std::string_view instead of const std::string & or const char *
- Remove the subdevice tag cache from device_t (since device finders are now recommended) and replace it with a map covering directly owned subdevices only
- Move the working directory setup method out of device_image_interface (only the UI seems to actually use the full version of this)
- Change output_manager to use std::string_view for output name arguments
- Change core_options to accept std::string_view for most name and value arguments (return values are still C strings for now)
- Change miscellaneous other functions to accept std::string_view arguments
- Remove a few string accessor macros from romload.h
- Remove many unnecessary c_str() calls from logging/error messages
Diffstat (limited to 'src/emu/image.cpp')
-rw-r--r-- | src/emu/image.cpp | 95 |
1 files changed, 91 insertions, 4 deletions
diff --git a/src/emu/image.cpp b/src/emu/image.cpp index 28a704354f0..4b9302fa9d3 100644 --- a/src/emu/image.cpp +++ b/src/emu/image.cpp @@ -8,15 +8,20 @@ ***************************************************************************/ -#include <cctype> - #include "emu.h" -#include "emuopts.h" #include "image.h" + #include "config.h" -#include "xmlfile.h" +#include "drivenum.h" +#include "emuopts.h" #include "softlist.h" +#include "corestr.h" +#include "xmlfile.h" +#include "zippath.h" + +#include <cctype> + //************************************************************************** // IMAGE MANAGER @@ -251,3 +256,85 @@ void image_manager::postdevice_init() /* add a callback for when we shut down */ machine().add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(&image_manager::unload_all, this)); } + + +//************************************************************************** +// WORKING DIRECTORIES +//************************************************************************** + +//------------------------------------------------- +// try_change_working_directory - tries to change +// the working directory, but only if the directory +// actually exists +//------------------------------------------------- + +bool image_manager::try_change_working_directory(std::string &working_directory, const std::string &subdir) +{ + const osd::directory::entry *entry; + bool success = false; + bool done = false; + + auto directory = osd::directory::open(working_directory); + if (directory) + { + while (!done && (entry = directory->read()) != nullptr) + { + if (!core_stricmp(subdir.c_str(), entry->name)) + { + done = true; + success = entry->type == osd::directory::entry::entry_type::DIR; + } + } + + directory.reset(); + } + + // did we successfully identify the directory? + if (success) + working_directory = util::zippath_combine(working_directory, subdir); + + return success; +} + + +//------------------------------------------------- +// setup_working_directory - sets up the working +// directory according to a few defaults +//------------------------------------------------- + +std::string image_manager::setup_working_directory() +{ + bool success = false; + // get user-specified directory and make sure it exists + std::string working_directory = machine().options().sw_path(); + // if multipath, get first + size_t i = working_directory.find_first_of(';'); + if (i != std::string::npos) + working_directory.resize(i); + // validate directory + if (!working_directory.empty()) + if (osd::directory::open(working_directory)) + success = true; + + // if not exist, use previous method + if (!success) + { + // first set up the working directory to be the starting directory + osd_get_full_path(working_directory, "."); + // now try browsing down to "software" + if (try_change_working_directory(working_directory, "software")) + success = true; + } + + if (success) + { + // now down to a directory for this computer + int gamedrv = driver_list::find(machine().system()); + while(gamedrv != -1 && !try_change_working_directory(working_directory, driver_list::driver(gamedrv).name)) + { + gamedrv = driver_list::compatible_with(gamedrv); + } + } + + return working_directory; +} |