|
|
@@ -10,6 +10,7 @@ using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows.Forms;
|
|
|
+using System.Xml.Linq;
|
|
|
using Y.Utils.DataUtils.EncryptUtils;
|
|
|
using Y.Utils.IOUtils.FileUtils;
|
|
|
using Y.Utils.IOUtils.PathUtils;
|
|
|
@@ -39,11 +40,14 @@ namespace Oreo.FileMan.Views
|
|
|
|
|
|
if (!File.Exists(newfile))
|
|
|
{
|
|
|
- int spendtime = 0;
|
|
|
- if ((spendtime = FileEncryptTool.Encrypt(file, newfile, pwd)) > 0)
|
|
|
+ Task.Factory.StartNew(() =>
|
|
|
{
|
|
|
- MessageBox.Show("恭喜你,加密成功。共耗时:" + spendtime, "加密成功");
|
|
|
- }
|
|
|
+ int spendtime = 0;
|
|
|
+ if ((spendtime = FileEncryptTool.Encrypt(file, newfile, pwd, UIProgress)) > 0)
|
|
|
+ {
|
|
|
+ MessageBox.Show("恭喜你,加密成功。共耗时:" + spendtime, "加密成功");
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -68,11 +72,14 @@ namespace Oreo.FileMan.Views
|
|
|
string newfile = file.Substring(0, file.Length - ".fmk".Length);
|
|
|
if (!File.Exists(newfile))
|
|
|
{
|
|
|
- int spendtime = 0;
|
|
|
- if ((spendtime = FileEncryptTool.Decrypt(file, newfile, pwd)) > 0)
|
|
|
+ Task.Factory.StartNew(() =>
|
|
|
{
|
|
|
- MessageBox.Show("恭喜你,解密成功。共耗时:" + spendtime, "解密成功");
|
|
|
- }
|
|
|
+ int spendtime = 0;
|
|
|
+ if ((spendtime = FileEncryptTool.Decrypt(file, newfile, pwd, UIProgress)) > 0)
|
|
|
+ {
|
|
|
+ MessageBox.Show("恭喜你,解密成功。共耗时:" + spendtime, "解密成功");
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -84,50 +91,71 @@ namespace Oreo.FileMan.Views
|
|
|
|
|
|
private void MainForm_Load(object sender, EventArgs e)
|
|
|
{
|
|
|
- bool flag = CanUpdate();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void button2_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
- int flag = FilePackageTool.Pack(@"D:\temp\测试打包\新建文件夹", @"D:\temp\测试打包\新建文件夹.pkg");
|
|
|
- if (flag > 0)
|
|
|
- MessageBox.Show("打包成功");
|
|
|
+ Task.Factory.StartNew(() =>
|
|
|
+ {
|
|
|
+ int flag = FilePackageTool.Pack(@"D:\Temp\测试压缩\Root", @"D:\Temp\测试压缩\Root.pkg", UIProgress);
|
|
|
+ if (flag > 0)
|
|
|
+ MessageBox.Show("打包成功");
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
- int flag = FilePackageTool.Unpack(@"D:\temp\测试打包\新建文件夹.pkg", @"D:\temp\测试打包\新建文件夹");
|
|
|
- if (flag > 0)
|
|
|
- MessageBox.Show("拆包成功");
|
|
|
+ Task.Factory.StartNew(() =>
|
|
|
+ {
|
|
|
+ int flag = FilePackageTool.Unpack(@"D:\Temp\测试压缩\Root.pkg", @"D:\Temp\测试压缩\Root", UIProgress);
|
|
|
+ if (flag > 0)
|
|
|
+ MessageBox.Show("拆包成功");
|
|
|
+ });
|
|
|
+ }
|
|
|
+ private void UIProgress(long current, long total)
|
|
|
+ {
|
|
|
+ BeginInvoke(new Action(() =>
|
|
|
+ {
|
|
|
+ progressBar1.Maximum = 100;
|
|
|
+ progressBar1.Value = (int)(current * 100 / total);
|
|
|
+ }));
|
|
|
}
|
|
|
|
|
|
private bool CanUpdate()
|
|
|
{
|
|
|
+ string file = AppDomain.CurrentDomain.BaseDirectory + "Settings";
|
|
|
string key = "TodayUpdateTimes";
|
|
|
DateTime today = DateTime.Parse(string.Format("{0}-{1}-{2} 00:00:00", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day));
|
|
|
DateTime setday = today;
|
|
|
|
|
|
//读取配置
|
|
|
- string temp = ConfigurationManager.AppSettings[key];
|
|
|
+ string temp = CanUpdateGetConfig(file, key);
|
|
|
if (DateTime.TryParse(temp, out setday) && setday >= today && setday <= today.AddDays(1))
|
|
|
{
|
|
|
if (setday.Hour < 3)
|
|
|
- CanUpdateSetConfig(key, setday.AddHours(1).ToString());//累加hour记录次数
|
|
|
+ CanUpdateSetConfig(file, key, setday.AddHours(1).ToString());//累加hour记录次数
|
|
|
else
|
|
|
return false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//配置失效,设置为默认值
|
|
|
- CanUpdateSetConfig(key, today.ToString());
|
|
|
+ CanUpdateSetConfig(file, key, today.ToString());
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
- private bool CanUpdateSetConfig(string key, string value)
|
|
|
+ private bool CanUpdateSetConfig(string file, string key, string value)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
|
|
+ //文件不存在则创建
|
|
|
+ if (!File.Exists(file + ".config"))
|
|
|
+ {
|
|
|
+ XElement xe = new XElement("configuration");
|
|
|
+ xe.Save(file + ".config");
|
|
|
+ }
|
|
|
+ Configuration config = ConfigurationManager.OpenExeConfiguration(file);
|
|
|
if (config.AppSettings.Settings.AllKeys.Contains(key))
|
|
|
{
|
|
|
config.AppSettings.Settings[key].Value = value;
|
|
|
@@ -137,13 +165,25 @@ namespace Oreo.FileMan.Views
|
|
|
config.AppSettings.Settings.Add(key, value);
|
|
|
}
|
|
|
config.Save(ConfigurationSaveMode.Modified);
|
|
|
- ConfigurationManager.RefreshSection("appSettings");
|
|
|
return true;
|
|
|
}
|
|
|
- catch
|
|
|
+ catch (Exception e)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
+ private string CanUpdateGetConfig(string file, string key)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ Configuration config = ConfigurationManager.OpenExeConfiguration(file);
|
|
|
+ if (config.AppSettings.Settings.AllKeys.Contains(key))
|
|
|
+ {
|
|
|
+ return config.AppSettings.Settings[key].Value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception e) { }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|
|
|
}
|