• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

How do I check to see if a file is read only, if I import my game to a Linux or MacOS platform in gml?

Ok, heres another one of my headaches with GMS....

I notice that only the Windows version of GMS2, has the feature of letting you check a files attributes. Well the most important
file attribute that I need is to know for a file is, if a file is read only. Lets, say I want to import my game to a Linux or
MacOS that has GMS2.....

How do you program your game to check whether a file will let you write to it or on a Linux or MacOS platfrom, in GMS2 ?

If I want to overwrite an existing file, or append data to an existing file, or delete an existing file, then I want to check to see
if the read only file attribute exists beforehand....... because if I don't, something bad will happen. It wouldn't make sense
to try and write to a file that is read only, and not inform the user through the game that it cant write to that file. However
the manual doesn't say what exists instead for the other licenses of GMS for Linux or MacOS platforms, in this circumstance.

So the other idea that came to my mind... that maybe there is a error value that I need to check for when I open a file for
writing. I did not find one thing about a error value to check for in any of the functions that open files for writing, when
those functions fail. Not one of any of the examples provided in the manual demonstrates in the code examples, show how to
use those functions, using a if statement to check if those functions fail, to tell the user ( or the programmer ) that they cant
open the file for writing to ( in the case that the file exists and its permissions are set to read only ).

Since the Windows version of GMS is the only version that allows the program to check to see if a file is read only,
the conclusion that I am thinking ( which I hope is not true ), is that for the other two platforms, Linux and MacOS which
don't have that feature in gml to check a file attribute, is that you have to inconvenience the user player with the task, of
having them go outside of the game, to check if the file is read only or not, by using the OS.

Is this a design fault of GMS, or what is the solution ? I am just going by what I am reading in the manual.
 

rIKmAN

Member
Have a look around for any extensions that will allow you to do the checking on Mac/Linux?

I haven't checked but my first thought would be that maybe one of the extensions by @Samuel Venable can do it as most if not all of his stuff is cross platform Win/Mac/Linux and deals with filesystem stuff.

You can wait for him to confirm (if he sees the @) but I would just take a look at the signature on his posts as IIRC he lists all of his extensions there and you should be able to check each one out to see if it does what you want.

If they don't, then maybe talk to him about contracting the work for the features you want.
 
S

Sam (Deleted User)

Guest
Have a look around for any extensions that will allow you to do the checking on Mac/Linux?

I haven't checked but my first thought would be that maybe one of the extensions by @Samuel Venable can do it as most if not all of his stuff is cross platform Win/Mac/Linux and deals with filesystem stuff.

You can wait for him to confirm (if he sees the @) but I would just take a look at the signature on his posts as IIRC he lists all of his extensions there and you should be able to check each one out to see if it does what you want.

If they don't, then maybe talk to him about contracting the work for the features you want.
I literally just made an update to my file manager extension and was about to publish it, but adding the ability to read more attributes is very useful and I was thinking of adding a means to do this already, but the guy who I updated the extension for didn't need that in specific. This is really good timing.
 
I literally just made an update to my file manager extension and was about to publish it, but adding the ability to read more attributes is very useful and I was thinking of adding a means to do this already, but the guy who I updated the extension for didn't need that in specific. This is really good timing.
I downloaded one of your assets ( I think I need to update it ), that I have questions that I want to ask you about... on a different subject about using MS-DOS from GMS.

However, to stick to my OP, I find it really strange that Windows is the only platform in which GMS allows you to check for file attributes. I have no idea why in GMS its not possible in Linux or MacOS, to do the same job. Maybe @Nocturne might know something about this, or someone who is more familiar with those licenses of GMS. I just want to be able program the game to check if a file is read only. I have
looked through the GMS manual online, and I found nothing for help.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
I'm pretty sure GMS only reads those attributes on windows because of legacy code from the old GM7 (or earlier!)... Given that windows has a looooong history, those functions still work now even though I doubt the internal GM code has been touched in a decade!!!! If you want these functions to work on other platforms, or equivalent functions to be added for other platforms, contact YYG and hope they sort it out... Or you'll have to make them yourself via extensions.
 
If they don't, then maybe talk to him about contracting the work for the features you want.
If it comes to the point where I have to contract someone to make me a custom extension for GMS just to a read file attribute in Linux or MacOS, then I will drop the whole idea of importing my game/software to Linux and MacOS, because its not worth it. This is a serious design fault on the development of GMS by YoYoGames. It does not make sense to have one license of GMS, such as Windows, to have the ability to read file attributes, if you cant provide the same thing for linux or MacOS licenses of GMS.
 
I'm pretty sure GMS only reads those attributes on windows because of legacy code from the old GM7 (or earlier!)... Given that windows has a looooong history, those functions still work now even though I doubt the internal GM code has been touched in a decade!!!! If you want these functions to work on other platforms, or equivalent functions to be added for other platforms, contact YYG and hope they sort it out... Or you'll have to make them yourself via extensions.
If thats what I have to do, then I wont import my game to those platforms that GMS has licenses for. Its not worth it.
 

FrostyCat

Redemption Seeker
If it comes to the point where I have to contract someone to make me a custom extension for GMS just to a read file attribute in Linux or MacOS, then I will drop the whole idea of importing my game/software to Linux and MacOS, because its not worth it. This is a serious design fault on the development of GMS by YoYoGames. It does not make sense to have one license of GMS, such as Windows, to have the ability to read file attributes, if you cant provide the same thing for linux or MacOS licenses of GMS.
Except on Unix-based platforms (which Linux and Mac OS both are), read-only status is not a simple single flag like on Windows. It is based on your current user ID and group ID, relative to a set of flags governing read, write, and execute permissions for same-user, same-group, and other. So if you have a permission of-rwx-r-x-r-x on a file owned by user A, it would be read-write if a program run by user A accesses it, but read-only if a program run by some other non-root user B accesses it. file_attributes is a Windows-only function because it dates from when GM was a Windows-only program, and file attributes on Windows work on a completely different basis than file attributes on Unix-based platforms.
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
Usually you perform an operation (such as opening a file_text for writing/append, or saving a buffer) and check the status to see if it succeeded, then notify the user if it didn't.

There are numerous cases where operation can fail (even Windows has complex group permissions that are separate from file attributes) and it would make little sense to attempt to predict them on individual basis.
 
Except on Unix-based platforms (which Linux and Mac OS both are), read-only status is not a simple single flag like on Windows. It is based on your current user ID and group ID, relative to a set of flags governing read, write, and execute permissions for same-user, same-group, and other. So if you have a permission of-rwx-r-x-r-x on a file owned by user A, it would be read-write if a program run by user A accesses it, but read-only if a program run by some other non-root user B accesses it. file_attributes is a Windows-only function because it dates from when GM was a Windows-only program, and file attributes on Windows work on a completely different basis than file attributes on Unix-based platforms.
That does not validate the reason to NOT have a function for Linux or MacOS in GMS, that does the same thing. All I want to do is check the file attributes for a read-only attribute, or in some method, at least through a function that interprets the error from the function I am calling that indicates that writing to a file can not be done. It could mean many things, but it would mean, in general that that the file is read-only for a reason. I have neither of those abilities in GMS, when it comes to Linux or MacOS. Tbh, I have no idea how MacOS implements Linux in its OS compared to PCs that have Linux, but I do know they do both use something equivalent to Window's file attributes, when it comes to indicating a read-only file. The issue of user permissions based on user ID and group ID is not the problem.

I can write on any of the operating systems , a piece of portable code written in C that checks if a file can be written to, or not. The program can run in Windows( using Visual Studio ) /MS-DOS ( using DJGPP ) , Linux ( using gcc ), and in MacOS ( using Code Warrior )
the following code in C, using this snippet from a program I wrote :


// if the file has a read only attribute...
if ((pf = fopen(*(argv+1), "wb+")) == NULL)
{
printf("ERROR: can not delete %s, process aborted\n",*(argv+1));
fclose(pf);
exit(4);
}



IF any of the functions in GMS that involve opening a file for writing to , could return a NULL file pointer ( or whatever GMS would call it ), it would determine that the file can not be written to. The game in GMS , does not have explain to the user, that the file is read only, it only has to explain that the file can not be written to, which can imply that the file is read only, OR in the case of Linux, the user does not have permission due to user ID and group ID. I dont care about any of the other attributes that Windows has, or what Linux has for its file attributes. The ability to check if a file is read only is the most important thing for any program that reads and writes files, in any programming language.

