Compare commits

...

11 Commits
3.0.1 ... 3.0.3

Author SHA1 Message Date
Matthieu Gautier
2ea701b6d6 New version 3.0.3 2018-11-12 12:25:16 +01:00
Matthieu Gautier
be6f96adc0 Merge pull request #179 from kiwix/fix_library
Fix library
2018-11-12 12:21:54 +01:00
Matthieu Gautier
4b31842c4a Correctly convert filesize from Kbyte to byte.
`reader.getFileSize()` return the size of the zim in Kbyte in a
`unsigned int` (32 bits). This is ok as it would overflow if the size
of the size is greater than 4294967295 kbytes (so ~4Tbytes).

However, we need to convert the return size into a unsigned 64 bits integer
else, when converting to bytes, we will overflow at 4Gbytes.
Even in `m_size` is a uint64_t.
2018-11-12 12:16:05 +01:00
Matthieu Gautier
cf1cfe774e Correctly check for ArticleCount and MediaCount before writing them. 2018-11-12 10:58:10 +01:00
Matthieu Gautier
82b38b96e2 Merge pull request #178 from kiwix/fix_en_mapping
Fix en mapping
2018-11-12 10:57:18 +01:00
Matthieu Gautier
8c4b9fbe95 Add missing en->eng mapping to codeisomapping.
The most common used language was missing :/

Fix kiwix/kiwix-desktop#51
2018-11-12 10:36:45 +01:00
Matthieu Gautier
ab63cb2fb8 Sort codeisomapping alphabetically.
This is only code formating, no real change.
2018-11-12 10:34:19 +01:00
Matthieu Gautier
3958b2a06f Make the internal map codeisomapping static.
Symbole should not be visible outside of the compilation unit.
2018-11-12 10:33:35 +01:00
Matthieu Gautier
9fa7d78ba1 Merge pull request #176 from kiwix/win_relpath
Win relpath
2018-11-03 12:33:14 +01:00
Matthieu Gautier
57d3552b97 New version 3.0.2 2018-11-03 12:20:13 +01:00
Matthieu Gautier
d4ecda40ff Use the correct separator when computing relativePath. 2018-11-03 12:18:54 +01:00
7 changed files with 208 additions and 172 deletions

View File

@@ -1,3 +1,16 @@
kiwix-lib 3.0.3
===============
* Add the 'en' language to the mapping alpha2-code ('en') to alpha3-code
('eng').
* Correctly write the 'ArticleCount' and 'MediaCount' in the library.xml.
* Correctly fill the book size for the zim file size.
kiwix-lib 3.0.2
===============
* Use the correct path separator when computing relativePath on Windows.
kiwix-lib 3.0.1
===============

View File

@@ -1,5 +1,5 @@
project('kiwix-lib', 'cpp',
version : '3.0.1',
version : '3.0.3',
license : 'GPL',
default_options : ['c_std=c11', 'cpp_std=c++11', 'werror=true'])

View File

@@ -87,7 +87,7 @@ void Book::update(const kiwix::Reader& reader)
m_origId = reader.getOrigId();
m_articleCount = reader.getArticleCount();
m_mediaCount = reader.getMediaCount();
m_size = reader.getFileSize() << 10;
m_size = static_cast<uint64_t>(reader.getFileSize()) << 10;
reader.getFavicon(m_favicon, m_faviconMimeType);
}

View File

@@ -20,252 +20,278 @@
#include <common/otherTools.h>
#include <map>
std::map<std::string, std::string> codeisomapping {
{ "af", "afg" },
{ "ax", "ala" },
{ "al", "alb" },
{ "dz", "dza" },
{ "as", "asm" },
static std::map<std::string, std::string> codeisomapping {
//a
{ "ad", "and" },
{ "ao", "ago" },
{ "ai", "aia" },
{ "aq", "ata" },
{ "ae", "are" },
{ "af", "afg" },
{ "ag", "atg" },
{ "ar", "arg" },
{ "ai", "aia" },
{ "al", "alb" },
{ "am", "arm" },
{ "aw", "abw" },
{ "au", "aus" },
{ "an", "ant" },
{ "ao", "ago" },
{ "aq", "ata" },
{ "ar", "arg" },
{ "as", "asm" },
{ "at", "aut" },
{ "au", "aus" },
{ "aw", "abw" },
{ "ax", "ala" },
{ "az", "aze" },
{ "bs", "bhs" },
{ "bh", "bhr" },
{ "bd", "bgd" },
{ "bb", "brb" },
{ "by", "blr" },
{ "be", "bel" },
{ "bz", "blz" },
{ "bj", "ben" },
{ "bm", "bmu" },
{ "bt", "btn" },
{ "bo", "bol" },
//b
{ "ba", "bih" },
{ "bw", "bwa" },
{ "bv", "bvt" },
{ "br", "bra" },
{ "vg", "vgb" },
{ "io", "iot" },
{ "bn", "brn" },
{ "bg", "bgr" },
{ "bb", "brb" },
{ "bd", "bgd" },
{ "be", "bel" },
{ "bf", "bfa" },
{ "bg", "bgr" },
{ "bh", "bhr" },
{ "bi", "bdi" },
{ "kh", "khm" },
{ "cm", "cmr" },
{ "bj", "ben" },
{ "bl", "blm" },
{ "bn", "brn" },
{ "bm", "bmu" },
{ "bo", "bol" },
{ "br", "bra" },
{ "bs", "bhs" },
{ "bt", "btn" },
{ "bv", "bvt" },
{ "bw", "bwa" },
{ "by", "blr" },
{ "bz", "blz" },
//c
{ "ca", "can" },
{ "cv", "cpv" },
{ "ky", "cym" },
{ "cf", "caf" },
{ "td", "tcd" },
{ "cl", "chl" },
{ "cn", "chn" },
{ "hk", "hkg" },
{ "mo", "mac" },
{ "cx", "cxr" },
{ "cc", "cck" },
{ "co", "col" },
{ "km", "com" },
{ "cg", "cog" },
{ "cd", "cod" },
{ "ck", "cok" },
{ "cr", "cri" },
{ "cf", "caf" },
{ "cg", "cog" },
{ "ch", "che" },
{ "ci", "civ" },
{ "hr", "hrv" },
{ "ck", "cok" },
{ "cl", "chl" },
{ "cm", "cmr" },
{ "cn", "chn" },
{ "co", "col" },
{ "cr", "cri" },
{ "cu", "cub" },
{ "cv", "cpv" },
{ "cx", "cxr" },
{ "cy", "cyp" },
{ "cz", "cze" },
{ "dk", "dnk" },
//d
{ "de", "deu" },
{ "dj", "dji" },
{ "dk", "dnk" },
{ "dm", "dma" },
{ "do", "dom" },
{ "dz", "dza" },
//e
{ "ec", "ecu" },
{ "eg", "egy" },
{ "sv", "slv" },
{ "gq", "gnq" },
{ "er", "eri" },
{ "ee", "est" },
{ "eg", "egy" },
{ "eh", "esh" },
{ "en", "eng" },
{ "er", "eri" },
{ "es", "esp" },
{ "et", "eth" },
{ "fk", "flk" },
{ "fo", "fro" },
{ "fj", "fji" },
//f
{ "fi", "fin" },
{ "fj", "fji" },
{ "fk", "flk" },
{ "fm", "fsm" },
{ "fo", "fro" },
{ "fr", "fra" },
{ "gf", "guf" },
{ "pf", "pyf" },
{ "tf", "atf" },
//g
{ "ga", "gab" },
{ "gm", "gmb" },
{ "gb", "gbr" },
{ "gd", "grd" },
{ "ge", "geo" },
{ "de", "deu" },
{ "gf", "guf" },
{ "gg", "ggy" },
{ "gh", "gha" },
{ "gi", "gib" },
{ "gr", "grc" },
{ "gl", "grl" },
{ "gd", "grd" },
{ "gp", "glp" },
{ "gu", "gum" },
{ "gt", "gtm" },
{ "gg", "ggy" },
{ "gm", "gmb" },
{ "gn", "gin" },
{ "gp", "glp" },
{ "gq", "gnq" },
{ "gr", "grc" },
{ "gs", "sgs" },
{ "gt", "gtm" },
{ "gu", "gum" },
{ "gw", "gnb" },
{ "gy", "guy" },
{ "ht", "hti" },
//h
{ "hk", "hkg" },
{ "hm", "hmd" },
{ "va", "vat" },
{ "hn", "hnd" },
{ "hr", "hrv" },
{ "ht", "hti" },
{ "hu", "hun" },
{ "is", "isl" },
{ "in", "ind" },
//i
{ "id", "idn" },
{ "ir", "irn" },
{ "iq", "irq" },
{ "ie", "irl" },
{ "im", "imn" },
{ "il", "isr" },
{ "im", "imn" },
{ "in", "ind" },
{ "io", "iot" },
{ "iq", "irq" },
{ "ir", "irn" },
{ "is", "isl" },
{ "it", "ita" },
{ "jm", "jam" },
{ "jp", "jpn" },
//j
{ "je", "jey" },
{ "jm", "jam" },
{ "jo", "jor" },
{ "kz", "kaz" },
{ "jp", "jpn" },
//k
{ "ke", "ken" },
{ "kg", "kgz" },
{ "kh", "khm" },
{ "ki", "kir" },
{ "km", "com" },
{ "kn", "kna" },
{ "kp", "prk" },
{ "kr", "kor" },
{ "kw", "kwt" },
{ "kg", "kgz" },
{ "ky", "cym" },
{ "kz", "kaz" },
//l
{ "la", "lao" },
{ "lv", "lva" },
{ "lb", "lbn" },
{ "ls", "lso" },
{ "lr", "lbr" },
{ "ly", "lby" },
{ "lc", "lca" },
{ "li", "lie" },
{ "lk", "lka" },
{ "lr", "lbr" },
{ "ls", "lso" },
{ "lt", "ltu" },
{ "lu", "lux" },
{ "mk", "mkd" },
{ "lv", "lva" },
{ "ly", "lby" },
//m
{ "ma", "mar" },
{ "mc", "mco" },
{ "md", "mda" },
{ "me", "mne" },
{ "mf", "maf" },
{ "mg", "mdg" },
{ "mw", "mwi" },
{ "my", "mys" },
{ "mv", "mdv" },
{ "ml", "mli" },
{ "mt", "mlt" },
{ "mh", "mhl" },
{ "mk", "mkd" },
{ "ml", "mli" },
{ "mm", "mmr" },
{ "mn", "mng" },
{ "mo", "mac" },
{ "mp", "mnp" },
{ "mq", "mtq" },
{ "mr", "mrt" },
{ "mu", "mus" },
{ "yt", "myt" },
{ "mx", "mex" },
{ "fm", "fsm" },
{ "md", "mda" },
{ "mc", "mco" },
{ "mn", "mng" },
{ "me", "mne" },
{ "ms", "msr" },
{ "ma", "mar" },
{ "mt", "mlt" },
{ "mu", "mus" },
{ "mv", "mdv" },
{ "mw", "mwi" },
{ "mx", "mex" },
{ "my", "mys" },
{ "mz", "moz" },
{ "mm", "mmr" },
//n
{ "na", "nam" },
{ "nr", "nru" },
{ "np", "npl" },
{ "nl", "nld" },
{ "an", "ant" },
{ "nc", "ncl" },
{ "nz", "nzl" },
{ "ni", "nic" },
{ "ne", "ner" },
{ "ng", "nga" },
{ "nu", "niu" },
{ "nf", "nfk" },
{ "mp", "mnp" },
{ "ng", "nga" },
{ "ni", "nic" },
{ "nl", "nld" },
{ "no", "nor" },
{ "np", "npl" },
{ "nr", "nru" },
{ "nu", "niu" },
{ "nz", "nzl" },
//o
{ "om", "omn" },
{ "pk", "pak" },
{ "pw", "plw" },
{ "ps", "pse" },
//p
{ "pa", "pan" },
{ "pg", "png" },
{ "py", "pry" },
{ "pe", "per" },
{ "pf", "pyf" },
{ "pg", "png" },
{ "ph", "phl" },
{ "pn", "pcn" },
{ "pk", "pak" },
{ "pl", "pol" },
{ "pt", "prt" },
{ "pm", "spm" },
{ "pn", "pcn" },
{ "pr", "pri" },
{ "ps", "pse" },
{ "pt", "prt" },
{ "pw", "plw" },
{ "py", "pry" },
//q
{ "qa", "qat" },
//r
{ "re", "reu" },
{ "ro", "rou" },
{ "rs", "srb" },
{ "ru", "rus" },
{ "rw", "rwa" },
{ "bl", "blm" },
{ "sh", "shn" },
{ "kn", "kna" },
{ "lc", "lca" },
{ "mf", "maf" },
{ "pm", "spm" },
{ "vc", "vct" },
{ "ws", "wsm" },
{ "sm", "smr" },
{ "st", "stp" },
//s
{ "sa", "sau" },
{ "sn", "sen" },
{ "rs", "srb" },
{ "sc", "syc" },
{ "sl", "sle" },
{ "sg", "sgp" },
{ "sk", "svk" },
{ "si", "svn" },
{ "sb", "slb" },
{ "so", "som" },
{ "za", "zaf" },
{ "gs", "sgs" },
{ "ss", "ssd" },
{ "es", "esp" },
{ "lk", "lka" },
{ "sc", "syc" },
{ "sd", "sdn" },
{ "sr", "sur" },
{ "sj", "sjm" },
{ "sz", "swz" },
{ "se", "swe" },
{ "ch", "che" },
{ "sg", "sgp" },
{ "sh", "shn" },
{ "si", "svn" },
{ "sj", "sjm" },
{ "sk", "svk" },
{ "sl", "sle" },
{ "sm", "smr" },
{ "sn", "sen" },
{ "so", "som" },
{ "sr", "sur" },
{ "ss", "ssd" },
{ "st", "stp" },
{ "sv", "slv" },
{ "sy", "syr" },
{ "tw", "twn" },
{ "tj", "tjk" },
{ "tz", "tza" },
{ "th", "tha" },
{ "tl", "tls" },
{ "tg", "tgo" },
{ "tk", "tkl" },
{ "to", "ton" },
{ "tt", "tto" },
{ "tn", "tun" },
{ "tr", "tur" },
{ "tm", "tkm" },
{ "sz", "swz" },
//t
{ "tc", "tca" },
{ "td", "tcd" },
{ "tf", "atf" },
{ "tg", "tgo" },
{ "th", "tha" },
{ "tj", "tjk" },
{ "tk", "tkl" },
{ "tl", "tls" },
{ "tm", "tkm" },
{ "tn", "tun" },
{ "to", "ton" },
{ "tr", "tur" },
{ "tt", "tto" },
{ "tv", "tuv" },
{ "ug", "uga" },
{ "tw", "twn" },
{ "tz", "tza" },
//u
{ "ua", "ukr" },
{ "ae", "are" },
{ "gb", "gbr" },
{ "us", "usa" },
{ "ug", "uga" },
{ "um", "umi" },
{ "us", "usa" },
{ "uy", "ury" },
{ "uz", "uzb" },
{ "vu", "vut" },
//v
{ "va", "vat" },
{ "vc", "vct" },
{ "ve", "ven" },
{ "vn", "vnm" },
{ "vg", "vgb" },
{ "vi", "vir" },
{ "vn", "vnm" },
{ "vu", "vut" },
//w
{ "wf", "wlf" },
{ "eh", "esh" },
{ "ws", "wsm" },
//y
{ "ye", "yem" },
{ "yt", "myt" },
// z
{ "za", "zaf" },
{ "zm", "zmb" },
{ "zw", "zwe" }
};

View File

@@ -35,9 +35,9 @@
#endif
#ifdef _WIN32
#define SEPARATOR "\\"
const std::string SEPARATOR("\\");
#else
#define SEPARATOR "/"
const std::string SEPARATOR("/");
#include <unistd.h>
#endif
@@ -66,9 +66,7 @@ string computeRelativePath(const string path, const string absolutePath)
while (commonCount < pathParts.size()
&& commonCount < absolutePathParts.size()
&& pathParts[commonCount] == absolutePathParts[commonCount]) {
if (!pathParts[commonCount].empty()) {
commonCount++;
}
}
string relativePath;
@@ -76,18 +74,17 @@ string computeRelativePath(const string path, const string absolutePath)
/* On Windows you have a token more because the root is represented
by a letter */
if (commonCount == 0) {
relativePath = "../";
relativePath = ".." + SEPARATOR;
}
#endif
for (unsigned int i = commonCount; i < pathParts.size(); i++) {
relativePath += "../";
relativePath += ".." + SEPARATOR;
}
for (unsigned int i = commonCount; i < absolutePathParts.size(); i++) {
relativePath += absolutePathParts[i];
relativePath += i + 1 < absolutePathParts.size() ? "/" : "";
relativePath += i + 1 < absolutePathParts.size() ? SEPARATOR : "";
}
return relativePath;
}

View File

@@ -145,10 +145,10 @@ bool Library::writeToFile(const std::string& path) {
bookNode.append_attribute("url") = book.getUrl().c_str();
}
if (!book.getArticleCount())
if (book.getArticleCount())
bookNode.append_attribute("articleCount") = to_string(book.getArticleCount()).c_str();
if (!book.getMediaCount())
if (book.getMediaCount())
bookNode.append_attribute("mediaCount") = to_string(book.getMediaCount()).c_str();
if (book.getSize()) {

View File

@@ -851,7 +851,7 @@ bool Reader::isCorrupted() const
unsigned int Reader::getFileSize() const
{
zim::File* file = this->getZimFileHandler();
zim::offset_type size = 0;
zim::size_type size = 0;
if (file != NULL) {
size = file->getFilesize();