diff options
Diffstat (limited to 'backends')
11 files changed, 82 insertions, 64 deletions
diff --git a/backends/networking/sdl_net/getclienthandler.cpp b/backends/networking/sdl_net/getclienthandler.cpp index ef085c6082..8e940a1a9c 100644 --- a/backends/networking/sdl_net/getclienthandler.cpp +++ b/backends/networking/sdl_net/getclienthandler.cpp @@ -107,7 +107,7 @@ const char *GetClientHandler::responseMessage(long responseCode) { void GetClientHandler::prepareHeaders() { if (!_specialHeaders.contains("Content-Type")) - setHeader("Content-Type", "text/html"); + setHeader("Content-Type", "text/html; charset=UTF-8"); if (!_specialHeaders.contains("Content-Length") && _stream) setHeader("Content-Length", Common::String::format("%u", _stream->size())); diff --git a/backends/networking/sdl_net/handlers/createdirectoryhandler.cpp b/backends/networking/sdl_net/handlers/createdirectoryhandler.cpp index ad90c44a26..a1d1d9b7fc 100644 --- a/backends/networking/sdl_net/handlers/createdirectoryhandler.cpp +++ b/backends/networking/sdl_net/handlers/createdirectoryhandler.cpp @@ -57,35 +57,35 @@ void CreateDirectoryHandler::handle(Client &client) { // check that <path> is not an absolute root if (path == "" || path == "/") { - handleError(client, _("Can't create directory here!")); + handleError(client, HandlerUtils::toUtf8(_("Can't create directory here!"))); return; } // check that <path> contains no '../' if (HandlerUtils::hasForbiddenCombinations(path)) { - handleError(client, _("Invalid path!")); + handleError(client, HandlerUtils::toUtf8(_("Invalid path!"))); return; } // transform virtual path to actual file system one Common::String prefixToRemove = "", prefixToAdd = ""; if (!transformPath(path, prefixToRemove, prefixToAdd) || path.empty()) { - handleError(client, _("Invalid path!")); + handleError(client, HandlerUtils::toUtf8(_("Invalid path!"))); return; } // check that <path> exists, is directory and isn't forbidden AbstractFSNode *node = g_system->getFilesystemFactory()->makeFileNodePath(path); if (!HandlerUtils::permittedPath(node->getPath())) { - handleError(client, _("Invalid path!")); + handleError(client, HandlerUtils::toUtf8(_("Invalid path!"))); return; } if (!node->exists()) { - handleError(client, _("Parent directory doesn't exists!")); + handleError(client, HandlerUtils::toUtf8(_("Parent directory doesn't exists!"))); return; } if (!node->isDirectory()) { - handleError(client, _("Can't create a directory within a file!")); + handleError(client, HandlerUtils::toUtf8(_("Can't create a directory within a file!"))); return; } @@ -95,20 +95,20 @@ void CreateDirectoryHandler::handle(Client &client) { node = g_system->getFilesystemFactory()->makeFileNodePath(path + name); if (node->exists()) { if (!node->isDirectory()) { - handleError(client, _("There is a file with that name in the parent directory!")); + handleError(client, HandlerUtils::toUtf8(_("There is a file with that name in the parent directory!"))); return; } } else { // create the <directory_name> in <path> if (!node->createDirectory()) { - handleError(client, _("Failed to create the directory!")); + handleError(client, HandlerUtils::toUtf8(_("Failed to create the directory!"))); return; } } // if json requested, respond with it if (client.queryParameter("answer_json") == "true") { - setJsonResponseHandler(client, "success", _("Directory created successfully!")); + setJsonResponseHandler(client, "success", HandlerUtils::toUtf8(_("Directory created successfully!"))); return; } @@ -117,9 +117,9 @@ void CreateDirectoryHandler::handle(Client &client) { client, Common::String::format( "%s<br/><a href=\"files?path=%s\">%s</a>", - _("Directory created successfully!"), + HandlerUtils::toUtf8(_("Directory created successfully!")).c_str(), client.queryParameter("path").c_str(), - _("Back to parent directory") + HandlerUtils::toUtf8(_("Back to parent directory")).c_str() ), (client.queryParameter("ajax") == "true" ? "/filesAJAX?path=" : "/files?path=") + LocalWebserver::urlEncodeQueryParameterValue(client.queryParameter("path")) diff --git a/backends/networking/sdl_net/handlers/downloadfilehandler.cpp b/backends/networking/sdl_net/handlers/downloadfilehandler.cpp index 281be2d27f..8f434ed75e 100644 --- a/backends/networking/sdl_net/handlers/downloadfilehandler.cpp +++ b/backends/networking/sdl_net/handlers/downloadfilehandler.cpp @@ -40,40 +40,40 @@ void DownloadFileHandler::handle(Client &client) { // check that <path> is not an absolute root if (path == "" || path == "/") { - HandlerUtils::setFilesManagerErrorMessageHandler(client, _("Invalid path!")); + HandlerUtils::setFilesManagerErrorMessageHandler(client, HandlerUtils::toUtf8(_("Invalid path!"))); return; } // check that <path> contains no '../' if (HandlerUtils::hasForbiddenCombinations(path)) { - HandlerUtils::setFilesManagerErrorMessageHandler(client, _("Invalid path!")); + HandlerUtils::setFilesManagerErrorMessageHandler(client, HandlerUtils::toUtf8(_("Invalid path!"))); return; } // transform virtual path to actual file system one Common::String prefixToRemove = "", prefixToAdd = ""; if (!transformPath(path, prefixToRemove, prefixToAdd, false) || path.empty()) { - HandlerUtils::setFilesManagerErrorMessageHandler(client, _("Invalid path!")); + HandlerUtils::setFilesManagerErrorMessageHandler(client, HandlerUtils::toUtf8(_("Invalid path!"))); return; } // check that <path> exists, is directory and isn't forbidden AbstractFSNode *node = g_system->getFilesystemFactory()->makeFileNodePath(path); if (!HandlerUtils::permittedPath(node->getPath())) { - HandlerUtils::setFilesManagerErrorMessageHandler(client, _("Invalid path!")); + HandlerUtils::setFilesManagerErrorMessageHandler(client, HandlerUtils::toUtf8(_("Invalid path!"))); return; } if (!node->exists()) { - HandlerUtils::setFilesManagerErrorMessageHandler(client, _("The file doesn't exist!")); + HandlerUtils::setFilesManagerErrorMessageHandler(client, HandlerUtils::toUtf8(_("The file doesn't exist!"))); return; } if (node->isDirectory()) { - HandlerUtils::setFilesManagerErrorMessageHandler(client, _("Can't download a directory!")); + HandlerUtils::setFilesManagerErrorMessageHandler(client, HandlerUtils::toUtf8(_("Can't download a directory!"))); return; } Common::SeekableReadStream *stream = node->createReadStream(); if (stream == nullptr) { - HandlerUtils::setFilesManagerErrorMessageHandler(client, _("Failed to read the file!")); + HandlerUtils::setFilesManagerErrorMessageHandler(client, HandlerUtils::toUtf8(_("Failed to read the file!"))); return; } diff --git a/backends/networking/sdl_net/handlers/filesajaxpagehandler.cpp b/backends/networking/sdl_net/handlers/filesajaxpagehandler.cpp index 94cc74103a..eda5d1305d 100644 --- a/backends/networking/sdl_net/handlers/filesajaxpagehandler.cpp +++ b/backends/networking/sdl_net/handlers/filesajaxpagehandler.cpp @@ -56,7 +56,7 @@ void FilesAjaxPageHandler::handle(Client &client) { // load stylish response page from the archive Common::SeekableReadStream *const stream = HandlerUtils::getArchiveFile(FILES_PAGE_NAME); if (stream == nullptr) { - HandlerUtils::setFilesManagerErrorMessageHandler(client, _("The page is not available without the resources. Make sure file wwwroot.zip from ScummVM distribution is available in 'themepath'.")); + HandlerUtils::setFilesManagerErrorMessageHandler(client, HandlerUtils::toUtf8(_("The page is not available without the resources. Make sure file wwwroot.zip from ScummVM distribution is available in 'themepath'."))); return; } @@ -64,16 +64,16 @@ void FilesAjaxPageHandler::handle(Client &client) { Common::String path = client.queryParameter("path"); //these occur twice: - replace(response, "{create_directory_button}", _("Create directory")); - replace(response, "{create_directory_button}", _("Create directory")); - replace(response, "{upload_files_button}", _("Upload files")); //tab - replace(response, "{upload_file_button}", _("Upload files")); //button in the tab - replace(response, "{create_directory_desc}", _("Type new directory name:")); - replace(response, "{upload_file_desc}", _("Select a file to upload:")); - replace(response, "{or_upload_directory_desc}", _("Or select a directory (works in Chrome only):")); - replace(response, "{index_of}", _("Index of ")); - replace(response, "{loading}", _("Loading...")); - replace(response, "{error}", _("Error occurred")); + replace(response, "{create_directory_button}", HandlerUtils::toUtf8(_("Create directory"))); + replace(response, "{create_directory_button}", HandlerUtils::toUtf8(_("Create directory"))); + replace(response, "{upload_files_button}", HandlerUtils::toUtf8(_("Upload files"))); //tab + replace(response, "{upload_file_button}", HandlerUtils::toUtf8(_("Upload files"))); //button in the tab + replace(response, "{create_directory_desc}", HandlerUtils::toUtf8(_("Type new directory name:"))); + replace(response, "{upload_file_desc}", HandlerUtils::toUtf8(_("Select a file to upload:"))); + replace(response, "{or_upload_directory_desc}", HandlerUtils::toUtf8(_("Or select a directory (works in Chrome only):"))); + replace(response, "{index_of}", HandlerUtils::toUtf8(_("Index of "))); + replace(response, "{loading}", HandlerUtils::toUtf8(("Loading..."))); + replace(response, "{error}", HandlerUtils::toUtf8(_("Error occurred"))); replace(response, "{start_path}", encodeDoubleQuotesAndSlashes(path)); LocalWebserver::setClientGetHandler(client, response); } diff --git a/backends/networking/sdl_net/handlers/filespagehandler.cpp b/backends/networking/sdl_net/handlers/filespagehandler.cpp index 22afa83af8..72e230088a 100644 --- a/backends/networking/sdl_net/handlers/filespagehandler.cpp +++ b/backends/networking/sdl_net/handlers/filespagehandler.cpp @@ -78,8 +78,8 @@ Common::String getDisplayPath(Common::String s) { bool FilesPageHandler::listDirectory(Common::String path, Common::String &content, const Common::String &itemTemplate) { if (path == "" || path == "/") { if (ConfMan.hasKey("rootpath", "cloud")) - addItem(content, itemTemplate, IT_DIRECTORY, "/root/", _("File system root")); - addItem(content, itemTemplate, IT_DIRECTORY, "/saves/", _("Saved games")); + addItem(content, itemTemplate, IT_DIRECTORY, "/root/", HandlerUtils::toUtf8(_("File system root"))); + addItem(content, itemTemplate, IT_DIRECTORY, "/saves/", HandlerUtils::toUtf8(_("Saved games"))); return true; } @@ -116,7 +116,7 @@ bool FilesPageHandler::listDirectory(Common::String path, Common::String &conten filePath = "/"; else filePath = parentPath(prefixToAdd + filePath); - addItem(content, itemTemplate, IT_PARENT_DIRECTORY, filePath, _("Parent directory")); + addItem(content, itemTemplate, IT_PARENT_DIRECTORY, filePath, HandlerUtils::toUtf8(_("Parent directory"))); } // fill the content @@ -182,7 +182,7 @@ void FilesPageHandler::addItem(Common::String &content, const Common::String &it void FilesPageHandler::handle(Client &client) { Common::String response = "<html>" \ - "<head><title>ScummVM</title></head>" \ + "<head><title>ScummVM</title><meta charset=\"utf-8\"/></head>" \ "<body>" \ "<p>{create_directory_desc}</p>" \ "<form action=\"create\">" \ @@ -215,21 +215,21 @@ void FilesPageHandler::handle(Client &client) { // show an error message if failed to list directory if (!listDirectory(path, content, itemTemplate)) { - HandlerUtils::setFilesManagerErrorMessageHandler(client, _("ScummVM couldn't list the directory you specified.")); + HandlerUtils::setFilesManagerErrorMessageHandler(client, HandlerUtils::toUtf8(_("ScummVM couldn't list the directory you specified."))); return; } //these occur twice: - replace(response, "{create_directory_button}", _("Create directory")); - replace(response, "{create_directory_button}", _("Create directory")); + replace(response, "{create_directory_button}", HandlerUtils::toUtf8(_("Create directory"))); + replace(response, "{create_directory_button}", HandlerUtils::toUtf8(_("Create directory"))); replace(response, "{path}", encodeDoubleQuotes(client.queryParameter("path"))); replace(response, "{path}", encodeDoubleQuotes(client.queryParameter("path"))); - replace(response, "{upload_files_button}", _("Upload files")); //tab - replace(response, "{upload_file_button}", _("Upload files")); //button in the tab - replace(response, "{create_directory_desc}", _("Type new directory name:")); - replace(response, "{upload_file_desc}", _("Select a file to upload:")); - replace(response, "{or_upload_directory_desc}", _("Or select a directory (works in Chrome only):")); - replace(response, "{index_of_directory}", Common::String::format(_("Index of %s"), encodeHtmlEntities(getDisplayPath(client.queryParameter("path"))).c_str())); + replace(response, "{upload_files_button}", HandlerUtils::toUtf8(_("Upload files"))); //tab + replace(response, "{upload_file_button}", HandlerUtils::toUtf8(_("Upload files"))); //button in the tab + replace(response, "{create_directory_desc}", HandlerUtils::toUtf8(_("Type new directory name:"))); + replace(response, "{upload_file_desc}", HandlerUtils::toUtf8(_("Select a file to upload:"))); + replace(response, "{or_upload_directory_desc}", HandlerUtils::toUtf8(_("Or select a directory (works in Chrome only):"))); + replace(response, "{index_of_directory}", Common::String::format("%s %s", HandlerUtils::toUtf8(_("Index of")).c_str(), encodeHtmlEntities(getDisplayPath(client.queryParameter("path"))).c_str())); replace(response, "{content}", content); LocalWebserver::setClientGetHandler(client, response); } diff --git a/backends/networking/sdl_net/handlers/indexpagehandler.cpp b/backends/networking/sdl_net/handlers/indexpagehandler.cpp index 876bdde9ce..f872810bad 100644 --- a/backends/networking/sdl_net/handlers/indexpagehandler.cpp +++ b/backends/networking/sdl_net/handlers/indexpagehandler.cpp @@ -39,8 +39,8 @@ void IndexPageHandler::handle(Client &client) { client, Common::String::format( "%s<br/><a href=\"files\">%s</a>", - _("This is a local webserver index page."), - _("Open Files manager") + HandlerUtils::toUtf8(_("This is a local webserver index page.")).c_str(), + HandlerUtils::toUtf8(_("Open Files manager")).c_str() ), "/filesAJAX" ); diff --git a/backends/networking/sdl_net/handlers/listajaxhandler.cpp b/backends/networking/sdl_net/handlers/listajaxhandler.cpp index 7c2801539d..e364712283 100644 --- a/backends/networking/sdl_net/handlers/listajaxhandler.cpp +++ b/backends/networking/sdl_net/handlers/listajaxhandler.cpp @@ -42,8 +42,8 @@ Common::JSONObject ListAjaxHandler::listDirectory(Common::String path) { if (path == "" || path == "/") { if (ConfMan.hasKey("rootpath", "cloud")) - addItem(itemsList, IT_DIRECTORY, "/root/", _("File system root")); - addItem(itemsList, IT_DIRECTORY, "/saves/", _("Saved games")); + addItem(itemsList, IT_DIRECTORY, "/root/", HandlerUtils::toUtf8(_("File system root"))); + addItem(itemsList, IT_DIRECTORY, "/saves/", HandlerUtils::toUtf8(_("Saved games"))); successResult.setVal("items", new Common::JSONValue(itemsList)); return successResult; } @@ -81,7 +81,7 @@ Common::JSONObject ListAjaxHandler::listDirectory(Common::String path) { filePath = "/"; else filePath = parentPath(prefixToAdd + filePath); - addItem(itemsList, IT_PARENT_DIRECTORY, filePath, _("Parent directory")); + addItem(itemsList, IT_PARENT_DIRECTORY, filePath, HandlerUtils::toUtf8(_("Parent directory"))); } // fill the content diff --git a/backends/networking/sdl_net/handlers/uploadfilehandler.cpp b/backends/networking/sdl_net/handlers/uploadfilehandler.cpp index 6b8be15f1f..c3454a9c41 100644 --- a/backends/networking/sdl_net/handlers/uploadfilehandler.cpp +++ b/backends/networking/sdl_net/handlers/uploadfilehandler.cpp @@ -40,35 +40,35 @@ void UploadFileHandler::handle(Client &client) { // check that <path> is not an absolute root if (path == "" || path == "/" || path == "\\") { - HandlerUtils::setFilesManagerErrorMessageHandler(client, _("Invalid path!")); + HandlerUtils::setFilesManagerErrorMessageHandler(client, HandlerUtils::toUtf8(_("Invalid path!"))); return; } // check that <path> contains no '../' if (HandlerUtils::hasForbiddenCombinations(path)) { - HandlerUtils::setFilesManagerErrorMessageHandler(client, _("Invalid path!")); + HandlerUtils::setFilesManagerErrorMessageHandler(client, HandlerUtils::toUtf8(_("Invalid path!"))); return; } // transform virtual path to actual file system one Common::String prefixToRemove = "", prefixToAdd = ""; if (!transformPath(path, prefixToRemove, prefixToAdd, false) || path.empty()) { - HandlerUtils::setFilesManagerErrorMessageHandler(client, _("Invalid path!")); + HandlerUtils::setFilesManagerErrorMessageHandler(client, HandlerUtils::toUtf8(_("Invalid path!"))); return; } // check that <path> exists, is directory and isn't forbidden AbstractFSNode *node = g_system->getFilesystemFactory()->makeFileNodePath(path); if (!HandlerUtils::permittedPath(node->getPath())) { - HandlerUtils::setFilesManagerErrorMessageHandler(client, _("Invalid path!")); + HandlerUtils::setFilesManagerErrorMessageHandler(client, HandlerUtils::toUtf8(_("Invalid path!"))); return; } if (!node->exists()) { - HandlerUtils::setFilesManagerErrorMessageHandler(client, _("The parent directory doesn't exist!")); + HandlerUtils::setFilesManagerErrorMessageHandler(client, HandlerUtils::toUtf8(_("The parent directory doesn't exist!"))); return; } if (!node->isDirectory()) { - HandlerUtils::setFilesManagerErrorMessageHandler(client, _("Can't upload into a file!")); + HandlerUtils::setFilesManagerErrorMessageHandler(client, HandlerUtils::toUtf8(_("Can't upload into a file!"))); return; } diff --git a/backends/networking/sdl_net/handlerutils.cpp b/backends/networking/sdl_net/handlerutils.cpp index 73ddf9e83f..36f615f93b 100644 --- a/backends/networking/sdl_net/handlerutils.cpp +++ b/backends/networking/sdl_net/handlerutils.cpp @@ -28,6 +28,7 @@ #include "common/file.h" #include "common/translation.h" #include "common/unzip.h" +#include "common/encoding.h" namespace Networking { @@ -171,8 +172,23 @@ bool HandlerUtils::permittedPath(const Common::String path) { return hasPermittedPrefix(path) && !isBlacklisted(path); } +Common::String HandlerUtils::toUtf8(const char *text) { +#ifdef USE_TRANSLATION + Common::String guiEncoding = TransMan.getCurrentCharset(); + if (guiEncoding != "ASCII") { + char *utf8Text = Common::Encoding::convert("utf-8", guiEncoding, text, strlen(text)); + if (utf8Text != nullptr) { + Common::String str(utf8Text); + delete [] utf8Text; + return str; + } + } +#endif + return Common::String(text); +} + void HandlerUtils::setMessageHandler(Client &client, Common::String message, Common::String redirectTo) { - Common::String response = "<html><head><title>ScummVM</title></head><body>{message}</body></html>"; + Common::String response = "<html><head><title>ScummVM</title><meta charset=\"utf-8\"/></head><body>{message}</body></html>"; // load stylish response page from the archive Common::SeekableReadStream *const stream = getArchiveFile(INDEX_PAGE_NAME); @@ -194,7 +210,7 @@ void HandlerUtils::setFilesManagerErrorMessageHandler(Client &client, Common::St message.c_str(), client.queryParameter("ajax") == "true" ? "AJAX" : "", "%2F", //that's encoded "/" - _("Back to the files manager") + toUtf8(_("Back to the files manager")).c_str() ), redirectTo ); diff --git a/backends/networking/sdl_net/handlerutils.h b/backends/networking/sdl_net/handlerutils.h index 0958294595..10ef2dc66a 100644 --- a/backends/networking/sdl_net/handlerutils.h +++ b/backends/networking/sdl_net/handlerutils.h @@ -41,6 +41,8 @@ public: static bool hasPermittedPrefix(const Common::String &path); static bool permittedPath(const Common::String path); + static Common::String toUtf8(const char*); + static void setMessageHandler(Client &client, Common::String message, Common::String redirectTo = ""); static void setFilesManagerErrorMessageHandler(Client &client, Common::String message, Common::String redirectTo = ""); }; diff --git a/backends/networking/sdl_net/uploadfileclienthandler.cpp b/backends/networking/sdl_net/uploadfileclienthandler.cpp index 8486b6e92e..fb00b6bf5e 100644 --- a/backends/networking/sdl_net/uploadfileclienthandler.cpp +++ b/backends/networking/sdl_net/uploadfileclienthandler.cpp @@ -66,7 +66,7 @@ void UploadFileClientHandler::handle(Client *client) { // fail on suspicious headers if (_headersStream->size() > Reader::SUSPICIOUS_HEADERS_SIZE) { - setErrorMessageHandler(*client, _("Invalid request: headers are too long!")); + setErrorMessageHandler(*client, HandlerUtils::toUtf8(_("Invalid request: headers are too long!"))); } break; @@ -108,7 +108,7 @@ void UploadFileClientHandler::handleBlockHeaders(Client *client) { // fail on suspicious headers if (_headersStream->size() > Reader::SUSPICIOUS_HEADERS_SIZE) { - setErrorMessageHandler(*client, _("Invalid request: headers are too long!")); + setErrorMessageHandler(*client, HandlerUtils::toUtf8(_("Invalid request: headers are too long!"))); } // search for "upload_file" field @@ -134,11 +134,11 @@ void UploadFileClientHandler::handleBlockHeaders(Client *client) { path += '/'; AbstractFSNode *originalNode = g_system->getFilesystemFactory()->makeFileNodePath(path + filename); if (!HandlerUtils::permittedPath(originalNode->getPath())) { - setErrorMessageHandler(*client, _("Invalid path!")); + setErrorMessageHandler(*client, HandlerUtils::toUtf8(_("Invalid path!"))); return; } if (originalNode->exists()) { - setErrorMessageHandler(*client, _("There is a file with that name in the parent directory!")); + setErrorMessageHandler(*client, HandlerUtils::toUtf8(_("There is a file with that name in the parent directory!"))); return; } @@ -152,7 +152,7 @@ void UploadFileClientHandler::handleBlockHeaders(Client *client) { Common::DumpFile *f = new Common::DumpFile(); if (!f->open(originalNode->getPath(), true)) { delete f; - setErrorMessageHandler(*client, _("Failed to upload the file!")); + setErrorMessageHandler(*client, HandlerUtils::toUtf8(_("Failed to upload the file!"))); return; } @@ -181,7 +181,7 @@ void UploadFileClientHandler::handleBlockContent(Client *client) { if (client->noMoreContent()) { // if no file field was found - failure if (_uploadedFiles == 0) { - setErrorMessageHandler(*client, _("No file was passed!")); + setErrorMessageHandler(*client, HandlerUtils::toUtf8(_("No file was passed!"))); } else { setSuccessHandler(*client); } @@ -199,9 +199,9 @@ void UploadFileClientHandler::setSuccessHandler(Client &client) { client, Common::String::format( "%s<br/><a href=\"files?path=%s\">%s</a>", - _("Uploaded successfully!"), + HandlerUtils::toUtf8(_("Uploaded successfully!")).c_str(), client.queryParameter("path").c_str(), - _("Back to parent directory") + HandlerUtils::toUtf8(_("Back to parent directory")).c_str() ), (client.queryParameter("ajax") == "true" ? "/filesAJAX?path=" : "/files?path=") + LocalWebserver::urlEncodeQueryParameterValue(client.queryParameter("path")) |