From a05e491ed734e6bd34ff0f0c7c9c86ff70cb40cc Mon Sep 17 00:00:00 2001 From: Hazim Gazov Date: Sat, 26 Jun 2010 17:14:03 +0000 Subject: [PATCH] add ability to view gvfs entries in hex editor --- indra/newview/dofloaterhex.cpp | 80 +++++++++++++++++++++----- indra/newview/dofloaterhex.h | 7 ++- indra/newview/llfloatervfsexplorer.cpp | 15 +++++ indra/newview/llfloatervfsexplorer.h | 79 ++++++++++++------------- 4 files changed, 128 insertions(+), 53 deletions(-) diff --git a/indra/newview/dofloaterhex.cpp b/indra/newview/dofloaterhex.cpp index e30295b1e..a851798fd 100644 --- a/indra/newview/dofloaterhex.cpp +++ b/indra/newview/dofloaterhex.cpp @@ -27,26 +27,47 @@ std::list 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 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); +} + // diff --git a/indra/newview/dofloaterhex.h b/indra/newview/dofloaterhex.h index 9c49b3e49..57998b66f 100644 --- a/indra/newview/dofloaterhex.h +++ b/indra/newview/dofloaterhex.h @@ -8,12 +8,13 @@ #include "dohexeditor.h" #include "llinventory.h" #include "llviewerimage.h" +#include "llassettype.h" class DOFloaterHex : public LLFloater { public: - DOFloaterHex(LLInventoryItem* item); + DOFloaterHex(LLUUID item_id, BOOL vfs=false, LLAssetType::EType asset_type = LLAssetType::AT_NONE); static void show(LLUUID item_id); BOOL postBuild(void); 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 onCommitColumnCount(LLUICtrl *control, void *user_data); void handleSizing(); + void readVFile(); LLInventoryItem* mItem; + LLUUID mAssetId; + LLAssetType::EType mAssetType; + BOOL mVFS; DOHexEditor* mEditor; static std::list sInstances; private: diff --git a/indra/newview/llfloatervfsexplorer.cpp b/indra/newview/llfloatervfsexplorer.cpp index 395d7c280..6adb0a475 100644 --- a/indra/newview/llfloatervfsexplorer.cpp +++ b/indra/newview/llfloatervfsexplorer.cpp @@ -1,4 +1,5 @@ // +//A lot of bad things going on in here, needs a rewrite. #include "llviewerprecompiledheaders.h" #include "llfloatervfsexplorer.h" #include "lluictrlfactory.h" @@ -9,6 +10,7 @@ #include "lllocalinventory.h" #include "llviewerwindow.h" #include "llassetconverter.h" +#include "dohexeditor.h" LLFloaterVFSExplorer* LLFloaterVFSExplorer::sInstance; std::map LLFloaterVFSExplorer::sVFSFileMap; @@ -67,6 +69,7 @@ void LLFloaterVFSExplorer::refresh() void LLFloaterVFSExplorer::reloadAll() { //get our magic from gvfs here + //this should re-request all assets from the server if possible. refresh(); } void LLFloaterVFSExplorer::setEditID(LLUUID edit_id) @@ -169,4 +172,16 @@ void LLFloaterVFSExplorer::onClickReload(void* user_data) LLFloaterVFSExplorer* floaterp = (LLFloaterVFSExplorer*)user_data; floaterp->reloadAll(); } +// static +void LLFloaterVFSExplorer::onClickEditData(void* user_data) +{ + LLVFSFileSpecifier file; + std::map::iterator end = sVFSFileMap.end(); + for(std::map::iterator iter = sVFSFileMap.begin(); iter != end; ++iter) + { + if((*iter).first.mFileID == mEditID) + file = (*iter).first; + } + DOHexEditor::showVFS(file.mFileID, file.mFileType); +} // diff --git a/indra/newview/llfloatervfsexplorer.h b/indra/newview/llfloatervfsexplorer.h index aa92de7c9..c945beb52 100644 --- a/indra/newview/llfloatervfsexplorer.h +++ b/indra/newview/llfloatervfsexplorer.h @@ -1,39 +1,40 @@ -// -#ifndef LL_LLFLOATERVFSEXPLORER_H -#define LL_LLFLOATERVFSEXPLORER_H - -#include "llfloater.h" -#include "llassettype.h" -#include "llvfs.h" - -class LLFloaterVFSExplorer : LLFloater -{ -typedef struct -{ - std::string mFilename; - std::string mName; - LLUUID mID; - LLAssetType::EType mType; -} entry; -public: - LLFloaterVFSExplorer(); - ~LLFloaterVFSExplorer(); - static void show(); - BOOL postBuild(); - void refresh(); - void reloadAll(); - void removeEntry(); - void setEditID(LLUUID edit_id); - LLVFSFileSpecifier getEditEntry(); - static void onCommitFileList(LLUICtrl* ctrl, void* user_data); - static void onClickCopyUUID(void* user_data); - static void onClickRemove(void* user_data); - static void onClickReload(void* user_data); -private: - static LLFloaterVFSExplorer* sInstance; - static std::map sVFSFileMap; - LLUUID mEditID; - void setEditEnabled(bool enabled); -}; -#endif -// +// +#ifndef LL_LLFLOATERVFSEXPLORER_H +#define LL_LLFLOATERVFSEXPLORER_H + +#include "llfloater.h" +#include "llassettype.h" +#include "llvfs.h" + +class LLFloaterVFSExplorer : LLFloater +{ +typedef struct +{ + std::string mFilename; + std::string mName; + LLUUID mID; + LLAssetType::EType mType; +} entry; +public: + LLFloaterVFSExplorer(); + ~LLFloaterVFSExplorer(); + static void show(); + BOOL postBuild(); + void refresh(); + void reloadAll(); + void removeEntry(); + void setEditID(LLUUID edit_id); + LLVFSFileSpecifier getEditEntry(); + static void onCommitFileList(LLUICtrl* ctrl, void* user_data); + static void onClickCopyUUID(void* user_data); + static void onClickRemove(void* user_data); + static void onClickReload(void* user_data); + static void onClickEditData(void* user_data); +private: + static LLFloaterVFSExplorer* sInstance; + static std::map sVFSFileMap; + LLUUID mEditID; + void setEditEnabled(bool enabled); +}; +#endif +//