Skip to content

Commit

Permalink
android: add embedded ftp server support
Browse files Browse the repository at this point in the history
  • Loading branch information
Cpasjuste committed Jun 15, 2022
1 parent 7de49b8 commit 2b69e1f
Show file tree
Hide file tree
Showing 1,401 changed files with 419,246 additions and 17 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set(OPTION_BUILTIN_LIBCONFIG OFF CACHE BOOL "Build libconfig from sources")
set(OPTION_BUILTIN_MINIZIP OFF CACHE BOOL "Build minizip from sources")
set(OPTION_MPV_PLAYER ON CACHE BOOL "Add support for video snaps (mpv)")
set(OPTION_UPDATE_CONFIG OFF CACHE BOOL "Force config file updating")
set(OPTION_FTP_SERVER OFF CACHE BOOL "Embedded ftp server")
####################
# BUILD OPTIONS
####################
Expand Down
2 changes: 1 addition & 1 deletion libcross2d
4 changes: 2 additions & 2 deletions pfbneo/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ android {
externalNativeBuild {
cmake {
cppFlags '-std=c++17'
arguments "-DPLATFORM_ANDROID=ON", "-DANDROID_ASSETS_PATH=${sourceSets.main.assets.srcDirs[0]}", "-DOPTION_EMU=pfbneo"
arguments "-DOPTION_EMU=pfbneo", "-DPLATFORM_ANDROID=ON", "-DOPTION_FTP_SERVER=ON", "-DANDROID_ASSETS_PATH=${sourceSets.main.assets.srcDirs[0]}"
}
}
}
Expand Down Expand Up @@ -50,4 +50,4 @@ dependencies {
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation project(path: ':lib')
}
}
4 changes: 2 additions & 2 deletions pgen/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ android {
externalNativeBuild {
cmake {
cppFlags '-std=c++17'
arguments "-DPLATFORM_ANDROID=ON", "-DOPTION_EMU=pgen", "-DANDROID_ASSETS_PATH=${sourceSets.main.assets.srcDirs[0]}"
arguments "-DOPTION_EMU=pgen", "-DPLATFORM_ANDROID=ON", "-DOPTION_FTP_SERVER=ON", "-DANDROID_ASSETS_PATH=${sourceSets.main.assets.srcDirs[0]}"
}
}
}
Expand Down Expand Up @@ -50,4 +50,4 @@ dependencies {
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation project(path: ':lib')
}
}
4 changes: 2 additions & 2 deletions pnes/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ android {
externalNativeBuild {
cmake {
cppFlags '-std=c++17'
arguments "-DPLATFORM_ANDROID=ON", "-DOPTION_EMU=pnes", "-DANDROID_ASSETS_PATH=${sourceSets.main.assets.srcDirs[0]}"
arguments "-DOPTION_EMU=pnes", "-DPLATFORM_ANDROID=ON", "-DOPTION_FTP_SERVER=ON", "-DANDROID_ASSETS_PATH=${sourceSets.main.assets.srcDirs[0]}"
}
}
}
Expand Down Expand Up @@ -50,4 +50,4 @@ dependencies {
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation project(path: ':lib')
}
}
4 changes: 2 additions & 2 deletions psnes/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ android {
externalNativeBuild {
cmake {
cppFlags '-std=c++17'
arguments "-DPLATFORM_ANDROID=ON", "-DANDROID_ASSETS_PATH=${sourceSets.main.assets.srcDirs[0]}", "-DOPTION_EMU=psnes"
arguments "-DOPTION_EMU=psnes", "-DPLATFORM_ANDROID=ON", "-DOPTION_FTP_SERVER=ON", "-DANDROID_ASSETS_PATH=${sourceSets.main.assets.srcDirs[0]}"
}
}
}
Expand Down Expand Up @@ -50,4 +50,4 @@ dependencies {
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation project(path: ':lib')
}
}
6 changes: 6 additions & 0 deletions ui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ else ()
list(APPEND LDFLAGS minizip)
endif ()

