std::string FileSystem::LocateDir(std::string _dir, int flags) const
{
	if (!CheckFile(_dir)) {
		return "";
	}

	// if it's an absolute path, don't look for it in the data directories
	if (FileSystemHandler::IsAbsolutePath(_dir)) {
		return _dir;
	}

	std::string dir = _dir;
	FixSlashes(dir);

	if (flags & WRITE) {
		std::string writeableDir = fs.GetWriteDir() + dir;
		FixSlashes(writeableDir);
		if (flags & CREATE_DIRS) {
			CreateDirectory(writeableDir);
		}
		return writeableDir;
	} else {
		const std::vector<std::string>& datadirs = fs.GetDataDirectories();
		std::vector<std::string>::const_iterator dd;
		for (dd = datadirs.begin(); dd != datadirs.end(); ++dd) {
			std::string dirPath((*dd) + dir);
			if (fs.DirExists(dirPath)) {
				return dirPath;
			}
		}
		return dir;
	}
}
Exemplo n.º 2
0
bool FileSystem::Remove(std::string file) const
{
	if (!CheckFile(file))
		return false;
	FixSlashes(file);
	return fs.remove(file);
}
Exemplo n.º 3
0
hsFileStream* FindFilePath(plString path, plString base) {
    if (path.empty())
        return NULL;

    // Scan first from the provided path:
    hsFileStream* S = NULL;
    path = FixSlashes(path);
    if (hsFileStream::FileExists(base + path)) {
        S = new hsFileStream();
        S->open(base + path, fmRead);
        return S;
    }

    // If that fails, scan the parent, so we can loop around and find
    // files with explicit locations (sfx/ and dat/ prefixes)
    base = cdUp(base);
    if (hsFileStream::FileExists(base + path)) {
        S = new hsFileStream();
        S->open(base + path, fmRead);
        return S;
    }

    // Otherwise, we can't find the referenced file
    return NULL;
}
Exemplo n.º 4
0
FILE* FileSystem::fopen(std::string file, const char* mode) const
{
	if (!CheckFile(file) || !CheckMode(mode))
		return NULL;
	FixSlashes(file);
	return fs.fopen(file, mode);
}
/**
 * @brief remove a file
 *
 * Operates on the current working directory.
 */
bool FileSystem::Remove(std::string file) const
{
	if (!CheckFile(file))
		return false;
	FixSlashes(file);
	return ::remove(file.c_str()) == 0;
}
Exemplo n.º 6
0
size_t FileSystem::GetFilesize(std::string file) const
{
	if (!CheckFile(file))
		return 0;
	FixSlashes(file);
	return fs.GetFilesize(file);
}
Exemplo n.º 7
0
std::ofstream* FileSystem::ofstream(std::string file, std::ios_base::openmode mode) const
{
	if (!CheckFile(file))
		return NULL;
	FixSlashes(file);
	return fs.ofstream(file, mode);
}
Exemplo n.º 8
0
bool FileSystem::CreateDirectory(std::string dir) const
{
	if (!CheckFile(dir))
		return false;
	FixSlashes(dir);
	return fs.mkdir(dir);
}
Exemplo n.º 9
0
std::vector<std::string> FileSystem::GetNativeFilenames(std::string file, bool write) const
{
	if (!CheckFile(file))
		return std::vector<std::string>();
	FixSlashes(file);
	return fs.GetNativeFilenames(file, write);
}
Exemplo n.º 10
0
FILE *STEAM_fopen(const char *filename, const char *options)
{
	TSteamError steamError;
	char wadName[_MAX_PATH];
	SteamHandle_t hndl;

	strcpy(wadName,filename);			
	FixSlashes(wadName);

#if 0
	strlwr(wadName);
	if (   strstr(wadName, "client.dll")
	   )
	   hndl = STEAM_INVALID_HANDLE; // convenient breakpoint spot...
#endif

	if ( STEAMtrackingProgress )
	{
		DoEventTic(FALSE);
	}

	hndl = SteamOpenFile(wadName, options, &steamError);
	CheckError((FILE *)hndl, &steamError);

	return (FILE *)hndl;
}
Exemplo n.º 11
0
plString GetInternalName(const plString& filename) {
    // Different files are stored in different locations; this function
    // will try to guess where to put things based on the file's extension.
    // This is all based on the contents of .sum files included with the
    // games that I examined for this.

    plString split = s_oldFormat ? "/" : "\\";
    plString name = FixSlashes(filename).afterLast(PATHSEP);
    plString ext = name.afterLast('.');
    if (s_oldFormat && ext == "prp")
        return name;
    if (ext == "ogg" || ext == "wav")
        return plString("sfx") + split + name;
    if (ext == "exe" || ext == "dll" || ext == "map" || ext == "pdb")
        return name;
    if (ext == "sdl")
        return plString("SDL") + split + name;
    if (ext == "pak")
        return plString("Python") + split + name;
    if (ext == "fx")
        return plString("fx") + split + name;

    // dat is the default, since so many file types go there...
    // To name a few,
    // prp, age, fni, csv, sub, node, pfp, dat, tron, hex, tga, loc
    return plString("dat") + split + name;
}
Exemplo n.º 12
0
/**
 * @brief get filesize
 *
 * @return the filesize or 0 if the file doesn't exist.
 */
