Broken favorites - possible reason spotted in serverlist.cpp

Post Reply
Ducky
Member
Posts: 12
Joined: Fri Mar 22, 2013 20:48

Broken favorites - possible reason spotted in serverlist.cpp

by Ducky » Post

After I've read on the forum about the favorites serverlist problem with the windows builds being due to different line-ending conventions, I think I've identified a (or one...) possible reason for this (I apologize for currently not being able to build mt on my machine to test this) :

(all in serverlist.cpp, ServerList:: )
Both in deleteEntry () and insert (), the file is written in text mode, which - on win - implies a cr/lf conversion to the native format (done via std::ofstream stream (path.c_str()) - which opens in text-mode by default).
This leads to cr/lf and line endings instead of just lf.
However, in getLocal(), the favorites file is explicitely opened as binary via istream(path.c_str(), std::ios::binary);.

As the favorites load ok when the line endings are manually changed in favoriteservers.txt, I can imagine that using the same file mode for reading and writing streams could do the trick...

rarkenin
Member
Posts: 668
Joined: Tue Nov 20, 2012 20:48

by rarkenin » Post

Ducky wrote:After I've read on the forum about the favorites serverlist problem with the windows builds being due to different line-ending conventions, I think I've identified a (or one...) possible reason for this (I apologize for currently not being able to build mt on my machine to test this) :

(all in serverlist.cpp, ServerList:: )
Both in deleteEntry () and insert (), the file is written in text mode, which - on win - implies a cr/lf conversion to the native format (done via std::ofstream stream (path.c_str()) - which opens in text-mode by default).
This leads to cr/lf and line endings instead of just lf.
However, in getLocal(), the favorites file is explicitely opened as binary via istream(path.c_str(), std::ios::binary);.

As the favorites load ok when the line endings are manually changed in favoriteservers.txt, I can imagine that using the same file mode for reading and writing streams could do the trick...
You should file a pull request. But, should the file be opened in text mode for editability in a text editor, or binary for readability?
Admin pro tempore on 0gb.us:30000. Ask me if you have a problem, or just want help.
This is a signature virus. Add me to your signature so that I can multiply.
Now working on my own clone, Mosstest.
I guess I'm back for some time.

Ducky
Member
Posts: 12
Joined: Fri Mar 22, 2013 20:48

by Ducky » Post

rarkenin wrote:You should file a pull request. But, should the file be opened in text mode for editability in a text editor, or binary for readability?
Depends if it is intended to be manually edited - afaik text-mode conversion is pretty tolerant in the mingw libs, handling both win and unix endings, so reading in text mode would probably make it less problematic.

But I can't say what the msvc or mac (which uses just cr instead of lf iirc) builds do with other systems lineendings, and codewise the fav-file contents are also parsed (as a single string chunk...) by other functions... so writing the file as binary may less likely break something else (or having a deeper look into it) ;)

Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests