mirror of
https://github.com/Dushistov/sdcv.git
synced 2025-12-15 17:31:56 +00:00
Merge pull request #38 from nijel/master
Store integer magic in cache file
This commit is contained in:
@@ -491,7 +491,8 @@ private:
|
|||||||
static std::list<std::string> get_cache_variant(const std::string &url);
|
static std::list<std::string> get_cache_variant(const std::string &url);
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *OffsetIndex::CACHE_MAGIC = "StarDict's Cache, Version: 0.1";
|
const char *OffsetIndex::CACHE_MAGIC = "StarDict's Cache, Version: 0.2";
|
||||||
|
#define CACHE_MAGIC_BYTES 0x51a4d1c1
|
||||||
|
|
||||||
class WordListIndex : public IIndexFile
|
class WordListIndex : public IIndexFile
|
||||||
{
|
{
|
||||||
@@ -573,7 +574,11 @@ bool OffsetIndex::load_cache(const std::string &url)
|
|||||||
continue;
|
continue;
|
||||||
if (strncmp(mf.begin(), CACHE_MAGIC, strlen(CACHE_MAGIC)) != 0)
|
if (strncmp(mf.begin(), CACHE_MAGIC, strlen(CACHE_MAGIC)) != 0)
|
||||||
continue;
|
continue;
|
||||||
memcpy(&wordoffset[0], mf.begin() + strlen(CACHE_MAGIC), wordoffset.size() * sizeof(wordoffset[0]));
|
guint32 tmp;
|
||||||
|
memcpy(&tmp, mf.begin() + strlen(CACHE_MAGIC), sizeof(tmp));
|
||||||
|
if (tmp != CACHE_MAGIC_BYTES)
|
||||||
|
continue;
|
||||||
|
memcpy(&wordoffset[0], mf.begin() + strlen(CACHE_MAGIC) + sizeof(guint32), wordoffset.size() * sizeof(wordoffset[0]));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -605,10 +610,13 @@ bool OffsetIndex::save_cache(const std::string &url, bool verbose)
|
|||||||
const std::list<std::string> vars = get_cache_variant(url);
|
const std::list<std::string> vars = get_cache_variant(url);
|
||||||
for (const std::string &item : vars) {
|
for (const std::string &item : vars) {
|
||||||
FILE *out = fopen(item.c_str(), "wb");
|
FILE *out = fopen(item.c_str(), "wb");
|
||||||
|
guint32 magic = CACHE_MAGIC_BYTES;
|
||||||
if (!out)
|
if (!out)
|
||||||
continue;
|
continue;
|
||||||
if (fwrite(CACHE_MAGIC, 1, strlen(CACHE_MAGIC), out) != strlen(CACHE_MAGIC))
|
if (fwrite(CACHE_MAGIC, 1, strlen(CACHE_MAGIC), out) != strlen(CACHE_MAGIC))
|
||||||
continue;
|
continue;
|
||||||
|
if (fwrite(&magic, 1, sizeof(magic), out) != sizeof(magic))
|
||||||
|
continue;
|
||||||
if (fwrite(&wordoffset[0], sizeof(wordoffset[0]), wordoffset.size(), out) != wordoffset.size())
|
if (fwrite(&wordoffset[0], sizeof(wordoffset[0]), wordoffset.size(), out) != wordoffset.size())
|
||||||
continue;
|
continue;
|
||||||
fclose(out);
|
fclose(out);
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user