| 1 | package SDL2::filesystem 0.01 { | ||
| 2 | use SDL2::Utils; | ||
| 3 | use SDL2::stdinc; | ||
| 4 | use SDL2::error; | ||
| 5 | # | ||
| 6 | attach filesystem => { | ||
| 7 | SDL_GetBasePath => [ [], 'string' ], | ||
| 8 | SDL_GetPrefPath => [ [ 'string', 'string' ], 'string' ] | ||
| 9 | }; | ||
| 10 | |||
| 11 | =encoding utf-8 | ||
| 12 | |||
| 13 | =head1 NAME | ||
| 14 | |||
| 15 | SDL2::filesystem - Filesystem SDL API Functions | ||
| 16 | |||
| 17 | =head1 SYNOPSIS | ||
| 18 | |||
| 19 | use SDL2 qw[:filesystem]; | ||
| 20 | |||
| 21 | =head1 DESCRIPTION | ||
| 22 | |||
| 23 | SDL2::filesystem provides functions to deal with the filesystem. | ||
| 24 | |||
| 25 | =head1 Functions | ||
| 26 | |||
| 27 | These may be imported by name or with the C<:filesystem> tag. | ||
| 28 | |||
| 29 | =head2 C<SDL_GetBasePath( )> | ||
| 30 | |||
| 31 | Get the directory where the application was run from. | ||
| 32 | |||
| 33 | This is not necessarily a fast call, so you should call this once near startup | ||
| 34 | and save the string if you need it. | ||
| 35 | |||
| 36 | B<Mac OS X and iOS Specific Functionality>: If the application is in a ".app" | ||
| 37 | bundle, this function returns the Resource directory (e.g. | ||
| 38 | C<MyApp.app/Contents/Resources/>). This behaviour can be overridden by adding a | ||
| 39 | property to the Info.plist file. Adding a string key with the name | ||
| 40 | C<SDL_FILESYSTEM_BASE_DIR_TYPE> with a supported value will change the | ||
| 41 | behaviour. | ||
| 42 | |||
| 43 | Supported values for the C<SDL_FILESYSTEM_BASE_DIR_TYPE> property (Given an | ||
| 44 | application in C</Applications/SDLApp/MyApp.app>): | ||
| 45 | |||
| 46 | =over | ||
| 47 | |||
| 48 | =item C<resource>: bundle resource directory (the default). For example: C</Applications/SDLApp/MyApp.app/Contents/Resources> | ||
| 49 | |||
| 50 | =item C<bundle>: the Bundle directory. For example: C</Applications/SDLApp/MyApp.app/> | ||
| 51 | |||
| 52 | =item C<parent>: the containing directory of the bundle. For example: C</Applications/SDLApp/> | ||
| 53 | |||
| 54 | =back | ||
| 55 | |||
| 56 | The returned path is guaranteed to end with a path separator (C<\> on Windows, | ||
| 57 | C</> on most other platforms). | ||
| 58 | |||
| 59 | The pointer returned is owned by the caller. Please call SDL_free() on the | ||
| 60 | pointer when done with it. | ||
| 61 | |||
| 62 | Returns an absolute path in UTF-8 encoding to the application data directory. | ||
| 63 | C<undef> will be returned on error or when the platform doesn't implement this | ||
| 64 | functionality, call C<SDL_GetError( )> for more information. | ||
| 65 | |||
| 66 | =head2 C<( ... )> | ||
| 67 | |||
| 68 | Get the user-and-app-specific path where files can be written. | ||
| 69 | |||
| 70 | Get the "pref dir". This is meant to be where users can write personal files | ||
| 71 | (preferences and save games, etc) that are specific to your application. This | ||
| 72 | directory is unique per user, per application. | ||
| 73 | |||
| 74 | This function will decide the appropriate location in the native filesystem, | ||
| 75 | create the directory if necessary, and return a string of the absolute path to | ||
| 76 | the directory in UTF-8 encoding. | ||
| 77 | |||
| 78 | On Windows, the string might look like: C<C:\Users\bob\AppData\Roaming\My | ||
| 79 | Company\My Program Name\> | ||
| 80 | |||
| 81 | On Linux, the string might look like: C</home/bob/.local/share/My Program | ||
| 82 | Name/> | ||
| 83 | |||
| 84 | On Mac OS X, the string might look like: C</Users/bob/Library/Application | ||
| 85 | Support/My Program Name/> | ||
| 86 | |||
| 87 | You should assume the path returned by this function is the only safe place to | ||
| 88 | write files (and that L<< C<SDL_GetBasePath( )>|/C<SDL_GetBasePath( )> >>, | ||
| 89 | while it might be writable, or even the parent of the returned path, isn't | ||
| 90 | where you should be writing things). | ||
| 91 | |||
| 92 | Both the org and app strings may become part of a directory name, so please | ||
| 93 | follow these rules: | ||
| 94 | |||
| 95 | =over | ||
| 96 | |||
| 97 | =item - Try to use the same org string (_including case-sensitivity_) for all your applications that use this function. | ||
| 98 | |||
| 99 | =item - Always use a unique app string for each one, and make sure it never changes for an app once you've decided on it. | ||
| 100 | |||
| 101 | =item - Unicode characters are legal, as long as it's UTF-8 encoded, but... | ||
| 102 | |||
| 103 | =item - ...only use letters, numbers, and spaces. Avoid punctuation like "Game Name 2: Bad Guy's Revenge!" ... "Game Name 2" is sufficient. | ||
| 104 | |||
| 105 | =back | ||
| 106 | |||
| 107 | The returned path is guaranteed to end with a path separator (C<\> on Windows, | ||
| 108 | C</> on most other platforms). | ||
| 109 | |||
| 110 | The pointer returned is owned by the caller. Please call C<SDL_free( ... )> on | ||
| 111 | the pointer when done with it. | ||
| 112 | |||
| 113 | Expected parameters include: | ||
| 114 | |||
| 115 | =over | ||
| 116 | |||
| 117 | =item C<org> - the name of your organization | ||
| 118 | |||
| 119 | =item C<app> - the name of your application | ||
| 120 | |||
| 121 | =back | ||
| 122 | |||
| 123 | Returns a UTF-8 string of the user directory in platform-dependent notation. | ||
| 124 | C<undef> if there's a problem (creating directory failed, etc.). | ||
| 125 | |||
| 126 | =head1 LICENSE | ||
| 127 | |||
| 128 | Copyright (C) Sanko Robinson. | ||
| 129 | |||
| 130 | This library is free software; you can redistribute it and/or modify it under | ||
| 131 | the terms found in the Artistic License 2. Other copyrights, terms, and | ||
| 132 | conditions may apply to data transmitted through this module. | ||
| 133 | |||
| 134 | =head1 AUTHOR | ||
| 135 | |||
| 136 | Sanko Robinson E<lt>sanko@cpan.orgE<gt> | ||
| 137 | |||
| 138 | =begin stopwords | ||
| 139 | |||
| 140 | iOS pref dir | ||
| 141 | |||
| 142 | =end stopwords | ||
| 143 | |||
| 144 | =cut | ||
| 145 | |||
| 146 | }; | ||
| 147 | 1; |