size_t FileSystem::GetFileSize(std::string file) const
{
	if (!CheckFile(file)) {
		return 0;
	}
	FixSlashes(file);
	return FileSystemHandler::GetFileSize(file);
}
Exemplo n.º 13
0
/**
 * @brief remove a file
 *
 * Operates on the current working directory.
 */
bool FileSystem::Remove(std::string file) const
{
	if (!CheckFile(file)) {
		return false;
	}
	FixSlashes(file);
	return FileSystemHandler::DeleteFile(file);
}
Exemplo n.º 14
0
std::string FixPath(const std::string& s)
{
    if(s.empty())
        return s;
    const char *p = s.c_str();
    while(p[0] == '.' && (p[1] == '/' || p[1] == '\\'))
        p += 2;
    if(!*p)
        return "";
    char end = s[s.length() - 1];
    if(end == '/' || end == '\\')
    {
        std::string r(p);
        r.erase(r.length() - 1); // strip trailing '/'
        return FixSlashes(r);
    }
    return FixSlashes(p);
}
Exemplo n.º 15
0
/**
 * @brief get filesize
 *
 * @return the filesize or 0 if the file doesn't exist.
 */
size_t FileSystem::GetFilesize(std::string file) const
{
	if (!CheckFile(file))
		return 0;
	FixSlashes(file);
	struct stat info;
	if (stat(file.c_str(), &info) != 0)
		return 0;
	return info.st_size;
}
Exemplo n.º 16
0
HANDLE STEAM_FindFirstFile(char *pszMatchName, STEAMFindFilter filter, WIN32_FIND_DATA *findInfo)
{
	TSteamElemInfo steamFindInfo;
	HANDLE hResult = INVALID_HANDLE_VALUE;
	SteamHandle_t steamResult;
	char tmpMatchName[_MAX_PATH];
	TSteamError steamError;

	if ( STEAMtrackingProgress )
	{
		DoEventTic(FALSE);
	}

	strcpy(tmpMatchName, pszMatchName);			
	FixSlashes(tmpMatchName);

	steamResult = SteamFindFirst(tmpMatchName, (ESteamFindFilter)filter, &steamFindInfo, &steamError);
	CheckError(NULL, &steamError);

	if ( steamResult == STEAM_INVALID_HANDLE )
	{
		hResult = INVALID_HANDLE_VALUE;
	}

	else
	{
		hResult = (HANDLE)steamResult;
		strcpy(findInfo->cFileName, steamFindInfo.cszName);
		
// NEED TO DEAL WITH THIS STUFF!!!  FORTUNATELY HALF-LIFE DOESN'T USE ANY OF IT
// AND ARCANUM USES _findfirst() etc.
//
//		findInfo->ftLastWriteTime = steamFindInfo.lLastModificationTime;
//		findInfo->ftCreationTime = steamFindInfo.lCreationTime;
//		findInfo->ftLastAccessTime = steamFindInfo.lLastAccessTime;
//		findInfo->nFileSizeHigh = ;
//		findInfo->nFileSizeLow = ;

		// Determine if the found object is a directory...
		if ( steamFindInfo.bIsDir )
			findInfo->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
		else
			findInfo->dwFileAttributes &= ~FILE_ATTRIBUTE_DIRECTORY;

		// Determine if the found object was local or remote.
		// ***NOTE*** we are hijacking the FILE_ATTRIBUTE_OFFLINE bit and using it in a different
		//            (but similar) manner than the WIN32 documentation indicates ***NOTE***
		if ( steamFindInfo.bIsLocal )
			findInfo->dwFileAttributes &= ~FILE_ATTRIBUTE_OFFLINE;
		else
			findInfo->dwFileAttributes |= FILE_ATTRIBUTE_OFFLINE;
	}
	
	return hResult;
}
Exemplo n.º 17
0
std::string GetFileDirectory(const char *source)
{
	std::string r = source;
	FixSlashes(r);
	const std::size_t pos = r.rfind(GetDirectorySlashA());
	if (pos != std::string::npos)
	{
		r = r.substr(0, pos + 1);
	}
	return r;
}
Exemplo n.º 18
0
std::string GetFileName(const std::string& source)
{
	std::string r = source;
	FixSlashes(r);
	const std::size_t pos = r.rfind(GetDirectorySlashA());
	if (pos != std::string::npos)
	{
		r = r.substr(pos + 1, std::string::npos);
	}
	return r;
}
Exemplo n.º 19
0
std::vector<std::string> FileSystem::FindFiles(std::string dir, const std::string& pattern, bool recurse, bool include_dirs) const
{
	if (!CheckFile(dir))
		return std::vector<std::string>();
	if (dir.empty())
		dir = "./";
	if (dir[dir.length() - 1] != '/' && dir[dir.length() - 1] != '\\')
		dir += '/';
	FixSlashes(dir);
	return fs.FindFiles(dir, pattern, recurse, include_dirs);
}
Exemplo n.º 20
0
/**
 * @brief locate a file
 *
 * Attempts to locate a file.
 *
 * If the FileSystem::WRITE flag is set, it just returns the argument
 * (assuming the file should come in the current working directory).
 * If FileSystem::CREATE_DIRS is set it tries to create the subdirectory
 * the file should live in.
 *
 * Otherwise (if flags == 0), it dispatches the call to
 * FileSystemHandler::LocateFile(), which either searches for it in multiple
 * data directories (UNIX) or just returns the argument (Windows).
 */
