diff --git a/indra/llcommon/aialert.cpp b/indra/llcommon/aialert.cpp index f3d4f5af3..587a206bc 100644 --- a/indra/llcommon/aialert.cpp +++ b/indra/llcommon/aialert.cpp @@ -35,6 +35,13 @@ namespace AIAlert { +Error::Error(Prefix const& prefix, modal_nt type, + Error const& alert) : mLines(alert.mLines), mModal(type) +{ + if (alert.mModal == modal) mModal = modal; + if (prefix) mLines.push_front(Line(prefix)); +} + Error::Error(Prefix const& prefix, modal_nt type, std::string const& xml_desc, AIArgs const& args) : mModal(type) { diff --git a/indra/llcommon/aialert.h b/indra/llcommon/aialert.h index 574426a9f..4d3704cfb 100644 --- a/indra/llcommon/aialert.h +++ b/indra/llcommon/aialert.h @@ -231,6 +231,9 @@ class LL_COMMON_API Error : public std::exception lines_type const& lines(void) const { return mLines; } bool is_modal(void) const { return mModal == modal; } + // Existing alert, just add a prefix and turn alert into modal if appropriate. + Error(Prefix const& prefix, modal_nt type, Error const& alert); + // A string with zero or more replacements. Error(Prefix const& prefix, modal_nt type, std::string const& xml_desc, AIArgs const& args = AIArgs()); @@ -269,28 +272,33 @@ class LL_COMMON_API ErrorCode : public Error // Accessor. int getCode(void) const { return mCode; } + // Just an Error with a code. + ErrorCode(Prefix const& prefix, modal_nt type, int code, + Error const& alert) : + Error(prefix, type, alert), mCode(code) { } + // A string with zero or more replacements. ErrorCode(Prefix const& prefix, modal_nt type, int code, std::string const& xml_desc, AIArgs const& args = AIArgs()) : - Error(prefix, modal, xml_desc, args) { } + Error(prefix, type, xml_desc, args), mCode(code) { } // Same as above bit prepending the message with the text of another alert. ErrorCode(Prefix const& prefix, modal_nt type, int code, Error const& alert, std::string const& xml_desc, AIArgs const& args = AIArgs()) : - Error(prefix, modal, alert, xml_desc, args) { } + Error(prefix, type, alert, xml_desc, args), mCode(code) { } // Same as above but appending the message with the text of another alert. // (no args) ErrorCode(Prefix const& prefix, modal_nt type, int code, std::string const& xml_desc, Error const& alert) : - Error(prefix, modal, xml_desc, alert) { } + Error(prefix, type, xml_desc, alert), mCode(code) { } // (with args) ErrorCode(Prefix const& prefix, modal_nt type, int code, std::string const& xml_desc, AIArgs const& args, Error const& alert) : - Error(prefix, modal, xml_desc, args, alert) { } + Error(prefix, type, xml_desc, args, alert), mCode(code) { } }; } // namespace AIAlert diff --git a/indra/llcommon/aifile.cpp b/indra/llcommon/aifile.cpp index c963f5109..cd2ade77a 100644 --- a/indra/llcommon/aifile.cpp +++ b/indra/llcommon/aifile.cpp @@ -61,8 +61,8 @@ AIFile::~AIFile() //static void AIFile::mkdir(std::string const& dirname, int perms) { - int rc = LLFile::mkdir(dirname, perms); - if (rc < 0 && rc != EEXIST) + int rc = LLFile::mkdir_nowarn(dirname, perms); + if (rc < 0 && errno != EEXIST) { THROW_ERROR("AIFile_mkdir_Failed_to_create_DIRNAME", AIArgs("[DIRNAME]", dirname)); } @@ -71,8 +71,8 @@ void AIFile::mkdir(std::string const& dirname, int perms) //static void AIFile::rmdir(std::string const& dirname) { - int rc = LLFile::rmdir(dirname); - if (rc < 0 && rc != ENOENT) + int rc = LLFile::rmdir_nowarn(dirname); + if (rc < 0 && errno != ENOENT) { THROW_ERROR("AIFile_rmdir_Failed_to_remove_DIRNAME", AIArgs("[DIRNAME]", dirname)); } @@ -101,7 +101,8 @@ void AIFile::close(LLFILE* file) //static void AIFile::remove(std::string const& filename) { - if (LLFile::remove(filename) < 0) + int rc = LLFile::remove_nowarn(filename); + if (rc < 0 && errno != ENOENT) { THROW_ERROR("AIFile_remove_Failed_to_remove_FILENAME", AIArgs("[FILENAME]", filename)); } @@ -110,7 +111,7 @@ void AIFile::remove(std::string const& filename) //static void AIFile::rename(std::string const& filename, std::string const& newname) { - if (LLFile::rename(filename, newname) < 0) + if (LLFile::rename_nowarn(filename, newname) < 0) { THROW_ERROR("AIFile_rename_Failed_to_rename_FILE_to_NEWFILE", AIArgs("[FILE]", filename)("[NEWFILE]", newname)); } diff --git a/indra/llcommon/llfile.cpp b/indra/llcommon/llfile.cpp index 4a34ffaf9..686a516b9 100644 --- a/indra/llcommon/llfile.cpp +++ b/indra/llcommon/llfile.cpp @@ -174,7 +174,7 @@ int warnif(const std::string& desc, const std::string& filename, int rc, int acc } // static -int LLFile::mkdir(const std::string& dirname, int perms) +int LLFile::mkdir_nowarn(const std::string& dirname, int perms) { #if LL_WINDOWS // permissions are ignored on Windows @@ -184,13 +184,19 @@ int LLFile::mkdir(const std::string& dirname, int perms) #else int rc = ::mkdir(dirname.c_str(), (mode_t)perms); #endif + return rc; +} + +int LLFile::mkdir(const std::string& dirname, int perms) +{ + int rc = LLFile::mkdir_nowarn(dirname, perms); // We often use mkdir() to ensure the existence of a directory that might // already exist. Don't spam the log if it does. return warnif("mkdir", dirname, rc, EEXIST); } // static -int LLFile::rmdir(const std::string& dirname) +int LLFile::rmdir_nowarn(const std::string& dirname) { #if LL_WINDOWS // permissions are ignored on Windows @@ -200,6 +206,12 @@ int LLFile::rmdir(const std::string& dirname) #else int rc = ::rmdir(dirname.c_str()); #endif + return rc; +} + +int LLFile::rmdir(const std::string& dirname) +{ + int rc = LLFile::rmdir_nowarn(dirname); return warnif("rmdir", dirname, rc); } @@ -241,8 +253,7 @@ int LLFile::close(LLFILE * file) return ret_value; } - -int LLFile::remove(const std::string& filename) +int LLFile::remove_nowarn(const std::string& filename) { #if LL_WINDOWS std::string utf8filename = filename; @@ -251,10 +262,16 @@ int LLFile::remove(const std::string& filename) #else int rc = ::remove(filename.c_str()); #endif + return rc; +} + +int LLFile::remove(const std::string& filename) +{ + int rc = LLFile::remove_nowarn(filename); return warnif("remove", filename, rc); } -int LLFile::rename(const std::string& filename, const std::string& newname) +int LLFile::rename_nowarn(const std::string& filename, const std::string& newname) { #if LL_WINDOWS std::string utf8filename = filename; @@ -265,6 +282,12 @@ int LLFile::rename(const std::string& filename, const std::string& newname) #else int rc = ::rename(filename.c_str(),newname.c_str()); #endif + return rc; +} + +int LLFile::rename(const std::string& filename, const std::string& newname) +{ + int rc = LLFile::rename_nowarn(filename, newname); return warnif(STRINGIZE("rename to '" << newname << "' from"), filename, rc); } diff --git a/indra/llcommon/llfile.h b/indra/llcommon/llfile.h index 1f5514f3e..cc990f6ab 100644 --- a/indra/llcommon/llfile.h +++ b/indra/llcommon/llfile.h @@ -68,6 +68,12 @@ public: static int close(LLFILE * file); + // Singu extension: the same as below, but doesn't print a warning as to leave errno alone. + static int mkdir_nowarn(const std::string& filename, int perms); + static int rmdir_nowarn(const std::string& filename); + static int remove_nowarn(const std::string& filename); + static int rename_nowarn(const std::string& filename, const std::string& newname); + // perms is a permissions mask like 0777 or 0700. In most cases it will // be overridden by the user's umask. It is ignored on Windows. static int mkdir(const std::string& filename, int perms = 0700); diff --git a/indra/llui/llnotifications.cpp b/indra/llui/llnotifications.cpp index 73dd99109..b8fab0994 100644 --- a/indra/llui/llnotifications.cpp +++ b/indra/llui/llnotifications.cpp @@ -1480,29 +1480,11 @@ LLNotificationPtr LLNotifications::add(const LLNotification::Params& p) return pNotif; } +namespace AIAlert { std::string text(Error const& error, int suppress_mask = 0); } LLNotificationPtr LLNotifications::add(AIAlert::Error const& error, int type, unsigned int suppress_mask) { - std::string alert_text; - bool suppress_newlines = false; - bool last_was_prefix = false; - for (AIAlert::Error::lines_type::const_iterator line = error.lines().begin(); line != error.lines().end(); ++line) - { - // Even if a line is suppressed, we print its leading newline if requested, but never more than one. - if (!suppress_newlines && line->prepend_newline()) - { - alert_text += '\n'; - suppress_newlines = true; - } - if (!line->suppressed(suppress_mask)) - { - if (last_was_prefix) alert_text += ' '; // The translation system strips off spaces... add them back. - alert_text += LLTrans::getString(line->getXmlDesc(), line->args()); - suppress_newlines = false; - last_was_prefix = line->is_prefix(); - } - } LLSD substitutions = LLSD::emptyMap(); - substitutions["[PAYLOAD]"] = alert_text; + substitutions["[PAYLOAD]"] = AIAlert::text(error, suppress_mask); return add(LLNotification::Params((type == AIAlert::modal || error.is_modal()) ? "AIAlertModal" : "AIAlert").substitutions(substitutions)); } diff --git a/indra/llui/llnotificationsutil.cpp b/indra/llui/llnotificationsutil.cpp index 134a5c267..4c24b511e 100644 --- a/indra/llui/llnotificationsutil.cpp +++ b/indra/llui/llnotificationsutil.cpp @@ -25,6 +25,7 @@ #include "linden_common.h" #include "llnotificationsutil.h" +#include "lltrans.h" #include "llnotifications.h" #include "llsd.h" @@ -33,7 +34,7 @@ namespace AIAlert { -LLNotificationPtr add(Error const& error, modal_nt type, unsigned int suppress_mask) +LLNotificationPtr add(Error const& error, unsigned int suppress_mask, modal_nt type) { return LLNotifications::instance().add(error, type, suppress_mask); } @@ -68,6 +69,30 @@ LLNotificationPtr add(std::string const& xml_desc, AIArgs const& args, Error con return LLNotifications::instance().add(Error(Prefix(), type, xml_desc, args, error), type, suppress_mask); } +std::string text(Error const& error, int suppress_mask) +{ + std::string alert_text; + bool suppress_newlines = false; + bool last_was_prefix = false; + for (Error::lines_type::const_iterator line = error.lines().begin(); line != error.lines().end(); ++line) + { + // Even if a line is suppressed, we print its leading newline if requested, but never more than one. + if (!suppress_newlines && line->prepend_newline()) + { + alert_text += '\n'; + suppress_newlines = true; + } + if (!line->suppressed(suppress_mask)) + { + if (last_was_prefix) alert_text += ' '; // The translation system strips off spaces... add them back. + alert_text += LLTrans::getString(line->getXmlDesc(), line->args()); + suppress_newlines = false; + last_was_prefix = line->is_prefix(); + } + } + return alert_text; +} + } // namespace AIAlert LLNotificationPtr LLNotificationsUtil::add(const std::string& name) diff --git a/indra/llui/llnotificationsutil.h b/indra/llui/llnotificationsutil.h index fb0fb1ba4..893d2269c 100644 --- a/indra/llui/llnotificationsutil.h +++ b/indra/llui/llnotificationsutil.h @@ -64,7 +64,7 @@ namespace AIAlert // Just show the caught alert error. LLNotificationPtr add(Error const& error, - modal_nt type = not_modal, unsigned int suppress_mask = 0); + unsigned int suppress_mask = 0, modal_nt type = not_modal); // Short cuts for enforcing modal alerts. inline LLNotificationPtr add_modal(std::string const& xml_desc) { return add(xml_desc, modal); } @@ -73,6 +73,10 @@ namespace AIAlert inline LLNotificationPtr add_modal(Error const& error, std::string const& xml_desc, AIArgs const& args, unsigned int suppress_mask = 0) { return add(error, xml_desc, args, suppress_mask, modal); } inline LLNotificationPtr add_modal(std::string const& xml_desc, Error const& error, unsigned int suppress_mask = 0) { return add(xml_desc, error, suppress_mask, modal); } inline LLNotificationPtr add_modal(std::string const& xml_desc, AIArgs const& args, Error const& error, unsigned int suppress_mask = 0) { return add(xml_desc, args, error, suppress_mask, modal); } + inline LLNotificationPtr add_modal(Error const& error, unsigned int suppress_mask = 0) { return add(error, suppress_mask, modal); } + + // Return the full, translated, texted of the alert (possibly suppressing certain output). + std::string text(Error const& error, int suppress_mask = 0); } namespace LLNotificationsUtil