diff --git a/Blarg.GameFramework.SDL2/IO/SDLFileSystem.cs b/Blarg.GameFramework.SDL2/IO/SDLFileSystem.cs index bd9dd06..1c608e1 100644 --- a/Blarg.GameFramework.SDL2/IO/SDLFileSystem.cs +++ b/Blarg.GameFramework.SDL2/IO/SDLFileSystem.cs @@ -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) diff --git a/Blarg.GameFramework.SDL2/SDLApplication.cs b/Blarg.GameFramework.SDL2/SDLApplication.cs index 0116d5f..b441053 100644 --- a/Blarg.GameFramework.SDL2/SDLApplication.cs +++ b/Blarg.GameFramework.SDL2/SDLApplication.cs @@ -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);