Esempio n. 1
0
        /// <summary>
        /// Load the configuration from file.
        /// </summary>
        /// <param name="path">The source configuration file</param>
        /// <returns></returns>
        public static ScreenShotConfiguration Load(string path)
        {
            ScreenShotConfiguration ss;
            try
            {
                //If file exists then load from the file, otherwise use the defaults
                if (File.Exists(path)) {

                    var json = File.ReadAllText(path);
                    var serializer = new JavaScriptSerializer();

                    ss = serializer.Deserialize<ScreenShotConfiguration>(json);
                } else {
                    ss = new ScreenShotConfiguration();
                }

            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(String.Format("Could not load configuration from '{0}'. Error was '{1}'", path, ex.Message), ex);
            }

            try
            {
                //If the ScreenShot key exists in the registry, then startup is enabled.
                RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                ss.LaunchOnLogin = (key.GetValue("ScreenShot", null) != null);

            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(String.Format("Could not load configuration from registry. Error was '{1}'", path, ex.Message), ex);
            }

            return ss;
        }
Esempio n. 2
0
        private void LoadSettings()
        {
            //Set the config filename
            _configPath = System.IO.Path.Combine(Environment.CurrentDirectory, "ScreenShotSettings.config");

            //Load the configuration.
            ScreenShotConfiguration config;
            try {
                config = ScreenShotConfiguration.Load(_configPath);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ScreenShot", MessageBoxButtons.OK, MessageBoxIcon.Error);

                //For resilience, use the default settings if configuration cannot be loaded.
                config = new ScreenShotConfiguration();
            }

            //Start up the worker
            _worker = new Worker(config);

            //Clear out existing bindings.
            foreach (Control c in this.Controls)
                c.DataBindings.Clear();

            //Set the screen control bindings
            txtFSKey.DataBindings.Add("Text", _worker.Config.FullScreenHotKey, "Key");
            chkFSAlt.DataBindings.Add("Checked", _worker.Config.FullScreenHotKey, "Alt");
            chkFSShift.DataBindings.Add("Checked", _worker.Config.FullScreenHotKey, "Shift");
            chkFSCtrl.DataBindings.Add("Checked", _worker.Config.FullScreenHotKey, "Ctrl");
            chkFSWin.DataBindings.Add("Checked", _worker.Config.FullScreenHotKey, "Win");

            txtAWKey.DataBindings.Add("Text", _worker.Config.ActiveWindowHotKey, "Key");
            chkAWAlt.DataBindings.Add("Checked", _worker.Config.ActiveWindowHotKey, "Alt");
            chkAWShift.DataBindings.Add("Checked", _worker.Config.ActiveWindowHotKey, "Shift");
            chkAWCtrl.DataBindings.Add("Checked", _worker.Config.ActiveWindowHotKey, "Ctrl");
            chkAWWin.DataBindings.Add("Checked", _worker.Config.ActiveWindowHotKey, "Win");

            chkRightClick.DataBindings.Add("Checked", _worker.Config, "EnableRightClick");
            chkLaunchOnLogin.DataBindings.Add("Checked", _worker.Config, "LaunchOnLogin");
        }