Пример #1
0
int ConfigFile::Write(const char *name){
	
	Section *s;
	s=&head;
	bool first=true;

	File *fp=os.GetFile(name);

	if(fp->OpenWrite()){

		while(s!=NULL){
			string str;
			s->Write(&str);
			fp->WriteStr((char*)str.c_str());
			s=s->GetNext();
		}
		modified=false;
		delete fp;
		return true;
	}else{
		printf("\nFailed to save config file %s\n",name);
		delete fp;
		return false;
	}
}
Пример #2
0
ConfigFile::ConfigFile(const char *name, bool newfile) {
	filename=name;
	lastaccess=NULL;

	printf ("Use config file %s\n", filename.c_str());
	
	if(!newfile){
	    File *fp=os.GetFile(filename.c_str());
	    char line[1024];
	    string section;
	    section="";
	    if(fp->OpenRead()){
		while(fp->ReadLine(line,1023)!=NULL) {
		    if(line[0]=='['){
			//new section
			char *ptr=strchr(line,']');
			if(ptr!=NULL)
			    *ptr='\0';
			section=(&line[1]);
		    }else{
			//normal line
			head.AddLineToSection(line,(char*)section.c_str());
		    }
		}
	    }
	    delete fp;
	};
}