mirror of
https://github.com/scummvm/scummvm.git
synced 2024-05-29 01:07:44 -04:00
BACKENDS: Migrate to Path API
This commit is contained in:
parent
04d68d87c0
commit
9bdf1233b1
|
@ -163,7 +163,7 @@ Common::DialogManager::DialogResult MacOSXDialogManager::showFileBrowser(const C
|
|||
BrowserDialogPresenter* presenter = [[BrowserDialogPresenter alloc] init];
|
||||
[presenter performSelectorOnMainThread:@selector(showOpenPanel:) withObject:panel waitUntilDone:YES];
|
||||
if (presenter->_url) {
|
||||
Common::String filename = [[presenter->_url path] UTF8String];
|
||||
Common::Path filename([[presenter->_url path] UTF8String]);
|
||||
choice = Common::FSNode(filename);
|
||||
result = kDialogOk;
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
|
||||
class AssetInputStream : public Common::SeekableReadStream {
|
||||
public:
|
||||
AssetInputStream(AAssetManager *as, const Common::String &path);
|
||||
AssetInputStream(AAssetManager *as, const Common::Path &path);
|
||||
virtual ~AssetInputStream();
|
||||
|
||||
virtual bool eos() const { return _eos; }
|
||||
|
@ -63,9 +63,9 @@ private:
|
|||
bool _eos;
|
||||
};
|
||||
|
||||
AssetInputStream::AssetInputStream(AAssetManager *as, const Common::String &path) :
|
||||
AssetInputStream::AssetInputStream(AAssetManager *as, const Common::Path &path) :
|
||||
_eos(false), _pos(0) {
|
||||
_asset = AAssetManager_open(as, path.c_str(), AASSET_MODE_RANDOM);
|
||||
_asset = AAssetManager_open(as, path.toString(Common::Path::kNativeSeparator).c_str(), AASSET_MODE_RANDOM);
|
||||
_len = AAsset_getLength64(_asset);
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ AndroidAssetArchive::~AndroidAssetArchive() {
|
|||
}
|
||||
|
||||
bool AndroidAssetArchive::hasFile(const Common::Path &path) const {
|
||||
Common::String name = path.toString();
|
||||
Common::String name = path.toString(Common::Path::kNativeSeparator);
|
||||
AAsset *asset = AAssetManager_open(_am, name.c_str(), AASSET_MODE_RANDOM);
|
||||
bool exists = false;
|
||||
if (asset != NULL) {
|
||||
|
@ -132,14 +132,14 @@ int AndroidAssetArchive::listMembers(Common::ArchiveMemberList &member_list) con
|
|||
}
|
||||
|
||||
int count = 0;
|
||||
Common::List<Common::String> dirs;
|
||||
Common::List<Common::Path> dirs;
|
||||
dirs.push_back("");
|
||||
for (const auto& currentDir : dirs) {
|
||||
AAssetDir *dir = AAssetManager_openDir(_am, "");
|
||||
const char *file = AAssetDir_getNextFileName(dir);
|
||||
|
||||
while (file) {
|
||||
member_list.push_back(getMember(currentDir + Common::String(file)));
|
||||
member_list.push_back(getMember(currentDir.appendComponent(file)));
|
||||
++count;
|
||||
file = AAssetDir_getNextFileName(dir);
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ Common::SeekableReadStream *AndroidAssetArchive::createReadStreamForMember(const
|
|||
if (!hasFile(path)) {
|
||||
return nullptr;
|
||||
}
|
||||
return new AssetInputStream(_am, path.toString());
|
||||
return new AssetInputStream(_am, path);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -46,14 +46,11 @@ bool ImageViewer::load(int imageNum) {
|
|||
unload();
|
||||
|
||||
// build string
|
||||
char number[8];
|
||||
Common::sprintf_s(number, "%d", imageNum);
|
||||
Common::String imageNameStr(imageName);
|
||||
Common::String specificImageName = imageNameStr + Common::String(number) + Common::String(".png");
|
||||
Common::Path specificImageName(Common::String::format("%s%d.png",imageName, imageNum));
|
||||
|
||||
// search for image file
|
||||
if (!SearchMan.hasFile(specificImageName)) {
|
||||
PSP_ERROR("file %s not found\n", specificImageName.c_str());
|
||||
PSP_ERROR("file %s not found\n", specificImageName.toString(Common::Path::kNativeSeparator).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -74,19 +71,19 @@ bool ImageViewer::load(int imageNum) {
|
|||
|
||||
char error[100];
|
||||
if (status == PngLoader::BAD_FILE) {
|
||||
Common::sprintf_s(error, "Cannot display %s. Not a proper PNG file", specificImageName.c_str());
|
||||
Common::sprintf_s(error, "Cannot display %s. Not a proper PNG file", specificImageName.toString(Common::Path::kNativeSeparator).c_str());
|
||||
GUI::TimedMessageDialog dialog(Common::U32String(error), 4000);
|
||||
dialog.runModal();
|
||||
return false;
|
||||
} else if (status == PngLoader::OUT_OF_MEMORY) {
|
||||
Common::sprintf_s(error, "Out of memory loading %s. Try making the image smaller", specificImageName.c_str());
|
||||
Common::sprintf_s(error, "Out of memory loading %s. Try making the image smaller", specificImageName.toString(Common::Path::kNativeSeparator).c_str());
|
||||
GUI::TimedMessageDialog dialog(Common::U32String(error), 4000);
|
||||
dialog.runModal();
|
||||
return false;
|
||||
}
|
||||
// try to load the image file
|
||||
if (!image.load()) {
|
||||
Common::sprintf_s(error, "Cannot display %s. Not a proper PNG file", specificImageName.c_str());
|
||||
Common::sprintf_s(error, "Cannot display %s. Not a proper PNG file", specificImageName.toString(Common::Path::kNativeSeparator).c_str());
|
||||
GUI::TimedMessageDialog dialog(Common::U32String(error), 4000);
|
||||
dialog.runModal();
|
||||
return false;
|
||||
|
|
|
@ -132,7 +132,7 @@ void OSystem_MacOSX::addSysArchivesToSearchSet(Common::SearchSet &s, int priorit
|
|||
OSystem_POSIX::addSysArchivesToSearchSet(s, priority);
|
||||
|
||||
// Get URL of the Resource directory of the .app bundle
|
||||
Common::String bundlePath = getResourceAppBundlePathMacOSX();
|
||||
Common::Path bundlePath(getResourceAppBundlePathMacOSX(), Common::Path::kNativeSeparator);
|
||||
if (!bundlePath.empty()) {
|
||||
// Success: search with a depth of 2 so the shaders are found
|
||||
s.add("__OSX_BUNDLE__", new Common::FSDirectory(bundlePath, 2), priority);
|
||||
|
@ -265,7 +265,7 @@ Common::Path OSystem_MacOSX::getDefaultIconsPath() {
|
|||
Common::Path OSystem_MacOSX::getDefaultDLCsPath() {
|
||||
const Common::Path defaultDLCsPath(getAppSupportPathMacOSX() + "/DLCs");
|
||||
|
||||
if (!Posix::assureDirectoryExists(defaultDLCsPath.toString())) {
|
||||
if (!Posix::assureDirectoryExists(defaultDLCsPath.toString(Common::Path::kNativeSeparator))) {
|
||||
return Common::Path();
|
||||
}
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ Common::Path OSystem_POSIX::getDefaultConfigFileName() {
|
|||
if (configFile.size() < MAXPATHLEN) {
|
||||
struct stat sb;
|
||||
if (stat(configFile.c_str(), &sb) == 0) {
|
||||
return configFile;
|
||||
return Common::Path(configFile, '/');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ Common::Path OSystem_POSIX::getDefaultConfigFileName() {
|
|||
configFile = baseConfigName;
|
||||
}
|
||||
|
||||
return configFile;
|
||||
return Common::Path(configFile, '/');
|
||||
}
|
||||
|
||||
Common::String OSystem_POSIX::getXdgUserDir(const char *name) {
|
||||
|
@ -182,7 +182,7 @@ Common::String OSystem_POSIX::getXdgUserDir(const char *name) {
|
|||
|
||||
// Find the requested directory line in the xdg-user-dirs configuration file
|
||||
// Example line value: XDG_PICTURES_DIR="$HOME/Pictures"
|
||||
Common::FSNode userDirsFile(configHome + "/user-dirs.dirs");
|
||||
Common::FSNode userDirsFile(Common::Path(configHome + "/user-dirs.dirs", '/'));
|
||||
if (!userDirsFile.exists() || !userDirsFile.isReadable() || userDirsFile.isDirectory()) {
|
||||
return "";
|
||||
}
|
||||
|
@ -245,7 +245,7 @@ Common::Path OSystem_POSIX::getDefaultIconsPath() {
|
|||
if (prefix == nullptr || !*prefix) {
|
||||
prefix = getenv("HOME");
|
||||
if (prefix == nullptr) {
|
||||
return Common::String();
|
||||
return Common::Path();
|
||||
}
|
||||
|
||||
iconsPath = ".cache/";
|
||||
|
@ -254,14 +254,14 @@ Common::Path OSystem_POSIX::getDefaultIconsPath() {
|
|||
iconsPath += "scummvm/icons";
|
||||
|
||||
if (!Posix::assureDirectoryExists(iconsPath, prefix)) {
|
||||
return Common::String();
|
||||
return Common::Path();
|
||||
}
|
||||
|
||||
return Common::Path(prefix).join(iconsPath);
|
||||
}
|
||||
|
||||
Common::Path OSystem_POSIX::getDefaultDLCsPath() {
|
||||
Common::Path dlcsPath;
|
||||
Common::String dlcsPath;
|
||||
|
||||
// On POSIX systems we follow the XDG Base Directory Specification for
|
||||
// where to store files. The version we based our code upon can be found
|
||||
|
@ -270,17 +270,19 @@ Common::Path OSystem_POSIX::getDefaultDLCsPath() {
|
|||
if (prefix == nullptr || !*prefix) {
|
||||
prefix = getenv("HOME");
|
||||
if (prefix == nullptr) {
|
||||
return Common::String();
|
||||
return Common::Path();
|
||||
}
|
||||
|
||||
dlcsPath = ".cache/";
|
||||
}
|
||||
dlcsPath = dlcsPath.join(Common::Path("scummvm/dlcs"));
|
||||
if (!Posix::assureDirectoryExists(dlcsPath.toString(), prefix)) {
|
||||
|
||||
dlcsPath += "scummvm/dlcs";
|
||||
|
||||
if (!Posix::assureDirectoryExists(dlcsPath, prefix)) {
|
||||
return Common::Path();
|
||||
}
|
||||
|
||||
return dlcsPath;
|
||||
return Common::Path(prefix).join(dlcsPath);
|
||||
}
|
||||
|
||||
Common::Path OSystem_POSIX::getScreenshotsPath() {
|
||||
|
@ -345,7 +347,7 @@ Common::Path OSystem_POSIX::getDefaultLogFileName() {
|
|||
if (prefix == nullptr || !*prefix) {
|
||||
prefix = getenv("HOME");
|
||||
if (prefix == nullptr) {
|
||||
return Common::String();
|
||||
return Common::Path();
|
||||
}
|
||||
|
||||
logFile = ".cache/";
|
||||
|
@ -354,7 +356,7 @@ Common::Path OSystem_POSIX::getDefaultLogFileName() {
|
|||
logFile += "scummvm/logs";
|
||||
|
||||
if (!Posix::assureDirectoryExists(logFile, prefix)) {
|
||||
return Common::String();
|
||||
return Common::Path();
|
||||
}
|
||||
|
||||
Common::Path logPath(prefix);
|
||||
|
|
|
@ -332,7 +332,7 @@ void OSystem_SDL::initBackend() {
|
|||
#endif
|
||||
|
||||
ConfMan.registerDefault("iconspath", this->getDefaultIconsPath());
|
||||
ConfMan.registerDefault("dlcspath", this->getDefaultDLCsPath().toString());
|
||||
ConfMan.registerDefault("dlcspath", this->getDefaultDLCsPath());
|
||||
|
||||
_inited = true;
|
||||
|
||||
|
|
|
@ -438,7 +438,7 @@ public:
|
|||
const Common::ArchiveMemberPtr getMember(const Common::Path &path) const override;
|
||||
Common::SeekableReadStream *createReadStreamForMember(const Common::Path &path) const override;
|
||||
private:
|
||||
typedef Common::List<Common::String> FilenameList;
|
||||
typedef Common::List<Common::Path> FilenameList;
|
||||
|
||||
FilenameList _files;
|
||||
};
|
||||
|
@ -449,7 +449,8 @@ BOOL CALLBACK EnumResNameProc(HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName
|
|||
|
||||
Win32ResourceArchive *arch = (Win32ResourceArchive *)lParam;
|
||||
Common::String filename = Win32::tcharToString(lpszName);
|
||||
arch->_files.push_back(filename);
|
||||
// We use / as path separator in resources
|
||||
arch->_files.push_back(Common::Path(filename, '/'));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -458,9 +459,8 @@ Win32ResourceArchive::Win32ResourceArchive() {
|
|||
}
|
||||
|
||||
bool Win32ResourceArchive::hasFile(const Common::Path &path) const {
|
||||
Common::String name = path.toString();
|
||||
for (FilenameList::const_iterator i = _files.begin(); i != _files.end(); ++i) {
|
||||
if (i->equalsIgnoreCase(name))
|
||||
if (i->equalsIgnoreCase(path))
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -481,7 +481,8 @@ const Common::ArchiveMemberPtr Win32ResourceArchive::getMember(const Common::Pat
|
|||
}
|
||||
|
||||
Common::SeekableReadStream *Win32ResourceArchive::createReadStreamForMember(const Common::Path &path) const {
|
||||
Common::String name = path.toString();
|
||||
// We store paths in resources using / separator
|
||||
Common::String name = path.toString('/');
|
||||
TCHAR *tName = Win32::stringToTchar(name);
|
||||
HRSRC resource = FindResource(nullptr, tName, MAKEINTRESOURCE(256));
|
||||
free(tName);
|
||||
|
|
Loading…
Reference in a new issue