Example #1
0
        private void OnSelectExternalApp(object sender, System.EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter           = ApplicationManager.GetString("Exe") + " (*.exe)|*.exe";
            dialog.Title            = ApplicationManager.GetString("ExternalApp.Title");
            dialog.DefaultExtension = "exe";

            string AppPath = this._ExternalAppPath.Text;

            if (Settings.IsValidPathToExecutable(AppPath) && File.Exists(AppPath))
            {
                dialog.FileName = AppPath;
            }
            else if (!((this._Settings.ExternalApp.Length != 0) && File.Exists(this._Settings.ExternalApp)))
            {
                dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
                dialog.FileName         = "*.exe";
            }
            else
            {
                dialog.FileName = this._Settings.ExternalApp;
            }

            if (dialog.ShowDialog(this.Handle))
            {
                this._ExternalAppPath.Text = dialog.FileName;
            }
        }
Example #2
0
        private void OnTryApplySettings(bool closeForm)
        {
            if (this._ChangedItems != SettingsItems.None)
            {
                if ((this._ImageDestinations & ImageDestinations.File) == ImageDestinations.File)
                {
                    // working directory check
                    if (!Settings.IsValidPath(this._WorkingDirectoryPath.Text))
                    {
                        MessageBox.Show(this, ApplicationManager.GetString("InvalidDirectoryName"), System.Windows.Forms.MessageBoxIcon.Warning);

                        return;
                    }

                    if (!Directory.Exists(this._WorkingDirectoryPath.Text))
                    {
                        MessageBox.Show(this, ApplicationManager.GetString("DirectoryNotExist"), System.Windows.Forms.MessageBoxIcon.Warning);

                        return;
                    }

                    // file name check
                    if (!Settings.IsValidFileNameFormat(this._FileNameSelector.Text))
                    {
                        MessageBox.Show(this, ApplicationManager.GetString("InvalidFileName"), System.Windows.Forms.MessageBoxIcon.Warning);

                        return;
                    }

                    // external app path check
                    if (this._UseExternalApp.Checked)
                    {
                        if (!Settings.IsValidPathToExecutable(this._ExternalAppPath.Text))
                        {
                            MessageBox.Show(this, ApplicationManager.GetString("InvalidExecutablePath"), System.Windows.Forms.MessageBoxIcon.Warning);

                            return;
                        }

                        if (!File.Exists(this._ExternalAppPath.Text))
                        {
                            MessageBox.Show(this, ApplicationManager.GetString("ExternalAppNotFound"), System.Windows.Forms.MessageBoxIcon.Warning);

                            return;
                        }
                    }

                    this._Settings.WorkingDirectory = this._WorkingDirectoryPath.Text;
                    this._Settings.UseFileOverwrite = this._UseFileOverwrite.Checked;
                    this._Settings.UpdateFileNameFormat(this._FileNameSelector.Text);

                    if (this._Settings.UseExternalApp = this._UseExternalApp.Checked)
                    {
                        this._Settings.ExternalApp = this._ExternalAppPath.Text;
                    }
                }

                this._Settings.IncludeCursor     = this._IncludeCursor.Checked;
                this._Settings.AutoStartup       = this._AutoStartup.Checked;
                this._Settings.AlwaysOnTop       = this._AlwaysOnTop.Checked;
                this._Settings.ImageDestinations = this._ImageDestinations;

                this._CurrentFormatId = this._Settings.FileType.FormatId;
                this._ChangedItems    = SettingsItems.None;
                this._Apply.Enabled   = false;
                this.TopMost          = this._Settings.AlwaysOnTop;

                Configuration.Current.Settings.FromSettings(this._Settings);
                Configuration.Save(this._Settings);
            }

            if (closeForm)
            {
                this.Close();
            }
        }
Example #3
0
        private static Items Load()
        {
            Settings settings = new Settings();

            FileType[]         supportedTypes = new FileType[] { new PngFileType(), new BmpFileType(), new TiffFileType(), new JpegFileType(), new GifFileType() };
            FileTypeCollection fileTypes      = new FileTypeCollection(supportedTypes);

            using (RegistryKey Key = Registry.CurrentUser.OpenSubKey(@"Software\Goletas\ScreenCapture", RegistryKeyPermissionCheck.ReadSubTree))
            {
                if (Key != null)
                {
                    try
                    {
                        for (int i = 0; i < supportedTypes.Length; i++)
                        {
                            if (supportedTypes[i].IsEditable)
                            {
                                supportedTypes[i].Deserialize(Key.GetValue(supportedTypes[i].FormatId.ToString("B")) as byte[]);
                            }
                        }

                        settings.IncludeCursor = Settings.Int32ToBoolTrueOnFail(Key.GetValue("IncludeCursor"));
                        settings.AlwaysOnTop   = Settings.Int32ToBoolFalseOnFail(Key.GetValue("AlwaysOnTop"));
                        if (settings.UpdateFileNameFormat(Key.GetValue("FileName") as string))
                        {
                            settings.ImageDestinations = Settings.ToImageDestinations(Key.GetValue("ImageDestinations"));
                        }
                        settings.WorkingDirectory = Key.GetValue("WorkingDirectory") as string;
                        settings.UseExternalApp   = Settings.Int32ToBoolFalseOnFail(Key.GetValue("UseExternalApp"));
                        settings.ExternalApp      = Key.GetValue("ExternalApp") as string;
                        settings.UseFileOverwrite = Settings.Int32ToBoolFalseOnFail(Key.GetValue("UseFileOverwrite"));

                        string FormatId = Key.GetValue("FileType") as string;
                        int    TypeIndex;

                        if (Settings.IsGuid(FormatId) && ((TypeIndex = fileTypes.IndexOf(new Guid(FormatId))) >= 0))
                        {
                            settings.FileType = fileTypes[TypeIndex];
                        }
                    }
                    catch (IOException)
                    {
                    }
                }
            }

            using (RegistryKey Key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", RegistryKeyPermissionCheck.ReadSubTree))
            {
                if (Key != null)
                {
                    try
                    {
                        settings.AutoStartup = ((Key.GetValue("Goletas.ScreenCapture") as string) == ("\"" + System.Windows.Forms.Application.ExecutablePath + "\" background"));
                    }
                    catch (IOException)
                    {
                    }
                }
            }

            if (settings.FileType == null)
            {
                settings.FileType = fileTypes[0];
            }

            if (!Settings.IsValidPath(settings.WorkingDirectory))
            {
                settings.WorkingDirectory  = null;
                settings.ImageDestinations = ImageDestinations.Clipboard;
            }

            if (!Settings.IsValidPathToExecutable(settings.ExternalApp))
            {
                settings.ExternalApp    = null;
                settings.UseExternalApp = false;
            }

            return(new Items(Settings.Synchronized(settings), fileTypes));
        }