json-canonicalizer/JsonCanonicalizer.UI/OneFileTaskForm.cs
2026-08-03 14:00:09 +03:00

62 lines
1.8 KiB
C#

namespace JsonCanonicalizer.UI;
public partial class OneFileTaskForm : Form
{
public OneFileTaskForm()
{
InitializeComponent();
}
private void btnSrcFile_Click(object sender, EventArgs e)
{
dlgSrcFile.FileName = txtSrcFile.Text;
if (dlgSrcFile.ShowDialog() == DialogResult.OK)
{
txtSrcFile.Text = dlgSrcFile.FileName;
}
}
private void btnDstFile_Click(object sender, EventArgs e)
{
dlgDstFile.FileName = txtDstFile.Text;
if (dlgDstFile.ShowDialog() == DialogResult.OK)
{
txtDstFile.Text = dlgDstFile.FileName;
}
}
private void btnDoIt_Click(object sender, EventArgs e)
{
if (String.IsNullOrWhiteSpace(txtSrcFile.Text))
{
MessageBox.Show("Íå âûáðàí èñõîäíûé ôàéë", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (String.IsNullOrWhiteSpace(txtDstFile.Text))
{
MessageBox.Show("Íå çàäàí ôàéë ðåçóëüòàòà", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!File.Exists(txtSrcFile.Text))
{
MessageBox.Show("Èñõîäíûé ôàéë íå ñóùåñòâóåò", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
using Stream src = new FileStream(txtSrcFile.Text, FileMode.Open);
using Stream dst = new FileStream(txtDstFile.Text, FileMode.Create);
BL.Canonicalizer.Canonicalize(src, dst);
MessageBox.Show("Ãîòîâî", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}