OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
/// <summary>
/// Dearchive the region embodied in this request.
/// </summary>
Dearchive the region embodied in this request.
Dearchive the region embodied in this request .
public void DearchiveRegion()
        {
            int successfulAssetRestores = 0;
            int failedAssetRestores = 0;
            DearchiveScenesInfo dearchivedScenes;
            Dictionary<UUID, DearchiveContext> sceneContexts = new Dictionary<UUID, DearchiveContext>();
            string fullPath = "NONE";
            TarArchiveReader archive = null;
            byte[] data;
            TarArchiveReader.TarEntryType entryType;
            try
            {
                FindAndLoadControlFile(out archive, out dearchivedScenes);
                while ((data = archive.ReadEntry(out fullPath, out entryType)) != null)
                {
                    if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType)
                        continue;
                    Scene scene;
                    string filePath;
                    if (!dearchivedScenes.GetRegionFromPath(fullPath, out scene, out filePath))
                        continue;   
                    DearchiveContext sceneContext = null;
                    if (scene != null)
                    {
                        if (!sceneContexts.TryGetValue(scene.RegionInfo.RegionID, out sceneContext))
                        {
                            sceneContext = new DearchiveContext(scene);
                            sceneContexts.Add(scene.RegionInfo.RegionID, sceneContext);
                        }
                    }
                    if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH) && !m_noObjects)
                    {
                        sceneContext.SerialisedSceneObjects.Add(Encoding.UTF8.GetString(data));
                    }
                    else if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH) && !m_skipAssets)
                    {
                        if (LoadAsset(filePath, data))
                            successfulAssetRestores++;
                        else
                            failedAssetRestores++;
                        if ((successfulAssetRestores + failedAssetRestores) % 250 == 0)
                            m_log.Debug("[ARCHIVER]: Loaded " + successfulAssetRestores + " assets and failed to load " + failedAssetRestores + " assets...");
                    }
                    else if (filePath.StartsWith(ArchiveConstants.TERRAINS_PATH) && (!m_merge || m_forceTerrain))
                    {
                        LoadTerrain(scene, filePath, data);
                    }
                    else if (!m_merge && filePath.StartsWith(ArchiveConstants.SETTINGS_PATH))
                    {
                        LoadRegionSettings(scene, filePath, data, dearchivedScenes);
                    } 
                    else if (filePath.StartsWith(ArchiveConstants.LANDDATA_PATH) && (!m_merge || m_forceParcels))
                    {
                        sceneContext.SerialisedParcels.Add(Encoding.UTF8.GetString(data));
                    } 
                    else if (filePath == ArchiveConstants.CONTROL_FILE_PATH)
                    {
                    }
                }
            }
            catch (Exception e)
            {
                m_log.Error(
                    String.Format("[ARCHIVER]: Aborting load with error in archive file {0} ", fullPath), e);
                m_errorMessage += e.ToString();
                m_rootScene.EventManager.TriggerOarFileLoaded(m_requestId, new List<UUID>(), m_errorMessage);
                return;
            }
            finally
            {
                if (archive != null)
                    archive.Close();
            }
            if (!m_skipAssets)
            {
                m_log.InfoFormat("[ARCHIVER]: Restored {0} assets", successfulAssetRestores);
                if (failedAssetRestores > 0)
                {
                    m_log.ErrorFormat("[ARCHIVER]: Failed to load {0} assets", failedAssetRestores);
                    m_errorMessage += String.Format("Failed to load {0} assets", failedAssetRestores);
                }
            }
            foreach (DearchiveContext sceneContext in sceneContexts.Values)
            {
                m_log.InfoFormat("[ARCHIVER]: Loading region {0}", sceneContext.Scene.RegionInfo.RegionName);
                if (!m_merge)
                {
                    m_log.Info("[ARCHIVER]: Clearing all existing scene objects");
                    sceneContext.Scene.DeleteAllSceneObjects();
                }
                try
                {
                    LoadParcels(sceneContext.Scene, sceneContext.SerialisedParcels);
                    LoadObjects(sceneContext.Scene, sceneContext.SerialisedSceneObjects, sceneContext.SceneObjects);
                    IEstateModule estateModule = sceneContext.Scene.RequestModuleInterface<IEstateModule>();
                    if (estateModule != null)
                        estateModule.TriggerRegionInfoChange();
                }
                catch (Exception e)
                {
                    m_log.Error("[ARCHIVER]: Error loading parcels or objects ", e);
                    m_errorMessage += e.ToString();
                    m_rootScene.EventManager.TriggerOarFileLoaded(m_requestId, new List<UUID>(), m_errorMessage);
                    return;
                }
            }
            WorkManager.RunInThread(o =>
            {
                Thread.Sleep(15000);
                m_log.Info("[ARCHIVER]: Starting scripts in scene objects");
                foreach (DearchiveContext sceneContext in sceneContexts.Values)
                {
                    foreach (SceneObjectGroup sceneObject in sceneContext.SceneObjects)
                    {
                        sceneObject.CreateScriptInstances(0, false, sceneContext.Scene.DefaultScriptEngine, 0); 
                        sceneObject.ResumeScripts();
                    }
                    sceneContext.SceneObjects.Clear();
                }
            }, null, string.Format("ReadArchiveStartScripts (request {0})", m_requestId));
            m_log.InfoFormat("[ARCHIVER]: Successfully loaded archive");
            m_rootScene.EventManager.TriggerOarFileLoaded(m_requestId, dearchivedScenes.GetLoadedScenes(), m_errorMessage);
        }
