using System;
using System.Net;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using IReaper.Properties;
using IReaper.Net;
namespace IReaper.Configurations{
public partial class StartUpCriticalCheck : Form
{
Settings currentSettings;
public StartUpCriticalCheck()
{
InitializeComponent();
currentSettings = new Settings();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
//get from properties settings
//path
string path = currentSettings.RootPath;
this.textBoxPath.Text = path;
//proxy
ProxySelector selector = (ProxySelector)currentSettings.ProxySelector;
switch (selector)
{
case ProxySelector.IE:
this.radioBtnIE.Checked = true;
break;
case ProxySelector.None:
this.radioBtnDirect.Checked = true;
break;
case ProxySelector.UserSpecified:
this.radioBtnHttp.Checked = true;
break;
}
//get uri and credential from settings
string proxyUriString = Settings.Default.ProxyURI;
string proxyCredentialString = Settings.Default.ProxyCredentials;
Uri uri;
Uri.TryCreate(proxyUriString, UriKind.Absolute, out uri);
if (uri == null)
return;
WebProxy proxy = new WebProxy(uri);
//set uri's path and port
this.textBoxAddress.Text = proxy.Address.AbsolutePath;
this.textBoxPort.Text = proxy.Address.Port.ToString();
//get the credential
if (proxyCredentialString != null)
{
string[] spliter = proxyCredentialString.Split(':');
if (spliter.Length == 2)
{
this.textBoxUserName.Text = spliter[0];
this.textBoxPassword.Text = spliter[1];
}
}
}
private void folderControlBtn_Click(object sender, EventArgs e)
{
if (DialogResult.OK == this.folderBrowserDialog1.ShowDialog())
{
this.textBoxPath.Text = this.folderBrowserDialog1.SelectedPath;
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void UpdateSettings(object sender, EventArgs e)
{
if (sender is UserControl && !this.Visible)//UserControl.VisiableChange
{
//
if (this.textBoxPath.Text == Properties.Settings.Default.RootPath)
return;
}
//
if (!Directory.Exists(this.textBoxPath.Text))
{
if (DialogResult.Yes != MessageBox.Show(
Resources.TheFolder + this.textBoxPath.Text + Resources.NotExistsAndCreate,
Resources.TheFolder + this.textBoxPath.Text + Resources.NotExists,
MessageBoxButtons.YesNo))
{
return;
}
else
{
try
{
Directory.CreateDirectory(this.textBoxPath.Text);
}
catch (Exception ex)
{
MessageBox.Show(Resources.FailedToCreateFolder + ex.Message,
Resources.FailedToCreateFolder,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
}
}
//
if (this.radioBtnDirect.Checked)
{
currentSettings.ProxySelector = (short)ProxySelector.None;
}
//
else if (this.radioBtnHttp.Checked)
{
try
{
//
Uri uri;
Uri.TryCreate("http://" + this.textBoxAddress.Text + ":" + int.Parse(this.textBoxPort.Text),UriKind.Absolute,out uri);
if (uri == null)
return;
currentSettings.ProxyURI = uri.ToString();
//
if (this.textBoxPassword.Text.Length == 0 &&
this.textBoxUserName.Text.Length == 0)
{
currentSettings.ProxyCredentials = this.textBoxUserName.Text + ":" + this.textBoxPassword.Text;
}
currentSettings.ProxySelector = (short)ProxySelector.UserSpecified;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
else
{
currentSettings.ProxySelector = (short)ProxySelector.IE;
}
currentSettings.RootPath = this.textBoxPath.Text;
currentSettings.Save();
Properties.Settings.Default.Reload();
MessageBox.Show(Resources.Updated);
this.Close();
}
private void CloseApplication(object sender, EventArgs e)
{
this.Close();
Application.Exit();
}
private void radioBtnHttp_CheckedChanged(object sender, EventArgs e)
{
this.panelProxySettings.Enabled = this.radioBtnHttp.Checked;
}
}
}
|