diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt index 8d0e54aa7..0f41e254d 100644 --- a/indra/llcommon/CMakeLists.txt +++ b/indra/llcommon/CMakeLists.txt @@ -25,7 +25,6 @@ include_directories( set(llcommon_SOURCE_FILES aialert.cpp - aifile.cpp aiframetimer.cpp aisyncclient.cpp aithreadid.cpp @@ -116,7 +115,6 @@ set(llcommon_HEADER_FILES CMakeLists.txt aialert.h - aifile.h aiframetimer.h airecursive.h aisyncclient.h diff --git a/indra/llcommon/aifile.cpp b/indra/llcommon/aifile.cpp deleted file mode 100644 index cd2ade77a..000000000 --- a/indra/llcommon/aifile.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/** - * @file aifile.cpp - * @brief POSIX file operations that throw on error. - * - * Copyright (c) 2013, Aleric Inglewood. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution. - * - * CHANGELOG - * and additional copyright holders. - * - * 03/11/2013 - * Initial version, written by Aleric Inglewood @ SL - */ - -#include "linden_common.h" -#include "aifile.h" -#include "aialert.h" - -#if LL_WINDOWS -#include -#include // Windows errno -#else -#include -#endif - -AIFile::AIFile(std::string const& filename, char const* accessmode) -{ - mFp = AIFile::fopen(filename, accessmode); -} - -AIFile::~AIFile() -{ - AIFile::close(mFp); -} - -// Like THROW_MALERTE but appends "LLFile::strerr(errn) << " (" << errn << ')'" as argument to replace [ERROR]. -#define THROW_ERROR(...) \ - do { \ - int errn = errno; \ - std::ostringstream error; \ - error << LLFile::strerr(errn) << " (" << errn << ')'; \ - THROW_MALERT_CLASS(AIAlert::ErrorCode, errn, __VA_ARGS__ ("[ERROR]", error.str())); \ - } while(0) - -//static -void AIFile::mkdir(std::string const& dirname, int perms) -{ - int rc = LLFile::mkdir_nowarn(dirname, perms); - if (rc < 0 && errno != EEXIST) - { - THROW_ERROR("AIFile_mkdir_Failed_to_create_DIRNAME", AIArgs("[DIRNAME]", dirname)); - } -} - -//static -void AIFile::rmdir(std::string const& dirname) -{ - int rc = LLFile::rmdir_nowarn(dirname); - if (rc < 0 && errno != ENOENT) - { - THROW_ERROR("AIFile_rmdir_Failed_to_remove_DIRNAME", AIArgs("[DIRNAME]", dirname)); - } -} - -//static -LLFILE* AIFile::fopen(std::string const& filename, const char* mode) -{ - LLFILE* fp = LLFile::fopen(filename, mode); - if (!fp) - { - THROW_ERROR("AIFile_fopen_Failed_to_open_FILENAME", AIArgs("[FILENAME]", filename)); - } - return fp; -} - -//static -void AIFile::close(LLFILE* file) -{ - if (LLFile::close(file) < 0) - { - THROW_ERROR("AIFile_close_Failed_to_close_file", AIArgs); - } -} - -//static -void AIFile::remove(std::string const& filename) -{ - int rc = LLFile::remove_nowarn(filename); - if (rc < 0 && errno != ENOENT) - { - THROW_ERROR("AIFile_remove_Failed_to_remove_FILENAME", AIArgs("[FILENAME]", filename)); - } -} - -//static -void AIFile::rename(std::string const& filename, std::string const& newname) -{ - 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/aifile.h b/indra/llcommon/aifile.h deleted file mode 100644 index 1b110496a..000000000 --- a/indra/llcommon/aifile.h +++ /dev/null @@ -1,59 +0,0 @@ -/** - * @file aifile.h - * @brief Declaration of AIFile. - * - * Copyright (c) 2013, Aleric Inglewood. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution. - * - * CHANGELOG - * and additional copyright holders. - * - * 02/11/2013 - * Initial version, written by Aleric Inglewood @ SL - */ - -#ifndef AIFILE_H -#define AIFILE_H - -#include "llfile.h" - -// As LLFile, but throws AIAlert instead of printing a warning. -class LL_COMMON_API AIFile -{ - private: - LLFILE* mFp; - - public: - // Scoped file (exception safe). Throws AIAlertCode with errno on failure. - AIFile(std::string const& filename, char const* accessmode); - ~AIFile(); - - operator LLFILE* () const { return mFp; } - - // All these functions take UTF8 path/filenames. - static LLFILE* fopen(std::string const& filename, char const* accessmode); - static void close(LLFILE* file); - - static void mkdir(std::string const& dirname, int perms = 0700); // Does NOT throw when dirname already exists. - static void rmdir(std::string const& dirname); // Does NOT throw when dirname does not exist. - static void remove(std::string const& filename); // Does NOT throw when filename does not exist. - static void rename(std::string const& filename, std::string const& newname); -}; - -#endif // AIFILE_H diff --git a/indra/llxml/CMakeLists.txt b/indra/llxml/CMakeLists.txt index d65bf3146..2245255cd 100644 --- a/indra/llxml/CMakeLists.txt +++ b/indra/llxml/CMakeLists.txt @@ -13,7 +13,7 @@ include_directories( ) set(llxml_SOURCE_FILES - #aixml.cpp + aixml.cpp llcontrol.cpp llxmlnode.cpp llxmlparser.cpp @@ -23,7 +23,7 @@ set(llxml_SOURCE_FILES set(llxml_HEADER_FILES CMakeLists.txt - #aixml.h + aixml.h llcontrol.h llcontrolgroupreader.h llxmlnode.h diff --git a/indra/llxml/aixml.cpp b/indra/llxml/aixml.cpp index dffe3d73a..02b972e80 100644 --- a/indra/llxml/aixml.cpp +++ b/indra/llxml/aixml.cpp @@ -32,7 +32,6 @@ #include "aixml.h" #include "llmd5.h" #include -#include "aifile.h" //============================================================================= // Overview @@ -311,11 +310,10 @@ void AIXMLElement::child(LLDate const& element) //----------------------------------------------------------------------------- // AIXMLStream -AIXMLStream::AIXMLStream(LLFILE* fp, bool standalone) : mOfs(fp) +AIXMLStream::AIXMLStream(const std::string& filename, bool standalone) : mOfs(filename) { - char const* sp = standalone ? " standalone=\"yes\"" : ""; - int rc = fprintf(fp, "\n", sp); - if (rc < 0 || ferror(fp)) + mOfs << "\n"; + if (!mOfs) { // I don't think that errno is set to anything else but EBADF here, // so there is not really any informative message to add here. @@ -342,7 +340,6 @@ AIXMLParser::AIXMLParser(std::string const& filename, char const* file_desc, std AIArgs args; if (!mXmlTree.parseFile(filename, TRUE)) { - AIFile dummy(filename, "rb"); // Check if the file can be opened at all (throws with a more descriptive error if not). error = "AIXMLParser_Cannot_parse_FILEDESC_FILENAME"; } else diff --git a/indra/llxml/aixml.h b/indra/llxml/aixml.h index 3ff971101..358eed756 100644 --- a/indra/llxml/aixml.h +++ b/indra/llxml/aixml.h @@ -151,7 +151,7 @@ void AIXMLElement::child(FWD_ITERATOR i1, FWD_ITERATOR const& i2) class AIXMLStream { protected: llofstream mOfs; - AIXMLStream(LLFILE* fp, bool standalone); + AIXMLStream(const std::string& filename, bool standalone); ~AIXMLStream(); }; @@ -159,7 +159,7 @@ class AIXMLStream { class AIXMLRootElement : public AIXMLStream, public AIXMLElement { public: - AIXMLRootElement(LLFILE* fp, char const* name, bool standalone = true) : AIXMLStream(fp, standalone), AIXMLElement(mOfs, name, 0) { } + AIXMLRootElement(const std::string& filename, char const* name, bool standalone = true) : AIXMLStream(filename, standalone), AIXMLElement(mOfs, name, 0) { } }; class AIXMLElementParser diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt index 1ac784f5b..b06020155 100644 --- a/indra/newview/CMakeLists.txt +++ b/indra/newview/CMakeLists.txt @@ -78,7 +78,7 @@ include_directories( set(viewer_SOURCE_FILES NACLantispam.cpp aihttpview.cpp - #aixmllindengenepool.cpp + aixmllindengenepool.cpp alfloaterregiontracker.cpp aoremotectrl.cpp ascentfloatercontactgroups.cpp @@ -613,7 +613,7 @@ set(viewer_HEADER_FILES NACLantispam.h aihttpview.h - #aixmllindengenepool.h + aixmllindengenepool.h alfloaterregiontracker.h aoremotectrl.h ascentfloatercontactgroups.h diff --git a/indra/newview/aixmllindengenepool.cpp b/indra/newview/aixmllindengenepool.cpp index 2e62a7955..5494a0700 100644 --- a/indra/newview/aixmllindengenepool.cpp +++ b/indra/newview/aixmllindengenepool.cpp @@ -68,7 +68,7 @@ AIXMLLindenGenepool::MetaData::MetaData(AIXMLElementParser const& parser) parser.attribute(DEFAULT_LLDATE_NAME, mDate); } -AIXMLLindenGenepool::AIXMLLindenGenepool(LLFILE* fp) : AIXMLRootElement(fp, "linden_genepool") +AIXMLLindenGenepool::AIXMLLindenGenepool(const std::string& filename) : AIXMLRootElement(filename, "linden_genepool") { attribute("version", "1.0"); attribute("metaversion", "1.0"); diff --git a/indra/newview/aixmllindengenepool.h b/indra/newview/aixmllindengenepool.h index c3a5a65d6..42aa5d35c 100644 --- a/indra/newview/aixmllindengenepool.h +++ b/indra/newview/aixmllindengenepool.h @@ -53,7 +53,7 @@ class AIXMLLindenGenepool : public AIXMLRootElement MetaData(AIXMLElementParser const& parser); }; - AIXMLLindenGenepool(LLFILE* fp); + AIXMLLindenGenepool(const std::string& filename); }; class AIVisualParamIDValuePair diff --git a/indra/newview/llfloatercustomize.cpp b/indra/newview/llfloatercustomize.cpp index 657920701..87bb14ffe 100644 --- a/indra/newview/llfloatercustomize.cpp +++ b/indra/newview/llfloatercustomize.cpp @@ -55,8 +55,7 @@ #include "statemachine/aifilepicker.h" #include "hippogridmanager.h" -//#include "aixmllindengenepool.h" -#include "aifile.h" +#include "aixmllindengenepool.h" using namespace LLAvatarAppearanceDefines; @@ -314,7 +313,6 @@ void LLFloaterCustomize::onBtnImport() void LLFloaterCustomize::onBtnImport_continued(AIFilePicker* filepicker) { -#if 0 if (!filepicker->hasFilename()) { // User canceled import. @@ -457,7 +455,6 @@ void LLFloaterCustomize::onBtnImport_continued(AIFilePicker* filepicker) { AIAlert::add("AIXMLImportWearableTypeMismatch", args("[TYPE]", label)("[ARCHETYPENAME]", wearable_types)); } -#endif } // reX: new function @@ -514,9 +511,7 @@ void LLFloaterCustomize::onBtnExport_continued(LLViewerWearable* edit_wearable, bool success = false; try { - AIFile outfile(filename, "wb"); - - AIXMLLindenGenepool linden_genepool(outfile); + AIXMLLindenGenepool linden_genepool(filename); linden_genepool.child(edit_wearable->getArchetype()); success = true; diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp index 217544bf6..5a12c6e0c 100644 --- a/indra/newview/llvoavatar.cpp +++ b/indra/newview/llvoavatar.cpp @@ -113,8 +113,7 @@ #include "llskinningutil.h" #include "llfloaterexploreanimations.h" -//#include "aixmllindengenepool.h" -#include "aifile.h" +#include "aixmllindengenepool.h" #include "llavatarname.h" #include "../lscript/lscript_byteformat.h" @@ -9420,11 +9419,9 @@ void LLVOAvatar::dumpArchetypeXML(const std::string& prefix, bool group_by_weara void LLVOAvatar::dumpArchetypeXML_cont(std::string const& fullpath, bool group_by_wearables) { -#if 0 try { - AIFile outfile(fullpath, "wb"); - AIXMLLindenGenepool linden_genepool(outfile); + AIXMLLindenGenepool linden_genepool(fullpath); if (group_by_wearables) { @@ -9496,7 +9493,6 @@ void LLVOAvatar::dumpArchetypeXML_cont(std::string const& fullpath, bool group_b { AIAlert::add_modal("AIXMLdumpArchetypeXMLError", AIArgs("[FILE]", fullpath), error); } -#endif }