diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index 275455b9d..370a47448 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -409,6 +409,14 @@ int main(int argc, char* argv[]) // Always close the log on exit. atexit(&onExit); + // Check if the configuration file exists, and if not, create it. + // This should only happen on first application startup. + if (!Utils::FileSystem::exists(Utils::FileSystem::getHomePath() + + "/.emulationstation/es_settings.cfg")) { + LOG(LogInfo) << "Settings file es_settings.cfg does not exist, creating it..."; + Settings::getInstance()->saveFile(); + } + Window window; SystemScreenSaver screensaver(&window); PowerSaver::init(); @@ -492,6 +500,14 @@ int main(int argc, char* argv[]) } } + // Check if the media directory exists, and if not, log a warning. + if (!Utils::FileSystem::isDirectory(FileData::getMediaDirectory()) || + Utils::FileSystem::isSymlink(FileData::getMediaDirectory())) { + LOG(LogWarning) << "Warning - Games media directory does not exist " + "(or is not a directory or a symlink):"; + LOG(LogWarning) << FileData::getMediaDirectory(); + } + // Generate joystick events since we're done loading. SDL_JoystickEventState(SDL_ENABLE); diff --git a/es-app/src/scrapers/Scraper.cpp b/es-app/src/scrapers/Scraper.cpp index d9fe7d7a2..39f2473d4 100644 --- a/es-app/src/scrapers/Scraper.cpp +++ b/es-app/src/scrapers/Scraper.cpp @@ -232,6 +232,14 @@ MDResolveHandle::MDResolveHandle(const ScraperSearchResult& result, if(it->existingMediaFile != "") Utils::FileSystem::removeFile(it->existingMediaFile); + // If the media directory does not exist, something is wrong, possibly permission + // problems or the MediaDirectory setting points to a file instead of a directory. + if (!Utils::FileSystem::isDirectory(Utils::FileSystem::getParent(filePath))) { + setError("Media directory does not exist and can't be created. " + "Permission problems?"); + return; + } + #ifdef _WIN64 std::ofstream stream(Utils::String::stringToWideString(filePath).c_str(), std::ios_base::out | std::ios_base::binary); @@ -337,6 +345,13 @@ void ImageDownloadHandle::update() if(mExistingMediaFile != "") Utils::FileSystem::removeFile(mExistingMediaFile); + // If the media directory does not exist, something is wrong, possibly permission + // problems or the MediaDirectory setting points to a file instead of a directory. + if (!Utils::FileSystem::isDirectory(Utils::FileSystem::getParent(mSavePath))) { + setError("Media directory does not exist and can't be created. Permission problems?"); + return; + } + #ifdef _WIN64 std::ofstream stream(Utils::String::stringToWideString(mSavePath).c_str(), std::ios_base::out | std::ios_base::binary); diff --git a/es-core/src/Settings.cpp b/es-core/src/Settings.cpp index 10d643855..0fdf343c1 100644 --- a/es-core/src/Settings.cpp +++ b/es-core/src/Settings.cpp @@ -252,7 +252,7 @@ void saveMap(pugi::xml_document& doc, std::map& map, const char* type) void Settings::saveFile() { - LOG(LogDebug) << "Settings::saveFile() : Saving Settings to file."; + LOG(LogDebug) << "Settings::saveFile(): Saving Settings to file."; const std::string path = Utils::FileSystem::getHomePath() + "/.emulationstation/es_settings.cfg";