diff --git a/Sources/appl/Buffer/BufferText.cpp b/Sources/appl/Buffer/BufferText.cpp index 19240eb..ede9c03 100644 --- a/Sources/appl/Buffer/BufferText.cpp +++ b/Sources/appl/Buffer/BufferText.cpp @@ -128,8 +128,7 @@ BufferText::BufferText(etk::FSNode &fileName) : Buffer(fileName) APPL_WARNING("File can not be open in read mode : " << myFile); SetModify(true); } else { - // TODO : Old methode to file access : - //m_EdnBuf.DumpFrom(myFile); + m_EdnBuf.DumpFrom(myFile); myFile.FileClose(); SetModify(false); } @@ -157,8 +156,7 @@ void BufferText::Save(void) if (false == myFile.FileOpenWrite()) { APPL_ERROR("Can not open in writing the specify file"); } else { - // TODO : Old methode to file access : - //m_EdnBuf.DumpIn(myFile); + m_EdnBuf.DumpIn(myFile); myFile.FileClose(); SetModify(false); } diff --git a/Sources/appl/Buffer/EdnBuf/EdnBuf.cpp b/Sources/appl/Buffer/EdnBuf/EdnBuf.cpp index c1efad6..2c4eb30 100644 --- a/Sources/appl/Buffer/EdnBuf/EdnBuf.cpp +++ b/Sources/appl/Buffer/EdnBuf/EdnBuf.cpp @@ -89,10 +89,10 @@ EdnBuf::~EdnBuf(void) * @return true if OK / false if an error occured * */ -bool EdnBuf::DumpIn(FILE *myFile) +bool EdnBuf::DumpIn(etk::FSNode &file) { // write Data - return m_data.DumpIn(myFile); + return m_data.DumpIn(file); } @@ -104,9 +104,9 @@ bool EdnBuf::DumpIn(FILE *myFile) * @return true if OK / false if an error occured * */ -bool EdnBuf::DumpFrom(FILE *myFile) +bool EdnBuf::DumpFrom(etk::FSNode &file) { - if (true == m_data.DumpFrom(myFile) ) { + if (true == m_data.DumpFrom(file) ) { // set no selection UpdateSelection(0, 0, m_data.Size() ); // generate HighLight diff --git a/Sources/appl/Buffer/EdnBuf/EdnBuf.h b/Sources/appl/Buffer/EdnBuf/EdnBuf.h index 5c28ba0..be2dd2d 100644 --- a/Sources/appl/Buffer/EdnBuf/EdnBuf.h +++ b/Sources/appl/Buffer/EdnBuf/EdnBuf.h @@ -78,8 +78,8 @@ class EdnBuf { void SetAll( etk::Vector &text); void GetRange( int32_t start, int32_t end, etk::Vector &output); void GetRange( int32_t start, int32_t end, etk::UString &output); - bool DumpIn( FILE *myFile); - bool DumpFrom( FILE *myFile); + bool DumpIn( etk::FSNode &file); + bool DumpFrom( etk::FSNode &file); // replace with operator [] ... int8_t operator[] (int32_t); int32_t Insert( int32_t pos, etk::Vector &insertText); diff --git a/Sources/appl/Buffer/EdnVectorBuf.cpp b/Sources/appl/Buffer/EdnVectorBuf.cpp index 4e55425..0eff815 100644 --- a/Sources/appl/Buffer/EdnVectorBuf.cpp +++ b/Sources/appl/Buffer/EdnVectorBuf.cpp @@ -114,12 +114,12 @@ static int32_t getFileSize(FILE *myFile) * @return true if OK / false if an error occured * */ -bool EdnVectorBuf::DumpIn(FILE *myFile) +bool EdnVectorBuf::DumpIn(etk::FSNode &file) { bool ret = true; // write Data - (void)fwrite(m_data, sizeof(int8_t), m_gapStart, myFile); - (void)fwrite(&m_data[m_gapEnd], sizeof(int8_t), m_allocated - m_gapEnd, myFile); + (void)file.FileWrite(m_data, sizeof(int8_t), m_gapStart); + (void)file.FileWrite(&m_data[m_gapEnd], sizeof(int8_t), m_allocated - m_gapEnd); return ret; } @@ -132,19 +132,19 @@ bool EdnVectorBuf::DumpIn(FILE *myFile) * @return true if OK / false if an error occured * */ -bool EdnVectorBuf::DumpFrom(FILE *myFile) +bool EdnVectorBuf::DumpFrom(etk::FSNode &file) { bool ret = true; - int32_t length = getFileSize(myFile); + uint32_t length = file.FileSize(); // error case ... - if (length < 0) { - length = 0; + if (length > 2000000000) { + return false; } // allocate the current buffer : ChangeAllocation(length + GAP_SIZE_MIN); // insert Data - int32_t nbReadData = fread(&m_data[GAP_SIZE_MIN], sizeof(int8_t), length, myFile); + int32_t nbReadData = file.FileRead(&m_data[GAP_SIZE_MIN], sizeof(int8_t), length); APPL_INFO("load data : filesize=" << length << ", readData=" << nbReadData); // check ERROR if (nbReadData != length) { diff --git a/Sources/appl/Buffer/EdnVectorBuf.h b/Sources/appl/Buffer/EdnVectorBuf.h index 52afcdd..abea599 100644 --- a/Sources/appl/Buffer/EdnVectorBuf.h +++ b/Sources/appl/Buffer/EdnVectorBuf.h @@ -27,6 +27,7 @@ #define __EDN_VECTOR_BUF_H__ #include +#include #undef __class__ #define __class__ "EdnVectorBuf" @@ -265,8 +266,8 @@ class EdnVectorBuf EdnVectorBuf(const EdnVectorBuf & Evb); ~EdnVectorBuf(); - bool DumpIn( FILE *myFile); - bool DumpFrom( FILE *myFile); + bool DumpIn( etk::FSNode &file); + bool DumpFrom( etk::FSNode &file); EdnVectorBuf & operator=( const EdnVectorBuf & Evb); int8_t operator[] (int32_t pos);