代码拉取完成,页面将自动刷新
同步操作将从 leo/supervisor 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "resource.h"
#include "miniz.h"
#include <memory>
#include <cstring>
extern char _binary_res_zip_start;
extern char _binary_res_zip_end;
static std::string MimeType(const std::string & sName) {
auto nIdx = sName.find_last_of(".");
if (nIdx == std::string::npos || nIdx == sName.size() - 1) return "text/plain";
auto sExt = sName.substr(nIdx + 1, sName.size() - nIdx - 1);
if (sExt == "html" || sExt == "htm" || sExt == "shtm" || sExt == "shtml") {
return "text/html";
} else if (sExt == "css") {
return "text/css";
} else if (sExt == "js") {
return "application/x-javascript";
} else if (sExt == "ico" || sExt == "icon") {
return "image/x-icon";
} else if (sExt == "gif") {
return "image/gif";
} else if (sExt == "jpg" || sExt == "jpeg") {
return "image/jpeg";
} else if (sExt == "png") {
return "image/png";
} else if (sExt == "svg") {
return "image/svg+xml";
} else if (sExt == "txt") {
return "text/plain";
} else if (sExt == "xml" || sExt == "xslt" || sExt == "xsl") {
return "text/xml";
} else if (sExt == "ttf") {
return "application/x-font-ttf";
} else {
return "text/plain";
}
}
Resource::~Resource() {
for (auto & kv : _mAssets) {
free(kv.second.pData);
}
if (_pZip) {
mz_zip_reader_end(_pZip);
delete _pZip;
}
_mAssets.clear();
}
Resource & Resource::Instance() {
static std::unique_ptr<Resource> GIns;
if (!GIns) GIns.reset(new Resource);
return *GIns;
}
bool Resource::Load() {
void * pData = &_binary_res_zip_start;
size_t nSize = (&_binary_res_zip_end - &_binary_res_zip_start);
_pZip = new mz_zip_archive_tag;
memset(_pZip, 0, sizeof(mz_zip_archive_tag));
if (!mz_zip_reader_init_mem(_pZip, pData, nSize, 0)) return false;
mz_uint nCount = mz_zip_reader_get_num_files(_pZip);
for (mz_uint nIdx = 0; nIdx < nCount; ++nIdx) {
mz_zip_archive_file_stat iStat;
if (mz_zip_reader_is_file_a_directory(_pZip, nIdx) || !mz_zip_reader_file_stat(_pZip, nIdx, &iStat)) continue;
std::string sType = MimeType(iStat.m_filename);
Asset iAsset;
memset(&iAsset, 0, sizeof(iAsset));
iAsset.pData = (char *)mz_zip_reader_extract_to_heap(_pZip, nIdx, &iAsset.nSize, 0);
strncpy(iAsset.pType, sType.data(), sType.size());
_mAssets[iStat.m_filename] = iAsset;
}
return true;
}
Asset * Resource::Get(const std::string & sPath) {
auto it = _mAssets.find(sPath);
if (it == _mAssets.end()) return nullptr;
return &it->second;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。