mirror of
https://github.com/DarkStore-3DS/DarkStore.git
synced 2026-07-02 16:49:05 +00:00
Add FTP.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* This file is part of Universal-Updater
|
||||
* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "screens/screen.hpp"
|
||||
|
||||
class FTPScreen : public Screen
|
||||
{
|
||||
public:
|
||||
void Draw(void) const override;
|
||||
void Logic(u32 hDown, u32 hHeld, touchPosition touch) override;
|
||||
|
||||
private:
|
||||
int ftpEnabled = 1;
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef _3DS
|
||||
#include <3ds.h>
|
||||
#define ESC(x) "\x1b[" #x
|
||||
#define RESET ESC(0m)
|
||||
#define BLACK ESC(30m)
|
||||
#define RED ESC(31;1m)
|
||||
#define GREEN ESC(32;1m)
|
||||
#define YELLOW ESC(33;1m)
|
||||
#define BLUE ESC(34;1m)
|
||||
#define MAGENTA ESC(35;1m)
|
||||
#define CYAN ESC(36;1m)
|
||||
#define WHITE ESC(37;1m)
|
||||
#else
|
||||
#define ESC(x)
|
||||
#define RESET
|
||||
#define BLACK
|
||||
#define RED
|
||||
#define GREEN
|
||||
#define YELLOW
|
||||
#define BLUE
|
||||
#define MAGENTA
|
||||
#define CYAN
|
||||
#define WHITE
|
||||
#endif
|
||||
|
||||
void console_init(void);
|
||||
|
||||
__attribute__((format(printf,1,2)))
|
||||
void console_set_status(const char *fmt, ...);
|
||||
|
||||
__attribute__((format(printf,1,2)))
|
||||
void console_print(const char *fmt, ...);
|
||||
|
||||
__attribute__((format(printf,1,2)))
|
||||
void debug_print(const char *fmt, ...);
|
||||
|
||||
void console_render(void);
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <3ds.h>
|
||||
|
||||
/*! Loop status */
|
||||
typedef enum
|
||||
{
|
||||
LOOP_CONTINUE, /*!< Continue looping */
|
||||
LOOP_RESTART, /*!< Reinitialize */
|
||||
LOOP_EXIT, /*!< Terminate looping */
|
||||
} loop_status_t;
|
||||
|
||||
bool isTransfering;
|
||||
char ftp_accepted_connection[50], ftp_file_transfer[100];
|
||||
|
||||
int ftp_init(void);
|
||||
loop_status_t ftp_loop(void);
|
||||
void ftp_exit(void);
|
||||
@@ -44,5 +44,12 @@
|
||||
|
||||
"FUTURE_SCRIPT": "This Script is a Future Script.",
|
||||
"OUTDATED_SCRIPT": "This Script is outdated.",
|
||||
"UP-TO-DATE": "This Script is Up-To-Date."
|
||||
"UP-TO-DATE": "This Script is Up-To-Date.",
|
||||
|
||||
"FTP_MODE": "FTP Mode",
|
||||
"FTP_INITIALIZED": "FTP Initialized.",
|
||||
"FAILED_GET_IP": "Failed to get IP.",
|
||||
"FAILED_INITIALIZE_FTP": "Failed to initialize FTP.",
|
||||
"B_FTP_EXIT": "Press B to exit from FTP.",
|
||||
"WIFI_NOT_ENABLED": "WiFi not enabled."
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ int main()
|
||||
romfsInit();
|
||||
sdmcInit();
|
||||
cfguInit();
|
||||
acInit();
|
||||
// Create Folder if missing.
|
||||
mkdir("sdmc:/3ds", 0777);
|
||||
mkdir("sdmc:/3ds/Universal-Updater", 0777);
|
||||
@@ -90,6 +91,7 @@ int main()
|
||||
Gui::exit();
|
||||
gfxExit();
|
||||
cfguExit();
|
||||
acExit();
|
||||
romfsExit();
|
||||
sdmcExit();
|
||||
return 0;
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* This file is part of Universal-Updater
|
||||
* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "lang/lang.hpp"
|
||||
|
||||
#include "screens/ftpScreen.hpp"
|
||||
#include "screens/screenCommon.hpp"
|
||||
|
||||
#include "utils/config.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <unistd.h>
|
||||
|
||||
extern "C" {
|
||||
#include "ftp.h"
|
||||
}
|
||||
|
||||
void FTPScreen::Draw(void) const
|
||||
{
|
||||
ftp_init();
|
||||
Result ret = 0;
|
||||
char buf[137], hostname[128];
|
||||
u32 wifiStatus = 0;
|
||||
ret = gethostname(hostname, sizeof(hostname));
|
||||
|
||||
while(ftpEnabled == 1) {
|
||||
ftp_loop();
|
||||
Gui::clearTextBufs();
|
||||
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
|
||||
Gui::DrawTop();
|
||||
Gui::DrawString((400-Gui::GetStringWidth(0.8f, Lang::get("FTP_MODE")))/2, 2, 0.8f, Config::TxtColor, Lang::get("FTP_MODE"), 400);
|
||||
Gui::DrawBottom();
|
||||
ret = ACU_GetWifiStatus(&wifiStatus);
|
||||
|
||||
if ((wifiStatus != 0) && R_SUCCEEDED(ret)) {
|
||||
Gui::DrawStringCentered(0, 40, 0.48f, Config::TxtColor, Lang::get("FTP_INITIALIZED"), 320);
|
||||
snprintf(buf, 137, "IP: %s:5000", R_FAILED(ret)? Lang::get("FAILED_GET_IP").c_str() : hostname);
|
||||
|
||||
if (strlen(ftp_accepted_connection) != 0)
|
||||
Gui::DrawStringCentered(0, 80, 0.45f, Config::TxtColor, ftp_accepted_connection, 320);
|
||||
|
||||
if (strlen(ftp_file_transfer) != 0)
|
||||
Gui::DrawStringCentered(0, 150, 0.45f, Config::TxtColor, ftp_file_transfer, 320);
|
||||
}
|
||||
else {
|
||||
Gui::DrawStringCentered(0, 40, 0.48f, Config::TxtColor, Lang::get("FAILED_INITIALIZE_FTP"), 320);
|
||||
snprintf(buf, 18, Lang::get("WIFI_NOT_ENABLED").c_str());
|
||||
}
|
||||
|
||||
Gui::DrawStringCentered(0, 60, 0.48, Config::TxtColor, buf, 320);
|
||||
Gui::DrawStringCentered(0, 220, 0.48f, Config::TxtColor, Lang::get("B_FTP_EXIT"), 320);
|
||||
|
||||
Gui::clearTextBufs();
|
||||
C3D_FrameEnd(0);
|
||||
hidScanInput();
|
||||
u32 hDown = hidKeysDown();
|
||||
|
||||
if (hDown & KEY_B)
|
||||
break;
|
||||
}
|
||||
memset(ftp_accepted_connection, 0, 20); // Empty accepted connection address.
|
||||
memset(ftp_file_transfer, 0, 50); // Empty transfer status.
|
||||
ftp_exit();
|
||||
|
||||
Gui::screenBack();
|
||||
return;
|
||||
}
|
||||
|
||||
// Needed here, otherwise it won't compile.
|
||||
void FTPScreen::Logic(u32 hDown, u32 hHeld, touchPosition touch)
|
||||
{
|
||||
}
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include "download/download.hpp"
|
||||
|
||||
#include "screens/ftpScreen.hpp"
|
||||
#include "screens/mainMenu.hpp"
|
||||
#include "screens/scriptBrowse.hpp"
|
||||
#include "screens/scriptlist.hpp"
|
||||
@@ -92,6 +93,10 @@ void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
}
|
||||
}
|
||||
|
||||
if (hDown & KEY_X) {
|
||||
Gui::setScreen(std::make_unique<FTPScreen>());
|
||||
}
|
||||
|
||||
if (hDown & KEY_TOUCH) {
|
||||
if (touching(touch, mainButtons[0])) {
|
||||
Gui::setScreen(std::make_unique<ScriptList>());
|
||||
|
||||
@@ -0,0 +1,237 @@
|
||||
#include "utils/console.h"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _3DS
|
||||
#include <3ds.h>
|
||||
|
||||
static PrintConsole status_console;
|
||||
static PrintConsole main_console;
|
||||
static PrintConsole tcp_console;
|
||||
#if ENABLE_LOGGING
|
||||
static bool disable_logging = false;
|
||||
#endif
|
||||
|
||||
/*! initialize console subsystem */
|
||||
void
|
||||
console_init(void)
|
||||
{
|
||||
consoleInit(GFX_TOP, &status_console);
|
||||
consoleSetWindow(&status_console, 0, 0, 50, 1);
|
||||
|
||||
consoleInit(GFX_TOP, &main_console);
|
||||
consoleSetWindow(&main_console, 0, 1, 50, 29);
|
||||
|
||||
consoleInit(GFX_BOTTOM, &tcp_console);
|
||||
|
||||
consoleSelect(&main_console);
|
||||
}
|
||||
|
||||
/*! set status bar contents
|
||||
*
|
||||
* @param[in] fmt format string
|
||||
* @param[in] ... format arguments
|
||||
*/
|
||||
void
|
||||
console_set_status(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
consoleSelect(&status_console);
|
||||
va_start(ap, fmt);
|
||||
vprintf(fmt, ap);
|
||||
#ifdef ENABLE_LOGGING
|
||||
vfprintf(stderr, fmt, ap);
|
||||
#endif
|
||||
va_end(ap);
|
||||
consoleSelect(&main_console);
|
||||
}
|
||||
|
||||
/*! add text to the console
|
||||
*
|
||||
* @param[in] fmt format string
|
||||
* @param[in] ... format arguments
|
||||
*/
|
||||
void
|
||||
console_print(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vprintf(fmt, ap);
|
||||
#ifdef ENABLE_LOGGING
|
||||
if (!disable_logging)
|
||||
vfprintf(stderr, fmt, ap);
|
||||
#endif
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
/*! print debug message
|
||||
*
|
||||
* @param[in] fmt format string
|
||||
* @param[in] ... format arguments
|
||||
*/
|
||||
void
|
||||
debug_print(const char *fmt, ...)
|
||||
{
|
||||
#ifdef ENABLE_LOGGING
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*! print tcp tables */
|
||||
static void
|
||||
print_tcp_table(void)
|
||||
{
|
||||
static SOCU_TCPTableEntry tcp_entries[32];
|
||||
socklen_t optlen;
|
||||
size_t i;
|
||||
int rc, lines = 0;
|
||||
|
||||
#ifdef ENABLE_LOGGING
|
||||
disable_logging = true;
|
||||
#endif
|
||||
|
||||
consoleSelect(&tcp_console);
|
||||
console_print("\x1b[0;0H\x1b[K");
|
||||
optlen = sizeof(tcp_entries);
|
||||
rc = SOCU_GetNetworkOpt(SOL_CONFIG, NETOPT_TCP_TABLE, tcp_entries, &optlen);
|
||||
if(rc != 0 && errno != ENODEV)
|
||||
console_print(RED "tcp table: %d %s\n\x1b[J\n" RESET, errno, strerror(errno));
|
||||
else if(rc == 0)
|
||||
{
|
||||
for(i = 0; lines < 30 && i < optlen / sizeof(SOCU_TCPTableEntry); ++i)
|
||||
{
|
||||
SOCU_TCPTableEntry *entry = &tcp_entries[i];
|
||||
struct sockaddr_in *local = (struct sockaddr_in*)&entry->local;
|
||||
struct sockaddr_in *remote = (struct sockaddr_in*)&entry->remote;
|
||||
|
||||
console_print(GREEN "%stcp[%zu]: ", i == 0 ? "" : "\n", i);
|
||||
switch(entry->state)
|
||||
{
|
||||
case TCP_STATE_CLOSED:
|
||||
console_print("CLOSED\x1b[K");
|
||||
local = remote = NULL;
|
||||
break;
|
||||
|
||||
case TCP_STATE_LISTEN:
|
||||
console_print("LISTEN\x1b[K");
|
||||
remote = NULL;
|
||||
break;
|
||||
|
||||
case TCP_STATE_ESTABLISHED:
|
||||
console_print("ESTABLISHED\x1b[K");
|
||||
break;
|
||||
|
||||
case TCP_STATE_FINWAIT1:
|
||||
console_print("FINWAIT1\x1b[K");
|
||||
break;
|
||||
|
||||
case TCP_STATE_FINWAIT2:
|
||||
console_print("FINWAIT2\x1b[K");
|
||||
break;
|
||||
|
||||
case TCP_STATE_CLOSE_WAIT:
|
||||
console_print("CLOSE_WAIT\x1b[K");
|
||||
break;
|
||||
|
||||
case TCP_STATE_LAST_ACK:
|
||||
console_print("LAST_ACK\x1b[K");
|
||||
break;
|
||||
|
||||
case TCP_STATE_TIME_WAIT:
|
||||
console_print("TIME_WAIT\x1b[K");
|
||||
break;
|
||||
|
||||
default:
|
||||
console_print("State %lu\x1b[K", entry->state);
|
||||
break;
|
||||
}
|
||||
|
||||
++lines;
|
||||
|
||||
if(local && (lines++ < 30))
|
||||
console_print("\n Local %s:%u\x1b[K", inet_ntoa(local->sin_addr),
|
||||
ntohs(local->sin_port));
|
||||
|
||||
if(remote && (lines++ < 30))
|
||||
console_print("\n Peer %s:%u\x1b[K", inet_ntoa(remote->sin_addr),
|
||||
ntohs(remote->sin_port));
|
||||
}
|
||||
|
||||
console_print(RESET "\x1b[J");
|
||||
}
|
||||
else
|
||||
console_print("\x1b[2J");
|
||||
|
||||
consoleSelect(&main_console);
|
||||
|
||||
#ifdef ENABLE_LOGGING
|
||||
disable_logging = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*! draw console to screen */
|
||||
void
|
||||
console_render(void)
|
||||
{
|
||||
/* print tcp table */
|
||||
print_tcp_table();
|
||||
|
||||
/* flush framebuffer */
|
||||
gfxFlushBuffers();
|
||||
gspWaitForVBlank();
|
||||
gfxSwapBuffers();
|
||||
}
|
||||
#else
|
||||
|
||||
/* this is a lot easier when you have a real console */
|
||||
|
||||
void
|
||||
console_init(void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
console_set_status(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vprintf(fmt, ap);
|
||||
va_end(ap);
|
||||
fputc('\n', stdout);
|
||||
}
|
||||
|
||||
void
|
||||
console_print(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vprintf(fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
debug_print(const char *fmt, ...)
|
||||
{
|
||||
#ifdef ENABLE_LOGGING
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
#endif
|
||||
}
|
||||
|
||||
void console_render(void)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
+4042
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user