private string GetDriversFilePath(WindowsDriversFile windowsDriversFile) { string name; switch (windowsDriversFile) { case WindowsDriversFile.Hosts: name = "hosts"; break; case WindowsDriversFile.Networks: name = "networks"; break; case WindowsDriversFile.Protocol: name = "protocol"; break; case WindowsDriversFile.Services: name = "services"; break; default: throw new ArgumentOutOfRangeException(nameof(windowsDriversFile), windowsDriversFile, null); } return(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "drivers\\etc\\" + name)); }
public void GetDriversFile(WindowsDriversFile windowsDriversFile) { ConnectionInfo.SendCommand(this, new[] { (byte)WindowsDriversCommunication.GetDriversFile, (byte)windowsDriversFile }); LogService.Send(string.Format((string)Application.Current.Resources["GetDriverConfigurationFile"], windowsDriversFile)); }
private string ReadDriversFile(WindowsDriversFile windowsDriversFile) { var file = new FileInfo(GetDriversFilePath(windowsDriversFile)); if (!file.Exists) { return($"# FILE NOT FOUND: {file.FullName}\r\n#Saving will result in creating the file"); } using (var fileStream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (var streamReader = new StreamReader(fileStream)) return(streamReader.ReadToEnd()); }
private void SendDriverFile(WindowsDriversFile windowsDriversFile, IConnectionInfo connectionInfo) { var content = ReadDriversFile(windowsDriversFile); var contentData = Encoding.UTF8.GetBytes(content); var response = new byte[contentData.Length + 2]; response[0] = (byte)WindowsDriversCommunication.ResponseDriversFileContent; response[1] = (byte)windowsDriversFile; Buffer.BlockCopy(contentData, 0, response, 2, contentData.Length); connectionInfo.CommandResponse(this, response); }
public void EditDriversFile(WindowsDriversFile windowsDriversFile, string content) { var contentData = Encoding.UTF8.GetBytes(content); var packet = new byte[contentData.Length + 2]; packet[0] = (byte)WindowsDriversCommunication.ChangeDriversFile; packet[1] = (byte)windowsDriversFile; Buffer.BlockCopy(contentData, 0, packet, 2, contentData.Length); ConnectionInfo.SendCommand(this, packet); LogService.Send(string.Format((string)Application.Current.Resources["SaveConfigurationFile"], windowsDriversFile)); }
public DriversFileContentReceivedEventArgs(string content, WindowsDriversFile windowsDriversFile) { Content = content; WindowsDriversFile = windowsDriversFile; }
public DriverConfigurationViewModel(WindowsDriversFile windowsDriversFile) { WindowsDriversFile = windowsDriversFile; }