Răsfoiți Sursa

Added DeInit() and SetWriteDir() functions.

Brucey 5 ani în urmă
părinte
comite
0f4b0f0c17
3 a modificat fișierele cu 36 adăugiri și 1 ștergeri
  1. 2 1
      io.mod/common.bmx
  2. 7 0
      io.mod/glue.c
  3. 27 0
      io.mod/io.bmx

+ 2 - 1
io.mod/common.bmx

@@ -27,12 +27,13 @@ Import "glue.c"
 Extern
 
 	Function bmx_PHYSFS_init:Int()
+	Function PHYSFS_deinit:Int()
 	Function bmx_PHYSHS_getLastError:String()
 	Function bmx_PHYSFS_mount:Int(newDir:String, mountPoint:String, appendToPath:Int)
 	Function bmx_PHYSFS_getBaseDir:String()
 	Function bmx_PHYSFS_getPrefDir:String(org:String, app:String)
 	Function bmx_PHYSFS_mountMemory:Int(dirPtr:Byte Ptr, dirLen:Int, newDir:String, mountPoint:String, appendToPath:Int)
-	
+	Function bmx_PHYSFS_setWriteDir:Int(newDir:String)
 	
 	Function PHYSFS_tell:Long(filePtr:Byte Ptr)
 	Function PHYSFS_seek:Int(filePtr:Byte Ptr, newPos:Long)

+ 7 - 0
io.mod/glue.c

@@ -151,3 +151,10 @@ void bmx_blitzio_closeDir(struct MaxFilesEnumeration * mfe) {
 	PHYSFS_freeList(mfe->files);
 	free(mfe);
 }
+
+int bmx_PHYSFS_setWriteDir(BBString * newDir) {
+	char buf[1024];
+	size_t len = 1024;
+	bbStringToUTF8StringBuffer(newDir, buf, &len);
+	return PHYSFS_setWriteDir(buf);
+}

+ 27 - 0
io.mod/io.bmx

@@ -52,6 +52,23 @@ Type MaxIO
 		End If
 		ioInitialized = True
 	End Function
+	
+	Rem
+	bbdoc: Deinitializes the abstraction layer.
+	about: This closes any files opened via the abstraction layer, blanks the search/write paths, frees memory, and invalidates all of your file handles.
+
+	Note that this call can FAIL if there's a file open for writing that refuses to close (for example, the underlying operating system was
+	buffering writes to network filesystem, and the fileserver has crashed, or a hard drive has failed, etc). It is usually best to close
+	all write handles yourself before calling this function, so that you can gracefully handle a specific failure.
+
+	Once successfully deinitialized, #Init() can be called again to restart the subsystem. All default API states are restored at this point.
+	End Rem
+	Function DeInit:Int()
+		If ioInitialized Then
+			ioInitialized = False
+			Return PHYSFS_deinit()
+		End If
+	End Function
 
 	Rem
 	bbdoc: Adds an archive or directory to the search path.
@@ -129,6 +146,16 @@ Type MaxIO
 	Function GetPrefDir:String(org:String, app:String)
 		Return bmx_PHYSFS_getPrefDir(org, app)
 	End Function
+	
+	Rem
+	bbdoc: Indicates where files may be written.
+	about: Sets a new write dir. This will override the previous setting.
+
+	This call will fail (and fail to change the write dir) if the current write dir still has files open in it.
+	End Rem
+	Function SetWriteDir:Int(newDir:String)
+		Return bmx_PHYSFS_setWriteDir(newDir)
+	End Function
 
 	Rem
 	bbdoc: Gets various information about a directory or a file.