Blacklist refactoring:
* Removed unnecessary includes * Removed unnecessary statics * Use by-reference parameters for object calls * Refactored code to adhere coding conventions
parent
6f9d980a3c
commit
8798c8d08b
|
|
@ -26,11 +26,11 @@
|
|||
*/
|
||||
|
||||
#include "llviewerprecompiledheaders.h"
|
||||
|
||||
#include "fsfloaterwsassetblacklist.h"
|
||||
|
||||
#include "fswsassetblacklist.h"
|
||||
#include "llfloater.h"
|
||||
#include "lluuid.h"
|
||||
#include "llsd.h"
|
||||
#include "llscrolllistctrl.h"
|
||||
#include "llviewercontrol.h"
|
||||
|
||||
|
|
@ -70,17 +70,15 @@ std::string FSFloaterWSAssetBlacklist::TypeToString(S32 type)
|
|||
|
||||
void FSFloaterWSAssetBlacklist::BuildBlacklist()
|
||||
{
|
||||
typedef std::map<LLUUID, LLSD>::iterator it_type;
|
||||
std::map<LLUUID,LLSD> data = FSWSAssetBlacklist::getInstance()->BlacklistData;
|
||||
t_blacklist_data data = FSWSAssetBlacklist::instance().getBlacklistData();
|
||||
|
||||
for(it_type iterator = data.begin(); iterator != data.end(); iterator++)
|
||||
for (t_blacklist_data::const_iterator iterator = data.begin(); iterator != data.end(); ++iterator)
|
||||
{
|
||||
LLSD data = iterator->second;
|
||||
addElementToList(iterator->first, iterator->second);
|
||||
addElementToList(iterator->first, iterator->second);
|
||||
}
|
||||
}
|
||||
|
||||
void FSFloaterWSAssetBlacklist::addElementToList(LLUUID id, LLSD data)
|
||||
void FSFloaterWSAssetBlacklist::addElementToList(const LLUUID& id, const LLSD& data)
|
||||
{
|
||||
LLSD element;
|
||||
element["id"] = id;
|
||||
|
|
@ -100,7 +98,7 @@ void FSFloaterWSAssetBlacklist::addElementToList(LLUUID id, LLSD data)
|
|||
mResultList->addElement(element, ADD_BOTTOM);
|
||||
}
|
||||
|
||||
void FSFloaterWSAssetBlacklist::removeElementFromList(LLUUID id)
|
||||
void FSFloaterWSAssetBlacklist::removeElementFromList(const LLUUID& id)
|
||||
{
|
||||
mResultList->deleteSingleItem(mResultList->getItemIndex(id));
|
||||
}
|
||||
|
|
@ -129,12 +127,11 @@ BOOL FSFloaterWSAssetBlacklist::postBuild()
|
|||
|
||||
void FSFloaterWSAssetBlacklist::onRemoveBtn()
|
||||
{
|
||||
std::vector<LLScrollListItem*> list=mResultList->getAllSelected();
|
||||
std::vector<LLScrollListItem*> list = mResultList->getAllSelected();
|
||||
|
||||
for (std::vector<LLScrollListItem*>::iterator it = list.begin(); it != list.end(); it++)
|
||||
for (std::vector<LLScrollListItem*>::const_iterator it = list.begin(); it != list.end(); ++it)
|
||||
{
|
||||
LLScrollListItem* item = *it;
|
||||
FSWSAssetBlacklist::getInstance()->removeItemFromBlacklist(item->getUUID());
|
||||
FSWSAssetBlacklist::instance().removeItemFromBlacklist((*it)->getUUID());
|
||||
}
|
||||
|
||||
mResultList->deleteSelectedItems();
|
||||
|
|
|
|||
|
|
@ -29,13 +29,9 @@
|
|||
#define FS_FLOATERWSASSETBLACKLIST_H
|
||||
|
||||
#include "llfloater.h"
|
||||
#include "llassettype.h"
|
||||
|
||||
|
||||
class LLScrollListCtrl;
|
||||
|
||||
|
||||
|
||||
class FSFloaterWSAssetBlacklist : public LLFloater
|
||||
{
|
||||
LOG_CLASS(FSFloaterWSAssetBlacklist);
|
||||
|
|
@ -44,13 +40,12 @@ public:
|
|||
virtual ~FSFloaterWSAssetBlacklist();
|
||||
|
||||
/*virtual*/ void onOpen(const LLSD& key);
|
||||
|
||||
/*virtual*/ BOOL postBuild();
|
||||
|
||||
std::string TypeToString(S32 type);
|
||||
void BuildBlacklist();
|
||||
void addElementToList(LLUUID id, LLSD data);
|
||||
void removeElementFromList(LLUUID id);
|
||||
|
||||
void addElementToList(const LLUUID& id, const LLSD& data);
|
||||
void removeElementFromList(const LLUUID& id);
|
||||
|
||||
protected:
|
||||
void onRemoveBtn();
|
||||
|
|
|
|||
|
|
@ -26,21 +26,15 @@
|
|||
*/
|
||||
|
||||
#include "llviewerprecompiledheaders.h"
|
||||
|
||||
#include "fswsassetblacklist.h"
|
||||
#include "llsdserialize.h"
|
||||
#include "llassettype.h"
|
||||
#include "llstring.h"
|
||||
#include "llviewerregion.h"
|
||||
#include "llagent.h"
|
||||
|
||||
#include "fsfloaterwsassetblacklist.h"
|
||||
#include "llfloaterreg.h"
|
||||
#include "llsdserialize.h"
|
||||
#include "llvfs.h"
|
||||
#include "llaudioengine.h"
|
||||
#include "llxorcipher.h"
|
||||
|
||||
std::string FSWSAssetBlacklist::blacklist_file_name;
|
||||
std::map<LLUUID,LLSD> FSWSAssetBlacklist::BlacklistData;
|
||||
BlacklistMAP FSWSAssetBlacklist::BlacklistIDs;
|
||||
|
||||
const LLUUID MAGIC_ID("3c115e51-04f4-523c-9fa6-98aff1034730");
|
||||
|
||||
|
|
@ -66,26 +60,26 @@ LLAssetType::EType S32toAssetType(S32 assetindex)
|
|||
|
||||
void FSWSAssetBlacklist::init()
|
||||
{
|
||||
blacklist_file_name = gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, "asset_blacklist.xml");
|
||||
mBlacklistFileName = gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, "asset_blacklist.xml");
|
||||
loadBlacklist();
|
||||
}
|
||||
|
||||
bool FSWSAssetBlacklist::isBlacklisted(LLUUID id, LLAssetType::EType type)
|
||||
bool FSWSAssetBlacklist::isBlacklisted(const LLUUID& id, LLAssetType::EType type)
|
||||
{
|
||||
if (BlacklistData.size() == 0)
|
||||
if (mBlacklistData.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
BlacklistMAP::iterator it;
|
||||
it = BlacklistIDs.find(type);
|
||||
t_blacklist_type_map::iterator it;
|
||||
it = mBlacklistTypeContainer.find(type);
|
||||
|
||||
if (it == BlacklistIDs.end())
|
||||
if (it == mBlacklistTypeContainer.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<LLUUID> uuids = it->second;
|
||||
t_blacklisted_uuid_container uuids = it->second;
|
||||
if (std::find(uuids.begin(), uuids.end(), id) != uuids.end())
|
||||
{
|
||||
return true;
|
||||
|
|
@ -94,7 +88,7 @@ bool FSWSAssetBlacklist::isBlacklisted(LLUUID id, LLAssetType::EType type)
|
|||
return false;
|
||||
}
|
||||
|
||||
void FSWSAssetBlacklist::addNewItemToBlacklist(LLUUID id, std::string name, std::string region, LLAssetType::EType type, bool save)
|
||||
void FSWSAssetBlacklist::addNewItemToBlacklist(const LLUUID& id, const std::string& name, const std::string& region, LLAssetType::EType type, bool save)
|
||||
{
|
||||
LLDate curdate = LLDate(time_corrected());
|
||||
std::string input_date = curdate.asString();
|
||||
|
|
@ -110,33 +104,34 @@ void FSWSAssetBlacklist::addNewItemToBlacklist(LLUUID id, std::string name, std:
|
|||
addNewItemToBlacklistData(id, data, save);
|
||||
}
|
||||
|
||||
void FSWSAssetBlacklist::removeItemFromBlacklist(LLUUID id)
|
||||
void FSWSAssetBlacklist::removeItemFromBlacklist(const LLUUID& id)
|
||||
{
|
||||
std::map<LLUUID,LLSD>::iterator it;
|
||||
it = BlacklistData.find(id);
|
||||
if (it == BlacklistData.end())
|
||||
t_blacklist_data::iterator it;
|
||||
it = mBlacklistData.find(id);
|
||||
if (it == mBlacklistData.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
LLSD data = it->second;
|
||||
|
||||
BlacklistIDs[S32toAssetType(data["asset_type"].asInteger())].erase(
|
||||
std::remove(BlacklistIDs[S32toAssetType(data["asset_type"].asInteger())].begin(),
|
||||
BlacklistIDs[S32toAssetType(data["asset_type"].asInteger())].end(), id),
|
||||
BlacklistIDs[S32toAssetType(data["asset_type"].asInteger())].end());
|
||||
LLAssetType::EType type = S32toAssetType(data["asset_type"].asInteger());
|
||||
|
||||
BlacklistData.erase(id);
|
||||
mBlacklistTypeContainer[type].erase(
|
||||
std::remove(mBlacklistTypeContainer[type].begin(),
|
||||
mBlacklistTypeContainer[type].end(), id),
|
||||
mBlacklistTypeContainer[type].end());
|
||||
|
||||
mBlacklistData.erase(id);
|
||||
|
||||
saveBlacklist();
|
||||
}
|
||||
|
||||
void FSWSAssetBlacklist::addNewItemToBlacklistData(LLUUID id, LLSD data, bool save)
|
||||
void FSWSAssetBlacklist::addNewItemToBlacklistData(const LLUUID& id, const LLSD& data, bool save)
|
||||
{
|
||||
LLAssetType::EType type = S32toAssetType(data["asset_type"].asInteger());
|
||||
|
||||
addEntryToBlacklistMap(id,type);
|
||||
BlacklistData.insert(std::pair<LLUUID,LLSD>(id,data));
|
||||
mBlacklistData.insert(std::pair<LLUUID,LLSD>(id,data));
|
||||
|
||||
if (save)
|
||||
{
|
||||
|
|
@ -150,7 +145,7 @@ void FSWSAssetBlacklist::addNewItemToBlacklistData(LLUUID id, LLSD data, bool sa
|
|||
}
|
||||
}
|
||||
|
||||
bool FSWSAssetBlacklist::addEntryToBlacklistMap(LLUUID id, LLAssetType::EType type)
|
||||
bool FSWSAssetBlacklist::addEntryToBlacklistMap(const LLUUID& id, LLAssetType::EType type)
|
||||
{
|
||||
if (id.isNull())
|
||||
{
|
||||
|
|
@ -160,43 +155,39 @@ bool FSWSAssetBlacklist::addEntryToBlacklistMap(LLUUID id, LLAssetType::EType ty
|
|||
std::stringstream typesstream;
|
||||
typesstream << (int)type;
|
||||
std::string types = typesstream.str();
|
||||
std::map<LLAssetType::EType,std::vector<LLUUID> >::iterator it;
|
||||
it = BlacklistIDs.find(type);
|
||||
t_blacklist_type_map::iterator it;
|
||||
it = mBlacklistTypeContainer.find(type);
|
||||
|
||||
if (it == BlacklistIDs.end())
|
||||
if (it != mBlacklistTypeContainer.end())
|
||||
{
|
||||
std::vector<LLUUID> vec;
|
||||
vec.push_back(id);
|
||||
BlacklistIDs[type] = vec;
|
||||
it = BlacklistIDs.find(type);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (it != BlacklistIDs.end())
|
||||
{
|
||||
BlacklistIDs[type].push_back(id);
|
||||
return true;
|
||||
mBlacklistTypeContainer[type].push_back(id);
|
||||
}
|
||||
return false;
|
||||
else
|
||||
{
|
||||
t_blacklisted_uuid_container vec;
|
||||
vec.push_back(id);
|
||||
mBlacklistTypeContainer[type] = vec;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void FSWSAssetBlacklist::loadBlacklist()
|
||||
{
|
||||
if (gDirUtilp->fileExists(blacklist_file_name))
|
||||
if (gDirUtilp->fileExists(mBlacklistFileName))
|
||||
{
|
||||
llifstream blacklistdata(blacklist_file_name);
|
||||
if (blacklistdata.is_open())
|
||||
llifstream mBlacklistData(mBlacklistFileName);
|
||||
if (mBlacklistData.is_open())
|
||||
{
|
||||
LLSD data;
|
||||
if (LLSDSerialize::fromXML(data, blacklistdata) >= 1)
|
||||
if (LLSDSerialize::fromXML(data, mBlacklistData) >= 1)
|
||||
{
|
||||
for(LLSD::map_iterator itr = data.beginMap(); itr != data.endMap(); ++itr)
|
||||
for (LLSD::map_const_iterator itr = data.beginMap(); itr != data.endMap(); ++itr)
|
||||
{
|
||||
LLUUID uid = LLUUID(itr->first);
|
||||
LLXORCipher cipher(MAGIC_ID.mData, UUID_BYTES);
|
||||
cipher.decrypt(uid.mData, UUID_BYTES);
|
||||
LLSD data = itr->second;
|
||||
if(uid.isNull())
|
||||
if (uid.isNull())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
@ -208,7 +199,7 @@ void FSWSAssetBlacklist::loadBlacklist()
|
|||
}
|
||||
}
|
||||
}
|
||||
blacklistdata.close();
|
||||
mBlacklistData.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -222,7 +213,7 @@ void FSWSAssetBlacklist::loadBlacklist()
|
|||
if (oldfile.is_open())
|
||||
{
|
||||
LLSDSerialize::fromXMLDocument(datallsd, oldfile);
|
||||
for (LLSD::map_iterator itr = datallsd.beginMap(); itr != datallsd.endMap(); ++itr)
|
||||
for (LLSD::map_const_iterator itr = datallsd.beginMap(); itr != datallsd.endMap(); ++itr)
|
||||
{
|
||||
LLUUID uid = LLUUID(itr->first);
|
||||
LLSD data = itr->second;
|
||||
|
|
@ -258,10 +249,10 @@ void FSWSAssetBlacklist::loadBlacklist()
|
|||
|
||||
void FSWSAssetBlacklist::saveBlacklist()
|
||||
{
|
||||
llofstream save_file(blacklist_file_name);
|
||||
llofstream save_file(mBlacklistFileName);
|
||||
LLSD savedata;
|
||||
|
||||
for (std::map<LLUUID,LLSD>::iterator itr = BlacklistData.begin(); itr != BlacklistData.end(); ++itr)
|
||||
for (t_blacklist_data::const_iterator itr = mBlacklistData.begin(); itr != mBlacklistData.end(); ++itr)
|
||||
{
|
||||
// <FS:CR> Apply "cheesy encryption" to obfuscate these to the user.
|
||||
LLUUID shadow_id(itr->first);
|
||||
|
|
|
|||
|
|
@ -28,31 +28,33 @@
|
|||
#ifndef FS_WSASSETBLACKLIST_H
|
||||
#define FS_WSASSETBLACKLIST_H
|
||||
|
||||
#include "llviewerprecompiledheaders.h"
|
||||
#include "llsingleton.h"
|
||||
#include "llfloater.h"
|
||||
#include "llassettype.h"
|
||||
|
||||
|
||||
typedef std::map<LLAssetType::EType,std::vector<LLUUID> > BlacklistMAP;
|
||||
typedef std::vector<LLUUID> t_blacklisted_uuid_container;
|
||||
typedef std::map<LLAssetType::EType, t_blacklisted_uuid_container > t_blacklist_type_map;
|
||||
typedef std::map<LLUUID, LLSD> t_blacklist_data;
|
||||
|
||||
class FSWSAssetBlacklist : public LLSingleton<FSWSAssetBlacklist>
|
||||
{
|
||||
public:
|
||||
void init();
|
||||
bool isBlacklisted(LLUUID id, LLAssetType::EType type);
|
||||
void addNewItemToBlacklist(LLUUID id, std::string name, std::string region, LLAssetType::EType type, bool save = true);
|
||||
void addNewItemToBlacklistData(LLUUID id, LLSD data, bool save = true);
|
||||
void removeItemFromBlacklist(LLUUID id);
|
||||
static std::map<LLUUID,LLSD> BlacklistData;
|
||||
bool isBlacklisted(const LLUUID& id, LLAssetType::EType type);
|
||||
void addNewItemToBlacklist(const LLUUID& id, const std::string& name, const std::string& region, LLAssetType::EType type, bool save = true);
|
||||
void addNewItemToBlacklistData(const LLUUID& id, const LLSD& data, bool save = true);
|
||||
void removeItemFromBlacklist(const LLUUID& id);
|
||||
|
||||
t_blacklist_data getBlacklistData() const { return mBlacklistData; };
|
||||
|
||||
private:
|
||||
void loadBlacklist();
|
||||
void saveBlacklist();
|
||||
bool addEntryToBlacklistMap(LLUUID id, LLAssetType::EType type);
|
||||
bool addEntryToBlacklistMap(const LLUUID& id, LLAssetType::EType type);
|
||||
|
||||
static std::string blacklist_file_name;
|
||||
static BlacklistMAP BlacklistIDs;
|
||||
std::string mBlacklistFileName;
|
||||
t_blacklist_type_map mBlacklistTypeContainer;
|
||||
t_blacklist_data mBlacklistData;
|
||||
};
|
||||
|
||||
#endif // FS_WSASSETBLACKLIST_H
|
||||
Loading…
Reference in New Issue