From 62556133ebe2e94d31cc05696099efcf846647fd Mon Sep 17 00:00:00 2001 From: amate Date: Wed, 15 Aug 2018 03:23:05 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=BBCUtil::getMimeType=E3=81=A7Content-Typ?= =?UTF-8?q?e=E3=82=92=E3=83=AC=E3=82=B8=E3=82=B9=E3=83=88=E3=83=AA?= =?UTF-8?q?=E3=81=8B=E3=82=89=E6=8B=A1=E5=BC=B5=E5=AD=90=E3=82=92=E6=A4=9C?= =?UTF-8?q?=E7=B4=A2=E3=81=97=E3=81=A6=E8=BF=94=E3=81=99=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ・local.ptronで日本語のファイルをリクエストされても返せるようにした ・seekposが常に0を返すようになっていたので、streamoffへキャストするように変更 --- Proxydomo/RequestManager.cpp | 25 ++++++++++++++++++++----- Proxydomo/proximodo/util.cpp | 22 ++++++++++++++++++---- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/Proxydomo/RequestManager.cpp b/Proxydomo/RequestManager.cpp index 72c692f..4297888 100644 --- a/Proxydomo/RequestManager.cpp +++ b/Proxydomo/RequestManager.cpp @@ -1048,11 +1048,19 @@ bool CRequestManager::_HandleLocalPtron() return true; } - wstring filename = CUtil::makePath(subpath); - if (::PathFileExists(Misc::GetFullPath_ForExe(filename.c_str()))) { - _FakeResponse("200 OK", filename); + path filepath = CUtil::makePath(subpath); + path fullpath = (LPCWSTR)Misc::GetFullPath_ForExe(filepath.native().c_str()); + if (exists(fullpath)) { + _FakeResponse("200 OK", filepath.native()); } else { - _FakeResponse("404 Not Found"); + filepath = UTF16fromUTF8(CUtil::UESC(filepath.string().c_str())); + path fullpath = (LPCWSTR)Misc::GetFullPath_ForExe(filepath.native().c_str()); + if (exists(fullpath)) { + _FakeResponse("200 OK", filepath.native()); + + } else { + _FakeResponse("404 Not Found"); + } } while (_SendIn()); // Ō܂őMĂ܂ @@ -1088,7 +1096,14 @@ bool CRequestManager::_HandleLocalPtron() if (exists(fullpath)) { _FakeResponse("200 OK", filepath.native()); } else { - _FakeResponse("404 Not Found"); + filepath = UTF16fromUTF8(CUtil::UESC(filepath.string().c_str())); + path fullpath = (LPCWSTR)Misc::GetFullPath_ForExe(filepath.native().c_str()); + if (exists(fullpath)) { + _FakeResponse("200 OK", filepath.native()); + + } else { + _FakeResponse("404 Not Found"); + } } while (_SendIn()); // Ō܂őMĂ܂ diff --git a/Proxydomo/proximodo/util.cpp b/Proxydomo/proximodo/util.cpp index c0ce4d2..5628866 100644 --- a/Proxydomo/proximodo/util.cpp +++ b/Proxydomo/proximodo/util.cpp @@ -34,7 +34,9 @@ #include #include #include +#include #include "..\Misc.h" +#include "..\CodeConvert.h" using namespace std; @@ -623,7 +625,7 @@ string CUtil::getFile(string filename) { auto eofPos = fs.tellg(); fs.clear(); fs.seekg(0, std::ios::beg); - size_t fileSize = (size_t)eofPos.seekpos(); + auto fileSize = (streamoff)eofPos; std::string content; content.resize(fileSize); @@ -644,8 +646,8 @@ string CUtil::getFile(wstring filename) { auto eofPos = fs.tellg(); fs.clear(); fs.seekg(0, std::ios::beg); - size_t fileSize = (size_t)eofPos.seekpos(); - + auto fileSize = (streamoff)eofPos; + std::string content; content.resize(fileSize); fs.read(const_cast(content.data()), fileSize); @@ -659,6 +661,7 @@ string CUtil::getMimeType(string filename) { if (dot == string::npos) return "application/octet-stream"; string ext = filename.substr(dot+1); + lower(ext); //wxString mime; //wxFileType* type = wxTheMimeTypesManager->GetFileTypeFromExtension(S2W(ext)); //if (type != NULL && type->GetMimeType(&mime)) @@ -682,6 +685,17 @@ string CUtil::getMimeType(string filename) { else if (ext == "json") return "application/json"; + CRegKey reg; + LSTATUS ret = reg.Open(HKEY_CLASSES_ROOT, CodeConvert::UTF16fromUTF8((std::string(".") + ext)).c_str(), KEY_READ); + if (ret == ERROR_SUCCESS) { + WCHAR contentType[128] = L""; + ULONG length = 128; + ret = reg.QueryStringValue(L"Content Type", contentType, &length); + if (ret == ERROR_SUCCESS) { + return CodeConvert::UTF8fromUTF16(contentType); + } + } + return "application/octet-stream"; } @@ -987,7 +1001,7 @@ std::vector CUtil::LoadBinaryFile(const std::wstring& filePath) auto eofPos = fs.tellg(); fs.clear(); fs.seekg(0, std::ios::beg); - size_t fileSize = (size_t)eofPos.seekpos(); + auto fileSize = (streamoff)eofPos; std::vector vec(fileSize); fs.read((char*)vec.data(), fileSize);