diff --git a/icon/捕获.PNG b/icon/捕获.PNG new file mode 100644 index 0000000..139b293 Binary files /dev/null and b/icon/捕获.PNG differ diff --git a/icon/捕获.ico b/icon/捕获.ico new file mode 100644 index 0000000..722b2f4 Binary files /dev/null and b/icon/捕获.ico differ diff --git a/src/common/platform.cpp b/src/common/platform.cpp new file mode 100644 index 0000000..26a4402 --- /dev/null +++ b/src/common/platform.cpp @@ -0,0 +1,101 @@ +#include "platform.h" + +#include "log.h" + +#ifdef _WIN32 +#include +#include +#elif __APPLE__ +#include +#include +#include +#include +#include +#elif __linux__ +#include +#include +#include +#include +#include +#endif + +std::string GetMac() { + char mac_addr[16]; + int len = 0; +#ifdef _WIN32 + IP_ADAPTER_INFO adapterInfo[16]; + DWORD bufferSize = sizeof(adapterInfo); + + DWORD result = GetAdaptersInfo(adapterInfo, &bufferSize); + if (result == ERROR_SUCCESS) { + PIP_ADAPTER_INFO adapter = adapterInfo; + while (adapter) { + for (UINT i = 0; i < adapter->AddressLength; i++) { + len += sprintf(mac_addr + len, "%.2X", adapter->Address[i]); + } + break; + } + } +#elif __APPLE__ + std::string if_name = "en0"; + + struct ifaddrs *addrs; + struct ifaddrs *cursor; + const struct sockaddr_dl *dlAddr; + + if (!getifaddrs(&addrs)) { + cursor = addrs; + while (cursor != 0) { + const struct sockaddr_dl *socAddr = + (const struct sockaddr_dl *)cursor->ifa_addr; + if ((cursor->ifa_addr->sa_family == AF_LINK) && + (socAddr->sdl_type == IFT_ETHER) && + strcmp(if_name.c_str(), cursor->ifa_name) == 0) { + dlAddr = (const struct sockaddr_dl *)cursor->ifa_addr; + const unsigned char *base = + (const unsigned char *)&dlAddr->sdl_data[dlAddr->sdl_nlen]; + for (int i = 0; i < dlAddr->sdl_alen; i++) { + len += sprintf(mac_addr + len, "%.2X", base[i]); + } + } + cursor = cursor->ifa_next; + } + freeifaddrs(addrs); + } +#elif __linux__ + int sock = socket(AF_INET, SOCK_DGRAM, 0); + if (sock < 0) { + return ""; + } + struct ifreq ifr; + struct ifconf ifc; + char buf[1024]; + ifc.ifc_len = sizeof(buf); + ifc.ifc_buf = buf; + if (ioctl(sock, SIOCGIFCONF, &ifc) < 0) { + close(sock); + return ""; + } + struct ifreq *it = ifc.ifc_req; + const struct ifreq *const end = it + (ifc.ifc_len / sizeof(struct ifreq)); + for (; it != end; ++it) { + std::strcpy(ifr.ifr_name, it->ifr_name); + if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) { + continue; + } + if (ifr.ifr_flags & IFF_LOOPBACK) { + continue; + } + if (ioctl(sock, SIOCGIFHWADDR, &ifr) < 0) { + continue; + } + std::string mac_address; + for (int i = 0; i < 6; ++i) { + len += sprintf(mac_addr + len, "%.2X", ifr.ifr_hwaddr.sa_data[i] & 0xff); + } + break; + } + close(sock); +#endif + return mac_addr; +} \ No newline at end of file diff --git a/src/common/platform.h b/src/common/platform.h new file mode 100644 index 0000000..f9f15ae --- /dev/null +++ b/src/common/platform.h @@ -0,0 +1,14 @@ +/* + * @Author: DI JUNKUN + * @Date: 2023-12-18 + * Copyright (c) 2023 by DI JUNKUN, All Rights Reserved. + */ + +#ifndef _PLATFORM_H_ +#define _PLATFORM_H_ + +#include + +std::string GetMac(); + +#endif \ No newline at end of file diff --git a/src/gui/main.cpp b/src/gui/main.cpp index 4ca1297..c7e9657 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -1,22 +1,11 @@ #include #include #ifdef _WIN32 -// #pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"") +#ifdef REMOTE_DESK_DEBUG #pragma comment(linker, "/subsystem:\"console\"") -#include -#include -#elif __APPLE__ -#include -#include -#include -#include -#include -#elif __linux__ -#include -#include -#include -#include -#include +#else +#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"") +#endif #endif #include @@ -27,6 +16,8 @@ #include #include +#include "platform.h" + extern "C" { #include #include @@ -478,87 +469,6 @@ int initResampler() { } } -std::string GetMac() { - char mac_addr[16]; - int len = 0; -#ifdef _WIN32 - IP_ADAPTER_INFO adapterInfo[16]; - DWORD bufferSize = sizeof(adapterInfo); - - DWORD result = GetAdaptersInfo(adapterInfo, &bufferSize); - if (result == ERROR_SUCCESS) { - PIP_ADAPTER_INFO adapter = adapterInfo; - while (adapter) { - for (UINT i = 0; i < adapter->AddressLength; i++) { - len += sprintf(mac_addr + len, "%.2X", adapter->Address[i]); - } - break; - } - } -#elif __APPLE__ - std::string if_name = "en0"; - - struct ifaddrs *addrs; - struct ifaddrs *cursor; - const struct sockaddr_dl *dlAddr; - - if (!getifaddrs(&addrs)) { - cursor = addrs; - while (cursor != 0) { - const struct sockaddr_dl *socAddr = - (const struct sockaddr_dl *)cursor->ifa_addr; - if ((cursor->ifa_addr->sa_family == AF_LINK) && - (socAddr->sdl_type == IFT_ETHER) && - strcmp(if_name.c_str(), cursor->ifa_name) == 0) { - dlAddr = (const struct sockaddr_dl *)cursor->ifa_addr; - const unsigned char *base = - (const unsigned char *)&dlAddr->sdl_data[dlAddr->sdl_nlen]; - for (int i = 0; i < dlAddr->sdl_alen; i++) { - len += sprintf(mac_addr + len, "%.2X", base[i]); - } - } - cursor = cursor->ifa_next; - } - freeifaddrs(addrs); - } -#elif __linux__ - int sock = socket(AF_INET, SOCK_DGRAM, 0); - if (sock < 0) { - return ""; - } - struct ifreq ifr; - struct ifconf ifc; - char buf[1024]; - ifc.ifc_len = sizeof(buf); - ifc.ifc_buf = buf; - if (ioctl(sock, SIOCGIFCONF, &ifc) < 0) { - close(sock); - return ""; - } - struct ifreq *it = ifc.ifc_req; - const struct ifreq *const end = it + (ifc.ifc_len / sizeof(struct ifreq)); - for (; it != end; ++it) { - std::strcpy(ifr.ifr_name, it->ifr_name); - if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) { - continue; - } - if (ifr.ifr_flags & IFF_LOOPBACK) { - continue; - } - if (ioctl(sock, SIOCGIFHWADDR, &ifr) < 0) { - continue; - } - std::string mac_address; - for (int i = 0; i < 6; ++i) { - len += sprintf(mac_addr + len, "%.2X", ifr.ifr_hwaddr.sa_data[i] & 0xff); - } - break; - } - close(sock); -#endif - return mac_addr; -} - int main() { LOG_INFO("Remote desk"); @@ -713,6 +623,7 @@ int main() { { while (SignalStatus::SignalConnected != server_signal_status && !done) { + std::this_thread::sleep_for(std::chrono::seconds(1)); } if (done) { diff --git a/xmake.lua b/xmake.lua index 3ef384f..708e40a 100644 --- a/xmake.lua +++ b/xmake.lua @@ -5,8 +5,8 @@ set_license("LGPL-3.0") add_rules("mode.release", "mode.debug") set_languages("c++17") -set_policy("build.warning", true) -set_warnings("all", "extra") +-- set_policy("build.warning", true) +-- set_warnings("all", "extra") add_defines("UNICODE") if is_mode("debug") then @@ -53,6 +53,12 @@ target("log") add_headerfiles("src/log/log.h") add_includedirs("src/log", {public = true}) +target("common") + set_kind("object") + add_deps("log") + add_files("src/common/*.cpp") + add_includedirs("src/common", {public = true}) + target("screen_capturer") set_kind("object") add_deps("log") @@ -85,7 +91,7 @@ target("device_controller") target("remote_desk") set_kind("binary") - add_deps("log", "screen_capturer", "device_controller", "projectx") + add_deps("log", "common", "screen_capturer", "device_controller", "projectx") add_files("src/gui/main.cpp") -- after_install(function (target)