private void btnZapisz_Click(object sender, EventArgs e)
{
if (sekundy < 10)
{
MessageBox.Show("Liczba sekund nie moze byc mniejsza niz 10");
return;
}
sekundy = Int32.Parse(txtSekundy.Text);
if (!Directory.Exists(txtSciezka.Text))
Directory.CreateDirectory(txtSciezka.Text);
int tmp;
if (chbProxy.Checked && (txtSerwer.Text == "" || txtPort.Text == "" || !Int32.TryParse(txtPort.Text, out tmp)))
{
MessageBox.Show("Ustaw poprawnie proxy");
return;
}
if (chbProxy.Checked && chbUwierzytelnienie.Checked && (txtLogin.Text == "" || txtHaslo.Text == ""))
{
MessageBox.Show("Ustaw poprawnie proxy");
return;
}
if (chbProxy.Checked)
{
WebProxy wp = new WebProxy(txtSerwer.Text + ":" + txtPort.Text, chbUwierzytelnienie.Checked);
if (chbUwierzytelnienie.Checked)
wp.Credentials = new NetworkCredential(txtLogin.Text, txtHaslo.Text);
WebRequest.DefaultWebProxy = wp;
}
else
{
WebRequest.DefaultWebProxy = null;
}
try
{
XmlSerializer xml = new XmlSerializer(typeof(ustawienia_uzytkownika));
ustawienia_uzytkownika gu = new ustawienia_uzytkownika(chbProxy.Checked ? 1 : 0, txtSerwer.Text, txtPort.Text==""?-1:Int32.Parse(txtPort.Text), chbUwierzytelnienie.Checked ? 1 : 0, txtLogin.Text, txtHaslo.Text, txtSciezka.Text, sekundy, radioLog.Checked ? 1 : radioPopup.Checked ? 2 : radioTray.Checked ? 0 : -1);
TextWriter tw = new StreamWriter(KomClass.Login + "/ustawienia.ini");
xml.Serialize(tw, gu, names);
tw.Close();
}
catch (Exception ex)
{
MessageBox.Show("Nie mozna bylo zapisac ustawien"+ex.ToString());
}
z.zmianaKontroli(radioLog.Checked ? 1 : radioPopup.Checked ? 2 : radioTray.Checked ? 0 : -1);
Thread zmianaF = new Thread(new ParameterizedThreadStart(zmianaFolderu));
bledyKontrola = radioLog.Checked ? 1 : radioPopup.Checked ? 2 : radioTray.Checked ? 0 : -1;
if (fol != txtSciezka.Text)
{
pliki p = new pliki();
TextWriter sw = new StreamWriter(KomClass.Login + "/pliki.xml", false);
XmlSerializer xml = new XmlSerializer(typeof(pliki));
xml.Serialize(sw, p, names);
sw.Close();
}
fol = txtSciezka.Text;
zmianaF.Start(txtSciezka.Text);
}