Skip to content

Commit

Permalink
Merge pull request #18631 from hrydgard/remote-iso-folder-prep
Browse files Browse the repository at this point in the history
Remote ISO: Prepare to allow sharing folders directly
  • Loading branch information
hrydgard committed Dec 29, 2023
2 parents 9e82b12 + 74a33ab commit 1e65841
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Common/Net/HTTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ bool Connection::Connect(int maxTries, double timeout, bool *cancelConnect) {

selectResult = select(maxfd, nullptr, &fds, nullptr, &tv);
if (cancelConnect && *cancelConnect) {
WARN_LOG(HTTP, "connect: cancelled (1)");
break;
}
}
Expand All @@ -196,6 +197,7 @@ bool Connection::Connect(int maxTries, double timeout, bool *cancelConnect) {
}

if (cancelConnect && *cancelConnect) {
WARN_LOG(HTTP, "connect: cancelled (2)");
break;
}

Expand Down
2 changes: 1 addition & 1 deletion Common/Net/HTTPHeaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class RequestHeader {
enum RequestType {
SIMPLE, FULL,
};
RequestType type;
RequestType type = SIMPLE;
enum Method {
GET,
HEAD,
Expand Down
2 changes: 1 addition & 1 deletion Common/Net/HTTPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ ServerRequest::~ServerRequest() {
}
delete in_;
if (!out_->Empty()) {
ERROR_LOG(IO, "Output not empty - connection abort? (%s)", this->header_.resource);
WARN_LOG(IO, "Output not empty - connection abort? (%s) (%d bytes)", this->header_.resource, out_->BytesRemaining());
}
delete out_;
}
Expand Down
10 changes: 7 additions & 3 deletions Common/Net/Sinks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void InputSink::AccountDrain(size_t bytes) {
}
}

bool InputSink::Empty() {
bool InputSink::Empty() const {
return valid_ == 0;
}

Expand Down Expand Up @@ -418,8 +418,12 @@ void OutputSink::AccountDrain(int bytes) {
}
}

bool OutputSink::Empty() {
bool OutputSink::Empty() const {
return valid_ == 0;
}

};
int OutputSink::BytesRemaining() const {
return valid_;
}

} // namespace net
7 changes: 4 additions & 3 deletions Common/Net/Sinks.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class InputSink {
bool Skip(size_t bytes);
void Discard();

bool Empty();
bool Empty() const;
bool TryFill();

private:
Expand Down Expand Up @@ -54,7 +54,8 @@ class OutputSink {
bool Flush(bool allowBlock = true);
void Discard();

bool Empty();
bool Empty() const;
int BytesRemaining() const;

private:
void Drain();
Expand All @@ -72,4 +73,4 @@ class OutputSink {
size_t valid_;
};

};
} // namespace net
24 changes: 24 additions & 0 deletions Common/UI/PopupScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,4 +692,28 @@ std::string FileChooserChoice::ValueText() const {
return path.GetFilename();
}

FolderChooserChoice::FolderChooserChoice(std::string *value, const std::string &text, LayoutParams *layoutParams)
: AbstractChoiceWithValueDisplay(text, layoutParams), value_(value) {
OnClick.Add([=](UI::EventParams &) {
System_BrowseForFolder(text_, [=](const std::string &returnValue, int) {
if (*value_ != returnValue) {
*value = returnValue;
UI::EventParams e{};
e.s = *value;
OnChange.Trigger(e);
}
});
return UI::EVENT_DONE;
});
}

std::string FolderChooserChoice::ValueText() const {
if (value_->empty()) {
auto di = GetI18NCategory(I18NCat::DIALOG);
return di->T("Default");
}
Path path(*value_);
return path.GetFilename();
}

} // namespace
13 changes: 13 additions & 0 deletions Common/UI/PopupScreens.h
Original file line number Diff line number Diff line change
Expand Up @@ -436,4 +436,17 @@ class FileChooserChoice : public AbstractChoiceWithValueDisplay {
BrowseFileType fileType_;
};

class FolderChooserChoice : public AbstractChoiceWithValueDisplay {
public:
FolderChooserChoice(std::string *value, const std::string &title, LayoutParams *layoutParams = nullptr);
std::string ValueText() const override;

Event OnChange;

private:
std::string *value_;
BrowseFileType fileType_;
};


} // namespace UI
6 changes: 6 additions & 0 deletions Core/WebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ static Path LocalFromRemotePath(const std::string &path) {

static void DiscHandler(const http::ServerRequest &request, const Path &filename) {
s64 sz = File::GetFileSize(filename);
if (sz == 0) {
// Probably failed
request.WriteHttpResponseHeader("1.0", 404, -1, "text/plain");
request.Out()->Push("File not found.");
return;
}

std::string range;
if (request.Method() == http::RequestHeader::HEAD) {
Expand Down
1 change: 1 addition & 0 deletions UI/RemoteISOScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ bool RemoteISOConnectScreen::FindServer(std::string &resultHost, int &resultPort

std::lock_guard<std::mutex> guard(statusLock_);
statusMessage_ = formatted;
INFO_LOG(SYSTEM, "Remote: %s", formatted.c_str());
};

http.SetUserAgent(StringFromFormat("PPSSPP/%s", PPSSPP_GIT_VERSION));
Expand Down

0 comments on commit 1e65841

Please sign in to comment.