Add cfgfile lib from Xe-Release
This commit is contained in:
parent
0a8d0291db
commit
d0f9f6bbf2
|
@ -0,0 +1,70 @@
|
|||
// A Test to read Config files
|
||||
// This is a modified version
|
||||
// The Config File Should be a text file
|
||||
// and the content as follows
|
||||
// key=value
|
||||
|
||||
#include "cfgfile.hh"
|
||||
|
||||
static void Trim(std::string &str){
|
||||
if(str.empty()){//String is empty
|
||||
return;
|
||||
}
|
||||
|
||||
size_t i,start_pos,end_pos;
|
||||
|
||||
for(i=0;i<str.size();i++){//Get Start Position
|
||||
if(!isspace(str[i])){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(i==str.size()){//Only Space and Tabs in string
|
||||
return;
|
||||
}
|
||||
|
||||
start_pos=i;
|
||||
|
||||
for(i=str.size()-1;i>=0;i--){//Get End Position
|
||||
if(!isspace(str[i])){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
end_pos=i;
|
||||
|
||||
str=str.substr(start_pos,end_pos+1);
|
||||
}
|
||||
|
||||
bool readCfgFile(const char * cfgfilePath,const std::string &key,std::string &value){
|
||||
//Open The Config File
|
||||
std::fstream cfgfile;
|
||||
cfgfile.open(cfgfilePath);
|
||||
if(!cfgfile.is_open()){
|
||||
std::cout<<"Failed to open the file!"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
//Read each line of config file and get value
|
||||
char tmp[1000];
|
||||
while(!cfgfile.eof()){
|
||||
cfgfile.getline(tmp,1000);
|
||||
std::string line(tmp);
|
||||
std::size_t pos = line.find('=');//Get the position of '='
|
||||
|
||||
if(pos == std::string::npos){
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string tmpkey=line.substr(0,pos);
|
||||
if(tmpkey == key){
|
||||
value=line.substr(pos+1);
|
||||
Trim(value);
|
||||
cfgfile.close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
cfgfile.close();
|
||||
return false;
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
bool readCfgFile(const char * cfgfilePath,const std::string &key,std::string &value);
|
|
@ -20,6 +20,9 @@ pkg_check_modules (GTKMM3 REQUIRED gtkmm-3.0)
|
|||
include_directories (${GTKMM3_INCLUDE_DIRS})
|
||||
link_directories (${GTKMM3_LIBRARY_DIRS})
|
||||
|
||||
#Source files
|
||||
set(SOURCE_FILE src/main.cc src/MyWin.cc src/MyPrefs.cc ../cfgfile/cfgfile.cc)
|
||||
|
||||
#Compile Resource
|
||||
|
||||
set(RESOURCE_LIST
|
||||
|
@ -48,9 +51,9 @@ if(WIN32)
|
|||
set_property(SOURCE ../icon.rc APPEND PROPERTY
|
||||
OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/../icon.ico
|
||||
)
|
||||
add_executable(${PROJECT_NAME} WIN32 ${app_WINRC} src/main.cc src/MyWin.cc src/MyPrefs.cc ${RESOURCE_FILE})
|
||||
add_executable(${PROJECT_NAME} WIN32 ${app_WINRC} ${SOURCE_FILE} ${RESOURCE_FILE})
|
||||
else()
|
||||
add_executable(${PROJECT_NAME} src/main.cc src/MyWin.cc src/MyPrefs.cc ${RESOURCE_FILE})
|
||||
add_executable(${PROJECT_NAME} ${SOURCE_FILE} ${RESOURCE_FILE})
|
||||
|
||||
endif(WIN32)
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "winpe.xpm"
|
||||
#include "../Gtk4/img7.xpm"
|
||||
#include "image_types.hh"
|
||||
#include "cfgfile/cfgfile.hh"
|
||||
#include <iostream>
|
||||
|
||||
MyPrefs::MyPrefs()
|
||||
|
|
Loading…
Reference in New Issue