From cfa0f3595c53e3567bb12cb194a37617a7b8a662 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期一, 24 三月 2025 17:39:35 +0800
Subject: [PATCH] 1.缓存文件的备份。
---
.gitignore | 1
SourceCode/Bond/Servo/EqsGraphWnd.cpp | 9 ----
SourceCode/Bond/Servo/CEquipment.cpp | 15 +++++++
SourceCode/Bond/Servo/CMaster.cpp | 37 ++++++++++++++++++
SourceCode/Bond/Servo/CMaster.h | 2 +
SourceCode/Bond/Servo/CEquipment.h | 2 +
6 files changed, 56 insertions(+), 10 deletions(-)
diff --git a/.gitignore b/.gitignore
index 99779f8..8681c35 100644
--- a/.gitignore
+++ b/.gitignore
@@ -49,3 +49,4 @@
SourceCode/Bond/BoounionPLC/BoounionPLC.vcxproj.user
SourceCode/Bond/x64/Debug/ServoConfiguration.ini
*.iobj
+SourceCode/Bond/x64/Debug/Backups/
diff --git a/SourceCode/Bond/Servo/CEquipment.cpp b/SourceCode/Bond/Servo/CEquipment.cpp
index 393191b..0633bf2 100644
--- a/SourceCode/Bond/Servo/CEquipment.cpp
+++ b/SourceCode/Bond/Servo/CEquipment.cpp
@@ -7,7 +7,7 @@
CEquipment::CEquipment() : m_nID(0), m_strName(""), m_strDescription(""), m_station(0, 255)
{
- m_listener = { nullptr, nullptr };
+ m_listener = { nullptr, nullptr, nullptr };
m_alive = {FALSE, 0, FALSE};
m_bCimState = FALSE;
m_bUpstreamInline = FALSE;
@@ -49,6 +49,7 @@
{
m_listener.onAlive = listener.onAlive;
m_listener.onCimStateChanged = listener.onCimStateChanged;
+ m_listener.onDataChanged = listener.onDataChanged;
}
void CEquipment::setCcLink(CCCLinkIEControl* pCcLink)
@@ -563,6 +564,9 @@
else if (nRet == FLOW_ACCEPT) {
m_glassList.pop_front();
pContext->release(); // 添加到列队时addRef, 取出时release
+ if (m_listener.onDataChanged != nullptr) {
+ m_listener.onDataChanged(this, 0);
+ }
}
pContext->release();
@@ -582,6 +586,11 @@
pGlass->addRef();
m_glassList.push_back(pGlass);
Unlock();
+
+ if (m_listener.onDataChanged != nullptr) {
+ m_listener.onDataChanged(this, 0);
+ }
+
return FLOW_ACCEPT;
}
@@ -593,5 +602,9 @@
pGlass->addRef();
m_glassList.push_back(pGlass);
Unlock();
+
+ if (m_listener.onDataChanged != nullptr) {
+ m_listener.onDataChanged(this, 0);
+ }
}
}
diff --git a/SourceCode/Bond/Servo/CEquipment.h b/SourceCode/Bond/Servo/CEquipment.h
index 576adaa..60c3490 100644
--- a/SourceCode/Bond/Servo/CEquipment.h
+++ b/SourceCode/Bond/Servo/CEquipment.h
@@ -25,10 +25,12 @@
#define VCR_MAX 1
typedef std::function<void(void* pEiuipment, BOOL bAlive)> ONALIVE;
+ typedef std::function<void(void* pEiuipment, int code)> ONDATACHANGED;
typedef struct _EquipmentListener
{
ONALIVE onAlive;
ONALIVE onCimStateChanged;
+ ONDATACHANGED onDataChanged;
} EquipmentListener;
// Memory Block 结构体定义
diff --git a/SourceCode/Bond/Servo/CMaster.cpp b/SourceCode/Bond/Servo/CMaster.cpp
index 0975cde..145531f 100644
--- a/SourceCode/Bond/Servo/CMaster.cpp
+++ b/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;
diff --git a/SourceCode/Bond/Servo/CMaster.h b/SourceCode/Bond/Servo/CMaster.h
index adf5059..f3a531b 100644
--- a/SourceCode/Bond/Servo/CMaster.h
+++ b/SourceCode/Bond/Servo/CMaster.h
@@ -48,6 +48,7 @@
int addBakeCooling(StepListener& listener);
void connectEquipments();
int saveCache();
+ int saveCacheAndBackups();
int readCache();
void serialize(CArchive& ar);
@@ -56,6 +57,7 @@
CCCLinkIEControl m_cclink;
std::list<CEquipment*> m_listEquipment;
std::string m_strFilepath;
+ BOOL m_bDataModify;
};
}
diff --git a/SourceCode/Bond/Servo/EqsGraphWnd.cpp b/SourceCode/Bond/Servo/EqsGraphWnd.cpp
index 50d569d..466ca8e 100644
--- a/SourceCode/Bond/Servo/EqsGraphWnd.cpp
+++ b/SourceCode/Bond/Servo/EqsGraphWnd.cpp
@@ -35,14 +35,7 @@
m_hWnd = NULL;
m_crFrame = GetSysColor(COLOR_WINDOWFRAME);
m_crBkgnd = RGB(255, 255, 255);
- m_listener.onConnectPin = nullptr;
- m_listener.onCheckConnectPin = nullptr;
- m_listener.onDisconnectPin = nullptr;
- m_listener.onDeleteEqItem = nullptr;
- m_listener.onEqItemPosChanged = nullptr;
- m_listener.onDblckEqItem = nullptr;
- m_listener.onRclickEqItem = nullptr;
- m_listener.onSelectEqItem = nullptr;
+ m_listener = {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr };
m_crItemBackground[0] = RGB(218, 218, 218);
m_crItemBackground[1] = RGB(193, 208, 227);
m_crItemFrame[0] = RGB(128, 128, 128);
--
Gitblit v1.9.3