mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-18 11:19:10 +00:00
Finish deprecation of pnUtPath
This commit is contained in:
@ -440,6 +440,7 @@ int hsMessageBoxWithOwner(hsWindowHndl owner, const wchar_t message[], const wch
|
||||
# include <limits.h>
|
||||
# define MAX_PATH PATH_MAX
|
||||
#endif
|
||||
#define MAX_EXT (256)
|
||||
|
||||
// Useful floating point utilities
|
||||
inline float hsDegreesToRadians(float deg) { return float(deg * (M_PI / 180)); }
|
||||
|
@ -50,6 +50,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
# include <limits.h>
|
||||
# include <unistd.h>
|
||||
# include <sys/types.h>
|
||||
# include <dirent.h>
|
||||
# include <fnmatch.h>
|
||||
# include <cstdlib>
|
||||
# include <functional>
|
||||
# include <memory>
|
||||
@ -283,8 +285,11 @@ FILE *plFileSystem::Open(const plFileName &filename, const char *mode)
|
||||
bool plFileSystem::Unlink(const plFileName &filename)
|
||||
{
|
||||
#if HS_BUILD_FOR_WIN32
|
||||
return _wunlink(filename.AsString().ToWchar()) == 0;
|
||||
plStringBuffer<wchar_t> wfilename = filename.AsString().ToWchar();
|
||||
_wchmod(wfilename, S_IWRITE);
|
||||
return _wunlink(wfilename) == 0;
|
||||
#else
|
||||
chmod(filename.AsString().c_str(), S_IWRITE);
|
||||
return unlink(filename.AsString().c_str()) == 0;
|
||||
#endif
|
||||
}
|
||||
@ -343,6 +348,55 @@ bool plFileSystem::CreateDir(const plFileName &dir, bool checkParents)
|
||||
#endif
|
||||
}
|
||||
|
||||
std::vector<plFileName> plFileSystem::ListDir(const plFileName &path, const char *pattern)
|
||||
{
|
||||
std::vector<plFileName> contents;
|
||||
|
||||
#if HS_BUILD_FOR_WIN32
|
||||
if (!pattern || !pattern[0])
|
||||
pattern = "*";
|
||||
plFileName searchPattern = plFileName::Join(path, pattern);
|
||||
|
||||
WIN32_FIND_DATAW findData;
|
||||
HANDLE hFind = FindFirstFileW(searchPattern.AsString().ToWchar(), &findData);
|
||||
if (hFind == INVALID_HANDLE_VALUE)
|
||||
return contents;
|
||||
|
||||
do {
|
||||
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
||||
// Should also handle . and ..
|
||||
continue;
|
||||
}
|
||||
|
||||
contents.push_back(plFileName::Join(path, plString::FromWchar(findData.cFileName)));
|
||||
} while (FindNextFileW(hFind, &findData));
|
||||
|
||||
FindClose(hFind);
|
||||
#else
|
||||
DIR *dir = opendir(path.AsString().c_str());
|
||||
if (!dir)
|
||||
return contents;
|
||||
|
||||
struct dirent *de;
|
||||
while (de = readdir(dir)) {
|
||||
if (plFileInfo(de->d_name).IsDirectory()) {
|
||||
// Should also handle . and ..
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pattern && pattern[0] && fnmatch(pattern, de->d_name))
|
||||
contents.push_back(plFileName::Join(path, de->d_name));
|
||||
else if (!pattern || !pattern[0])
|
||||
contents.push_back(plFileName::Join(path, de->d_name));
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
#endif
|
||||
|
||||
return contents;
|
||||
}
|
||||
|
||||
|
||||
plFileName plFileSystem::GetUserDataPath()
|
||||
{
|
||||
static plFileName _userData;
|
||||
|
@ -303,6 +303,15 @@ namespace plFileSystem
|
||||
*/
|
||||
bool CreateDir(const plFileName &dir, bool checkParents = false);
|
||||
|
||||
/** Fetch a list of files contained in the supplied \a path.
|
||||
* If \a pattern is specified (e.g. "*.tmp"), use that to filter
|
||||
* matches. Otherwise, all files in the path will be returned.
|
||||
* Note that returned filenames include the provided path -- to
|
||||
* get only the filename, call .GetFileName() on an entry.
|
||||
*/
|
||||
std::vector<plFileName> ListDir(const plFileName &path,
|
||||
const char *pattern = nullptr);
|
||||
|
||||
/** Get the User's data directory. If it doesn't exist, this will
|
||||
* create it.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user