ftpiiu_plugin/src/main.cpp

111 lines
3.4 KiB
C++
Raw Normal View History

2022-02-04 14:33:59 +01:00
#include "BackgroundThread.hpp"
#include "utils/logger.h"
#include "virtualpath.h"
#include <coreinit/cache.h>
#include <cstring>
2019-11-24 14:20:08 +01:00
#include <iosuhax.h>
#include <iosuhax_devoptab.h>
#include <iosuhax_disc_interface.h>
#include <nn/ac.h>
2022-02-04 14:33:59 +01:00
#include <wups.h>
2019-11-24 14:20:08 +01:00
WUPS_PLUGIN_NAME("FTPiiU");
WUPS_PLUGIN_DESCRIPTION("FTP Server");
WUPS_PLUGIN_VERSION("0.1");
WUPS_PLUGIN_AUTHOR("Maschell");
WUPS_PLUGIN_LICENSE("GPL");
2021-09-24 19:41:27 +02:00
WUPS_USE_WUT_DEVOPTAB();
2019-11-24 14:20:08 +01:00
uint32_t hostIpAddress = 0;
2022-02-04 14:33:59 +01:00
int iosuhaxMount = 0;
int fsaFd = -1;
2019-11-24 14:20:08 +01:00
2021-09-24 19:49:11 +02:00
BackgroundThread *thread = nullptr;
2019-11-24 14:20:08 +01:00
/* Entry point */
2021-09-24 19:49:11 +02:00
ON_APPLICATION_START() {
2021-09-17 16:53:11 +02:00
nn::ac::Initialize();
2021-09-24 19:49:11 +02:00
nn::ac::ConnectAsync();
2021-09-17 16:53:11 +02:00
nn::ac::GetAssignedAddress(&hostIpAddress);
initLogging();
2019-11-24 14:20:08 +01:00
//!*******************************************************************
//! Initialize FS *
//!*******************************************************************
2022-01-30 21:05:09 +01:00
VirtualMountDevice("fs:/");
AddVirtualFSPath("vol", nullptr, nullptr);
AddVirtualFSVOLPath("external01", nullptr, nullptr);
AddVirtualFSVOLPath("content", nullptr, nullptr);
2020-11-26 23:32:44 +01:00
int res = IOSUHAX_Open(nullptr);
2021-09-24 19:49:11 +02:00
if (res < 0) {
2022-05-14 19:49:12 +02:00
DEBUG_FUNCTION_LINE_ERR("IOSUHAX_open failed");
2019-11-24 14:20:08 +01:00
} else {
iosuhaxMount = 1;
//fatInitDefault();
fsaFd = IOSUHAX_FSA_Open();
2021-09-24 19:49:11 +02:00
if (fsaFd < 0) {
2022-05-14 19:49:12 +02:00
DEBUG_FUNCTION_LINE_ERR("IOSUHAX_FSA_Open failed");
2019-11-24 14:20:08 +01:00
}
DEBUG_FUNCTION_LINE("IOSUHAX_FSA_Open done");
2019-11-24 14:20:08 +01:00
mount_fs("slccmpt01", fsaFd, "/dev/slccmpt01", "/vol/storage_slccmpt01");
mount_fs("storage_odd_tickets", fsaFd, "/dev/odd01", "/vol/storage_odd_tickets");
mount_fs("storage_odd_updates", fsaFd, "/dev/odd02", "/vol/storage_odd_updates");
mount_fs("storage_odd_content", fsaFd, "/dev/odd03", "/vol/storage_odd_content");
mount_fs("storage_odd_content2", fsaFd, "/dev/odd04", "/vol/storage_odd_content2");
2021-09-24 19:49:11 +02:00
mount_fs("storage_slc", fsaFd, nullptr, "/vol/system");
mount_fs("storage_mlc", fsaFd, nullptr, "/vol/storage_mlc01");
mount_fs("storage_usb", fsaFd, nullptr, "/vol/storage_usb01");
2019-11-24 14:20:08 +01:00
VirtualMountDevice("slccmpt01:/");
VirtualMountDevice("storage_odd_tickets:/");
VirtualMountDevice("storage_odd_updates:/");
VirtualMountDevice("storage_odd_content:/");
VirtualMountDevice("storage_odd_content2:/");
VirtualMountDevice("storage_slc:/");
VirtualMountDevice("storage_mlc:/");
VirtualMountDevice("storage_usb:/");
VirtualMountDevice("usb:/");
}
thread = BackgroundThread::getInstance();
DCFlushRange(&thread, 4);
}
2021-09-24 19:49:11 +02:00
void stopThread() {
2019-11-24 14:20:08 +01:00
BackgroundThread::destroyInstance();
}
2021-09-24 19:49:11 +02:00
ON_APPLICATION_REQUESTS_EXIT() {
2022-05-14 19:49:12 +02:00
DEBUG_FUNCTION_LINE_VERBOSE("Ending ftp server");
2019-11-24 14:20:08 +01:00
stopThread();
2022-05-14 19:49:12 +02:00
DEBUG_FUNCTION_LINE_VERBOSE("Ended ftp Server.");
2022-01-30 21:05:09 +01:00
2021-09-24 19:49:11 +02:00
if (iosuhaxMount) {
2019-11-24 14:20:08 +01:00
IOSUHAX_sdio_disc_interface.shutdown();
IOSUHAX_usb_disc_interface.shutdown();
unmount_fs("slccmpt01");
unmount_fs("storage_odd_tickets");
unmount_fs("storage_odd_updates");
unmount_fs("storage_odd_content");
unmount_fs("storage_odd_content2");
unmount_fs("storage_slc");
unmount_fs("storage_mlc");
unmount_fs("storage_usb");
IOSUHAX_FSA_Close(fsaFd);
IOSUHAX_Close();
}
2022-01-30 21:05:09 +01:00
DEBUG_FUNCTION_LINE("Unmount virtual paths");
2019-11-24 14:20:08 +01:00
UnmountVirtualPaths();
2022-01-30 21:05:09 +01:00
deinitLogging();
2019-11-24 14:20:08 +01:00
}