ftpiiu_plugin/src/main.cpp

96 lines
3.1 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>
2022-08-27 13:35:12 +02:00
#include <mocha/mocha.h>
2019-11-24 14:20:08 +01:00
#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;
2021-09-24 19:49:11 +02:00
BackgroundThread *thread = nullptr;
2019-11-24 14:20:08 +01:00
2022-08-27 13:35:12 +02:00
MochaUtilsStatus MountWrapper(const char *mount, const char *dev, const char *mountTo) {
auto res = Mocha_MountFS(mount, dev, mountTo);
if (res == MOCHA_RESULT_ALREADY_EXISTS) {
res = Mocha_MountFS(mount, nullptr, mountTo);
}
if (res == MOCHA_RESULT_SUCCESS) {
std::string mountPath = std::string(mount) + ":/";
VirtualMountDevice(mountPath.c_str());
DEBUG_FUNCTION_LINE_VERBOSE("Mounted %s", mountPath.c_str());
} else {
DEBUG_FUNCTION_LINE_ERR("Failed to mount %s: %s [%d]", mount, Mocha_GetStatusStr(res), res);
}
return res;
}
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);
2022-08-27 13:35:12 +02:00
MochaUtilsStatus res;
if ((res = Mocha_InitLibrary()) == MOCHA_RESULT_SUCCESS) {
MountWrapper("slccmpt01", "/dev/slccmpt01", "/vol/storage_slccmpt01");
MountWrapper("storage_odd_tickets", nullptr, "/vol/storage_odd01");
MountWrapper("storage_odd_updates", nullptr, "/vol/storage_odd02");
MountWrapper("storage_odd_content", nullptr, "/vol/storage_odd03");
MountWrapper("storage_odd_content2", nullptr, "/vol/storage_odd04");
MountWrapper("storage_slc", "/dev/slc01", "/vol/storage_slc01");
Mocha_MountFS("storage_mlc", nullptr, "/vol/storage_mlc01");
Mocha_MountFS("storage_usb", nullptr, "/vol/storage_usb01");
2019-11-24 14:20:08 +01:00
} else {
2022-08-27 13:35:12 +02:00
DEBUG_FUNCTION_LINE_ERR("Failed to init libmocha: %s [%d]", Mocha_GetStatusStr(res), res);
2019-11-24 14:20:08 +01:00
}
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
2022-08-27 13:35:12 +02:00
Mocha_UnmountFS("slccmpt01");
Mocha_UnmountFS("storage_odd_tickets");
Mocha_UnmountFS("storage_odd_updates");
Mocha_UnmountFS("storage_odd_content");
Mocha_UnmountFS("storage_odd_content2");
Mocha_UnmountFS("storage_slc");
Mocha_UnmountFS("storage_mlc");
Mocha_UnmountFS("storage_usb");
2019-11-24 14:20:08 +01:00
2022-09-04 09:40:09 +02:00
Mocha_DeInitLibrary();
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
}