diff options
Diffstat (limited to 'backends/networking')
-rw-r--r-- | backends/networking/sdl_net/handlers/filespagehandler.cpp | 5 | ||||
-rw-r--r-- | backends/networking/sdl_net/uploadfileclienthandler.cpp | 29 | ||||
-rw-r--r-- | backends/networking/sdl_net/uploadfileclienthandler.h | 1 | ||||
-rw-r--r-- | backends/networking/wwwroot.zip | bin | 231000 -> 231402 bytes | |||
-rw-r--r-- | backends/networking/wwwroot/.files.html | 8 |
5 files changed, 29 insertions, 14 deletions
diff --git a/backends/networking/sdl_net/handlers/filespagehandler.cpp b/backends/networking/sdl_net/handlers/filespagehandler.cpp index 9dba0c54ad..e519c5ac8b 100644 --- a/backends/networking/sdl_net/handlers/filespagehandler.cpp +++ b/backends/networking/sdl_net/handlers/filespagehandler.cpp @@ -59,7 +59,9 @@ void FilesPageHandler::handle(Client &client) { "<hr/>" \ "<p>{upload_file_desc}</p>" \ "<form action=\"upload?path={path}\" method=\"post\" enctype=\"multipart/form-data\">" \ - "<input type=\"file\" name=\"upload_file[]\" multiple/>" \ + "<input type=\"file\" name=\"upload_file-f\" allowdirs multiple/>" \ + "<span>{or_upload_directory_desc}</span>" \ + "<input type=\"file\" name=\"upload_file-d\" directory webkitdirectory multiple/>" \ "<input type=\"submit\" value=\"{upload_file_button}\"/>" \ "</form>" "<hr/>" \ @@ -90,6 +92,7 @@ void FilesPageHandler::handle(Client &client) { 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, "{content}", content); LocalWebserver::setClientGetHandler(client, response); } diff --git a/backends/networking/sdl_net/uploadfileclienthandler.cpp b/backends/networking/sdl_net/uploadfileclienthandler.cpp index 0ca5e3f684..7cbb11874c 100644 --- a/backends/networking/sdl_net/uploadfileclienthandler.cpp +++ b/backends/networking/sdl_net/uploadfileclienthandler.cpp @@ -24,6 +24,7 @@ #include "backends/fs/fs-factory.h" #include "backends/networking/sdl_net/handlerutils.h" #include "backends/networking/sdl_net/localwebserver.h" +#include "common/file.h" #include "common/memstream.h" #include "common/translation.h" @@ -31,7 +32,7 @@ namespace Networking { UploadFileClientHandler::UploadFileClientHandler(Common::String parentDirectoryPath): _state(UFH_READING_CONTENT), _headersStream(nullptr), _contentStream(nullptr), - _parentDirectoryPath(parentDirectoryPath) {} + _parentDirectoryPath(parentDirectoryPath), _uploadedFiles(0) {} UploadFileClientHandler::~UploadFileClientHandler() { delete _headersStream; @@ -114,16 +115,13 @@ void UploadFileClientHandler::handleBlockHeaders(Client *client) { Common::String headers = readEverythingFromMemoryStream(_headersStream); Common::String fieldName = ""; readFromThatUntilDoubleQuote(headers.c_str(), "name=\"", fieldName); - if (!fieldName.hasPrefix("upload_file[")) return; + if (!fieldName.hasPrefix("upload_file")) return; Common::String filename = ""; readFromThatUntilDoubleQuote(headers.c_str(), "filename=\"", filename); - // check that <filename> is not empty - if (filename.empty()) { - setErrorMessageHandler(*client, _("Invalid filename!")); - return; - } + // skip block if <filename> is empty + if (filename.empty()) return; // check that <path>/<filename> doesn't exist Common::String path = _parentDirectoryPath; @@ -134,12 +132,15 @@ void UploadFileClientHandler::handleBlockHeaders(Client *client) { return; } - // create file stream - _contentStream = originalNode->createWriteStream(); - if (_contentStream == nullptr) { + // create file stream (and necessary subdirectories) + Common::DumpFile *f = new Common::DumpFile(); + if (!f->open(originalNode->getPath(), true)) { + delete f; setErrorMessageHandler(*client, _("Failed to upload the file!")); return; } + + _contentStream = f; } void UploadFileClientHandler::handleBlockContent(Client *client) { @@ -148,6 +149,7 @@ void UploadFileClientHandler::handleBlockContent(Client *client) { // if previous block headers were file-related and created a stream if (_contentStream) { _contentStream->flush(); + ++_uploadedFiles; if (client->noMoreContent()) { // success - redirect back to directory listing @@ -165,9 +167,12 @@ void UploadFileClientHandler::handleBlockContent(Client *client) { } } - // if no file field was found, but no more content avaiable - failure + // no more content avaiable if (client->noMoreContent()) { - setErrorMessageHandler(*client, _("No file was passed!")); + // if no file field was found - failure + if (_uploadedFiles == 0) { + setErrorMessageHandler(*client, _("No file was passed!")); + } else _state = UFH_STOP; return; } } diff --git a/backends/networking/sdl_net/uploadfileclienthandler.h b/backends/networking/sdl_net/uploadfileclienthandler.h index de6941bf4f..f61a2fab5e 100644 --- a/backends/networking/sdl_net/uploadfileclienthandler.h +++ b/backends/networking/sdl_net/uploadfileclienthandler.h @@ -41,6 +41,7 @@ class UploadFileClientHandler: public ClientHandler { Common::MemoryReadWriteStream *_headersStream; Common::WriteStream *_contentStream; Common::String _parentDirectoryPath; + uint32 _uploadedFiles; void handleBlockHeaders(Client *client); void handleBlockContent(Client *client); diff --git a/backends/networking/wwwroot.zip b/backends/networking/wwwroot.zip Binary files differindex ae19ef7d29..3aa9bdda65 100644 --- a/backends/networking/wwwroot.zip +++ b/backends/networking/wwwroot.zip diff --git a/backends/networking/wwwroot/.files.html b/backends/networking/wwwroot/.files.html index c83a59f718..2c0bceb333 100644 --- a/backends/networking/wwwroot/.files.html +++ b/backends/networking/wwwroot/.files.html @@ -26,7 +26,13 @@ <div id="upload_file" class="modal"> <p>{upload_file_desc}</p> <form action="upload?path={path}" method="post" enctype="multipart/form-data"> - <input type="file" name="upload_file[]" multiple/> + <!-- we don't need "[]" in the name, as our webserver is not using PHP --> + <!-- "allowdirs" is a proposal, not implemented yet --> + <input type="file" name="upload_file-f" allowdirs multiple/> + <br/><br/> + <p>{or_upload_directory_desc}</p> + <!-- "directory"/"webkitdirectory" works in Chrome only yet, "multiple" is just in case here --> + <input type="file" name="upload_file-d" directory webkitdirectory multiple/> <input type="submit" value="{upload_file_button}"/> </form> </div> |