diff --git a/etk/archive/Archive.cpp b/etk/archive/Archive.cpp index ee79256..f63fb14 100644 --- a/etk/archive/Archive.cpp +++ b/etk/archive/Archive.cpp @@ -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(); + } +} diff --git a/etk/archive/Archive.h b/etk/archive/Archive.h index 8503177..f2b84c7 100644 --- a/etk/archive/Archive.h +++ b/etk/archive/Archive.h @@ -21,9 +21,19 @@ namespace etk class Content { private: - etk::Vector 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 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& 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. diff --git a/etk/archive/Zip.cpp b/etk/archive/Zip.cpp index b234f60..775ef38 100644 --- a/etk/archive/Zip.cpp +++ b/etk/archive/Zip.cpp @@ -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) << "'"); +} diff --git a/etk/archive/Zip.h b/etk/archive/Zip.h index 83b97b9..195c53d 100644 --- a/etk/archive/Zip.h +++ b/etk/archive/Zip.h @@ -26,6 +26,8 @@ namespace etk public: Zip(const etk::UString& _fileName); virtual ~Zip(void); + protected: // herited functions : + virtual void LoadFile(int32_t _id); }; }; }; diff --git a/etk/os/FSNode.cpp b/etk/os/FSNode.cpp index 2b11fc9..a7c09af 100644 --- a/etk/os/FSNode.cpp +++ b/etk/os/FSNode.cpp @@ -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; }