Page 1 of 1

[0.13.1] Can't save to readonly save

Posted: Thu Jun 30, 2016 5:58 pm
by Killerbee
The game is unable to save to readonly saves.
I discovered this after I downloaded a save from the forum.
When I removed the readonly flag from the file I was able to save again.

You will probably have to combine these stackoverflow answers:
http://stackoverflow.com/questions/1255 ... ess-on-nix
http://stackoverflow.com/questions/7913 ... a-file-mfc

Into something like this:
if (!access(name, W_OK)) {
SetFileAttributes(name, GetFileAttributes(name) & ~FILE_ATTRIBUTE_READONLY);
}

Re: [0.13.1] Can't save to readonly save

Posted: Thu Jun 30, 2016 6:12 pm
by Shadowkeeper256
Isn't that what read-only is supposed to do?

Re: [0.13.1] Can't save to readonly save

Posted: Thu Jun 30, 2016 6:13 pm
by Killerbee
It is, except when it is unintended, like when I download a save and want to continue with it.

Re: [0.13.1] Can't save to readonly save

Posted: Thu Jun 30, 2016 7:20 pm
by Adil
Well, it's not factorio that sets that flag. And file access control isn't performed by the game as well.

Re: [0.13.1] Can't save to readonly save

Posted: Thu Jun 30, 2016 7:29 pm
by Loewchen
I am a bit lost, if you expect to be able to save to a file or directory that is read only, then your expectations are the problem. Or am I misunderstanding you?

Re: [0.13.1] Can't save to readonly save

Posted: Thu Jun 30, 2016 8:08 pm
by Oxyd
Can't reproduce.

Re: [0.13.1] Can't save to readonly save

Posted: Thu Jun 30, 2016 8:45 pm
by Killerbee
My expectation is that I can download a savegame, place it in the saves map and can continue playing with it.
Currently that isn't possible because Factorio doesn't take control of the file which gives errors like this:
Image

Re: [0.13.1] Can't save to readonly save

Posted: Thu Jun 30, 2016 9:02 pm
by Shadowkeeper256
So your expectation is that the game overrides the OS's restriction on files that have been set read-only? ... (and by from what you've said so far are locked down due to ownership-lockdown, also an OS feature to protect you as a user ...)

Re: [0.13.1] Can't save to readonly save

Posted: Fri Jul 01, 2016 7:16 am
by Killerbee
It isn't much of a protection mechanism because it is already too late if the game opens a savegame with an exploit.

But if people are worried about it why not implement something like in Microsoft Word, it will prompt the user if it want to edit the file the downloaded file.
Factortio can ask a question like: "This savegame is marked as readonly, are you sure you want to overwrite it?"

Re: [0.13.1] Can't save to readonly save

Posted: Fri Jul 01, 2016 7:19 am
by Zeblote
The problem here is that your file is marked as read-only. That does NOT happen by just placing a downloaded file in the folder.

Maybe right click the factorio folder in appdata and apply read-only off for all subfolders just to be sure.

Re: [0.13.1] Can't save to readonly save

Posted: Fri Jul 01, 2016 8:07 am
by Rseding91
I download save files *allllll the time* to look at peoples saves from bug reports and never once have had this issue.

It sounds like you've got some permissions issue wrong on your computer or maybe an antivirus software is changing downloads to read-only.

Re: [0.13.1] Can't save to readonly save

Posted: Fri Jul 01, 2016 8:52 am
by y.petremann
For my case I think that the game is doing right, a readonly file shouldn't be overwritable that easy, I think that a user error and to show that, I think that you should put a message directed toward the player about his file being readonly and having him to set write permissions manually or saving to another name.

Re: [0.13.1] Can't save to readonly save

Posted: Fri Jul 01, 2016 10:25 am
by Killerbee
If you refuse to solve this issue at least make the message readable for the average user.
And preferably with some explanation to the user how to remove the readonly permission.

Re: [0.13.1] Can't save to readonly save

Posted: Fri Jul 01, 2016 11:20 am
by Tychon
Killerbee wrote:It isn't much of a protection mechanism because it is already too late if the game opens a savegame with an exploit.
read only does not mean a save file cannot be read so it isn't any exploit or whatever.
Killerbee wrote:But if people are worried about it why not implement something like in Microsoft Word, it will prompt the user if it want to edit the file the downloaded file.
Factortio can ask a question like: "This savegame is marked as readonly, are you sure you want to overwrite it?"
Word also cannot edit a read only file. The read only mark can ONLY be changed by the OS. Nothing else. What Word offers you is to create a copy but it cannot edit a read only file.

Re: [0.13.1] Can't save to readonly save

Posted: Fri Jul 01, 2016 1:32 pm
by Killerbee
Tychon wrote:
Killerbee wrote:It isn't much of a protection mechanism because it is already too late if the game opens a savegame with an exploit.
read only does not mean a save file cannot be read so it isn't any exploit or whatever.
Killerbee wrote:But if people are worried about it why not implement something like in Microsoft Word, it will prompt the user if it want to edit the file the downloaded file.
Factortio can ask a question like: "This savegame is marked as readonly, are you sure you want to overwrite it?"
Word also cannot edit a read only file. The read only mark can ONLY be changed by the OS. Nothing else. What Word offers you is to create a copy but it cannot edit a read only file.
You obviously didn't understand my exploit comment.
Someone said it is part of a protection of the OS, which isn't the case.
When the save is corrupted, for example a string says it's 700 characters long while it in reality is only 30 characters long a badly programmed program will still try to read those missing 670 characters.
This can be used to crash programs, execute abitrary code etc.
The game will load the save regardless of the readonly flag, so when something like that is in the save and the savegame loading code is bad it will offer no protection.

Your comment about only the OS can change the flag isn't true as you could have seen in my first comment.
I've also tested in same code it wrote myself and I can easily remove the readonly flag without admin rights.
Just checked it in word, and it appears I was wrong, it doesn't change the readonly flag, but at least it gives a clean error.