MainForm.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.IO.Compression;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using Y.Utils.DataUtils.EncryptUtils;
  13. using Y.Utils.IOUtils.FileUtils;
  14. using Y.Utils.IOUtils.PathUtils;
  15. namespace Oreo.FileMan.Views
  16. {
  17. public partial class MainForm : Form
  18. {
  19. FileCodeTool fct = new FileCodeTool();
  20. public MainForm()
  21. {
  22. InitializeComponent();
  23. }
  24. private void BtFileEncrypt_Click(object sender, EventArgs e)
  25. {
  26. string pwd = "123456789012";
  27. OpenFileDialog fileDialog = new OpenFileDialog();
  28. fileDialog.Title = "请选择要加密的文件";
  29. fileDialog.Filter = "所有文件|*.*";
  30. if (fileDialog.ShowDialog() == DialogResult.OK)
  31. {
  32. string file = fileDialog.FileName;
  33. if (File.Exists(file))
  34. {
  35. string newfile = file + ".fmk";
  36. if (!File.Exists(newfile))
  37. {
  38. int spendtime = 0;
  39. if ((spendtime = FileEncryptTool.Encrypt(file, newfile, pwd)) > 0)
  40. {
  41. MessageBox.Show("恭喜你,加密成功。共耗时:" + spendtime, "加密成功");
  42. }
  43. }
  44. else
  45. {
  46. MessageBox.Show("您选择的文件已存在加密文件", "??");
  47. }
  48. }
  49. }
  50. }
  51. private void BtFileDecrypt_Click(object sender, EventArgs e)
  52. {
  53. string pwd = "123456789012";
  54. string[] fileInfo = new string[128];
  55. OpenFileDialog fileDialog = new OpenFileDialog();
  56. fileDialog.Title = "请选择要解密的文件";
  57. fileDialog.Filter = "加密文件|*.fmk";
  58. if (fileDialog.ShowDialog() == DialogResult.OK)
  59. {
  60. string file = fileDialog.FileName;
  61. if (File.Exists(file))
  62. {
  63. string newfile = file.Substring(0, file.Length - ".fmk".Length);
  64. if (!File.Exists(newfile))
  65. {
  66. int spendtime = 0;
  67. if ((spendtime = FileEncryptTool.Decrypt(file, newfile, pwd)) > 0)
  68. {
  69. MessageBox.Show("恭喜你,解密成功。共耗时:" + spendtime, "解密成功");
  70. }
  71. }
  72. else
  73. {
  74. MessageBox.Show("您选择的文件已存在解密文件", "??");
  75. }
  76. }
  77. }
  78. }
  79. private void MainForm_Load(object sender, EventArgs e)
  80. {
  81. ////打包
  82. //Dictionary<string, object> dicToPack = new Dictionary<string, object>();
  83. ////dicToPack.Add("key1", Image.FromFile(@"D:\temp\测试打包\1511925984.jpeg"));
  84. ////dicToPack.Add("key2", Image.FromFile(@"D:\temp\测试打包\1555714799.jpeg"));
  85. //dicToPack.Add("key1", FilePackageTool.FileDeSerialize(@"D:\temp\测试打包\新建文件夹\新建文本文档 1.txt"));
  86. //dicToPack.Add("key2", FilePackageTool.FileDeSerialize(@"D:\temp\测试打包\新建文件夹\新建文本文档 2.txt"));
  87. //dicToPack.Add("key3", "hello world");
  88. //FilePackageTool.ResourcePackage(dicToPack, @"D:\temp\测试打包\pkg1.pkg");
  89. ////解包
  90. ////Dictionary<string, object> dicRcv = FilePackageTool.ResourceUnpack(@"D:\temp\测试打包\pkg1.pkg");
  91. }
  92. private void button2_Click(object sender, EventArgs e)
  93. {
  94. //string a = @"D:\Temp\测试压缩\Root\Plugin\NetAssist.exe";
  95. //FileCompressTool.Compress(a);
  96. //string b = @"D:\Temp\测试压缩\Root\Plugin\NetAssist.exe.gz";
  97. //FileCompressTool.Decompress(b);
  98. //FilePackageTool.Pack(@"D:\Temp\测试压缩\Root2", @"D:\Temp\测试压缩\Root2.pkg");
  99. FilePackageTool.Unpack(@"D:\Temp\测试压缩\Root2.pkg", @"D:\Temp\测试压缩\Root2");
  100. }
  101. }
  102. }