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,17 +27,18 @@
std::list<DOFloaterHex*> DOFloaterHex::sInstances; std::list<DOFloaterHex*> DOFloaterHex::sInstances;
S32 DOFloaterHex::sUploadAmount = 10; S32 DOFloaterHex::sUploadAmount = 10;
DOFloaterHex::DOFloaterHex(LLInventoryItem* item) DOFloaterHex::DOFloaterHex(LLUUID item_id, BOOL vfs, LLAssetType::EType asset_type)
: LLFloater() : LLFloater()
{ {
sInstances.push_back(this); sInstances.push_back(this);
mItem = item;
LLUICtrlFactory::getInstance()->buildFloater(this, "floater_hex.xml"); LLUICtrlFactory::getInstance()->buildFloater(this, "floater_hex.xml");
} }
// static //this bit should be rewritten entirely
void DOFloaterHex::show(LLUUID item_id) void DOFloaterHex::show(LLUUID item_id, BOOL vfs, LLAssetType::EType asset_type)
{ {
if(!vfs)
{
LLInventoryItem* item = (LLInventoryItem*)gInventory.getItem(item_id); LLInventoryItem* item = (LLInventoryItem*)gInventory.getItem(item_id);
if(item) if(item)
{ {
@@ -45,8 +46,28 @@ void DOFloaterHex::show(LLUUID item_id)
gFloaterView->getNewFloaterPosition(&left, &top); gFloaterView->getNewFloaterPosition(&left, &top);
LLRect rect = gSavedSettings.getRect("FloaterHexRect"); LLRect rect = gSavedSettings.getRect("FloaterHexRect");
rect.translate(left - rect.mLeft, top - rect.mTop); rect.translate(left - rect.mLeft, top - rect.mTop);
DOFloaterHex* floaterp = new DOFloaterHex(item); DOFloaterHex* floaterp = new DOFloaterHex(item_id);
floaterp->setRect(rect); 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_id);
floaterp->setRect(rect);
floaterp->mVFS = true;
floaterp->mAssetId = item_id;
floaterp->mAssetType = asset_type;
gFloaterView->adjustToFitScreen(floaterp, FALSE); gFloaterView->adjustToFitScreen(floaterp, FALSE);
} }
} }
@@ -80,7 +101,7 @@ BOOL DOFloaterHex::postBuild(void)
childSetEnabled("save_btn", false); childSetEnabled("save_btn", false);
childSetAction("save_btn", onClickSave, this); childSetAction("save_btn", onClickSave, this);
if(mItem) if(!mVFS && mItem)
{ {
std::string title = "Hex editor: " + mItem->getName(); std::string title = "Hex editor: " + mItem->getName();
const char* asset_type_name = LLAssetType::lookup(mItem->getType()); const char* asset_type_name = LLAssetType::lookup(mItem->getType());
@@ -90,19 +111,21 @@ BOOL DOFloaterHex::postBuild(void)
} }
setTitle(title); setTitle(title);
} }
#if OPENSIM_RULES!=1 if(!mVFS)
if(mItem->getCreatorUUID() == gAgentID)
{ {
#endif /* OPENSIM_RULES!=1 */
// Load the asset // Load the asset
editor->setVisible(FALSE); editor->setVisible(FALSE);
childSetText("status_text", std::string("Loading...")); childSetText("status_text", std::string("Loading..."));
LLInventoryBackup::download(mItem, this, imageCallback, assetCallback); 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 { } else {
this->close(false); this->close(false);
} }
#endif /* OPENSIM_RULES!=1 */
return TRUE; 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> // </edit>

View File

@@ -8,12 +8,13 @@
#include "dohexeditor.h" #include "dohexeditor.h"
#include "llinventory.h" #include "llinventory.h"
#include "llviewerimage.h" #include "llviewerimage.h"
#include "llassettype.h"
class DOFloaterHex class DOFloaterHex
: public LLFloater : public LLFloater
{ {
public: public:
DOFloaterHex(LLInventoryItem* item); 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 postBuild(void); BOOL postBuild(void);
void close(bool app_quitting); void close(bool app_quitting);
@@ -33,7 +34,11 @@ public:
static void onSaveComplete(const LLUUID& asset_uuid, void* user_data, S32 status, LLExtStat ext_status); static void onSaveComplete(const LLUUID& asset_uuid, void* user_data, S32 status, LLExtStat ext_status);
static void onCommitColumnCount(LLUICtrl *control, void *user_data); static void onCommitColumnCount(LLUICtrl *control, void *user_data);
void handleSizing(); void handleSizing();
void readVFile();
LLInventoryItem* mItem; LLInventoryItem* mItem;
LLUUID mAssetId;
LLAssetType::EType mAssetType;
BOOL mVFS;
DOHexEditor* mEditor; DOHexEditor* mEditor;
static std::list<DOFloaterHex*> sInstances; static std::list<DOFloaterHex*> sInstances;
private: private:

View File

@@ -1,4 +1,5 @@
// <edit> // <edit>
//A lot of bad things going on in here, needs a rewrite.
#include "llviewerprecompiledheaders.h" #include "llviewerprecompiledheaders.h"
#include "llfloatervfsexplorer.h" #include "llfloatervfsexplorer.h"
#include "lluictrlfactory.h" #include "lluictrlfactory.h"
@@ -9,6 +10,7 @@
#include "lllocalinventory.h" #include "lllocalinventory.h"
#include "llviewerwindow.h" #include "llviewerwindow.h"
#include "llassetconverter.h" #include "llassetconverter.h"
#include "dohexeditor.h"
LLFloaterVFSExplorer* LLFloaterVFSExplorer::sInstance; LLFloaterVFSExplorer* LLFloaterVFSExplorer::sInstance;
std::map<LLVFSFileSpecifier, LLVFSFileBlock*> LLFloaterVFSExplorer::sVFSFileMap; std::map<LLVFSFileSpecifier, LLVFSFileBlock*> LLFloaterVFSExplorer::sVFSFileMap;
@@ -67,6 +69,7 @@ void LLFloaterVFSExplorer::refresh()
void LLFloaterVFSExplorer::reloadAll() void LLFloaterVFSExplorer::reloadAll()
{ {
//get our magic from gvfs here //get our magic from gvfs here
//this should re-request all assets from the server if possible.
refresh(); refresh();
} }
void LLFloaterVFSExplorer::setEditID(LLUUID edit_id) void LLFloaterVFSExplorer::setEditID(LLUUID edit_id)
@@ -169,4 +172,16 @@ void LLFloaterVFSExplorer::onClickReload(void* user_data)
LLFloaterVFSExplorer* floaterp = (LLFloaterVFSExplorer*)user_data; LLFloaterVFSExplorer* floaterp = (LLFloaterVFSExplorer*)user_data;
floaterp->reloadAll(); floaterp->reloadAll();
} }
// static
void LLFloaterVFSExplorer::onClickEditData(void* 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)
file = (*iter).first;
}
DOHexEditor::showVFS(file.mFileID, file.mFileType);
}
// </edit> // </edit>

View File

@@ -29,6 +29,7 @@ public:
static void onClickCopyUUID(void* user_data); static void onClickCopyUUID(void* user_data);
static void onClickRemove(void* user_data); static void onClickRemove(void* user_data);
static void onClickReload(void* user_data); static void onClickReload(void* user_data);
static void onClickEditData(void* user_data);
private: private:
static LLFloaterVFSExplorer* sInstance; static LLFloaterVFSExplorer* sInstance;
static std::map<LLVFSFileSpecifier, LLVFSFileBlock*> sVFSFileMap; static std::map<LLVFSFileSpecifier, LLVFSFileBlock*> sVFSFileMap;