Core/Directory: Fix GetResultSize and IsResultDirectory methods on Posix
This commit is contained in:
parent
e299e1f03e
commit
d6392c33ad
|
|
@ -82,6 +82,7 @@ Nazara Engine:
|
||||||
- Fix copy and move semantic on HandledObject and ObjectHandle
|
- Fix copy and move semantic on HandledObject and ObjectHandle
|
||||||
- Add support for emissive and normal maps in .mtl loader using custom keywords ([map_]emissive and [map_]normal)
|
- Add support for emissive and normal maps in .mtl loader using custom keywords ([map_]emissive and [map_]normal)
|
||||||
- Music, Sound and SoundEmitter are now movable
|
- Music, Sound and SoundEmitter are now movable
|
||||||
|
- Fixed Directory::GetResultSize and Directory::IsResultDirectory on Posix systems
|
||||||
|
|
||||||
Nazara Development Kit:
|
Nazara Development Kit:
|
||||||
- Added ImageWidget (#139)
|
- Added ImageWidget (#139)
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,11 @@
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Core/Posix/DirectoryImpl.hpp>
|
#include <Nazara/Core/Posix/DirectoryImpl.hpp>
|
||||||
|
#include <Nazara/Core/Directory.hpp>
|
||||||
#include <Nazara/Core/Error.hpp>
|
#include <Nazara/Core/Error.hpp>
|
||||||
|
#include <Nazara/Core/MemoryHelper.hpp>
|
||||||
#include <Nazara/Core/String.hpp>
|
#include <Nazara/Core/String.hpp>
|
||||||
|
#include <cstring>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
@ -13,9 +16,9 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
DirectoryImpl::DirectoryImpl(const Directory* parent)
|
DirectoryImpl::DirectoryImpl(const Directory* parent) :
|
||||||
|
m_parent(parent)
|
||||||
{
|
{
|
||||||
NazaraUnused(parent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirectoryImpl::Close()
|
void DirectoryImpl::Close()
|
||||||
|
|
@ -30,19 +33,32 @@ namespace Nz
|
||||||
|
|
||||||
UInt64 DirectoryImpl::GetResultSize() const
|
UInt64 DirectoryImpl::GetResultSize() const
|
||||||
{
|
{
|
||||||
struct stat64 resulststat;
|
if (S_ISREG(m_result->d_type))
|
||||||
stat64(m_result->d_name, &resulststat);
|
{
|
||||||
|
String path = m_parent->GetPath();
|
||||||
|
std::size_t pathSize = path.GetSize();
|
||||||
|
|
||||||
return static_cast<UInt64>(resulststat.st_size);
|
std::size_t resultNameSize = std::strlen(m_result->d_name);
|
||||||
|
|
||||||
|
std::size_t fullNameSize = pathSize + 1 + resultNameSize;
|
||||||
|
StackArray<char> fullName = NazaraStackAllocationNoInit(char, fullNameSize + 1);
|
||||||
|
std::memcpy(&fullName[0], path.GetConstBuffer(), pathSize * sizeof(char));
|
||||||
|
fullName[pathSize] = '/';
|
||||||
|
std::memcpy(&fullName[pathSize + 1], m_result->d_name, resultNameSize * sizeof(char));
|
||||||
|
fullName[fullNameSize] = '\0';
|
||||||
|
|
||||||
|
struct stat64 results;
|
||||||
|
stat64(fullName.data(), &results);
|
||||||
|
|
||||||
|
return results.st_size;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DirectoryImpl::IsResultDirectory() const
|
bool DirectoryImpl::IsResultDirectory() const
|
||||||
{
|
{
|
||||||
struct stat64 filestats;
|
return S_ISDIR(m_result->d_type);
|
||||||
if (stat64(m_result->d_name, &filestats) == -1) // error
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return S_ISDIR(filestats.st_mode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DirectoryImpl::NextResult()
|
bool DirectoryImpl::NextResult()
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ namespace Nz
|
||||||
static bool Remove(const String& dirPath);
|
static bool Remove(const String& dirPath);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
const Directory* m_parent;
|
||||||
DIR* m_handle;
|
DIR* m_handle;
|
||||||
dirent64* m_result;
|
dirent64* m_result;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue