fix a couple of things for the vfs explorer

This commit is contained in:
Hazim Gazov
2010-06-26 17:27:48 +00:00
parent a05e491ed7
commit 1145f8aa2e
6 changed files with 163 additions and 136 deletions

View File

@@ -55,32 +55,25 @@ const S32 BLOCK_LENGTH_INVALID = -1; // mLength for invalid LLVFSFileBlocks
LLVFS *gVFS = NULL;
// internal class definitions
class LLVFSBlock
{
public:
LLVFSBlock()
{
mLocation = 0;
mLength = 0;
}
LLVFSBlock(U32 loc, S32 size)
{
mLocation = loc;
mLength = size;
}
static bool locationSortPredicate(
const LLVFSBlock* lhs,
const LLVFSBlock* rhs)
{
return lhs->mLocation < rhs->mLocation;
}
public:
U32 mLocation;
S32 mLength; // allocated block size
};
LLVFSBlock::LLVFSBlock()
{
mLocation = 0;
mLength = 0;
}
LLVFSBlock::LLVFSBlock(U32 loc, S32 size)
{
mLocation = loc;
mLength = size;
}
bool LLVFSBlock::locationSortPredicate(
const LLVFSBlock* lhs,
const LLVFSBlock* rhs)
{
return lhs->mLocation < rhs->mLocation;
}
LLVFSFileSpecifier::LLVFSFileSpecifier()
: mFileID(),
@@ -108,117 +101,106 @@ bool LLVFSFileSpecifier::operator==(const LLVFSFileSpecifier &rhs) const
}
class LLVFSFileBlock : public LLVFSBlock, public LLVFSFileSpecifier
LLVFSFileBlock::LLVFSFileBlock() : LLVFSBlock(), LLVFSFileSpecifier()
{
public:
LLVFSFileBlock() : LLVFSBlock(), LLVFSFileSpecifier()
{
init();
}
LLVFSFileBlock(const LLUUID &file_id, LLAssetType::EType file_type, U32 loc = 0, S32 size = 0)
: LLVFSBlock(loc, size), LLVFSFileSpecifier( file_id, file_type )
{
init();
}
init();
}
void init()
{
mSize = 0;
mIndexLocation = -1;
mAccessTime = (U32)time(NULL);
LLVFSFileBlock::LLVFSFileBlock(const LLUUID &file_id, LLAssetType::EType file_type, U32 loc, S32 size) :
LLVFSBlock(loc, size), LLVFSFileSpecifier( file_id, file_type )
{
init();
}
for (S32 i = 0; i < (S32)VFSLOCK_COUNT; i++)
{
mLocks[(EVFSLock)i] = 0;
}
}
void LLVFSFileBlock::init()
{
mSize = 0;
mIndexLocation = -1;
mAccessTime = (U32)time(NULL);
#ifdef LL_LITTLE_ENDIAN
inline void swizzleCopy(void *dst, void *src, int size) { memcpy(dst, src, size); /* Flawfinder: ignore */}
for (S32 i = 0; i < (S32)VFSLOCK_COUNT; i++)
{
mLocks[(EVFSLock)i] = 0;
}
}
#else
inline U32 swizzle32(U32 x)
{
return(((x >> 24) & 0x000000FF) | ((x >> 8) & 0x0000FF00) | ((x << 8) & 0x00FF0000) |((x << 24) & 0xFF000000));
}
inline U16 swizzle16(U16 x)
{
return( ((x >> 8) & 0x000000FF) | ((x << 8) & 0x0000FF00) );
}
inline void swizzleCopy(void *dst, void *src, int size)
{
if(size == 4)
{
((U32*)dst)[0] = swizzle32(((U32*)src)[0]);
}
else if(size == 2)
{
((U16*)dst)[0] = swizzle16(((U16*)src)[0]);
}
else
{
// Perhaps this should assert...
memcpy(dst, src, size); /* Flawfinder: ignore */
}
}
#endif
#ifdef LL_LITTLE_ENDIAN
void LLVFSFileBlock::swizzleCopy(void *dst, void *src, int size) { memcpy(dst, src, size); /* Flawfinder: ignore */}
void serialize(U8 *buffer)
#else
U32 LLVFSFileBlock::swizzle32(U32 x)
{
return(((x >> 24) & 0x000000FF) | ((x >> 8) & 0x0000FF00) | ((x << 8) & 0x00FF0000) |((x << 24) & 0xFF000000));
}
U16 LLVFSFileBlock::swizzle16(U16 x)
{
return( ((x >> 8) & 0x000000FF) | ((x << 8) & 0x0000FF00) );
}
void LLVFSFileBlock::swizzleCopy(void *dst, void *src, int size)
{
if(size == 4)
{
swizzleCopy(buffer, &mLocation, 4);
buffer += 4;
swizzleCopy(buffer, &mLength, 4);
buffer +=4;
swizzleCopy(buffer, &mAccessTime, 4);
buffer +=4;
memcpy(buffer, &mFileID.mData, 16); /* Flawfinder: ignore */
buffer += 16;
S16 temp_type = mFileType;
swizzleCopy(buffer, &temp_type, 2);
buffer += 2;
swizzleCopy(buffer, &mSize, 4);
((U32*)dst)[0] = swizzle32(((U32*)src)[0]);
}
void deserialize(U8 *buffer, const S32 index_loc)
else if(size == 2)
{
mIndexLocation = index_loc;
swizzleCopy(&mLocation, buffer, 4);
buffer += 4;
swizzleCopy(&mLength, buffer, 4);
buffer += 4;
swizzleCopy(&mAccessTime, buffer, 4);
buffer += 4;
memcpy(&mFileID.mData, buffer, 16);
buffer += 16;
S16 temp_type;
swizzleCopy(&temp_type, buffer, 2);
mFileType = (LLAssetType::EType)temp_type;
buffer += 2;
swizzleCopy(&mSize, buffer, 4);
((U16*)dst)[0] = swizzle16(((U16*)src)[0]);
}
static BOOL insertLRU(LLVFSFileBlock* const& first,
LLVFSFileBlock* const& second)
else
{
return (first->mAccessTime == second->mAccessTime)
? *first < *second
: first->mAccessTime < second->mAccessTime;
// Perhaps this should assert...
memcpy(dst, src, size); /* Flawfinder: ignore */
}
public:
S32 mSize;
S32 mIndexLocation; // location of index entry
U32 mAccessTime;
BOOL mLocks[VFSLOCK_COUNT]; // number of outstanding locks of each type
static const S32 SERIAL_SIZE;
};
}
#endif
void LLVFSFileBlock::serialize(U8 *buffer)
{
swizzleCopy(buffer, &mLocation, 4);
buffer += 4;
swizzleCopy(buffer, &mLength, 4);
buffer +=4;
swizzleCopy(buffer, &mAccessTime, 4);
buffer +=4;
memcpy(buffer, &mFileID.mData, 16); /* Flawfinder: ignore */
buffer += 16;
S16 temp_type = mFileType;
swizzleCopy(buffer, &temp_type, 2);
buffer += 2;
swizzleCopy(buffer, &mSize, 4);
}
void LLVFSFileBlock::deserialize(U8 *buffer, const S32 index_loc)
{
mIndexLocation = index_loc;
swizzleCopy(&mLocation, buffer, 4);
buffer += 4;
swizzleCopy(&mLength, buffer, 4);
buffer += 4;
swizzleCopy(&mAccessTime, buffer, 4);
buffer += 4;
memcpy(&mFileID.mData, buffer, 16);
buffer += 16;
S16 temp_type;
swizzleCopy(&temp_type, buffer, 2);
mFileType = (LLAssetType::EType)temp_type;
buffer += 2;
swizzleCopy(&mSize, buffer, 4);
}
BOOL LLVFSFileBlock::insertLRU(LLVFSFileBlock* const& first,
LLVFSFileBlock* const& second)
{
return (first->mAccessTime == second->mAccessTime)
? *first < *second
: first->mAccessTime < second->mAccessTime;
}
// Helper structure for doing lru w/ stl... is there a simpler way?
struct LLVFSFileBlock_less

View File

@@ -59,9 +59,24 @@ enum EVFSLock
VFSLOCK_COUNT = 3
};
// internal classes
class LLVFSBlock;
class LLVFSFileBlock;
//<edit>
//the VFS explorer requires that the class definition of these be available outside of llvfs
class LLVFSBlock
{
public:
LLVFSBlock();
LLVFSBlock(U32 loc, S32 size);
static bool locationSortPredicate(
const LLVFSBlock* lhs,
const LLVFSBlock* rhs);
public:
U32 mLocation;
S32 mLength; // allocated block size
};
class LLVFSFileSpecifier
{
public:
@@ -75,6 +90,32 @@ public:
LLAssetType::EType mFileType;
};
class LLVFSFileBlock : public LLVFSBlock, public LLVFSFileSpecifier
{
public:
LLVFSFileBlock();
LLVFSFileBlock(const LLUUID &file_id, LLAssetType::EType file_type, U32 loc = 0, S32 size = 0);
void init();
#ifdef LL_LITTLE_ENDIAN
inline void swizzleCopy(void *dst, void *src, int size);
#else
inline U32 swizzle32(U32 x);
inline U16 swizzle16(U16 x);
inline void swizzleCopy(void *dst, void *src, int size);
#endif
void serialize(U8 *buffer);
void deserialize(U8 *buffer, const S32 index_loc);
static BOOL insertLRU(LLVFSFileBlock* const& first,
LLVFSFileBlock* const& second);
S32 mSize;
S32 mIndexLocation; // location of index entry
U32 mAccessTime;
BOOL mLocks[VFSLOCK_COUNT]; // number of outstanding locks of each type
static const S32 SERIAL_SIZE;
};
//<edit>
class LLVFS
{
public:

View File

@@ -473,13 +473,13 @@ void DOFloaterHex::readVFile()
delete[] buffer;
floater->mEditor->setValue(new_data);
floater->mEditor->setVisible(TRUE);
mEditor->setValue(new_data);
mEditor->setVisible(TRUE);
floater->childSetText("status_text", std::string("Editing VFile"));
childSetText("status_text", std::string("Editing VFile"));
floater->childSetEnabled("upload_btn", false);
floater->childSetEnabled("save_btn", false);
childSetEnabled("upload_btn", false);
childSetEnabled("save_btn", false);
}
// </edit>

