/* * $RCSfile: Settings.cs,v $ * Copyright (C) 2006 Rob Loach (http://robloach.net) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO; using Microsoft.Win32; namespace ScreenCap { public partial class Settings : Form { public Settings() { InitializeComponent(); comboFileFormat.Items.AddRange(Enum.GetNames(typeof(Config.ImageFormat))); txtSaveDirectory.Text = Config.SaveDirectory; txtFilenameFormat.Text = Config.FilenameFormat; comboFileFormat.Text = Config.FileFormat.ToString(); chkSnapshot.Checked = Config.SnapshotSound; chkStartup.Checked = Config.StartupSound; txtCaptureActiveWindow.Text = m_CaptureWindow.ToString() + " + " + txtCapture.Text; txtCaptureActiveClientArea.Text = m_CaptureClientArea.ToString() + " + " + txtCapture.Text; chkGenerateThumbnails.Checked = Config.GenerateThumbnails; chkGenerateThumbnails_CheckedChanged(null, null); chkMaxWidth.Checked = Config.SetMaxWidth; chkMaxHeight.Checked = Config.SetMaxHeight; chkMaxWidth_CheckedChanged(null, null); chkMaxHeight_CheckedChanged(null, null); numMaxWidth.Value = Config.MaxWidth; numMaxHeight.Value = Config.MaxHeight; txtThumbFilenameFormat.Text = Config.ThumbnailFileFormat; comboThumbImageFormat.Items.AddRange(Enum.GetNames(typeof(Config.ImageFormat))); comboThumbImageFormat.Text = Config.ThumbnailImageFormat.ToString(); RegistryKey rkApp = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true); if (rkApp.GetValue(Application.ProductName) == null) chkStartOnWindowsStartup.Checked = false; else chkStartOnWindowsStartup.Checked = true; numIndex.Value = ScreenCapture.CaptureIndex; chkNotifyStartup.Checked = Config.NotifyStartup; chkNotifySnapshot.Checked = Config.NotifySnapshot; txtServer.Text = Config.FtpServer; txtUsername.Text = Config.FtpUsername; txtRemotePath.Text = Config.FtpPath; } private Keys m_CaptureWindow = Config.CaptureActiveWindow; private Keys m_CaptureClientArea = Config.CaptureActiveClientArea; private void btnCancel_Click(object sender, EventArgs e) { this.Close(); } private void btnOK_Click(object sender, EventArgs e) { btnApply_Click(sender, e); this.Close(); } private void btnApply_Click(object sender, EventArgs e) { Config.SaveDirectory = txtSaveDirectory.Text; Config.FilenameFormat = txtFilenameFormat.Text; Config.FileFormat = (Config.ImageFormat)Enum.Parse(typeof(Config.ImageFormat), comboFileFormat.Text, true); Config.SnapshotSound = chkSnapshot.Checked; Config.StartupSound = chkStartup.Checked; Config.CaptureActiveWindow = m_CaptureWindow; Config.CaptureActiveClientArea = m_CaptureClientArea; ScreenCap.keyCapArea = m_CaptureClientArea; ScreenCap.keyCapWindow = m_CaptureWindow; Config.GenerateThumbnails = chkGenerateThumbnails.Checked; Config.SetMaxWidth = chkMaxWidth.Checked; Config.SetMaxHeight = chkMaxHeight.Checked; Config.MaxWidth = (int)numMaxWidth.Value; Config.MaxHeight = (int)numMaxHeight.Value; Config.ThumbnailFileFormat = txtThumbFilenameFormat.Text; Config.ThumbnailImageFormat = (Config.ImageFormat)Enum.Parse(typeof(Config.ImageFormat), comboThumbImageFormat.Text, true); RegistryKey rkApp = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true); if(chkStartOnWindowsStartup.Checked) rkApp.SetValue(Application.ProductName, "\"" + Application.ExecutablePath.ToString() + "\""); else rkApp.DeleteValue(Application.ProductName, false); ScreenCapture.CaptureIndex = (int)numIndex.Value; Config.NotifyStartup = chkNotifyStartup.Checked; Config.NotifySnapshot = chkNotifySnapshot.Checked; Config.FtpPath = txtRemotePath.Text; Config.FtpServer = txtServer.Text; Config.FtpUsername = txtUsername.Text; try { Config.Save(); } catch (Exception ex) { MessageBox.Show(this, "An unknown error caused the configuration settings not to save:\n\n" + ex.Message, "ScreenCap", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); } } private void btnSaveDirectoryBrowse_Click(object sender, EventArgs e) { browseFolder.Description = "Select where you would like screenshots to be saved."; //browseFolder.SelectedPath = switch (browseFolder.ShowDialog(this)) { case DialogResult.OK: txtSaveDirectory.Text = browseFolder.SelectedPath; break; } } private void Settings_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Escape) btnCancel_Click(sender, e); } private void txtCaptureActiveWindow_KeyDown(object sender, KeyEventArgs e) { if ((e.KeyCode == Keys.Menu) || (e.KeyCode == Keys.LMenu) || (e.KeyCode == Keys.RMenu)) return; m_CaptureWindow = e.KeyCode; txtCaptureActiveWindow.Text = m_CaptureWindow.ToString() + " + " + txtCapture.Text; } private void txtCaptureActiveClientArea_KeyDown(object sender, KeyEventArgs e) { if ((e.KeyCode == Keys.Menu) || (e.KeyCode == Keys.LMenu) || (e.KeyCode == Keys.RMenu)) return; m_CaptureClientArea = e.KeyCode; txtCaptureActiveClientArea.Text = m_CaptureClientArea.ToString() + " + " + txtCapture.Text; } private void chkGenerateThumbnails_CheckedChanged(object sender, EventArgs e) { groupThumbnails.Enabled = chkGenerateThumbnails.Checked; } private void UpdateThumbnailExample() { int index = 12; DateTime now = DateTime.Now; string ext = comboThumbImageFormat.Text.ToLower(); try { txtThumbExample.Text = string.Format(txtThumbFilenameFormat.Text, ext, index, now); txtThumbExample.Text = txtThumbExample.Text.Replace("/", ""); txtThumbExample.Text = txtThumbExample.Text.Replace("\\", ""); txtThumbExample.Text = txtThumbExample.Text.Replace("\"", ""); txtThumbExample.Text = txtThumbExample.Text.Replace("<", ""); txtThumbExample.Text = txtThumbExample.Text.Replace(">", ""); txtThumbExample.Text = txtThumbExample.Text.Replace("|", ""); txtThumbExample.Text = txtThumbExample.Text.Replace("?", ""); } catch { txtThumbExample.Text = "Formatting Error"; } } private void UpdateExample() { int index = (int)numIndex.Value; DateTime now = DateTime.Now; string ext = comboFileFormat.Text.ToLower(); try { txtExample.Text = string.Format(txtFilenameFormat.Text, ext, index, now); txtExample.Text = txtExample.Text.Replace("/", ""); txtExample.Text = txtExample.Text.Replace("\\", ""); txtExample.Text = txtExample.Text.Replace("\"", ""); txtExample.Text = txtExample.Text.Replace("<", ""); txtExample.Text = txtExample.Text.Replace(">", ""); txtExample.Text = txtExample.Text.Replace("|", ""); txtExample.Text = txtExample.Text.Replace("?", ""); } catch { txtExample.Text = "Formatting Error"; } } private void Event_TextChanged(object sender, EventArgs e) { UpdateExample(); } private void chkMaxWidth_CheckedChanged(object sender, EventArgs e) { numMaxWidth.Enabled = chkMaxWidth.Checked; } private void chkMaxHeight_CheckedChanged(object sender, EventArgs e) { numMaxHeight.Enabled = chkMaxHeight.Checked; } private void UpdateThumbnailExample_TextChanged(object sender, EventArgs e) { UpdateThumbnailExample(); } private void btnViewScreenShots_Click(object sender, EventArgs e) { System.Diagnostics.Process.Start(Config.SaveDirectory); } private void listFTP_DragDrop(object sender, DragEventArgs e) { listFTP.Items.Clear(); FtpClient client = new FtpClient(txtServer.Text, txtUsername.Text, txtPassword.Text); try { client.Login(); } catch (FtpClient.FtpException ex) { listFTP.Items.Add(ex.Message); return; } listFTP.Items.Add("Successfully logged in."); if (txtRemotePath.Text != "") { try { client.ChangeDir(txtRemotePath.Text); } catch (FtpClient.FtpException ex) { listFTP.Items.Add(ex.Message); return; } listFTP.Items.Add("Changed directory to " + txtRemotePath.Text + "."); } string[] files = (string[])e.Data.GetData(DataFormats.FileDrop, false); foreach (string file in files) { FileInfo info = new FileInfo(file); if (info.Exists) { try { client.Upload(info.FullName); listFTP.Items.Add("Uploaded " + info.Name + "."); } catch (FtpClient.FtpException ex) { listFTP.Items.Add(ex.Message); } } else { listFTP.Items.Add(info.Name + " not found..."); } } client.Close(); listFTP.Items.Add("Disconnected from server."); } private void listFTP_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.All; else e.Effect = DragDropEffects.None; } } }