aboutsummaryrefslogtreecommitdiff
path: root/backends/networking/sdl_net
diff options
context:
space:
mode:
authorAlexander Tkachev2016-07-12 10:48:10 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commit389c669a4744629e19e48e8243dac1a8875e60c2 (patch)
treeb21b41ceac899b95a91f70adc90e01f9fb5f0eb7 /backends/networking/sdl_net
parent29e6020574e1bed81e20cf5ab5df521285d28615 (diff)
downloadscummvm-rg350-389c669a4744629e19e48e8243dac1a8875e60c2.tar.gz
scummvm-rg350-389c669a4744629e19e48e8243dac1a8875e60c2.tar.bz2
scummvm-rg350-389c669a4744629e19e48e8243dac1a8875e60c2.zip
CLOUD: Add "directory" form for webserver "/upload"
The attribute is Chrome-only.
Diffstat (limited to 'backends/networking/sdl_net')
-rw-r--r--backends/networking/sdl_net/handlers/filespagehandler.cpp5
-rw-r--r--backends/networking/sdl_net/uploadfileclienthandler.cpp29
-rw-r--r--backends/networking/sdl_net/uploadfileclienthandler.h1
3 files changed, 22 insertions, 13 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);