Sign in to follow this  
Followers 0
Servant of the Lord

Cross platform filepath naming conventions

11 posts in this topic

Hi, I'm trying to create a set of guidelines for my cross-platform project concerning filepaths and filenames,
I startd with [url="http://www.boost.org/doc/libs/1_36_0/libs/filesystem/doc/portability_guide.htm"]Boost Filesystem portabillity guide[/url], but I have some additional questions.

First: I mostly only care about Windows XP and Later, Mac OSX and later, and the most common flavors of Linux.
Second: What about Android and iOS limitations? Anyone know (without violating any NDAs) about XBox Arcade limitations?

Is Windows XP still limited to a max path of 260 characters? What about Windows Vista and beyond?

Amongst the common OSes I mentioned, is there any limitation on the size of a single filename or directory name? What is the maximum compatible filename or directory name size?

Is there any limitation still on the "depth" of the folders? Am I still limited to 8 folders deep on Mac OSX, WinXP, or major Linux distros? I can go to at least 15 on Windows 7, just glancing at my current directory.

[size=2]For fun:[/size]
[size=2]D:\Jamin\Programming\Projects\AdventureFar\GameClient\Game\Data\World\Areas\Tests\MyTestArea\(-1,2)\Floor\Floor 0\Layers[/size]

Can I really not have spaces in my path? I can seriously only have 0-9, a-z, A-Z, '_', and '-'?
On the common OSes mentioned above, I can't cross-platformly use < >, ( ), or [ ]?
What about commas, am I banned from those if I want to be cross-platform?

Any help here is much appreciated! Most of the cross-platform filepath articles I find and trying to keep me cross-platform to OSes from before 2000 or so, which doesn't concern my project.
0

Share this post


Link to post
Share on other sites
All of that complexity is why a lot of games go with a single data file approach. That is you create a single file, containing all game data, which works like (and often is) a zip file. There are cross platform libraries like http://icculus.org/physfs/ to handle reading zip files.

Of course storing files like that isn't very convenient during development, so you'll also want to support reading the files directly from the filesystem on at least one platform.

You may also find it useful to support more than one zip file, it makes patches easier for example, but the main thing is that you end up with a very small number of files, each with a simple file name that will work on any platform you support.
3

Share this post


Link to post
Share on other sites
[quote name='e?dd' timestamp='1343515371' post='4964123']
Here, all characters except '/' are allowed in path segments, including funny things like '\n'. Stay away from using ':' in paths if possible as that can sometimes confuse the Finder due to Mac OS 9 baggage. Backslash, '\\', really does mean a backslash character. It's not a separator under any circumstances.
[/quote]
I just want to add to this, because OS X is a little weird in this regard. In the Finder, you can give a filename with a '/' character in it, but it get's converted to a ':' character. So if you name a file "a/z" it will show as "a/z" in the Finder, but from the Terminal it will show as "a:z".

Moral of the story: just don't even try to use "/" or ":" in file/folder names.

I'd say more, but edd said it all, pretty much.
0

Share this post


Link to post
Share on other sites
I know you can use spaces in file/folder names in XP (I mean, a system installed folder is "Program Files" after all), and with Linux/OS X (which is also a UNIX) you can use spaces (I know on most Linux distros you can even use , \b, \r, \n, etc, though it's generally frowned upon since it makes displaying file names fussy). As far as I can tell commas are fine (I just named a folder "Browsers, things"). Colons (':') are not, since Windows uses them for basically resource forks and some OSes use them for path separators (I don't know if any of them are still used today, but Boost::filesystem deals with them.).

What are you planning on using the long paths for? Is it something that could be better served using a file format (world info) or an archive (static game info)? Or do you just want to make sure you can write saved games to your game's data folder?

[b]Edit:[/b] Note to self: refresh thread before replying... Edited by Firestryke31
0

Share this post


