zip/unzip functionality [WIP]

This commit is contained in:
citizen 2019-12-18 11:26:59 +01:00
parent f1f176772d
commit 9a6317b1f7
Signed by: wanderer
GPG Key ID: A6FA3CA298BA2223
3 changed files with 71 additions and 3 deletions

8
Form1.Designer.cs generated
View File

@ -61,7 +61,7 @@
//
// button1
//
this.button1.Location = new System.Drawing.Point(467, 91);
this.button1.Location = new System.Drawing.Point(467, 120);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
@ -109,7 +109,7 @@
//
// button5
//
this.button5.Location = new System.Drawing.Point(558, 91);
this.button5.Location = new System.Drawing.Point(558, 120);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(75, 23);
this.button5.TabIndex = 9;
@ -191,6 +191,7 @@
this.button9.TabIndex = 17;
this.button9.Text = "zip";
this.button9.UseVisualStyleBackColor = true;
this.button9.Click += new System.EventHandler(this.button9_Click);
//
// button10
//
@ -200,11 +201,12 @@
this.button10.TabIndex = 18;
this.button10.Text = "unzip";
this.button10.UseVisualStyleBackColor = true;
this.button10.Click += new System.EventHandler(this.button10_Click);
//
// button12
//
this.button12.Enabled = false;
this.button12.Location = new System.Drawing.Point(713, 28);
this.button12.Location = new System.Drawing.Point(727, 342);
this.button12.Name = "button12";
this.button12.Size = new System.Drawing.Size(75, 23);
this.button12.TabIndex = 21;

View File

@ -4,6 +4,7 @@ using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
@ -203,5 +204,69 @@ namespace KRY_0x04
}
}
}
private void button9_Click(object sender, EventArgs e)
{
/* zip */
using (var dlg = new FolderBrowserDialog())
{
dlg.Description = "choose a folder to zip";
string pathTo_dirToZip = dlg.SelectedPath;
using (OpenFileDialog dlggg = new OpenFileDialog())
{
dlggg.Title = "where to save sha256sum";
string path_to_sha256sum = dlggg.FileName;
// VYTVORENI ADRESARE dirToZip
Directory.CreateDirectory(pathTo_dirToZip);
// VYTVORENI/ZAPIS SOUBORU sha256OfMessage.txt DO ADRESARE dirToZip
// OBSAHEM SOUBORU sha256OfMessage.txt je SHA256 OTISK SOUBORU, KTERY SE NACHAZI NA CESTE pathToMessageForTransfer
File.WriteAllText(path_to_sha256sum, sha256sum(textBox1.Text));
try
{
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "zipFile.zip"))
{
File.Delete(AppDomain.CurrentDomain.BaseDirectory + "zipFile.zip");
}
// VYTVORENI ZIP ARCHIVU zipFile.zip Z ADRESARE dirToZip
ZipFile.CreateFromDirectory(pathTo_dirToZip, AppDomain.CurrentDomain.BaseDirectory + "zipFile.zip");
}
catch (IOException exception)
{
MessageBox.Show("error: " + exception.ToString(), "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void button10_Click(object sender, EventArgs e)
{
/* unzip */
using (OpenFileDialog dlg = new OpenFileDialog())
{
string pathTo_UnzippedDir = Path.GetDirectoryName(dlg.FileName);
path = Path.GetDirectoryName(dlg.FileName);
dlg.Filter = "zip (*.zip)|*.zip|custom (*.*)|*.*";
if (Directory.Exists(pathTo_UnzippedDir))
{
Directory.Move(pathTo_UnzippedDir, pathTo_UnzippedDir + "-OLD");
}
try
{
ZipFile.ExtractToDirectory(dlg.FileName, pathTo_UnzippedDir);
}
catch (IOException exc)
{
MessageBox.Show("error: " + exc.ToString(), "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}

1
dsa.msg Normal file
View File

@ -0,0 +1 @@
hello world