private static void MainLoop(string fileName, MumbleLink ml) { while (!ShouldExit()) { MumbleLink.LinkedMem state; MumbleLink.GW2Context context; ml.Read(out state, out context); string newContents = genContents(state, context); if (newContents != oldContents) { File.WriteAllText(fileName, newContents); DayNightCycle.TimeOfDay tod = DayNightCycle.Classify(); Console.WriteLine("{0}: Updated file: GW2MapId = {1}, " + "GW2TOD = {2}, GW2Active = {3}.", DateTime.Now, context.mapId, (int)tod, active ? 1 : 0); oldContents = newContents; Thread.Sleep(WriteDelayMs); } Thread.Sleep(PollIntervalMs); } }
private static string genContents( MumbleLink.LinkedMem state, MumbleLink.GW2Context context) { currentTick++; if (lastUiTickValue != state.uiTick) { lastChangedTick = currentTick; } lastUiTickValue = state.uiTick; active = currentTick - lastChangedTick < ActivityTimeoutTicks; return(String.Format("#define GW2MapId {0}\n" + "#define GW2TOD {1}\n" + "#define GW2Active {2}\n" + "#define TimeZone {3}\n", context.mapId, (int)DayNightCycle.Classify(), active ? 1 : 0, (int)TimeZone.CurrentTimeZone.GetUtcOffset( DateTime.Now).TotalSeconds)); }