Реализован базовый функционал редактора конфигов
Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
This commit is contained in:
125
ConfigEditor/MainForm.Designer.cs
generated
125
ConfigEditor/MainForm.Designer.cs
generated
@@ -30,15 +30,15 @@
|
||||
{
|
||||
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
|
||||
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
|
||||
this.файлToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.открытьToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.сохранитьToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.сохранитьКакToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.saveAsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
|
||||
this.сгенерироватьMD5ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.generateMD5ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
|
||||
this.закрытьФайлToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.закрытьToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.closeFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.closeProgramToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@@ -55,77 +55,89 @@
|
||||
// menuStrip1
|
||||
//
|
||||
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.файлToolStripMenuItem});
|
||||
this.fileToolStripMenuItem});
|
||||
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip1.Name = "menuStrip1";
|
||||
this.menuStrip1.Size = new System.Drawing.Size(800, 24);
|
||||
this.menuStrip1.TabIndex = 1;
|
||||
this.menuStrip1.Text = "menuStrip1";
|
||||
//
|
||||
// файлToolStripMenuItem
|
||||
// fileToolStripMenuItem
|
||||
//
|
||||
this.файлToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.открытьToolStripMenuItem,
|
||||
this.сохранитьToolStripMenuItem,
|
||||
this.сохранитьКакToolStripMenuItem,
|
||||
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.openToolStripMenuItem,
|
||||
this.saveToolStripMenuItem,
|
||||
this.saveAsToolStripMenuItem,
|
||||
this.toolStripSeparator1,
|
||||
this.сгенерироватьMD5ToolStripMenuItem,
|
||||
this.generateMD5ToolStripMenuItem,
|
||||
this.toolStripSeparator2,
|
||||
this.закрытьФайлToolStripMenuItem,
|
||||
this.закрытьToolStripMenuItem});
|
||||
this.файлToolStripMenuItem.Name = "файлToolStripMenuItem";
|
||||
this.файлToolStripMenuItem.Size = new System.Drawing.Size(48, 20);
|
||||
this.файлToolStripMenuItem.Text = "Файл";
|
||||
this.closeFileToolStripMenuItem,
|
||||
this.closeProgramToolStripMenuItem});
|
||||
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
|
||||
this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
|
||||
this.fileToolStripMenuItem.Text = "File";
|
||||
//
|
||||
// открытьToolStripMenuItem
|
||||
// openToolStripMenuItem
|
||||
//
|
||||
this.открытьToolStripMenuItem.Name = "открытьToolStripMenuItem";
|
||||
this.открытьToolStripMenuItem.Size = new System.Drawing.Size(185, 22);
|
||||
this.открытьToolStripMenuItem.Text = "Открыть";
|
||||
this.открытьToolStripMenuItem.Click += new System.EventHandler(this.открытьToolStripMenuItem_Click);
|
||||
this.openToolStripMenuItem.Name = "openToolStripMenuItem";
|
||||
this.openToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O)));
|
||||
this.openToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.openToolStripMenuItem.Text = "Open";
|
||||
this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click);
|
||||
//
|
||||
// сохранитьToolStripMenuItem
|
||||
// saveToolStripMenuItem
|
||||
//
|
||||
this.сохранитьToolStripMenuItem.Name = "сохранитьToolStripMenuItem";
|
||||
this.сохранитьToolStripMenuItem.Size = new System.Drawing.Size(185, 22);
|
||||
this.сохранитьToolStripMenuItem.Text = "Сохранить";
|
||||
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
|
||||
this.saveToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S)));
|
||||
this.saveToolStripMenuItem.Size = new System.Drawing.Size(241, 22);
|
||||
this.saveToolStripMenuItem.Text = "Save";
|
||||
this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click);
|
||||
//
|
||||
// сохранитьКакToolStripMenuItem
|
||||
// saveAsToolStripMenuItem
|
||||
//
|
||||
this.сохранитьКакToolStripMenuItem.Name = "сохранитьКакToolStripMenuItem";
|
||||
this.сохранитьКакToolStripMenuItem.Size = new System.Drawing.Size(185, 22);
|
||||
this.сохранитьКакToolStripMenuItem.Text = "Сохранить как...";
|
||||
this.saveAsToolStripMenuItem.Name = "saveAsToolStripMenuItem";
|
||||
this.saveAsToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)(((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Shift)
|
||||
| System.Windows.Forms.Keys.S)));
|
||||
this.saveAsToolStripMenuItem.Size = new System.Drawing.Size(241, 22);
|
||||
this.saveAsToolStripMenuItem.Text = "Save As...";
|
||||
this.saveAsToolStripMenuItem.Click += new System.EventHandler(this.saveAsToolStripMenuItem_Click);
|
||||
//
|
||||
// toolStripSeparator1
|
||||
//
|
||||
this.toolStripSeparator1.Name = "toolStripSeparator1";
|
||||
this.toolStripSeparator1.Size = new System.Drawing.Size(182, 6);
|
||||
this.toolStripSeparator1.Size = new System.Drawing.Size(177, 6);
|
||||
//
|
||||
// сгенерироватьMD5ToolStripMenuItem
|
||||
// generateMD5ToolStripMenuItem
|
||||
//
|
||||
this.сгенерироватьMD5ToolStripMenuItem.Name = "сгенерироватьMD5ToolStripMenuItem";
|
||||
this.сгенерироватьMD5ToolStripMenuItem.Size = new System.Drawing.Size(185, 22);
|
||||
this.сгенерироватьMD5ToolStripMenuItem.Text = "Сгенерировать MD5";
|
||||
this.generateMD5ToolStripMenuItem.Name = "generateMD5ToolStripMenuItem";
|
||||
this.generateMD5ToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.G)));
|
||||
this.generateMD5ToolStripMenuItem.Size = new System.Drawing.Size(241, 22);
|
||||
this.generateMD5ToolStripMenuItem.Text = "Generate MD5";
|
||||
this.generateMD5ToolStripMenuItem.Click += new System.EventHandler(this.generateMD5ToolStripMenuItem_Click);
|
||||
//
|
||||
// toolStripSeparator2
|
||||
//
|
||||
this.toolStripSeparator2.Name = "toolStripSeparator2";
|
||||
this.toolStripSeparator2.Size = new System.Drawing.Size(182, 6);
|
||||
this.toolStripSeparator2.Size = new System.Drawing.Size(177, 6);
|
||||
//
|
||||
// закрытьФайлToolStripMenuItem
|
||||
// closeFileToolStripMenuItem
|
||||
//
|
||||
this.закрытьФайлToolStripMenuItem.Name = "закрытьФайлToolStripMenuItem";
|
||||
this.закрытьФайлToolStripMenuItem.Size = new System.Drawing.Size(185, 22);
|
||||
this.закрытьФайлToolStripMenuItem.Text = "Закрыть файл";
|
||||
this.closeFileToolStripMenuItem.Name = "closeFileToolStripMenuItem";
|
||||
this.closeFileToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Q)));
|
||||
this.closeFileToolStripMenuItem.Size = new System.Drawing.Size(241, 22);
|
||||
this.closeFileToolStripMenuItem.Text = "Close file";
|
||||
this.closeFileToolStripMenuItem.Click += new System.EventHandler(this.closeFileToolStripMenuItem_Click);
|
||||
//
|
||||
// закрытьToolStripMenuItem
|
||||
// closeProgramToolStripMenuItem
|
||||
//
|
||||
this.закрытьToolStripMenuItem.Name = "закрытьToolStripMenuItem";
|
||||
this.закрытьToolStripMenuItem.Size = new System.Drawing.Size(185, 22);
|
||||
this.закрытьToolStripMenuItem.Text = "Закрыть";
|
||||
this.закрытьToolStripMenuItem.Click += new System.EventHandler(this.закрытьToolStripMenuItem_Click);
|
||||
this.closeProgramToolStripMenuItem.Name = "closeProgramToolStripMenuItem";
|
||||
this.closeProgramToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)(((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Shift)
|
||||
| System.Windows.Forms.Keys.Q)));
|
||||
this.closeProgramToolStripMenuItem.Size = new System.Drawing.Size(209, 22);
|
||||
this.closeProgramToolStripMenuItem.Text = "Close";
|
||||
this.closeProgramToolStripMenuItem.Click += new System.EventHandler(this.closeToolStripMenuItem_Click);
|
||||
//
|
||||
// Form1
|
||||
// MainForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
@@ -133,8 +145,9 @@
|
||||
this.Controls.Add(this.richTextBox1);
|
||||
this.Controls.Add(this.menuStrip1);
|
||||
this.MainMenuStrip = this.menuStrip1;
|
||||
this.Name = "Form1";
|
||||
this.Name = "MainForm";
|
||||
this.Text = "SaveWizard Config Editor";
|
||||
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.MainForm_FormClosed);
|
||||
this.menuStrip1.ResumeLayout(false);
|
||||
this.menuStrip1.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
@@ -146,15 +159,15 @@
|
||||
|
||||
private System.Windows.Forms.RichTextBox richTextBox1;
|
||||
private System.Windows.Forms.MenuStrip menuStrip1;
|
||||
private System.Windows.Forms.ToolStripMenuItem файлToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem открытьToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem сохранитьToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem сохранитьКакToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem saveToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem saveAsToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
|
||||
private System.Windows.Forms.ToolStripMenuItem сгенерироватьMD5ToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem generateMD5ToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
|
||||
private System.Windows.Forms.ToolStripMenuItem закрытьФайлToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem закрытьToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem closeFileToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem closeProgramToolStripMenuItem;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,21 @@
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ConfigEditor
|
||||
{
|
||||
public partial class MainForm: Form
|
||||
{
|
||||
private string opened_file = null;
|
||||
|
||||
public MainForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void открытьToolStripMenuItem_Click(object sender, System.EventArgs e)
|
||||
private void openToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
OpenFileDialog ofd = new OpenFileDialog()
|
||||
{
|
||||
@@ -19,11 +24,81 @@ namespace ConfigEditor
|
||||
Multiselect = false
|
||||
};
|
||||
if (ofd.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
opened_file = ofd.FileName;
|
||||
richTextBox1.Text = File.ReadAllText(ofd.FileName);
|
||||
}
|
||||
}
|
||||
|
||||
private void закрытьToolStripMenuItem_Click(object sender, System.EventArgs e)
|
||||
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
File.WriteAllText(opened_file, richTextBox1.Text);
|
||||
}
|
||||
|
||||
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
SaveFileDialog sfd = new SaveFileDialog
|
||||
{
|
||||
Title = "Сохранить файл конфигурации",
|
||||
Filter = "Файл *.json|*.json"
|
||||
};
|
||||
if (sfd.ShowDialog() == DialogResult.OK)
|
||||
File.WriteAllText(sfd.FileName, richTextBox1.Text);
|
||||
}
|
||||
|
||||
private void generateMD5ToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
using (var md5 = MD5.Create())
|
||||
{
|
||||
using (FileStream stream = File.OpenRead(opened_file))
|
||||
md5.ComputeHash(stream);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
byte[] hash = md5.Hash;
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
sb.Append(hash[i].ToString("x2"));
|
||||
|
||||
Clipboard.SetText(sb.ToString());
|
||||
MessageBox.Show($"Hash successfully copied into your clipboard.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
}
|
||||
|
||||
private bool CheckChanges()
|
||||
{
|
||||
if (richTextBox1.Text != File.ReadAllText(opened_file))
|
||||
{
|
||||
DialogResult result = MessageBox.Show("The document has been modified.\nDo you want to save your changes?", "Question", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
File.WriteAllText(opened_file, richTextBox1.Text);
|
||||
MessageBox.Show("File successfully saved.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
return true;
|
||||
}
|
||||
else if (result == DialogResult.Cancel)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void closeFileToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!CheckChanges())
|
||||
return;
|
||||
richTextBox1.Clear();
|
||||
opened_file = null;
|
||||
}
|
||||
|
||||
private void closeToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!CheckChanges())
|
||||
return;
|
||||
Application.Exit();
|
||||
}
|
||||
|
||||
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
|
||||
{
|
||||
if (!CheckChanges())
|
||||
return;
|
||||
Application.Exit();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user