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. More... | |
string | expandTilde (std::string path) |
Expand the '~' character to the users home directory. More... | |
void | mkdir (zstring_view path, mode_t mode) |
Create the specified directory. More... | |
void | mkdirp (std::string path) |
Acts like the unix command "mkdir -p". More... | |
int | unlink (zstring_view path) |
Call unlink() in a platform-independent manner. More... | |
int | rmdir (zstring_view path) |
Call rmdir() in a platform-independent manner. More... | |
int | deleteRecursive (zstring_view path) |
Recursively delete a file or directory and (in case of a directory) all its sub-components. More... | |
FILE_t | openFile (zstring_view filename, zstring_view mode) |
Call fopen() in a platform-independent manner. More... | |
void | openOfStream (std::ofstream &stream, zstring_view filename) |
Open an ofstream in a platform-independent manner. More... | |
void | openOfStream (std::ofstream &stream, zstring_view filename, std::ios_base::openmode mode) |
Open an ofstream in a platform-independent manner. More... | |
string_view | getFilename (std::string_view path) |
Returns the file portion of a path name. More... | |
string_view | getDirName (std::string_view path) |
Returns the directory portion of a path. More... | |
string_view | getExtension (std::string_view path) |
Returns the extension portion of a path. More... | |
string_view | stripExtension (std::string_view path) |
Returns the path without extension. More... | |
string | join (std::string_view part1, std::string_view part2) |
Join two paths. More... | |
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. More... | |
string | getAbsolutePath (std::string_view path) |
Transform given path into an absolute path. More... | |
bool | isAbsolutePath (std::string_view path) |
Checks whether it's a absolute path or not. More... | |
string | getUserHomeDir (std::string_view username) |
Get user's home directory. More... | |
const string & | getUserOpenMSXDir () |
Get the openMSX dir in the user's home directory. More... | |
const string & | getUserDataDir () |
Get the openMSX data dir in the user's home directory. More... | |
const string & | getSystemDataDir () |
Get system directory. More... | |
std::optional< Stat > | getStat (zstring_view filename) |
Call stat() and return the stat structure. More... | |
bool | isRegularFile (const Stat &st) |
bool | isRegularFile (zstring_view filename) |
Is this a regular file (no directory, device, ..)? More... | |
bool | isDirectory (const Stat &st) |
bool | isDirectory (zstring_view directory) |
Is this a directory? More... | |
bool | exists (zstring_view filename) |
Does this file (directory) exists? More... | |
string | getNextNumberedFileName (std::string_view directory, std::string_view prefix, std::string_view extension) |
Gets the next numbered file name with the specified prefix in the specified directory, with the specified extension. More... | |
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. More... | |
string | getTempDir () |
Get the name of the temp directory on the system. More... | |
FILE_t | openUniqueFile (const std::string &directory, std::string &filename) |
Open a new file with a unique name in the provided directory. More... | |
const std::string & | getConventionalPath (const std::string &path) |
Returns the path in conventional path-delimiter. More... | |
std::string | getConventionalPath (std::string &&path) |
const std::string & | getNativePath (const std::string &path) |
Returns the path in native path-delimiter. More... | |
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. More... | |
std::string | expandCurrentDirFromDrive (std::string &&path) |
time_t | getModificationDate (const Stat &st) |
Get the date/time of last modification. More... | |
std::string | findShareDir () |
Variables | |
const char | nativePathSeparator |
using openmsx::FileOperations::FILE_t = typedef std::unique_ptr<FILE, FClose> |
Definition at line 19 of file FileOperations.hh.
using openmsx::FileOperations::Stat = typedef stat |
Definition at line 236 of file FileOperations.hh.
int openmsx::FileOperations::deleteRecursive | ( | zstring_view | path | ) |
Recursively delete a file or directory and (in case of a directory) all its sub-components.
Definition at line 210 of file FileOperations.cc.
References zstring_view::c_str().
Referenced by TEST_CASE().
bool openmsx::FileOperations::exists | ( | zstring_view | filename | ) |
Does this file (directory) exists?
Definition at line 565 of file FileOperations.cc.
Referenced by openmsx::CartridgeSlotManager::allocateAnyPrimarySlot(), openmsx::CartridgeSlotManager::allocateSlot(), openmsx::CartridgeSlotManager::allocateSpecificPrimarySlot(), openmsx::CartridgeSlotManager::freeSlot(), openmsx::CartridgeSlotManager::getAnyFreeSlot(), openmsx::CartridgeSlotManager::getSpecificSlot(), openmsx::CassettePlayer::serialize(), openmsx::DiskChanger::serialize(), openmsx::Filename::updateAfterLoadState(), and openmsx::CartridgeSlotManager::~CartridgeSlotManager().
|
inline |
Get the current directory of the specified drive Linux: return the given string unchanged.
Definition at line 181 of file FileOperations.hh.
|
inline |
Definition at line 182 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 84 of file FileOperations.cc.
References getUserHomeDir(), and needsTildeExpansion().
Referenced by openmsx::RestoreMachineCommand::execute(), openmsx::FilePoolCore::getFile(), and getUserOpenMSXDir().
std::string openmsx::FileOperations::findShareDir | ( | ) |
std::string openmsx::FileOperations::getAbsolutePath | ( | std::string_view | path | ) |
Transform given path into an absolute path.
FileException |
Definition at line 364 of file FileOperations.cc.
References getCurrentWorkingDirectory(), isAbsolutePath(), and join().
Referenced by openmsx::HardwareConfig::createRomConfig(), and openmsx::Filename::updateAfterLoadState().
|
inline |
Returns the path in conventional path-delimiter.
path | The pathname. |
Definition at line 156 of file FileOperations.hh.
Referenced by getUserHomeDir(), mkdirp(), and openmsx::CommandLineParser::parse().
|
inline |
Definition at line 157 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 345 of file FileOperations.cc.
References MAXPATHLEN, and utf8::utf16to8().
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 285 of file FileOperations.cc.
std::string_view openmsx::FileOperations::getExtension | ( | std::string_view | path | ) |
Returns the extension portion of a path.
path | The pathname |
Definition at line 293 of file FileOperations.cc.
References getFilename().
std::string_view openmsx::FileOperations::getFilename | ( | std::string_view | path | ) |
Returns the file portion of a path name.
path | The pathname |
Definition at line 277 of file FileOperations.cc.
Referenced by openmsx::HardwareConfig::createRomConfig(), getExtension(), and openmsx::FileBase::getOriginalName().
|
inline |
Get the date/time of last modification.
Is guaranteed to not be INVALID_TIME_T.
Definition at line 264 of file FileOperations.hh.
References openmsx::Date::adjustTimeT().
|
inline |
Returns the path in native path-delimiter.
path | The pathname. |
Definition at line 170 of file FileOperations.hh.
Referenced by openmsx::LocalFile::LocalFile(), mkdir(), and openmsx::LocalFile::preCacheFile().
|
inline |
Definition at line 171 of file FileOperations.hh.
std::string openmsx::FileOperations::getNextNumberedFileName | ( | std::string_view | directory, |
std::string_view | prefix, | ||
std::string_view | extension | ||
) |
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 |
Definition at line 588 of file FileOperations.cc.
References getUserOpenMSXDir(), mkdirp(), and strCat().
Referenced by openmsx::StoreMachineCommand::execute(), parseCommandFileArgument(), and openmsx::Paper::save().
std::optional< Stat > openmsx::FileOperations::getStat | ( | zstring_view | filename | ) |
Call stat() and return the stat structure.
filename | the file path |
Definition at line 517 of file FileOperations.cc.
Referenced by openmsx::detail::foreach_dirent(), and isDirectory().
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 448 of file FileOperations.cc.
References MAXPATHLEN, and utf8::unchecked::size().
Referenced by getTempDir(), and openmsx::Interpreter::Interpreter().
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 644 of file FileOperations.cc.
References getSystemDataDir(), openmsx::L, utf8::utf16to8(), and VLA.
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 437 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 388 of file FileOperations.cc.
References getConventionalPath(), MAXPATHLEN, and utf8::utf16to8().
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 418 of file FileOperations.cc.
References expandTilde(), and strCat().
Referenced by openmsx::RestoreMachineCommand::execute(), getNextNumberedFileName(), and getUserDataDir().
bool openmsx::FileOperations::isAbsolutePath | ( | std::string_view | path | ) |
Checks whether it's a absolute path or not.
path | The pathname. |
Definition at line 374 of file FileOperations.cc.
Referenced by getAbsolutePath(), and join().
bool openmsx::FileOperations::isDirectory | ( | const Stat & | st | ) |
Definition at line 554 of file FileOperations.cc.
Referenced by openmsx::DirAsDSK::DirAsDSK(), openmsx::detail::foreach_dirent(), isDirectory(), and mkdirp().
bool openmsx::FileOperations::isDirectory | ( | zstring_view | directory | ) |
Is this a directory?
Definition at line 559 of file FileOperations.cc.
References getStat(), and isDirectory().
bool openmsx::FileOperations::isRegularFile | ( | const Stat & | st | ) |
Definition at line 544 of file FileOperations.cc.
Referenced by openmsx::HardwareConfig::createRomConfig(), openmsx::detail::foreach_dirent(), openmsx::Reactor::getHwConfigs(), 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 548 of file FileOperations.cc.
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 310 of file FileOperations.cc.
References isAbsolutePath(), and strCat().
Referenced by getAbsolutePath(), openmsx::Reactor::getHwConfigs(), join(), and openmsx::FileContext::resolveCreate().
std::string openmsx::FileOperations::join | ( | string_view | part1, |
string_view | part2, | ||
string_view | part3 | ||
) |
Definition at line 320 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 325 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 109 of file FileOperations.cc.
References zstring_view::c_str(), zstring_view::ends_with(), getNativePath(), mkdir(), and utf8::utf8to16().
Referenced by 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 135 of file FileOperations.cc.
References getConventionalPath(), and isDirectory().
Referenced by getNextNumberedFileName(), openmsx::LocalFile::LocalFile(), 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 79 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 240 of file FileOperations.cc.
References zstring_view::c_str(), zstring_view::find(), and utf8::utf8to16().
Referenced by openmsx::LocalFile::LocalFile(), openmsx::MidiInReader::plugHelper(), openmsx::RS232Tester::plugHelper(), and openmsx::XmlOutputArchive::XmlOutputArchive().
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 254 of file FileOperations.cc.
References zstring_view::c_str(), and utf8::utf8to16().
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 265 of file FileOperations.cc.
References zstring_view::c_str(), and utf8::utf8to16().
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 675 of file FileOperations.cc.
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 615 of file FileOperations.cc.
References getNextNumberedFileName().
int openmsx::FileOperations::rmdir | ( | zstring_view | path | ) |
Call rmdir() in a platform-independent manner.
Definition at line 178 of file FileOperations.cc.
References zstring_view::c_str(), rmdir(), and utf8::utf8to16().
Referenced by rmdir().
std::string_view openmsx::FileOperations::stripExtension | ( | std::string_view | path | ) |
Returns the path without extension.
path | The pathname |
Definition at line 302 of file FileOperations.cc.
int openmsx::FileOperations::unlink | ( | zstring_view | path | ) |
Call unlink() in a platform-independent manner.
Definition at line 169 of file FileOperations.cc.
References zstring_view::c_str(), unlink(), and utf8::utf8to16().
Referenced by unlink(), and openmsx::AviWriter::~AviWriter().
const char openmsx::FileOperations::nativePathSeparator |
Definition at line 21 of file FileOperations.hh.