On this topic, I just ran a test to check compatibility of ConfigFile between Godot 3 and Godot 4. I did the test using Godot 3.5.3-stable and Godot 4.2-dev6.
The test result:
Plain text files created by ConfigFile in either version are read correctly by the other version.
Encrypted files created by ConfigFile in either version are NOT readable by the other version. The result reported by ConfigFile is ERR_FILE_CORRUPT = 16.
Here's the code, if anyone wants to try it. The same code works in both Godot versions. You may need to change the path in the constant DIR.
extends Node
const I: int = 42
const F: float = 7.5
const B: bool = true
const S: String = "hello"
const V: Vector2 = Vector2(1.1, 2.2)
const A: Array = [3, 4]
const D: Dictionary = {"a": 15, "b": 30}
const DATA: Dictionary = {
"I": I,
"F": F,
"B": B,
"S": S,
"V": V,
"A": A,
"D": D,
}
const DIR: String = "/tmp/godot_configfile_test/"
const PATH_GODOT_3: String = DIR + "godot3.txt"
const PATH_GODOT_3_ENCRYPTED: String = DIR + "godot3_encrypted.dat"
const PATH_GODOT_4: String = DIR + "godot4.txt"
const PATH_GODOT_4_ENCRYPTED: String = DIR + "godot4_encrypted.dat"
const PASSWORD: String = "godot"
func _ready() -> void:
var version: int = Engine.get_version_info()["major"]
print_debug("Godot version=", version)
match version:
3:
write_file(PATH_GODOT_3)
write_file(PATH_GODOT_3_ENCRYPTED, true)
4:
write_file(PATH_GODOT_4)
write_file(PATH_GODOT_4_ENCRYPTED, true)
read_and_test_file(PATH_GODOT_3)
read_and_test_file(PATH_GODOT_3_ENCRYPTED, true)
read_and_test_file(PATH_GODOT_4)
read_and_test_file(PATH_GODOT_4_ENCRYPTED, true)
func write_file(path: String, encrypted: bool = false) -> void:
var config_file: ConfigFile = ConfigFile.new()
config_file.set_value("section", "key", DATA)
var err: int
if encrypted:
err = config_file.save_encrypted_pass(path, PASSWORD)
else:
err = config_file.save(path)
if err == OK:
print_debug("Successfully wrote file '%s'" % path)
else:
print_debug("Failed to write file '%s', error=%d" % [path, err])
func read_and_test_file(path: String, encrypted: bool = false) -> void:
var config_file: ConfigFile = ConfigFile.new()
var err: int
if encrypted:
err = config_file.load_encrypted_pass(path, PASSWORD)
else:
err = config_file.load(path)
if err == OK:
print_debug("Successfully read file '%s'" % path)
else:
print_debug("Failed to read file '%s', error=%d" % [path, err])
return
var data: Dictionary = config_file.get_value("section", "key")
if data == null:
print_debug("Failed to extract data from file")
return
print_debug("data=", data)
var ok: bool = true
if not data is Dictionary:
print_debug("Data test failed: data type")
ok = false
if not data.has_all(DATA.keys()):
print_debug("Data test failed: missing key(s)")
ok = false
if not (data["I"] is int and data["I"] == I):
print_debug("Data test failed: I")
ok = false
if not (data["F"] is float and data["F"] == F):
print_debug("Data test failed: F")
ok = false
if not (data["B"] is bool and data["B"] == B):
print_debug("Data test failed: B")
ok = false
if not (data["S"] is String and data["S"] == S):
print_debug("Data test failed: S")
ok = false
if not (data["V"] is Vector2 and data["V"].x == V.x and data["V"].y == V.y):
print_debug("Data test failed: V")
ok = false
if not (data["A"] is Array and data["A"].size() == A.size()\
and data["A"][0] == A[0] and data["A"][1] == A[1]):
print_debug("Data test failed: A")
ok = false
if not (data["D"] is Dictionary and data["D"].size() == D.size()\
and data["D"]["a"] == D["a"] and data["D"]["b"] == D["b"]):
print_debug("Data test failed: D")
ok = false
if ok:
print_debug("All data tests passed for file '%s'" % path)
I just tried the code posted above by belgian_street_lamp, in Godot 4. It successfully reads an encrypted file created by ConfigFile in Godot 3.