// parameters: // product_name 例如 "fingerprintcenter" // return: // true 初始化成功 // false 初始化失败,应立刻退出应用程序 public static bool Initial(string product_name, Delegate_skipSerialNumberCheck skipCheck = null) { ProductName = product_name; ClientVersion = Assembly.GetAssembly(TypeOfProgram).GetName().Version.ToString(); if (ApplicationDeployment.IsNetworkDeployed == true) { // MessageBox.Show(this, "network"); DataDir = Application.LocalUserAppDataPath; } else { DataDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); } UserDir = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), product_name); PathUtil.TryCreateDir(UserDir); UserTempDir = Path.Combine(UserDir, "temp"); PathUtil.TryCreateDir(UserTempDir); UserLogDir = Path.Combine(UserDir, "log"); PathUtil.TryCreateDir(UserLogDir); InitialConfig(); #if NO var repository = log4net.LogManager.CreateRepository("main"); log4net.GlobalContext.Properties["LogFileName"] = Path.Combine(UserLogDir, "log_"); log4net.Config.XmlConfigurator.Configure(repository); LibraryChannelManager.Log = LogManager.GetLogger("main", "channellib"); _log = LogManager.GetLogger("main", product_name // "fingerprintcenter" ); #endif Log.Logger = new LoggerConfiguration() // .MinimumLevel.Information() .MinimumLevel.ControlledBy(_loggingLevel) .WriteTo.File(Path.Combine(UserLogDir, "log_.txt"), rollingInterval: RollingInterval.Day) .CreateLogger(); // 启动时在日志中记载当前 .exe 版本号 // 此举也能尽早发现日志目录无法写入的问题,会抛出异常 WriteInfoLog(Assembly.GetAssembly(TypeOfProgram /*typeof(ClientInfo)*/).FullName); { // 检查序列号 // if (DateTime.Now >= start_day || this.MainForm.IsExistsSerialNumberStatusFile() == true) if (SerialNumberMode == "must" && (skipCheck == null || skipCheck() == false)) { // 在用户目录中写入一个隐藏文件,表示序列号功能已经启用 // this.WriteSerialNumberStatusFile(); ClientInfo.WriteInfoLog($"尝试打开序列号对话框"); int nRet = VerifySerialCode($"{product_name}需要先设置序列号才能使用", "", "reinput", out string strError); if (nRet == -1) { ClientInfo.WriteErrorLog($"序列号不正确,{product_name} 退出"); MessageBox.Show(MainForm, $"{product_name}需要先设置序列号才能使用"); API.PostMessage(MainForm.Handle, API.WM_CLOSE, 0, 0); return(false); } ClientInfo.WriteInfoLog($"序列号对话框被确认。nRet={nRet}, strError={strError}"); } } return(true); }
// parameters: // product_name 例如 "fingerprintcenter" public static void Initial(string product_name, Delegate_skipSerialNumberCheck skipCheck = null) { ProductName = product_name; ClientVersion = Assembly.GetAssembly(TypeOfProgram).GetName().Version.ToString(); if (ApplicationDeployment.IsNetworkDeployed == true) { // MessageBox.Show(this, "network"); DataDir = Application.LocalUserAppDataPath; } else { DataDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); } UserDir = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), product_name); PathUtil.TryCreateDir(UserDir); UserTempDir = Path.Combine(UserDir, "temp"); PathUtil.TryCreateDir(UserTempDir); UserLogDir = Path.Combine(UserDir, "log"); PathUtil.TryCreateDir(UserLogDir); // 初始化setting配置文件 InitialConfig(); var repository = log4net.LogManager.CreateRepository("main"); log4net.GlobalContext.Properties["LogFileName"] = Path.Combine(UserLogDir, "log_"); log4net.Config.XmlConfigurator.Configure(repository); //LibraryChannelManager.Log = LogManager.GetLogger("main", "channellib"); _log = LogManager.GetLogger("main", "dp2mini" // product_name ); // 启动时在日志中记载当前 .exe 版本号 // 此举也能尽早发现日志目录无法写入的问题,会抛出异常 WriteInfoLog(Assembly.GetAssembly(typeof(ClientInfo)).FullName); /* * { * // 检查序列号 * // if (DateTime.Now >= start_day || this.MainForm.IsExistsSerialNumberStatusFile() == true) * if (SerialNumberMode == "must" * && (skipCheck == null || skipCheck() == false)) * { * // 在用户目录中写入一个隐藏文件,表示序列号功能已经启用 * // this.WriteSerialNumberStatusFile(); * * int nRet = VerifySerialCode($"{product_name}需要先设置序列号才能使用", * "", * "reinput", * out string strError); * if (nRet == -1) * { * MessageBox.Show(MainForm, $"{product_name}需要先设置序列号才能使用"); * API.PostMessage(MainForm.Handle, API.WM_CLOSE, 0, 0); * return; * } * } * } */ }