Remove FileCat.cpp & .h

Not used anywhere in the code.
Moved ChompSlash from FileCat.cpp to image.cpp, as the only two references besides ones in filecat.cpp for the function were in there. The references are inside an #ifdef 0 block so they are not compiled currently, but this should prevent them from not working IF we ever enable them
This commit is contained in:
Asdow
2023-10-21 15:38:31 +03:00
parent d43a597423
commit 5b635784cd
5 changed files with 11 additions and 151 deletions
-1
View File
@@ -9,7 +9,6 @@ set(SGPSrc
"${CMAKE_CURRENT_SOURCE_DIR}/DirectDraw Calls.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/DirectX Common.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/English.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/FileCat.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/FileMan.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Flic.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Font.cpp"
-100
View File
@@ -1,100 +0,0 @@
//
// Snap: Implementation of the TFileCat class
//
#include "FileCat.h"
#include "readdir.h"
// Remove a slash or backslash (if any) from the end of a string
void ChompSlash(std::string& s)
{
if ( s.empty() ) return;
if ( *s.rbegin() == '\\' || *s.rbegin() == '/' ) {
s.erase( s.length() - 1 );
}
}
// Build a new file catalogue by recursively traversing the root directory
void TFileCat::NewCat(std::string root)
{
fRootDir = root;
ChompSlash(fRootDir);
fFileCat.clear();
TraverseDir(fRootDir);
}
// Look for a given file in the catalogue
// Unless pathIncludesRoot == true, will prepend the root directory to path
bool TFileCat::FindFile(std::string path, bool pathIncludesRoot) const
{
if (pathIncludesRoot) return fFileCat.find(path) != fFileCat.end();
else return fFileCat.find(fRootDir + '\\' + path) != fFileCat.end();
}
// Delete a given file from the catalogue
// Unless pathIncludesRoot == true, will prepend the root directory to path
size_t TFileCat::RemoveFile(std::string path, bool pathIncludesRoot)
{
if (pathIncludesRoot) return fFileCat.erase(path);
else return fFileCat.erase(fRootDir + '\\' + path);
}
// Delete all files from a given directory in the catalogue
// Unless pathIncludesRoot == true, will prepend the root directory to path
size_t TFileCat::RemoveDir(std::string dir, bool pathIncludesRoot)
{
if ( !pathIncludesRoot ) dir = fRootDir + '\\' + dir;
ChompSlash(dir);
std::string dirlower = dir + '\\';
std::string dirupper = dir + char('\\'+1);
TCatalogue::iterator upper = fFileCat.upper_bound(dirupper);
TCatalogue::iterator lower;
int deleted = 0;
while ( ( lower = fFileCat.lower_bound(dirlower) ) != upper) {
fFileCat.erase(lower);
deleted++;
}
return deleted;
}
// Recursively traverse a directory, adding regular files to the catalogue
void TFileCat::TraverseDir(std::string dir, int depth)
{
using std::string;
static string dot( ".");
static string dotdot( "..");
static string svn( ".svn");
if (!dir.empty()) dir += '\\';
TReadDir readDir((dir + "*").c_str());
char const* fileName;
unsigned attrib;
while ( readDir.NextFile(fileName, attrib) ) {
if (dot == fileName || dotdot == fileName || svn == fileName) continue;
string fullPath = dir + fileName;
if (attrib & FILE_ATTRIBUTE_DIRECTORY) {
if (depth < 0) TraverseDir(fullPath);
else if (depth > 0) TraverseDir(fullPath, depth-1);
}
else {
fFileCat.insert(fullPath);
}
}
}
-48
View File
@@ -1,48 +0,0 @@
//
// Snap: Declaration of the TFileCat class
//
// This class catalogues files in a directory and all its subdirectories
//
#ifndef FILECAT_H
#define FILECAT_H
#include "stringicmp.h"
#include <string>
#include <set>
class TFileCat {
public:
TFileCat(std::string root) { NewCat(root); }
TFileCat() {}
// Build a new file catalogue by recursively traversing the root directory
void NewCat(std::string root);
std::string GetRootDir() const { return fRootDir; }
// Look for a given file in the catalogue
// Unless pathIncludesRoot == true, will prepend the root directory to path
bool FindFile(std::string path, bool pathIncludesRoot = false) const;
// Delete a given file from the catalogue
// Unless pathIncludesRoot == true, will prepend the root directory to path
size_t RemoveFile(std::string path, bool pathIncludesRoot = false);
// Delete all files from a given directory in the catalogue
// Unless pathIncludesRoot == true, will prepend the root directory to path
size_t RemoveDir(std::string dir, bool pathIncludesRoot = false);
private:
typedef std::set<std::string, TStringiLess> TCatalogue;
std::string fRootDir;
TCatalogue fFileCat;
// Recursively traverse a directory, adding regular files to the catalogue
void TraverseDir(std::string dir, int depth = -1);
};
#endif // FILECAT_H
-2
View File
@@ -20,10 +20,8 @@
//**************************************************************************
#include "types.h"
#include "Windows.h"
#include "FileCat.h"
//**************************************************************************
+11
View File
@@ -406,7 +406,18 @@ vfs::Path CreateFileName(vfs::Path const& sOutPathName, vfs::Path const& sFileNa
outPath += vfs::Path(fullpath.str());
return outPath;
}
#if 0
// Remove a slash or backslash (if any) from the end of a string
void ChompSlash(std::string& s)
{
if (s.empty()) return;
if (*s.rbegin() == '\\' || *s.rbegin() == '/') {
s.erase(s.length() - 1);
}
}
bool CImage::WriteAsBMPs(vfs_string sOutPathName)
{
if(!this->LoadData())