From 4040821c1bb48fcef9ee35abdbe2800c6ebb78db Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 2 Dec 2015 09:21:44 +0100 Subject: [PATCH] Fixed: Search icons under Linux in default directories --- code/ryzom/client/src/init.cpp | 102 ++++++++++++++++++++++----------- 1 file changed, 69 insertions(+), 33 deletions(-) diff --git a/code/ryzom/client/src/init.cpp b/code/ryzom/client/src/init.cpp index 285382a4e..8270d6f21 100644 --- a/code/ryzom/client/src/init.cpp +++ b/code/ryzom/client/src/init.cpp @@ -761,6 +761,35 @@ static void addPackedSheetUpdatePaths(NLMISC::IProgressCallback &progress) } } +#if defined(NL_OS_UNIX) && !defined(NL_OS_MAC) +static bool addRyzomIconBitmap(const std::string &directory, vector &bitmaps) +{ + if (CFile::isDirectory(directory)) + { + // build filename from directory and default ryzom client icon name + std::string filename = NLMISC::toString("%s/%s.png", directory.c_str(), RYZOM_CLIENT_ICON); + + if (CFile::fileExists(filename)) + { + CIFile file; + + if (file.open(filename)) + { + CBitmap bitmap; + + if (bitmap.load(file)) + { + bitmaps.push_back(bitmap); + return true; + } + } + } + } + + return false; +} +#endif + //--------------------------------------------------- // prelogInit : // Initialize the application before login @@ -1065,50 +1094,57 @@ void prelogInit() Driver->setWindowTitle(CI18N::get("TheSagaOfRyzom")); #if defined(NL_OS_UNIX) && !defined(NL_OS_MAC) - // add all existing icons - vector directories; + // add all existing directory prefixes + vector directoryPrefixes; - // system directories - directories.push_back("/usr/share/icons/hicolor/256x256/apps"); - directories.push_back("/usr/share/icons/hicolor/128x128/apps"); - directories.push_back("/usr/share/icons/hicolor/96x96/apps"); - directories.push_back("/usr/share/icons/hicolor/48x48/apps"); - directories.push_back("/usr/share/icons/hicolor/32x32/apps"); - directories.push_back("/usr/share/icons/hicolor/24x24/apps"); - directories.push_back("/usr/share/icons/hicolor/22x22/apps"); - directories.push_back("/usr/share/icons/hicolor/16x16/apps"); - directories.push_back("/usr/share/pixmaps"); + // user local directory prefix (~/.local) + const char* homeDirectory = getenv("HOME"); - // local directories - directories.push_back("~/.local/share/icons/hicolor/256x256/apps"); - directories.push_back("~/.local/share/icons/hicolor/128x128/apps"); - directories.push_back("~/.local/share/icons/hicolor/96x96/apps"); - directories.push_back("~/.local/share/icons/hicolor/48x48/apps"); - directories.push_back("~/.local/share/icons/hicolor/32x32/apps"); - directories.push_back("~/.local/share/icons/hicolor/24x24/apps"); - directories.push_back("~/.local/share/icons/hicolor/22x22/apps"); - directories.push_back("~/.local/share/icons/hicolor/16x16/apps"); - directories.push_back("~/.local/share/pixmaps"); + if (homeDirectory) + directoryPrefixes.push_back(CPath::standardizePath(homeDirectory) + ".local"); - // check if an icon is present in registered paths - directories.push_back("."); + // system local directory prefix (/usr/local) + directoryPrefixes.push_back("/usr/local"); + + // system directory prefix (/usr) + directoryPrefixes.push_back("/usr"); + + // all supported icon sizes + vector iconSizes; + iconSizes.push_back(512); + iconSizes.push_back(256); + iconSizes.push_back(128); + iconSizes.push_back(96); + iconSizes.push_back(48); + iconSizes.push_back(32); + iconSizes.push_back(24); + iconSizes.push_back(22); + iconSizes.push_back(16); vector bitmaps; - for(size_t i = 0; i < directories.size(); ++i) + // process all icon sizes + for(size_t j = 0; j < iconSizes.size(); ++j) { - std::string filename = NLMISC::toString("%s/%s.png", directories[i].c_str(), RYZOM_CLIENT_ICON); - - CIFile file; - - if (CFile::fileExists(filename) && file.open(filename)) + // process all directory prefixes + for(size_t i = 0; i < directoryPrefixes.size(); ++i) { - CBitmap bitmap; - if (bitmap.load(file)) - bitmaps.push_back(bitmap); + uint size = iconSizes[j]; + + // build directory where to look for icon + std::string directory = toString("%s/share/icons/hicolor/%ux%u/apps", directoryPrefixes[i].c_str(), size, size); + + // if found, skip other directories for this icon size + if (addRyzomIconBitmap(directory, bitmaps)) break; } } + if (bitmaps.empty()) + { + // check if an icon is present in current directory + addRyzomIconBitmap(".", bitmaps); + } + Driver->setWindowIcon(bitmaps); #endif