View File

@@ -15,7 +15,7 @@ class DOFloaterHex
{
public:
DOFloaterHex(LLUUID item_id, BOOL vfs=false, LLAssetType::EType asset_type = LLAssetType::AT_NONE);
static void show(LLUUID item_id);
static void show(LLUUID item_id, BOOL vfs=false, LLAssetType::EType asset_type = LLAssetType::AT_NONE);
BOOL postBuild(void);
void close(bool app_quitting);
static void imageCallback(BOOL success,

View File

@@ -10,7 +10,7 @@
#include "lllocalinventory.h"
#include "llviewerwindow.h"
#include "llassetconverter.h"
#include "dohexeditor.h"
#include "dofloaterhex.h"
LLFloaterVFSExplorer* LLFloaterVFSExplorer::sInstance;
std::map<LLVFSFileSpecifier, LLVFSFileBlock*> LLFloaterVFSExplorer::sVFSFileMap;
@@ -42,6 +42,7 @@ BOOL LLFloaterVFSExplorer::postBuild()
childSetAction("remove_btn", onClickRemove, this);
childSetAction("reload_all_btn", onClickReload, this);
childSetAction("copy_uuid_btn", onClickCopyUUID, this);
childSetAction("edit_data_btn", onClickEditData, this);
refresh();
return TRUE;
}
@@ -140,6 +141,7 @@ void LLFloaterVFSExplorer::setEditEnabled(bool enabled)
childSetEnabled("name_edit", false);
childSetEnabled("id_edit", false);
childSetEnabled("type_combo", false);
childSetEnabled("edit_data_btn", enabled);
childSetEnabled("remove_btn", enabled);
childSetEnabled("copy_uuid_btn", enabled);
}
@@ -175,13 +177,14 @@ void LLFloaterVFSExplorer::onClickReload(void* user_data)
// static
void LLFloaterVFSExplorer::onClickEditData(void* user_data)
{
LLFloaterVFSExplorer* floaterp = (LLFloaterVFSExplorer*)user_data;
LLVFSFileSpecifier file;
std::map<LLVFSFileSpecifier, LLVFSFileBlock*>::iterator end = sVFSFileMap.end();
for(std::map<LLVFSFileSpecifier, LLVFSFileBlock*>::iterator iter = sVFSFileMap.begin(); iter != end; ++iter)
{
if((*iter).first.mFileID == mEditID)
if((*iter).first.mFileID == floaterp->mEditID)
file = (*iter).first;
}
DOHexEditor::showVFS(file.mFileID, file.mFileType);
DOFloaterHex::show(file.mFileID, true, file.mFileType);
}
// </edit>

View File

@@ -85,4 +85,5 @@
</combo_box>
<button name="copy_uuid_btn" follows="left|bottom" width="75" bottom="7" left="10" height="20" label="Copy UUID"/>
<button name="remove_btn" follows="left|bottom" width="75" bottom_delta="0" left_delta="75" height="20" label="Remove"/>
<button name="edit_data_btn" follows="left|bottom" width="75" bottom_delta="0" left_delta="75" height="20" label="View Data"/>
</floater>