123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383 |
- using AILicenseGenerator.Helper;
- using AILicenseGenerator.Models;
- using Microsoft.Win32;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Text.Json;
- using System.Windows;
- using Vinno.AI.CommonSDK.Enums;
- namespace AILicenseGenerator
- {
- /// <summary>
- /// MainWindow.xaml 的交互逻辑
- /// </summary>
- public partial class MainWindow : Window
- {
- private const string _logFolderName = "AILicenseGeneratorLogs";
- private const string _generateFolderName = "GenerateFolder";
- private const string _functionSettingFile = "FunctionInfo.ini";
- private const string _licenseFileNameWithWildcard = "*****License.lic";
- private readonly string _version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
- private readonly string _generateFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _generateFolderName);
- private List<AIFunctionInfoDTO> _enabledFunctionList = new List<AIFunctionInfoDTO>();
- private List<AIFunctionInfoDTO> _functionList = new List<AIFunctionInfoDTO>();
- private List<AIFunctionInfoDTO> _functionListForAllEnginesVersion = new List<AIFunctionInfoDTO>();
- public MainWindow()
- {
- InitializeComponent();
- Title = "AILicenseGenerator_" + _version;
- Logger.LogDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _logFolderName);
- TranslateHelper.Init(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "Chinese.json"));
- FunctionInit();
- AllFunctionListForAllEnginesVersionInit();
- if (AllFunctionEnableCheckBox.IsChecked == false)
- {
- FunctionDataGrid.ItemsSource = _functionList;
- }
- else
- {
- FunctionDataGrid.ItemsSource = _functionListForAllEnginesVersion;
- }
- this.DataContext = this;
- }
- private void FunctionInit()
- {
- var functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(AIDiagnosisSDK.AIDiagnosis.AllFunctions);
- if (functions != null)
- {
- _functionList.AddRange(functions);
- }
- functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(MyocardialDiagnosisSDK.MyocardialDiagnosis.AllFunctions);
- if (functions != null)
- {
- _functionList.AddRange(functions);
- }
- functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(ThyroidClassificationSDK.ThyroidClassification.AllFunctions);
- if (functions != null)
- {
- _functionList.AddRange(functions);
- }
- functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(AutoEFDiagnosisSDK.AutoEFDiagnosis.AllFunctions);
- if (functions != null)
- {
- _functionList.AddRange(functions);
- }
- functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(AutoIVCDiagnosisSDK.AutoIVCDiagnosis.AllFunctions);
- if (functions != null)
- {
- _functionList.AddRange(functions);
- }
- functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(AutoVTIDiagnosisSDK.AutoVTIDiagnosis.AllFunctions);
- if (functions != null)
- {
- _functionList.AddRange(functions);
- }
- functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(HepatoRenalRatioDiagnosisSDK.HepatoRenalRatioDiagnosis.AllFunctions);
- if (functions != null)
- {
- _functionList.AddRange(functions);
- }
- functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(VetHeartDiagnosisSDK.VetHeartDiagnosis.AllFunctions);
- if(functions!=null)
- {
- _functionList.AddRange(functions);
- }
- functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(CarotidClassificationSDK.CarotidClassification.AllFunctions);
- if (functions != null)
- {
- _functionList.AddRange(functions);
- }
- functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(AmnioticFluidDiagnosisSDK.AmnioticFluidDiagnosis.AllFunctions);
- if (functions != null)
- {
- _functionList.AddRange(functions);
- }
- functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(AutoDFRDiagnosisSDK.AutoDFRDiagnosis.AllFunctions);
- if (functions != null)
- {
- _functionList.AddRange(functions);
- }
- functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(NerveIdentificationSDK.NerveIdentification.AllFunctions);
- if (functions != null)
- {
- _functionList.AddRange(functions);
- }
- functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(AutoBLineDiagnosisSDK.AutoBLineDiagnosis.AllFunctions);
- if (functions != null)
- {
- _functionList.AddRange(functions);
- }
- functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(FatLayerIdentificationSDK.FatLayerIdentification.AllFunctions);
- if (functions != null)
- {
- _functionList.AddRange(functions);
- }
- }
- private void AllFunctionListForAllEnginesVersionInit()
- {
- var functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(AIDiagnosisSDK.AIDiagnosis.AllFunctions);
- if(functions!=null)
- {
- _functionListForAllEnginesVersion.AddRange(functions);
- }
- functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(MyocardialDiagnosisSDK.MyocardialDiagnosis.AllFunctions);
- if (functions != null)
- {
- _functionListForAllEnginesVersion.AddRange(functions);
- }
- functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(ThyroidClassificationSDK.ThyroidClassification.AllFunctions);
- if (functions != null)
- {
- _functionListForAllEnginesVersion.AddRange(functions);
- }
- functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(AutoEFDiagnosisSDK.AutoEFDiagnosis.AllFunctions);
- if (functions != null)
- {
- _functionListForAllEnginesVersion.AddRange(functions);
- }
- functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(AutoIVCDiagnosisSDK.AutoIVCDiagnosis.AllFunctions);
- if (functions != null)
- {
- _functionListForAllEnginesVersion.AddRange(functions);
- }
- functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(AutoVTIDiagnosisSDK.AutoVTIDiagnosis.AllFunctions);
- if (functions != null)
- {
- _functionListForAllEnginesVersion.AddRange(functions);
- }
- functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(HepatoRenalRatioDiagnosisSDK.HepatoRenalRatioDiagnosis.AllFunctions);
- if (functions != null)
- {
- _functionListForAllEnginesVersion.AddRange(functions);
- }
- functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(VetHeartDiagnosisSDK.VetHeartDiagnosis.AllFunctions);
- if (functions != null)
- {
- _functionListForAllEnginesVersion.AddRange(functions);
- }
- functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(CarotidClassificationSDK.CarotidClassification.AllFunctions);
- if (functions != null)
- {
- _functionListForAllEnginesVersion.AddRange(functions);
- }
- functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(AmnioticFluidDiagnosisSDK.AmnioticFluidDiagnosis.AllFunctions);
- if (functions != null)
- {
- _functionListForAllEnginesVersion.AddRange(functions);
- }
- functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(AutoDFRDiagnosisSDK.AutoDFRDiagnosis.AllFunctions);
- if (functions != null)
- {
- _functionListForAllEnginesVersion.AddRange(functions);
- }
- functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(NerveIdentificationSDK.NerveIdentification.AllFunctions);
- if (functions != null)
- {
- _functionListForAllEnginesVersion.AddRange(functions);
- }
- functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(AutoBLineDiagnosisSDK.AutoBLineDiagnosis.AllFunctions);
- if (functions != null)
- {
- _functionListForAllEnginesVersion.AddRange(functions);
- }
- functions = AIConvertHelper.ConvertListFunctionInfoToListAIFunctionInfoDTO(FatLayerIdentificationSDK.FatLayerIdentification.AllFunctions);
- if (functions != null)
- {
- _functionListForAllEnginesVersion.AddRange(functions);
- }
- foreach (var function in _functionListForAllEnginesVersion)
- {
- function.Version = "All";
- foreach (var enigne in function.Engines)
- {
- enigne.Version = "All";
- }
- }
- }
- private void FunctionSettingButton_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- PreGeneration();
- var jsonString = JsonSerializer.Serialize(_enabledFunctionList, new JsonSerializerOptions
- {
- WriteIndented = true,
- });
- var filePath = Path.Combine(_generateFolderPath, _functionSettingFile);
- File.WriteAllText(filePath, jsonString);
- PostGeneration(_generateFolderPath);
- MessageBox.Show($"配置文件生成成功", "提示");
- }
- catch (Exception ex)
- {
- MessageBox.Show($"配置文件生成出错,{ex}", "提示");
- }
- }
- private void PreGeneration()
- {
- DirectoryHelper.DeleteDirectory(_generateFolderPath);
- DirectoryHelper.CreateDirectory(_generateFolderPath);
- GetEnabledFunctions();
- }
- private void GetEnabledFunctions()
- {
- _enabledFunctionList.Clear();
- if (AllFunctionEnableCheckBox.IsChecked == true)
- {
- var enableFunctions = _functionListForAllEnginesVersion.Where(x => x.IsEnabled).ToList();
- foreach (var function in enableFunctions)
- {
- var enabledEngines = function.Engines.Where(x => x.IsEnabled).ToList();
- _enabledFunctionList.Add(new AIFunctionInfoDTO(function.FunctionName, function.IsEnabled, function.Version, function.ExpiredTime, enabledEngines));
- }
- }
- else
- {
- var enableFunctions = _functionList.Where(x => x.IsEnabled).ToList();
- foreach (var function in enableFunctions)
- {
- var enabledEngines = function.Engines.Where(x => x.IsEnabled).ToList();
- _enabledFunctionList.Add(new AIFunctionInfoDTO(function.FunctionName, function.IsEnabled, function.Version, function.ExpiredTime, enabledEngines));
- }
- }
- }
- private void PostGeneration(string path)
- {
- using (Process process = new Process())
- {
- ProcessStartInfo psi = new ProcessStartInfo("Explorer.exe");
- psi.Arguments = path;
- process.StartInfo = psi;
- process.Start();
- }
- }
- private void LicenseButton_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- PreGeneration();
- if (_enabledFunctionList != null)
- {
- foreach (var function in _enabledFunctionList)
- {
- if (Enum.TryParse(function.FunctionName, out AIEnumType type))
- {
- var licenseFileName = _licenseFileNameWithWildcard.Replace("*****", type.ToString());
- var jsonString = JsonSerializer.Serialize(function, new JsonSerializerOptions
- {
- WriteIndented = true,
- });
- var desString = DesBuilder.Encrypt(jsonString);
- var filePath = Path.Combine(_generateFolderPath, licenseFileName);
- File.WriteAllText(filePath, desString);
- }
- }
- }
- PostGeneration(_generateFolderPath);
- MessageBox.Show($"License生成成功", "提示");
- }
- catch (Exception ex)
- {
- MessageBox.Show($"License生成出错,{ex}", "提示");
- }
- }
- private void GenerateButton_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- PreGeneration();
- var jsonString = JsonSerializer.Serialize(_enabledFunctionList, new JsonSerializerOptions
- {
- WriteIndented = true,
- });
- var filePath = Path.Combine(_generateFolderPath, _functionSettingFile);
- File.WriteAllText(filePath, jsonString);
- if (_enabledFunctionList != null)
- {
- foreach (var function in _enabledFunctionList)
- {
- if (Enum.TryParse(function.FunctionName, out AIEnumType type))
- {
- var licenseFileName = _licenseFileNameWithWildcard.Replace("*****", type.ToString());
- jsonString = JsonSerializer.Serialize(function, new JsonSerializerOptions
- {
- WriteIndented = true,
- });
- var desString = DesBuilder.Encrypt(jsonString);
- filePath = Path.Combine(_generateFolderPath, licenseFileName);
- File.WriteAllText(filePath, desString);
- }
- }
- }
- PostGeneration(_generateFolderPath);
- MessageBox.Show($"全部生成成功", "提示");
- }
- catch (Exception ex)
- {
- MessageBox.Show($"全部生成出错,{ex}", "提示");
- }
- }
- private void AllFunctionEnable_Click(object sender, RoutedEventArgs e)
- {
- if (AllFunctionEnableCheckBox.IsChecked == false)
- {
- FunctionDataGrid.ItemsSource = _functionList;
- }
- else
- {
- FunctionDataGrid.ItemsSource = _functionListForAllEnginesVersion;
- }
- }
- private void LicenseDecryptButton_Click(object sender, RoutedEventArgs e)
- {
- OpenFileDialog openFileDialog = new OpenFileDialog
- {
- Filter = "License文件|*.lic",
- Multiselect = true,
- Title = "选择License文件"
- };
- if (openFileDialog.ShowDialog() ?? false)
- {
- var files = openFileDialog.FileNames;
- if (files != null && files.Length > 0)
- {
- var filePath = Path.GetDirectoryName(files[0]);
- foreach (var file in files)
- {
- try
- {
- var fileName = Path.GetFileNameWithoutExtension(file);
- var newFileName = $"Decrpt{fileName}.txt";
- var newFilePath = Path.Combine(filePath, newFileName);
- var licenseInfo = File.ReadAllText(file);
- var decryptInfo = DesBuilder.Decrypt(licenseInfo);
- File.WriteAllText(newFilePath, decryptInfo);
- }
- catch(Exception ex)
- {
- MessageBox.Show($"解密出错:{ex}", "提示");
- }
- }
- PostGeneration(filePath);
- MessageBox.Show($"解密完成!", "提示");
- }
- }
- }
- }
- }
|