LAPTOP-SNT8I5JK\Boounion
2025-03-24 cfa0f3595c53e3567bb12cb194a37617a7b8a662
SourceCode/Bond/Servo/CMaster.cpp
@@ -14,6 +14,7 @@
   CMaster::CMaster()
   {
      m_listener = {nullptr, nullptr, nullptr};
      m_bDataModify = FALSE;
   }
   CMaster::~CMaster()
@@ -126,6 +127,10 @@
            m_listener.onEqCimStateChanged(this, p, bOn);
         }
      };
      listener.onDataChanged = [&](void* pEquipment, int code) -> void {
         m_bDataModify = TRUE;
      };
      pEquipment->setListener(listener);
      pEquipment->setCcLink(&m_cclink);
      m_listEquipment.push_back(pEquipment);
@@ -578,7 +583,13 @@
      // 自动保存缓存
      saveCache();
      if (i % (4 * 2) == 0) {
         if (m_bDataModify) {
            saveCacheAndBackups();
            m_bDataModify = FALSE;
         }
      }
   }
   void CMaster::connectEquipments()
@@ -669,6 +680,30 @@
      return 0;
   }
   int CMaster::saveCacheAndBackups()
   {
      saveCache();
      // 创建备份目录
      CString strNewFile;
      CString strFileDir = m_strFilepath.c_str();
      int index = strFileDir.ReverseFind('\\');
      ASSERT(index > 0);
      strFileDir = strFileDir.Left(index);
      strFileDir = strFileDir + _T("Backups");
      ::CreateDirectory(strFileDir, nullptr);
      CTime time = CTime::GetCurrentTime();
      strNewFile.Format(_T("%s//Master_%d_%02d_%02d_%02d_%02d_%02d.dat"),
         (LPTSTR)(LPCTSTR)strFileDir,
         time.GetYear(), time.GetMonth(), time.GetDay(),
         time.GetHour(), time.GetMinute(), time.GetSecond());
      ::CopyFile(m_strFilepath.c_str(), strNewFile, FALSE);
      return 0;
   }
   void CMaster::setCacheFilepath(const char* pszFilepath)
   {
      m_strFilepath = pszFilepath;