Common: Remove unused Copy, CopyDir and GetThemeDir functions from FileUtil.
This commit is contained in:
parent
f4e1d8ea36
commit
5a9b706f31
2 changed files with 0 additions and 123 deletions
|
@ -264,83 +264,6 @@ bool Rename(const std::string &srcFilename, const std::string &destFilename)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// copies file srcFilename to destFilename, returns true on success
|
|
||||||
bool Copy(const std::string &srcFilename, const std::string &destFilename)
|
|
||||||
{
|
|
||||||
LOG_TRACE(Common_Filesystem, "%s --> %s",
|
|
||||||
srcFilename.c_str(), destFilename.c_str());
|
|
||||||
#ifdef _WIN32
|
|
||||||
if (CopyFile(Common::UTF8ToTStr(srcFilename).c_str(), Common::UTF8ToTStr(destFilename).c_str(), FALSE))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
LOG_ERROR(Common_Filesystem, "failed %s --> %s: %s",
|
|
||||||
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
|
|
||||||
return false;
|
|
||||||
#else
|
|
||||||
|
|
||||||
// buffer size
|
|
||||||
#define BSIZE 1024
|
|
||||||
|
|
||||||
char buffer[BSIZE];
|
|
||||||
|
|
||||||
// Open input file
|
|
||||||
FILE *input = fopen(srcFilename.c_str(), "rb");
|
|
||||||
if (!input)
|
|
||||||
{
|
|
||||||
LOG_ERROR(Common_Filesystem, "opening input failed %s --> %s: %s",
|
|
||||||
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// open output file
|
|
||||||
FILE *output = fopen(destFilename.c_str(), "wb");
|
|
||||||
if (!output)
|
|
||||||
{
|
|
||||||
fclose(input);
|
|
||||||
LOG_ERROR(Common_Filesystem, "opening output failed %s --> %s: %s",
|
|
||||||
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// copy loop
|
|
||||||
while (!feof(input))
|
|
||||||
{
|
|
||||||
// read input
|
|
||||||
int rnum = fread(buffer, sizeof(char), BSIZE, input);
|
|
||||||
if (rnum != BSIZE)
|
|
||||||
{
|
|
||||||
if (ferror(input) != 0)
|
|
||||||
{
|
|
||||||
LOG_ERROR(Common_Filesystem,
|
|
||||||
"failed reading from source, %s --> %s: %s",
|
|
||||||
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
|
|
||||||
goto bail;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// write output
|
|
||||||
int wnum = fwrite(buffer, sizeof(char), rnum, output);
|
|
||||||
if (wnum != rnum)
|
|
||||||
{
|
|
||||||
LOG_ERROR(Common_Filesystem,
|
|
||||||
"failed writing to output, %s --> %s: %s",
|
|
||||||
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
|
|
||||||
goto bail;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// close files
|
|
||||||
fclose(input);
|
|
||||||
fclose(output);
|
|
||||||
return true;
|
|
||||||
bail:
|
|
||||||
if (input)
|
|
||||||
fclose(input);
|
|
||||||
if (output)
|
|
||||||
fclose(output);
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the size of filename (64bit)
|
// Returns the size of filename (64bit)
|
||||||
u64 GetSize(const std::string &filename)
|
u64 GetSize(const std::string &filename)
|
||||||
{
|
{
|
||||||
|
@ -564,43 +487,6 @@ bool DeleteDirRecursively(const std::string &directory)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create directory and copy contents (does not overwrite existing files)
|
|
||||||
void CopyDir(const std::string &source_path, const std::string &dest_path)
|
|
||||||
{
|
|
||||||
#ifndef _WIN32
|
|
||||||
if (source_path == dest_path) return;
|
|
||||||
if (!FileUtil::Exists(source_path)) return;
|
|
||||||
if (!FileUtil::Exists(dest_path)) FileUtil::CreateFullPath(dest_path);
|
|
||||||
|
|
||||||
struct dirent dirent, *result = nullptr;
|
|
||||||
DIR *dirp = opendir(source_path.c_str());
|
|
||||||
if (!dirp) return;
|
|
||||||
|
|
||||||
while (!readdir_r(dirp, &dirent, &result) && result)
|
|
||||||
{
|
|
||||||
const std::string virtualName(result->d_name);
|
|
||||||
// check for "." and ".."
|
|
||||||
if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
|
|
||||||
((virtualName[0] == '.') && (virtualName[1] == '.') &&
|
|
||||||
(virtualName[2] == '\0')))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
std::string source, dest;
|
|
||||||
source = source_path + virtualName;
|
|
||||||
dest = dest_path + virtualName;
|
|
||||||
if (IsDirectory(source))
|
|
||||||
{
|
|
||||||
source += '/';
|
|
||||||
dest += '/';
|
|
||||||
if (!FileUtil::Exists(dest)) FileUtil::CreateFullPath(dest);
|
|
||||||
CopyDir(source, dest);
|
|
||||||
}
|
|
||||||
else if (!FileUtil::Exists(dest)) FileUtil::Copy(source, dest);
|
|
||||||
}
|
|
||||||
closedir(dirp);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the current directory
|
// Returns the current directory
|
||||||
std::string GetCurrentDir()
|
std::string GetCurrentDir()
|
||||||
{
|
{
|
||||||
|
|
|
@ -90,9 +90,6 @@ bool DeleteDir(const std::string &filename);
|
||||||
// renames file srcFilename to destFilename, returns true on success
|
// renames file srcFilename to destFilename, returns true on success
|
||||||
bool Rename(const std::string &srcFilename, const std::string &destFilename);
|
bool Rename(const std::string &srcFilename, const std::string &destFilename);
|
||||||
|
|
||||||
// copies file srcFilename to destFilename, returns true on success
|
|
||||||
bool Copy(const std::string &srcFilename, const std::string &destFilename);
|
|
||||||
|
|
||||||
// creates an empty file filename, returns true on success
|
// creates an empty file filename, returns true on success
|
||||||
bool CreateEmptyFile(const std::string &filename);
|
bool CreateEmptyFile(const std::string &filename);
|
||||||
|
|
||||||
|
@ -106,9 +103,6 @@ bool DeleteDirRecursively(const std::string &directory);
|
||||||
// Returns the current directory
|
// Returns the current directory
|
||||||
std::string GetCurrentDir();
|
std::string GetCurrentDir();
|
||||||
|
|
||||||
// Create directory and copy contents (does not overwrite existing files)
|
|
||||||
void CopyDir(const std::string &source_path, const std::string &dest_path);
|
|
||||||
|
|
||||||
// Set the current directory to given directory
|
// Set the current directory to given directory
|
||||||
bool SetCurrentDir(const std::string &directory);
|
bool SetCurrentDir(const std::string &directory);
|
||||||
|
|
||||||
|
@ -116,9 +110,6 @@ bool SetCurrentDir(const std::string &directory);
|
||||||
// directory. To be used in "multi-user" mode (that is, installed).
|
// directory. To be used in "multi-user" mode (that is, installed).
|
||||||
const std::string& GetUserPath(const unsigned int DirIDX, const std::string &newPath="");
|
const std::string& GetUserPath(const unsigned int DirIDX, const std::string &newPath="");
|
||||||
|
|
||||||
// probably doesn't belong here
|
|
||||||
//std::string GetThemeDir(const std::string& theme_name);
|
|
||||||
|
|
||||||
// Returns the path to where the sys file are
|
// Returns the path to where the sys file are
|
||||||
std::string GetSysDirectory();
|
std::string GetSysDirectory();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue