60 lines
1.8 KiB
C++
60 lines
1.8 KiB
C++
/* -----------------------------------------------------------------------------
|
|
GSFramework
|
|
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
|
----------------------------------------------------------------------------- */
|
|
|
|
|
|
#include "filesystem/io_base.h"
|
|
#include "filesystem/io_handle.h"
|
|
#include "memory/nauto_ptr.h"
|
|
#include "nstring/nstring.h"
|
|
#include "hash/nsha1.h"
|
|
#include "log/log.h"
|
|
|
|
using GS::String;
|
|
using namespace GS::IO;
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
bool Base::FileLoad(const char *uri, GS::Array <char> &buffer)
|
|
{
|
|
AutoPtr <Handle> h(Open(uri));
|
|
if (h.IsNull())
|
|
return false;
|
|
|
|
size_t size = h->GetSize();
|
|
if (!buffer.Allocate(size))
|
|
return false;
|
|
|
|
return asbool(h->Read(buffer.c_ptr(), size) == size);
|
|
}
|
|
bool Base::FileSave(const char *uri, const GS::Array <char> &buffer)
|
|
{
|
|
AutoPtr <Handle> h(Open(uri, ModeWrite));
|
|
if (h.IsNull())
|
|
return false;
|
|
|
|
return asbool(h->Write(buffer.c_ptr(), buffer.GetSize()) == buffer.GetSize());
|
|
}
|
|
//------------------------------------------------------------------------------
|
|
|
|
//------------------------------------------------------------------------------
|
|
bool Base::Exists(const char *uri)
|
|
{
|
|
AutoPtr <Handle> h(Open(uri, ModeRead));
|
|
return h.IsValid();
|
|
}
|
|
String Base::Hash(const char *uri)
|
|
{
|
|
Array <char> data;
|
|
return FileLoad(uri, data) ? SHA1::ComputeHexa(data) : String();
|
|
}
|
|
//------------------------------------------------------------------------------
|
|
|
|
//------------------------------------------------------------------------------
|
|
String Base::MapToAbsolute(const char *uri) const
|
|
{ return String(uri); }
|
|
String Base::MapToRelative(const char *path) const
|
|
{ return String(path); }
|
|
//------------------------------------------------------------------------------
|