mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
Lister des fichiers
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
27
apps/reader/utility.cpp
Normal 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
10
apps/reader/utility.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef __UTILITY_H__
|
||||
#define __UTILITY_H__
|
||||
|
||||
namespace reader
|
||||
{
|
||||
|
||||
bool stringEndsWith(const char* str, const char* end);
|
||||
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user