private void OnMachineInfoRequest(INetworkConnection con, Packet packet) { bool cpu, gpu, drives, mainboard, os, ram; cpu = gpu = drives = mainboard = os = ram = false; PacketGenericMessage m = packet as PacketGenericMessage; m.ReplyPacket = CreateStandardReply(packet, ReplyType.OK, ""); if (m.Parms.GetBoolProperty("cpu").GetValueOrDefault(false)) { cpu = true; CPUInfo ci = MachineInfo.ReadCPUInfo(); m.ReplyPacket.Parms.SetProperty("cpu", ci.ToString()); } if (m.Parms.GetBoolProperty("gpu").GetValueOrDefault(false)) { gpu = true; VideoCardInfo gi = MachineInfo.ReadGPUInfo(); m.ReplyPacket.Parms.SetProperty("gpu", gi.ToString()); } if (m.Parms.GetBoolProperty("drives").GetValueOrDefault(false)) { drives = true; PatcherLib.DriveInfo di = MachineInfo.ReadLogicalDiskInfo(); m.ReplyPacket.Parms.SetProperty("drives", di.ToString()); } if (m.Parms.GetBoolProperty("mainboard").GetValueOrDefault(false)) { mainboard = true; MotherboardInfo mi = MachineInfo.ReadMotherboardInfo(); m.ReplyPacket.Parms.SetProperty("mainboard", mi.ToString()); } if (m.Parms.GetBoolProperty("os").GetValueOrDefault(false)) { os = true; OperatingSystemInfo osr = MachineInfo.ReadOperatingSystemInfo(); m.ReplyPacket.Parms.SetProperty("os", osr.ToString()); } if (m.Parms.GetBoolProperty("ram").GetValueOrDefault(false)) { ram = true; RamInfo ri = MachineInfo.ReadRAMInfo(); m.ReplyPacket.Parms.SetProperty("ram", ri.ToString()); } if (MachineInfoRequestArrived != null) { MachineInfoRequestArrived(cpu, gpu, mainboard, drives, os, ram); } }
public static DriveInfo ReadLogicalDiskInfo() { DriveInfo drives = new DriveInfo(); try { ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT DeviceID, Description, FileSystem, FreeSpace, Size FROM Win32_LogicalDisk"); Dictionary<string, string> data = new Dictionary<string, string>(); foreach (ManagementObject queryObj in searcher.Get()) { DiskInfo di = new DiskInfo(); if (queryObj["DeviceID"] != null) { di.DeviceID = queryObj["DeviceID"].ToString(); } if (queryObj["Description"] != null) { di.DriveType = queryObj["Description"].ToString(); } if (queryObj["FileSystem"] != null) { di.FileSystem = queryObj["FileSystem"].ToString(); } if (queryObj["FreeSpace"] != null) { di.FreeSpace = Util.ConvertBytesToMegabytes(UInt64.Parse(queryObj["FreeSpace"].ToString())); } if (queryObj["Size"] != null) { di.Size = Util.ConvertBytesToMegabytes(UInt64.Parse(queryObj["Size"].ToString())); } drives.Drives.Add(di); } } catch (Exception e) { } finally { } return drives; }