mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-17 10:52:46 +00:00
Remove hsFiles in favor of plFilesystem stuff
This commit is contained in:
@ -5,7 +5,6 @@ include_directories("../../PubUtilLib")
|
||||
include_directories(${ZLIB_INCLUDE_DIR})
|
||||
|
||||
set(plFile_SOURCES
|
||||
hsFiles.cpp
|
||||
plBrowseFolder.cpp
|
||||
plEncryptedStream.cpp
|
||||
plInitFileReader.cpp
|
||||
@ -13,16 +12,7 @@ set(plFile_SOURCES
|
||||
plStreamSource.cpp
|
||||
)
|
||||
|
||||
if(WIN32 AND NOT CYGWIN)
|
||||
set(plFile_SOURCES ${plFile_SOURCES} hsFiles_Win.cpp)
|
||||
endif(WIN32 AND NOT CYGWIN)
|
||||
|
||||
if(UNIX)
|
||||
set(plFile_SOURCES ${plFile_SOURCES} hsFiles_Unix.cpp)
|
||||
endif(UNIX)
|
||||
|
||||
set(plFile_HEADERS
|
||||
hsFiles.h
|
||||
plBrowseFolder.h
|
||||
plEncryptedStream.h
|
||||
plInitFileReader.h
|
||||
|
@ -1,182 +0,0 @@
|
||||
/*==LICENSE==*
|
||||
|
||||
CyanWorlds.com Engine - MMOG client, server and tools
|
||||
Copyright (C) 2011 Cyan Worlds, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Additional permissions under GNU GPL version 3 section 7
|
||||
|
||||
If you modify this Program, or any covered work, by linking or
|
||||
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
|
||||
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
|
||||
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
|
||||
(or a modified version of those libraries),
|
||||
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
|
||||
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
|
||||
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
|
||||
licensors of this Program grant you additional
|
||||
permission to convey the resulting work. Corresponding Source for a
|
||||
non-source form of such a combination shall include the source code for
|
||||
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
|
||||
work.
|
||||
|
||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
or by snail mail at:
|
||||
Cyan Worlds, Inc.
|
||||
14617 N Newport Hwy
|
||||
Mead, WA 99021
|
||||
|
||||
*==LICENSE==*/
|
||||
#include "hsFiles.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#include "hsExceptions.h"
|
||||
|
||||
#if HS_BUILD_FOR_WIN32
|
||||
#define kDirChar '\\'
|
||||
#else
|
||||
#define kDirChar '/'
|
||||
#endif
|
||||
|
||||
|
||||
static const char* FindNameInPath(const char path[])
|
||||
{
|
||||
const char* name = ::strrchr(path, kDirChar);
|
||||
|
||||
if (name == nil)
|
||||
name = path;
|
||||
return name;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
hsFile::hsFile() : fPathAndName(nil), fFILE(nil)
|
||||
{
|
||||
}
|
||||
|
||||
hsFile::hsFile(const char pathAndName[]) : fPathAndName(nil), fFILE(nil)
|
||||
{
|
||||
if (pathAndName)
|
||||
fPathAndName = hsStrcpy(pathAndName);
|
||||
}
|
||||
|
||||
hsFile::~hsFile()
|
||||
{
|
||||
this->SetPathAndName(nil);
|
||||
}
|
||||
|
||||
const char* hsFile::GetPathAndName()
|
||||
{
|
||||
return fPathAndName;
|
||||
}
|
||||
|
||||
void hsFile::SetPathAndName(const char pathAndName[])
|
||||
{
|
||||
this->Close();
|
||||
|
||||
if (fPathAndName)
|
||||
{ delete[] fPathAndName;
|
||||
fPathAndName = nil;
|
||||
}
|
||||
if (pathAndName)
|
||||
fPathAndName = hsStrcpy(pathAndName);
|
||||
}
|
||||
|
||||
const char* hsFile::GetName()
|
||||
{
|
||||
return FindNameInPath(this->GetPathAndName());
|
||||
}
|
||||
|
||||
FILE* hsFile::OpenFILE(const char mode[], bool throwIfFailure)
|
||||
{
|
||||
this->Close();
|
||||
|
||||
// We call the virtual method here rather than using
|
||||
// fPathAndName directly, allowing a subclass to construct
|
||||
// the name if necessary
|
||||
//
|
||||
const char* name = this->GetPathAndName();
|
||||
if (name)
|
||||
fFILE = ::fopen(name, mode);
|
||||
|
||||
hsThrowIfTrue(throwIfFailure && fFILE == nil);
|
||||
return fFILE;
|
||||
}
|
||||
|
||||
hsStream* hsFile::OpenStream(const char mode[], bool throwIfFailure)
|
||||
{
|
||||
FILE* file = this->OpenFILE(mode, throwIfFailure);
|
||||
|
||||
if (file)
|
||||
{ hsUNIXStream* stream = new hsUNIXStream;
|
||||
stream->SetFILE(file);
|
||||
return stream;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
void hsFile::Close()
|
||||
{
|
||||
if (fFILE)
|
||||
{ int err = ::fflush(fFILE);
|
||||
hsIfDebugMessage(err != 0, "fflush failed", err);
|
||||
err = ::fclose(fFILE);
|
||||
hsIfDebugMessage(err != 0, "fclose failed", err);
|
||||
fFILE = nil;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool hsFolderIterator::NextFileSuffix(const char suffix[])
|
||||
{
|
||||
while (this->NextFile())
|
||||
{ const char* fileSuffix = ::strrchr(this->GetFileName(), '.');
|
||||
if (fileSuffix != nil && stricmp(fileSuffix, suffix) == 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int hsFolderIterator::GetPathAndName(char pathandname[])
|
||||
{
|
||||
hsAssert(pathandname, "NULL path string");
|
||||
const char* name = this->GetFileName();
|
||||
int pathLen = strlen(fPath);
|
||||
|
||||
// add 1 for null terminator
|
||||
int totalLen = pathLen + sizeof(kDirChar) + strlen(name) + 1;
|
||||
hsAssert(totalLen <= kFolderIterator_MaxPath, "Overrun kFolderIterator_MaxPath");
|
||||
|
||||
if (pathandname)
|
||||
{
|
||||
strcpy(pathandname, fPath);
|
||||
if (pathLen > 0 && pathandname[pathLen - 1] != kDirChar)
|
||||
pathandname[pathLen++] = kDirChar;
|
||||
strcpy(pathandname + pathLen, name);
|
||||
}
|
||||
return totalLen;
|
||||
}
|
||||
|
||||
FILE* hsFolderIterator::OpenFILE(const char mode[])
|
||||
{
|
||||
char fileName[kFolderIterator_MaxPath];
|
||||
|
||||
(void)this->GetPathAndName(fileName);
|
||||
|
||||
return ::fopen(fileName, mode);
|
||||
}
|
||||
|
@ -1,141 +0,0 @@
|
||||
/*==LICENSE==*
|
||||
|
||||
CyanWorlds.com Engine - MMOG client, server and tools
|
||||
Copyright (C) 2011 Cyan Worlds, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Additional permissions under GNU GPL version 3 section 7
|
||||
|
||||
If you modify this Program, or any covered work, by linking or
|
||||
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
|
||||
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
|
||||
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
|
||||
(or a modified version of those libraries),
|
||||
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
|
||||
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
|
||||
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
|
||||
licensors of this Program grant you additional
|
||||
permission to convey the resulting work. Corresponding Source for a
|
||||
non-source form of such a combination shall include the source code for
|
||||
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
|
||||
work.
|
||||
|
||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
or by snail mail at:
|
||||
Cyan Worlds, Inc.
|
||||
14617 N Newport Hwy
|
||||
Mead, WA 99021
|
||||
|
||||
*==LICENSE==*/
|
||||
#ifndef hsFiles_Defined
|
||||
#define hsFiles_Defined
|
||||
|
||||
#include "hsStream.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#if HS_BUILD_FOR_UNIX
|
||||
#include <limits.h>
|
||||
#define kFolderIterator_MaxPath PATH_MAX
|
||||
#define SetCurrentDirectory chdir
|
||||
#else
|
||||
#define kFolderIterator_MaxPath _MAX_PATH
|
||||
#endif
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
class hsFile {
|
||||
hsFile& operator=(const hsFile&); // disallow assignment
|
||||
protected:
|
||||
char* fPathAndName;
|
||||
FILE* fFILE;
|
||||
public:
|
||||
hsFile();
|
||||
hsFile(const char pathAndName[]);
|
||||
virtual ~hsFile();
|
||||
|
||||
const char* GetName();
|
||||
virtual const char* GetPathAndName();
|
||||
virtual void SetPathAndName(const char pathAndName[]);
|
||||
|
||||
virtual FILE* OpenFILE(const char mode[], bool throwIfFailure = false);
|
||||
virtual hsStream* OpenStream(const char mode[], bool throwIfFailure = false);
|
||||
|
||||
virtual void Close(); // called automatically in the destructor
|
||||
};
|
||||
typedef hsFile hsUnixFile; // for compatibility
|
||||
typedef hsFile hsOSFile;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
class hsFolderIterator {
|
||||
char fPath[kFolderIterator_MaxPath];
|
||||
struct hsFolderIterator_Data* fData;
|
||||
bool fCustomFilter;
|
||||
public:
|
||||
#ifdef HS_BUILD_FOR_WIN32
|
||||
hsFolderIterator(const char path[] = nil, bool useCustomFilter=false);
|
||||
#else
|
||||
hsFolderIterator(const char path[] = nil, bool unused=true);
|
||||
hsFolderIterator(const struct FSSpec* spec); // Alt constructor
|
||||
#endif
|
||||
virtual ~hsFolderIterator();
|
||||
|
||||
const char* GetPath() const { return fPath; }
|
||||
void SetPath(const char path[]);
|
||||
|
||||
void Reset();
|
||||
bool NextFile();
|
||||
bool NextFileSuffix(const char suffix[]);
|
||||
const char* GetFileName() const;
|
||||
int GetPathAndName(char pathandname[] = nil);
|
||||
bool IsDirectory( void ) const;
|
||||
|
||||
FILE* OpenFILE(const char mode[]);
|
||||
|
||||
#if HS_BUILD_FOR_WIN32
|
||||
void SetWinSystemDir(const char subdir[]); // e.g. "Fonts"
|
||||
void SetFileFilterStr(const char filterStr[]); // e.g. "*.*"
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef HS_BUILD_FOR_WIN32
|
||||
// only implemented on Win32 for now
|
||||
class hsWFolderIterator {
|
||||
wchar_t fPath[kFolderIterator_MaxPath];
|
||||
struct hsWFolderIterator_Data* fData;
|
||||
bool fCustomFilter;
|
||||
public:
|
||||
hsWFolderIterator(const wchar_t path[] = nil, bool useCustomFilter=false);
|
||||
virtual ~hsWFolderIterator();
|
||||
|
||||
const wchar_t* GetPath() const { return fPath; }
|
||||
void SetPath(const wchar_t path[]);
|
||||
|
||||
void Reset();
|
||||
bool NextFile();
|
||||
bool NextFileSuffix(const wchar_t suffix[]);
|
||||
const wchar_t* GetFileName() const;
|
||||
int GetPathAndName(wchar_t pathandname[] = nil);
|
||||
bool IsDirectory( void ) const;
|
||||
|
||||
FILE* OpenFILE(const wchar_t mode[]);
|
||||
|
||||
void SetWinSystemDir(const wchar_t subdir[]); // e.g. "Fonts"
|
||||
void SetFileFilterStr(const wchar_t filterStr[]); // e.g. "*.*"
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,145 +0,0 @@
|
||||
/*==LICENSE==*
|
||||
|
||||
CyanWorlds.com Engine - MMOG client, server and tools
|
||||
Copyright (C) 2011 Cyan Worlds, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Additional permissions under GNU GPL version 3 section 7
|
||||
|
||||
If you modify this Program, or any covered work, by linking or
|
||||
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
|
||||
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
|
||||
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
|
||||
(or a modified version of those libraries),
|
||||
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
|
||||
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
|
||||
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
|
||||
licensors of this Program grant you additional
|
||||
permission to convey the resulting work. Corresponding Source for a
|
||||
non-source form of such a combination shall include the source code for
|
||||
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
|
||||
work.
|
||||
|
||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
or by snail mail at:
|
||||
Cyan Worlds, Inc.
|
||||
14617 N Newport Hwy
|
||||
Mead, WA 99021
|
||||
|
||||
*==LICENSE==*/
|
||||
#include "hsFiles.h"
|
||||
|
||||
#if HS_BUILD_FOR_UNIX
|
||||
|
||||
#include <errno.h>
|
||||
#include <dirent.h>
|
||||
#include <limits.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <glob.h>
|
||||
#include <string>
|
||||
#include "hsTemplates.h"
|
||||
|
||||
struct hsFolderIterator_Data {
|
||||
glob_t fGlobBuf;
|
||||
bool fInited;
|
||||
int fCnt;
|
||||
hsFolderIterator_Data() : fInited(false), fCnt(0) {}
|
||||
// ~hsFolderIterator_Data() { fInited=false; globfree(&fData->fGlobBuf); }
|
||||
};
|
||||
|
||||
hsFolderIterator::hsFolderIterator(const char path[], bool)
|
||||
{
|
||||
fData = new hsFolderIterator_Data;
|
||||
|
||||
this->SetPath(path);
|
||||
}
|
||||
|
||||
hsFolderIterator::~hsFolderIterator()
|
||||
{
|
||||
this->Reset();
|
||||
delete fData;
|
||||
}
|
||||
|
||||
void hsFolderIterator::SetPath(const char path[])
|
||||
{
|
||||
fPath[0] = 0;
|
||||
if (path)
|
||||
{
|
||||
::strcpy(fPath, path);
|
||||
}
|
||||
this->Reset();
|
||||
}
|
||||
|
||||
void hsFolderIterator::Reset()
|
||||
{
|
||||
if (fData->fInited)
|
||||
{
|
||||
globfree(&fData->fGlobBuf);
|
||||
fData->fCnt = 0;
|
||||
fData->fInited=false;
|
||||
}
|
||||
}
|
||||
bool hsFolderIterator::NextFile()
|
||||
{
|
||||
if (fData->fInited == false)
|
||||
{
|
||||
std::string path=fPath;
|
||||
if(!(strchr(fPath,'*') || strchr(fPath,'?') || strchr(fPath,'[')))
|
||||
{
|
||||
if (fPath[strlen(fPath)-1] != PATH_SEPARATOR)
|
||||
path = path + PATH_SEPARATOR_STR + "*";
|
||||
else
|
||||
path = path + "*";
|
||||
}
|
||||
|
||||
if(glob(path.c_str(), 0, NULL, &fData->fGlobBuf) != 0 ) {
|
||||
return false;
|
||||
}
|
||||
fData->fInited=true;
|
||||
fData->fCnt = 0;
|
||||
}
|
||||
|
||||
return fData->fCnt++ < fData->fGlobBuf.gl_pathc;
|
||||
}
|
||||
|
||||
const char* hsFolderIterator::GetFileName() const
|
||||
{
|
||||
if (!fData->fInited || fData->fCnt > fData->fGlobBuf.gl_pathc)
|
||||
throw "end of folder";
|
||||
|
||||
plFileName fn = fData->fGlobBuf.gl_pathv[fData->fCnt-1];
|
||||
return fn.GetFileName().c_str();
|
||||
}
|
||||
|
||||
bool hsFolderIterator::IsDirectory( void ) const
|
||||
{
|
||||
// rob, please forgive me, this is my best attempt...
|
||||
if(fData->fCnt > fData->fGlobBuf.gl_pathc )
|
||||
return false;
|
||||
|
||||
struct stat info;
|
||||
const char* fn=fData->fGlobBuf.gl_pathv[fData->fCnt-1];
|
||||
if( stat( fn, &info ) )
|
||||
{
|
||||
printf("Error calling stat(): %s errno=%d\n", strerror(errno), errno);
|
||||
return false;
|
||||
}
|
||||
return ( info.st_mode & S_IFDIR ) ? true : false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -1,320 +0,0 @@
|
||||
/*==LICENSE==*
|
||||
|
||||
CyanWorlds.com Engine - MMOG client, server and tools
|
||||
Copyright (C) 2011 Cyan Worlds, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Additional permissions under GNU GPL version 3 section 7
|
||||
|
||||
If you modify this Program, or any covered work, by linking or
|
||||
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
|
||||
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
|
||||
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
|
||||
(or a modified version of those libraries),
|
||||
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
|
||||
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
|
||||
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
|
||||
licensors of this Program grant you additional
|
||||
permission to convey the resulting work. Corresponding Source for a
|
||||
non-source form of such a combination shall include the source code for
|
||||
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
|
||||
work.
|
||||
|
||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
or by snail mail at:
|
||||
Cyan Worlds, Inc.
|
||||
14617 N Newport Hwy
|
||||
Mead, WA 99021
|
||||
|
||||
*==LICENSE==*/
|
||||
#include "hsFiles.h"
|
||||
#include "HeadSpin.h"
|
||||
#include "hsWindows.h"
|
||||
|
||||
#if HS_BUILD_FOR_WIN32
|
||||
|
||||
#include "hsExceptions.h"
|
||||
|
||||
struct hsFolderIterator_Data {
|
||||
HANDLE fSearchHandle;
|
||||
WIN32_FIND_DATA fFindData;
|
||||
bool fValid;
|
||||
};
|
||||
|
||||
hsFolderIterator::hsFolderIterator(const char path[], bool useCustomFilter)
|
||||
{
|
||||
fCustomFilter = useCustomFilter;
|
||||
|
||||
fData = new hsFolderIterator_Data;
|
||||
fData->fSearchHandle = nil;
|
||||
fData->fValid = true;
|
||||
|
||||
if(useCustomFilter)
|
||||
{
|
||||
this->SetFileFilterStr(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->SetPath(path);
|
||||
}
|
||||
}
|
||||
|
||||
hsFolderIterator::~hsFolderIterator()
|
||||
{
|
||||
delete fData;
|
||||
}
|
||||
|
||||
void hsFolderIterator::SetPath(const char path[])
|
||||
{
|
||||
fCustomFilter = false;
|
||||
fPath[0] = 0;
|
||||
if (path)
|
||||
{
|
||||
::strcpy(fPath, path);
|
||||
|
||||
// Make sure the dir ends with a slash
|
||||
char lastchar = fPath[strlen(fPath)-1];
|
||||
if (lastchar != '\\' && lastchar != '/')
|
||||
strcat(fPath, "\\");
|
||||
}
|
||||
|
||||
this->Reset();
|
||||
}
|
||||
|
||||
void hsFolderIterator::SetWinSystemDir(const char subdir[])
|
||||
{
|
||||
int ret = GetWindowsDirectory(fPath, _MAX_PATH);
|
||||
hsAssert(ret != 0, "Error getting windows directory in UseWindowsFontsPath");
|
||||
|
||||
if (subdir)
|
||||
{ ::strcat(fPath, "\\");
|
||||
::strcat(fPath, subdir);
|
||||
::strcat(fPath, "\\");
|
||||
}
|
||||
this->Reset();
|
||||
}
|
||||
|
||||
void hsFolderIterator::SetFileFilterStr(const char filterStr[])
|
||||
{
|
||||
fPath[0] = 0;
|
||||
if (filterStr)
|
||||
{
|
||||
fCustomFilter = true;
|
||||
::strcpy(fPath, filterStr);
|
||||
}
|
||||
|
||||
this->Reset();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void hsFolderIterator::Reset()
|
||||
{
|
||||
if (fData->fSearchHandle)
|
||||
{ FindClose(fData->fSearchHandle);
|
||||
fData->fSearchHandle = nil;
|
||||
}
|
||||
fData->fValid = true;
|
||||
}
|
||||
|
||||
bool hsFolderIterator::NextFile()
|
||||
{
|
||||
if (fData->fValid == false)
|
||||
return false;
|
||||
|
||||
if (fData->fSearchHandle == nil)
|
||||
{ int len = ::strlen(fPath);
|
||||
|
||||
if(fCustomFilter == false)
|
||||
{
|
||||
fPath[len] = '*';
|
||||
fPath[len+1] = 0;
|
||||
}
|
||||
|
||||
fData->fSearchHandle = FindFirstFile(fPath, &fData->fFindData);
|
||||
fPath[len] = 0;
|
||||
|
||||
if (fData->fSearchHandle == INVALID_HANDLE_VALUE)
|
||||
{ fData->fSearchHandle = nil;
|
||||
fData->fValid = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{ if (FindNextFile(fData->fSearchHandle, &fData->fFindData) == false)
|
||||
{ FindClose(fData->fSearchHandle);
|
||||
fData->fSearchHandle = nil;
|
||||
fData->fValid = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hsFolderIterator::IsDirectory( void ) const
|
||||
{
|
||||
if( fData->fValid && ( fData->fFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* hsFolderIterator::GetFileName() const
|
||||
{
|
||||
if (fData->fValid == false)
|
||||
hsThrow( "end of folder");
|
||||
|
||||
return fData->fFindData.cFileName;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct hsWFolderIterator_Data {
|
||||
HANDLE fSearchHandle;
|
||||
WIN32_FIND_DATAW fFindData;
|
||||
bool fValid;
|
||||
};
|
||||
|
||||
hsWFolderIterator::hsWFolderIterator(const wchar_t path[], bool useCustomFilter)
|
||||
{
|
||||
fCustomFilter = useCustomFilter;
|
||||
|
||||
fData = new hsWFolderIterator_Data;
|
||||
fData->fSearchHandle = nil;
|
||||
fData->fValid = true;
|
||||
|
||||
if(useCustomFilter)
|
||||
SetFileFilterStr(path);
|
||||
else
|
||||
SetPath(path);
|
||||
}
|
||||
|
||||
hsWFolderIterator::~hsWFolderIterator()
|
||||
{
|
||||
delete fData;
|
||||
}
|
||||
|
||||
void hsWFolderIterator::SetPath(const wchar_t path[])
|
||||
{
|
||||
fCustomFilter = false;
|
||||
fPath[0] = 0;
|
||||
if (path)
|
||||
{
|
||||
wcscpy(fPath, path);
|
||||
|
||||
// Make sure the dir ends with a slash
|
||||
wchar_t lastchar = fPath[wcslen(fPath)-1];
|
||||
if (lastchar != L'\\' && lastchar != L'/')
|
||||
wcscat(fPath, L"\\");
|
||||
}
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
void hsWFolderIterator::SetWinSystemDir(const wchar_t subdir[])
|
||||
{
|
||||
int ret = GetWindowsDirectoryW(fPath, _MAX_PATH);
|
||||
hsAssert(ret != 0, "Error getting windows directory in UseWindowsFontsPath");
|
||||
|
||||
if (subdir)
|
||||
{
|
||||
wcscat(fPath, L"\\");
|
||||
wcscat(fPath, subdir);
|
||||
wcscat(fPath, L"\\");
|
||||
}
|
||||
Reset();
|
||||
}
|
||||
|
||||
void hsWFolderIterator::SetFileFilterStr(const wchar_t filterStr[])
|
||||
{
|
||||
fPath[0] = 0;
|
||||
if (filterStr)
|
||||
{
|
||||
fCustomFilter = true;
|
||||
wcscpy(fPath, filterStr);
|
||||
}
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void hsWFolderIterator::Reset()
|
||||
{
|
||||
if (fData->fSearchHandle)
|
||||
{
|
||||
FindClose(fData->fSearchHandle);
|
||||
fData->fSearchHandle = nil;
|
||||
}
|
||||
fData->fValid = true;
|
||||
}
|
||||
|
||||
bool hsWFolderIterator::NextFile()
|
||||
{
|
||||
if (fData->fValid == false)
|
||||
return false;
|
||||
|
||||
if (fData->fSearchHandle == nil)
|
||||
{
|
||||
int len = wcslen(fPath);
|
||||
|
||||
if(fCustomFilter == false)
|
||||
{
|
||||
fPath[len] = L'*';
|
||||
fPath[len+1] = L'\0';
|
||||
}
|
||||
|
||||
fData->fSearchHandle = FindFirstFileW(fPath, &fData->fFindData);
|
||||
fPath[len] = 0;
|
||||
|
||||
if (fData->fSearchHandle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
fData->fSearchHandle = nil;
|
||||
fData->fValid = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (FindNextFileW(fData->fSearchHandle, &fData->fFindData) == false)
|
||||
{
|
||||
FindClose(fData->fSearchHandle);
|
||||
fData->fSearchHandle = nil;
|
||||
fData->fValid = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hsWFolderIterator::IsDirectory( void ) const
|
||||
{
|
||||
if( fData->fValid && ( fData->fFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const wchar_t* hsWFolderIterator::GetFileName() const
|
||||
{
|
||||
if (fData->fValid == false)
|
||||
hsThrow( "end of folder");
|
||||
|
||||
return fData->fFindData.cFileName;
|
||||
}
|
||||
|
||||
#endif // HS_BUILD_FOR_WIN32
|
@ -41,7 +41,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
*==LICENSE==*/
|
||||
|
||||
#include <string>
|
||||
#include "hsFiles.h"
|
||||
#include "plStreamSource.h"
|
||||
#include "plSecureStream.h"
|
||||
#include "plEncryptedStream.h"
|
||||
@ -106,8 +105,7 @@ std::vector<plFileName> plStreamSource::GetListOfNames(const plFileName& dir, co
|
||||
|
||||
// loop through all the file data records, and create the list
|
||||
std::vector<plFileName> retVal;
|
||||
decltype(fFileData.begin()) curData;
|
||||
for (curData = fFileData.begin(); curData != fFileData.end(); curData++)
|
||||
for (auto curData = fFileData.begin(); curData != fFileData.end(); curData++)
|
||||
{
|
||||
if ((curData->second.fDir == sDir) && (curData->second.fExt == ext))
|
||||
retVal.push_back(curData->second.fFilename);
|
||||
@ -116,15 +114,11 @@ std::vector<plFileName> plStreamSource::GetListOfNames(const plFileName& dir, co
|
||||
#ifndef PLASMA_EXTERNAL_RELEASE
|
||||
// in internal releases, we can use on-disk files if they exist
|
||||
// Build the search string as "dir/*.ext"
|
||||
plString searchStr = plFileName::Join(sDir, "*." + ext).AsString();
|
||||
|
||||
hsFolderIterator folderIter(searchStr.c_str(), true);
|
||||
while (folderIter.NextFile())
|
||||
std::vector<plFileName> files = plFileSystem::ListDir(sDir, ("*." + ext).c_str());
|
||||
for (auto iter = files.begin(); iter != files.end(); ++iter)
|
||||
{
|
||||
plFileName filename = plFileName::Join(sDir, folderIter.GetFileName());
|
||||
|
||||
if (fFileData.find(filename) == fFileData.end()) // we haven't added it yet
|
||||
retVal.push_back(filename);
|
||||
if (fFileData.find(*iter) == fFileData.end()) // we haven't added it yet
|
||||
retVal.push_back(*iter);
|
||||
}
|
||||
#endif // PLASMA_EXTERNAL_RELEASE
|
||||
|
||||
|
Reference in New Issue
Block a user