useVCamChecker.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { VCAM_LIST } from "@/constants/constant-namelist";
  2. import { store } from "@/store/store";
  3. import { execLocal, fileExists } from "@/utils/nativeMethods";
  4. import { watch } from "vue";
  5. export function useVCamChecker() {
  6. /** 检测出错则提示;检测通过则将禁用登录按钮的flag置为false */
  7. async function checkVCamTxt() {
  8. let cameraInfo;
  9. try {
  10. const fs: typeof import("fs") = window.nodeRequire("fs");
  11. try {
  12. cameraInfo = fs.readFileSync("CameraInfo.txt", "utf-8");
  13. } catch (error) {
  14. logger({
  15. cnl: ["local", "server"],
  16. key: "checkVCamTxt",
  17. pgu: "AUTO",
  18. dtl: "CameraInfo.txt出错--0",
  19. ejn: JSON.stringify(error),
  20. });
  21. await new Promise((resolve2) => setTimeout(resolve2, 3000));
  22. cameraInfo = fs.readFileSync("CameraInfo.txt", "utf-8");
  23. }
  24. } catch (error) {
  25. logger({
  26. cnl: ["local", "server"],
  27. key: "checkVCamTxt",
  28. pgu: "AUTO",
  29. stk: error instanceof Error ? error.message : JSON.stringify(error),
  30. dtl: "读取CameraInfo.txt出错",
  31. ext: { errorType: "e-02", applicationNames: cameraInfo },
  32. });
  33. $message.error("系统检测出错(e-02),请退出程序后重试!", {
  34. duration: 2 * 24 * 60 * 60,
  35. });
  36. return;
  37. }
  38. let found = false;
  39. if (cameraInfo && cameraInfo.trim()) {
  40. for (const vc of VCAM_LIST) {
  41. if (cameraInfo.toUpperCase().includes(vc.toUpperCase())) {
  42. found = true;
  43. $message.info("在考试期间,请关掉虚拟摄像头软件,诚信考试。", {
  44. duration: 2 * 24 * 60 * 60,
  45. });
  46. logger({
  47. cnl: ["local", "server"],
  48. key: "checkVCamTxt",
  49. pgu: "AUTO",
  50. dtl: "提示CameraInfo.txt成功",
  51. ext: { applicationNames: cameraInfo },
  52. });
  53. }
  54. }
  55. }
  56. disableLoginBtnBecauseVCam = found;
  57. }
  58. let disableLoginBtnBecauseVCam = $ref(true);
  59. const QECSConfig = $computed(() => store.QECSConfig);
  60. watch(QECSConfig, async () => {
  61. if (
  62. !QECSConfig.PREVENT_CHEATING_CONFIG.includes("DISABLE_VIRTUAL_CAMERA")
  63. ) {
  64. disableLoginBtnBecauseVCam = false;
  65. return;
  66. }
  67. if (import.meta.env.DEV) return;
  68. const fs: typeof import("fs") = window.nodeRequire("fs");
  69. try {
  70. fileExists("CameraInfo.txt") && fs.unlinkSync("CameraInfo.txt");
  71. } catch (error) {
  72. console.log(error);
  73. logger({
  74. cnl: ["local", "server"],
  75. key: "checkVCamTxt",
  76. dtl: "unlink CameraInfo.txt 失败",
  77. });
  78. }
  79. await execLocal("multiCamera.exe");
  80. await checkVCamTxt();
  81. });
  82. return { disableLoginBtnBecauseVCam: $$(disableLoginBtnBecauseVCam) };
  83. }