Is there a way to set or determine file share access?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By NocturnalWisp

When using something like File.open within gdscript, is there a way to set the file sharing settings on the access.

The example being, (I use Unity for everything else) C# has a FileInfo constructor that takes an enum called FileShare. It allows other programs to write and/or read while I’m accessing the file in my program.

My particular use case is for speeding up iteration using data driven csv or custom data files. I did a similar thing in Unity where I could alter a file during run time and it would change values that are being utilized in the game. AKA Hot Reloading.

Thanks for any help!

:bust_in_silhouette: Reply From: aipie

Yes, you can provide ModeFlags.
see this for the open-method.
https://docs.godotengine.org/en/stable/classes/class_file.html#class-file-method-open
You can click through on the parameter ModeFlags type to see all available values.

Thank you for your answer!

However it’s not quite what I am looking for. The ModeFlags only help provide access to that particular file in my application. I am looking to make sure that other applications can have access to my file at the same time. Most likely NotePad, or some general text editor.

The C# class constructor can take a FileShare enum in the constructor allowing other processes to access the same file: https://docs.microsoft.com/en-us/dotnet/api/system.io.fileshare?view=net-6.0

It also takes in the FileMode for the particular process I am running. Is this a C++ thing? Will I need to write a module to customize this behaviour?

Thank you for your help!

NocturnalWisp | 2022-05-03 18:51

:bust_in_silhouette: Reply From: NocturnalWisp

So as it seems, the file is shared anyway after some testing. I can open up an external text editor while my game is running and alter files (In this case I am using YAML) without needing to restart the game.

If you come across this question and are looking to set the file share so no other process than your game can access, you may need to write an editor plugin.

Hope this helps!