mirror of
https://github.com/kanjitalk755/macemu.git
synced 2025-01-26 01:31:09 +00:00
Avoid the use of min(). Add helpers to access the network control panel
registry -- aka get pretty printed names from GUID ethernet devices.
This commit is contained in:
parent
2d5c088601
commit
9232fbe4df
@ -24,6 +24,12 @@
|
||||
#include "util_windows.h"
|
||||
#include "main.h"
|
||||
|
||||
#include <list>
|
||||
using std::list;
|
||||
|
||||
#include <string>
|
||||
using std::string;
|
||||
|
||||
BOOL exists( const char *path )
|
||||
{
|
||||
HFILE h;
|
||||
@ -53,7 +59,10 @@ BOOL create_file( const char *path, DWORD size )
|
||||
if(SetEndOfFile(h)) {
|
||||
ok = true;
|
||||
if(SetFilePointer( h, 0, NULL, FILE_BEGIN) != 0xFFFFFFFF) {
|
||||
DWORD written, zeroed_size = min(1024*1024,size);
|
||||
DWORD written;
|
||||
DWORD zeroed_size = size;
|
||||
if (zeroed_size > 1024*1024)
|
||||
zeroed_size = 1024*1024;
|
||||
char *b = (char *)malloc(zeroed_size);
|
||||
if(b) {
|
||||
memset( b, 0, zeroed_size );
|
||||
@ -135,3 +144,119 @@ bool check_drivers(void)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Network control panel helpers
|
||||
*/
|
||||
|
||||
struct panel_reg {
|
||||
string name;
|
||||
string guid;
|
||||
};
|
||||
|
||||
static list<panel_reg> network_registry;
|
||||
typedef list<panel_reg>::const_iterator network_registry_iterator;
|
||||
|
||||
#define NETWORK_CONNECTIONS_KEY \
|
||||
"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}"
|
||||
|
||||
static void get_network_registry(void)
|
||||
{
|
||||
LONG status;
|
||||
HKEY network_connections_key;
|
||||
DWORD len;
|
||||
int i = 0;
|
||||
|
||||
if (network_registry.size() > 0)
|
||||
return;
|
||||
|
||||
status = RegOpenKeyEx(
|
||||
HKEY_LOCAL_MACHINE,
|
||||
NETWORK_CONNECTIONS_KEY,
|
||||
0,
|
||||
KEY_READ,
|
||||
&network_connections_key);
|
||||
|
||||
if (status != ERROR_SUCCESS)
|
||||
return;
|
||||
|
||||
while (true) {
|
||||
char enum_name[256];
|
||||
char connection_string[256];
|
||||
HKEY connection_key;
|
||||
char name_data[256];
|
||||
DWORD name_type;
|
||||
const char name_string[] = "Name";
|
||||
|
||||
len = sizeof (enum_name);
|
||||
status = RegEnumKeyEx(
|
||||
network_connections_key,
|
||||
i,
|
||||
enum_name,
|
||||
&len,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
if (status != ERROR_SUCCESS)
|
||||
break;
|
||||
|
||||
snprintf (connection_string, sizeof(connection_string),
|
||||
"%s\\%s\\Connection",
|
||||
NETWORK_CONNECTIONS_KEY, enum_name);
|
||||
|
||||
status = RegOpenKeyEx(
|
||||
HKEY_LOCAL_MACHINE,
|
||||
connection_string,
|
||||
0,
|
||||
KEY_READ,
|
||||
&connection_key);
|
||||
|
||||
if (status == ERROR_SUCCESS) {
|
||||
len = sizeof (name_data);
|
||||
status = RegQueryValueEx(
|
||||
connection_key,
|
||||
name_string,
|
||||
NULL,
|
||||
&name_type,
|
||||
(BYTE *)name_data,
|
||||
&len);
|
||||
|
||||
if (status == ERROR_SUCCESS && name_type == REG_SZ) {
|
||||
panel_reg pr;
|
||||
pr.name = name_data;
|
||||
pr.guid = enum_name;
|
||||
network_registry.push_back(pr);
|
||||
}
|
||||
RegCloseKey (connection_key);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
RegCloseKey (network_connections_key);
|
||||
}
|
||||
|
||||
const char *ether_name_to_guid(const char *name)
|
||||
{
|
||||
get_network_registry();
|
||||
|
||||
for (network_registry_iterator it = network_registry.begin(); it != network_registry.end(); it++) {
|
||||
if (strcmp((*it).name.c_str(), name) == 0)
|
||||
return (*it).guid.c_str();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *ether_guid_to_name(const char *guid)
|
||||
{
|
||||
get_network_registry();
|
||||
|
||||
for (network_registry_iterator it = network_registry.begin(); it != network_registry.end(); it++) {
|
||||
if (strcmp((*it).guid.c_str(), guid) == 0)
|
||||
return (*it).name.c_str();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -43,4 +43,8 @@ class mutex_t {
|
||||
void unlock() { LeaveCriticalSection(&cs); }
|
||||
};
|
||||
|
||||
// Network control panel helpers
|
||||
extern const char *ether_name_to_guid(const char *name);
|
||||
extern const char *ether_guid_to_name(const char *guid);
|
||||
|
||||
#endif // _UTIL_WINDOWS_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user