add ability to view gvfs entries in hex editor

This commit is contained in:
Hazim Gazov
2010-06-26 17:14:03 +00:00
parent dda0b2d3d6
commit a05e491ed7
4 changed files with 128 additions and 53 deletions

View File

@@ -27,26 +27,47 @@
std::list<DOFloaterHex*> DOFloaterHex::sInstances;
S32 DOFloaterHex::sUploadAmount = 10;
DOFloaterHex::DOFloaterHex(LLInventoryItem* item)
DOFloaterHex::DOFloaterHex(LLUUID item_id, BOOL vfs, LLAssetType::EType asset_type)
: LLFloater()
{
sInstances.push_back(this);
mItem = item;
LLUICtrlFactory::getInstance()->buildFloater(this, "floater_hex.xml");
}
// static
void DOFloaterHex::show(LLUUID item_id)
//this bit should be rewritten entirely
void DOFloaterHex::show(LLUUID item_id, BOOL vfs, LLAssetType::EType asset_type)
{
LLInventoryItem* item = (LLInventoryItem*)gInventory.getItem(item_id);
if(item)
if(!vfs)
{
LLInventoryItem* item = (LLInventoryItem*)gInventory.getItem(item_id);
if(item)
{
S32 left, top;
gFloaterView->getNewFloaterPosition(&left, &top);
LLRect rect = gSavedSettings.getRect("FloaterHexRect");
rect.translate(left - rect.mLeft, top - rect.mTop);
DOFloaterHex* floaterp = new DOFloaterHex(item_id);
floaterp->setRect(rect);
floaterp->mVFS = false;
floaterp->mAssetId = item->getAssetUUID();
floaterp->mAssetType = item->getType();
floaterp->mItem = item;
gFloaterView->adjustToFitScreen(floaterp, FALSE);
}
} else if (item_id.notNull() && asset_type != LLAssetType::AT_NONE) {
S32 left, top;
gFloaterView->getNewFloaterPosition(&left, &top);
LLRect rect = gSavedSettings.getRect("FloaterHexRect");
rect.translate(left - rect.mLeft, top - rect.mTop);
DOFloaterHex* floaterp = new DOFloaterHex(item);
DOFloaterHex* floaterp = new DOFloaterHex(item_id);
floaterp->setRect(rect);
floaterp->mVFS = true;
floaterp->mAssetId = item_id;
floaterp->mAssetType = asset_type;
gFloaterView->adjustToFitScreen(floaterp, FALSE);
}
}
@@ -80,7 +101,7 @@ BOOL DOFloaterHex::postBuild(void)
childSetEnabled("save_btn", false);
childSetAction("save_btn", onClickSave, this);
if(mItem)
if(!mVFS && mItem)
{
std::string title = "Hex editor: " + mItem->getName();
const char* asset_type_name = LLAssetType::lookup(mItem->getType());
@@ -90,19 +111,21 @@ BOOL DOFloaterHex::postBuild(void)
}
setTitle(title);
}
#if OPENSIM_RULES!=1
if(mItem->getCreatorUUID() == gAgentID)
if(!mVFS)
{
#endif /* OPENSIM_RULES!=1 */
// Load the asset
editor->setVisible(FALSE);
childSetText("status_text", std::string("Loading..."));
LLInventoryBackup::download(mItem, this, imageCallback, assetCallback);
#if OPENSIM_RULES!=1
}
else if (mVFS) //the asset already exists in the VFS, we don't need to fetch it
//and we don't want to associate it with an item
{
setTitle(mAssetId.asString());
readVFile();
} else {
this->close(false);
}
#endif /* OPENSIM_RULES!=1 */
return TRUE;
}
@@ -428,4 +451,35 @@ void DOFloaterHex::handleSizing()
}
}
void DOFloaterHex::readVFile()
{
// quick cut paste job
// Todo: this doesn't work for static vfs shit
LLVFile file(gVFS, mAssetId, mAssetType, LLVFile::READ);
S32 size = file.getSize();
char* buffer = new char[size];
if (buffer == NULL)
{
llerrs << "Memory Allocation Failed" << llendl;
return;
}
file.read((U8*)buffer, size);
std::vector<U8> new_data;
for(S32 i = 0; i < size; i++)
new_data.push_back(buffer[i]);
delete[] buffer;
floater->mEditor->setValue(new_data);
floater->mEditor->setVisible(TRUE);
floater->childSetText("status_text", std::string("Editing VFile"));
floater->childSetEnabled("upload_btn", false);
floater->childSetEnabled("save_btn", false);
}
// </edit>