So if your writing a game in GMS2 for the Linux or MacOS, what happens when you try to write to a file that is read only? Does the program crash? Does the OS halt the program with a annoying pop-up message or something equivalent? I would like to know how you compensate for this problem in GMS2, when it comes to those two platform systems.
 

rIKmAN

Member
If it comes to the point where I have to contract someone to make me a custom extension for GMS just to a read file attribute in Linux or MacOS, then I will drop the whole idea of importing my game/software to Linux and MacOS, because its not worth it.
Cool, end of discussion then I guess.

Apologies for the pointless @ Sam.
 
Last edited:
Cool, end of discussion then I guess.

Apologies for the pointless @ Sam.
So if your writing a game in GMS2 for the Linux or MacOS, what happens when you try to write to a file that is read only? Does the program crash? Does the OS halt the program with a annoying pop-up message or something equivalent? I would like to know how you compensate for this problem in GMS2, when it comes to those two platform systems.
 
S

Sam (Deleted User)

Guest
So if your writing a game in GMS2 for the Linux or MacOS, what happens when you try to write to a file that is read only? Does the program crash? Does the OS halt the program with a annoying pop-up message or something equivalent? I would like to know how you compensate for this problem in GMS2, when it comes to those two platform systems.
No
 
S

Sam (Deleted User)

Guest
You can use my file manager extension to do this already I just realized.

It requires writing your file of choice to the sandbox directory, which can be gotten with `game_save_id` constant.

After the file is written you can copy it try to delete the destination file and overwrite it, like so:

GML:
if (file_delete("C:/path/to/destination/file.txt") == true) {
  file_copy(game_save_id + "file.txt", "C:/path/to/destination/file.txt");
} else {
  show_error("you do not have permission to save to this destination file!", false);
}
My extension overrides these file_* functions allowing you to check for success/failure as a boolean return value. If the operation failed, you do not have permissive to save that file there. If it worked, copy the file you wrote to out of your sandbox save directory and put it where you actually want it. My file manager also allows you to break the sandbox with the functions it overrides, regardless of whether the sandbox is turned on or not. Environment variables can also be used so you can alternatively do something like this for portability:

GML:
if (os_type == os_windows) { // This is only defined on Win32 usually if running from an MSYS2 terminal; not a big deal.
  environment_set_variable("HOME", environment_expand_variables("${HOMEDRIVE}${HOMEPATH}")); // set variable accordingly
}
if (environment_get_variable("HOME") != "") { // variable exists
  if (file_delete("${HOME}/file.txt") == true) {
    file_copy(game_save_id + "file.txt", "${HOME}/file.txt");
  } else {
    show_error("you do not have permission to save to this destination file!", false);
  }
} else {
  show_error("${HOME} environment variable not set! Cannot save to directory.", false);
}
 
Last edited by a moderator:
You can use my file manager extension to do this already I just realized.

It requires writing your file of choice to the sandbox directory, which can be gotten with `game_save_id` constant.

After the file is written you can copy it try to delete the destination file and overwrite it, like so:

GML:
if (file_delete("C:/path/to/destination/file.txt") == true) {
  file_copy(game_save_id + "file.txt", "C:/path/to/destination/file.txt");
} else {
  show_error("you do not have permission to save to this destination file!", false);
}
My extension overrides these file_* functions allowing you to check for success/failure as a boolean return value. If the operation failed, you do not have permissive to save that file there. If it worked, copy the file you wrote to out of your sandbox save directory and put it where you actually want it. My file manager also allows you to break the sandbox with the functions it overrides, regardless of whether the sandbox is turned on or not. Environment variables can also be used so you can alternatively do something like this for portability:

GML:
if (os_type == os_windows) { // This is only defined on Win32 usually if running from an MSYS2 terminal; not a big deal.
  environment_set_variable("HOME", environment_expand_variables("${HOMEDRIVE}${HOMEPATH}")); // set variable accordingly
}
if (environment_get_variable("HOME") != "") { // variable exists
  if (file_delete("${HOME}/file.txt") == true) {
    file_copy(game_save_id + "file.txt", "${HOME}/file.txt");
  } else {
    show_error("you do not have permission to save to this destination file!", false);
  }
} else {
  show_error("${HOME} environment variable not set! Cannot save to directory.", false);
}
Thank you very much! I will have to check it out when I have the time.
 
Top