private static AppSettings Load() { try { throw new Exception(); byte[] settingsSize = new byte[4]; BatteryRAM.Read(0, settingsSize, 0, 4); int size = settingsSize[0] * 256 + settingsSize[1]; if (size == 0 || size > 2044) { throw new Exception(); } int pages = size / 4 + (size % 4 == 0 ? 0 : 1); byte[] aux = new byte[pages * 4]; BatteryRAM.Read(4, aux, 0, pages * 4); byte[] settings = new byte[size]; Array.Copy(aux, settings, size); return((AppSettings)Reflection.Deserialize(settings, typeof(AppSettings))); } catch { return(new AppSettings()); } }
public const UInt32 RtcValidMagic = 0x6d605ea1; // This is set in BatteryRam when the RTC is valid. static WallClock() { // Establish if the RTC is valid or not based on a magic value set in battery RAM. var buf = new byte[4]; BatteryRAM.Read(0, buf, 0, buf.Length); var batteryRamClockVal = Utility.ExtractValueFromArray(buf, 0, 4); RtcIsValid = batteryRamClockVal == RtcValidMagic; if (RtcIsValid) { Utility.SetLocalTime(RealTimeClock.GetTime()); } else { Utility.SetLocalTime(new DateTime(2011, 01, 01, 0, 0, 0)); // Fake the start of 2011. } }