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()); // 最後まで送信してしまう @@ -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()); // 最後まで送信してしまう 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);