You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
168 lines
4.3 KiB
C++
168 lines
4.3 KiB
C++
/*
|
|
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
* its licensors.
|
|
*
|
|
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
* distribution (the "License"). All use of this software is governed by the License,
|
|
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
*
|
|
*/
|
|
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
|
|
#include "EditorDefs.h"
|
|
|
|
#include "PakFile.h"
|
|
|
|
// AzFramework
|
|
#include <AzFramework/Archive/INestedArchive.h>
|
|
#include <AzFramework/Archive/IArchive.h>
|
|
|
|
// Editor
|
|
#include "Util/CryMemFile.h"
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
CPakFile::CPakFile()
|
|
: m_pArchive(NULL)
|
|
, m_pCryPak(NULL)
|
|
{
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
CPakFile::CPakFile(AZ::IO::IArchive* pCryPak)
|
|
: m_pArchive(NULL)
|
|
, m_pCryPak(pCryPak)
|
|
{
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
CPakFile::~CPakFile()
|
|
{
|
|
Close();
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
CPakFile::CPakFile(const char* filename)
|
|
{
|
|
m_pArchive = NULL;
|
|
Open(filename);
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
void CPakFile::Close()
|
|
{
|
|
m_pArchive = NULL;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
bool CPakFile::Open(const char* filename, bool bAbsolutePath)
|
|
{
|
|
if (m_pArchive)
|
|
{
|
|
Close();
|
|
}
|
|
|
|
auto pCryPak = m_pCryPak ? m_pCryPak : GetIEditor()->GetSystem()->GetIPak();
|
|
if (pCryPak == NULL)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (bAbsolutePath)
|
|
{
|
|
m_pArchive = pCryPak->OpenArchive(filename, nullptr, AZ::IO::INestedArchive::FLAGS_ABSOLUTE_PATHS);
|
|
}
|
|
else
|
|
{
|
|
m_pArchive = pCryPak->OpenArchive(filename);
|
|
}
|
|
if (m_pArchive)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
bool CPakFile::OpenForRead(const char* filename)
|
|
{
|
|
if (m_pArchive)
|
|
{
|
|
Close();
|
|
}
|
|
auto pCryPak = m_pCryPak ? m_pCryPak : GetIEditor()->GetSystem()->GetIPak();
|
|
if (pCryPak == NULL)
|
|
{
|
|
return false;
|
|
}
|
|
m_pArchive = pCryPak->OpenArchive(filename, nullptr, AZ::IO::INestedArchive::FLAGS_OPTIMIZED_READ_ONLY | AZ::IO::INestedArchive::FLAGS_ABSOLUTE_PATHS);
|
|
if (m_pArchive)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
bool CPakFile::UpdateFile(const char* filename, CCryMemFile& file, bool bCompress)
|
|
{
|
|
if (m_pArchive)
|
|
{
|
|
int nSize = file.GetLength();
|
|
|
|
UpdateFile(filename, file.GetMemPtr(), nSize, bCompress);
|
|
file.Close();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
bool CPakFile::UpdateFile(const char* filename, CMemoryBlock& mem, bool bCompress, int nCompressLevel)
|
|
{
|
|
if (m_pArchive)
|
|
{
|
|
return UpdateFile(filename, mem.GetBuffer(), mem.GetSize(), bCompress, nCompressLevel);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
bool CPakFile::UpdateFile(const char* filename, void* pBuffer, int nSize, bool bCompress, int nCompressLevel)
|
|
{
|
|
if (m_pArchive)
|
|
{
|
|
if (bCompress)
|
|
{
|
|
return 0 == m_pArchive->UpdateFile(filename, pBuffer, nSize, AZ::IO::INestedArchive::METHOD_DEFLATE, nCompressLevel);
|
|
}
|
|
else
|
|
{
|
|
return 0 == m_pArchive->UpdateFile(filename, pBuffer, nSize);
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
bool CPakFile::RemoveFile(const char* filename)
|
|
{
|
|
if (m_pArchive)
|
|
{
|
|
return m_pArchive->RemoveFile(filename);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
bool CPakFile::RemoveDir(const char* directory)
|
|
{
|
|
if (m_pArchive)
|
|
{
|
|
return m_pArchive->RemoveDir(directory);
|
|
}
|
|
return false;
|
|
}
|