* move userinfo for inventory archiving up to module class so that it only has to be done once
parent
e7427f21bd
commit
f74326c1b0
|
@ -48,8 +48,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
|
|||
protected TarArchiveReader archive;
|
||||
private static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding();
|
||||
|
||||
private string m_firstName;
|
||||
private string m_lastName;
|
||||
private CachedUserInfo m_userInfo;
|
||||
private string m_invPath;
|
||||
|
||||
/// <value>
|
||||
|
@ -60,10 +59,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
|
|||
CommunicationsManager commsManager;
|
||||
|
||||
public InventoryArchiveReadRequest(
|
||||
string firstName, string lastName, string invPath, string loadPath, CommunicationsManager commsManager)
|
||||
CachedUserInfo userInfo, string invPath, string loadPath, CommunicationsManager commsManager)
|
||||
: this(
|
||||
firstName,
|
||||
lastName,
|
||||
userInfo,
|
||||
invPath,
|
||||
new GZipStream(new FileStream(loadPath, FileMode.Open), CompressionMode.Decompress),
|
||||
commsManager)
|
||||
|
@ -71,10 +69,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
|
|||
}
|
||||
|
||||
public InventoryArchiveReadRequest(
|
||||
string firstName, string lastName, string invPath, Stream loadStream, CommunicationsManager commsManager)
|
||||
CachedUserInfo userInfo, string invPath, Stream loadStream, CommunicationsManager commsManager)
|
||||
{
|
||||
m_firstName = firstName;
|
||||
m_lastName = lastName;
|
||||
m_userInfo = userInfo;
|
||||
m_invPath = invPath;
|
||||
m_loadStream = loadStream;
|
||||
this.commsManager = commsManager;
|
||||
|
@ -174,33 +171,16 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
|
|||
int successfulItemRestores = 0;
|
||||
List<InventoryNodeBase> nodesLoaded = new List<InventoryNodeBase>();
|
||||
|
||||
UserProfileData userProfile = commsManager.UserService.GetUserProfile(m_firstName, m_lastName);
|
||||
if (null == userProfile)
|
||||
{
|
||||
m_log.ErrorFormat("[INVENTORY ARCHIVER]: Failed to find user {0} {1}", m_firstName, m_lastName);
|
||||
return nodesLoaded;
|
||||
}
|
||||
|
||||
CachedUserInfo userInfo = commsManager.UserProfileCacheService.GetUserDetails(userProfile.ID);
|
||||
if (null == userInfo)
|
||||
if (!m_userInfo.HasReceivedInventory)
|
||||
{
|
||||
m_log.ErrorFormat(
|
||||
"[INVENTORY ARCHIVER]: Failed to find user info for {0} {1} {2}",
|
||||
m_firstName, m_lastName, userProfile.ID);
|
||||
"[INVENTORY ARCHIVER]: Have not yet received inventory info for user {0} {1}",
|
||||
m_userInfo.UserProfile.Name, m_userInfo.UserProfile.ID);
|
||||
|
||||
return nodesLoaded;
|
||||
}
|
||||
|
||||
if (!userInfo.HasReceivedInventory)
|
||||
{
|
||||
m_log.ErrorFormat(
|
||||
"[INVENTORY ARCHIVER]: Have not yet received inventory info for user {0} {1} {2}",
|
||||
m_firstName, m_lastName, userProfile.ID);
|
||||
|
||||
return nodesLoaded;
|
||||
}
|
||||
|
||||
InventoryFolderImpl inventoryFolder = userInfo.RootFolder.FindFolderByPath(m_invPath);
|
||||
InventoryFolderImpl inventoryFolder = m_userInfo.RootFolder.FindFolderByPath(m_invPath);
|
||||
|
||||
if (null == inventoryFolder)
|
||||
{
|
||||
|
@ -232,15 +212,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
|
|||
|
||||
if (item != null)
|
||||
{
|
||||
item.Creator = userProfile.ID;
|
||||
item.Owner = userProfile.ID;
|
||||
item.Creator = m_userInfo.UserProfile.ID;
|
||||
item.Owner = m_userInfo.UserProfile.ID;
|
||||
|
||||
// Reset folder ID to the one in which we want to load it
|
||||
// TODO: Properly restore entire folder structure. At the moment all items are dumped in this
|
||||
// single folder no matter where in the saved folder structure they are.
|
||||
item.Folder = inventoryFolder.ID;
|
||||
|
||||
userInfo.AddItem(item);
|
||||
m_userInfo.AddItem(item);
|
||||
successfulItemRestores++;
|
||||
nodesLoaded.Add(item);
|
||||
}
|
||||
|
|
|
@ -48,8 +48,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
|
|||
protected CommunicationsManager commsManager;
|
||||
protected Dictionary<UUID, int> assetUuids = new Dictionary<UUID, int>();
|
||||
|
||||
private string m_firstName;
|
||||
private string m_lastName;
|
||||
private CachedUserInfo m_userInfo;
|
||||
private string m_invPath;
|
||||
|
||||
/// <value>
|
||||
|
@ -61,13 +60,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
|
|||
/// Constructor
|
||||
/// </summary>
|
||||
public InventoryArchiveWriteRequest(
|
||||
string firstName, string lastName, string invPath, string savePath, CommunicationsManager commsManager)
|
||||
CachedUserInfo userInfo, string invPath, string savePath, CommunicationsManager commsManager)
|
||||
: this(
|
||||
firstName,
|
||||
lastName,
|
||||
invPath,
|
||||
new GZipStream(new FileStream(savePath, FileMode.Create), CompressionMode.Compress),
|
||||
commsManager)
|
||||
userInfo,
|
||||
invPath,
|
||||
new GZipStream(new FileStream(savePath, FileMode.Create), CompressionMode.Compress),
|
||||
commsManager)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -75,10 +73,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
|
|||
/// Constructor
|
||||
/// </summary>
|
||||
public InventoryArchiveWriteRequest(
|
||||
string firstName, string lastName, string invPath, Stream saveStream, CommunicationsManager commsManager)
|
||||
CachedUserInfo userInfo, string invPath, Stream saveStream, CommunicationsManager commsManager)
|
||||
{
|
||||
m_firstName = firstName;
|
||||
m_lastName = lastName;
|
||||
m_userInfo = userInfo;
|
||||
m_invPath = invPath;
|
||||
m_saveStream = saveStream;
|
||||
this.commsManager = commsManager;
|
||||
|
@ -183,26 +180,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
|
|||
|
||||
public void Execute()
|
||||
{
|
||||
UserProfileData userProfile = commsManager.UserService.GetUserProfile(m_firstName, m_lastName);
|
||||
if (null == userProfile)
|
||||
{
|
||||
m_log.ErrorFormat("[INVENTORY ARCHIVER]: Failed to find user {0} {1}", m_firstName, m_lastName);
|
||||
return;
|
||||
}
|
||||
|
||||
CachedUserInfo userInfo = commsManager.UserProfileCacheService.GetUserDetails(userProfile.ID);
|
||||
if (null == userInfo)
|
||||
{
|
||||
m_log.ErrorFormat(
|
||||
"[INVENTORY ARCHIVER]: Failed to find user info for {0} {1} {2}",
|
||||
m_firstName, m_lastName, userProfile.ID);
|
||||
return;
|
||||
}
|
||||
|
||||
InventoryFolderImpl inventoryFolder = null;
|
||||
InventoryItemBase inventoryItem = null;
|
||||
|
||||
if (userInfo.HasReceivedInventory)
|
||||
if (m_userInfo.HasReceivedInventory)
|
||||
{
|
||||
// Eliminate double slashes and any leading / on the path. This might be better done within InventoryFolderImpl
|
||||
// itself (possibly at a small loss in efficiency).
|
||||
|
@ -218,25 +199,25 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
|
|||
// Therefore if we still start with a / after the split, then we need the root folder
|
||||
if (m_invPath.Length == 0)
|
||||
{
|
||||
inventoryFolder = userInfo.RootFolder;
|
||||
inventoryFolder = m_userInfo.RootFolder;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_invPath = m_invPath.Remove(m_invPath.LastIndexOf(InventoryFolderImpl.PATH_DELIMITER));
|
||||
inventoryFolder = userInfo.RootFolder.FindFolderByPath(m_invPath);
|
||||
inventoryFolder = m_userInfo.RootFolder.FindFolderByPath(m_invPath);
|
||||
}
|
||||
|
||||
// The path may point to an item instead
|
||||
if (inventoryFolder == null)
|
||||
{
|
||||
inventoryItem = userInfo.RootFolder.FindItemByPath(m_invPath);
|
||||
inventoryItem = m_userInfo.RootFolder.FindItemByPath(m_invPath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.ErrorFormat(
|
||||
"[INVENTORY ARCHIVER]: Have not yet received inventory info for user {0} {1} {2}",
|
||||
m_firstName, m_lastName, userProfile.ID);
|
||||
"[INVENTORY ARCHIVER]: Have not yet received inventory info for user {0} {1}",
|
||||
m_userInfo.UserProfile.Name, m_userInfo.UserProfile.ID);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ using Nini.Config;
|
|||
using OpenMetaverse;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Framework.Communications;
|
||||
using OpenSim.Framework.Communications.Cache;
|
||||
using OpenSim.Region.Framework.Interfaces;
|
||||
using OpenSim.Region.Framework.Scenes;
|
||||
|
||||
|
@ -85,22 +86,22 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
|
|||
m_scenes[scene.RegionInfo.RegionID] = scene;
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
public void PostInitialise() {}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
public void Close() {}
|
||||
|
||||
public void DearchiveInventory(string firstName, string lastName, string invPath, Stream loadStream)
|
||||
{
|
||||
if (m_scenes.Count > 0)
|
||||
{
|
||||
InventoryArchiveReadRequest request =
|
||||
new InventoryArchiveReadRequest(firstName, lastName, invPath, loadStream, m_commsManager);
|
||||
CachedUserInfo userInfo = GetUserInfo(firstName, lastName);
|
||||
|
||||
UpdateClientWithLoadedNodes(firstName, lastName, request.Execute());
|
||||
if (userInfo != null)
|
||||
{
|
||||
InventoryArchiveReadRequest request =
|
||||
new InventoryArchiveReadRequest(userInfo, invPath, loadStream, m_commsManager);
|
||||
UpdateClientWithLoadedNodes(userInfo, request.Execute());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,7 +109,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
|
|||
{
|
||||
if (m_scenes.Count > 0)
|
||||
{
|
||||
new InventoryArchiveWriteRequest(firstName, lastName, invPath, saveStream, m_commsManager).Execute();
|
||||
CachedUserInfo userInfo = GetUserInfo(firstName, lastName);
|
||||
|
||||
if (userInfo != null)
|
||||
new InventoryArchiveWriteRequest(userInfo, invPath, saveStream, m_commsManager).Execute();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,10 +120,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
|
|||
{
|
||||
if (m_scenes.Count > 0)
|
||||
{
|
||||
InventoryArchiveReadRequest request =
|
||||
new InventoryArchiveReadRequest(firstName, lastName, invPath, loadPath, m_commsManager);
|
||||
CachedUserInfo userInfo = GetUserInfo(firstName, lastName);
|
||||
|
||||
UpdateClientWithLoadedNodes(firstName, lastName, request.Execute());
|
||||
if (userInfo != null)
|
||||
{
|
||||
InventoryArchiveReadRequest request =
|
||||
new InventoryArchiveReadRequest(userInfo, invPath, loadPath, m_commsManager);
|
||||
UpdateClientWithLoadedNodes(userInfo, request.Execute());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,7 +135,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
|
|||
{
|
||||
if (m_scenes.Count > 0)
|
||||
{
|
||||
new InventoryArchiveWriteRequest(firstName, lastName, invPath, savePath, m_commsManager).Execute();
|
||||
CachedUserInfo userInfo = GetUserInfo(firstName, lastName);
|
||||
|
||||
if (userInfo != null)
|
||||
new InventoryArchiveWriteRequest(userInfo, invPath, savePath, m_commsManager).Execute();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,23 +184,46 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
|
|||
ArchiveInventory(firstName, lastName, invPath, savePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get user information for the given name.
|
||||
/// </summary>
|
||||
/// <param name="firstName"></param>
|
||||
/// <param name="lastName"></param>
|
||||
/// <returns></returns>
|
||||
protected CachedUserInfo GetUserInfo(string firstName, string lastName)
|
||||
{
|
||||
UserProfileData userProfile = m_commsManager.UserService.GetUserProfile(firstName, lastName);
|
||||
|
||||
if (null == userProfile)
|
||||
{
|
||||
m_log.ErrorFormat("[INVENTORY ARCHIVER]: Failed to find user {0} {1}", firstName, lastName);
|
||||
return null;
|
||||
}
|
||||
|
||||
CachedUserInfo userInfo = m_commsManager.UserProfileCacheService.GetUserDetails(userProfile.ID);
|
||||
if (null == userInfo)
|
||||
{
|
||||
m_log.ErrorFormat(
|
||||
"[INVENTORY ARCHIVER]: Failed to find user info for {0} {1} {2}",
|
||||
firstName, lastName, userProfile.ID);
|
||||
return null;
|
||||
}
|
||||
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Notify the client of loaded nodes if they are logged in
|
||||
/// </summary>
|
||||
/// <param name="loadedNodes">Can be empty. In which case, nothing happens</param>
|
||||
private void UpdateClientWithLoadedNodes(string firstName, string lastName, List<InventoryNodeBase> loadedNodes)
|
||||
private void UpdateClientWithLoadedNodes(CachedUserInfo userInfo, List<InventoryNodeBase> loadedNodes)
|
||||
{
|
||||
if (loadedNodes.Count == 0)
|
||||
return;
|
||||
|
||||
UserProfileData userProfile = m_commsManager.UserService.GetUserProfile(firstName, lastName);
|
||||
|
||||
if (null == userProfile)
|
||||
return;
|
||||
|
||||
foreach (Scene scene in m_scenes.Values)
|
||||
{
|
||||
ScenePresence user = scene.GetScenePresence(userProfile.ID);
|
||||
ScenePresence user = scene.GetScenePresence(userInfo.UserProfile.ID);
|
||||
|
||||
if (user != null && !user.IsChildAgent)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue