diff options
Diffstat (limited to 'indra/llfilesystem')
-rw-r--r-- | indra/llfilesystem/lldir.cpp | 33 | ||||
-rw-r--r-- | indra/llfilesystem/lldir.h | 4 | ||||
-rw-r--r-- | indra/llfilesystem/lldir_linux.cpp | 4 | ||||
-rw-r--r-- | indra/llfilesystem/lldir_mac.cpp | 2 | ||||
-rw-r--r-- | indra/llfilesystem/lldir_mac.h | 2 | ||||
-rw-r--r-- | indra/llfilesystem/lldir_utils_objc.h | 2 | ||||
-rw-r--r-- | indra/llfilesystem/lldir_utils_objc.mm | 2 | ||||
-rw-r--r-- | indra/llfilesystem/lldir_win32.cpp | 13 | ||||
-rw-r--r-- | indra/llfilesystem/lldir_win32.h | 2 | ||||
-rw-r--r-- | indra/llfilesystem/llfilesystem.cpp | 42 | ||||
-rw-r--r-- | indra/llfilesystem/llfilesystem.h | 12 | ||||
-rw-r--r-- | indra/llfilesystem/lllfsthread.h | 6 |
12 files changed, 78 insertions, 46 deletions
diff --git a/indra/llfilesystem/lldir.cpp b/indra/llfilesystem/lldir.cpp index 69b23f9cf8..ee5dec2b77 100644 --- a/indra/llfilesystem/lldir.cpp +++ b/indra/llfilesystem/lldir.cpp @@ -71,6 +71,7 @@ LLDir *gDirUtilp = (LLDir *)&gDirUtil; /// Values for findSkinnedFilenames(subdir) parameter const char *LLDir::XUI = "xui", + *LLDir::HTML = "html", *LLDir::TEXTURES = "textures", *LLDir::SKINBASE = ""; @@ -761,14 +762,13 @@ std::vector<std::string> LLDir::findSkinnedFilenames(const std::string& subdir, else { // We do not recognize this subdir. Investigate. - std::string subdir_path(add(getDefaultSkinDir(), subdir)); - if (fileExists(add(subdir_path, "en"))) + if (skinExists(subdir, "en")) { // defaultSkinDir/subdir contains subdir "en". That's our // default language; this subdir is localized. found = sLocalized.insert(StringMap::value_type(subdir, "en")).first; } - else if (fileExists(add(subdir_path, "en-us"))) + else if (skinExists(subdir, "en-us")) { // defaultSkinDir/subdir contains subdir "en-us" but not "en". // Set as default language; this subdir is localized. @@ -865,6 +865,33 @@ std::vector<std::string> LLDir::findSkinnedFilenames(const std::string& subdir, return results; } +// virtual +bool LLDir::skinExists(const std::string& subdir, const std::string& skin) const +{ + std::string skin_path(add(getDefaultSkinDir(), subdir, skin)); + return fileExists(skin_path); +} + +// virtual +std::string LLDir::getFileContents(const std::string& filename) const +{ + LLFILE* fp = LLFile::fopen(filename, "rb"); /* Flawfinder: ignore */ + if (fp) + { + fseek(fp, 0, SEEK_END); + U32 length = ftell(fp); + fseek(fp, 0, SEEK_SET); + + std::vector<char> buffer(length); + size_t nread = fread(buffer.data(), 1, length, fp); + fclose(fp); + + return std::string(buffer.data(), nread); + } + + return LLStringUtil::null; +} + std::string LLDir::getTempFilename() const { LLUUID random_uuid; diff --git a/indra/llfilesystem/lldir.h b/indra/llfilesystem/lldir.h index b9a046ba33..d43921c292 100644 --- a/indra/llfilesystem/lldir.h +++ b/indra/llfilesystem/lldir.h @@ -72,6 +72,8 @@ class LLDir // pure virtual functions virtual std::string getCurPath() = 0; virtual bool fileExists(const std::string &filename) const = 0; + virtual bool skinExists(const std::string& subdir, const std::string &skin) const; + virtual std::string getFileContents(const std::string& filename) const; const std::string findFile(const std::string& filename, const std::vector<std::string> filenames) const; const std::string findFile(const std::string& filename, const std::string& searchPath1 = "", const std::string& searchPath2 = "", const std::string& searchPath3 = "") const; @@ -150,7 +152,7 @@ class LLDir const std::string& filename, ESkinConstraint constraint=CURRENT_SKIN) const; /// Values for findSkinnedFilenames(subdir) parameter - static const char *XUI, *TEXTURES, *SKINBASE; + static const char *XUI, *HTML, *TEXTURES, *SKINBASE; /** * Return the base-language pathname from findSkinnedFilenames(), or * the empty string if no such file exists. Parameters are identical to diff --git a/indra/llfilesystem/lldir_linux.cpp b/indra/llfilesystem/lldir_linux.cpp index 80ad05345a..44e24a1625 100644 --- a/indra/llfilesystem/lldir_linux.cpp +++ b/indra/llfilesystem/lldir_linux.cpp @@ -247,11 +247,11 @@ bool LLDir_Linux::fileExists(const std::string &filename) const int res = stat(filename.c_str(), &stat_data); if (!res) { - return TRUE; + return true; } else { - return FALSE; + return false; } } diff --git a/indra/llfilesystem/lldir_mac.cpp b/indra/llfilesystem/lldir_mac.cpp index 9ad8e274b6..0d9695e161 100644 --- a/indra/llfilesystem/lldir_mac.cpp +++ b/indra/llfilesystem/lldir_mac.cpp @@ -1,6 +1,6 @@ /** * @file lldir_mac.cpp - * @brief Implementation of directory utilities for Mac OS X + * @brief Implementation of directory utilities for macOS * * $LicenseInfo:firstyear=2002&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/llfilesystem/lldir_mac.h b/indra/llfilesystem/lldir_mac.h index 558727ebbc..0290fb773b 100644 --- a/indra/llfilesystem/lldir_mac.h +++ b/indra/llfilesystem/lldir_mac.h @@ -1,6 +1,6 @@ /** * @file lldir_mac.h - * @brief Definition of directory utilities class for Mac OS X + * @brief Definition of directory utilities class for macOS * * $LicenseInfo:firstyear=2000&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/llfilesystem/lldir_utils_objc.h b/indra/llfilesystem/lldir_utils_objc.h index 59dbeb4aec..48148aad95 100644 --- a/indra/llfilesystem/lldir_utils_objc.h +++ b/indra/llfilesystem/lldir_utils_objc.h @@ -1,6 +1,6 @@ /** * @file lldir_utils_objc.h - * @brief Definition of directory utilities class for Mac OS X + * @brief Definition of directory utilities class for macOS * * $LicenseInfo:firstyear=2020&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/llfilesystem/lldir_utils_objc.mm b/indra/llfilesystem/lldir_utils_objc.mm index 20540fb93c..01fe9e1f2c 100644 --- a/indra/llfilesystem/lldir_utils_objc.mm +++ b/indra/llfilesystem/lldir_utils_objc.mm @@ -1,6 +1,6 @@ /** * @file lldir_utils_objc.mm - * @brief Cocoa implementation of directory utilities for Mac OS X + * @brief Cocoa implementation of directory utilities for macOS * * $LicenseInfo:firstyear=2020&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/llfilesystem/lldir_win32.cpp b/indra/llfilesystem/lldir_win32.cpp index b3b3afb37e..f65cc90dc3 100644 --- a/indra/llfilesystem/lldir_win32.cpp +++ b/indra/llfilesystem/lldir_win32.cpp @@ -47,14 +47,16 @@ DWORD GetDllVersion(LPCTSTR lpszDllName); namespace { // anonymous - enum class prst { INIT, OPEN, SKIP } state = prst::INIT; + enum class prst { INIT, OPEN, SKIP }; + prst state{ prst::INIT }; + // This is called so early that we can't count on static objects being // properly constructed yet, so declare a pointer instead of an instance. std::ofstream* prelogf = nullptr; void prelog(const std::string& message) { - boost::optional<std::string> prelog_name; + std::optional<std::string> prelog_name; switch (state) { @@ -75,6 +77,7 @@ namespace (*prelogf) << "========================================================================" << std::endl; // fall through, don't break + [[fallthrough]]; case prst::OPEN: (*prelogf) << message << std::endl; @@ -253,7 +256,7 @@ LLDir_Win32::LLDir_Win32() // Determine the location of the App-Read-Only-Data // Try the working directory then the exe's dir. - mAppRODataDir = mWorkingDir; + mAppRODataDir = mWorkingDir; // if (mExecutableDir.find("indra") == std::string::npos) @@ -379,11 +382,11 @@ bool LLDir_Win32::fileExists(const std::string &filename) const int res = LLFile::stat(filename, &stat_data); if (!res) { - return TRUE; + return true; } else { - return FALSE; + return false; } } diff --git a/indra/llfilesystem/lldir_win32.h b/indra/llfilesystem/lldir_win32.h index 450efaf9da..fa6d5fd320 100644 --- a/indra/llfilesystem/lldir_win32.h +++ b/indra/llfilesystem/lldir_win32.h @@ -50,7 +50,7 @@ public: /*virtual*/ std::string getLLPluginFilename(std::string base_name); private: - void* mDirSearch_h; + void* mDirSearch_h{ nullptr }; llutf16string mCurrentDir; }; diff --git a/indra/llfilesystem/llfilesystem.cpp b/indra/llfilesystem/llfilesystem.cpp index 4c836c8838..235aae0be3 100644 --- a/indra/llfilesystem/llfilesystem.cpp +++ b/indra/llfilesystem/llfilesystem.cpp @@ -124,14 +124,14 @@ bool LLFileSystem::renameFile(const LLUUID& old_file_id, const LLAssetType::ETyp if (LLFile::rename(old_filename, new_filename) != 0) { - // We would like to return FALSE here indicating the operation + // We would like to return false here indicating the operation // failed but the original code does not and doing so seems to // break a lot of things so we go with the flow... - //return FALSE; + //return false; LL_WARNS() << "Failed to rename " << old_file_id << " to " << new_id_str << " reason: " << strerror(errno) << LL_ENDL; } - return TRUE; + return true; } // static @@ -153,9 +153,9 @@ S32 LLFileSystem::getFileSize(const LLUUID& file_id, const LLAssetType::EType fi return file_size; } -BOOL LLFileSystem::read(U8* buffer, S32 bytes) +bool LLFileSystem::read(U8* buffer, S32 bytes) { - BOOL success = FALSE; + bool success = false; std::string id; mFileID.toString(id); @@ -183,7 +183,7 @@ BOOL LLFileSystem::read(U8* buffer, S32 bytes) mPosition += mBytesRead; if (mBytesRead) { - success = TRUE; + success = true; } } @@ -195,19 +195,19 @@ S32 LLFileSystem::getLastBytesRead() return mBytesRead; } -BOOL LLFileSystem::eof() +bool LLFileSystem::eof() { return mPosition >= getSize(); } -BOOL LLFileSystem::write(const U8* buffer, S32 bytes) +bool LLFileSystem::write(const U8* buffer, S32 bytes) { std::string id_str; mFileID.toString(id_str); const std::string extra_info = ""; const std::string filename = LLDiskCache::getInstance()->metaDataToFilepath(id_str, mFileType, extra_info); - BOOL success = FALSE; + bool success = false; if (mMode == APPEND) { @@ -218,7 +218,7 @@ BOOL LLFileSystem::write(const U8* buffer, S32 bytes) mPosition = ofs.tellp(); // <FS:Ansariel> Fix asset caching - success = TRUE; + success = true; } } // <FS:Ansariel> Fix asset caching @@ -231,7 +231,7 @@ BOOL LLFileSystem::write(const U8* buffer, S32 bytes) ofs.seekp(mPosition, std::ios::beg); ofs.write((const char*)buffer, bytes); mPosition += bytes; - success = TRUE; + success = true; } else { @@ -241,7 +241,7 @@ BOOL LLFileSystem::write(const U8* buffer, S32 bytes) { ofs.write((const char*)buffer, bytes); mPosition += bytes; - success = TRUE; + success = true; } } } @@ -255,14 +255,14 @@ BOOL LLFileSystem::write(const U8* buffer, S32 bytes) mPosition += bytes; - success = TRUE; + success = true; } } return success; } -BOOL LLFileSystem::seek(S32 offset, S32 origin) +bool LLFileSystem::seek(S32 offset, S32 origin) { if (-1 == origin) { @@ -278,18 +278,18 @@ BOOL LLFileSystem::seek(S32 offset, S32 origin) LL_WARNS() << "Attempt to seek past end of file" << LL_ENDL; mPosition = size; - return FALSE; + return false; } else if (new_pos < 0) { LL_WARNS() << "Attempt to seek past beginning of file" << LL_ENDL; mPosition = 0; - return FALSE; + return false; } mPosition = new_pos; - return TRUE; + return true; } S32 LLFileSystem::tell() const @@ -308,19 +308,19 @@ S32 LLFileSystem::getMaxSize() return INT_MAX; } -BOOL LLFileSystem::rename(const LLUUID& new_id, const LLAssetType::EType new_type) +bool LLFileSystem::rename(const LLUUID& new_id, const LLAssetType::EType new_type) { LLFileSystem::renameFile(mFileID, mFileType, new_id, new_type); mFileID = new_id; mFileType = new_type; - return TRUE; + return true; } -BOOL LLFileSystem::remove() +bool LLFileSystem::remove() { LLFileSystem::removeFile(mFileID, mFileType); - return TRUE; + return true; } diff --git a/indra/llfilesystem/llfilesystem.h b/indra/llfilesystem/llfilesystem.h index d934a408c2..ea1b9cf3a1 100644 --- a/indra/llfilesystem/llfilesystem.h +++ b/indra/llfilesystem/llfilesystem.h @@ -40,18 +40,18 @@ class LLFileSystem LLFileSystem(const LLUUID& file_id, const LLAssetType::EType file_type, S32 mode = LLFileSystem::READ); ~LLFileSystem(); - BOOL read(U8* buffer, S32 bytes); + bool read(U8* buffer, S32 bytes); S32 getLastBytesRead(); - BOOL eof(); + bool eof(); - BOOL write(const U8* buffer, S32 bytes); - BOOL seek(S32 offset, S32 origin = -1); + bool write(const U8* buffer, S32 bytes); + bool seek(S32 offset, S32 origin = -1); S32 tell() const; S32 getSize(); S32 getMaxSize(); - BOOL rename(const LLUUID& new_id, const LLAssetType::EType new_type); - BOOL remove(); + bool rename(const LLUUID& new_id, const LLAssetType::EType new_type); + bool remove(); static bool getExists(const LLUUID& file_id, const LLAssetType::EType file_type); static bool removeFile(const LLUUID& file_id, const LLAssetType::EType file_type, int suppress_error = 0); diff --git a/indra/llfilesystem/lllfsthread.h b/indra/llfilesystem/lllfsthread.h index f2693a1172..3038e1be12 100644 --- a/indra/llfilesystem/lllfsthread.h +++ b/indra/llfilesystem/lllfsthread.h @@ -114,8 +114,8 @@ public: //------------------------------------------------------------------------ public: - LLLFSThread(bool threaded = TRUE); - ~LLLFSThread(); + LLLFSThread(bool threaded = true); + ~LLLFSThread(); // Return a Request handle handle_t read(const std::string& filename, /* Flawfinder: ignore */ @@ -126,7 +126,7 @@ public: Responder* responder); // static initializers - static void initClass(bool local_is_threaded = TRUE); // Setup sLocal + static void initClass(bool local_is_threaded = true); // Setup sLocal static S32 updateClass(U32 ms_elapsed); static void cleanupClass(); // Delete sLocal |