private void WriteConfiguration() { var data = BinaryStructure.WriteBinary(m_deviceConfiguration); try { HidConnector.Instance.WriteConfiguration(data, m_worker); } catch (TimeoutException) { InfoBox.Show("Unable to write configuration."); } }
private byte[] PrepairConfiguration(byte[] source, ArcticFoxConfiguration existedConfiguration = null) { var result = BinaryStructure.ReadBinary<ArcticFoxConfiguration>(m_encryption.Decode(source)); if (existedConfiguration == null) { SetSharedDeviceInfo(result.Info); } else { result.Info = existedConfiguration.Info; } return BinaryStructure.WriteBinary(result); }
private void SaveAsMenuItem_Click(object sender, EventArgs e) { if (m_deviceConfiguration == null) { return; } var isBinary = ModifierKeys.HasFlag(Keys.Control) && ModifierKeys.HasFlag(Keys.Alt); using (var sf = new SaveFileDialog { Filter = FileFilters.ArcticFoxConfigFilter }) { if (sf.ShowDialog() != DialogResult.OK) { return; } try { SaveWorkspace(); var cfgCopy = BinaryStructure.Copy(m_deviceConfiguration); { cfgCopy.Info.FirmwareVersion = 0; cfgCopy.Info.HardwareVersion = 0; cfgCopy.Info.MaxPower = 0; cfgCopy.Info.NumberOfBatteries = 0; cfgCopy.Info.ProductId = string.Empty; } byte[] bytes; if (isBinary) { bytes = BinaryStructure.WriteBinary(cfgCopy); } else { using (var ms = new MemoryStream()) { Serializer.Write(new SerializableConfiguration(BinaryStructure.WriteToDictionary(cfgCopy)), ms); bytes = ms.ToArray(); } } File.WriteAllBytes(sf.FileName, m_encryption.Encode(bytes)); } catch (Exception ex) { Trace.ErrorException("An error occurred during save ArcticFox configuration.", ex); } } }
private void DeviceConnected(bool isConnected) { try { if (HidConnector.Instance.IsDeviceConnected && m_configuration.SynchronizeTimeWhenDeviceIsConnected) { var now = DateTime.Now; var dateTime = new ArcticFoxConfiguration.DateTime { Year = (ushort)now.Year, Month = (byte)now.Month, Day = (byte)now.Day, Hour = (byte)now.Hour, Minute = (byte)now.Minute, Second = (byte)now.Second }; var data = BinaryStructure.WriteBinary(dateTime); HidConnector.Instance.SetDateTime(data); } if (HidConnector.Instance.IsDeviceConnected && m_configuration.OpenArcticFoxConfigurationWhenDeviceIsConnected) { UpdateUI(() => { var window = m_openedWindow; if (window == null) { ArcticFoxConfigurationButton.PerformClick(); } else if (window.GetType() == typeof(ArcticFoxConfigurationWindow)) { NativeMethods.SetForegroundWindow(m_openedWindow.Handle); } }); } } catch (Exception) { // Ignore } }