[DEV] try a new mode of the archive loading data (only when needed)
This commit is contained in:
parent
2e664009f8
commit
fd6dc6e6cc
@ -46,3 +46,28 @@ etk::Archive* etk::Archive::Load(const etk::UString& _fileName)
|
||||
}
|
||||
|
||||
|
||||
void etk::Archive::Open(const etk::UString& _key)
|
||||
{
|
||||
if (m_content.Exist(_key)==false) {
|
||||
TK_ERROR("Try open an unexistant file : '" << _key << "'");
|
||||
return;
|
||||
}
|
||||
if (m_content[_key].GetNumberOfRef()==-1) {
|
||||
LoadFile(m_content.GetId(_key));
|
||||
m_content[_key].IncreaseRef();
|
||||
}
|
||||
m_content[_key].IncreaseRef();
|
||||
}
|
||||
|
||||
void etk::Archive::Close(const etk::UString& _key)
|
||||
{
|
||||
if (m_content.Exist(_key)==false) {
|
||||
TK_ERROR("Try close an unexistant file : '" << _key << "'");
|
||||
return;
|
||||
}
|
||||
if (m_content[_key].GetNumberOfRef()==0){
|
||||
TK_ERROR("Try close one more time the file : '" << _key << "'");
|
||||
} else {
|
||||
m_content[_key].DecreaseRef();
|
||||
}
|
||||
}
|
||||
|
@ -21,9 +21,19 @@ namespace etk
|
||||
class Content
|
||||
{
|
||||
private:
|
||||
etk::Vector<char> m_data; // if null ==> this is a folder...
|
||||
int32_t m_link; //!< number of element open on this file
|
||||
public:
|
||||
Content(esize_t _basicSize=0) : m_data(_basicSize) { m_data.ReSize(_basicSize, 0); };
|
||||
void IncreaseRef(void) { m_link++; };
|
||||
void DecreaseRef(void) { m_link--; };
|
||||
int32_t GetNumberOfRef(void) const { return m_link; };
|
||||
private:
|
||||
esize_t m_theoricSize; //!< number of element open on this file
|
||||
public:
|
||||
esize_t GetTheoricSize(void) const { return m_theoricSize; };
|
||||
private:
|
||||
etk::Vector<char> m_data;
|
||||
public:
|
||||
Content(esize_t _basicSize=0) : m_link(-1), m_theoricSize(_basicSize) { };
|
||||
esize_t Size(void) const { return m_data.Size(); };
|
||||
void* Data(void) const { return (void*)&m_data[0]; };
|
||||
etk::Vector<char>& GetDataVector(void) { return m_data; };
|
||||
@ -71,10 +81,26 @@ namespace etk
|
||||
* @return true if the file is present
|
||||
*/
|
||||
bool Exist(const etk::UString& _key) const { return m_content.Exist(_key); };
|
||||
/**
|
||||
* @brief Load the specific file in the memory
|
||||
* @param[in] _key Name of the file
|
||||
*/
|
||||
void Open(const etk::UString& _key);
|
||||
/**
|
||||
* @brief Un-Load the specific file from the memory
|
||||
* @param[in] _key Name of the file
|
||||
*/
|
||||
void Close(const etk::UString& _key);
|
||||
/**
|
||||
* @brief Display all Element in the archive
|
||||
*/
|
||||
void Display(void);
|
||||
protected:
|
||||
/**
|
||||
* @brief Request the load in memory of the concerned file.
|
||||
* @param[in] _id Id of the file to load.
|
||||
*/
|
||||
virtual void LoadFile(int32_t _id) { };
|
||||
public:
|
||||
/**
|
||||
* @brief Load an Achive with a specific name.
|
||||
|
@ -44,6 +44,8 @@ etk::archive::Zip::Zip(const etk::UString& _fileName) :
|
||||
}
|
||||
int error = UNZ_OK;
|
||||
m_content.Add(tmpFileName, etk::Archive::Content(tmpFileInfo.uncompressed_size));
|
||||
// request the resize of the data :
|
||||
m_content[tmpFileName].GetDataVector().ReSize(tmpFileInfo.uncompressed_size, 0);
|
||||
void* data = m_content[tmpFileName].Data();
|
||||
if(NULL == data) {
|
||||
TK_ERROR("Allocation error...");
|
||||
@ -78,3 +80,7 @@ etk::archive::Zip::~Zip(void)
|
||||
};
|
||||
};
|
||||
|
||||
void etk::archive::Zip::LoadFile(int32_t _id)
|
||||
{
|
||||
TK_WARNING("Load file Here ... : " << _id << " = '" << m_content.GetKey(_id) << "'");
|
||||
}
|
||||
|
@ -26,6 +26,8 @@ namespace etk
|
||||
public:
|
||||
Zip(const etk::UString& _fileName);
|
||||
virtual ~Zip(void);
|
||||
protected: // herited functions :
|
||||
virtual void LoadFile(int32_t _id);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
@ -1321,7 +1321,7 @@ uint64_t etk::FSNode::FileSize(void)
|
||||
if( etk::FSN_TYPE_DATA == m_type
|
||||
|| etk::FSN_TYPE_THEME_DATA == m_type) {
|
||||
if (true == LoadDataZip()) {
|
||||
return m_zipContent->Size();
|
||||
return m_zipContent->GetTheoricSize();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user