|
|
@@ -5,11 +5,14 @@ using System.Management; |
|
|
|
using System.Net.NetworkInformation; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.IO; |
|
|
|
using System.Configuration; |
|
|
|
|
|
|
|
namespace CNAS_DBSync |
|
|
|
{ |
|
|
|
public partial class ActivationForm : Form |
|
|
|
{ |
|
|
|
private const string ACTIVATION_FILE = "activation.config"; |
|
|
|
|
|
|
|
public bool IsActivated { get; private set; } |
|
|
|
|
|
|
|
public ActivationForm() |
|
|
@@ -18,6 +21,39 @@ namespace CNAS_DBSync |
|
|
|
IsActivated = false; |
|
|
|
} |
|
|
|
|
|
|
|
// 检查是否已激活 |
|
|
|
public bool CheckActivation() |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
string activationPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ACTIVATION_FILE); |
|
|
|
if (File.Exists(activationPath)) |
|
|
|
{ |
|
|
|
string machineCode = GetMachineCode(); |
|
|
|
string savedMachineCode = File.ReadAllText(activationPath); |
|
|
|
return machineCode == savedMachineCode; |
|
|
|
} |
|
|
|
} |
|
|
|
catch |
|
|
|
{ |
|
|
|
// 如果读取失败,返回未激活状态 |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
private void SaveActivation() |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
string activationPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ACTIVATION_FILE); |
|
|
|
File.WriteAllText(activationPath, GetMachineCode()); |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
MessageBox.Show($"保存激活状态失败:{ex.Message}", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void btnActivate_Click(object sender, EventArgs e) |
|
|
|
{ |
|
|
|
string activationCode = txtActivationCode.Text.Trim(); |
|
|
@@ -32,6 +68,7 @@ namespace CNAS_DBSync |
|
|
|
if (ValidateActivationCode(activationCode)) |
|
|
|
{ |
|
|
|
IsActivated = true; |
|
|
|
SaveActivation(); // 保存激活状态 |
|
|
|
this.DialogResult = DialogResult.OK; |
|
|
|
this.Close(); |
|
|
|
} |
|
|
|