summaryrefslogtreecommitdiff
path: root/indra/newview/llfloaterspellchecksettings.cpp
diff options
context:
space:
mode:
authorOz Linden <oz@lindenlab.com>2012-06-14 21:21:42 -0400
committerOz Linden <oz@lindenlab.com>2012-06-14 21:21:42 -0400
commit02f0f87f95c7f47a93d20de9478bf0b2d5c6e4e6 (patch)
tree8ecaca41b3d03c4b1df24b78417d36207127f332 /indra/newview/llfloaterspellchecksettings.cpp
parentc8f21753fa4cc88e3ad58f9e117c231d6f5388c0 (diff)
STORM-1880: copy imported dictionary files rather than moving them
Diffstat (limited to 'indra/newview/llfloaterspellchecksettings.cpp')
-rw-r--r--indra/newview/llfloaterspellchecksettings.cpp124
1 files changed, 93 insertions, 31 deletions
diff --git a/indra/newview/llfloaterspellchecksettings.cpp b/indra/newview/llfloaterspellchecksettings.cpp
index 5116ec50a6..758ac23b4c 100644
--- a/indra/newview/llfloaterspellchecksettings.cpp
+++ b/indra/newview/llfloaterspellchecksettings.cpp
@@ -35,6 +35,7 @@
#include "llspellcheck.h"
#include "lltrans.h"
#include "llviewercontrol.h"
+#include "llnotificationsutil.h"
#include <boost/algorithm/string.hpp>
@@ -291,47 +292,108 @@ void LLFloaterSpellCheckerImport::onBtnOK()
return;
}
- LLSD custom_dict_info;
- custom_dict_info["is_primary"] = (bool)gDirUtilp->fileExists(dict_aff);
- custom_dict_info["name"] = mDictionaryBasename;
- custom_dict_info["language"] = dict_language;
-
- LLSD custom_dict_map;
- llifstream custom_file_in(LLSpellChecker::getDictionaryUserPath() + "user_dictionaries.xml");
- if (custom_file_in.is_open())
+ bool imported = false;
+ std::string settings_dic = LLSpellChecker::getDictionaryUserPath() + mDictionaryBasename + ".dic";
+ if ( copyFile( dict_dic, settings_dic ) )
{
- LLSDSerialize::fromXMLDocument(custom_dict_map, custom_file_in);
- custom_file_in.close();
- }
-
- LLSD::array_iterator it = custom_dict_map.beginArray();
- for (; it != custom_dict_map.endArray(); ++it)
- {
- LLSD& dict_info = *it;
- if (dict_info["name"].asString() == mDictionaryBasename)
+ if (gDirUtilp->fileExists(dict_aff))
+ {
+ std::string settings_aff = LLSpellChecker::getDictionaryUserPath() + mDictionaryBasename + ".aff";
+ if (copyFile( dict_aff, settings_aff ))
+ {
+ imported = true;
+ }
+ else
+ {
+ LLSD args = LLSD::emptyMap();
+ args["FROM_NAME"] = dict_aff;
+ args["TO_NAME"] = settings_aff;
+ LLNotificationsUtil::add("SpellingDictImportFailed", args);
+ }
+ }
+ else
{
- dict_info = custom_dict_info;
- break;
+ imported = true;
}
}
- if (custom_dict_map.endArray() == it)
+ else
{
- custom_dict_map.append(custom_dict_info);
+ LLSD args = LLSD::emptyMap();
+ args["FROM_NAME"] = dict_dic;
+ args["TO_NAME"] = settings_dic;
+ LLNotificationsUtil::add("SpellingDictImportFailed", args);
}
- llofstream custom_file_out(LLSpellChecker::getDictionaryUserPath() + "user_dictionaries.xml", std::ios::trunc);
- if (custom_file_out.is_open())
+ if ( imported )
{
- LLSDSerialize::toPrettyXML(custom_dict_map, custom_file_out);
- custom_file_out.close();
- }
+ LLSD custom_dict_info;
+ custom_dict_info["is_primary"] = (bool)gDirUtilp->fileExists(dict_aff);
+ custom_dict_info["name"] = mDictionaryBasename;
+ custom_dict_info["language"] = dict_language;
+
+ LLSD custom_dict_map;
+ llifstream custom_file_in(LLSpellChecker::getDictionaryUserPath() + "user_dictionaries.xml");
+ if (custom_file_in.is_open())
+ {
+ LLSDSerialize::fromXMLDocument(custom_dict_map, custom_file_in);
+ custom_file_in.close();
+ }
+
+ LLSD::array_iterator it = custom_dict_map.beginArray();
+ for (; it != custom_dict_map.endArray(); ++it)
+ {
+ LLSD& dict_info = *it;
+ if (dict_info["name"].asString() == mDictionaryBasename)
+ {
+ dict_info = custom_dict_info;
+ break;
+ }
+ }
+ if (custom_dict_map.endArray() == it)
+ {
+ custom_dict_map.append(custom_dict_info);
+ }
- LLFile::rename(dict_dic, LLSpellChecker::getDictionaryUserPath() + mDictionaryBasename + ".dic");
- if (gDirUtilp->fileExists(dict_aff))
- {
- LLFile::rename(dict_aff, LLSpellChecker::getDictionaryUserPath() + mDictionaryBasename + ".aff");
+ llofstream custom_file_out(LLSpellChecker::getDictionaryUserPath() + "user_dictionaries.xml", std::ios::trunc);
+ if (custom_file_out.is_open())
+ {
+ LLSDSerialize::toPrettyXML(custom_dict_map, custom_file_out);
+ custom_file_out.close();
+ }
+
+ LLSpellChecker::refreshDictionaryMap();
}
- LLSpellChecker::refreshDictionaryMap();
closeFloater(false);
}
+
+bool LLFloaterSpellCheckerImport::copyFile(const std::string from, const std::string to)
+{
+ bool copied = false;
+ LLFILE* in = LLFile::fopen(from, "rb"); /* Flawfinder: ignore */
+ if (in)
+ {
+ LLFILE* out = LLFile::fopen(to, "wb"); /* Flawfinder: ignore */
+ if (out)
+ {
+ char buf[16384]; /* Flawfinder: ignore */
+ size_t readbytes;
+ bool write_ok = true;
+ while(write_ok && (readbytes = fread(buf, 1, 16384, in))) /* Flawfinder: ignore */
+ {
+ if (fwrite(buf, 1, readbytes, out) != readbytes)
+ {
+ LL_WARNS("SpellCheck") << "Short write" << LL_ENDL;
+ write_ok = false;
+ }
+ }
+ if ( write_ok )
+ {
+ copied = true;
+ }
+ fclose(out);
+ }
+ }
+ fclose(in);
+ return copied;
+}