1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-25 10:42:20 -05:00

AppendFile.

This commit is contained in:
Merlijn Wajer 2010-05-24 12:08:23 +02:00
parent c29d3b66e4
commit e0198ddb91
4 changed files with 93 additions and 0 deletions

View File

@ -707,17 +707,77 @@ Simba provides several functions to access files - that is, read
from them and write to them. from them and write to them.
\subsection{CreateFile} \subsection{CreateFile}
CreateFile creates a file. It will only create
the file if ti doesn't already exist.
Events called:
\begin{itemize}
\item WriteFileEvent
\end{itemize}
\subsection{OpenFile} \subsection{OpenFile}
Opens a file for reading.
Events called:
\begin{itemize}
\item ReadFileEvent
\end{itemize}
\subsection{RewriteFile} \subsection{RewriteFile}
Rewrite files opens a file for reading and writing, but will remove all the
contents of a file. To open a file for appending, use AppendFile.
Events called:
\begin{itemize}
\item WriteFileEvent
\end{itemize}
\subsection{AppendFile}
AppendFile opens a file for reading and writing, and will not remove the
contents of the file.
Events called:
\begin{itemize}
\item WriteFileEvent
\end{itemize}
\subsection{CloseFile} \subsection{CloseFile}
CloseFile closes the given file.
\subsection{EndOfFile} \subsection{EndOfFile}
EndOfFile returns true if the character pointer in the file has reached the end
of the file.
\subsection{FileSize} \subsection{FileSize}
FileSize returns the length of the file in bytes.
\subsection{ReadFileString} \subsection{ReadFileString}
ReadFileString reads a string from a file.
\subsection{WriteFileString} \subsection{WriteFileString}
WriteFileString writes a string to a file
\subsection{SetFileCharPointer} \subsection{SetFileCharPointer}
Set the char pointer to a specific position.
\subsection{FilePointerPos} \subsection{FilePointerPos}
Get the position of the char pointer.
\subsection{DirectoryExists} \subsection{DirectoryExists}
Returns true if the directory exists.
\subsection{FileExists} \subsection{FileExists}
Returns true if the file exists.
\subsection{WriteINI} \subsection{WriteINI}
\subsection{ReadINI} \subsection{ReadINI}
\subsection{DeleteINI} \subsection{DeleteINI}

View File

@ -36,6 +36,11 @@ begin
Result := CurrThread.Client.MFiles.RewriteFile(Path, Shared); Result := CurrThread.Client.MFiles.RewriteFile(Path, Shared);
end; end;
function ps_AppendFile(const Path: string): Integer; extdecl;
begin
Result := CurrThread.Client.MFiles.AppendFile(Path);
end;
procedure ps_CloseFile(FileNum: Integer); extdecl; procedure ps_CloseFile(FileNum: Integer); extdecl;
begin begin
CurrThread.Client.MFiles.CloseFile(FileNum); CurrThread.Client.MFiles.CloseFile(FileNum);

View File

@ -111,6 +111,7 @@ SetCurrSection('Files');
AddFunction(@ps_CreateFile, 'function CreateFile(const Path: string): Integer;'); AddFunction(@ps_CreateFile, 'function CreateFile(const Path: string): Integer;');
AddFunction(@ps_OpenFile, 'function OpenFile(const Path: string; Shared: Boolean): Integer;'); AddFunction(@ps_OpenFile, 'function OpenFile(const Path: string; Shared: Boolean): Integer;');
AddFunction(@ps_RewriteFile, 'function RewriteFile(const Path: string; Shared: Boolean): Integer;'); AddFunction(@ps_RewriteFile, 'function RewriteFile(const Path: string; Shared: Boolean): Integer;');
AddFunction(@ps_AppendFile, 'function AppendFile(const Path: string): Integer;');
AddFunction(@ps_CloseFile, 'procedure CloseFile(FileNum: Integer);'); AddFunction(@ps_CloseFile, 'procedure CloseFile(FileNum: Integer);');
AddFunction(@ps_EndOfFile, 'function EndOfFile(FileNum: Integer): Boolean;'); AddFunction(@ps_EndOfFile, 'function EndOfFile(FileNum: Integer): Boolean;');
AddFunction(@ps_FileSize, 'function FileSize(FileNum: Integer): LongInt;'); AddFunction(@ps_FileSize, 'function FileSize(FileNum: Integer): LongInt;');

View File

@ -44,6 +44,7 @@ type
function CreateFile(Path: string): Integer; function CreateFile(Path: string): Integer;
function OpenFile(Path: string; Shared: Boolean): Integer; function OpenFile(Path: string; Shared: Boolean): Integer;
function RewriteFile(Path: string; Shared: Boolean): Integer; function RewriteFile(Path: string; Shared: Boolean): Integer;
function AppendFile(Path: string): Integer;
procedure CloseFile(FileNum: Integer); procedure CloseFile(FileNum: Integer);
function EndOfFile(FileNum: Integer): Boolean; function EndOfFile(FileNum: Integer): Boolean;
function FileSizeMuf(FileNum: Integer): LongInt; function FileSizeMuf(FileNum: Integer): LongInt;
@ -273,6 +274,32 @@ begin
Result := AddFileToManagedList(Path, FS, fMode); Result := AddFileToManagedList(Path, FS, fMode);
end; end;
function TMFiles.AppendFile(Path: string): Integer;
var
FS: TFileStream;
fMode: Integer;
Continue : Boolean;
begin
if Assigned(WriteFileEvent) then
begin
Continue := true;
WriteFileEvent(Self,path,continue);
if not Continue then
exit(File_EventError);
end;
fMode := fmOpenReadWrite;
if not FileExists(Path) then
fMode := fMode or fmCreate;
try
FS := TFileStream.Create(UTF8ToSys(Path), fMode);
FS.Seek(0, fsFromEnd);
Result := AddFileToManagedList(Path, FS, fMode);
except
Result := File_AccesError;
TClient(Client).Writeln(Format('AppendFile - Exception. Could not create file: %s',[path]));
end;
end;
{/\ {/\
Opens a file for writing. And deletes the contents. Opens a file for writing. And deletes the contents.
Returns the handle (index) to the File Array. Returns the handle (index) to the File Array.