#include "Request.h" #include "Response.h" #include #include #include #include "json.hpp" #include using namespace std; using namespace HTTPWrapper; ofstream mlog("log.txt"); std::string GBKToUTF8(const std::string& GBKString) { // GBK -> Unicode int nLen = MultiByteToWideChar(CP_ACP, 0, GBKString.c_str(), -1, NULL, 0); std::unique_ptr buff(new wchar_t[nLen + 8]); memset(buff.get(), 0, nLen + 8); MultiByteToWideChar(CP_ACP, 0, GBKString.c_str(), -1, buff.get(), nLen + 8); // Unicode -> UTF8 nLen = WideCharToMultiByte(CP_UTF8, 0, buff.get(), -1, NULL, 0, NULL, NULL); std::unique_ptr xbuff(new char[nLen + 8]); memset(xbuff.get(), 0, nLen + 8); WideCharToMultiByte(CP_UTF8, 0, buff.get(), -1, xbuff.get(), nLen + 8, NULL, NULL); return std::string(xbuff.get()); } std::wstring GBKToUnicode(const std::string& GBKString) { // GBK -> Unicode int nLen = MultiByteToWideChar(CP_ACP, 0, GBKString.c_str(), GBKString.size(), NULL, 0); std::unique_ptr buff(new wchar_t[nLen + 8]); MultiByteToWideChar(CP_UTF8, 0, GBKString.c_str(), GBKString.size(), buff.get(), nLen + 8); buff[nLen] = 0; return std::wstring(buff.get()); } string urlencode(const string& url) { string ostr; for (const unsigned char& c : url) { if ((c >= '0'&&c <= '9') || (c >= 'a'&&c <= 'z') || (c >= 'A'&&c <= 'Z') || (c == '-') || (c == '_') || (c == '.')) ostr.push_back(c); else { unsigned int first = c / 16; unsigned int second = c % 16; ostr.append("%"); ostr.push_back((char)((first < 10) ? ('0' + first) : ('A' + first - 10))); ostr.push_back((char)((second < 10) ? ('0' + second) : ('A' + second - 10))); } } return ostr; } vector GetList() { vector vec; WIN32_FIND_DATA fnd; HANDLE hand = FindFirstFile("F:\\faaq\\OutSideVideo\\*.mp4", &fnd); if (hand == INVALID_HANDLE_VALUE) return vec; do { if (strcmp(fnd.cFileName, ".") != 0 && strcmp(fnd.cFileName, "..") != 0) { int len = strlen(fnd.cFileName); if (strcmp(fnd.cFileName + len - 4, ".mp4") == 0) { char tmp[2048] = { 0 }; strncpy(tmp, fnd.cFileName, len - 4); vec.push_back(urlencode(GBKToUTF8(tmp))); } } } while (FindNextFile(hand, &fnd)); FindClose(hand); return vec; } int main() { Request req; Response res; nlohmann::json j; vector lst = GetList(); j["files"] = lst; res.writer << j; return 0; }