/// <summary> /// Check to see if the planetary hour (or lunar phase, if applicable) has changed. If so, notify the user /// </summary> private void phTick(object sender, System.EventArgs e) { if (pHours.CurrentHour() == (PlanetaryHours.Planet)(-1)) // Planetary day changed; recalculate hours { pHours = new PlanetaryHours(conf); // Just in case new hour is same as last recorded hour, but the computer had been suspended currentHour = (PlanetaryHours.Planet)(-2); // -2 because pHours.CurrentHour() could be -1 upon error. } if (currentHour != pHours.CurrentHour()) { currentHour = pHours.CurrentHour(); NotifyUser(); updateTray(); if (currentHour == (PlanetaryHours.Planet)(-1)) { ErrorMessage("An internal error has occured", new Exception("pHours.CurrentHour returns -1 twice - unable to calculate planetary hours"), conf); } } if (conf.Caption == Config.CaptionType.LunarPhase && currentPhase != localPhases.CurrentPhase(DateTime.UtcNow)) { localPhases = new LunarPhase(DateTime.UtcNow); currentPhase = localPhases.CurrentPhase(DateTime.UtcNow); updateTray(); } }
/// <summary> /// This is called after the user clicks "Apply" or "OK" in the Properties form, in case the locality has changed. /// </summary> public void RefreshHours() { pHours = new PlanetaryHours(conf); if (pHours.CurrentHour() == (PlanetaryHours.Planet)(-1)) { ErrorMessage("Unable to determine the current planetary hour.", new Exception("pHours.GetHour returns null at UTC" + DateTime.UtcNow.ToString()), conf); } initContextMenu(); if (conf.Caption == Config.CaptionType.LunarPhase) { localPhases = new LunarPhase(DateTime.UtcNow); currentPhase = localPhases.CurrentPhase(DateTime.UtcNow); } updateTray(); if (currentHour != pHours.CurrentHour()) { currentHour = pHours.CurrentHour(); NotifyUser(); } phClock.Interval = conf.Interval(); }
public ChronosXPCore(System.Windows.Application entry) { Entry = entry; Application.ApplicationExit += new System.EventHandler(appExit); Application.Idle += new System.EventHandler(appIdle); conf = new Config(this); if (!conf.LoadOK) { Shutdown(); return; } string[] args = Environment.GetCommandLineArgs(); bool showproperties = false; // The command-line arguments should only be used for testing, or internally foreach (string arg in args) { switch (arg.ToLower()) { case "/english": conf.Language = Config.CultureEN; break; case "/nederlands": case "/dutch": conf.Language = Config.CultureNL; break; case "/español": case "/espanol": case "/spanish": conf.Language = Config.CultureES; break; case "/italiano": case "/italian": conf.Language = Config.CultureIT; break; case "/français": case "/francais": case "/french": conf.Language = Config.CultureFR; break; case "/português": case "/portugues": case "/portuguese": conf.Language = Config.CulturePT; break; case "/hungarian": case "/magyar": conf.Language = Config.CultureHU; break; case "/greek": conf.Language = Config.CultureGR; break; case "/hebrew": conf.Language = Config.CultureHE; break; case "/standalone": conf.RunFromTrayNow = false; break; case "/tray": conf.RunFromTrayNow = true; break; case "/properties": showproperties = true; break; case "/nogradient": conf.UseGradient = false; break; case "/gradient": conf.UseGradient = true; break; case "/nocheckupdate": checkUpdate = false; break; case "/fastcheckupdate": fastCheckUpdate = true; break; #if BETA case "/debugnotify": debugnotify = true; break; // This is to create screen-shots (for the web page) of a BETA, but make it look like a release. Use with // /currentculture=(culture), to set Thread.CurrentCulture (which prints the VisualMonthCalendar in that language) // /photogenic implies /debugnotify case "/photogenic": Photogenic = true; debugnotify = true; break; #endif default: if (arg.ToLower().StartsWith("/zenith=")) { string[] zz = arg.Split(new char[] { '=' }, 2); try { conf.ZenithDistance = double.Parse(zz[1]); } catch { MessageBox.Show(conf.GetString("Core.InvalidArgument") + ": " + arg, "ChronosXP", MessageBoxButtons.OK, MessageBoxIcon.Error); Shutdown(); return; } } else if (arg.ToLower().StartsWith("/iconset=")) { string[] zz = arg.Split(new char[] { '=' }, 2); if (zz[1].ToLower().Equals("silver") || zz[1].ToLower().Equals("black") || zz[1].ToLower().Equals("multi")) { conf.Fx.IconSet = zz[1]; } else { MessageBox.Show(conf.GetString("Core.InvalidArgument") + ": " + arg, "ChronosXP", MessageBoxButtons.OK, MessageBoxIcon.Error); Shutdown(); return; } } else if (arg.ToLower().StartsWith("/currentculture=")) { string[] zz = arg.Split(new char[] { '=' }, 2); try { conf.CurrentCulture = new CultureInfo(zz[1]); Application.CurrentCulture = conf.CurrentCulture; Thread.CurrentThread.CurrentUICulture = conf.CurrentCulture; } catch { MessageBox.Show("Unsupported culture: " + zz[1], "ChronosXP", MessageBoxButtons.OK, MessageBoxIcon.Error); Shutdown(); return; } } else { continue; //MessageBox.Show (conf.GetString ("Core.InvalidArgument") + ": " + arg, "ChronosXP", // MessageBoxButtons.OK, MessageBoxIcon.Error); //Application.Exit(); //return; } break; } } // tray mode? initialize the NotifyIcon, ContextMenu and Timer, and calculate planetary hours. if (conf.RunFromTrayNow) { initTray(); pHours = new PlanetaryHours(conf); currentHour = pHours.CurrentHour(); updateTray(); if (conf.Caption == Config.CaptionType.LunarPhase) { localPhases = new LunarPhase(DateTime.UtcNow); currentPhase = localPhases.CurrentPhase(DateTime.UtcNow); } // This timer checks to see if the planetary hour has changed; if so, notify the user (if applicable) and change the NotifyIcon // and it's ToolTip text. phClock = new System.Windows.Forms.Timer(); phClock.Interval = conf.Interval(); phClock.Tick += new System.EventHandler(phTick); phClock.Start(); // This timer periodically updates the system tray icon; this is to ensure that the ChronosXP is not hidden with the // inactive icons, and also because of a bug that makes the icon distorted after doing a <Windows key>+L trayClock = new System.Windows.Forms.Timer(); trayClock.Interval = 55555; trayClock.Tick += new System.EventHandler(trayTick); trayClock.Start(); // When in tray mode, bind Alt+F11 to open the Planetary Hours Calendar (see this.WndProc) PInvoke.RegisterHotKey(Handle, 101, PInvoke.MOD_ALT, PInvoke.VK_F11); } #if WINDOWS if (conf.Run == 1) // First time ChronosXP is run? Prompt user to configure locality { DialogResult res = MessageBox.Show(conf.GetString("Core.WelcomeText"), conf.GetString("Core.WelcomeTitle"), MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (res == DialogResult.Yes) { ShowProperties(); } else { MessageBox.Show(conf.GetString("Core.NoConfigText"), conf.GetString("Core.NoConfigTitle"), MessageBoxButtons.OK, MessageBoxIcon.Information); } } #endif #if BETA if (conf.BetaExpiry.CompareTo(DateTime.Now) <= 0) // Beta expired? Prompt user to upgrade { auxThread = new Thread(new ThreadStart(threadBetaExpired)); auxThread.Start(); if (conf.RunFromTrayNow) { betaClock = new System.Windows.Forms.Timer(); betaClock.Interval = 2255555; betaClock.Tick += new System.EventHandler(betaWarnTick); betaClock.Start(); } } else #endif // BETA #if WINDOWS // First, second or third time ChronosXP is run? Notify user that its running in the background with a balloon window if (conf.Run < 3 && conf.RunFromTrayNow) { auxThread = new Thread(new ThreadStart(threadBgRunning)); auxThread.Start(); } #endif // WINDOWS //if !DEBUG CheckUpdates(); //endif / DEBUG // standalone mode? display the Planetary Hours Calendar if (!conf.RunFromTrayNow) { ShowCalendar(); } // run with /properties argument? Show the Properties form. if (showproperties) { ShowProperties(); } }
/// <summary> /// Update the tray icon /// </summary> private void updateTray() { if (conf.Caption == Config.CaptionType.LunarPhase && localPhases == null) { localPhases = new LunarPhase(DateTime.UtcNow); currentPhase = localPhases.CurrentPhase(DateTime.UtcNow); } if (currentHour == (PlanetaryHours.Planet)(-1)) { pHours = new PlanetaryHours(conf); currentHour = pHours.CurrentHour(); } if (currentHour == (PlanetaryHours.Planet)(-1)) { trayIcon.Icon = new Icon(conf.Fx.ResourceStream("Exclamation.ico")); ErrorMessage("A serious internal error has occured; please report this error to the author of ChronosXP at " + Config.Email, new Exception("ChronosXP.PlanetaryHours failed twice at " + DateTime.Now.ToString() + "; unable to determine planetary hour."), conf); } else { try { if (conf.Fx.IconSet.Equals("Silver") && pHours.CurrentHour() == PlanetaryHours.Planet.Saturn) { trayIcon.Icon = conf.Fx.GlyphIconSmall("Tray.Saturn"); } else { trayIcon.Icon = conf.Fx.GlyphIconSmall(pHours.CurrentEnglishHour()); } string stat; switch (conf.Caption) { default: case Config.CaptionType.HourNumber: stat = pHours.HourOfDay(DateTime.Now); break; case Config.CaptionType.HouseOfMoment: stat = pHours.HouseOfMoment(DateTime.Now); break; case Config.CaptionType.LunarPhase: int i = localPhases.PhaseNum(DateTime.UtcNow); if (i == -1) { i = 7; } stat = conf.GetString(LunarPhase.PhaseName[i]); break; } string s = pHours.DayString() + "\r\n" + pHours.CurrentHourString() + "\r\n" + stat; // Too bad we're limited to 64 chars, because this would be nice... //string s = pHours.DayString() + ", " + pHours.CurrentHourString() + "\r\n" + // pHours.HourOfDay(DateTime.Now) + ", " + pHours.HouseOfMoment(DateTime.Now) + "\r\n" + // localPhases.PhaseNum(DateTime.UtcNow); if (s.Length >= 64) { s = s.Remove(60, s.Length - 60) + "..."; } trayIcon.Text = s; } catch (Exception ex) { trayIcon.Icon = new Icon(conf.Fx.ResourceStream("Exclamation.ico")); ErrorMessage("Unable to set glyph icon. [CurrentEnglishHour=" + pHours.CurrentEnglishHour() + "]", ex); } } }