mirror of https://github.com/kiwix/libkiwix.git
+ better factorisation of the code (moved from manager.cpp to pathTools.cpp) -> creation of functions getFileSize() and getFileSizeAsString()
This commit is contained in:
parent
9182f4e529
commit
98bf706297
|
@ -236,12 +236,7 @@ namespace kiwix {
|
|||
mediaCountStream << reader.getMediaCount();
|
||||
book.mediaCount = mediaCountStream.str();
|
||||
|
||||
struct stat filestatus;
|
||||
stat( path.c_str(), &filestatus );
|
||||
unsigned int size = filestatus.st_size / 1024;
|
||||
char csize[42];
|
||||
sprintf (csize, "%u", size);
|
||||
book.size = csize;
|
||||
book.size = getFileSizeAsString(path);
|
||||
|
||||
string favicon;
|
||||
string faviconMimeType;
|
||||
|
|
|
@ -23,10 +23,6 @@
|
|||
#include <string>
|
||||
#include <sstream>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <pugixml.hpp>
|
||||
|
||||
|
|
|
@ -71,3 +71,14 @@ string removeLastPathElement(const string path, const bool removePreSeparator, c
|
|||
return newPath;
|
||||
}
|
||||
|
||||
unsigned int getFileSize(const string &path) {
|
||||
struct stat filestatus;
|
||||
stat(path.c_str(), &filestatus);
|
||||
return filestatus.st_size / 1024;
|
||||
}
|
||||
|
||||
string getFileSizeAsString(const string &path) {
|
||||
char csize[42];
|
||||
sprintf(csize, "%u", getFileSize(path));
|
||||
return csize;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,10 @@
|
|||
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -29,5 +33,7 @@ bool isRelativePath(const string &path);
|
|||
string computeAbsolutePath(const string libraryPath, const string relativePath);
|
||||
string removeLastPathElement(const string path, const bool removePreSeparator = false,
|
||||
const bool removePostSeparator = false);
|
||||
unsigned int getFileSize(const string &path);
|
||||
string getFileSizeAsString(const string &path);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue