mirror of
https://github.com/jakcron/nstool.git
synced 2024-12-22 18:55:29 +00:00
[fnd] Removed unused functions.
This commit is contained in:
parent
7a8d8e0fea
commit
4be0b51ddb
|
@ -1,6 +1,5 @@
|
|||
#pragma once
|
||||
#include <string>
|
||||
#include <fnd/MemoryBlob.h>
|
||||
|
||||
namespace fnd
|
||||
{
|
||||
|
@ -13,10 +12,6 @@ namespace fnd
|
|||
#endif
|
||||
|
||||
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 getEnvironVar(std::string& var, const std::string& key);
|
||||
void appendToPath(std::string& base, const std::string& add);
|
||||
|
|
|
@ -11,9 +11,6 @@
|
|||
|
||||
using namespace fnd;
|
||||
|
||||
static const std::string kModuleName = "IO";
|
||||
static const size_t kBlockSize = 0x100000;
|
||||
|
||||
size_t io::getFileSize(const std::string& path)
|
||||
{
|
||||
std::ifstream f;
|
||||
|
@ -25,112 +22,6 @@ size_t io::getFileSize(const std::string& path)
|
|||
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)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
|
|
Loading…
Reference in a new issue