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);
            }
        }
        static void Main(string[] args)
        {
            if (!ParseArgs(args))
            {
                PrintUsage();
                return;
            }
            if (launch != null)
            {
                try {
                    Console.WriteLine("Launching \"{0}\" {1}", launch, launchArgs);
                    game = Process.Start(launch, launchArgs);
                } catch (Exception ex) {
                    Console.Error.WriteLine(ex.Message);
                    Console.Error.WriteLine("\nLaunch failed. Press enter to exit.");
                    Console.ReadLine();
                    return;
                }
            }
            Console.WriteLine("Maintaining {0} with map data from Guild Wars 2 "
                              + "using the Mumble Link API", fileName);
            if (hide)
            {
                ShowWindow(GetConsoleWindow(), ShowWindowCommands.Hide);
            }

            using (var ml = MumbleLink.Open()) {
                try {
                    MainLoop(fileName, ml);
                } catch (UnauthorizedAccessException ex) {
                    if (hide)
                    {
                        ShowWindow(GetConsoleWindow(), ShowWindowCommands.Normal);
                    }
                    Console.WriteLine(ex.Message);
                    if (!isAdministrator())
                    {
                        try {
                            elevate(args);
                            return;
                        } catch (Exception) { }
                    }
                    Console.WriteLine("\nPermission was denied. Press enter to exit.");
                    Console.ReadLine();
                    return;
                }
            }
        }