std::string FileSystem::LocateFile(std::string file, int flags) const
{
	if (!CheckFile(file))
		return "";
	FixSlashes(file);

	if (flags & WRITE) {

		if (flags & CREATE_DIRS)
			CreateDirectory(GetDirectory(file));

		return file;
	}
	return fs.LocateFile(file);
}
Exemplo n.º 21
0
std::string FileSystem::LocateFile(std::string file, int flags) const
{
	if (!CheckFile(file)) {
		return "";
	}

	// if it's an absolute path, don't look for it in the data directories
	if (FileSystemHandler::IsAbsolutePath(file)) {
		return file;
	}

	FixSlashes(file);

	if (flags & WRITE) {
		std::string writeableFile = fs.GetWriteDir() + file;
		FixSlashes(writeableFile);
		if (flags & CREATE_DIRS) {
			CreateDirectory(GetDirectory(writeableFile));
		}
		return writeableFile;
	}

	return fs.LocateFile(file);
}
Exemplo n.º 22
0
std::string AddLastSlash(const std::string& path)
{
	if (path.empty())
	{
		return "";
	}
	std::string r = path;
	FixSlashes(r);
	const std::size_t lastChar = r.size() - 1;
	if (r.at(lastChar) != GetDirectorySlashA())
	{
		r.resize(lastChar + 2);
		r[lastChar + 1] = GetDirectorySlashA();
	}
	return r;
}
Exemplo n.º 23
0
/*
===================================
STEAM_GetLocalCopy

Get a local copy of a remote file so that future accesses to this file do not
go out to the server.
===================================
*/
void STEAM_GetLocalCopy( const char *fileName )
{
	char tmpFileName[_MAX_PATH];
	TSteamError steamError;

	if ( STEAMtrackingProgress )
	{
		DoEventTic(TRUE);
	}

	strcpy(tmpFileName, fileName);			
	FixSlashes(tmpFileName);

	SteamGetLocalFileCopy(tmpFileName, &steamError);
	CheckError(NULL, &steamError);
}
Exemplo n.º 24
0
int STEAM_stat(const char *path, struct _stat *buf)
{
	TSteamElemInfo Info;
	int returnVal;
	struct _stat tmpBuf;
	TSteamError steamError;

	char tmpPath[_MAX_PATH];

	if ( STEAMtrackingProgress )
	{
		DoEventTic(FALSE);
	}

	strcpy(tmpPath, path);			
	FixSlashes(tmpPath);

	memset(buf, 0, sizeof(struct _stat));

	returnVal= SteamStat(tmpPath, &Info, &steamError);

	if ( returnVal == 0 )
	{
		if (Info.bIsDir )
		{
			buf->st_mode |= _S_IFDIR;
			buf->st_size = 0;
		}
		else
		{
			buf->st_mode |= _S_IFREG;
			buf->st_size = Info.uSizeOrCount;
		}

		buf->st_atime = Info.lLastAccessTime;
		buf->st_mtime = Info.lLastModificationTime;
		buf->st_ctime = Info.lCreationTime;


		_stat(path, &tmpBuf);
	}

	CheckError(NULL, &steamError);
	return returnVal;
}
Exemplo n.º 25
0
long STEAM_findfirst(char *pszMatchName, STEAMFindFilter filter, struct _finddata_t *fileinfo )
{
	TSteamElemInfo steamFindInfo;
	long hResult = -1;
	SteamHandle_t steamResult;
	char tmpMatchName[_MAX_PATH];
	TSteamError steamError;

	if ( STEAMtrackingProgress )
	{
		DoEventTic(FALSE);
	}

	strcpy(tmpMatchName, pszMatchName);			
	FixSlashes(tmpMatchName);

	steamResult = SteamFindFirst(tmpMatchName, (ESteamFindFilter)filter, &steamFindInfo, &steamError);
	CheckError(NULL, &steamError);

	if ( steamResult == STEAM_INVALID_HANDLE )
	{
		hResult = -1;
	}

	else
	{
		hResult = (long)steamResult;
		strcpy(fileinfo->name, steamFindInfo.cszName);

		fileinfo->size = steamFindInfo.uSizeOrCount;
		fileinfo->time_access = steamFindInfo.lLastAccessTime;
		fileinfo->time_create = steamFindInfo.lCreationTime;
		fileinfo->time_write = steamFindInfo.lLastModificationTime;
		
		// Determine if the found object is a directory...
		if ( steamFindInfo.bIsDir )
			fileinfo->attrib = _A_SUBDIR;
		else
			fileinfo->attrib = _A_NORMAL;

		// ??? Is there anything we can do with bIsLocal?
	}
	
	return hResult;
}
Exemplo n.º 26
0
/*
===================================
STEAM_FileIsAvailLocal

Determine if the file is available locally.
===================================
*/
int STEAM_FileIsAvailLocal( const char *file )
{
	char tmpFileName[_MAX_PATH];
	TSteamError steamError;
	int result;

	if ( STEAMtrackingProgress )
	{
		DoEventTic(TRUE);
	}

	strcpy(tmpFileName, file);			
	FixSlashes(tmpFileName);

	result = SteamIsFileImmediatelyAvailable(tmpFileName, &steamError);
	CheckError(NULL, &steamError);
	return result;
}
Exemplo n.º 27
0
std::vector<std::string> FileSystem::LocateDirs(const std::string& _dir) const
{
	std::vector<std::string> found;

	if (!CheckFile(_dir) || FileSystemHandler::IsAbsolutePath(_dir)) {
		return found;
	}

	std::string dir = _dir;
	FixSlashes(dir);

	const std::vector<std::string>& datadirs = fs.GetDataDirectories();
	std::vector<std::string>::const_iterator dd;
	for (dd = datadirs.begin(); dd != datadirs.end(); ++dd) {
		std::string dirPath((*dd) + dir);
		if (fs.DirExists(dirPath)) {
			found.push_back(dirPath);
		}
	}

	return found;
}
Exemplo n.º 28
0
/**
 * @brief find files
 *
 * Compiles a std::vector of all files below dir that match pattern.
 *
 * If FileSystem::RECURSE flag is set it recurses into subdirectories.
 * If FileSystem::INCLUDE_DIRS flag is set it includes directories in the
 * result too, as long as they match the pattern.
 *
 * Note that pattern doesn't apply to the names of recursed directories,
 * it does apply to the files inside though.
 */
