openMSX
|
Classes | |
struct | FClose |
Typedefs | |
using | FILE_t = std::unique_ptr< FILE, FClose > |
using | Stat = stat |
Functions | |
bool | needsTildeExpansion (std::string_view path) |
Returns true iff expandTilde(s) would have an effect. | |
string | expandTilde (std::string path) |
Expand the '~' character to the users home directory. | |
void | mkdir (zstring_view path, mode_t mode) |
Create the specified directory. | |
void | mkdirp (std::string path) |
Acts like the unix command "mkdir -p". | |
int | unlink (zstring_view path) |
Call unlink() in a platform-independent manner. | |
int | rmdir (zstring_view path) |
Call rmdir() in a platform-independent manner. | |
int | deleteRecursive (const std::string &path) |
FILE_t | openFile (zstring_view filename, zstring_view mode) |
Call fopen() in a platform-independent manner. | |
void | openOfStream (std::ofstream &stream, zstring_view filename) |
Open an ofstream in a platform-independent manner. | |
void | openOfStream (std::ofstream &stream, zstring_view filename, std::ios_base::openmode mode) |
Open an ofstream in a platform-independent manner. | |
string_view | getFilename (std::string_view path) |
Returns the file portion of a path name. | |
string_view | getDirName (std::string_view path) |
Returns the directory portion of a path. | |
string_view | getExtension (std::string_view path) |
Returns the extension portion of a path. | |
string_view | stripExtension (std::string_view path) |
Returns the path without extension. | |
string | join (std::string_view part1, std::string_view part2) |
Join two paths. | |
string | join (string_view part1, string_view part2, string_view part3) |
string | join (string_view part1, string_view part2, string_view part3, string_view part4) |
string | getCurrentWorkingDirectory () |
Returns the current working directory. | |
string | getAbsolutePath (std::string_view path) |
Transform given path into an absolute path. | |
bool | isAbsolutePath (std::string_view path) |
Checks whether it's a absolute path or not. | |
string | getUserHomeDir (std::string_view username) |
Get user's home directory. | |
const string & | getUserOpenMSXDir () |
Get the openMSX dir in the user's home directory. | |
const string & | getUserDataDir () |
Get the openMSX data dir in the user's home directory. | |
const string & | getSystemDataDir () |
Get system directory. | |
const string & | getSystemDocDir () |
Get system doc directory. | |
std::optional< Stat > | getStat (zstring_view filename) |
Call stat() and return the stat structure. | |
bool | isRegularFile (const Stat &st) |
bool | isRegularFile (zstring_view filename) |
Is this a regular file (no directory, device, ..)? | |
bool | isDirectory (const Stat &st) |
bool | isDirectory (zstring_view directory) |
Is this a directory? | |
bool | exists (zstring_view filename) |
Does this file (directory) exists? | |
string | getNextNumberedFileName (std::string_view directory, std::string_view prefix, std::string_view extension, bool addSeparator=false) |
Gets the next numbered file name with the specified prefix in the specified directory, with the specified extension. | |
string | parseCommandFileArgument (std::string_view argument, std::string_view directory, std::string_view prefix, std::string_view extension) |
Helper function for parsing filename arguments in Tcl commands. | |
string | getTempDir () |
Get the name of the temp directory on the system. | |
FILE_t | openUniqueFile (const std::string &directory, std::string &filename) |
Open a new file with a unique name in the provided directory. | |
int | deleteRecursive (zstring_view path) |
Recursively delete a file or directory and (in case of a directory) all its sub-components. | |
const std::string & | getConventionalPath (const std::string &path) |
Returns the path in conventional path-delimiter. | |
std::string | getConventionalPath (std::string &&path) |
const std::string & | getNativePath (const std::string &path) |
Returns the path in native path-delimiter. | |
std::string | getNativePath (std::string &&path) |
const std::string & | expandCurrentDirFromDrive (const std::string &path) |
Get the current directory of the specified drive Linux: return the given string unchanged. | |
std::string | expandCurrentDirFromDrive (std::string &&path) |
time_t | getModificationDate (const Stat &st) |
Get the date/time of last modification. | |
std::string | findResourceDir (const std::string &resourceDirName) |
Variables | |
const char | nativePathSeparator |
using openmsx::FileOperations::FILE_t = typedef std::unique_ptr<FILE, FClose> |
Definition at line 20 of file FileOperations.hh.
using openmsx::FileOperations::Stat = typedef stat |
Definition at line 244 of file FileOperations.hh.
int openmsx::FileOperations::deleteRecursive | ( | const std::string & | path | ) |
Definition at line 222 of file FileOperations.cc.
References deleteRecursive(), openmsx::ReadDir::getEntry(), isDirectory(), rmdir(), and unlink().
Referenced by deleteRecursive(), and TEST_CASE().
int openmsx::FileOperations::deleteRecursive | ( | zstring_view | path | ) |
Recursively delete a file or directory and (in case of a directory) all its sub-components.
bool openmsx::FileOperations::exists | ( | zstring_view | filename | ) |
Does this file (directory) exists?
Definition at line 595 of file FileOperations.cc.
References getStat().
Referenced by parseCommandFileArgument(), openmsx::CassettePlayer::serialize(), openmsx::DiskChanger::serialize(), openmsx::ImGuiReverseBar::showMenu(), and openmsx::Filename::updateAfterLoadState().
|
inline |
Get the current directory of the specified drive Linux: return the given string unchanged.
Definition at line 182 of file FileOperations.hh.
|
inline |
Definition at line 183 of file FileOperations.hh.
std::string openmsx::FileOperations::expandTilde | ( | std::string | path | ) |
Expand the '~' character to the users home directory.
path | Pathname, with or without '~' character |
Definition at line 83 of file FileOperations.cc.
References getUserHomeDir(), and needsTildeExpansion().
Referenced by openmsx::NowindCommand::execute(), openmsx::RestoreMachineCommand::execute(), openmsx::FilePoolCore::getFile(), getUserOpenMSXDir(), and parseCommandFileArgument().
std::string openmsx::FileOperations::findResourceDir | ( | const std::string & | resourceDirName | ) |
Referenced by getSystemDataDir(), and getSystemDocDir().
std::string openmsx::FileOperations::getAbsolutePath | ( | std::string_view | path | ) |
Transform given path into an absolute path.
FileException |
Definition at line 363 of file FileOperations.cc.
References getCurrentWorkingDirectory(), isAbsolutePath(), and join().
Referenced by openmsx::HardwareConfig::createRomConfig(), getSystemDataDir(), getSystemDocDir(), and openmsx::Filename::updateAfterLoadState().
|
inline |
Returns the path in conventional path-delimiter.
path | The pathname. |
Definition at line 157 of file FileOperations.hh.
Referenced by openmsx::ImGuiOpenFile::doPaint(), getSystemDataDir(), getSystemDocDir(), getUserHomeDir(), mkdirp(), and openmsx::CommandLineParser::parse().
|
inline |
Definition at line 158 of file FileOperations.hh.
std::string openmsx::FileOperations::getCurrentWorkingDirectory | ( | ) |
Returns the current working directory.
FileException | (for example when directory has been deleted). |
Definition at line 344 of file FileOperations.cc.
Referenced by getAbsolutePath().
std::string_view openmsx::FileOperations::getDirName | ( | std::string_view | path | ) |
Returns the directory portion of a path.
path | The pathname |
Definition at line 284 of file FileOperations.cc.
Referenced by parseCommandFileArgument().
std::string_view openmsx::FileOperations::getExtension | ( | std::string_view | path | ) |
Returns the extension portion of a path.
path | The pathname |
Definition at line 292 of file FileOperations.cc.
References getFilename().
Referenced by openmsx::ImGuiManager::paintImGui().
std::string_view openmsx::FileOperations::getFilename | ( | std::string_view | path | ) |
Returns the file portion of a path name.
path | The pathname |
Definition at line 276 of file FileOperations.cc.
Referenced by openmsx::HardwareConfig::createRomConfig(), openmsx::ImGuiMedia::displayNameForDriveContent(), openmsx::ImGuiMedia::displayNameForRom(), getExtension(), openmsx::FileBase::getOriginalName(), openmsx::ImGuiReverseBar::showMenu(), and openmsx::ImGuiSettings::showMenu().
|
inline |
Get the date/time of last modification.
Is guaranteed to not be INVALID_TIME_T.
Definition at line 272 of file FileOperations.hh.
References openmsx::Date::adjustTimeT().
|
inline |
Returns the path in native path-delimiter.
path | The pathname. |
Definition at line 171 of file FileOperations.hh.
Referenced by openmsx::LocalFile::LocalFile(), openmsx::LocalFile::LocalFile(), mkdir(), and openmsx::LocalFile::preCacheFile().
|
inline |
Definition at line 172 of file FileOperations.hh.
std::string openmsx::FileOperations::getNextNumberedFileName | ( | std::string_view | directory, |
std::string_view | prefix, | ||
std::string_view | extension, | ||
bool | addSeparator = false |
||
) |
Gets the next numbered file name with the specified prefix in the specified directory, with the specified extension.
Examples: automatic numbering of filenames for new screenshots or sound logs.
directory | Name of the directory in the openMSX user dir in which should be searched for the next filename |
prefix | Prefix of the filename with numbers |
extension | Extension of the filename with numbers |
addSeparator | Add separator character between 'prefix' and 'number'. |
Definition at line 615 of file FileOperations.cc.
References openmsx::ReadDir::getEntry(), getUserOpenMSXDir(), join(), mkdirp(), and strCat().
Referenced by parseCommandFileArgument(), openmsx::Paper::save(), and openmsx::ImGuiReverseBar::showMenu().
std::optional< Stat > openmsx::FileOperations::getStat | ( | zstring_view | filename | ) |
Call stat() and return the stat structure.
filename | the file path |
Definition at line 547 of file FileOperations.cc.
References zstring_view::c_str().
Referenced by exists(), openmsx::detail::foreach_dirent(), isDirectory(), and isRegularFile().
const std::string & openmsx::FileOperations::getSystemDataDir | ( | ) |
Get system directory.
UNI*Y: statically defined as "/opt/openMSX/share". Win32: use "same directory as .exe" + "/share".
Definition at line 447 of file FileOperations.cc.
References findResourceDir(), getAbsolutePath(), and getConventionalPath().
Referenced by getTempDir(), and openmsx::Interpreter::Interpreter().
const std::string & openmsx::FileOperations::getSystemDocDir | ( | ) |
Get system doc directory.
Win32: use "same directory as .exe" + "/doc".
Definition at line 481 of file FileOperations.cc.
References findResourceDir(), getAbsolutePath(), and getConventionalPath().
Referenced by openmsx::ImGuiHelp::showMenu().
std::string openmsx::FileOperations::getTempDir | ( | ) |
Get the name of the temp directory on the system.
Typically /tmp on *nix and C:/WINDOWS/TEMP on windows
Definition at line 677 of file FileOperations.cc.
References getSystemDataDir(), and openmsx::L.
Referenced by TEST_CASE().
const std::string & openmsx::FileOperations::getUserDataDir | ( | ) |
Get the openMSX data dir in the user's home directory.
Default value is "~/.openMSX/share" (UNIX) or "~/openMSX/share" (win)
Definition at line 436 of file FileOperations.cc.
References getUserOpenMSXDir().
Referenced by openmsx::Interpreter::Interpreter().
std::string openmsx::FileOperations::getUserHomeDir | ( | std::string_view | username | ) |
Get user's home directory.
username | The name of the user |
Definition at line 387 of file FileOperations.cc.
References getConventionalPath().
Referenced by expandTilde().
const std::string & openmsx::FileOperations::getUserOpenMSXDir | ( | ) |
Get the openMSX dir in the user's home directory.
Default value is "~/.openMSX" (UNIX) or "~/openMSX" (win)
Definition at line 417 of file FileOperations.cc.
References expandTilde(), and strCat().
Referenced by getNextNumberedFileName(), getUserDataDir(), parseCommandFileArgument(), and openmsx::ImGuiReverseBar::showMenu().
bool openmsx::FileOperations::isAbsolutePath | ( | std::string_view | path | ) |
Checks whether it's a absolute path or not.
path | The pathname. |
Definition at line 373 of file FileOperations.cc.
Referenced by getAbsolutePath(), join(), and mkdirp().
bool openmsx::FileOperations::isDirectory | ( | const Stat & | st | ) |
Definition at line 584 of file FileOperations.cc.
Referenced by deleteRecursive(), openmsx::DirAsDSK::DirAsDSK(), openmsx::detail::foreach_dirent(), isDirectory(), mkdirp(), and openmsx::ImGuiManager::paintImGui().
bool openmsx::FileOperations::isDirectory | ( | zstring_view | directory | ) |
Is this a directory?
Definition at line 589 of file FileOperations.cc.
References getStat(), and isDirectory().
bool openmsx::FileOperations::isRegularFile | ( | const Stat & | st | ) |
Definition at line 574 of file FileOperations.cc.
Referenced by openmsx::HardwareConfig::createRomConfig(), openmsx::detail::foreach_dirent(), openmsx::Reactor::getHwConfigs(), isRegularFile(), openmsx::OSDRectangle::setProperty(), and openmsx::OSDText::setProperty().
bool openmsx::FileOperations::isRegularFile | ( | zstring_view | filename | ) |
Is this a regular file (no directory, device, ..)?
Definition at line 578 of file FileOperations.cc.
References getStat(), and isRegularFile().
std::string openmsx::FileOperations::join | ( | std::string_view | part1, |
std::string_view | part2 | ||
) |
Join two paths.
Returns the equivalent of 'path1 + '/' + path2'. If 'part2' is an absolute path, that path is returned ('part1' is ignored). If 'part1' is empty or if it already ends with '/', there will be no extra '/' added between 'part1' and 'part2'.
Definition at line 309 of file FileOperations.cc.
References isAbsolutePath(), and strCat().
Referenced by getAbsolutePath(), openmsx::Reactor::getHwConfigs(), getNextNumberedFileName(), join(), join(), and openmsx::FileContext::resolveCreate().
std::string openmsx::FileOperations::join | ( | string_view | part1, |
string_view | part2, | ||
string_view | part3 | ||
) |
Definition at line 319 of file FileOperations.cc.
References join().
std::string openmsx::FileOperations::join | ( | string_view | part1, |
string_view | part2, | ||
string_view | part3, | ||
string_view | part4 | ||
) |
Definition at line 324 of file FileOperations.cc.
References join().
void openmsx::FileOperations::mkdir | ( | zstring_view | path, |
mode_t | mode | ||
) |
Create the specified directory.
Does some sanity checks so that it behaves the same on all platforms. The mode parameter is ignored on windows. For compatibility with *nix creating the root dir (or a drive name) is not an error instead the operation is silently ignored. This function can only create one directory at-a-time. You probably want to use the mkdirp function (see below).
path | The path of the directory to create |
mode | The permission bits (*nix only) |
FileException |
Definition at line 108 of file FileOperations.cc.
References zstring_view::c_str(), zstring_view::ends_with(), getNativePath(), and mkdir().
void openmsx::FileOperations::mkdirp | ( | std::string | path | ) |
Acts like the unix command "mkdir -p".
Creates the specified directory, including the parent directories.
path | The path of the directory to create |
FileException |
Definition at line 134 of file FileOperations.cc.
References getConventionalPath(), isAbsolutePath(), isDirectory(), and mkdir().
Referenced by getNextNumberedFileName(), openmsx::LocalFile::LocalFile(), parseCommandFileArgument(), openmsx::FileContext::resolveCreate(), and TEST_CASE().
bool openmsx::FileOperations::needsTildeExpansion | ( | std::string_view | path | ) |
Returns true iff expandTilde(s) would have an effect.
In other words: expandTilde(s) != s Mostly useful to assert that tilde expansion has already been done.
Definition at line 78 of file FileOperations.cc.
Referenced by expandTilde(), openmsx::FileContext::resolve(), and openmsx::FileContext::resolveCreate().
FILE_t openmsx::FileOperations::openFile | ( | zstring_view | filename, |
zstring_view | mode | ||
) |
Call fopen() in a platform-independent manner.
filename | the file path |
mode | the mode parameter, same as fopen |
Definition at line 239 of file FileOperations.cc.
References zstring_view::c_str(), and zstring_view::find().
Referenced by openmsx::ArchiveBase< MemInputArchive >::attribute(), openmsx::LocalFile::LocalFile(), openmsx::LocalFile::LocalFile(), openmsx::MidiInReader::plugHelper(), and openmsx::RS232Tester::plugHelper().
void openmsx::FileOperations::openOfStream | ( | std::ofstream & | stream, |
zstring_view | filename | ||
) |
Open an ofstream in a platform-independent manner.
stream | an ofstream |
filename | the file path |
Definition at line 253 of file FileOperations.cc.
References zstring_view::c_str().
Referenced by openmsx::MidiOutLogger::plugHelper(), and openmsx::RS232Tester::plugHelper().
void openmsx::FileOperations::openOfStream | ( | std::ofstream & | stream, |
zstring_view | filename, | ||
std::ios_base::openmode | mode | ||
) |
Open an ofstream in a platform-independent manner.
stream | an ofstream |
filename | the file path |
mode | the open mode |
Definition at line 264 of file FileOperations.cc.
References zstring_view::c_str().
FILE_t openmsx::FileOperations::openUniqueFile | ( | const std::string & | directory, |
std::string & | filename | ||
) |
Open a new file with a unique name in the provided directory.
directory | directory in which to open the temp file |
filename | [output param] the name of the resulting file |
Definition at line 707 of file FileOperations.cc.
References openmsx::L.
std::string openmsx::FileOperations::parseCommandFileArgument | ( | std::string_view | argument, |
std::string_view | directory, | ||
std::string_view | prefix, | ||
std::string_view | extension | ||
) |
Helper function for parsing filename arguments in Tcl commands.
Definition at line 648 of file FileOperations.cc.
References exists(), expandTilde(), getDirName(), getNextNumberedFileName(), getUserOpenMSXDir(), mkdirp(), and strCat().
Referenced by openmsx::CassettePlayerCommand::execute(), and openmsx::ImGuiReverseBar::showMenu().
int openmsx::FileOperations::rmdir | ( | zstring_view | path | ) |
Call rmdir() in a platform-independent manner.
Definition at line 177 of file FileOperations.cc.
References zstring_view::c_str().
Referenced by deleteRecursive().
std::string_view openmsx::FileOperations::stripExtension | ( | std::string_view | path | ) |
Returns the path without extension.
path | The pathname |
Definition at line 301 of file FileOperations.cc.
Referenced by openmsx::ImGuiReverseBar::showMenu(), and openmsx::ImGuiSettings::showMenu().
int openmsx::FileOperations::unlink | ( | zstring_view | path | ) |
Call unlink() in a platform-independent manner.
Definition at line 168 of file FileOperations.cc.
References zstring_view::c_str().
Referenced by deleteRecursive(), openmsx::ImGuiSettings::showMenu(), TEST_CASE(), and openmsx::AviWriter::~AviWriter().
const char openmsx::FileOperations::nativePathSeparator |
Definition at line 22 of file FileOperations.hh.