Browse Source

Merge pull request #72381 from yedpodtrzitko/yed/update-fileaccess-docs

docs: replace `File` with `FileAccess`
Rémi Verschelde 2 years ago
parent
commit
a5cefef2d8

+ 2 - 2
doc/classes/EditorImportPlugin.xml

@@ -37,8 +37,8 @@
 		    return [{"name": "my_option", "default_value": false}]
 
 		func _import(source_file, save_path, options, platform_variants, gen_files):
-		    var file = File.new()
-		    if file.open(source_file, File.READ) != OK:
+		    var file = FileAccess.open(source_file, FileAccess.READ)
+		    if file == null:
 		        return FAILED
 		    var mesh = ArrayMesh.new()
 		    # Fill the Mesh with data read in "file", left as an exercise to the reader.

+ 1 - 2
doc/classes/EditorTranslationParserPlugin.xml

@@ -15,8 +15,7 @@
 		extends EditorTranslationParserPlugin
 
 		func _parse_file(path, msgids, msgids_context_plural):
-		    var file = File.new()
-		    file.open(path, File.READ)
+		    var file = FileAccess.open(path, FileAccess.READ)
 		    var text = file.get_as_text()
 		    var split_strs = text.split(",", false)
 		    for s in split_strs:

+ 5 - 6
doc/classes/HashingContext.xml

@@ -11,15 +11,14 @@
 		const CHUNK_SIZE = 102
 
 		func hash_file(path):
-		    var ctx = HashingContext.new()
-		    var file = File.new()
-		    # Start a SHA-256 context.
-		    ctx.start(HashingContext.HASH_SHA256)
 		    # Check that file exists.
-		    if not file.file_exists(path):
+		    if not FileAccess.file_exists(path):
 		        return
+		    # Start a SHA-256 context.
+		    var ctx = HashingContext.new()
+		    ctx.start(HashingContext.HASH_SHA256)
 		    # Open the file to hash.
-		    file.open(path, File.READ)
+		    var file = FileAccess.open(path, FileAccess.READ)
 		    # Update the context after reading each chunk.
 		    while not file.eof_reached():
 		        ctx.update(file.get_buffer(CHUNK_SIZE))

+ 2 - 6
modules/minimp3/doc_classes/AudioStreamMP3.xml

@@ -21,21 +21,17 @@
 			[codeblocks]
 			[gdscript]
 			func load_mp3(path):
-			    var file = File.new()
-			    file.open(path, File.READ)
+			    var file = FileAccess.open(path, FileAccess.READ)
 			    var sound = AudioStreamMP3.new()
 			    sound.data = file.get_buffer(file.get_length())
-			    file.close()
 			    return sound
 			[/gdscript]
 			[csharp]
 			public AudioStreamMP3 LoadMP3(string path)
 			{
-			    var file = new File();
-			    file.Open(path, File.READ);
+			    using var file = FileAccess.Open(path, FileAccess.ModeFlags.Read);
 			    var sound = new AudioStreamMP3();
 			    sound.Data = file.GetBuffer(file.GetLength());
-			    file.Close();
 			    return sound;
 			}
 			[/csharp]