[fnd] Removed unused functions.

This commit is contained in:
jakcron 2018-06-24 17:17:21 +08:00
parent 7a8d8e0fea
commit 4be0b51ddb
2 changed files with 0 additions and 114 deletions

View file

@ -1,6 +1,5 @@
#pragma once #pragma once
#include <string> #include <string>
#include <fnd/MemoryBlob.h>
namespace fnd namespace fnd
{ {
@ -13,10 +12,6 @@ namespace fnd
#endif #endif
size_t getFileSize(const std::string& path); size_t getFileSize(const std::string& path);
void readFile(const std::string& path, MemoryBlob& blob);
void readFile(const std::string& path, size_t offset, size_t len, MemoryBlob& blob);
void writeFile(const std::string& path, const MemoryBlob& blob);
void writeFile(const std::string& path, const byte_t* data, size_t len);
void makeDirectory(const std::string& path); void makeDirectory(const std::string& path);
void getEnvironVar(std::string& var, const std::string& key); void getEnvironVar(std::string& var, const std::string& key);
void appendToPath(std::string& base, const std::string& add); void appendToPath(std::string& base, const std::string& add);

View file

@ -11,9 +11,6 @@
using namespace fnd; using namespace fnd;
static const std::string kModuleName = "IO";
static const size_t kBlockSize = 0x100000;
size_t io::getFileSize(const std::string& path) size_t io::getFileSize(const std::string& path)
{ {
std::ifstream f; std::ifstream f;
@ -25,112 +22,6 @@ size_t io::getFileSize(const std::string& path)
return static_cast<size_t>(f.tellg() - begin_pos); return static_cast<size_t>(f.tellg() - begin_pos);
} }
void io::readFile(const std::string& path, MemoryBlob & blob)
{
fnd::SimpleFile file;
try
{
file.open(path, file.Read);
}
catch (const fnd::Exception&)
{
throw fnd::Exception(kModuleName, "Failed to open \"" + path + "\": does not exist");
}
size_t filesz, filepos;
filesz = file.size();
try {
blob.alloc(filesz);
}
catch (const fnd::Exception& e)
{
throw fnd::Exception(kModuleName, "Failed to allocate memory for file: " + std::string(e.what()));
}
for (filepos = 0; filesz > kBlockSize; filesz -= kBlockSize, filepos += kBlockSize)
{
file.read(blob.getBytes() + filepos, kBlockSize);
}
if (filesz)
{
file.read(blob.getBytes() + filepos, filesz);
}
}
void fnd::io::readFile(const std::string& path, size_t offset, size_t len, MemoryBlob& blob)
{
fnd::SimpleFile file;
try
{
file.open(path, file.Read);
} catch (const fnd::Exception&)
{
throw fnd::Exception(kModuleName, "Failed to open \"" + path + "\": does not exist");
}
size_t filesz, filepos;
filesz = file.size();
file.seek(offset);
if (filesz < len || filesz < offset || filesz < (offset + len))
{
throw Exception(kModuleName, "Failed to open \"" + path + "\": file to small");
}
try
{
blob.alloc(filesz);
} catch (const fnd::Exception& e)
{
throw fnd::Exception(kModuleName, "Failed to allocate memory for file: " + std::string(e.what()));
}
for (filepos = 0; filesz > kBlockSize; filesz -= kBlockSize, filepos += kBlockSize)
{
file.read(blob.getBytes() + filepos, kBlockSize);
}
if (filesz)
{
file.read(blob.getBytes() + filepos, filesz);
}
}
void io::writeFile(const std::string& path, const MemoryBlob & blob)
{
writeFile(path, blob.getBytes(), blob.getSize());
}
void io::writeFile(const std::string & path, const byte_t * data, size_t len)
{
fnd::SimpleFile file;
try
{
file.open(path, file.Create);
} catch (const fnd::Exception&)
{
throw fnd::Exception(kModuleName, "Failed to open \"" + path + "\": does not exist");
}
size_t filesz, filepos;
filesz = len;
for (filepos = 0; filesz > kBlockSize; filesz -= kBlockSize, filepos += kBlockSize)
{
file.write(data + filepos, kBlockSize);
}
if (filesz)
{
file.write(data + filepos, filesz);
}
}
void io::makeDirectory(const std::string& path) void io::makeDirectory(const std::string& path)
{ {
#ifdef _WIN32 #ifdef _WIN32