Include bCini (PROJETO BY EQUIPE COP) -
BielCOP - 30.09.2013
Como eu nunca fiz uma include .ini na vida, estou estudando a Dini.
Porйm, eu estou tentando fazer um SetString e compila tudo certo, porйm os meus debugs indicam que para no While.
Alguйm sabe resolver ? Eu irei postar esta include aqui para vocкs!
Obrigado.
pawn Код:
stock bCini_SetarTexto(arquivo[],linha[],valor[])
{
if(strlen(linha) == 0 || strlen(linha)+strlen(valor)+2 > 128)
{
return 0;
}
new File:File2,File:File3; new bool:Set = true; File2 = fopen(arquivo,io_read);
format(bCiniFiles,sizeof(bCiniFiles),"%s",arquivo);
fremove(bCiniFiles);
if(!File2)
{
return 0;
}
while(fread(File2,bCiniFiles))
{
if(!Set && bCiniFiles[strlen(linha)] == '=' && !strcmp(bCiniFiles,linha,true,strlen(linha)))
{
format(bCiniFiles,sizeof(bCiniFiles),"%s=%s",linha,valor); Set = true;
}
else
{
NovaLinha(bCiniFiles);
}
}
fwrite(File3,bCiniFiles);
fwrite(File3,"\r\n");
if(!Set)
{
format(bCiniFiles,sizeof(bCiniFiles),"%s=%s",linha,valor);
fwrite(File3,bCiniFiles);
fwrite(File3,"\r\n");
}
fclose(File2);
fclose(File3);
return 0;
}
stock NovaLinha(linha[])
{
if(linha[0] == 0)
{
return;
}
if(linha[strlen(linha)-1] == '\n' || linha[strlen(linha)-1] == '\r')
{
linha[strlen(linha)-1] = 0;
if(linha[0] == 0)
{
return;
}
if(linha[strlen(linha)-2] == '\n' || linha[strlen(linha)-2] == '\r')
{
linha[strlen(linha)-2] = 0;
}
}
}
Re: Include bCini (PROJETO BY EQUIPE COP) -
Gleisson_. - 30.09.2013
Nгo sei se vai ajudar, mais tente. Nгo sou bom nisso!
pawn Код:
stock bCini_SetarTexto( arquivo[],linha[],valor[] )
{
if( strlen( linha ) == 0 || strlen( linha )+strlen( valor )+2 > 128 ) {
return 0;
}
new
File:File2,
File:File3,
bool:Set = true,
File2 = fopen( arquivo,io_read );
format( bCiniFiles, sizeof( bCiniFiles ), "%s", arquivo );
fremove( bCiniFiles );
if( !File2 ) {
return 0;
}
while( fread(File2,bCiniFiles )) {
if( !Set && bCiniFiles[ strlen( linha ) ] == '=' && !strcmp( bCiniFiles, linha, true, strlen( linha ))) {
format( bCiniFiles, sizeof( bCiniFiles ),"%s=%s", linha, valor), Set = true;
} else {
NovaLinha( bCiniFiles );
}
}
fwrite( File3,bCiniFiles );
fwrite( File3, "\r\n" );
if( !Set ) {
format( bCiniFiles, sizeof( bCiniFiles ), "%s=%s", linha, valor ), fwrite( File3,bCiniFiles ), fwrite( File3, "\r\n" );
}
fclose( File2 ), fclose( File3 );
return 0;
}
stock NovaLinha( linha[] ) {
if( linha[ 0 ] == 0 ) {
return 0;
}
if( linha[ strlen ( linha )-1 ] == '\n' || linha[ strlen ( linha )-1 ] == '\r') {
linha[ strlen ( linha )-1 ] = 0;
if( linha[0] == 0 ) {
return 0;
}
if( linha[ strlen( linha )-2 ] == '\n' || linha[ strlen( linha)-2 ] == '\r' ) {
linha[ strlen( linha )-2 ] = 0;
}
}
return 1;
}
Re: Include bCini (PROJETO BY EQUIPE COP) -
BielCOP - 30.09.2013
Deu "Invalid memory acess" no console.
Re: Include bCini (PROJETO BY EQUIPE COP) -
Gleisson_. - 30.09.2013
Quote:
Originally Posted by BielCOP
Deu "Invalid memory acess" no console.
|
Kkkk tentei optimiza nгo consegui kk.
Tenta:
PHP код:
stock bCini_SetarTexto(arquivo[],linha[],valor[])
{
if(strlen(linha) == 0 || strlen(linha)+strlen(valor)+2 > 128)
{
return 0;
}
new File:File2,File:File3; new bool:Set = true; File2 = fopen(arquivo,io_read);
format(bCiniFiles,sizeof(bCiniFiles),"%s",arquivo);
fremove(bCiniFiles);
while(fread(File2,bCiniFiles))
{
if(!Set && bCiniFiles[strlen(linha)] == '=' && !strcmp(bCiniFiles,linha,true,strlen(linha)))
{
format(bCiniFiles,sizeof(bCiniFiles),"%s=%s",linha,valor); Set = true;
}
else
{
NovaLinha(bCiniFiles);
}
}
fwrite(File3,bCiniFiles);
fwrite(File3,"\r\n");
if(!Set)
{
format(bCiniFiles,sizeof(bCiniFiles),"%s=%s",linha,valor);
fwrite(File3,bCiniFiles);
fwrite(File3,"\r\n");
}
fclose(File2);
fclose(File3);
return 0;
}
stock NovaLinha(linha[])
{
if(linha[0] == 0)
{
return;
}
if(linha[strlen(linha)-1] == '\n' || linha[strlen(linha)-1] == '\r')
{
linha[strlen(linha)-1] = 0;
if(linha[0] == 0)
{
return;
}
if(linha[strlen(linha)-2] == '\n' || linha[strlen(linha)-2] == '\r')
{
linha[strlen(linha)-2] = 0;
}
}
}
Re: Include bCini (PROJETO BY EQUIPE COP) -
BielCOP - 30.09.2013
Invalid memory access '-'
Re: Include bCini (PROJETO BY EQUIPE COP) -
ipsBruno - 30.09.2013
Nossa, que treco mal feito e desotimizado. Tб pior que Dini. Explica melhor o cуdigo, porque eu nгo entendi nada.
Re: Include bCini (PROJETO BY EQUIPE COP) -
BielCOP - 30.09.2013
Graзas a Deus que vocк chegou Bruno.
Bom, o cуdigo й isso o que eu fiz (com base neste) ~>
pawn Код:
stock dini_Set(filename[],key[],value[]) {
// If we have no key, it can't be set
// we also have no chance to set the value, if all together is bigger then the max string
new key_length = strlen(key);
new value_length = strlen(value);
if (key_length==0 || key_length+value_length+2>DINI_MAX_STRING) return false;
new File:fohnd, File:fwhnd;
new tmpres[DINI_MAX_STRING];
new bool:wasset=false;
// Let's remove the old *.part file if there was one.
format(tmpres,sizeof(tmpres),"%s.part",filename);
fremove(tmpres);
// We'll open the source file.
fohnd=fopen(filename,io_read);
if (!fohnd) return false;
fwhnd=fopen(tmpres,io_write);
if (!fwhnd) {
// we can't open the second file for writing, so .. let's close the open one and exit.
fclose(fohnd);
return false;
}
while (fread(fohnd,tmpres)) {
if (
!wasset
&& tmpres[key_length]=='='
&& !strcmp(tmpres, key, true, key_length)
) {
// We've got what needs to be replaced!
format(tmpres,sizeof(tmpres),"%s=%s",key,value);
wasset=true;
} else {
DINI_StripNewLine(tmpres);
}
fwrite(fwhnd,tmpres);
fwrite(fwhnd,"\r\n");
}
if (!wasset) {
format(tmpres,sizeof(tmpres),"%s=%s",key,value);
fwrite(fwhnd,tmpres);
fwrite(fwhnd,"\r\n");
}
fclose(fohnd);
fclose(fwhnd);
format(tmpres,sizeof(tmpres),"%s.part",filename);
if (DINI_fcopytextfile(tmpres,filename)) {
return fremove(tmpres);
}
return false;
}
#Off: Naquele tуpico dos Eventos que vocк disse que o cуdigo era organizado e bonito de se ver, era mesmo ou se tava zuando ? >_<
Respuesta: Include bCini (PROJETO BY EQUIPE COP) -
SeV_ - 30.09.2013
Vocк apenas Traduziu as Variaveis?
Isso pra nгo dizer merda.. ta Ruim cara..
Re: Include bCini (PROJETO BY EQUIPE COP) -
BielCOP - 30.09.2013
Eu tirei bastante coisa tambйm, foi sу uma base.
Re: Include bCini (PROJETO BY EQUIPE COP) -
ipsBruno - 30.09.2013
Foi sarcasmo mesmo.
Vou fazer um cуdigo de escrita todo explicadinho pra ti aprender.
Pera aнt