hedgewars/uPhysFSLayer.pas
branchqmlfrontend
changeset 11607 f0dcdbb9b2fe
parent 11403 b894922d58cc
child 11633 215b837c16f9
--- a/hedgewars/uPhysFSLayer.pas	Mon Mar 14 22:08:27 2016 +0300
+++ b/hedgewars/uPhysFSLayer.pas	Tue Mar 15 22:29:40 2016 +0300
@@ -22,17 +22,21 @@
 function rwopsOpenWrite(fname: shortstring): PSDL_RWops;
 
 function pfsOpenRead(fname: shortstring): PFSFile;
+function pfsOpenWrite(fname: shortstring): PFSFile;
+function pfsFlush(f: PFSFile): boolean;
 function pfsClose(f: PFSFile): boolean;
 function pfsSeek(f: PFSFile; pos: QWord): boolean;
 
 procedure pfsReadLn(f: PFSFile; var s: shortstring);
 procedure pfsReadLnA(f: PFSFile; var s: ansistring);
+procedure pfsWriteLn(f: PFSFile; s: shortstring);
 function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64;
 function pfsEOF(f: PFSFile): boolean;
 function pfsEnumerateFiles(dir: shortstring): PPChar;
 procedure pfsFreeList(list: PPChar);
 
 function pfsExists(fname: shortstring): boolean;
+function pfsMakeDir(path: shortstring): boolean;
 
 function  physfsReader(L: Plua_State; f: PFSFile; sz: Psize_t) : PChar; cdecl; external PhyslayerLibName;
 procedure physfsReaderSetBuffer(buf: pointer); cdecl; external PhyslayerLibName;
@@ -49,11 +53,16 @@
 function PHYSFS_deinit(): LongInt; cdecl; external PhysfsLibName;
 function PHYSFS_mount(newDir, mountPoint: PChar; appendToPath: LongBool) : LongBool; cdecl; external PhysfsLibName;
 function PHYSFS_openRead(fname: PChar): PFSFile; cdecl; external PhysfsLibName;
+function PHYSFS_openWrite(fname: PChar): PFSFile; cdecl; external PhysfsLibName;
+function PHYSFS_setWriteDir(path: PChar): LongBool; cdecl; external PhysfsLibName;
 function PHYSFS_eof(f: PFSFile): LongBool; cdecl; external PhysfsLibName;
 function PHYSFS_readBytes(f: PFSFile; buffer: pointer; len: Int64): Int64; cdecl; external PhysfsLibName;
+function PHYSFS_writeBytes(f: PFSFile; buffer: pointer; len: Int64): Int64; cdecl; external PhysfsLibName;
 function PHYSFS_seek(f: PFSFile; pos: QWord): LongBool; cdecl; external PhysfsLibName;
+function PHYSFS_flush(f: PFSFile): LongBool; cdecl; external PhysfsLibName;
 function PHYSFS_close(f: PFSFile): LongBool; cdecl; external PhysfsLibName;
 function PHYSFS_exists(fname: PChar): LongBool; cdecl; external PhysfsLibName;
+function PHYSFS_mkdir(path: PChar): LongBool; cdecl; external PhysfsLibName;
 function PHYSFS_getLastError(): PChar; cdecl; external PhysfsLibName;
 function PHYSFS_enumerateFiles(dir: PChar): PPChar; cdecl; external PhysfsLibName;
 procedure PHYSFS_freeList(list: PPChar); cdecl; external PhysfsLibName;
@@ -79,11 +88,21 @@
     exit(PHYSFS_openRead(Str2PChar(fname)));
 end;
 
+function pfsOpenWrite(fname: shortstring): PFSFile;
+begin
+    exit(PHYSFS_openWrite(Str2PChar(fname)));
+end;
+
 function pfsEOF(f: PFSFile): boolean;
 begin
     exit(PHYSFS_eof(f))
 end;
 
+function pfsFlush(f: PFSFile): boolean;
+begin
+    exit(PHYSFS_flush(f))
+end;
+
 function pfsClose(f: PFSFile): boolean;
 begin
     exit(PHYSFS_close(f))
@@ -99,6 +118,11 @@
     exit(PHYSFS_exists(Str2PChar(fname)))
 end;
 
+function pfsMakeDir(path: shortstring): boolean;
+begin
+    exit(PHYSFS_mkdir(Str2PChar(path)))
+end;
+
 function pfsEnumerateFiles(dir: shortstring): PPChar;
 begin
     exit(PHYSFS_enumerateFiles(Str2PChar(dir)))
@@ -144,6 +168,14 @@
 s:= s + ansistring(b)
 end;
 
+procedure pfsWriteLn(f: PFSFile; s: shortstring);
+var c: char;
+begin
+    c:= #10;
+    PHYSFS_writeBytes(f, @s[1], byte(s[0]));
+    PHYSFS_writeBytes(f, @c, 1);
+end;
+
 function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64;
 var r: Int64;
 begin
@@ -192,8 +224,11 @@
 {$ENDIF}
 
     pfsMountAtRoot(localPrefix);
+    pfsMount(userPrefix, PChar('/Config'));
+    pfsMakeDir('/Config/Data');
+    pfsMakeDir('/Config/Logs');
     pfsMountAtRoot(userPrefix + ansistring('/Data'));
-    pfsMount(userPrefix, PChar('/Config'));
+    PHYSFS_setWriteDir(userPrefix);
 
     hedgewarsMountPackages;