mirror of
https://github.com/moparisthebest/Simba
synced 2024-11-21 16:55:01 -05:00
AppendFile.
This commit is contained in:
parent
c29d3b66e4
commit
e0198ddb91
@ -707,17 +707,77 @@ Simba provides several functions to access files - that is, read
|
||||
from them and write to them.
|
||||
|
||||
\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}
|
||||
|
||||
Opens a file for reading.
|
||||
|
||||
Events called:
|
||||
\begin{itemize}
|
||||
\item ReadFileEvent
|
||||
\end{itemize}
|
||||
\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}
|
||||
|
||||
CloseFile closes the given file.
|
||||
|
||||
\subsection{EndOfFile}
|
||||
|
||||
EndOfFile returns true if the character pointer in the file has reached the end
|
||||
of the file.
|
||||
|
||||
\subsection{FileSize}
|
||||
|
||||
FileSize returns the length of the file in bytes.
|
||||
|
||||
\subsection{ReadFileString}
|
||||
|
||||
ReadFileString reads a string from a file.
|
||||
|
||||
\subsection{WriteFileString}
|
||||
|
||||
WriteFileString writes a string to a file
|
||||
|
||||
\subsection{SetFileCharPointer}
|
||||
|
||||
Set the char pointer to a specific position.
|
||||
|
||||
\subsection{FilePointerPos}
|
||||
|
||||
Get the position of the char pointer.
|
||||
|
||||
\subsection{DirectoryExists}
|
||||
|
||||
Returns true if the directory exists.
|
||||
|
||||
\subsection{FileExists}
|
||||
|
||||
Returns true if the file exists.
|
||||
|
||||
\subsection{WriteINI}
|
||||
\subsection{ReadINI}
|
||||
\subsection{DeleteINI}
|
||||
|
@ -36,6 +36,11 @@ begin
|
||||
Result := CurrThread.Client.MFiles.RewriteFile(Path, Shared);
|
||||
end;
|
||||
|
||||
function ps_AppendFile(const Path: string): Integer; extdecl;
|
||||
begin
|
||||
Result := CurrThread.Client.MFiles.AppendFile(Path);
|
||||
end;
|
||||
|
||||
procedure ps_CloseFile(FileNum: Integer); extdecl;
|
||||
begin
|
||||
CurrThread.Client.MFiles.CloseFile(FileNum);
|
||||
|
@ -111,6 +111,7 @@ SetCurrSection('Files');
|
||||
AddFunction(@ps_CreateFile, 'function CreateFile(const Path: string): 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_AppendFile, 'function AppendFile(const Path: string): Integer;');
|
||||
AddFunction(@ps_CloseFile, 'procedure CloseFile(FileNum: Integer);');
|
||||
AddFunction(@ps_EndOfFile, 'function EndOfFile(FileNum: Integer): Boolean;');
|
||||
AddFunction(@ps_FileSize, 'function FileSize(FileNum: Integer): LongInt;');
|
||||
|
@ -44,6 +44,7 @@ type
|
||||
function CreateFile(Path: string): Integer;
|
||||
function OpenFile(Path: string; Shared: Boolean): Integer;
|
||||
function RewriteFile(Path: string; Shared: Boolean): Integer;
|
||||
function AppendFile(Path: string): Integer;
|
||||
procedure CloseFile(FileNum: Integer);
|
||||
function EndOfFile(FileNum: Integer): Boolean;
|
||||
function FileSizeMuf(FileNum: Integer): LongInt;
|
||||
@ -273,6 +274,32 @@ begin
|
||||
Result := AddFileToManagedList(Path, FS, fMode);
|
||||
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.
|
||||
Returns the handle (index) to the File Array.
|
||||
|
Loading…
Reference in New Issue
Block a user