if (OPTION_FTP_SERVER)
add_subdirectory(external/fineftp-server)
list(APPEND FLAGS -D__FTP_SERVER__)
list(APPEND LDFLAGS fineftp::server)
endif ()

if (PLATFORM_LINUX OR PLATFORM_WINDOWS)
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)
Expand Down
3 changes: 3 additions & 0 deletions ui/c2dui_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ Config::Config(c2d::Io *io, int ver, const std::string &defaultRomsPath) {
append("FULLSCREEN", {"OFF", "ON"}, 0, Option::Id::GUI_FULLSCREEN, Option::Flags::BOOLEAN);
get()->at(get()->size() - 1).setInfo("YOU NEED TO RESTART THE APPLICATION AFTER CHANGING THIS OPTION");
#endif
#ifdef __FTP_SERVER__
append("FTP_SERVER", {"OFF", "ON"}, 0, Option::Id::GUI_FTP_SERVER, Option::Flags::BOOLEAN);
#endif

// build skin list
std::vector<std::string> skins;
Expand Down
1 change: 1 addition & 0 deletions ui/c2dui_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace c2dui {
GUI_SCREEN_WIDTH,
GUI_SCREEN_HEIGHT,
GUI_FULLSCREEN,
GUI_FTP_SERVER,
GUI_SKIN,
GUI_VIDEO_SNAP_DELAY,
MENU_ROM_OPTIONS,
Expand Down
36 changes: 33 additions & 3 deletions ui/c2dui_ui_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include <algorithm>
#include "c2dui.h"
#include "c2dui_ui_main.h"


UiMain::UiMain(const Vector2f &size, c2d::Io *io, Config *cfg) : C2DRenderer(size) {
printf("UiMain(%ix%i)\n", (int) UiMain::getSize().x, (int) UiMain::getSize().y);
Expand All @@ -22,8 +24,9 @@ UiMain::UiMain(const Vector2f &size, c2d::Io *io, Config *cfg) : C2DRenderer(siz
}

UiMain::~UiMain() {
// ui elements (C2DObject)
// are deleted by the renderer
#ifdef __FTP_SERVER__
delete (ftpServer);
#endif
#if 0
delete (scrapper);
#endif
Expand Down Expand Up @@ -70,7 +73,8 @@ void UiMain::init(UIRomList *_uiRomList, UiMenu *_uiMenu,
float fontSize = uiMessageBox->getTitleText()->getSize().y * 1.5f;
uiMessageBox->getTitleText()->setSize(
uiMessageBox->getTitleText()->getSize().x * 1.5f, fontSize);
uiMessageBox->getTitleText()->setSizeMax(uiMessageBox->getSize().x - (float) fontSize * 2, (float) fontSize + 4);
uiMessageBox->getTitleText()->setSizeMax(uiMessageBox->getSize().x - (float) fontSize * 2,
(float) fontSize + 4);
uiMessageBox->setSelectedColor(uiMessageBox->getFillColor(), uiMessageBox->getOutlineColor());
Color c = uiMessageBox->getOutlineColor();
c.a -= 150;
Expand All @@ -91,6 +95,13 @@ void UiMain::init(UIRomList *_uiRomList, UiMenu *_uiMenu,
updateInputMapping(false);
getInput()->setRepeatDelay(INPUT_DELAY);

#ifdef __FTP_SERVER__
bool startFtp = config->get(Option::Id::GUI_FTP_SERVER)->getValueBool();
if (startFtp) {
ftpServerStart();
}
#endif

#if 0
scrapper = new Scrapper(this);
#endif
Expand Down Expand Up @@ -223,3 +234,22 @@ void UiMain::updateInputMapping(bool isRomConfig) {
}
}
}

#ifdef __FTP_SERVER__

void UiMain::ftpServerStart() {
if (!ftpServer) {
ftpServer = new fineftp::FtpServer(3333);
ftpServer->addUser("pemu", "pemu", getIo()->getDataPath(), fineftp::Permission::All);
ftpServer->start(2);
}
}

void UiMain::ftpServerStop() {
if (ftpServer) {
delete (ftpServer);
ftpServer = nullptr;
}
}

#endif
17 changes: 17 additions & 0 deletions ui/c2dui_ui_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
#ifndef GUI_H
#define GUI_H

#ifdef __FTP_SERVER__

#include "fineftp/server.h"

#endif

#define UI_KEY_FILTER_ROMS 100
#define UI_KEY_SHOW_ROMLIST 101
#define UI_KEY_SHOW_MEMU_UI 102
Expand Down Expand Up @@ -69,6 +75,14 @@ namespace c2dui {

bool done = false;

#ifdef __FTP_SERVER__

void ftpServerStart();

void ftpServerStop();

#endif

private:

Config *config = nullptr;
Expand All @@ -83,6 +97,9 @@ namespace c2dui {
UiStatusBox *uiStatusBox = nullptr;
c2d::C2DClock timer;
unsigned int oldKeys = 0;
#ifdef __FTP_SERVER__
fineftp::FtpServer *ftpServer = nullptr;
#endif
};
}

Expand Down
19 changes: 14 additions & 5 deletions ui/c2dui_ui_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,24 @@ bool UiMenu::onInput(c2d::Input::Player *players) {
}
break;
#ifdef __VITA__
case Option::Id::ROM_WAIT_RENDERING:
if (isEmuRunning) {
((PSP2Renderer *) ui)->setWaitRendering(option.getValueBool());
}
break;
case Option::Id::ROM_WAIT_RENDERING:
if (isEmuRunning) {
((PSP2Renderer *) ui)->setWaitRendering(option.getValueBool());
}
break;
#endif
case Option::Id::GUI_VIDEO_SNAP_DELAY:
ui->getUiRomList()->setVideoSnapDelay(option.getValueInt());
break;
#ifdef __FTP_SERVER__
case Option::Id::GUI_FTP_SERVER:
if (option.getValueBool()) {
ui->ftpServerStart();
} else {
ui->ftpServerStop();
}
break;
#endif
default:
break;
}
Expand Down
19 changes: 19 additions & 0 deletions ui/external/fineftp-server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
*Debug
ipch

*.sdf
*.suo
*.aps
*.user
*.opendb
*.db
/_build
/_install
/.vs
/CMakeLists.txt.user

# Common build directories in CMake projects
build*

# Temporary Vim files
*.swp
3 changes: 3 additions & 0 deletions ui/external/fineftp-server/.gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "thirdparty/asio"]
path = thirdparty/asio
url = https://github.com/chriskohlhoff/asio.git
27 changes: 27 additions & 0 deletions ui/external/fineftp-server/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
cmake_minimum_required(VERSION 3.5.1)

set(CMAKE_CXX_STANDARD 14)

# Normalize backslashes from Windows paths
file(TO_CMAKE_PATH "${CMAKE_MODULE_PATH}" CMAKE_MODULE_PATH)
file(TO_CMAKE_PATH "${CMAKE_PREFIX_PATH}" CMAKE_PREFIX_PATH)
message(STATUS "Module Path: ${CMAKE_MODULE_PATH}")
message(STATUS "Prefix Path: ${CMAKE_PREFIX_PATH}")

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

project(fineftp)

set(as_subproject fineftp)

string(COMPARE EQUAL "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}" _cmp)
if (_cmp)
macro(find_package)
if(NOT "${ARGV0}" IN_LIST as_subproject)
_find_package(${ARGV})
endif()
endmacro()
endif()

add_subdirectory(fineftp-server)
#add_subdirectory(example)
6 changes: 6 additions & 0 deletions ui/external/fineftp-server/CMakeWindows.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mkdir _build
cd _build

cmake .. -DCMAKE_INSTALL_PREFIX=_install
cd ..
pause
21 changes: 21 additions & 0 deletions ui/external/fineftp-server/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Continental Corporation

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading

0 comments on commit 2b69e1f

Please sign in to comment.