Ejemplo n.º 1
0
// virtual
void LLPreviewNotecard::saveAs()
{
	std::string default_filename("untitled.notecard");
	const LLInventoryItem *item = getItem();
	if(item)
	{
	//	gAssetStorage->getAssetData(item->getAssetUUID(), LLAssetType::AT_NOTECARD, LLPreviewNotecard::gotAssetForSave, this, TRUE);
		default_filename = LLDir::getScrubbedFileName(item->getName());
	}

	LLFilePicker& file_picker = LLFilePicker::instance();
	if( !file_picker.getSaveFile( LLFilePicker::FFSAVE_NOTECARD, default_filename ) )
	{
		// User canceled or we failed to acquire save file.
		return;
	}
	// remember the user-approved/edited file name.
	std::string filename = file_picker.getFirstFile();

	LLViewerTextEditor* editor = getChild<LLViewerTextEditor>("Notecard Editor");

	std::string buffer;
	if (!editor->exportBuffer(buffer))
	{
		// FIXME: Notify the user!
		return;
	}

	S32 size = buffer.length() + 1;

	std::ofstream export_file(filename.c_str(), std::ofstream::binary);
	export_file.write(buffer.c_str(), size);
	export_file.close();
}
//Exports a pick to an XML - RK
void LLPanelPick::exportPick()
{
	LLFilePicker& file_picker = LLFilePicker::instance();
		
	if(!file_picker.getSaveFile(LLFilePicker::FFSAVE_XML))
		return;// User canceled save.

	std::string destination = file_picker.getFirstFile();

	LLSD datas;

	datas["name"] = mNameEditor->getText();
	datas["desc"] = mDescEditor->getText();
	datas["parcelID"] = mParcelID;
	datas["snapshotID"] = mSnapshotCtrl->getImageAssetID();
	datas["globalPos"] = mPosGlobal.getValue();
	datas["locationText"] = mLocationText;

	LLSD file;
	LLSD header;
	header["Version"] = 2;
	file["Header"] = header;
	std::string grid_uri = gHippoGridManager->getConnectedGrid()->getLoginUri();
	//LLStringUtil::toLower(uris[0]);
	file["Grid"] = grid_uri;
	file["Data"] = datas;

	// Create a file stream and write to it
	llofstream export_file(destination);
	LLSDSerialize::toPrettyXML(file, export_file);
	// Open the file save dialog
	export_file.close();
}
Ejemplo n.º 3
0
// static
void LLPreviewSound::gotAssetForSave(LLVFS *vfs,
									   const LLUUID& asset_uuid,
									   LLAssetType::EType type,
									   void* user_data, S32 status, LLExtStat ext_status)
{
	LLPreviewSound* self = (LLPreviewSound*) user_data;
	//const LLInventoryItem *item = self->getItem();

	LLVFile file(vfs, asset_uuid, type, 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);

	// Write it back out...

	LLFilePicker& file_picker = LLFilePicker::instance();
	if( !file_picker.getSaveFile( LLFilePicker::FFSAVE_OGG, LLDir::getScrubbedFileName(self->getItem()->getName())) )
	{
		// User canceled or we failed to acquire save file.
		return;
	}
	// remember the user-approved/edited file name.
	std::string filename = file_picker.getFirstFile();

	std::ofstream export_file(filename.c_str(), std::ofstream::binary);
	export_file.write(buffer, size);
	export_file.close();
}
Ejemplo n.º 4
0
// static
void LLPreviewAnim::gotAssetForSave_continued(char* buffer, S32 size, AIFilePicker* filepicker)
{
	if (filepicker->hasFilename())
	{
		std::string filename = filepicker->getFilename();
		std::ofstream export_file(filename.c_str(), std::ofstream::binary);
		export_file.write(buffer, size);
		export_file.close();
	}
	delete[] buffer;
}
Ejemplo n.º 5
0
//static
void LLFloaterAO::onClickSave(void* user_data)
{
	LLFilePicker& file_picker = LLFilePicker::instance();
	if(file_picker.getSaveFile( LLFilePicker::FFSAVE_AO, LLDir::getScrubbedFileName("untitled.ao")))
	{
		std::string file_name = file_picker.getFirstFile();
		llofstream export_file(file_name);
		LLSDSerialize::toXML(gSavedPerAccountSettings.getLLSD("AO.Settings"), export_file);
		export_file.close();
	}
}
//static
void LLFloaterBlacklist::saveToDisk()
{
	std::string file_name = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "blacklist_sg1.xml");
	llofstream export_file(file_name);
	LLSD data;
	for(std::map<LLUUID,LLSD>::iterator iter = blacklist_entries.begin(); iter != blacklist_entries.end(); ++iter)
	{
		data[iter->first.asString()] = iter->second;
	}
	LLSDSerialize::toPrettyXML(data, export_file);
	export_file.close();
}
//static
void LLFloaterBlacklist::onClickSave_continued(AIFilePicker* filepicker)
{
	if (filepicker->hasFilename())
	{
		std::string file_name = filepicker->getFilename();
		llofstream export_file(file_name);
		LLSD data;
		for(std::map<LLUUID,LLSD>::iterator iter = blacklist_entries.begin(); iter != blacklist_entries.end(); ++iter)
		{
			data[iter->first.asString()] = iter->second;
		}
		LLSDSerialize::toPrettyXML(data, export_file);	
		export_file.close();
	}
}
//static
void LLFloaterTeleportHistory::saveFile(const std::string &file_name)
{
    LLFloaterTeleportHistory *pFloaterHistory = LLFloaterTeleportHistory::findInstance();
    if(!pFloaterHistory)
        return;

    std::string temp_str = gDirUtilp->getLindenUserDir(true);
    if( temp_str.empty() )
    {
        LL_INFOS() << "Can't save teleport history - no user directory set yet." << LL_ENDL;
        return;
    }
    temp_str += gDirUtilp->getDirDelimiter() + file_name;
    llofstream export_file(temp_str);
    if (!export_file.good())
    {
        LL_WARNS() << "Unable to open " << file_name << " for output." << LL_ENDL;
        return;
    }
    LL_INFOS() << "Writing "<< file_name << " file at " << temp_str << LL_ENDL;

    LLSD elements;
    LLScrollListCtrl* pScrollList = pFloaterHistory->mPlacesList;
    if (pScrollList)
    {
        std::vector<LLScrollListItem*> data_list = pScrollList->getAllData();
        std::sort(data_list.begin(),data_list.end(),SortByAge());//Re-sort. Column sorting may have mucked the list up. Newer entries in front.
        for (std::vector<LLScrollListItem*>::iterator itr = data_list.begin(); itr != data_list.end(); ++itr)
        {
            //Pack into LLSD mimicing one passed to addElement
            LLSD data_entry;
            //id is actually reverse of the indexing of the element LLSD. Higher id = newer.
            data_entry["id"] = pScrollList->getItemCount() - elements.size() - 1;
            for(S32 i = 0; i < (*itr)->getNumColumns(); ++i)
            {
                data_entry["columns"][i]["column"]=pScrollList->getColumn(i)->mName;
                data_entry["columns"][i]["value"]=(*itr)->getColumn(i)->getValue();
            }
            elements.append(data_entry);
        }
    }
    LLSDSerialize::toXML(elements, export_file);
    export_file.close();
}
void LLPreviewNotecard::saveAs_continued(AIFilePicker* filepicker)
{
	if (!filepicker->hasFilename())
		return;

	LLViewerTextEditor* editor = findChild<LLViewerTextEditor>("Notecard Editor");

	std::string buffer;
	if (editor && !editor->exportBuffer(buffer))
	{
		// FIXME: Notify the user!
		return;
	}

	S32 size = buffer.length();

	std::string filename = filepicker->getFilename();
	std::ofstream export_file(filename.c_str(), std::ofstream::binary);
	export_file.write(buffer.c_str(), size);
	export_file.close();
}
void LLObjectBackup::exportWorker(void *userdata)
{	
	LLObjectBackup::getInstance()->updateExportNumbers();

	switch (LLObjectBackup::getInstance()->mExportState)
	{
		case EXPORT_INIT:
			{
				LLObjectBackup::getInstance()->show(true);		
				struct ff : public LLSelectedNodeFunctor
				{
					virtual bool apply(LLSelectNode* node)
					{
						return LLObjectBackup::getInstance()->validatePerms(node->mPermissions);
					}
				} func;

				if (LLSelectMgr::getInstance()->getSelection()->applyToNodes(&func, false))
				{
					LLObjectBackup::getInstance()->mExportState = EXPORT_STRUCTURE;
				}
				else
				{
					LL_WARNS("ObjectBackup") << "Incorrect permission to export" << LL_ENDL;
					LLObjectBackup::getInstance()->mExportState = EXPORT_FAILED;
					LLSelectMgr::getInstance()->getSelection()->unref();
				}
			}
			break;

		case EXPORT_STRUCTURE:
			{
				struct ff : public LLSelectedObjectFunctor
				{
					virtual bool apply(LLViewerObject* object)
					{
						bool is_attachment = object->isAttachment();
						object->boostTexturePriority(TRUE);
						LLViewerObject::child_list_t children = object->getChildren();
						children.push_front(object); //push root onto list
						LLSD prim_llsd = LLObjectBackup::getInstance()->primsToLLSD(children, is_attachment);				
						LLSD stuff;
						if (is_attachment)
						{
							stuff["root_position"] = object->getPositionEdit().getValue();
							stuff["root_rotation"] = ll_sd_from_quaternion(object->getRotationEdit());
						}
						else
						{
							stuff["root_position"] = object->getPosition().getValue();
							stuff["root_rotation"] = ll_sd_from_quaternion(object->getRotation());
						}
						stuff["group_body"] = prim_llsd;
						LLObjectBackup::getInstance()->mLLSD["data"].append(stuff);
						return true;
					}
				} func;

				LLObjectBackup::getInstance()->mExportState = EXPORT_LLSD;
				LLSelectMgr::getInstance()->getSelection()->applyToRootObjects(&func, false);
				LLSelectMgr::getInstance()->getSelection()->unref();
			}
			break;

		case EXPORT_TEXTURES:
			if (LLObjectBackup::getInstance()->mNextTextureReady == false)
				return;

			// Ok we got work to do
			LLObjectBackup::getInstance()->mNextTextureReady = false;

			if (LLObjectBackup::getInstance()->mTexturesList.empty())
			{
				LLObjectBackup::getInstance()->mExportState = EXPORT_DONE;
				return;
			}

			LLObjectBackup::getInstance()->exportNextTexture();
			break;

		case EXPORT_LLSD:
			{
				// Create a file stream and write to it
				llofstream export_file(LLObjectBackup::getInstance()->mFileName);
				LLSDSerialize::toPrettyXML(LLObjectBackup::getInstance()->mLLSD, export_file);
				export_file.close();
				LLObjectBackup::getInstance()->mNextTextureReady = true;	
				LLObjectBackup::getInstance()->mExportState = EXPORT_TEXTURES;
			}
			break;

		case EXPORT_DONE:
			gIdleCallbacks.deleteFunction(exportWorker);
			if (LLObjectBackup::getInstance()->mNonExportedTextures == LLObjectBackup::TEXTURE_OK)
			{
				LL_INFOS("ObjectBackup") << "Export successful and complete." << LL_ENDL;
				LLNotificationsUtil::add("ExportSuccessful");
			}
			else
			{
				LL_INFOS("ObjectBackup") << "Export successful but incomplete: some texture(s) not saved." << LL_ENDL;
				std::string reason;
				if (LLObjectBackup::getInstance()->mNonExportedTextures & LLObjectBackup::TEXTURE_BAD_PERM)
				{
					reason += "\nBad permissions/creator.";
				}
				if (LLObjectBackup::getInstance()->mNonExportedTextures & LLObjectBackup::TEXTURE_MISSING)
				{
					reason += "\nMissing texture (retrying after full rezzing might work).";
				}
				if (LLObjectBackup::getInstance()->mNonExportedTextures & LLObjectBackup::TEXTURE_BAD_ENCODING)
				{
					reason += "\nBad texture encoding.";
				}
				if (LLObjectBackup::getInstance()->mNonExportedTextures & LLObjectBackup::TEXTURE_IS_NULL)
				{
					reason += "\nNull texture.";
				}
				if (LLObjectBackup::getInstance()->mNonExportedTextures & LLObjectBackup::TEXTURE_SAVED_FAILED)
				{
					reason += "\nCould not write to disk.";
				}
				LLSD args;
				args["REASON"] = reason;
				LLNotificationsUtil::add("ExportPartial", args);
			}
			LLObjectBackup::getInstance()->close();
			break;

		case EXPORT_FAILED:
			gIdleCallbacks.deleteFunction(exportWorker);
			LL_WARNS("ObjectBackup") << "Export process aborted." << LL_ENDL;
			LLNotificationsUtil::add("ExportFailed");
			LLObjectBackup::getInstance()->close();
			break;
	}
}
Ejemplo n.º 11
0
LRESULT APIENTRY MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
        case WM_CREATE:
            create_toolbar(hwnd);
            create_term(hwnd);
            create_sysmenu(hwnd);

            return 0;

        case WM_SIZE:
            SendMessage(wndTB, TB_AUTOSIZE, 0, 0);
            get_def_size(LOWORD(lParam), HIWORD(lParam));
            return 0;

        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;

        case WM_COMMAND:
            switch (LOWORD(wParam))
            {
            case BUT_OPEN:
                open_file();
                break;
            case BUT_REWIND:
            but_rewind:
                if (play_state==-1)
                    break;
                EnterCriticalSection(&vt_mutex);
                replay_pause();
                tr.tv_sec=0;
                tr.tv_usec=0;
                set_prog();
                replay_seek();
                LeaveCriticalSection(&vt_mutex);
                play_state=1;
                replay_resume();
                do_replay();
                break;
            case BUT_PAUSE:
                if (play_state==1)
                    goto but_unpause;
            but_pause:
                CancelWaitableTimer(timer);
                replay_pause();
                set_buttons(1);
                break;
            case BUT_PLAY:
                if (play_state>1)
                    goto but_pause;
            but_unpause:
                replay_resume();
                do_replay();
                set_buttons(1);
                break;
            case BUT_SELSTART:
                if (play_state==-1)
                    break;
                get_pos();
                selstart=tr;
                set_prog_sel();
                break;
            case BUT_SELEND:
                if (play_state==-1)
                    break;
                selend=tr;
                set_prog_sel();
                break;
            case BUT_EXPORT:
                if (play_state==-1)
                    break;
                if (tcmp(selstart, selend)>=0)
                    break;
                export_file();
                break;
            }
            return 0;

        case WM_SYSCOMMAND:
            switch (LOWORD(wParam))
            {
            default:
                return DefWindowProc(hwnd, uMsg, wParam, lParam);
            case BUT_FONT:
                choose_font();
            }
            return 0;

        case WM_HSCROLL:
            if ((HANDLE)lParam==wndSpeed)
                speed_scrolled();
            else if ((HANDLE)lParam==wndProg)
                prog_scrolled();
            return 0;

        case WM_KEYDOWN:
            switch (wParam)
            {
            case VK_ADD:
            case 'F':
                adjust_speed(+1);
                break;
            case VK_SUBTRACT:
            case 'S':
                adjust_speed(-1);
                break;
            case '1':
                SendMessage(wndSpeed, TBM_SETPOS, 1, 2);
                speed_scrolled();
                break;
            case 'Q':
                DestroyWindow(wndMain);
                break;
            case 'O':
                open_file();
                break;
            case VK_SPACE:
                switch (play_state)
                {
                case -1:
                    open_file();
                    break;
                case 0:
                    play_state=2;
                    goto but_rewind;
                case 1:
                    goto but_unpause;
                case 2:
                case 3:
                    goto but_pause;
                }
                break;
            case 'R':
                goto but_rewind;
                break;
            case VK_RIGHT:
                adjust_pos(+10);
                break;
            case VK_LEFT:
                adjust_pos(-10);
                break;
            case VK_UP:
                adjust_pos(+60);
                break;
            case VK_DOWN:
                adjust_pos(-60);
                break;
            case VK_PRIOR:
                adjust_pos(+600);
                break;
            case VK_NEXT:
                adjust_pos(-600);
                break;
            }
            return 0;

        case WM_SIZING:
            constrain_size((LPRECT)lParam);
            return 1;

        default:
            return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }
    return 0;
}
Ejemplo n.º 12
0
int
main(int argc, char *argv[])
{
    int c;
    gboolean repair = FALSE;
    gboolean esync = FALSE;
    char *export_path = NULL;

#ifdef WIN32
    argv = get_argv_utf8 (&argc);
#endif

    config_dir = DEFAULT_CONFIG_DIR;

    while ((c = getopt_long(argc, argv,
                short_opts, long_opts, NULL)) != EOF) {
        switch (c) {
        case 'h':
            usage();
            exit(0);
        case 'v':
            exit(-1);
            break;
        case 'r':
            repair = TRUE;
            break;
        case 'e':
            esync = TRUE;
            break;
        case 'E':
            export_path = strdup(optarg);
            break;
        case 'c':
            config_dir = strdup(optarg);
            break;
        case 'd':
            seafile_dir = strdup(optarg);
            break;
        default:
            usage();
            exit(-1);
        }
    }

#if !GLIB_CHECK_VERSION(2, 35, 0)
    g_type_init();
#endif

    if (seafile_log_init ("-", "info", "debug") < 0) {
        seaf_warning ("Failed to init log.\n");
        exit (1);
    }

    ccnet_client = ccnet_client_new();
    if ((ccnet_client_load_confdir(ccnet_client, config_dir)) < 0) {
        seaf_warning ("Read config dir error\n");
        return -1;
    }

    if (seafile_dir == NULL)
        seafile_dir = g_build_filename (config_dir, "seafile-data", NULL);

#ifdef __linux__
    uid_t current_user, seafile_user;
    if (!check_user (seafile_dir, &current_user, &seafile_user)) {
        seaf_message ("Current user (%u) is not the user for running "
                      "seafile server (%u). Unable to run fsck.\n",
                      current_user, seafile_user);
        exit(1);
    }
#endif
    
    seaf = seafile_session_new(seafile_dir, ccnet_client);
    if (!seaf) {
        seaf_warning ("Failed to create seafile session.\n");
        exit (1);
    }

    GList *repo_id_list = NULL;
    int i;
    for (i = optind; i < argc; i++)
        repo_id_list = g_list_append (repo_id_list, g_strdup(argv[i]));

    if (export_path) {
        export_file (repo_id_list, seafile_dir, export_path);
    } else {
        seaf_fsck (repo_id_list, repair, esync);
    }

    return 0;
}
//static
void LLObjectBackup::exportWorker(void *userdata)
{	
	LLObjectBackup* self = findInstance();
	if (!self)
	{
		gIdleCallbacks.deleteFunction(exportWorker);
		LL_WARNS() << "Export process aborted. LLObjectBackup instance gone !"
				<< LL_ENDL;
		LLNotifications::instance().add("ExportAborted");
		return;
	}

	self->updateExportNumbers();

	switch (self->mExportState)
	{
		case EXPORT_INIT:
		{
			self->showFloater(true);
			//LLSelectMgr::getInstance()->getSelection()->ref(); // Singu Note: Don't do this.
			// Fall through to EXPORT_CHECK_PERMS
		}
		case EXPORT_CHECK_PERMS:
		{
			struct ff : public LLSelectedNodeFunctor
			{
				virtual bool apply(LLSelectNode* node)
				{
					return LLObjectBackup::validateNode(node);
				}
			} func;

			LLViewerObject* object;
			object = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
			if (object)
			{
				if (LLSelectMgr::getInstance()->getSelection()->applyToNodes(&func, false))
				{
					self->mExportState = EXPORT_FETCH_PHYSICS;
				}
				else
				{
					struct vv : public LLSelectedNodeFunctor
					{
						virtual bool apply(LLSelectNode* node)
						{
							return node->mValid;
						}
					} func2;

					if (LLSelectMgr::getInstance()->getSelection()->applyToNodes(&func2, false))
					{
						LL_WARNS() << "Incorrect permission to export" << LL_ENDL;
						self->mExportState = EXPORT_FAILED;
						LLSelectMgr::getInstance()->getSelection()->unref();
					}
					else
					{
						LL_DEBUGS("ObjectBackup") << "Nodes permissions not yet received, delaying..."
												  << LL_ENDL;
						self->mExportState = EXPORT_CHECK_PERMS;
					}
				}
			}
			else
			{
				self->mExportState = EXPORT_ABORTED;
				LLSelectMgr::getInstance()->getSelection()->unref();
			}
			break;
		}

		case EXPORT_FETCH_PHYSICS:
		{
			// Don't bother to try and fetch the extra physics flags if we
			// don't have sim support for them...
			if (!self->mGotExtraPhysics)
			{
				self->mExportState = EXPORT_STRUCTURE;
				break;
			}

			struct ff : public LLSelectedNodeFunctor
			{
				virtual bool apply(LLSelectNode* node)
				{
					LLViewerObject* object = node->getObject();
					return gObjectList.gotObjectPhysicsFlags(object);
				}
			} func;

			LLViewerObject* object = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
			if (object)
			{
				if (LLSelectMgr::getInstance()->getSelection()->applyToNodes(&func, false))
				{
					self->mExportState = EXPORT_STRUCTURE;
				}
				else
				{
					LL_DEBUGS("ObjectBackup") << "Nodes physics not yet received, delaying..."
											  << LL_ENDL;
				}
			}
			else
			{
				self->mExportState = EXPORT_ABORTED;
				LLSelectMgr::getInstance()->getSelection()->unref();
			}
			break;
		}

		case EXPORT_STRUCTURE:
		{
			struct ff : public LLSelectedObjectFunctor
			{
				virtual bool apply(LLViewerObject* object)
				{
					bool is_attachment = object->isAttachment();
					object->boostTexturePriority(true);
					LLViewerObject::child_list_t children = object->getChildren();
					children.push_front(object); //push root onto list
					LLObjectBackup* self = findInstance();
					LLSD prim_llsd = self->primsToLLSD(children,
													   is_attachment);
					LLSD stuff;
					if (is_attachment)
					{
						stuff["root_position"] = object->getPositionEdit().getValue();
						stuff["root_rotation"] = ll_sd_from_quaternion(object->getRotationEdit());
					}
					else
					{
						stuff["root_position"] = object->getPosition().getValue();
						stuff["root_rotation"] = ll_sd_from_quaternion(object->getRotation());
					}
					stuff["group_body"] = prim_llsd;
					self->mLLSD["data"].append(stuff);
					return true;
				}
			} func;

			LLViewerObject* object;
			object = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
			if (object)
			{
				self->mExportState = EXPORT_LLSD;
				LLSelectMgr::getInstance()->getSelection()->applyToRootObjects(&func, false);
			}
			else
			{
				self->mExportState = EXPORT_ABORTED;
			}
			LLSelectMgr::getInstance()->getSelection()->unref();
			break;
		}

		case EXPORT_TEXTURES:
		{
			if (!self->mCheckNextTexture)
			{
				// The texture is being fetched. Wait till next idle callback.
				return;
			}

			if (self->mTexturesList.empty())
			{
				self->mExportState = EXPORT_DONE;
				return;
			}

			// Ok, we got work to do...
			self->mCheckNextTexture = false;
			self->exportNextTexture();
			break;
		}

		case EXPORT_LLSD:
		{
			// Create a file stream and write to it
			llofstream export_file(self->mFileName);
			LLSDSerialize::toPrettyXML(self->mLLSD, export_file);
			export_file.close();
			self->mCheckNextTexture = true;
			self->mExportState = EXPORT_TEXTURES;
			break;
		}

		case EXPORT_DONE:
		{
			gIdleCallbacks.deleteFunction(exportWorker);
			if (self->mNonExportedTextures == LLObjectBackup::TEXTURE_OK)
			{
				LL_INFOS() << "Export successful and complete." << LL_ENDL;
				LLNotificationsUtil::add("ExportSuccessful");
			}
			else
			{
				LL_INFOS() << "Export successful but incomplete: some texture(s) not saved."
						<< LL_ENDL;
				std::string reason;
				U32 error_bits_map = self->mNonExportedTextures;
				if (error_bits_map & LLObjectBackup::TEXTURE_BAD_PERM)
				{
					reason += "\nBad permissions/creator.";
				}
				if (error_bits_map & LLObjectBackup::TEXTURE_MISSING)
				{
					reason += "\nMissing texture (retrying after full rezzing might work).";
				}
				if (error_bits_map & LLObjectBackup::TEXTURE_BAD_ENCODING)
				{
					reason += "\nBad texture encoding.";
				}
				if (error_bits_map & LLObjectBackup::TEXTURE_IS_NULL)
				{
					reason += "\nNull texture.";
				}
				if (error_bits_map & LLObjectBackup::TEXTURE_SAVED_FAILED)
				{
					reason += "\nCould not write to disk.";
				}
				LLSD args;
				args["REASON"] = reason;
				LLNotificationsUtil::add("ExportPartial", args);
			}
			self->destroy();
			break;
		}

		case EXPORT_FAILED:
		{
			gIdleCallbacks.deleteFunction(exportWorker);
			LL_WARNS() << "Export process failed." << LL_ENDL;
			LLNotificationsUtil::add("ExportFailed");
			self->destroy();
			break;
		}

		case EXPORT_ABORTED:
		{
			gIdleCallbacks.deleteFunction(exportWorker);
			LL_WARNS() << "Export process aborted." << LL_ENDL;
			LLNotificationsUtil::add("ExportAborted");
			self->destroy();
			break;
		}
	}
}
void primbackup::exportworker(void *userdata)
{	
	primbackup::getInstance()->updateexportnumbers();

	switch(primbackup::getInstance()->export_state)
	{
		case EXPORT_INIT: {
			primbackup::getInstance()->show();		
			LLSelectMgr::getInstance()->getSelection()->ref();

			struct ff : public LLSelectedNodeFunctor
			{
				virtual bool apply(LLSelectNode* node)
				{
					return primbackup::check_perms( node );
				}
			} func;

			if(LLSelectMgr::getInstance()->getSelection()->applyToNodes(&func,false))
			{
				if(gHippoGridManager->getConnectedGrid()->isSecondLife())
				{
					LLNotifications::instance().add("NoTextureExportSL");
				}
				primbackup::getInstance()->export_state=EXPORT_STRUCTURE;
			}
			else
			{
				llwarns << "Incorrect permission to export" << llendl;
				primbackup::getInstance()->export_state=EXPORT_DONE;
				primbackup::getInstance()->close();
				gIdleCallbacks.deleteFunction(exportworker);
				LLSelectMgr::getInstance()->getSelection()->unref();
			}
			break;
		}

		case EXPORT_STRUCTURE: {
			struct ff : public LLSelectedObjectFunctor
			{
				virtual bool apply(LLViewerObject* object)
				{
					object->boostTexturePriority(TRUE);
					LLViewerObject::child_list_t children = object->getChildren();
					children.push_front(object); //push root onto list
					LLSD prim_llsd=primbackup::getInstance()->prims_to_llsd(children);
					LLSD stuff;
					stuff["root_position"] = object->getPosition().getValue();
					stuff["root_rotation"] = ll_sd_from_quaternion(object->getRotation());
					stuff["group_body"] = prim_llsd;
					primbackup::getInstance()->llsd["data"].append(stuff);
					return true;
				}
			} func;

			primbackup::getInstance()->export_state=EXPORT_LLSD;
			LLSelectMgr::getInstance()->getSelection()->applyToRootObjects(&func,false);
			LLSelectMgr::getInstance()->getSelection()->unref();

			break;
		}

		case EXPORT_TEXTURES: {
			// Exporting object textures (or other content) from Second Life
			// without checking creator is a violation of the Second Life
			// Policy on Third-Party Viewers and Terms of Service.
			if(gHippoGridManager->getConnectedGrid()->isSecondLife())
			{
				primbackup::getInstance()->export_state=EXPORT_DONE;
				return;
			}

			if(primbackup::getInstance()->m_nexttextureready==false)
				return;

			//Ok we got work to do
			primbackup::getInstance()->m_nexttextureready=false;

			if(primbackup::getInstance()->textures.empty())
			{
				primbackup::getInstance()->export_state=EXPORT_DONE;
				return;
			}

			primbackup::getInstance()->export_next_texture();
			break;
		}

		case EXPORT_LLSD: {
			// Create a file stream and write to it
			llofstream export_file(primbackup::getInstance()->file_name);
			LLSDSerialize::toPrettyXML(primbackup::getInstance()->llsd, export_file);
			export_file.close();
			primbackup::getInstance()->m_nexttextureready=true;	
			primbackup::getInstance()->export_state=EXPORT_TEXTURES;
			break;
		}

		case EXPORT_DONE: {
			llinfos << "Backup complete" << llendl;
			gIdleCallbacks.deleteFunction(exportworker);
			primbackup::getInstance()->close();
			break;
		}
	}
}