std::vector<std::string> FileSystem::FindFiles(std::string dir, const std::string& pattern, int flags) const
{
	if (!CheckFile(dir)) {
		return std::vector<std::string>();
	}

	if (dir.empty()) {
		dir = "./";
	} else {
		const char lastChar = dir[dir.length() - 1];
		if ((lastChar != '/') && (lastChar != '\\')) {
			dir += '/';
		}
	}

	FixSlashes(dir);

	if (flags & ONLY_DIRS) {
		flags |= INCLUDE_DIRS;
	}

	return fs.FindFiles(dir, pattern, flags);
}
Exemplo n.º 29
0
gs2d::str_type::string AddLastSlash(const gs2d::str_type::string& path)
{
	if (path.empty())
	{
		return GS_L("");
	}
	gs2d::str_type::string r = (path);
	FixSlashes(r);
	const std::size_t lastChar = r.size()-1;

	if (r.at(lastChar) == GS_L('\\'))
	{
		r[lastChar] = GS_L('/');
		return r;
	}
	else if (r.at(lastChar) != GS_L('/'))
	{
		return r + GS_L("/");
	}
	else
	{
		return r;
	}
}
Exemplo n.º 30
0
	std::string AddLastSlash(const std::string& path)
	{
		if (path.empty())
		{
			return "";
		}
		std::string r = (path);
		FixSlashes(r);
		const std::size_t lastChar = r.size()-1;

		if (r.at(lastChar) == '/')
		{
			r[lastChar] = '\\';
			return r;
		}
		else if (r.at(lastChar) != '\\')
		{
			return r + "\\";
		}
		else
		{
			return r;
		}
	}