使用ini来添加版本检测需求
//.ini
;####################################################################################
;FileType:版本配置文件
;格 式:
; [节点]:为序号 (按照顺序添加版本)
; 标志:E(检测是否存在) P(权限检测) M(MD5检测) A(检测所有) T(检查文件内容,查询多条内容以|分割)
; version:版本号 (必填)
; plug=插件列表(以|分割)
; 文件路径=标志|(如果是A或M标志)MD5码
;####################################################################################
[0]
version=V1.0
[1]
version=V2.0
plug=mysql-server|php7.0|php7.0-curl|vlc|openjdk-8-jdk
/home/ledmedia/.config/autostart/LED_Upgrade.desktop=E|
/etc/udev/rules.d/70-persistent-net.rules=E|
/etc/acpi/poweroff_1.sh=E|
//Parse_INI_File.h
#ifndef PARSE_INI_FILE_H_
#define PARSE_INI_FILE_H_
#include <map>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
#define CONFIGLEN 256
enum INI_RES
{
INI_SUCCESS, //成功
INI_ERROR, //普通错误
INI_OPENFILE_ERROR, //打开文件失败
INI_NO_ATTR //无对应的键值
};
// 子键索引 子键值
typedef map<std::string,std::string> KEYMAP;
// 主键索引 主键值
typedef map<std::string,KEYMAP> MAINKEYMAP;
typedef MAINKEYMAP::iterator MAINMAPIT;
typedef KEYMAP::iterator MAPIT;
// config 文件的基本操作类
class CIni
{
public:
// 构造函数
CIni();
// 析够函数
virtual ~CIni();
public:
//获取整形的键值
int GetInt(const char* mAttr, const char* cAttr );
//获取键值的字符串
char *GetStr(const char* mAttr, const char* cAttr );
// 打开config 文件
INI_RES OpenFile(const char* pathName, const char* type);
// 关闭config 文件
INI_RES CloseFile();
// 打印所有文件内容
void PrintAllDate();
MAINKEYMAP m_Map;
protected:
// 读取config文件
INI_RES GetKey(const char* mAttr, const char* cAttr, char* value);
protected:
// 被打开的文件局柄
FILE* m_fp;
char m_szKey[ CONFIGLEN ];
};
#endif
//Parse_INI_File.cpp
#include "Parse_INI_File.h"
/******************************************************************************
* 功 能:构造函数
* 参 数:无
* 返回值:无
* 备 注:
******************************************************************************/
CIni::CIni( )
{
memset( m_szKey,0,sizeof(m_szKey) );
m_fp = NULL;
}
/******************************************************************************
* 功 能:析构函数
* 参 数:无
* 返回值:无
* 备 注:
******************************************************************************/
CIni::~CIni()
{
m_Map.clear();
}
/******************************************************************************
* 功 能:打开文件函数
* 参 数:无
* 返回值:
* 备 注:
******************************************************************************/
INI_RES CIni::OpenFile(const char* pathName, const char* type)
{
string szLine,szMainKey,szLastMainKey,szSubKey;
char strLine[ CONFIGLEN ] = { 0 };
KEYMAP mLastMap;
int nIndexPos = -1;
int nLeftPos = -1;
int nRightPos = -1;
m_fp = fopen(pathName, type);
if (m_fp == NULL){
printf( "open inifile %s error!\n",pathName );
return INI_OPENFILE_ERROR;
}
m_Map.clear();
while( fgets( strLine, CONFIGLEN,m_fp) ){
//忽略注释;
if(strLine[0] == ';'){
continue;
}
szLine.assign( strLine );
//删除字符串中的非必要字符
nLeftPos = szLine.find("\n" );
if( string::npos != nLeftPos ){
szLine.erase( nLeftPos,1 );
}
nLeftPos = szLine.find("\r" );
if( string::npos != nLeftPos ){
szLine.erase( nLeftPos,1 );
}
//判断是否是主键
nLeftPos = szLine.find("[");
nRightPos = szLine.find("]");
// cout<<"Src:"<<szLine<<endl;
// cout<<"L:"<<nLeftPos<<" R:"<<nRightPos<<endl;
if( nLeftPos != string::npos && nRightPos != string::npos && nLeftPos == 0){
szLine.erase( nLeftPos,1 );
nRightPos--;
szLine.erase( nRightPos,1 );
// cout<<"节点名称遍历:"<<szLastMainKey<<"大小:"<<szLastMainKey.length()<<endl;
if(strcmp(szLastMainKey.c_str(),"") != 0){
<