#ifndef INIFILE_H
#define INIFILE_H
#include <QSettings>
#include "UpdateSystem/UpdateSystem.h"
class IniFile
{
public:
IniFile();
void CreatExampleIniFile(QString path); //创建新文件
void ReadIniFile(); // 返回数据
bool CheckIni();
QSettings *IniInfo;
void DeleteIni(QString Group_data);
void AddIni(QStringList data);
void DeleteINI_Section(QString ObjSection,QString ObjPath);
void DeleteINI_Key(QString ObjSection, QString ObjKey,QString ObjPath);
};
#endif // INIFILE_H
#include "inifile.h"
#include <QDebug>
#include <QVector>
#include <QMessageBox>
QString IniFilePath;
IniFile::IniFile()
{
IniFilePath = Prj_Path.replace("exe","ini");
QFile Inifile(IniFilePath);
if(!Inifile.exists()){ //如果路径下不存在ini文件,新建一个
if(!Inifile.open(QIODevice::WriteOnly|QIODevice::Text)){ //如果打开不成功
qDebug()<<QObject::tr("打开失败");
}
else{
CreatExampleIniFile(IniFilePath);
Inifile.close();
}
}
else{//如果路径下存在ini文件
ReadIniFile();
}
}
void IniFile::CreatExampleIniFile(QString path)
{
IniInfo = new QSettings(path, QSettings::IniFormat);
IniInfo->beginGroup("0"); // 设置当前节名,代表以下的操作都是在这个节中
IniInfo->setValue( "Product_example", "1");
IniInfo->setValue( "ProductType", "1");
IniInfo->setValue( "ChipType", "ST");
IniInfo->setValue( "Address", "0x20000010~0x20010000:0x00000000\n0x00805000~0x0080A000:0x00020000");
IniInfo->endGroup(); // 结束当前节的操作
}
void IniFile::ReadIniFile()
{
if(!CheckIni()){ // 校验不通过,备