DEV9: Use UTF8 strings on windows for AdapterEntry

This commit is contained in:
TheLastRar 2022-02-06 15:20:38 +00:00 committed by lightningterror
parent 8aaeb1c7ce
commit 30bc9b04c5
4 changed files with 21 additions and 22 deletions

View File

@ -27,6 +27,8 @@
#include <wx/spinctrl.h>
#include <wx/gbsizer.h>
#include "common/StringUtil.h"
#include "Config.h"
#include "DEV9.h"
#include "pcap_io.h"
@ -319,8 +321,9 @@ public:
current = config.Eth;
for (size_t i = 0; i < list.size(); i++)
{
options.Add(list[i].name);
if (list[i].name == current)
wxString wxAdapterName = StringUtil::UTF8StringToWxString(list[i].name);
options.Add(wxAdapterName);
if (wxAdapterName == current)
selection = i + 1;
}
}

View File

@ -16,6 +16,7 @@
#include "PrecompiledHeader.h"
#include "common/RedtapeWindows.h"
#include "common/StringUtil.h"
#include <stdio.h>
#include <windows.h>
@ -186,9 +187,9 @@ std::vector<AdapterEntry> TAPAdapter::GetAdapters()
if (IsTAPDevice(enum_name))
{
AdapterEntry t;
t.type = NetApi::TAP;
t.name = std::wstring(name_data);
t.guid = std::wstring(enum_name);
t.type = Pcsx2Config::DEV9Options::NetApi::TAP;
t.name = StringUtil::WideStringToUTF8String(std::wstring(name_data));
t.guid = StringUtil::WideStringToUTF8String(std::wstring(enum_name));
tap_nic.push_back(t);
}
}

View File

@ -69,13 +69,9 @@ enum struct NetApi : int
struct AdapterEntry
{
NetApi type;
#ifdef _WIN32
std::wstring name;
std::wstring guid;
#else
//UTF8
std::string name;
std::string guid;
#endif
};
class NetAdapter

View File

@ -22,6 +22,7 @@
#include <iphlpapi.h>
//#include <ws2tcpip.h>
//#include <comdef.h>
#include "common/StringUtil.h"
#elif defined(__linux__)
#include <sys/ioctl.h>
#include <net/if.h>
@ -502,29 +503,27 @@ std::vector<AdapterEntry> PCAPAdapter::GetAdapters()
entry.type = NetApi::PCAP_Switched;
#ifdef _WIN32
//guid
wchar_t wEth[sizeof(config.Eth)] = {0};
mbstowcs(wEth, d->name, sizeof(config.Eth) - 1);
entry.guid = std::wstring(wEth);
entry.guid = std::string(d->name);
IP_ADAPTER_ADDRESSES adapterInfo;
std::unique_ptr<IP_ADAPTER_ADDRESSES[]> buffer;
if (PCAPGetWin32Adapter(d->name, &adapterInfo, &buffer))
entry.name = std::wstring(adapterInfo.FriendlyName);
if (PCAPGetWin32Adapter(entry.guid, &adapterInfo, &buffer))
entry.name = StringUtil::WideStringToUTF8String(std::wstring(adapterInfo.FriendlyName));
else
{
//have to use description
//NPCAP 1.10 is using an version of pcap that dosn't
//allow us to set it to use UTF8
//see https://github.com/nmap/npcap/issues/276
//But use MultiByteToWideChar so we can later switch to UTF8
int len_desc = strlen(d->description) + 1;
int len_buf = MultiByteToWideChar(CP_ACP, 0, d->description, len_desc, nullptr, 0);
//We have to convert from ANSI to wstring, to then convert to UTF8
const int len_desc = strlen(d->description) + 1;
const int len_buf = MultiByteToWideChar(CP_ACP, 0, d->description, len_desc, nullptr, 0);
wchar_t* buf = new wchar_t[len_buf];
MultiByteToWideChar(CP_ACP, 0, d->description, len_desc, buf, len_buf);
entry.name = std::wstring(buf);
delete[] buf;
std::unique_ptr<wchar_t[]> buf = std::make_unique<wchar_t[]>(len_buf);
MultiByteToWideChar(CP_ACP, 0, d->description, len_desc, buf.get(), len_buf);
entry.name = StringUtil::WideStringToUTF8String(std::wstring(buf.get()));
}
#else
entry.name = std::string(d->name);