Lister des fichiers

This commit is contained in:
Fournier Gabriel
2020-11-16 23:37:45 +01:00
parent b4e9ceed18
commit aacd1a6f32
4 changed files with 53 additions and 3 deletions

View File

@@ -4,6 +4,7 @@ app_headers += apps/reader/app.h
app_sreader_src = $(addprefix apps/reader/,\
app.cpp \
list_book_controller.cpp \
utility.cpp \
)
apps_src += $(app_sreader_src)

View File

@@ -1,5 +1,5 @@
#include "list_book_controller.h"
#include "utility.h"
namespace reader
{
@@ -12,8 +12,20 @@ ListBookController::ListBookController(Responder * parentResponder):
ViewController(parentResponder),
m_tableView(this, this)
{
m_files[0].name= "Harry Potter 1.txt";
m_nbFiles = 1;
size_t nbTotalFiles = External::Archive::numberOfFiles();
for(size_t i=0; i < nbTotalFiles; ++i)
{
External::Archive::File file;
External::Archive::fileAtIndex(i, file);
if(stringEndsWith(file.name, ".txt"))
{
m_files[m_nbFiles] = file;
m_nbFiles++;
if(m_nbFiles == NB_FILES)
break;
}
}
}
int ListBookController::numberOfRows() const

27
apps/reader/utility.cpp Normal file
View File

@@ -0,0 +1,27 @@
#include "utility.h"
#include <string.h>
namespace reader
{
bool stringEndsWith(const char* str, const char* pattern)
{
int strLength = strlen(str);
int patternLength = strlen(pattern);
if (patternLength > strLength)
return false;
const char* strIter = str + strlen(str);
const char* patternIter = pattern + strlen(pattern);
while(*strIter == *patternIter)
{
if(patternIter == pattern)
return true;
strIter--;
patternIter--;
}
return false;
}
}

10
apps/reader/utility.h Normal file
View File

@@ -0,0 +1,10 @@
#ifndef __UTILITY_H__
#define __UTILITY_H__
namespace reader
{
bool stringEndsWith(const char* str, const char* end);
}
#endif