chore: refactor LogicHandler

* replace occurences of using(...){} with declarations
* indentation
* rename dlggg
This commit is contained in:
citizen-VM 2021-01-10 23:38:31 +01:00
parent 769123a084
commit be808f1d72
Signed by: wanderer
GPG Key ID: 6391444A736EEE7E

View File

@ -13,19 +13,17 @@ namespace KRY_0x04
internal void load_msg(RichTextBox msgbox, TextBox msgpathbox, TextBox msgdetailsbox)
{
using (OpenFileDialog dlg = new OpenFileDialog())
{
dlg.Title = "pick a msg";
/* freedom for all */
dlg.Filter = "message (*.msg)|*.msg|custom (*.*)|*.*";
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "pick a msg";
/* freedom for all */
dlg.Filter = "message (*.msg)|*.msg|custom (*.*)|*.*";
if (dlg.ShowDialog() == DialogResult.OK)
{
msgbox.Text = File.ReadAllText(dlg.FileName);
msgpathbox.Text = dlg.FileName;
string f = dlg.FileName;
msgdetailsbox.Text = dsapls.get_file_metrics(f);
}
if (dlg.ShowDialog() == DialogResult.OK)
{
msgbox.Text = File.ReadAllText(dlg.FileName);
msgpathbox.Text = dlg.FileName;
string f = dlg.FileName;
msgdetailsbox.Text = dsapls.get_file_metrics(f);
}
}
@ -102,36 +100,32 @@ namespace KRY_0x04
internal void load_privkey(RichTextBox privkeybox, TextBox privkeypathbox)
{
using (OpenFileDialog dlg = new OpenFileDialog())
{
dlg.Title = "pick a privkey";
/* freedom for all */
dlg.Filter = "private key (*.pri)|*.pri|custom (*.*)|*.*";
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "pick a privkey";
/* freedom for all */
dlg.Filter = "private key (*.pri)|*.pri|custom (*.*)|*.*";
if (dlg.ShowDialog() == DialogResult.OK)
{
privkeybox.Text = File.ReadAllText(dlg.FileName);
privkeypathbox.Text = dlg.FileName;
}
if (dlg.ShowDialog() == DialogResult.OK)
{
privkeybox.Text = File.ReadAllText(dlg.FileName);
privkeypathbox.Text = dlg.FileName;
}
}
internal void load_pubkey(RichTextBox pubkeybox, TextBox pubkeypathbox)
{
using (OpenFileDialog dlg = new OpenFileDialog())
{
dlg.Title = "pick a pubkey";
/* freedom for all */
dlg.Filter = "public key (*.pub)|*.pub|custom (*.*)|*.*";
dlg.CheckFileExists = false;
dlg.CheckPathExists = false;
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "pick a pubkey";
/* freedom for all */
dlg.Filter = "public key (*.pub)|*.pub|custom (*.*)|*.*";
dlg.CheckFileExists = false;
dlg.CheckPathExists = false;
if (dlg.ShowDialog() == DialogResult.OK)
{
pubkeybox.Text = File.ReadAllText(dlg.FileName);
pubkeypathbox.Text = dlg.FileName;
}
if (dlg.ShowDialog() == DialogResult.OK)
{
pubkeybox.Text = File.ReadAllText(dlg.FileName);
pubkeypathbox.Text = dlg.FileName;
}
}
@ -144,45 +138,41 @@ namespace KRY_0x04
MessageBox.Show("load a msg file first, please", "oh hey");
return;
}
using (FolderBrowserDialog dlg = new FolderBrowserDialog())
FolderBrowserDialog dlg = new FolderBrowserDialog();
dlg.Description = "choose a folder to zip";
if (dlg.ShowDialog() == DialogResult.OK)
{
dlg.Description = "choose a folder to zip";
if (dlg.ShowDialog() == DialogResult.OK)
string pathTo_dirToZip = dlg.SelectedPath;
SaveFileDialog dlg_save_msg = new SaveFileDialog();
dlg_save_msg.Title = "where to save text of earlier specified msg";
dlg_save_msg.Filter = "msg in windows-recognizable text file ending with \"txt\" (*.txt)|*.txt|custom (*.*)|*.*";
if (dlg_save_msg.ShowDialog() == DialogResult.OK)
{
string pathTo_dirToZip = dlg.SelectedPath;
using (SaveFileDialog dlggg = new SaveFileDialog())
string path_to_msg = dlg_save_msg.FileName;
if (path_to_msg == "")
{
dlggg.Title = "where to save text of earlier specified msg";
dlggg.Filter = "msg in windows-recognizable text file ending with \"txt\" (*.txt)|*.txt|custom (*.*)|*.*";
if (dlggg.ShowDialog() == DialogResult.OK)
MessageBox.Show("please specify a path first", "not this again, come on");
return;
}
Directory.CreateDirectory(pathTo_dirToZip);
/* TODO - needs fixing */
File.WriteAllText(path_to_msg, msgbox.Text);
try
{
if (File.Exists(pathTo_dirToZip + "zipfile.zip"))
{
string path_to_msg = dlggg.FileName;
if (path_to_msg == "")
{
MessageBox.Show("please specify a path first", "not this again, come on");
return;
}
Directory.CreateDirectory(pathTo_dirToZip);
/* TODO - needs fixing */
File.WriteAllText(path_to_msg, msgbox.Text);
try
{
if (File.Exists(pathTo_dirToZip + "zipfile.zip"))
{
MessageBox.Show($"file exists: {pathTo_dirToZip + "zipfile.zip"}\ndeleting", "ayy");
File.Delete(pathTo_dirToZip + "zipfile.zip");
}
ZipFile.CreateFromDirectory(pathTo_dirToZip, pathTo_dirToZip + "zipfile.zip");
MessageBox.Show("great success!", "gj, zip created");
}
catch (IOException exception)
{
MessageBox.Show("error: " + exception.ToString(), "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
MessageBox.Show($"file exists: {pathTo_dirToZip + "zipfile.zip"}\ndeleting", "ayy");
File.Delete(pathTo_dirToZip + "zipfile.zip");
}
ZipFile.CreateFromDirectory(pathTo_dirToZip, pathTo_dirToZip + "zipfile.zip");
MessageBox.Show("great success!", "gj, zip created");
}
catch (IOException exception)
{
MessageBox.Show("error: " + exception.ToString(), "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
@ -191,36 +181,34 @@ namespace KRY_0x04
internal void do_unzip()
{
using (OpenFileDialog dlg = new OpenFileDialog())
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "choose a zip file to unzip";
dlg.Filter = "zip (*.zip)|*.zip|custom (*.*)|*.*";
if (dlg.ShowDialog() == DialogResult.OK)
{
dlg.Title = "choose a zip file to unzip";
dlg.Filter = "zip (*.zip)|*.zip|custom (*.*)|*.*";
if (dlg.ShowDialog() == DialogResult.OK)
string zipfile = dlg.FileName;
using (FolderBrowserDialog dlgg = new FolderBrowserDialog())
{
string zipfile = dlg.FileName;
using (FolderBrowserDialog dlgg = new FolderBrowserDialog())
dlgg.Description = "select folder to unzip the zip to yeeeaaah";
if (dlgg.ShowDialog() == DialogResult.OK)
{
dlgg.Description = "select folder to unzip the zip to yeeeaaah";
if (dlgg.ShowDialog() == DialogResult.OK)
string pathTo_UnzippedDir = dlgg.SelectedPath;
if (Directory.Exists(pathTo_UnzippedDir))
{
string pathTo_UnzippedDir = dlgg.SelectedPath;
pathTo_UnzippedDir = pathTo_UnzippedDir + "-NEW-" + DateTime.Now.ToString("yyyyMMddTHHmmss");
MessageBox.Show("dir exists, created a new one with the same name + date", "just so you know");
Directory.CreateDirectory(pathTo_UnzippedDir);
}
if (Directory.Exists(pathTo_UnzippedDir))
{
pathTo_UnzippedDir = pathTo_UnzippedDir + "-NEW-" + DateTime.Now.ToString("yyyyMMddTHHmmss");
MessageBox.Show("dir exists, created a new one with the same name + date", "just so you know");
Directory.CreateDirectory(pathTo_UnzippedDir);
}
try
{
ZipFile.ExtractToDirectory(zipfile, pathTo_UnzippedDir);
MessageBox.Show("great success!", "gj, archive unzipped");
}
catch (IOException exc)
{
MessageBox.Show("error: " + exc.ToString(), "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
try
{
ZipFile.ExtractToDirectory(zipfile, pathTo_UnzippedDir);
MessageBox.Show("great success!", "gj, archive unzipped");
}
catch (IOException exc)
{
MessageBox.Show("error: " + exc.ToString(), "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}