public void DearchiveRegion ( ) { int successfulAssetRestores = 0 ; int failedAssetRestores = 0 ; DearchiveScenesInfo dearchivedScenes ; Dictionary < UUID , DearchiveContext > sceneContexts = new Dictionary < UUID , DearchiveContext > ( ) ; string fullPath = " " ; TarArchiveReader archive = null ; byte [ ] data ; TarArchiveReader . TarEntryType entryType ; try { FindAndLoadControlFile ( out archive , out dearchivedScenes ) ; while ( ( data = archive . ReadEntry ( out fullPath , out entryType ) ) != null ) { if ( TarArchiveReader . TarEntryType . TYPE_DIRECTORY == entryType ) continue ; Scene scene ; string filePath ; if ( ! dearchivedScenes . GetRegionFromPath ( fullPath , out scene , out filePath ) ) continue ; DearchiveContext sceneContext = null ; if ( scene != null ) { if ( ! sceneContexts . TryGetValue ( scene . RegionInfo . RegionID , out sceneContext ) ) { sceneContext = new DearchiveContext ( scene ) ; sceneContexts . Add ( scene . RegionInfo . RegionID , sceneContext ) ; } } if ( filePath . StartsWith ( ArchiveConstants . OBJECTS_PATH ) && ! m_noObjects ) { sceneContext . SerialisedSceneObjects . Add ( Encoding . UTF8 . GetString ( data ) ) ; } else if ( filePath . StartsWith ( ArchiveConstants . ASSETS_PATH ) && ! m_skipAssets ) { if ( LoadAsset ( filePath , data ) ) successfulAssetRestores ++ ; else failedAssetRestores ++ ; if ( ( successfulAssetRestores + failedAssetRestores ) % 250 == 0 ) m_log . Debug ( " " + successfulAssetRestores + " " + failedAssetRestores + " " ) ; } else if ( filePath . StartsWith ( ArchiveConstants . TERRAINS_PATH ) && ( ! m_merge || m_forceTerrain ) ) { LoadTerrain ( scene , filePath , data ) ; } else if ( ! m_merge && filePath . StartsWith ( ArchiveConstants . SETTINGS_PATH ) ) { LoadRegionSettings ( scene , filePath , data , dearchivedScenes ) ; } else if ( filePath . StartsWith ( ArchiveConstants . LANDDATA_PATH ) && ( ! m_merge || m_forceParcels ) ) { sceneContext . SerialisedParcels . Add ( Encoding . UTF8 . GetString ( data ) ) ; } else if ( filePath == ArchiveConstants . CONTROL_FILE_PATH ) { } } } catch ( Exception e ) { m_log . Error ( String . Format ( " " , fullPath ) , e ) ; m_errorMessage += e . ToString ( ) ; m_rootScene . EventManager . TriggerOarFileLoaded ( m_requestId , new List < UUID > ( ) , m_errorMessage ) ; return ; } finally { if ( archive != null ) archive . Close ( ) ; } if ( ! m_skipAssets ) { m_log . InfoFormat ( " " , successfulAssetRestores ) ; if ( failedAssetRestores > 0 ) { m_log . ErrorFormat ( " " , failedAssetRestores ) ; m_errorMessage += String . Format ( " " , failedAssetRestores ) ; } } foreach ( DearchiveContext sceneContext in sceneContexts . Values ) { m_log . InfoFormat ( " " , sceneContext . Scene . RegionInfo . RegionName ) ; if ( ! m_merge ) { m_log . Info ( " " ) ; sceneContext . Scene . DeleteAllSceneObjects ( ) ; } try { LoadParcels ( sceneContext . Scene , sceneContext . SerialisedParcels ) ; LoadObjects ( sceneContext . Scene , sceneContext . SerialisedSceneObjects , sceneContext . SceneObjects ) ; IEstateModule estateModule = sceneContext . Scene . RequestModuleInterface < IEstateModule > ( ) ; if ( estateModule != null ) estateModule . TriggerRegionInfoChange ( ) ; } catch ( Exception e ) { m_log . Error ( " " , e ) ; m_errorMessage += e . ToString ( ) ; m_rootScene . EventManager . TriggerOarFileLoaded ( m_requestId , new List < UUID > ( ) , m_errorMessage ) ; return ; } } WorkManager . RunInThread ( o => { Thread . Sleep ( 15000 ) ; m_log . Info ( " " ) ; foreach ( DearchiveContext sceneContext in sceneContexts . Values ) { foreach ( SceneObjectGroup sceneObject in sceneContext . SceneObjects ) { sceneObject . CreateScriptInstances ( 0 , false , sceneContext . Scene . DefaultScriptEngine , 0 ) ; sceneObject . ResumeScripts ( ) ; } sceneContext . SceneObjects . Clear ( ) ; } } , null , string . Format ( " " , m_requestId ) ) ; m_log . InfoFormat ( " " ) ; m_rootScene . EventManager . TriggerOarFileLoaded ( m_requestId , dearchivedScenes . GetLoadedScenes ( ) , m_errorMessage ) ; }
Dearchive the region embodied in this request.
Dearchive the region embodied in this request .
// We dearchive all the scenes at once, because the files in the TAR archive might be mixed. // Therefore, we have to keep track of the dearchive context of all the scenes. //m_log.DebugFormat( //    "[ARCHIVER]: Successfully read {0} ({1} bytes)", filePath, data.Length); // Find the scene that this file belongs to // this file belongs to a region that we're not loading // Process the file // Ignore, because we already read the control file //m_log.Debug("[ARCHIVER]: Reached end of archive"); // Inform any interested parties that the region has changed. We waited until now so that all // of the region's objects will be loaded when we send this notification. // Start the scripts. We delayed this because we want the OAR to finish loading ASAP, so // that users can enter the scene. If we allow the scripts to start in the loop above // then they significantly increase the time until the OAR finishes loading. // StateSource.RegionStart