plane icon Welcome to Microsoft Flight Simulator’s SDK Q&A Platform!

You have questions regarding the SDK? DevMode Tools? SimConnect? You would like to submit an idea for future improvements, seek help or exchange knowledge? You’re in the right place.

Please take a moment to read the platform’s guidelines before you get started!

question

szm99 avatar image
szm99 asked szm99 answered

fail to get file write access

Hello Guys,

I try to write something to my add-on package, but I always get permission denied error. I have no problem to open file with fopen(".\\data\\test.txt", "rb");.

But I can't get the write permission with fopen(".\\data\\test.txt", "wb");. I search sdk, it look like I need to use "\work" to get the write permission, but I also have no luck with fopen("\work\data\\test.txt", "wb");, strerror() return "permission denied". Please let me know if I miss anything, thanks

gaugeswasm
10 |10000 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 4.8 MiB each and 23.8 MiB total.

Arzop avatar image
Arzop answered Paavo commented

Hi,

Indeed, to access a file, all of your paths must start with "\\work" such as

fopen("\\work\\file.txt", "w");


If you need a subfolder, you have to create one using mkdir before everything else

#include <sys/stat.h>

mkdir("\\work\\data", -1);
fopen("\\work\\data\\file.txt", "w");


Don't forget to use "\\" as path separator in your path. If you don't, it won't work at all or you might have strange file architecture.


Best regards

Maxime / Asobo

1 comment
10 |10000 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 4.8 MiB each and 23.8 MiB total.

How do functions like SimConnect_AICreateEnrouteATCAircraft() access files in "\\work" when used in a WASM module? Just plain "\\work\\flightplan.pln" does not seem to work.

0 Likes 0 ·
szm99 avatar image
szm99 answered

Thanks Maxime, but i still have problem to write file. Here is my code:


mkdir("\\work\\data", -1);

FILE *hFile=fopen("\\work\\data\\file.txt", "wb+");//strerror(errno) return "Not a tty" message

if(hFile)

{

char Char[32]="this is test string";

size_t Len=fwrite(Char, 1, strlen(Char)+1, hFile);


fseek(hFile, 0, SEEK_SET);

char Buf[32]="";

Len=fread(Buf, 1, strlen(Char)+1, hFile);//I can confirm fread can get the "this is test string", no error here


fclose(hFile);//no file been saved at my data folder

hFile=NULL;

}


Although fopen return a valid pointer, but strerror(errno) display a error message "Not a tty". fwrite() and fread() are all ok, I can see fread return the right string, but file.txt did not created at my data folder. If there are any other function I need to call to create a file at my folder? Thanks!

10 |10000 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 4.8 MiB each and 23.8 MiB total.

Arzop avatar image
Arzop answered

Hi,


I tested your code and it works well. If fopen, fwrite and fread work that means your file is created (the errno code is strange, i m going to investigate but it shouldn t be a problem).


Maybe you don t look at the correct location. Your "work" folder will be created in the same folder as your dll/pdb/natvis/... files. (not in your PackageSources folder)


If I may make a comment about your code, you should be careful about

strlen(Char) + 1

because you re going to write unwanted data in your file


Best regards

Maxime / Asobo

10 |10000 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 4.8 MiB each and 23.8 MiB total.

szm99 avatar image
szm99 answered

Hi Maxime,

I have find my file, fwrite() create it to E:\WpSystem\S-1-5-21-329881680-581370512-3514210937-1001\AppData\Local\Packages\Microsoft.FlightSimulator_8wekyb3d8bbwe\LocalState\packages\mycompany-aircraft-wasm-gauge\work\file.txt


I'm not sure, is it right? Thanks!

10 |10000 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 4.8 MiB each and 23.8 MiB total.

Arzop avatar image
Arzop answered

Hi,

Sorry for being late.


Are you using SampleWasmModule project as a base of your addon? If so, it explains "mycompany-aircraft-wasm-gauge" in your path. Otherwise, it s strange.


Best regards

Maxime / Asobo

10 |10000 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 4.8 MiB each and 23.8 MiB total.

szm99 avatar image
szm99 answered

Hi Maxime, my fs2020 is not install at default folder, it install at E:\FS2020. I think that cause the problem. Thanks!

10 |10000 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 4.8 MiB each and 23.8 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 5 attachments (including images) can be used with a maximum of 4.8 MiB each and 23.8 MiB total.