extend methods by which the correct assets path is "discovered"

This commit is contained in:
Gered 2013-08-25 13:21:51 -04:00
parent c72838c7fd
commit b28498fae6
2 changed files with 25 additions and 4 deletions

View file

@ -9,10 +9,30 @@ namespace Blarg.GameFramework.IO
{
string _assetsPath;
public SDLFileSystem()
public SDLFileSystem(ILogger logger)
{
string executablePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
_assetsPath = Path.Combine(executablePath, "assets");
string envAssetsPath = Environment.GetEnvironmentVariable("ASSETS_DIR");
string workingDirPath = Path.Combine(Environment.CurrentDirectory, "assets");
if (!String.IsNullOrEmpty(envAssetsPath))
{
logger.Info("SDL_FILESYSTEM", "Environment variable ASSETS_DIR value found.");
_assetsPath = envAssetsPath;
}
else if (Directory.Exists(workingDirPath))
{
logger.Info("SDL_FILESYSTEM", "'Assets' found under the current working directory.");
_assetsPath = workingDirPath;
}
else
{
// fallback to the default otherwise
logger.Info("SDL_FILESYSTEM", "Assuming 'Assets' directory located next to application executable.");
_assetsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "assets");
}
if (!Directory.Exists(_assetsPath))
logger.Warn("SDL_FILESYSTEM", "Attempting to use assets directory {0} which doesn't exist.", _assetsPath);
}
public Stream Open(string filename)

View file

@ -315,8 +315,9 @@ namespace Blarg.GameFramework
Logger.Warn(LOG_TAG, "\tMore information could not be obtained.");
}
_filesystem = new SDLFileSystem();
_filesystem = new SDLFileSystem(Logger);
Logger.Info(LOG_TAG, "Filesystem access initialized.");
Logger.Info(LOG_TAG, "Using assets path: {0}", _filesystem.AssetsPath);
int numVideoDrivers = SDL.SDL_GetNumVideoDrivers();
Logger.Info(LOG_TAG, "Video drivers present: {0}.", numVideoDrivers);