Ejemplo n.º 1
0
        //The method that loads all the settings in from the txt files.
        private void LoadSettings()
        {
            File_Managment.CreateDirFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\SanguinesStartUpUtils\\Settings\\", "Paths.txt");
            File_Managment.CreateDirFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\SanguinesStartUpUtils\\Settings\\", "Websites.txt");
            File_Managment.CreateDirFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\SanguinesStartUpUtils\\Settings\\", "Sounds.txt");

            //Simple
            shutdownCheck.Checked    = Convert.ToBoolean(File_Managment.ReadFromSettings("shutdownEnabled"));
            shutdownTimeTextBox.Text = File_Managment.ReadFromSettings("shutdownTime");
            startProgram.Checked     = Convert.ToBoolean(File_Managment.ReadFromSettings("programsEnabled"));
            openWebsite.Checked      = Convert.ToBoolean(File_Managment.ReadFromSettings("websitesEnabled"));
            playSounds.Checked       = Convert.ToBoolean(File_Managment.ReadFromSettings("soundsEnabled"));
            soundsDelay.Text         = File_Managment.ReadFromSettings("soundsDelay");

            programTextBox.Lines          = getExecutableName();
            programTextBox.SelectionStart = programTextBox.Text.Length;
            programTextBox.ScrollToCaret();
            soundTextBox.Lines          = getSoundName();
            soundTextBox.SelectionStart = soundTextBox.Text.Length;
            soundTextBox.ScrollToCaret();
            websitesTextBox.Lines          = File.ReadAllLines(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\SanguinesStartUpUtils\\Settings\\Websites.txt");
            websitesTextBox.SelectionStart = websitesTextBox.Text.Length;
            websitesTextBox.ScrollToCaret();

            //Advanced
            cmdTextBox.Lines = File_Managment.ReadFromCMD();
        }
        //This method starts the timer for system shutdown.
        private void ShutdownTimer()
        {
            double time;

            if (File_Managment.ReadFromSettings("shutdownTime") == null || Convert.ToInt32(File_Managment.ReadFromSettings("shutdownTime")) <= 10)
            {
                MessageBox.Show("Invalid shutdown Time! Setting time to 60 min.");
                time = TimeSpan.FromMinutes(60D).TotalMilliseconds;
                File_Managment.SaveToSettings("shutdownTime", "60");
            }
            else
            {
                time = TimeSpan.FromMinutes(Convert.ToDouble(File_Managment.ReadFromSettings("shutdownTime"))).TotalMilliseconds;
            }
            System.Timers.Timer aTimer = new System.Timers.Timer();
            aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
            aTimer.Interval = time;
            aTimer.Enabled  = true;
        }
        //This method executes the simple functions.
        private void Simple()
        {
            if (Convert.ToBoolean(File_Managment.ReadFromSettings("shutdownEnabled")))
            {
                ShutdownTimer();
            }

            if (Convert.ToBoolean(File_Managment.ReadFromSettings("programsEnabled")))
            {
                StartPrograms();
            }

            if (Convert.ToBoolean(File_Managment.ReadFromSettings("websitesEnabled")))
            {
                OpenWebsites();
            }

            if (Convert.ToBoolean(File_Managment.ReadFromSettings("soundsEnabled")))
            {
                new Thread(() =>
                {
                    Thread.CurrentThread.IsBackground = true;
                    SoundPlayer player = new SoundPlayer();
                    foreach (string line in File.ReadAllLines(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\SanguinesStartUpUtils\\Settings\\Sounds.txt"))
                    {
                        try
                        {
                            player = new SoundPlayer(line);
                            player.PlaySync();
                            Thread.Sleep(TimeSpan.FromSeconds(Convert.ToDouble(File_Managment.ReadFromSettings("soundsDelay"))));
                        }
                        catch { }
                    }
                }).Start();
            }
        }