main.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #include <QCoreApplication>
  2. #include "LHLogInit.h"
  3. #include "LHQLogAPI.h"
  4. #include "spdlog/spdlog.h"
  5. #include "ThreadPool.h"
  6. #include "LHCompareAPI.h"
  7. #include "signalstats_wrapper.h"
  8. #include "SoundCardData.h"
  9. #include <QDir>
  10. #include <QFile>
  11. void test();
  12. void test1();
  13. void LoadLibrary();
  14. int main(int argc, char* argv[])
  15. {
  16. QCoreApplication a(argc, argv);
  17. /* 初始化日志库 */
  18. initLog("SecurePlayAuxServer", g_apiLhQLog);
  19. auto logger = spdlog::get("main");
  20. if(logger == nullptr)
  21. {
  22. fmt::print("main logger is nullptr");
  23. return -1;
  24. }
  25. SPDLOG_LOGGER_INFO(logger, "★ ★ ★ ★ ★ ★ ☆ ☆ ACAServer ☆ ☆ ★ ★ ★ ★ ★ ★");
  26. SPDLOG_LOGGER_INFO(logger, "ACServer Version: {}", "6.0.0.0");
  27. /* 设置线程池最大线程个数 */
  28. CPPTP.setThreadMaxNum(512);
  29. /* 获取声卡信息 */
  30. SoundCards.InitData();
  31. void LoadLibrary();
  32. /* 初始化噪音检测功能 */
  33. signalstats_wrapper::initialize();
  34. // test();
  35. // CPPTP.add_task(test1);
  36. a.exec();
  37. /* 释放资源 */
  38. signalstats_wrapper::finalize();
  39. SPDLOG_LOGGER_INFO(logger, "ACAServer 结束运行");
  40. return 0;
  41. }
  42. /* 加载第三方动态库 */
  43. void LoadLibrary()
  44. {
  45. /* 加载一致性比对动态库 */
  46. if(LoadCompareLibrary())
  47. {
  48. SPDLOG_INFO("动态库加载成功!");
  49. }
  50. }
  51. void test()
  52. {
  53. QString appDataPath = QCoreApplication::applicationDirPath() + "/testDir";
  54. QDir dir;
  55. dir.setPath(appDataPath);
  56. if (!dir.exists()) {
  57. if(dir.mkpath(appDataPath))
  58. {
  59. SPDLOG_INFO("Directory created: {}", dir.absolutePath().toStdString());
  60. }
  61. else
  62. {
  63. SPDLOG_ERROR("Failed to create directory: {}", dir.absolutePath().toStdString());
  64. return;
  65. }
  66. }
  67. SPDLOG_INFO("当前文件夹: {}", dir.absolutePath().toStdString());
  68. // dir.setCurrent(appDataPath);
  69. QFile file(dir.filePath("test.txt"));
  70. if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
  71. file.write("Hello, World!");
  72. file.close();
  73. } else {
  74. SPDLOG_INFO("Failed to create file: {}", file.errorString().toStdString());
  75. }
  76. SPDLOG_INFO("Current directory: {}", dir.absolutePath().toStdString());
  77. SPDLOG_INFO("File created at: {}", file.fileName().toStdString());
  78. if(QFile::rename(file.fileName(), dir.filePath("test3.txt")))
  79. {
  80. SPDLOG_INFO("File renamed successfully to: {}", dir.filePath("test3.txt").toStdString());
  81. }
  82. else
  83. {
  84. SPDLOG_ERROR("Failed to rename file: {}", file.errorString().toStdString());
  85. }
  86. }
  87. void test1()
  88. {
  89. QFile file("test1.txt");
  90. if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
  91. file.write("Hello, World!");
  92. file.close();
  93. SPDLOG_INFO("File created successfully: {}", file.fileName().toStdString());
  94. } else {
  95. SPDLOG_ERROR("Failed to create file: {}", file.errorString().toStdString());
  96. }
  97. SPDLOG_INFO("File path: {}", file.fileName().toStdString());
  98. SPDLOG_INFO("Current working directory: {}", QDir::currentPath().toStdString());
  99. QFile::rename("test1.txt", "test2.txt");
  100. }