232 lines
9.8 KiB
C#
232 lines
9.8 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Win32;
|
|
|
|
namespace BetterEN5.Services
|
|
{
|
|
public class ActivationService : IActivationService
|
|
{
|
|
private const string RegPath = @"SOFTWARE\Seewo\EasiNote5";
|
|
private const string BEN5RegPath = @"SOFTWARE\BetterEN5";
|
|
|
|
public Task<bool> CheckActivationStatusAsync()
|
|
{
|
|
return Task.Run(() =>
|
|
{
|
|
try
|
|
{
|
|
using var key = Registry.CurrentUser.OpenSubKey(BEN5RegPath);
|
|
if (key != null)
|
|
{
|
|
var val = key.GetValue("Activated");
|
|
if (val != null && val.ToString() == "1")
|
|
return true;
|
|
}
|
|
}
|
|
catch { }
|
|
return false;
|
|
});
|
|
}
|
|
|
|
public Task<bool> ActivateProfessionalAsync(string licenseKey)
|
|
{
|
|
return Task.Run(() =>
|
|
{
|
|
try
|
|
{
|
|
var validKeys = new[] { "BEN5-PRO-2024-ACTIVATE", "SEEWO-EN5-PRO-VIP", "BETTER-SEEWO-PRO" };
|
|
bool valid = false;
|
|
foreach (var k in validKeys)
|
|
{
|
|
if (string.Equals(licenseKey.Trim(), k, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
valid = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!valid && licenseKey.Length >= 16)
|
|
valid = true;
|
|
|
|
if (!valid) return false;
|
|
|
|
using var key = Registry.CurrentUser.CreateSubKey(BEN5RegPath);
|
|
key.SetValue("Activated", 1, RegistryValueKind.DWord);
|
|
key.SetValue("LicenseKey", licenseKey, RegistryValueKind.String);
|
|
key.SetValue("ActivationDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), RegistryValueKind.String);
|
|
key.SetValue("LicenseType", "Professional", RegistryValueKind.String);
|
|
|
|
using var enKey = Registry.CurrentUser.CreateSubKey(RegPath);
|
|
enKey.SetValue("Professional", 1, RegistryValueKind.DWord);
|
|
|
|
var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
|
var configDir = Path.Combine(localAppData, "Seewo", "EasiNote5", "Config");
|
|
if (!Directory.Exists(configDir)) Directory.CreateDirectory(configDir);
|
|
var proFile = Path.Combine(configDir, "Professional.json");
|
|
var proConfig = new { Professional = true, LicenseKey = licenseKey, Features = new[] { "InkManager", "Converter", "TouchFix", "BoardSupport", "AdvancedExport" } };
|
|
File.WriteAllText(proFile, System.Text.Json.JsonSerializer.Serialize(proConfig, new System.Text.Json.JsonSerializerOptions { WriteIndented = true }));
|
|
|
|
return true;
|
|
}
|
|
catch { return false; }
|
|
});
|
|
}
|
|
|
|
public Task<bool> EnableIWBForNonTouchAsync()
|
|
{
|
|
return Task.Run(() =>
|
|
{
|
|
try
|
|
{
|
|
using var key = Registry.CurrentUser.CreateSubKey(RegPath);
|
|
key.SetValue("ForceIWB", 1, RegistryValueKind.DWord);
|
|
key.SetValue("SkipTouchCheck", 1, RegistryValueKind.DWord);
|
|
key.SetValue("NonTouchBoard", 1, RegistryValueKind.DWord);
|
|
key.SetValue("EnableMouseFallback", 1, RegistryValueKind.DWord);
|
|
|
|
var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
|
var configDir = Path.Combine(localAppData, "Seewo", "EasiNote5", "Config");
|
|
if (!Directory.Exists(configDir)) Directory.CreateDirectory(configDir);
|
|
var boardFile = Path.Combine(configDir, "IWBConfig.json");
|
|
var config = new
|
|
{
|
|
ForceIWB = true,
|
|
NonTouchBoard = true,
|
|
TouchDriverType = "MouseSimulation",
|
|
SkipTouchCheck = true,
|
|
EnableMultiTouch = false,
|
|
EnableMouseFallback = true,
|
|
BoardType = "LargeScreen",
|
|
LastFixTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
|
};
|
|
File.WriteAllText(boardFile, System.Text.Json.JsonSerializer.Serialize(config, new System.Text.Json.JsonSerializerOptions { WriteIndented = true }));
|
|
|
|
try
|
|
{
|
|
var appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
|
var cfgFkv = Path.Combine(appData, "Seewo", "EasiNote5", "Data", "Configs.fkv");
|
|
if (File.Exists(cfgFkv))
|
|
{
|
|
var content = File.ReadAllText(cfgFkv);
|
|
if (!content.Contains("\"NonTouchMode\""))
|
|
{
|
|
content = content.TrimEnd('}') + ",\"NonTouchMode\":true,\"LargeBoardMode\":true,\"ForceIWB\":true}";
|
|
File.WriteAllText(cfgFkv, content);
|
|
}
|
|
}
|
|
}
|
|
catch { }
|
|
|
|
return true;
|
|
}
|
|
catch { return false; }
|
|
});
|
|
}
|
|
|
|
public Task<bool> ApplyBoardSupportPatchAsync()
|
|
{
|
|
return Task.Run(() =>
|
|
{
|
|
try
|
|
{
|
|
var mainDir = Path.Combine(
|
|
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
|
|
"Seewo", "EasiNote5", "EasiNote5_5.2.4.9855", "Main");
|
|
|
|
var configsPath = Path.Combine(mainDir, "Configs", "configs.json");
|
|
if (File.Exists(configsPath))
|
|
{
|
|
var json = File.ReadAllText(configsPath);
|
|
if (!json.Contains("\"LargeBoard\""))
|
|
{
|
|
json = json.TrimEnd('}') + ",\"LargeBoard\":true,\"NonTouch\":true,\"IWBOnly\":true}";
|
|
File.WriteAllText(configsPath, json);
|
|
}
|
|
}
|
|
|
|
try
|
|
{
|
|
var shortcutPath = Path.Combine(
|
|
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
|
|
"希沃白板5-大屏模式.url");
|
|
if (!File.Exists(shortcutPath))
|
|
{
|
|
File.WriteAllText(shortcutPath,
|
|
"[InternetShortcut]\nURL=file:///" +
|
|
Path.Combine(mainDir, "EasiNote5.exe").Replace('\\', '/') +
|
|
"\nArguments=-m Display -iwb\nIconIndex=0\n");
|
|
}
|
|
}
|
|
catch { }
|
|
|
|
return true;
|
|
}
|
|
catch { return false; }
|
|
});
|
|
}
|
|
|
|
public Task<bool> LaunchBen5InstallerAsync()
|
|
{
|
|
return Task.Run(() =>
|
|
{
|
|
try
|
|
{
|
|
var possiblePaths = new[]
|
|
{
|
|
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Seewo", "EasiNote5", "Extensions", "Better-EN5", "1.1.0", "BEN5_Installer.exe"),
|
|
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Seewo", "EasiNote5", "Extensions", "Better-EN5", "BEN5_Installer.exe"),
|
|
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "BEN5_Installer.exe"),
|
|
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "BEN5_Registration_Patch.exe"),
|
|
};
|
|
|
|
foreach (var path in possiblePaths)
|
|
{
|
|
if (File.Exists(path))
|
|
{
|
|
Process.Start(new ProcessStartInfo
|
|
{
|
|
FileName = path,
|
|
UseShellExecute = true,
|
|
Verb = "runas"
|
|
});
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
catch { return false; }
|
|
});
|
|
}
|
|
|
|
public ActivationInfo GetCurrentStatus()
|
|
{
|
|
var info = new ActivationInfo();
|
|
try
|
|
{
|
|
using var key = Registry.CurrentUser.OpenSubKey(BEN5RegPath);
|
|
if (key != null)
|
|
{
|
|
info.IsProfessional = (int)(key.GetValue("Activated") ?? 0) == 1;
|
|
info.LicenseType = key.GetValue("LicenseType")?.ToString() ?? "Community";
|
|
info.LastActivationDate = key.GetValue("ActivationDate")?.ToString() ?? "";
|
|
}
|
|
}
|
|
catch { }
|
|
|
|
try
|
|
{
|
|
using var enKey = Registry.CurrentUser.OpenSubKey(RegPath);
|
|
if (enKey != null)
|
|
{
|
|
info.IsIWBActive = (int)(enKey.GetValue("ForceIWB") ?? 0) == 1;
|
|
info.IsNonTouchBoard = (int)(enKey.GetValue("NonTouchBoard") ?? 0) == 1;
|
|
}
|
|
}
|
|
catch { }
|
|
|
|
return info;
|
|
}
|
|
}
|
|
}
|