|
@@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|
|
using System.Diagnostics;
|
|
|
using System.Diagnostics.Eventing.Reader;
|
|
|
using System.Drawing;
|
|
|
+using System.Globalization;
|
|
|
using System.IO;
|
|
|
using System.IO.Ports;
|
|
|
using System.Linq;
|
|
@@ -270,23 +271,7 @@ namespace Welling_Motor_Debug_Tool
|
|
|
//端口初始化
|
|
|
mySerialProcess.Init();
|
|
|
toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
|
|
|
-
|
|
|
- //检查备忘录文件
|
|
|
- if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
|
|
|
- {
|
|
|
- System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.NoteFileName, "");
|
|
|
- }
|
|
|
-
|
|
|
- //检验流水号记录文件
|
|
|
- if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName1))
|
|
|
- {
|
|
|
- System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, "0");
|
|
|
- }
|
|
|
- if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName2))
|
|
|
- {
|
|
|
- System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, "0");
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
//检查文件夹
|
|
|
if (!Directory.Exists(localInfo.LocalPath))
|
|
|
{
|
|
@@ -305,6 +290,22 @@ namespace Welling_Motor_Debug_Tool
|
|
|
Directory.CreateDirectory(localInfo.LocalPath + localInfo.CfgPathName);
|
|
|
}
|
|
|
|
|
|
+ //检查备忘录文件
|
|
|
+ if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.NoteFileName))
|
|
|
+ {
|
|
|
+ System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.NoteFileName, "");
|
|
|
+ }
|
|
|
+
|
|
|
+ //检验流水号记录文件
|
|
|
+ if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName1))
|
|
|
+ {
|
|
|
+ System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName1, "0");
|
|
|
+ }
|
|
|
+ if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.SerialNumFileName2))
|
|
|
+ {
|
|
|
+ System.IO.File.WriteAllText(localInfo.LocalPath + localInfo.SerialNumFileName2, "0");
|
|
|
+ }
|
|
|
+
|
|
|
//服务器初始化
|
|
|
do
|
|
|
{
|
|
@@ -365,6 +366,70 @@ namespace Welling_Motor_Debug_Tool
|
|
|
scan_form.ShowDialog();
|
|
|
if (scan_form.textBox_Scan.Text == "ttium.123")
|
|
|
{
|
|
|
+ //检查许可
|
|
|
+ if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.OffLineUseKeyFileName)) //未许可
|
|
|
+ {
|
|
|
+ if (MessageBox.Show("无离线授权,请导入许可文件!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
|
|
|
+ {
|
|
|
+ Licences myLicences = new Licences();
|
|
|
+ myLicences.ShowDialog();
|
|
|
+ //从许可文件读取内容
|
|
|
+ string str_lic = aes.DecryptFromFile(myLicences.textBox_LicencePath.Text, "2D820F88F60A39D5", "3687C5216B19D16B");
|
|
|
+ string PC_Code = PC_Information.GetCPUSerialNumber();
|
|
|
+ if (PC_Code == str_lic) //授权码正确
|
|
|
+ {
|
|
|
+ aes.EncryptToFile(PC_Code, localInfo.LocalPath + localInfo.OffLineUseKeyFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
|
|
|
+ string strInfo = "";
|
|
|
+ strInfo = "0;" + DateTime.Now.ToString("yyyyMMdd");
|
|
|
+ aes.EncryptToFile(strInfo, localInfo.LocalPath + localInfo.OfflineUseLogFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
|
|
|
+ }
|
|
|
+ else //授权码错误
|
|
|
+ {
|
|
|
+ MessageBox.Show("许可文件无效,请联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
+ System.Environment.Exit(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ System.Environment.Exit(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else //已授权
|
|
|
+ {
|
|
|
+ string str_Key = aes.DecryptFromFile(localInfo.LocalPath + localInfo.OffLineUseKeyFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
|
|
|
+ //判断授权是否正确
|
|
|
+ if (PC_Information.GetCPUSerialNumber() == str_Key) //授权正确
|
|
|
+ {
|
|
|
+ //检查离线使用记录文件
|
|
|
+ if (!System.IO.File.Exists(localInfo.LocalPath + localInfo.OfflineUseLogFileName))
|
|
|
+ {
|
|
|
+ MessageBox.Show("许可文件内容缺失,请联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
+ System.Environment.Exit(0);
|
|
|
+ }
|
|
|
+ //获取离线使用记录并更新
|
|
|
+ string UseLog = aes.DecryptFromFile(localInfo.LocalPath + localInfo.OfflineUseLogFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
|
|
|
+ UInt32 UseTimes = Convert.ToUInt32(UseLog.Split(';')[0]);
|
|
|
+ UseTimes++;
|
|
|
+ string str = UseTimes.ToString() + ";" + UseLog.Split(';')[1];
|
|
|
+ aes.EncryptToFile(str, localInfo.LocalPath + localInfo.OfflineUseLogFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
|
|
|
+ //判断授权期限
|
|
|
+ DateTime DataOrigin = new DateTime();
|
|
|
+ DateTime.TryParseExact(UseLog.Split(';')[1], "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out DataOrigin);
|
|
|
+ DateTime DataEnd = DataOrigin.AddDays(90);
|
|
|
+ DateTime NowDate = DateTime.Now.Date;
|
|
|
+ if ((NowDate > DataEnd) || (UseTimes > 1000)) //第一次打开软件90天内,或1000次内
|
|
|
+ {
|
|
|
+ MessageBox.Show("离线授权过期,请联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
+ System.Environment.Exit(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MessageBox.Show("离线授权错误,请联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
+ System.Environment.Exit(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
OfflineFlag = true;
|
|
|
checkBox_OffLineFacMode.Checked = true;
|
|
|
checkBox_OffLineCheckMode.Checked = true;
|