Merge branch 'master' into vulkan
Former-commit-id: fd9f2f119e959847d4d9eabece7b678243b26bde
This commit is contained in:
@@ -71,7 +71,7 @@ namespace Nz
|
||||
{
|
||||
std::unique_ptr<Stream> stream(new MemoryStream(byteArray, openMode));
|
||||
|
||||
SetStream(m_ownedStream.get());
|
||||
SetStream(stream.get());
|
||||
// SetStream reset our smart pointer, set it after calling it
|
||||
m_ownedStream = std::move(stream);
|
||||
}
|
||||
@@ -89,7 +89,7 @@ namespace Nz
|
||||
{
|
||||
std::unique_ptr<Stream> stream(new MemoryView(ptr, size));
|
||||
|
||||
SetStream(m_ownedStream.get());
|
||||
SetStream(stream.get());
|
||||
// SetStream reset our smart pointer, set it after calling it
|
||||
m_ownedStream = std::move(stream);
|
||||
}
|
||||
@@ -107,7 +107,7 @@ namespace Nz
|
||||
{
|
||||
std::unique_ptr<Stream> stream(new MemoryView(ptr, size));
|
||||
|
||||
SetStream(m_ownedStream.get());
|
||||
SetStream(stream.get());
|
||||
// SetStream reset our smart pointer, set it after calling it
|
||||
m_ownedStream = std::move(stream);
|
||||
}
|
||||
|
||||
@@ -454,6 +454,25 @@ namespace Nz
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the size of the file
|
||||
* \return true if the file size has correctly changed
|
||||
*
|
||||
* \param size The size the file should have after this call
|
||||
*
|
||||
* \remark The cursor position is not affected by this call
|
||||
* \remark The file must be open in write mode
|
||||
*/
|
||||
bool File::SetSize(UInt64 size)
|
||||
{
|
||||
NazaraLock(m_mutex)
|
||||
|
||||
NazaraAssert(IsOpen(), "File is not open");
|
||||
NazaraAssert(IsWritable(), "File is not writable");
|
||||
|
||||
return m_impl->SetSize(size);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the file path
|
||||
* \return A reference to this
|
||||
|
||||
@@ -449,7 +449,7 @@ namespace Nz
|
||||
Parameter& parameter = CreateValue(name);
|
||||
parameter.type = ParameterType_String;
|
||||
|
||||
PlacementNew<String>(¶meter.value.stringVal, value);
|
||||
PlacementNew(¶meter.value.stringVal, value);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -464,7 +464,7 @@ namespace Nz
|
||||
Parameter& parameter = CreateValue(name);
|
||||
parameter.type = ParameterType_String;
|
||||
|
||||
PlacementNew<String>(¶meter.value.stringVal, value);
|
||||
PlacementNew(¶meter.value.stringVal, value);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -565,7 +565,7 @@ namespace Nz
|
||||
case ParameterType_String:
|
||||
parameter.type = ParameterType_String;
|
||||
|
||||
PlacementNew<String>(¶meter.value.stringVal, it->second.value.stringVal);
|
||||
PlacementNew(¶meter.value.stringVal, it->second.value.stringVal);
|
||||
break;
|
||||
|
||||
case ParameterType_Userdata:
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Win32/FileImpl.hpp>
|
||||
#include <Nazara/Core/CallOnExit.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Win32/Time.hpp>
|
||||
#include <memory>
|
||||
@@ -64,7 +65,7 @@ namespace Nz
|
||||
{
|
||||
access |= GENERIC_READ;
|
||||
|
||||
if ((mode & OpenMode_WriteOnly) == 0)
|
||||
if (mode & OpenMode_MustExit || (mode & OpenMode_WriteOnly) == 0)
|
||||
openMode |= OPEN_EXISTING;
|
||||
}
|
||||
|
||||
@@ -77,6 +78,8 @@ namespace Nz
|
||||
|
||||
if (mode & OpenMode_Truncate)
|
||||
openMode |= CREATE_ALWAYS;
|
||||
else if (mode & OpenMode_MustExit)
|
||||
openMode |= OPEN_EXISTING;
|
||||
else
|
||||
openMode |= OPEN_ALWAYS;
|
||||
}
|
||||
@@ -156,6 +159,31 @@ namespace Nz
|
||||
return SetFilePointerEx(m_handle, distance, nullptr, moveMethod) != 0;
|
||||
}
|
||||
|
||||
bool FileImpl::SetSize(UInt64 size)
|
||||
{
|
||||
UInt64 cursorPos = GetCursorPos();
|
||||
|
||||
CallOnExit resetCursor([this, cursorPos] ()
|
||||
{
|
||||
if (!SetCursorPos(CursorPosition_AtBegin, cursorPos))
|
||||
NazaraWarning("Failed to reset cursor position to previous position: " + Error::GetLastSystemError());
|
||||
});
|
||||
|
||||
if (!SetCursorPos(CursorPosition_AtBegin, size))
|
||||
{
|
||||
NazaraError("Failed to set file size: failed to move cursor position: " + Error::GetLastSystemError());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!SetEndOfFile(m_handle))
|
||||
{
|
||||
NazaraError("Failed to set file size: " + Error::GetLastSystemError());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::size_t FileImpl::Write(const void* buffer, std::size_t size)
|
||||
{
|
||||
DWORD written = 0;
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace Nz
|
||||
bool Open(const String& filePath, UInt32 mode);
|
||||
std::size_t Read(void* buffer, std::size_t size);
|
||||
bool SetCursorPos(CursorPosition pos, Int64 offset);
|
||||
bool SetSize(UInt64 size);
|
||||
std::size_t Write(const void* buffer, std::size_t size);
|
||||
|
||||
FileImpl& operator=(const FileImpl&) = delete;
|
||||
|
||||
@@ -634,7 +634,7 @@ namespace Nz
|
||||
void LuaInstance::PushFunction(LuaFunction func) const
|
||||
{
|
||||
LuaFunction* luaFunc = static_cast<LuaFunction*>(lua_newuserdata(m_state, sizeof(LuaFunction)));
|
||||
PlacementNew<LuaFunction>(luaFunc, std::move(func));
|
||||
PlacementNew(luaFunc, std::move(func));
|
||||
|
||||
lua_pushcclosure(m_state, ProxyFunc, 1);
|
||||
}
|
||||
|
||||
@@ -359,13 +359,10 @@ namespace Nz
|
||||
if (!s_defaultFont)
|
||||
{
|
||||
FontRef cabin = Font::New();
|
||||
if (!cabin->OpenFromMemory(r_cabinRegular, sizeof(r_cabinRegular)))
|
||||
{
|
||||
if (cabin->OpenFromMemory(r_cabinRegular, sizeof(r_cabinRegular)))
|
||||
s_defaultFont = cabin;
|
||||
else
|
||||
NazaraError("Failed to open default font");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
s_defaultFont = cabin;
|
||||
}
|
||||
|
||||
return s_defaultFont;
|
||||
|
||||
Reference in New Issue
Block a user