Esempio n. 1
0
        static void Main(string[] args)
        {
            //Boilerplate code
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //Create setup window
            Forms.Setup setupForm = new Forms.Setup();

            //Register commands
            Command.Register <Commands.Target>();
            Command.Register <Commands.TimeLeft>();
            Command.Register <Commands.ColorScheme>();
            Command.Register <Commands.Freeze>();
            Command.Register <Commands.EndMode>();
            Command.Register <Commands.StartTime>();
            Command.Register <Commands.Idle>();

            //If there is an argument, treat is as a file path and open it
            if (args.Length > 0)
            {
                setupForm.LoadFile(args[0]);
                setupForm.StartWithCurrentSettings();
            }
            else
            {
                //Show window and run message pump
                setupForm.Show();
            }

            Application.Run();

            //Dispose taskbar icon before shutdown
            TaskbarHelper.DisposeIcon();
        }
Esempio n. 2
0
        /// <summary>
        /// Sets the taskbar icon's progress information to mimic the timer
        /// </summary>
        /// <param name="f"></param>
        public static void SetProgress(Form f)
        {
            TimeSpan tl = Globals.PrimaryTimer.TimeLeft;

            //Get handle of form
            IntPtr handle = f.Handle;

            //Free mode -> No progress state
            if (Globals.PrimaryTimer.InFreeMode)
            {
                TaskbarHelper.SetState(handle, TaskbarHelper.TaskbarStates.NoProgress);
                return;
            }

            //Overtime -> Indeterminate state (Value does not apply)
            if (Globals.PrimaryTimer.Overtime)
            {
                TaskbarHelper.SetState(handle, TaskbarHelper.TaskbarStates.Indeterminate);
                return;
            }

            //Buffer for storing precalculated values
            double v = 60 - tl.Minutes;

            //1m -> red, yellow and green
            if (tl.TotalMinutes < 1)
            {
                v = 60 - tl.Seconds;
                switch (tl.Seconds % 3)
                {
                case 0:
                    setProgress(TaskbarHelper.TaskbarStates.Normal, v, 60);
                    break;

                case 1:
                    setProgress(TaskbarHelper.TaskbarStates.Paused, v, 60);
                    break;

                case 2:
                    setProgress(TaskbarHelper.TaskbarStates.Error, v, 60);
                    break;
                }
            }

            //1h -> green
            else if (tl.TotalHours < 1)
            {
                setProgress(TaskbarHelper.TaskbarStates.Normal, v, 59);
            }

            //2h -> yellow
            else if (tl.TotalHours < 2)
            {
                setProgress(TaskbarHelper.TaskbarStates.Paused, v, 60);
            }

            //3h -> red
            else if (tl.TotalHours < 3)
            {
                setProgress(TaskbarHelper.TaskbarStates.Error, v, 60);
            }

            //4h -> yellow, green
            else if (tl.TotalHours < 4)
            {
                setProgress(tl.Seconds % 2 == 0 ?
                            TaskbarHelper.TaskbarStates.Paused :
                            TaskbarHelper.TaskbarStates.Normal,
                            v, 60);
            }

            //5h -> red, green
            else if (tl.TotalHours < 5)
            {
                setProgress(tl.Seconds % 2 == 0 ?
                            TaskbarHelper.TaskbarStates.Error :
                            TaskbarHelper.TaskbarStates.Normal,
                            v, 60);
            }

            //6h -> red, yellow
            else if (tl.TotalHours < 6)
            {
                setProgress(tl.Seconds % 2 == 0 ?
                            TaskbarHelper.TaskbarStates.Error :
                            TaskbarHelper.TaskbarStates.Paused,
                            v, 60);
            }

            //1d -> solid green
            else if (tl.TotalDays < 1)
            {
                setProgress(TaskbarHelper.TaskbarStates.Normal, 1, 1);
            }

            //7d -> solid yellow
            else if (tl.TotalDays < 7)
            {
                setProgress(TaskbarHelper.TaskbarStates.Paused, 1, 1);
            }

            //>7d -> solid red
            else
            {
                setProgress(TaskbarHelper.TaskbarStates.Error, 1, 1);
            }

            //Shorthand for TaskbarHelper.SetState and TaskbarHelper.SetValue
            /* local */ void setProgress(TaskbarHelper.TaskbarStates state, double value, double maxValue)
            {
                TaskbarHelper.SetState(handle, state);
                TaskbarHelper.SetValue(handle, value, maxValue);
            }
        }