Link to post
Share on other sites
[quote name='e?dd' timestamp='1343515371' post='4964123'][i]...too much stuff to go through in one sitting....[/i][/quote]
Wow, thanks for that write-up; it contains alot of the kind of information I'm trying to understand. Some of it is really surprising, like the "D:abc.txt" and "\abc.txt" - both those meanings are new to me, and seem likely to accidentally occur in day-to-day programming.

I did a poor job of explaining myself: I'm currently using boost::filesystem for the actual OS interaction.
Boost gives a list of "cross platform" recommendations, but it seems exceedingly strict for modern OSes, so I'm wondering where I can ease up the restrictions if I only include things made in the past 10 years.

Since I'm using boost::filesystem, I don't need to directly deal with the nitty-gritty details of Windows or Mac specific function calls (thankfully!), but my concern is about my folder structure and filenames, and where I might have complications in the future in copying the entire data directory of my game onto a Mac or Linux machine for when I make a Mac or Linux port. I would like, as much as possible, that the layout of my datafiles remain constant between Mac and Linux and Windows, for ease of porting and also so player mods of my game work cross-platform. I would rather not ship and release the Windows version and then three months after that, when I complete the Mac port, find out I need to change the whole folder structure and filenames of critical data files, and then have to update the Windows version to match the new minimum requirements of both Mac and Linux (ruining any player mods, as well as just being a nuisance), and then go through that [i]again[/i] in another three months when I port to Linux.

I understand there will be inevitable complications when porting from Windows to Mac or Linux, but I'd like to do what I can ahead of time, to at least reduce the complications, and getting the file system as stable as possible would greatly assist that.

My biggest concern at the moment, is I have folders filled with sub-folders with names in the format: "(x,y)"
My recent understanding is that you can't use ( or ), or even commas, on Linux machines (right?), so now I have a problem! Better to catch it now, then after I ship for Windows.

[quote name='Adam_42' timestamp='1343518879' post='4964139']
All of that complexity is why a lot of games go with a single data file approach. That is you create a single file, containing all game data, which works like (and often is) a zip file. There are cross platform libraries like [url="http://icculus.org/physfs/"]http://icculus.org/physfs/[/url] to handle reading zip files.[/quote]
That's a great idea, and I would do that... but for one thing: Modding
My game is very very modable, and I do expect users to make use of that. My game's build-in level editor is (untestedly) cross platform, even.
If a user places a file in a special mod folder that follows the same folder structure as the game, the game will make use of the file instead of the game's original file, allowing users to do things like completely replace or alter the game's graphics, change NPC dialog, make fan-made translations, create their own levels or enemies, or even make an almost entirely new game - all without having to damage or replace the original data files of the game.

I suppose I could have the game data be entirely contained in one zip file, and then each mod be another zip file. It's definitely something to ponder...

