| | |
| | | CREATE TABLE TN_WATCH_USER ( |
| | | CN_S_LOGIN VARCHAR( 128 ) NOT NULL, |
| | | CN_S_SERVER_ID VARCHAR( 128 ) NOT NULL, |
| | | CN_S_BACKUP_DIR VARCHAR( 512 ) NOT NULL, |
| | | CN_S_SERVER_PATH VARCHAR( 512 ) NOT NULL, |
| | | primary key(CN_S_LOGIN,CN_S_SERVER_ID) |
| | | CREATE TABLE TN_WATCH_USER ( |
| | | CN_S_LOGIN VARCHAR (128) NOT NULL, |
| | | CN_S_SERVER_ID VARCHAR (128) NOT NULL, |
| | | CN_S_BACKUP_DIR VARCHAR (512) NOT NULL, |
| | | CN_S_SERVER_PATH VARCHAR (512) NOT NULL, |
| | | CN_S_ISLOGIN CHAR (2) DEFAULT N, |
| | | PRIMARY KEY ( |
| | | CN_S_LOGIN, |
| | | CN_S_SERVER_ID |
| | | ) |
| | | ); |
| New file |
| | |
| | | #include "mbcommfunc.h" |
| | | #include <QCoreApplication> |
| | | |
| | | CMBCommFunc::CMBCommFunc() |
| | | { |
| | | |
| | | } |
| | | |
| | | CMBCommFunc::~CMBCommFunc() |
| | | { |
| | | |
| | | } |
| | | |
| | | QString CMBCommFunc::exePath() |
| | | { |
| | | QString exePath = QCoreApplication::applicationDirPath(); |
| | | return exePath; |
| | | } |
| New file |
| | |
| | | #ifndef MBCOMMFUNC_H |
| | | #define MBCOMMFUNC_H |
| | | #include <QObject> |
| | | |
| | | class CMBCommFunc |
| | | { |
| | | public: |
| | | CMBCommFunc(); |
| | | ~CMBCommFunc(); |
| | | public: |
| | | static QString exePath(); |
| | | }; |
| | | |
| | | #endif // MBCOMMFUNC_H |
| | |
| | | #include "mbfileutil.h" |
| | | #include <QFileInfo> |
| | | #include <QDateTime> |
| | | #include <QDir> |
| | | |
| | | CMBFileUtil::CMBFileUtil() |
| | | { |
| | |
| | | QString strLastTime = lastModifiedTime.toString("yyyy.MM.dd hh:mm:ss"); |
| | | return strLastTime; |
| | | } |
| | | |
| | | |
| | | bool CMBFileUtil::createLevelDir(QString path) |
| | | { |
| | | QDir folder; |
| | | return folder.mkpath(path); |
| | | } |
| | | |
| | |
| | | ~CMBFileUtil(); |
| | | public: |
| | | static QString lastModifiedTime(QString fileName); |
| | | static bool createLevelDir(QString path); |
| | | }; |
| | | |
| | | #endif // MBFILEUTIL_H |
| | |
| | | |
| | | SOURCES += \ |
| | | main.cpp \ |
| | | mbcommfunc.cpp \ |
| | | mbfileutil.cpp \ |
| | | mbwatchapp.cpp \ |
| | | mbwatchmain.cpp |
| | | mbwatchconst.cpp \ |
| | | mbwatchfile.cpp \ |
| | | mbwatchmain.cpp \ |
| | | mbwatchmgr.cpp \ |
| | | mbwatchuser.cpp \ |
| | | mbwatchuserdb.cpp \ |
| | | mbwatchusermgr.cpp |
| | | |
| | | # Default rules for deployment. |
| | | qnx: target.path = /tmp/$${TARGET}/bin |
| | |
| | | include(qtservice/qtservice.pri) |
| | | |
| | | HEADERS += \ |
| | | mbcommfunc.h \ |
| | | mbfileutil.h \ |
| | | mbwatchapp.h \ |
| | | mbwatchmain.h |
| | | mbwatchconst.h \ |
| | | mbwatchfile.h \ |
| | | mbwatchmain.h \ |
| | | mbwatchmgr.h \ |
| | | mbwatchuser.h \ |
| | | mbwatchuserdb.h \ |
| | | mbwatchusermgr.h |
| | | |
| New file |
| | |
| | | #include "mbwatchconst.h" |
| | | |
| | | CMBWatchConst::CMBWatchConst() |
| | | { |
| | | |
| | | } |
| | | |
| | | CMBWatchConst::~CMBWatchConst() |
| | | { |
| | | |
| | | } |
| | | |
| | | void CMBWatchConst::setExePath(QString exePath) |
| | | { |
| | | m_exePath = exePath; |
| | | } |
| | | |
| | | QString CMBWatchConst::getExePath() |
| | | { |
| | | return m_exePath; |
| | | } |
| | | |
| | | QString CMBWatchConst::getDataPath() |
| | | { |
| | | QString path = m_exePath + "/" + "data"; |
| | | path = path.replace("//","/"); |
| | | return path; |
| | | } |
| | | |
| | | QString CMBWatchConst::getWatchPath() |
| | | { |
| | | QString path = m_exePath + "/" + "watch"; |
| | | path = path.replace("//","/"); |
| | | return path; |
| | | } |
| | | |
| | | QString CMBWatchConst::getWatchUserDB() |
| | | { |
| | | QString data = getDataPath(); |
| | | QString watchUser = data + "/mb_watch_user.db"; |
| | | watchUser = watchUser.replace("//","/"); |
| | | return watchUser; |
| | | } |
| New file |
| | |
| | | #ifndef MBWATCHCONST_H |
| | | #define MBWATCHCONST_H |
| | | #include <QObject> |
| | | |
| | | class CMBWatchConst |
| | | { |
| | | public: |
| | | CMBWatchConst(); |
| | | ~CMBWatchConst(); |
| | | private: |
| | | QString m_exePath; |
| | | public: |
| | | void setExePath(QString exePath); |
| | | public: |
| | | QString getExePath(); |
| | | public: |
| | | QString getDataPath(); |
| | | QString getWatchPath(); |
| | | QString getWatchUserDB(); |
| | | }; |
| | | |
| | | #endif // MBWATCHCONST_H |
| New file |
| | |
| | | #include "mbwatchfile.h" |
| | | #include <QDir> |
| | | |
| | | CMBWatchFile::CMBWatchFile() |
| | | { |
| | | m_pSystemWatcher = NULL; |
| | | } |
| | | |
| | | CMBWatchFile::~CMBWatchFile() |
| | | { |
| | | if( m_pSystemWatcher ){ |
| | | delete m_pSystemWatcher; |
| | | m_pSystemWatcher = NULL; |
| | | } |
| | | } |
| | | |
| | | |
| | | void CMBWatchFile::addWatchPath(QString path) |
| | | { |
| | | if( m_pSystemWatcher == NULL ){ |
| | | |
| | | m_pSystemWatcher = new QFileSystemWatcher(); |
| | | connect(m_pSystemWatcher, SIGNAL(fileChanged(QString)), this, SLOT(fileUpdated(QString))); |
| | | } |
| | | |
| | | // 添加监控路径 |
| | | m_pSystemWatcher->addPath(path); |
| | | } |
| | | |
| | | void CMBWatchFile::fileUpdated(const QString &path) |
| | | { |
| | | emit sigFileChange(path); |
| | | } |
| | | |
| | | |
| | | |
| New file |
| | |
| | | #ifndef MBWATCHFILE_H |
| | | #define MBWATCHFILE_H |
| | | #include <QObject> |
| | | #include <QFileSystemWatcher> |
| | | #include <QMap> |
| | | |
| | | class CMBWatchFile : public QObject |
| | | { |
| | | Q_OBJECT |
| | | public: |
| | | CMBWatchFile(); |
| | | ~CMBWatchFile(); |
| | | public: |
| | | void addWatchPath(QString path); |
| | | signals: |
| | | void sigFileChange(QString fileName); |
| | | public slots: |
| | | void fileUpdated(const QString &path); // 文件被修改时调用,path是监控的路径 |
| | | private: |
| | | QFileSystemWatcher *m_pSystemWatcher; // QFileSystemWatcher变量 |
| | | }; |
| | | |
| | | #endif // MBWATCHFILE_H |
| | |
| | | #include "mbwatchmain.h" |
| | | // mb_watch_user.db |
| | | // TN_WATCH_USER |
| | | // CN_S_LOGIN 联合主键 |
| | | // CN_S_SERVER_ID 联合主键 |
| | | // CN_S_BACKUP_DIR |
| | | // CN_S_SERVER_PATH |
| | | #include "mbcommfunc.h" |
| | | #include <iostream> |
| | | |
| | | // mb_watch_log_xxxx.db( xxx---> serverid login ) |
| | | // CN_S_ID 唯一值,由 CN_S_FILE_NAME ---> md5化成 |
| | |
| | | |
| | | CMBWatchMain::CMBWatchMain() |
| | | { |
| | | m_pMgr = new CMBWatchMgr(); |
| | | m_pWatchFile = new CMBWatchFile(); |
| | | |
| | | conn(); |
| | | } |
| | | |
| | | CMBWatchMain::~CMBWatchMain() |
| | | { |
| | | disConn(); |
| | | |
| | | if(m_pWatchFile){ |
| | | delete m_pWatchFile; |
| | | m_pWatchFile = NULL; |
| | | } |
| | | if( m_pMgr ){ |
| | | delete m_pMgr; |
| | | m_pMgr = NULL; |
| | | } |
| | | } |
| | | |
| | | void CMBWatchMain::conn() |
| | | { |
| | | connect(m_pWatchFile,SIGNAL(sigFileChange(QString)),this,SLOT(onSigFileChange(QString))); |
| | | } |
| | | |
| | | void CMBWatchMain::disConn() |
| | | { |
| | | disconnect(m_pWatchFile); |
| | | } |
| | | |
| | | void CMBWatchMain::start() |
| | | { |
| | | |
| | | init(); |
| | | } |
| | | |
| | | void CMBWatchMain::stop() |
| | |
| | | { |
| | | |
| | | } |
| | | |
| | | |
| | | void CMBWatchMain::init() |
| | | { |
| | | // 获取exe path |
| | | QString exePath = CMBCommFunc::exePath(); |
| | | m_pMgr->getConst()->setExePath(exePath); |
| | | |
| | | // 监控userdb |
| | | QString watchUserDB = m_pMgr->getConst()->getWatchUserDB(); |
| | | m_pWatchFile->addWatchPath(watchUserDB); |
| | | |
| | | QString errInfo; |
| | | if(!m_pMgr->init(errInfo)){ |
| | | std::cout << errInfo.toStdString() << std::endl; |
| | | return ; |
| | | } |
| | | } |
| | | |
| | | void CMBWatchMain::onSigFileChange(QString fileName) |
| | | { |
| | | |
| | | } |
| | | |
| | |
| | | #ifndef MBWATCHMAIN_H |
| | | #define MBWATCHMAIN_H |
| | | #include <QObject> |
| | | #include "mbwatchfile.h" |
| | | #include "mbwatchmgr.h" |
| | | |
| | | class CMBWatchMain : public QObject |
| | | { |
| | |
| | | public: |
| | | CMBWatchMain(); |
| | | ~CMBWatchMain(); |
| | | private: |
| | | CMBWatchMgr *m_pMgr; |
| | | CMBWatchFile *m_pWatchFile; |
| | | private: |
| | | void conn(); |
| | | void disConn(); |
| | | public: |
| | | void start(); |
| | | void stop(); |
| | | void pause(); |
| | | void resume(); |
| | | private: |
| | | void init(); |
| | | public slots: |
| | | void onSigFileChange(QString fileName); |
| | | }; |
| | | |
| | | #endif // MBWATCHMAIN_H |
| New file |
| | |
| | | #include "mbwatchmgr.h" |
| | | |
| | | CMBWatchMgr::CMBWatchMgr() |
| | | { |
| | | m_pConst = new CMBWatchConst(); |
| | | m_pUserDb = new CMBWatchUserDb(); |
| | | } |
| | | |
| | | CMBWatchMgr::~CMBWatchMgr() |
| | | { |
| | | if( m_pConst ){ |
| | | delete m_pConst; |
| | | m_pConst = NULL; |
| | | } |
| | | if( m_pUserDb ){ |
| | | delete m_pUserDb; |
| | | m_pUserDb = NULL; |
| | | } |
| | | |
| | | } |
| | | |
| | | CMBWatchConst *CMBWatchMgr::getConst() |
| | | { |
| | | return m_pConst; |
| | | } |
| | | |
| | | bool CMBWatchMgr::init(QString &errInfo) |
| | | { |
| | | QString watchUserDB = m_pConst->getWatchUserDB(); |
| | | if(!m_pUserDb->init(watchUserDB,errInfo)) |
| | | return false; |
| | | |
| | | |
| | | return true; |
| | | } |
| New file |
| | |
| | | #ifndef MBWATCHMGR_H |
| | | #define MBWATCHMGR_H |
| | | #include "mbwatchconst.h" |
| | | #include "mbwatchuserdb.h" |
| | | |
| | | class CMBWatchMgr |
| | | { |
| | | public: |
| | | CMBWatchMgr(); |
| | | ~CMBWatchMgr(); |
| | | private: |
| | | CMBWatchConst *m_pConst; |
| | | private: |
| | | CMBWatchUserDb *m_pUserDb; |
| | | public: |
| | | CMBWatchConst *getConst(); |
| | | public: |
| | | bool init(QString &errInfo); |
| | | }; |
| | | |
| | | #endif // MBWATCHMGR_H |
| New file |
| | |
| | | #include "mbwatchuser.h" |
| | | |
| | | CMBWatchUser::CMBWatchUser() |
| | | { |
| | | |
| | | } |
| | | |
| | | CMBWatchUser::~CMBWatchUser() |
| | | { |
| | | |
| | | } |
| | | |
| | | void CMBWatchUser::setLogin(QString login) |
| | | { |
| | | m_login = login; |
| | | } |
| | | |
| | | void CMBWatchUser::setSvrID(QString svrID) |
| | | { |
| | | m_svrID = svrID; |
| | | } |
| | | |
| | | void CMBWatchUser::setBackupDir(QString backupDir) |
| | | { |
| | | m_backupDir = backupDir; |
| | | } |
| | | |
| | | void CMBWatchUser::setSvrPath(QString svrPath) |
| | | { |
| | | m_svrPath = svrPath; |
| | | } |
| | | |
| | | void CMBWatchUser::setIsLogin(QString isLogin) |
| | | { |
| | | m_isLogin = isLogin; |
| | | } |
| | | |
| | | QString CMBWatchUser::getLogin() |
| | | { |
| | | return m_login; |
| | | } |
| | | |
| | | QString CMBWatchUser::getSvrID() |
| | | { |
| | | return m_svrID; |
| | | } |
| | | |
| | | QString CMBWatchUser::getBackupDir() |
| | | { |
| | | return m_backupDir; |
| | | } |
| | | |
| | | QString CMBWatchUser::getSvrPath() |
| | | { |
| | | return m_svrPath; |
| | | } |
| | | |
| | | QString CMBWatchUser::getIsLogin() |
| | | { |
| | | return m_isLogin; |
| | | } |
| New file |
| | |
| | | #ifndef MBWATCHUSER_H |
| | | #define MBWATCHUSER_H |
| | | #include <QObject> |
| | | |
| | | class CMBWatchUser; |
| | | typedef QVector<CMBWatchUser *> CMBWatchUserVector; |
| | | |
| | | |
| | | // mb_watch_user.db |
| | | // TN_WATCH_USER |
| | | // CN_S_LOGIN 联合主键 |
| | | // CN_S_SERVER_ID 联合主键 |
| | | // CN_S_BACKUP_DIR |
| | | // CN_S_SERVER_PATH |
| | | // CN_S_ISLOGIN |
| | | class CMBWatchUser |
| | | { |
| | | public: |
| | | CMBWatchUser(); |
| | | ~CMBWatchUser(); |
| | | private: |
| | | QString m_login; |
| | | QString m_svrID; |
| | | QString m_backupDir; |
| | | QString m_svrPath; |
| | | QString m_isLogin; |
| | | public: |
| | | void setLogin(QString login); |
| | | void setSvrID(QString svrID); |
| | | void setBackupDir(QString backupDir); |
| | | void setSvrPath(QString svrPath); |
| | | void setIsLogin(QString isLogin); |
| | | public: |
| | | QString getLogin(); |
| | | QString getSvrID(); |
| | | QString getBackupDir(); |
| | | QString getSvrPath(); |
| | | QString getIsLogin(); |
| | | }; |
| | | |
| | | #endif // MBWATCHUSER_H |
| New file |
| | |
| | | #include "mbwatchuserdb.h" |
| | | |
| | | CMBWatchUserDb::CMBWatchUserDb() |
| | | { |
| | | m_pMgr = new CMBWatchUserMgr(); |
| | | } |
| | | |
| | | CMBWatchUserDb::~CMBWatchUserDb() |
| | | { |
| | | if( m_pMgr ){ |
| | | delete m_pMgr; |
| | | m_pMgr = NULL; |
| | | } |
| | | } |
| | | |
| | | bool CMBWatchUserDb::init(QString path,QString &errInfo) |
| | | { |
| | | m_pMgr->removeAll(); |
| | | |
| | | |
| | | return true; |
| | | } |
| New file |
| | |
| | | #ifndef MBWATCHUSERDB_H |
| | | #define MBWATCHUSERDB_H |
| | | #include "mbwatchusermgr.h" |
| | | #include <QObject> |
| | | |
| | | class CMBWatchUserDb |
| | | { |
| | | public: |
| | | CMBWatchUserDb(); |
| | | ~CMBWatchUserDb(); |
| | | private: |
| | | CMBWatchUserMgr *m_pMgr; |
| | | public: |
| | | bool init(QString path,QString &errInfo); |
| | | }; |
| | | |
| | | #endif // MBWATCHUSERDB_H |
| New file |
| | |
| | | #include "mbwatchusermgr.h" |
| | | |
| | | CMBWatchUserMgr::CMBWatchUserMgr() |
| | | { |
| | | |
| | | } |
| | | |
| | | CMBWatchUserMgr::~CMBWatchUserMgr() |
| | | { |
| | | |
| | | } |
| | | |
| | | bool CMBWatchUserMgr::add(CMBWatchUser *pUser) |
| | | { |
| | | if( NULL == pUser ) |
| | | return false; |
| | | |
| | | QString login = pUser->getLogin(); |
| | | QString svrID = pUser->getSvrID(); |
| | | |
| | | if(is(login, svrID)) |
| | | return false; |
| | | |
| | | m_vector.append(pUser); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | CMBWatchUser *CMBWatchUserMgr::get(QString login, QString svrID) |
| | | { |
| | | login = login.trimmed(); |
| | | svrID = svrID.trimmed(); |
| | | if( login.isEmpty() || svrID.isEmpty() ) |
| | | return NULL; |
| | | |
| | | CMBWatchUserVector::iterator it; |
| | | CMBWatchUser *pUser = NULL; |
| | | |
| | | for( it = m_vector.begin();it != m_vector.end();it++ ) |
| | | { |
| | | pUser = *it; |
| | | QString tmpLogin = pUser->getLogin(); |
| | | QString tmpSvrID = pUser->getSvrID(); |
| | | |
| | | tmpLogin = tmpLogin.trimmed(); |
| | | tmpSvrID = tmpSvrID.trimmed(); |
| | | if( tmpLogin == login && tmpSvrID == svrID ) |
| | | return pUser; |
| | | } |
| | | return NULL; |
| | | } |
| | | |
| | | bool CMBWatchUserMgr::removeAll() |
| | | { |
| | | qDeleteAll(m_vector.begin(),m_vector.end()); |
| | | |
| | | m_vector.clear(); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | bool CMBWatchUserMgr::is(QString login, QString svrID) |
| | | { |
| | | CMBWatchUser *pUser = get(login, svrID); |
| | | if( NULL == pUser ) |
| | | return false; |
| | | |
| | | return true; |
| | | } |
| New file |
| | |
| | | #ifndef MBWATCHUSERMGR_H |
| | | #define MBWATCHUSERMGR_H |
| | | #include "mbwatchuser.h" |
| | | |
| | | class CMBWatchUserMgr |
| | | { |
| | | public: |
| | | CMBWatchUserMgr(); |
| | | ~CMBWatchUserMgr(); |
| | | private: |
| | | CMBWatchUserVector m_vector; |
| | | public: |
| | | bool add(CMBWatchUser *pUser ); // 添加数据 |
| | | CMBWatchUser *get(QString login,QString svrID); |
| | | bool removeAll(); // 移除 |
| | | bool is(QString login,QString svrID); |
| | | }; |
| | | |
| | | #endif // MBWATCHUSERMGR_H |