12.12.2014, 20:55
Hi, I start making own file functions for easier writing and reading but i got problem. I have that functions with example in OnFilterScriptInit.
File is created, but nothing is in there, can anyone help me?
Код:
#tryinclude <a_samp> #define MAXIMAL_FILE_PATH_LENGTH 32 #define MAXIMAL_KEY_LENGTH 128 #define MAXIMAL_VALUE_LENGTH 128 static File:CurrentHandle; static CurrentFilePath[MAXIMAL_FILE_PATH_LENGTH]; static filemode:CurrentFileMode; public OnFilterScriptInit() { FileCreate("Test.TXT"); FileOpen("Test.TXT"); FileWriteString("String","XYZ"); FileClose(); return 1; } static stock FileCreate(FileName[]) { if(!fexist(FileName)) { CurrentHandle = fopen(FileName,io_write); if(CurrentHandle) { fclose(CurrentHandle); } else { return 0; } } else { return 0; } return 1; } static stock FileRemove(FileName[]) { if(fexist(FileName)) { fremove(FileName); } else { return 0; } return 1; } static stock FileOpen(FilePath[],filemode:Mode = io_readwrite) { if(fexist(FilePath)) { CurrentHandle = fopen(FilePath,Mode); format(CurrentFilePath,sizeof(CurrentFilePath),FilePath); CurrentFileMode = Mode; if(!CurrentHandle) { return 0; } } else { return 0; } return 1; } static stock FileClose() { if(CurrentHandle) { fclose(CurrentHandle); CurrentHandle = File:0; } else { return 0; } return 1; } static stock FileWriteString(Key[],Value[]) { if(CurrentHandle) { static File:TemporaryHandle; TemporaryHandle = ftemp(); if(TemporaryHandle) { static Line[MAXIMAL_KEY_LENGTH + MAXIMAL_VALUE_LENGTH + 2]; static bool:Found; while(fread(CurrentHandle,Line)) { if(strlen(Line)) { if(!Found && strfind(Line,Key) != -1) { format(Line,sizeof(Line),"%s=%s",Key,Value); Found = true; } else { if(strfind(Line,"\r\n",true) != -1) { strmid(Line,"\r\n",strlen(Line) - 2,strlen(Line)); } } fwrite(TemporaryHandle,Line); fwrite(TemporaryHandle,"\r\n"); } } if(!Found) { format(Line,sizeof(Line),"%s=%s",Key,Value); fwrite(TemporaryHandle,Line); fwrite(TemporaryHandle,"\r\n"); } fclose(CurrentHandle); fremove(CurrentFilePath); CurrentHandle = fopen(CurrentFilePath,CurrentFileMode); if(CurrentHandle) { while(fread(TemporaryHandle,Line)) { if(strlen(Line)) { if(strfind(Line,"\r\n",true) != -1) { strmid(Line,"\r\n",strlen(Line) - 2,strlen(Line)); } fwrite(CurrentHandle,Line); fwrite(CurrentHandle,"\r\n"); } } fclose(TemporaryHandle); } else { return 0; } } else { return 0; } } else { return 0; } return 1; }