55 lines
1.9 KiB
C#
55 lines
1.9 KiB
C#
using System;
|
|
using System.Net;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Mk0.Software.Bildduplikate
|
|
{
|
|
public partial class API : Form
|
|
{
|
|
public API()
|
|
{
|
|
InitializeComponent();
|
|
textBoxApiUrl.Text = Properties.Settings.Default.ApiUrl;
|
|
textBoxPath1.Text = Properties.Settings.Default.ReplacePath;
|
|
textBoxPath2.Text = Properties.Settings.Default.ReplaceWith;
|
|
numericUpDown1.Value = Properties.Settings.Default.imagesFromAPI;
|
|
checkBoxAutoLoad.Checked = Properties.Settings.Default.autoload;
|
|
}
|
|
|
|
private void ButtonSave_Click(object sender, EventArgs e)
|
|
{
|
|
if (!CheckWebsite(textBoxApiUrl.Text.Trim() + "?test"))
|
|
{
|
|
MessageBox.Show("The URL of the API is not valid!" + Environment.NewLine + "Settings not saved!", "No valid API", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
else
|
|
{
|
|
Properties.Settings.Default.ApiUrl = textBoxApiUrl.Text.Trim();
|
|
Properties.Settings.Default.ReplacePath = textBoxPath1.Text.Trim();
|
|
Properties.Settings.Default.ReplaceWith = textBoxPath2.Text.Trim();
|
|
Properties.Settings.Default.imagesFromAPI = (int)numericUpDown1.Value;
|
|
Properties.Settings.Default.autoload = checkBoxAutoLoad.Checked;
|
|
Properties.Settings.Default.Save();
|
|
}
|
|
}
|
|
|
|
public bool CheckWebsite(string URL)
|
|
{
|
|
try
|
|
{
|
|
WebClient wc = new WebClient();
|
|
string HTMLSource = wc.DownloadString(URL);
|
|
if (HTMLSource.Contains("API is working properly"))
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|