What are the limitations of filenames and folder structures for .zips? I see there is a total limit of 4-ish GB, which isn't a problem, and to use forward slashes '/' instead of backslashes, which I already do. The file name, comment, and meta-data combined cannot exceed 65,535 bytes, which is plenty... But are there any limitations on symbols used? I can't see anything in the zip file format documentation about that. Filenames are optionally UTF-8 or the MSDOS ASCII, either of which work fine for me (the filenames don't need to be translated).
I just don't know what limitations there are on filenames. Can I use commas and parentheses and exclamation marks in zip filenames? Other than the 'use forward slashes', I don't see any information on the subject.

If I use zips, I'll let physFS handle it, but I still need to know how to name my files before I zip them up, and with what name to use when loading data from the zip.

[quote name='Firestryke31']What are you planning on using the long paths for? Is it something that could be better served using a file format (world info) or an archive (static game info)? Or do you just want to make sure you can write saved games to your game's data folder?[/quote]
Static game data (world, dialog, etc...) and dynamic data (config files, game saves), but all modifiable by the end-user.
At a basic level, users might just play around with the map editor a little, but at a more advanced level, they'd be manually adjust config files and creating new files in their own folder structure that mirrors the game's folder structure.

So yes, I suppose a archive file would really be the best option. One for the game, one for each mod or expansion. Edited by Servant of the Lord
0

Share this post


Link to post
Share on other sites
[quote name='Servant of the Lord' timestamp='1343584027' post='4964281']
My recent understanding is that you can't use ( or ), or even commas, on Linux machines (right?), so now I have a problem! Better to catch it now, then after I ship for Windows.
[/quote]

I'm pretty sure that I have seen/used both ( ) and , in linux paths.
0

Share this post


Link to post
Share on other sites
I don't think round brackets -- '(' and ')' -- should be a problem anywhere. Same goes for commas.

I think the suggestion of using pack files to distribute data is a good one, with additional search paths for mod content.

Zip files support UTF-8 if a bit is set in one of the headers. However (sigh) many versions of Windows (through to Vista, I think) do a poor job of unzipping such files if characters outside of the ASCII subset are used in path names.
1

Share this post


Link to post
Share on other sites
Out of interest, if you're aiming for cross-platform why not go for the most conservative approach? Obviously you need to figure out what the most conservative approach is, but it seems safest. Do you perhaps have automated tools that output assets with a particular filename structure that would make that cumbersome?

Would it perhaps make sense to have a function/method which creates the filenames based on enum values, asset ids, etc? That would at least mean you'd have the code side covered, you could easily change the filename format if you discovered issues. Of course renaming and moving the files would be a pest, but that could be handled with a tool.
2

Share this post


Link to post
Share on other sites
[quote name='jefferytitan' timestamp='1343600071' post='4964327']
Out of interest, if you're aiming for cross-platform why not go for the most conservative approach? Obviously you need to figure out what the most conservative approach is, but it seems safest. Do you perhaps have automated tools that output assets with a particular filename structure that would make that cumbersome?[/quote]
I'm trying to go with the lowest common denominator of rules, but I don't know what the rules are.
No automated tools or anything.
[quote]Would it perhaps make sense to have a function/method which creates the filenames based on enum values, asset ids, etc? That would at least mean you'd have the code side covered, you could easily change the filename format if you discovered issues. Of course renaming and moving the files would be a pest, but that could be handled with a tool.[/quote]
Well, I need users to being able to alter things if they want, and IDs for filenames would make it hard for users to understand what is referencing what.
Most of my filenames are perfectly fine, but a few have symbols in it, like the (x,y) folders I mentioned.

[quote name='wack' timestamp='1343595326' post='4964314']
I'm pretty sure that I have seen/used both ( ) and , in linux paths.
[/quote]

Really? Someone told me they are used for a special purpose in linux, and that some linux tools choke on them. QtCreator's QMake (a linux tool ported to Windows) messes up with ( ) for example.
If my program can handle it, fine. But does Linux's filesystem allow those symbols or will it cause unexpected issues later on? What about Mac OSX with ( ) and ','?
0

Share this post


Link to post
Share on other sites
I very much doubt Linux has a problem with ( and ). One or more shells might interpret them as having special meaning, but that has nothing to do with the filesystem(s) Linux uses. All command shells have such special characters (for which an escaping mechanism is provided). Same for OS X.

The fact that QtCreator doesn't handle these characters correctly is almost certainly a bug (or it too requires escape sequences you are thus far unaware of).
1

Share this post


Link to post
Share on other sites
It's actually GNU mingw 'make' that was having the problem with parentheses in paths (I had forgotten, it was two weeks ago), which QtCreator runs as part of the compiling process, QtCreator itself handles the filepaths fine. *shrugs*

Hmm, alright, thanks for all the help guys. Looks like it's just the tools that were choking on the symbols, not the OSes themselves. I'll just continue to use parentheses and commas, but will maybe use Zip archives for actual release. I really appreciate the help. Edited by Servant of the Lord
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0