2008-09-29 14:55:26 +00:00
/ *
* Copyright ( c ) Contributors , http : //opensimulator.org/
* See CONTRIBUTORS . TXT for a full list of copyright holders .
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions are met :
* * Redistributions of source code must retain the above copyright
* notice , this list of conditions and the following disclaimer .
* * Redistributions in binary form must reproduce the above copyright
* notice , this list of conditions and the following disclaimer in the
* documentation and / or other materials provided with the distribution .
2009-06-01 06:37:14 +00:00
* * Neither the name of the OpenSimulator Project nor the
2008-09-29 14:55:26 +00:00
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission .
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ` ` AS IS ' ' AND ANY
* EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED . IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES
* ( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ;
* LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
* ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
* /
2009-02-12 18:59:45 +00:00
using System ;
using System.Collections.Generic ;
using System.IO ;
using System.IO.Compression ;
using System.Reflection ;
2009-06-11 20:50:23 +00:00
using System.Threading ;
2009-02-12 18:59:45 +00:00
using System.Text ;
using System.Xml ;
using log4net ;
using OpenMetaverse ;
using OpenSim.Framework ;
using OpenSim.Framework.Communications ;
2009-05-04 17:32:20 +00:00
using OpenSim.Framework.Communications.Osp ;
using OpenSim.Framework.Serialization ;
using OpenSim.Framework.Serialization.External ;
2009-02-12 18:59:45 +00:00
using OpenSim.Region.CoreModules.World.Archiver ;
2009-09-06 19:16:56 +00:00
using OpenSim.Region.Framework.Scenes ;
2009-05-15 05:00:25 +00:00
using OpenSim.Services.Interfaces ;
2009-02-12 18:59:45 +00:00
2009-02-10 13:10:57 +00:00
namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
2008-09-29 14:55:26 +00:00
{
public class InventoryArchiveReadRequest
{
2008-12-03 05:18:28 +00:00
private static readonly ILog m_log = LogManager . GetLogger ( MethodBase . GetCurrentMethod ( ) . DeclaringType ) ;
2009-02-04 00:01:36 +00:00
2010-12-11 02:44:37 +00:00
/// <summary>
/// The maximum major version of archive that we can read. Minor versions shouldn't need a max number since version
/// bumps here should be compatible.
/// </summary>
public static int MAX_MAJOR_VERSION = 0 ;
2008-09-29 14:55:26 +00:00
protected TarArchiveReader archive ;
2008-10-19 18:19:18 +00:00
2010-01-10 18:40:07 +00:00
private UserAccount m_userInfo ;
2009-02-11 18:46:51 +00:00
private string m_invPath ;
2009-03-12 06:04:17 +00:00
2009-09-06 19:16:56 +00:00
/// <value>
/// We only use this to request modules
/// </value>
2009-09-30 16:00:09 +00:00
protected Scene m_scene ;
2009-09-06 19:16:56 +00:00
2009-02-11 18:46:51 +00:00
/// <value>
/// The stream from which the inventory archive will be loaded.
/// </value>
private Stream m_loadStream ;
2009-03-12 06:04:17 +00:00
2009-02-11 18:46:51 +00:00
public InventoryArchiveReadRequest (
2010-01-10 18:40:07 +00:00
Scene scene , UserAccount userInfo , string invPath , string loadPath )
2009-02-11 18:46:51 +00:00
: this (
2009-09-06 19:16:56 +00:00
scene ,
2009-02-12 17:41:09 +00:00
userInfo ,
2009-03-12 06:04:17 +00:00
invPath ,
2010-05-28 19:07:15 +00:00
new GZipStream ( ArchiveHelpers . GetStream ( loadPath ) , CompressionMode . Decompress ) )
2008-09-29 14:55:26 +00:00
{
}
2009-03-12 06:04:17 +00:00
2009-02-11 18:46:51 +00:00
public InventoryArchiveReadRequest (
2010-01-10 18:40:07 +00:00
Scene scene , UserAccount userInfo , string invPath , Stream loadStream )
2009-02-11 18:46:51 +00:00
{
2009-09-06 19:16:56 +00:00
m_scene = scene ;
2009-02-12 17:41:09 +00:00
m_userInfo = userInfo ;
2009-02-11 18:46:51 +00:00
m_invPath = invPath ;
2009-03-12 06:04:17 +00:00
m_loadStream = loadStream ;
}
2008-09-29 14:55:26 +00:00
2009-02-11 20:24:41 +00:00
/// <summary>
/// Execute the request
/// </summary>
/// <returns>
/// A list of the inventory nodes loaded. If folders were loaded then only the root folders are
/// returned
/// </returns>
public List < InventoryNodeBase > Execute ( )
2008-09-29 14:55:26 +00:00
{
string filePath = "ERROR" ;
int successfulAssetRestores = 0 ;
int failedAssetRestores = 0 ;
2008-10-19 17:51:42 +00:00
int successfulItemRestores = 0 ;
2010-06-04 23:48:33 +00:00
List < InventoryNodeBase > loadedNodes = new List < InventoryNodeBase > ( ) ;
2009-09-06 21:07:35 +00:00
2010-06-18 15:33:34 +00:00
List < InventoryFolderBase > folderCandidates
2009-09-06 21:07:35 +00:00
= InventoryArchiveUtils . FindFolderByPath (
2010-01-10 18:40:07 +00:00
m_scene . InventoryService , m_userInfo . PrincipalID , m_invPath ) ;
2008-10-19 18:19:18 +00:00
2010-06-18 15:33:34 +00:00
if ( folderCandidates . Count = = 0 )
2008-10-19 18:19:18 +00:00
{
2009-03-04 20:31:03 +00:00
// Possibly provide an option later on to automatically create this folder if it does not exist
2009-02-11 18:46:51 +00:00
m_log . ErrorFormat ( "[INVENTORY ARCHIVER]: Inventory path {0} does not exist" , m_invPath ) ;
2009-02-04 00:01:36 +00:00
2010-06-04 23:48:33 +00:00
return loadedNodes ;
2008-10-19 18:19:18 +00:00
}
2010-06-18 15:33:34 +00:00
InventoryFolderBase rootDestinationFolder = folderCandidates [ 0 ] ;
2009-02-11 18:46:51 +00:00
archive = new TarArchiveReader ( m_loadStream ) ;
2009-03-12 06:04:17 +00:00
2009-03-04 20:31:03 +00:00
// In order to load identically named folders, we need to keep track of the folders that we have already
2010-06-04 23:48:33 +00:00
// resolved
Dictionary < string , InventoryFolderBase > resolvedFolders = new Dictionary < string , InventoryFolderBase > ( ) ;
2008-09-29 14:55:26 +00:00
byte [ ] data ;
2009-01-22 16:43:28 +00:00
TarArchiveReader . TarEntryType entryType ;
2009-11-24 18:27:31 +00:00
try
2008-09-29 14:55:26 +00:00
{
2009-11-24 18:27:31 +00:00
while ( ( data = archive . ReadEntry ( out filePath , out entryType ) ) ! = null )
2009-11-23 02:26:06 +00:00
{
2010-12-11 02:44:37 +00:00
if ( filePath = = ArchiveConstants . CONTROL_FILE_PATH )
{
LoadControlFile ( filePath , data ) ;
}
else if ( filePath . StartsWith ( ArchiveConstants . ASSETS_PATH ) )
2009-11-09 17:04:05 +00:00
{
2009-11-24 18:27:31 +00:00
if ( LoadAsset ( filePath , data ) )
successfulAssetRestores + + ;
else
failedAssetRestores + + ;
if ( ( successfulAssetRestores ) % 50 = = 0 )
m_log . DebugFormat (
"[INVENTORY ARCHIVER]: Loaded {0} assets..." ,
successfulAssetRestores ) ;
}
else if ( filePath . StartsWith ( ArchiveConstants . INVENTORY_PATH ) )
{
2010-06-04 22:34:42 +00:00
filePath = filePath . Substring ( ArchiveConstants . INVENTORY_PATH . Length ) ;
// Trim off the file portion if we aren't already dealing with a directory path
if ( TarArchiveReader . TarEntryType . TYPE_DIRECTORY ! = entryType )
filePath = filePath . Remove ( filePath . LastIndexOf ( "/" ) + 1 ) ;
2009-11-24 18:27:31 +00:00
InventoryFolderBase foundFolder
= ReplicateArchivePathToUserInventory (
2010-06-04 23:48:33 +00:00
filePath , rootDestinationFolder , resolvedFolders , loadedNodes ) ;
2009-11-24 18:27:31 +00:00
if ( TarArchiveReader . TarEntryType . TYPE_DIRECTORY ! = entryType )
2009-11-09 17:04:05 +00:00
{
2009-11-24 18:27:31 +00:00
InventoryItemBase item = LoadItem ( data , foundFolder ) ;
if ( item ! = null )
{
successfulItemRestores + + ;
// If we're loading an item directly into the given destination folder then we need to record
// it separately from any loaded root folders
if ( rootDestinationFolder = = foundFolder )
2010-06-04 23:48:33 +00:00
loadedNodes . Add ( item ) ;
2009-11-24 18:27:31 +00:00
}
2009-11-09 17:04:05 +00:00
}
2008-10-19 17:51:42 +00:00
}
2008-09-29 14:55:26 +00:00
}
}
2009-11-24 18:27:31 +00:00
finally
{
archive . Close ( ) ;
}
2008-09-29 14:55:26 +00:00
2009-11-09 17:17:25 +00:00
m_log . DebugFormat (
"[INVENTORY ARCHIVER]: Successfully loaded {0} assets with {1} failures" ,
successfulAssetRestores , failedAssetRestores ) ;
m_log . InfoFormat ( "[INVENTORY ARCHIVER]: Successfully loaded {0} items" , successfulItemRestores ) ;
2009-03-12 06:04:17 +00:00
2010-06-04 23:48:33 +00:00
return loadedNodes ;
2008-09-29 14:55:26 +00:00
}
2009-12-23 05:00:46 +00:00
public void Close ( )
{
if ( m_loadStream ! = null )
m_loadStream . Close ( ) ;
}
2009-04-24 19:10:13 +00:00
/// <summary>
/// Replicate the inventory paths in the archive to the user's inventory as necessary.
/// </summary>
2010-06-18 16:10:16 +00:00
/// <param name="iarPath">The item archive path to replicate</param>
2009-04-24 19:10:13 +00:00
/// <param name="rootDestinationFolder">The root folder for the inventory load</param>
2010-06-04 23:48:33 +00:00
/// <param name="resolvedFolders">
/// The folders that we have resolved so far for a given archive path.
/// This method will add more folders if necessary
2009-04-24 19:10:13 +00:00
/// </param>
2010-06-04 23:48:33 +00:00
/// <param name="loadedNodes">
/// Track the inventory nodes created.
2009-04-24 19:10:13 +00:00
/// </param>
/// <returns>The last user inventory folder created or found for the archive path</returns>
2009-09-06 21:07:35 +00:00
public InventoryFolderBase ReplicateArchivePathToUserInventory (
2010-06-18 16:10:16 +00:00
string iarPath ,
2009-09-06 21:07:35 +00:00
InventoryFolderBase rootDestFolder ,
2010-06-04 23:48:33 +00:00
Dictionary < string , InventoryFolderBase > resolvedFolders ,
List < InventoryNodeBase > loadedNodes )
2009-04-24 19:10:13 +00:00
{
2010-06-18 16:10:16 +00:00
string iarPathExisting = iarPath ;
2009-04-24 19:10:13 +00:00
2009-11-13 20:24:45 +00:00
// m_log.DebugFormat(
// "[INVENTORY ARCHIVER]: Loading folder {0} {1}", rootDestFolder.Name, rootDestFolder.ID);
2010-06-04 23:48:33 +00:00
2010-06-18 16:10:16 +00:00
InventoryFolderBase destFolder = ResolveDestinationFolder ( rootDestFolder , ref iarPathExisting , resolvedFolders ) ;
2010-06-04 23:48:33 +00:00
2010-07-12 22:00:01 +00:00
// m_log.DebugFormat(
// "[INVENTORY ARCHIVER]: originalArchivePath [{0}], section already loaded [{1}]",
// iarPath, iarPathExisting);
2010-06-04 23:48:33 +00:00
2010-06-18 16:10:16 +00:00
string iarPathToCreate = iarPath . Substring ( iarPathExisting . Length ) ;
CreateFoldersForPath ( destFolder , iarPathExisting , iarPathToCreate , resolvedFolders , loadedNodes ) ;
2010-06-04 23:48:33 +00:00
return destFolder ;
}
/// <summary>
/// Resolve a destination folder
/// </summary>
///
/// We require here a root destination folder (usually the root of the user's inventory) and the archive
/// path. We also pass in a list of previously resolved folders in case we've found this one previously.
///
/// <param name="archivePath">
/// The item archive path to resolve. The portion of the path passed back is that
/// which corresponds to the resolved desintation folder.
/// <param name="rootDestinationFolder">
/// The root folder for the inventory load
/// </param>
/// <param name="resolvedFolders">
/// The folders that we have resolved so far for a given archive path.
/// </param>
/// <returns>
/// The folder in the user's inventory that matches best the archive path given. If no such folder was found
/// then the passed in root destination folder is returned.
/// </returns>
protected InventoryFolderBase ResolveDestinationFolder (
InventoryFolderBase rootDestFolder ,
ref string archivePath ,
Dictionary < string , InventoryFolderBase > resolvedFolders )
2010-06-18 16:37:28 +00:00
{
2010-06-04 23:48:33 +00:00
string originalArchivePath = archivePath ;
2009-04-24 19:10:13 +00:00
2009-09-06 21:07:35 +00:00
InventoryFolderBase destFolder = null ;
2009-04-24 19:10:13 +00:00
2009-09-08 15:29:31 +00:00
if ( archivePath . Length > 0 )
2009-04-24 19:10:13 +00:00
{
2009-09-08 15:29:31 +00:00
while ( null = = destFolder & & archivePath . Length > 0 )
2009-04-24 19:10:13 +00:00
{
2010-07-12 22:00:01 +00:00
// m_log.DebugFormat("[INVENTORY ARCHIVER]: Trying to resolve destination folder {0}", archivePath);
2010-06-18 16:37:28 +00:00
2010-06-04 23:48:33 +00:00
if ( resolvedFolders . ContainsKey ( archivePath ) )
2009-04-24 19:10:13 +00:00
{
2010-07-12 22:00:01 +00:00
// m_log.DebugFormat(
// "[INVENTORY ARCHIVER]: Found previously created folder from archive path {0}", archivePath);
2010-07-12 22:37:08 +00:00
destFolder = resolvedFolders [ archivePath ] ;
2009-04-24 19:10:13 +00:00
}
else
{
2010-06-04 23:48:33 +00:00
// Don't include the last slash so find the penultimate one
2009-09-08 15:29:31 +00:00
int penultimateSlashIndex = archivePath . LastIndexOf ( "/" , archivePath . Length - 2 ) ;
2009-04-24 19:10:13 +00:00
if ( penultimateSlashIndex > = 0 )
{
2010-06-04 23:48:33 +00:00
// Remove the last section of path so that we can see if we've already resolved the parent
2009-09-08 15:29:31 +00:00
archivePath = archivePath . Remove ( penultimateSlashIndex + 1 ) ;
2009-04-24 19:10:13 +00:00
}
else
{
2010-07-12 22:00:01 +00:00
// m_log.DebugFormat(
// "[INVENTORY ARCHIVER]: Found no previously created folder for archive path {0}",
// originalArchivePath);
2009-09-08 15:29:31 +00:00
archivePath = string . Empty ;
2009-09-06 21:07:35 +00:00
destFolder = rootDestFolder ;
2009-04-24 19:10:13 +00:00
}
}
}
}
2010-06-04 23:48:33 +00:00
if ( null = = destFolder )
2009-09-06 21:07:35 +00:00
destFolder = rootDestFolder ;
2010-06-04 23:48:33 +00:00
return destFolder ;
}
/// <summary>
/// Create a set of folders for the given path.
/// </summary>
/// <param name="destFolder">
/// The root folder from which the creation will take place.
/// </param>
2010-06-18 16:10:16 +00:00
/// <param name="iarPathExisting">
/// the part of the iar path that already exists
/// </param>
/// <param name="iarPathToReplicate">
/// The path to replicate in the user's inventory from iar
2010-06-04 23:48:33 +00:00
/// </param>
/// <param name="resolvedFolders">
/// The folders that we have resolved so far for a given archive path.
/// </param>
/// <param name="loadedNodes">
/// Track the inventory nodes created.
/// </param>
protected void CreateFoldersForPath (
2010-06-18 16:10:16 +00:00
InventoryFolderBase destFolder ,
string iarPathExisting ,
string iarPathToReplicate ,
Dictionary < string , InventoryFolderBase > resolvedFolders ,
2010-06-04 23:48:33 +00:00
List < InventoryNodeBase > loadedNodes )
{
2010-06-18 16:10:16 +00:00
string [ ] rawDirsToCreate = iarPathToReplicate . Split ( new char [ ] { '/' } , StringSplitOptions . RemoveEmptyEntries ) ;
2009-04-24 19:10:13 +00:00
int i = 0 ;
while ( i < rawDirsToCreate . Length )
{
2010-06-04 23:48:33 +00:00
// m_log.DebugFormat("[INVENTORY ARCHIVER]: Creating folder {0} from IAR", rawDirsToCreate[i]);
2009-04-24 19:10:13 +00:00
int identicalNameIdentifierIndex
= rawDirsToCreate [ i ] . LastIndexOf (
ArchiveConstants . INVENTORY_NODE_NAME_COMPONENT_SEPARATOR ) ;
2009-12-23 21:20:48 +00:00
if ( identicalNameIdentifierIndex < 0 )
{
i + + ;
continue ;
}
2009-09-06 21:07:35 +00:00
string newFolderName = rawDirsToCreate [ i ] . Remove ( identicalNameIdentifierIndex ) ;
2009-11-05 18:53:25 +00:00
2009-11-23 02:26:06 +00:00
newFolderName = InventoryArchiveUtils . UnescapeArchivePath ( newFolderName ) ;
2009-04-24 19:10:13 +00:00
UUID newFolderId = UUID . Random ( ) ;
2009-09-11 15:51:57 +00:00
// Asset type has to be Unknown here rather than Folder, otherwise the created folder can't be
// deleted once the client has relogged.
// The root folder appears to be labelled AssetType.Folder (shows up as "Category" in the client)
// even though there is a AssetType.RootCategory
2009-09-06 21:07:35 +00:00
destFolder
= new InventoryFolderBase (
2010-01-10 18:40:07 +00:00
newFolderId , newFolderName , m_userInfo . PrincipalID ,
2009-09-11 15:51:57 +00:00
( short ) AssetType . Unknown , destFolder . ID , 1 ) ;
2009-09-30 16:00:09 +00:00
m_scene . InventoryService . AddFolder ( destFolder ) ;
2009-04-24 19:10:13 +00:00
// Record that we have now created this folder
2010-06-18 16:10:16 +00:00
iarPathExisting + = rawDirsToCreate [ i ] + "/" ;
m_log . DebugFormat ( "[INVENTORY ARCHIVER]: Created folder {0} from IAR" , iarPathExisting ) ;
resolvedFolders [ iarPathExisting ] = destFolder ;
2009-04-24 19:10:13 +00:00
if ( 0 = = i )
2010-06-04 23:48:33 +00:00
loadedNodes . Add ( destFolder ) ;
2009-04-24 19:10:13 +00:00
i + + ;
2010-06-04 23:48:33 +00:00
}
2009-04-24 19:10:13 +00:00
}
2010-06-04 23:48:33 +00:00
2009-11-09 17:04:05 +00:00
/// <summary>
/// Load an item from the archive
/// </summary>
/// <param name="filePath">The archive path for the item</param>
/// <param name="data">The raw item data</param>
/// <param name="rootDestinationFolder">The root destination folder for loaded items</param>
/// <param name="nodesLoaded">All the inventory nodes (items and folders) loaded so far</param>
protected InventoryItemBase LoadItem ( byte [ ] data , InventoryFolderBase loadFolder )
{
InventoryItemBase item = UserInventoryItemSerializer . Deserialize ( data ) ;
// Don't use the item ID that's in the file
item . ID = UUID . Random ( ) ;
2010-01-09 17:09:32 +00:00
UUID ospResolvedId = OspResolver . ResolveOspa ( item . CreatorId , m_scene . UserAccountService ) ;
2009-11-09 17:04:05 +00:00
if ( UUID . Zero ! = ospResolvedId )
2010-01-03 21:10:45 +00:00
{
2009-11-09 17:04:05 +00:00
item . CreatorIdAsUuid = ospResolvedId ;
2009-11-26 16:39:30 +00:00
// XXX: For now, don't preserve the OSPA in the creator id (which actually gets persisted to the
// database). Instead, replace with the UUID that we found.
2010-01-03 21:10:45 +00:00
item . CreatorId = ospResolvedId . ToString ( ) ;
2009-11-26 16:39:30 +00:00
}
2009-11-09 17:04:05 +00:00
else
2009-11-26 16:39:30 +00:00
{
2010-01-10 18:40:07 +00:00
item . CreatorIdAsUuid = m_userInfo . PrincipalID ;
2009-11-26 16:39:30 +00:00
}
2009-11-09 17:04:05 +00:00
2010-01-10 18:40:07 +00:00
item . Owner = m_userInfo . PrincipalID ;
2009-11-09 17:04:05 +00:00
// Reset folder ID to the one in which we want to load it
item . Folder = loadFolder . ID ;
//m_userInfo.AddItem(item);
2009-11-23 02:26:06 +00:00
m_scene . InventoryService . AddItem ( item ) ;
2009-11-09 17:04:05 +00:00
return item ;
}
2008-09-29 14:55:26 +00:00
/// <summary>
/// Load an asset
/// </summary>
/// <param name="assetFilename"></param>
/// <param name="data"></param>
/// <returns>true if asset was successfully loaded, false otherwise</returns>
private bool LoadAsset ( string assetPath , byte [ ] data )
{
2008-09-29 15:33:58 +00:00
//IRegionSerialiser serialiser = scene.RequestModuleInterface<IRegionSerialiser>();
2008-09-29 14:55:26 +00:00
// Right now we're nastily obtaining the UUID from the filename
2009-03-12 06:04:17 +00:00
string filename = assetPath . Remove ( 0 , ArchiveConstants . ASSETS_PATH . Length ) ;
int i = filename . LastIndexOf ( ArchiveConstants . ASSET_EXTENSION_SEPARATOR ) ;
2008-09-29 14:55:26 +00:00
if ( i = = - 1 )
{
m_log . ErrorFormat (
2009-02-11 18:46:51 +00:00
"[INVENTORY ARCHIVER]: Could not find extension information in asset path {0} since it's missing the separator {1}. Skipping" ,
2009-03-12 06:04:17 +00:00
assetPath , ArchiveConstants . ASSET_EXTENSION_SEPARATOR ) ;
2008-09-29 14:55:26 +00:00
return false ;
}
string extension = filename . Substring ( i ) ;
string uuid = filename . Remove ( filename . Length - extension . Length ) ;
2009-03-12 06:04:17 +00:00
if ( ArchiveConstants . EXTENSION_TO_ASSET_TYPE . ContainsKey ( extension ) )
2008-09-29 14:55:26 +00:00
{
2009-03-12 06:04:17 +00:00
sbyte assetType = ArchiveConstants . EXTENSION_TO_ASSET_TYPE [ extension ] ;
2008-09-29 14:55:26 +00:00
2009-11-05 21:10:58 +00:00
if ( assetType = = ( sbyte ) AssetType . Unknown )
m_log . WarnFormat ( "[INVENTORY ARCHIVER]: Importing {0} byte asset {1} with unknown type" , data . Length , uuid ) ;
2008-09-29 14:55:26 +00:00
2009-11-05 21:10:58 +00:00
//m_log.DebugFormat("[INVENTORY ARCHIVER]: Importing asset {0}, type {1}", uuid, assetType);
2008-09-29 14:55:26 +00:00
2010-02-22 22:18:59 +00:00
AssetBase asset = new AssetBase ( new UUID ( uuid ) , "RandomName" , assetType , UUID . Zero . ToString ( ) ) ;
2008-09-29 14:55:26 +00:00
asset . Data = data ;
2009-09-06 19:16:56 +00:00
m_scene . AssetService . Store ( asset ) ;
2008-09-29 14:55:26 +00:00
return true ;
}
else
{
m_log . ErrorFormat (
2009-02-11 18:46:51 +00:00
"[INVENTORY ARCHIVER]: Tried to dearchive data with path {0} with an unknown type extension {1}" ,
2008-09-29 14:55:26 +00:00
assetPath , extension ) ;
return false ;
}
}
2010-12-11 02:44:37 +00:00
/// <summary>
/// Load control file
/// </summary>
/// <param name="path"></param>
/// <param name="data"></param>
protected void LoadControlFile ( string path , byte [ ] data )
{
int majorVersion = - 1 ;
int minorVersion = - 1 ;
string version = "ERROR" ;
NameTable nt = new NameTable ( ) ;
XmlNamespaceManager nsmgr = new XmlNamespaceManager ( nt ) ;
XmlParserContext context = new XmlParserContext ( null , nsmgr , null , XmlSpace . None ) ;
XmlTextReader xtr = new XmlTextReader ( Encoding . ASCII . GetString ( data ) , XmlNodeType . Document , context ) ;
while ( xtr . Read ( ) )
{
if ( xtr . NodeType = = XmlNodeType . Element )
{
if ( xtr . Name . ToString ( ) = = "archive" )
{
majorVersion = int . Parse ( xtr [ "major_version" ] ) ;
minorVersion = int . Parse ( xtr [ "minor_version" ] ) ;
version = string . Format ( "{0}.{1}" , majorVersion , minorVersion ) ;
}
}
}
if ( majorVersion > MAX_MAJOR_VERSION )
{
throw new Exception (
string . Format (
"The IAR you are trying to load has major version number of {0} but this version of OpenSim can only load IARs with major version number {1} and below" ,
majorVersion , MAX_MAJOR_VERSION ) ) ;
}
m_log . InfoFormat ( "[INVENTORY ARCHIVER]: Loading IAR with version {0}" , version ) ;
}
2008-09-29 14:55:26 +00:00
}
2010-12-11 02:44:37 +00:00
}