2025-03-01 03:49:40 +08:00
|
|
|
#include <csignal>
|
|
|
|
#include <iostream>
|
|
|
|
|
2024-12-12 22:43:24 +08:00
|
|
|
#include "server.h"
|
2024-12-16 14:21:39 +08:00
|
|
|
#include "version.h"
|
2025-04-16 22:19:49 +08:00
|
|
|
#include <of_path.h>
|
2024-12-14 19:49:44 +08:00
|
|
|
|
2025-01-22 09:35:38 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <io.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
|
|
|
|
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2025-04-16 22:19:49 +08:00
|
|
|
#if defined(GRAB_CRASH)
|
|
|
|
#ifdef USE_BOOST
|
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
namespace fs = boost::filesystem;
|
|
|
|
#else
|
|
|
|
#include <filesystem>
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
#endif
|
|
|
|
#include <crashelper.h>
|
|
|
|
#endif
|
2025-02-18 23:33:21 +08:00
|
|
|
|
2024-12-16 09:40:57 +08:00
|
|
|
int main(int argc, char* argv[])
|
2024-12-11 08:44:14 +08:00
|
|
|
{
|
2025-04-16 22:19:49 +08:00
|
|
|
#if defined(GRAB_CRASH)
|
|
|
|
auto config_dir = COfPath::get_config_dir("transm", true);
|
|
|
|
auto err = fs::path(config_dir).append("errs").string();
|
|
|
|
backward::SetDumpFileSavePath(err);
|
|
|
|
backward::SetDumpLogSavePath(err);
|
|
|
|
CRASHELPER_MARK_ENTRY();
|
|
|
|
#endif
|
2025-03-01 03:49:40 +08:00
|
|
|
|
2025-01-22 09:35:38 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
DWORD mode;
|
|
|
|
GetConsoleMode(hConsole, &mode);
|
|
|
|
mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
|
|
|
|
SetConsoleMode(hConsole, mode);
|
|
|
|
#endif
|
|
|
|
|
2025-03-01 03:49:40 +08:00
|
|
|
std::shared_ptr<int> deleter(new int(), [](int* p) {
|
|
|
|
fc_recovery_color();
|
|
|
|
delete p;
|
|
|
|
});
|
|
|
|
|
|
|
|
TLOGI("Build At {} {} under {} on {}", __DATE__, __TIME__, VERSION_GIT_COMMIT, VERSION_GIT_BRANCH);
|
2024-12-16 09:40:57 +08:00
|
|
|
int port = 9898;
|
|
|
|
if (argc < 2) {
|
2025-03-01 03:49:40 +08:00
|
|
|
TLOGI("Use Default Port:{}", port);
|
2024-12-16 14:21:39 +08:00
|
|
|
} else {
|
2024-12-16 09:40:57 +08:00
|
|
|
std::string str_port(argv[1]);
|
|
|
|
port = std::stoi(str_port);
|
2025-03-01 03:49:40 +08:00
|
|
|
TLOGI("Use Port:{}", port);
|
2024-12-16 09:40:57 +08:00
|
|
|
}
|
2024-12-12 23:11:55 +08:00
|
|
|
asio::io_context io_context;
|
2025-04-12 22:51:06 +08:00
|
|
|
TransmServer server(io_context);
|
2024-12-16 09:40:57 +08:00
|
|
|
if (!server.start(port)) {
|
2024-12-12 23:11:55 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
io_context.run();
|
2024-12-11 08:44:14 +08:00
|
|
|
return 0;
|
|
|
|
}
|