+ better factorisation of the code (moved from manager.cpp to pathTools.cpp) -> creation of functions getFileSize() and getFileSizeAsString()

This commit is contained in:
kelson42 2011-10-28 15:54:31 +00:00
parent 9182f4e529
commit 98bf706297
4 changed files with 18 additions and 10 deletions

View File

@ -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;

View File

@ -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>

View File

@ -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;
}

View File

@ -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