Ejemplo n.º 1
0
        public InventoryArchiveReadRequest(
            IRegistryCore registry, UserAccount userInfo, string invPath, string loadPath, bool merge,
            UUID overwriteCreator)
        {
            Stream str = ArchiveHelpers.GetStream(loadPath);

            if (str == null)
            {
                return;
            }

            m_registry        = registry;
            m_merge           = merge;
            m_userInfo        = userInfo;
            m_invName         = Path.GetFileNameWithoutExtension(loadPath);
            m_invPath         = invPath.StartsWith("/", StringComparison.Ordinal) ? invPath.Remove(0, 1) : invPath;
            m_loadStream      = new GZipStream(str, CompressionMode.Decompress);
            m_overridecreator = overwriteCreator;

            // we will need these at some time
            m_assetService     = m_registry.RequestModuleInterface <IAssetService> ();
            m_assetData        = Framework.Utilities.DataManager.RequestPlugin <IAssetDataPlugin> ();
            m_inventoryService = m_registry.RequestModuleInterface <IInventoryService> ();
            m_accountService   = m_registry.RequestModuleInterface <IUserAccountService> ();
        }
Ejemplo n.º 2
0
        public void RequestBytesRES(RageArchiveResourceFile7 file_, long newLength)
        {
            // determine header size...
            long x = GetHeaderSize();

            DataBlock        thisBlock = null;
            List <DataBlock> blocks    = GetBlocks();

            foreach (var q in blocks)
            {
                if (q.Tag == file_)
                {
                    thisBlock = q;
                }
            }

            long maxlength = ArchiveHelpers.FindSpace(blocks, thisBlock);

            if (maxlength < newLength)
            {
                // move...

                long offset = ArchiveHelpers.FindOffset(blocks, newLength, 512);
                ArchiveHelpers.MoveBytes(archive_.BaseStream, thisBlock.Offset, offset, thisBlock.Length);
                ((IRageArchiveFileEntry7)thisBlock.Tag).FileOffset = (uint)offset / 512;
            }

            file_.FileSize = (uint)newLength;
        }
Ejemplo n.º 3
0
        void LoadWhiteCoreArchive(IScene scene, string[] cmd)
        {
            string fileName = MainConsole.Instance.Prompt("What file name should we load?",
                                                          scene.RegionInfo.RegionName + ".abackup");

            // a couple of sanity checks
            string extension = Path.GetExtension(fileName);

            if (extension == string.Empty)
            {
                fileName = fileName + ".abackup";
            }

            if (!File.Exists(fileName))
            {
                MainConsole.Instance.Info("[Archiver]: Region archive file '" + fileName + "' not found.");
                return;
            }

            var stream = ArchiveHelpers.GetStream(fileName);

            if (stream == null)
            {
                MainConsole.Instance.Warn("No file found with the specified name.");
                return;
            }
            GZipStream       m_loadStream = new GZipStream(stream, CompressionMode.Decompress);
            TarArchiveReader reader       = new TarArchiveReader(m_loadStream);

            LoadRegionBackup(reader, scene);
            GC.Collect();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Clears all buffers for this archive and causes any buffered data to be
        /// written to the underlying device.
        /// </summary>
        public void Flush()
        {
            long headerSize = GetHeaderSize();

            do
            {
                var  blocks          = GetBlocks();
                long maxheaderlength = ArchiveHelpers.FindSpace(blocks, blocks[0]);
                if (maxheaderlength < headerSize)
                {
                    long newpos = ArchiveHelpers.FindOffset(blocks, blocks[1].Length, 512);
                    ArchiveHelpers.MoveBytes(archive_.BaseStream, blocks[1].Offset, newpos, blocks[1].Length);
                    ((IRageArchiveFileEntry7)blocks[1].Tag).FileOffset = (uint)(newpos / 512);

                    blocks          = GetBlocks();
                    maxheaderlength = ArchiveHelpers.FindSpace(blocks, blocks[0]);
                }
                else
                {
                    break;
                }
            } while (true);



            // calculate key...
            var tmp1 = GTA5Hash.CalculateHash(FileName);
            var tmp2 = (tmp1 + (uint)archive_.BaseStream.Length + (101 - 40)) % 0x65;

            //  archive_.key_ = GTA5Crypto.key_gta5;
            archive_.WriteHeader(GTA5Constants.PC_AES_KEY, GTA5Constants.PC_NG_KEYS[tmp2]);
            archive_.BaseStream.Flush();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Clears all buffers for this archive and causes any buffered data to be
        /// written to the underlying device.
        /// </summary>
        public void Flush()
        {
            long headerSize = GetHeaderSize();

            for (;;)
            {
                List <DataBlock> blocks = GetBlocks();

                long num = ArchiveHelpers.FindSpace(blocks, blocks[0]);

                if (num >= headerSize)
                {
                    break;
                }

                long num2 = ArchiveHelpers.FindOffset(blocks, blocks[1].Length, 512);

                ArchiveHelpers.MoveBytes(archive_.BaseStream, blocks[1].Offset, num2, blocks[1].Length);

                ((IRageArchiveFileEntry7)blocks[1].Tag).FileOffset = (uint)(num2 / 512);
                blocks = this.GetBlocks();
                num    = ArchiveHelpers.FindSpace(blocks, blocks[0]);
            }

            uint num3 = GTA5Hash.CalculateHash(FileName);
            uint num4 = (num3 + (uint)archive_.BaseStream.Length + 0x3D) % 0x65;

            archive_.WriteHeader(GTA5Constants.PC_AES_KEY, GTA5Constants.PC_NG_KEYS[(int)num4]);
            archive_.BaseStream.Flush();
        }
Ejemplo n.º 6
0
 public ArchiveReadRequest(IScene scene, string loadPath, bool merge, bool skipAssets,
                           int offsetX, int offsetY, int offsetZ, bool flipX, bool flipY, bool useParcelOwnership,
                           bool checkOwnership)
 {
     try
     {
         var stream = ArchiveHelpers.GetStream(loadPath);
         if (stream == null)
         {
             MainConsole.Instance.Error(
                 "[ARCHIVER]: We could not find the file specified, or the file was invalid: " + loadPath);
             return;
         }
         m_loadStream = new GZipStream(stream, CompressionMode.Decompress);
     }
     catch (EntryPointNotFoundException e)
     {
         MainConsole.Instance.ErrorFormat(
             "[ARCHIVER]: Mismatch between Mono and zlib1g library version when trying to create compression stream."
             + "If you've manually installed Mono, have you appropriately updated zlib1g as well?");
         MainConsole.Instance.Error(e);
     }
     Init(scene, m_loadStream, merge, skipAssets, offsetX, offsetY, offsetZ, flipX, flipY, useParcelOwnership,
          checkOwnership);
 }
Ejemplo n.º 7
0
        private void LoadAuroraArchive(string[] cmd)
        {
            IScene scene = MainConsole.Instance.ConsoleScene;

            if (scene == null)
            {
                MainConsole.Instance.Warn("Select a region first.");
                return;
            }

            string fileName = MainConsole.Instance.Prompt("What file name should we load?",
                                                          scene.RegionInfo.RegionName + ".abackup");


            var stream = ArchiveHelpers.GetStream(fileName);

            if (stream == null)
            {
                MainConsole.Instance.Warn("No file found with the specified name.");
                return;
            }
            GZipStream       m_loadStream = new GZipStream(stream, CompressionMode.Decompress);
            TarArchiveReader reader       = new TarArchiveReader(m_loadStream);

            LoadRegionBackup(reader, scene);
            GC.Collect();
        }
 public InventoryArchiveReadRequest(
     Scene scene, UserAccount userInfo, string invPath, string loadPath)
     : this(
         scene,
         userInfo,
         invPath,
         new GZipStream(ArchiveHelpers.GetStream(loadPath), CompressionMode.Decompress))
 {
 }
 public InventoryArchiveReadRequest(
     IRegistryCore registry, UserAccount userInfo, string invPath, string loadPath, bool merge)
     : this(
         registry,
         userInfo,
         invPath,
         new GZipStream(ArchiveHelpers.GetStream(loadPath), CompressionMode.Decompress),
         merge)
 {
 }
 public static async Task CheckAndSwapInstalledExternalPlugins()
 {
     try
     {
         if (ConfigManager.IsVersionChanged)
         {
             string minerPluginsPath = Paths.MinerPluginsPath();
             var zipPackages = Directory.GetFiles(Paths.RootPath("plugins_packages"), "*.zip", SearchOption.TopDirectoryOnly);
             var installedExternalPackages = Directory.GetDirectories(minerPluginsPath);
             foreach (var installedPath in installedExternalPackages)
             {
                 try
                 {
                     var uuid = installedPath.Replace(minerPluginsPath, "").Trim('\\');
                     if (!System.Guid.TryParse(uuid, out var _)) continue;
                     var zipPackage = zipPackages.FirstOrDefault(package => package.Contains(uuid));
                     if (zipPackage == null) continue;
                     // uzip to temp dir
                     var tmpPluginDir = installedPath + "_tmp";
                     Directory.CreateDirectory(tmpPluginDir);
                     await ArchiveHelpers.ExtractFileAsync(zipPackage, tmpPluginDir, null, CancellationToken.None);
                     // now copy move over files 
                     var tmpPackageFiles = Directory.GetFiles(tmpPluginDir, "*", SearchOption.AllDirectories);
                     var installedPackagePaths = Directory.GetFiles(installedPath, "*", SearchOption.AllDirectories);
                     foreach (var path in installedPackagePaths)
                     {
                         // skip if not file and skip all bins
                         if (!File.Exists(path) || path.Contains("bins")) continue;
                         var fileName = Path.GetFileName(path);
                         var moveFile = tmpPackageFiles.FirstOrDefault(file => Path.GetFileName(file) == fileName);
                         if (moveFile == null) continue;
                         try
                         {
                             File.Copy(moveFile, path, true);
                         }
                         catch (Exception e)
                         {
                             Logger.Error("CheckAndSwapInstalledExternalPlugins", e.Message);
                         }
                     }
                     Directory.Delete(tmpPluginDir, true);
                 }
                 catch (Exception e)
                 {
                     Logger.Error("CheckAndSwapInstalledExternalPlugins", e.Message);
                 }
             }
         }
     }
     catch (Exception e)
     {
         Logger.Error("CheckAndSwapInstalledExternalPlugins", e.Message);
     }
 }
Ejemplo n.º 11
0
        internal long FindSpace(long length)
        {
            // determine header size...
            long x = GetHeaderSize();

            List <DataBlock> blocks = GetBlocks();

            long offset = ArchiveHelpers.FindOffset(blocks, length, 512);

            return(offset);
        }
 public InventoryArchiveReadRequest(
     IInventoryService inv, IAssetService assets, IUserAccountService uacc, UserAccount userInfo, string invPath, string loadPath, bool merge)
     : this(
         inv,
         assets,
         uacc,
         userInfo,
         invPath,
         new GZipStream(ArchiveHelpers.GetStream(loadPath), CompressionMode.Decompress),
         merge)
 {
 }
Ejemplo n.º 13
0
        public static async Task CleanupPlugins()
        {
            Action <string> deleteDir  = (string path) => { try { Directory.Delete(path, true); } catch { } };
            Action <string> deleteFile = (string path) => { try { File.Delete(path); } catch { } };

            Logger.Info("MinerPluginsManager", "CleanupPlugins START");
            try
            {
                if (ConfigManager.IsVersionChanged)
                {
                    Logger.Info("MinerPluginsManager", "CleanupPlugins EXECUTE");
                    string minerPluginsPath          = Paths.MinerPluginsPath();
                    var    zipPackages               = Directory.GetFiles(Paths.RootPath("plugins_packages"), "*.zip", SearchOption.TopDirectoryOnly);
                    var    installedExternalPackages = Directory.GetDirectories(minerPluginsPath, "*", SearchOption.TopDirectoryOnly);
                    foreach (var installedPath in installedExternalPackages)
                    {
                        try
                        {
                            var uuid = installedPath.Replace(minerPluginsPath, "").Trim('\\');
                            if (!System.Guid.TryParse(uuid, out var _))
                            {
                                continue;
                            }
                            var zipPackage = zipPackages.FirstOrDefault(package => package.Contains(uuid));
                            if (zipPackage == null)
                            {
                                continue;
                            }
                            // cleanup old bins and dll's
                            deleteDir(Path.Combine(installedPath, "bins"));
                            deleteDir(Path.Combine(installedPath, "dlls"));
                            var installedPackageRootDlls = Directory.GetFiles(installedPath, "*.dll", SearchOption.TopDirectoryOnly);
                            foreach (var dllFile in installedPackageRootDlls)
                            {
                                deleteFile(dllFile);
                            }
                            await ArchiveHelpers.ExtractFileAsync(zipPackage, installedPath, null, CancellationToken.None);
                        }
                        catch (Exception e)
                        {
                            Logger.Error("MinerPluginsManager", $"CleanupPlugins {installedPath} Error: {e.Message}");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error("MinerPluginsManager", $"CleanupPlugins Error: {e.Message}");
            }
        }
Ejemplo n.º 14
0
        private void LoadAuroraArchive(string mod, string[] cmd)
        {
            IScene scene = MainConsole.Instance.ConsoleScene;

            if (scene == null)
            {
                m_log.Warn("Select a region first.");
                return;
            }

            string fileName = MainConsole.Instance.CmdPrompt("What file name should we load?", scene.RegionInfo.RegionName + ".backup");

            GZipStream       m_loadStream = new GZipStream(ArchiveHelpers.GetStream(fileName), CompressionMode.Decompress);
            TarArchiveReader reader       = new TarArchiveReader(m_loadStream);
        }
Ejemplo n.º 15
0
 public void SetExtractPath(Entry entry, string destinationPath)
 {
     if (destinationPath != null)
     {
         ExtractPaths.Add(entry, destinationPath);
         if (ArchiveHelpers.IsPlugin(destinationPath))
         {
             PluginPaths.Add(destinationPath);
         }
         else if (ArchiveHelpers.IsArchive(destinationPath))
         {
             ArchivePaths.Add(destinationPath);
         }
     }
 }
        private void LoadIAR(string fileName)
        {
            //Load the iar into memory
            TarArchiveReader archive = new TarArchiveReader(new GZipStream(ArchiveHelpers.GetStream(fileName), CompressionMode.Decompress));

            byte[] data;
            TarArchiveReader.TarEntryType entryType;
            string filePath;

            InventoryFolderBase rootDestFolder = new InventoryFolderBase(UUID.Zero, UUID.Zero);
            Dictionary <string, InventoryFolderBase> resolvedFolders = new Dictionary <string, InventoryFolderBase> ();

            while ((data = archive.ReadEntry(out filePath, out entryType)) != null)
            {
                if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH))
                {
                    LoadAsset(filePath, data);
                }
                else if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH))
                {
                    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);
                    }

                    InventoryFolderBase foundFolder
                        = ReplicateArchivePathToUserInventory(
                              filePath, rootDestFolder, ref resolvedFolders);

                    if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY != entryType)
                    {
                        LoadItem(data, foundFolder);
                    }
                }
            }

            archive.Close();


            //Got the .iar loaded into memory now
            // Time to put it into the GUI

            RebuildTreeView();
        }
        public InventoryArchiveReadRequest(
            IRegistryCore registry, UserAccount userInfo, string invPath, string loadPath, bool merge,
            UUID overwriteCreator)
        {
            Stream str = ArchiveHelpers.GetStream(loadPath);

            if (str == null)
            {
                return;
            }

            m_registry        = registry;
            m_merge           = merge;
            m_userInfo        = userInfo;
            m_invPath         = invPath;
            m_loadStream      = new GZipStream(str, CompressionMode.Decompress);
            m_overridecreator = overwriteCreator;
        }
        protected virtual void ReadBackup(IScene scene)
        {
            MainConsole.Instance.Debug("[FileBasedSimulationData]: Reading file for " + scene.RegionInfo.RegionName);
            List <uint> foundLocalIDs = new List <uint>();
            var         stream        = ArchiveHelpers.GetStream((m_loadDirectory == "" || m_loadDirectory == "/")
                                                      ? m_fileName
                                                      : Path.Combine(m_loadDirectory, m_fileName));

            if (stream == null)
            {
                lock (m_saveLock)
                {
                    if (!m_shutdown)
                    {
                        SaveBackup(m_saveDirectory, false);
                    }
                }
                return;
            }
            GZipStream       m_loadStream = new GZipStream(stream, CompressionMode.Decompress);
            TarArchiveReader reader       = new TarArchiveReader(m_loadStream);

            byte[] data;
            string filePath;

            TarArchiveReader.TarEntryType entryType;
            System.Collections.Concurrent.ConcurrentQueue <byte[]> groups = new System.Collections.Concurrent.ConcurrentQueue <byte[]>();
            //Load the archive data that we need
            while ((data = reader.ReadEntry(out filePath, out entryType)) != null)
            {
                if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType)
                {
                    continue;
                }

                if (filePath.StartsWith("parcels/"))
                {
                    //Only use if we are not merging
                    LandData parcel     = new LandData();
                    OSD      parcelData = OSDParser.DeserializeLLSDBinary(data);
                    parcel.FromOSD((OSDMap)parcelData);
                    m_parcels.Add(parcel);
                }
                else if (filePath.StartsWith("terrain/"))
                {
                    m_oldstyleterrain = data;
                }
                else if (filePath.StartsWith("revertterrain/"))
                {
                    m_oldstylerevertTerrain = data;
                }
                else if (filePath.StartsWith("newstyleterrain/"))
                {
                    m_terrain = data;
                }
                else if (filePath.StartsWith("newstylerevertterrain/"))
                {
                    m_revertTerrain = data;
                }
                else if (filePath.StartsWith("newstylewater/"))
                {
                    m_water = data;
                }
                else if (filePath.StartsWith("newstylerevertwater/"))
                {
                    m_revertWater = data;
                }
                else if (filePath.StartsWith("entities/"))
                {
                    MemoryStream     ms          = new MemoryStream(data);
                    SceneObjectGroup sceneObject = SceneObjectSerializer.FromXml2Format(ref ms, scene);

                    ms.Close();

                    ms = null;

                    data = null;

                    foreach (ISceneChildEntity part in sceneObject.ChildrenEntities())

                    {
                        if (!foundLocalIDs.Contains(part.LocalId))
                        {
                            foundLocalIDs.Add(part.LocalId);
                        }

                        else
                        {
                            part.LocalId = 0; //Reset it! Only use it once!
                        }
                    }

                    m_groups.Add(sceneObject);
                }
                data = null;
            }
            m_loadStream.Close();
            m_loadStream = null;


            foundLocalIDs.Clear();
            GC.Collect();
        }
Ejemplo n.º 19
0
        public void TestSaveOarV0_2()
        {
            TestHelper.InMethod();
            //log4net.Config.XmlConfigurator.Configure();

            SceneObjectPart  part1 = CreateSceneObjectPart1();
            SceneObjectGroup sog1  = new SceneObjectGroup(part1);

            m_scene.AddNewSceneObject(sog1, false);

            SceneObjectPart part2 = CreateSceneObjectPart2();

            AssetNotecard nc = new AssetNotecard();

            nc.BodyText = "Hello World!";
            nc.Encode();
            UUID      ncAssetUuid = new UUID("00000000-0000-0000-1000-000000000000");
            UUID      ncItemUuid  = new UUID("00000000-0000-0000-1100-000000000000");
            AssetBase ncAsset
                = AssetHelpers.CreateAsset(ncAssetUuid, AssetType.Notecard, nc.AssetData, UUID.Zero);

            m_scene.AssetService.Store(ncAsset);
            SceneObjectGroup  sog2 = new SceneObjectGroup(part2);
            TaskInventoryItem ncItem
                = new TaskInventoryItem {
                Name = "ncItem", AssetID = ncAssetUuid, ItemID = ncItemUuid
                };

            part2.Inventory.AddInventoryItem(ncItem, true);

            m_scene.AddNewSceneObject(sog2, false);

            MemoryStream archiveWriteStream = new MemoryStream();

            m_scene.EventManager.OnOarFileSaved += SaveCompleted;

            Guid requestId = new Guid("00000000-0000-0000-0000-808080808080");

            lock (this)
            {
                m_archiverModule.ArchiveRegion(archiveWriteStream, requestId);
                //AssetServerBase assetServer = (AssetServerBase)scene.CommsManager.AssetCache.AssetServer;
                //while (assetServer.HasWaitingRequests())
                //    assetServer.ProcessNextRequest();

                Monitor.Wait(this, 60000);
            }

            Assert.That(m_lastRequestId, Is.EqualTo(requestId));

            byte[]           archive           = archiveWriteStream.ToArray();
            MemoryStream     archiveReadStream = new MemoryStream(archive);
            TarArchiveReader tar = new TarArchiveReader(archiveReadStream);

            bool gotControlFile = false;
            bool gotNcAssetFile = false;

            string expectedNcAssetFileName = string.Format("{0}_{1}", ncAssetUuid, "notecard.txt");

            List <string> foundPaths    = new List <string>();
            List <string> expectedPaths = new List <string>();

            expectedPaths.Add(ArchiveHelpers.CreateObjectPath(sog1));
            expectedPaths.Add(ArchiveHelpers.CreateObjectPath(sog2));

            string filePath;

            TarArchiveReader.TarEntryType tarEntryType;

            while (tar.ReadEntry(out filePath, out tarEntryType) != null)
            {
                if (ArchiveConstants.CONTROL_FILE_PATH == filePath)
                {
                    gotControlFile = true;
                }
                else if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH))
                {
                    string fileName = filePath.Remove(0, ArchiveConstants.ASSETS_PATH.Length);

                    Assert.That(fileName, Is.EqualTo(expectedNcAssetFileName));
                    gotNcAssetFile = true;
                }
                else if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH))
                {
                    foundPaths.Add(filePath);
                }
            }

            Assert.That(gotControlFile, Is.True, "No control file in archive");
            Assert.That(gotNcAssetFile, Is.True, "No notecard asset file in archive");
            Assert.That(foundPaths, Is.EquivalentTo(expectedPaths));

            // TODO: Test presence of more files and contents of files.
        }
        protected internal void Save(ICollection <UUID> assetsFoundUuids, ICollection <UUID> assetsNotFoundUuids)
        {
            foreach (UUID uuid in assetsNotFoundUuids)
            {
                MainConsole.Instance.DebugFormat("[ARCHIVER]: Could not find asset {0}", uuid);
            }

//            MainConsole.Instance.InfoFormat(
//                "[ARCHIVER]: Received {0} of {1} assets requested",
//                assetsFoundUuids.Count, assetsFoundUuids.Count + assetsNotFoundUuids.Count);

            MainConsole.Instance.InfoFormat("[ARCHIVER]: Creating archive file.  This may take some time.");

            // Write out control file
            m_archiveWriter.WriteFile(ArchiveConstants.CONTROL_FILE_PATH, Create0p2ControlFile());
            MainConsole.Instance.InfoFormat("[ARCHIVER]: Added control file to archive.");

            // Write out region settings
            string settingsPath
                = String.Format("{0}{1}.xml", ArchiveConstants.SETTINGS_PATH, m_scene.RegionInfo.RegionName);

            m_archiveWriter.WriteFile(settingsPath,
                                      RegionSettingsSerializer.Serialize(m_scene.RegionInfo.RegionSettings));

            MainConsole.Instance.InfoFormat("[ARCHIVER]: Added region settings to archive.");

            // Write out land data (aka parcel) settings
            IParcelManagementModule parcelManagement = m_scene.RequestModuleInterface <IParcelManagementModule>();

            if (parcelManagement != null)
            {
                List <ILandObject> landObjects = parcelManagement.AllParcels();
                foreach (ILandObject lo in landObjects)
                {
                    LandData landData     = lo.LandData;
                    string   landDataPath = String.Format("{0}{1}.xml", ArchiveConstants.LANDDATA_PATH,
                                                          landData.GlobalID.ToString());
                    m_archiveWriter.WriteFile(landDataPath, LandDataSerializer.Serialize(landData));
                }
            }
            MainConsole.Instance.InfoFormat("[ARCHIVER]: Added parcel settings to archive.");

            // Write out terrain
            string terrainPath
                = String.Format("{0}{1}.r32", ArchiveConstants.TERRAINS_PATH, m_scene.RegionInfo.RegionName);

            MemoryStream ms = new MemoryStream();

            m_terrainModule.SaveToStream(m_terrainModule.TerrainMap, terrainPath, ms);
            m_archiveWriter.WriteFile(terrainPath, ms.ToArray());
            ms.Close();

            MainConsole.Instance.InfoFormat("[ARCHIVER]: Added terrain information to archive.");

            // Write out scene object metadata
            foreach (ISceneEntity sceneObject in m_sceneObjects)
            {
                //MainConsole.Instance.DebugFormat("[ARCHIVER]: Saving {0} {1}, {2}", entity.Name, entity.UUID, entity.GetType());

                string serializedObject = m_serialiser.SerializeGroupToXml2(sceneObject);
                m_archiveWriter.WriteFile(ArchiveHelpers.CreateObjectPath(sceneObject), serializedObject);
            }

            MainConsole.Instance.InfoFormat("[ARCHIVER]: Added scene objects to archive.");
        }
Ejemplo n.º 21
0
        public static async Task CleanupPlugins()
        {
            Action <string> deleteDirOrFile = (string path) => {
                if (Directory.Exists(path))
                {
                    try { Directory.Delete(path, true); } catch { }
                }
                if (File.Exists(path))
                {
                    try { File.Delete(path); } catch { }
                }
            };
            Func <string, List <string> > getObsoletePaths = (string dirPath) => {
                var sorted = Directory.GetDirectories(dirPath, "*.*", SearchOption.TopDirectoryOnly).OrderBy(fullPathDir => {
                    var verStr = fullPathDir.Replace(dirPath, "").Replace("\\", "").Trim();
                    return(Version.TryParse(verStr, out var ver) ? ver : new Version(1, 0));
                }).ToList();
                sorted.Remove(sorted.LastOrDefault());
                return(sorted);
            };

            Logger.Info("MinerPluginsManager", "CleanupPlugins START");
            try
            {
                Logger.Info("MinerPluginsManager", "CleanupPlugins EXECUTE");
                string minerPluginsPath          = Paths.MinerPluginsPath();
                var    zipPackages               = Directory.GetFiles(Paths.RootPath("plugins_packages"), "*.zip", SearchOption.TopDirectoryOnly);
                var    installedExternalPackages = Directory.GetDirectories(minerPluginsPath, "*", SearchOption.TopDirectoryOnly);
                foreach (var installedPath in installedExternalPackages)
                {
                    try
                    {
                        var uuid = installedPath.Replace(minerPluginsPath, "").Trim('\\');
                        if (!System.Guid.TryParse(uuid, out var _))
                        {
                            continue;
                        }
                        //if (!AcceptedPlugins.IsAccepted(uuid)) {
                        //    Logger.Info("MinerPluginsManager", $"CleanupPlugins Skipping {uuid}");
                        //    continue;
                        //}
                        Logger.Info("MinerPluginsManager", $"CleanupPlugins Replacing {uuid}");
                        var zipPackage = zipPackages.FirstOrDefault(package => package.Contains(uuid));
                        if (zipPackage == null)
                        {
                            continue;
                        }
                        // cleanup old bins and dll's
                        var removePackageDirBins = getObsoletePaths(Path.Combine(installedPath, "bins"));
                        foreach (var removeDir in removePackageDirBins)
                        {
                            deleteDirOrFile(removeDir);
                        }

                        var removePackageDirDlls = getObsoletePaths(Path.Combine(installedPath, "dlls"));
                        foreach (var removeDir in removePackageDirDlls)
                        {
                            deleteDirOrFile(removeDir);
                        }

                        var installedPackageRootDlls = Directory.GetFiles(installedPath, "*.dll", SearchOption.TopDirectoryOnly);
                        if (ConfigManager.IsVersionChanged || installedPackageRootDlls.Length > 1)
                        {
                            foreach (var dllFile in installedPackageRootDlls)
                            {
                                deleteDirOrFile(dllFile);
                            }
                            await ArchiveHelpers.ExtractFileAsync(null, zipPackage, installedPath, null, CancellationToken.None);
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.Error("MinerPluginsManager", $"CleanupPlugins {installedPath} Error: {e.Message}");
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error("MinerPluginsManager", $"CleanupPlugins Error: {e.Message}");
            }
        }
Ejemplo n.º 22
0
        public void TestSaveOar()
        {
            TestHelpers.InMethod();
//            log4net.Config.XmlConfigurator.Configure();

            SceneObjectGroup sog1;
            SceneObjectGroup sog2;
            UUID             ncAssetUuid;

            CreateTestObjects(m_scene, out sog1, out sog2, out ncAssetUuid);

            MemoryStream archiveWriteStream = new MemoryStream();

            m_scene.EventManager.OnOarFileSaved += SaveCompleted;

            Guid requestId = new Guid("00000000-0000-0000-0000-808080808080");

            lock (this)
            {
                m_archiverModule.ArchiveRegion(archiveWriteStream, requestId);
                //AssetServerBase assetServer = (AssetServerBase)scene.CommsManager.AssetCache.AssetServer;
                //while (assetServer.HasWaitingRequests())
                //    assetServer.ProcessNextRequest();

                Monitor.Wait(this, 60000);
            }

            Assert.That(m_lastRequestId, Is.EqualTo(requestId));

            byte[]           archive           = archiveWriteStream.ToArray();
            MemoryStream     archiveReadStream = new MemoryStream(archive);
            TarArchiveReader tar = new TarArchiveReader(archiveReadStream);

            bool gotNcAssetFile = false;

            string expectedNcAssetFileName = string.Format("{0}_{1}", ncAssetUuid, "notecard.txt");

            List <string> foundPaths    = new List <string>();
            List <string> expectedPaths = new List <string>();

            expectedPaths.Add(ArchiveHelpers.CreateObjectPath(sog1));
            expectedPaths.Add(ArchiveHelpers.CreateObjectPath(sog2));

            string filePath;

            TarArchiveReader.TarEntryType tarEntryType;

            byte[] data = tar.ReadEntry(out filePath, out tarEntryType);
            Assert.That(filePath, Is.EqualTo(ArchiveConstants.CONTROL_FILE_PATH));

            Dictionary <string, object> archiveOptions = new Dictionary <string, object>();
            ArchiveReadRequest          arr            = new ArchiveReadRequest(m_scene, (Stream)null, Guid.Empty, archiveOptions);

            arr.LoadControlFile(filePath, data, new DearchiveScenesInfo());

            Assert.That(arr.ControlFileLoaded, Is.True);

            while (tar.ReadEntry(out filePath, out tarEntryType) != null)
            {
                if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH))
                {
                    string fileName = filePath.Remove(0, ArchiveConstants.ASSETS_PATH.Length);

                    Assert.That(fileName, Is.EqualTo(expectedNcAssetFileName));
                    gotNcAssetFile = true;
                }
                else if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH))
                {
                    foundPaths.Add(filePath);
                }
            }

            Assert.That(gotNcAssetFile, Is.True, "No notecard asset file in archive");
            Assert.That(foundPaths, Is.EquivalentTo(expectedPaths));

            // TODO: Test presence of more files and contents of files.
        }
Ejemplo n.º 23
0
        public void TestSaveOarNoAssets()
        {
            TestHelpers.InMethod();
//            log4net.Config.XmlConfigurator.Configure();

            SceneObjectPart  part1 = CreateSceneObjectPart1();
            SceneObjectGroup sog1  = new SceneObjectGroup(part1);

            m_scene.AddNewSceneObject(sog1, false);

            SceneObjectPart part2 = CreateSceneObjectPart2();

            AssetNotecard nc = new AssetNotecard();

            nc.BodyText = "Hello World!";
            nc.Encode();
            UUID      ncAssetUuid = new UUID("00000000-0000-0000-1000-000000000000");
            UUID      ncItemUuid  = new UUID("00000000-0000-0000-1100-000000000000");
            AssetBase ncAsset
                = AssetHelpers.CreateAsset(ncAssetUuid, AssetType.Notecard, nc.AssetData, UUID.Zero);

            m_scene.AssetService.Store(ncAsset);
            SceneObjectGroup  sog2 = new SceneObjectGroup(part2);
            TaskInventoryItem ncItem
                = new TaskInventoryItem {
                Name = "ncItem", AssetID = ncAssetUuid, ItemID = ncItemUuid
                };

            part2.Inventory.AddInventoryItem(ncItem, true);

            m_scene.AddNewSceneObject(sog2, false);

            MemoryStream archiveWriteStream = new MemoryStream();

            Guid requestId = new Guid("00000000-0000-0000-0000-808080808080");

            Dictionary <string, Object> options = new Dictionary <string, Object>();

            options.Add("noassets", true);
            m_archiverModule.ArchiveRegion(archiveWriteStream, requestId, options);

            // Don't wait for completion - with --noassets save oar happens synchronously
//                Monitor.Wait(this, 60000);

            Assert.That(m_lastRequestId, Is.EqualTo(requestId));

            byte[]           archive           = archiveWriteStream.ToArray();
            MemoryStream     archiveReadStream = new MemoryStream(archive);
            TarArchiveReader tar = new TarArchiveReader(archiveReadStream);

            List <string> foundPaths    = new List <string>();
            List <string> expectedPaths = new List <string>();

            expectedPaths.Add(ArchiveHelpers.CreateObjectPath(sog1));
            expectedPaths.Add(ArchiveHelpers.CreateObjectPath(sog2));

            string filePath;

            TarArchiveReader.TarEntryType tarEntryType;

            byte[] data = tar.ReadEntry(out filePath, out tarEntryType);
            Assert.That(filePath, Is.EqualTo(ArchiveConstants.CONTROL_FILE_PATH));

            Dictionary <string, object> archiveOptions = new Dictionary <string, object>();
            ArchiveReadRequest          arr            = new ArchiveReadRequest(m_scene, (Stream)null, Guid.Empty, archiveOptions);

            arr.LoadControlFile(filePath, data, new DearchiveScenesInfo());

            Assert.That(arr.ControlFileLoaded, Is.True);

            while (tar.ReadEntry(out filePath, out tarEntryType) != null)
            {
                if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH))
                {
                    Assert.Fail("Asset was found in saved oar of TestSaveOarNoAssets()");
                }
                else if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH))
                {
                    foundPaths.Add(filePath);
                }
            }

            Assert.That(foundPaths, Is.EquivalentTo(expectedPaths));

            // TODO: Test presence of more files and contents of files.
        }
Ejemplo n.º 24
0
        public RegionData LoadBackup(string file)
        {
            if (!File.Exists(file))
            {
                return(null);
            }

            var stream = ArchiveHelpers.GetStream(file);

            if (stream == null)
            {
                return(null);
            }

            GZipStream       m_loadStream  = new GZipStream(stream, CompressionMode.Decompress);
            TarArchiveReader reader        = new TarArchiveReader(m_loadStream);
            List <uint>      foundLocalIDs = new List <uint>();
            RegionData       regiondata    = new RegionData();

            regiondata.Init();

            byte[] data;
            string filePath;

            TarArchiveReader.TarEntryType entryType;
            System.Collections.Concurrent.ConcurrentQueue <byte[]> groups =
                new System.Collections.Concurrent.ConcurrentQueue <byte[]>();
            //Load the archive data that we need
            while ((data = reader.ReadEntry(out filePath, out entryType)) != null)
            {
                if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType)
                {
                    continue;
                }

                if (filePath.StartsWith("parcels/"))
                {
                    //Only use if we are not merging
                    LandData parcel     = new LandData();
                    OSD      parcelData = OSDParser.DeserializeLLSDBinary(data);
                    parcel.FromOSD((OSDMap)parcelData);
                    if (parcel.OwnerID != UUID.Parse("05948863-b678-433e-87a4-e44d17678d1d"))
                    {
                        //The default owner of the 'default' region
                        regiondata.Parcels.Add(parcel);
                    }
                }
                else if (filePath.StartsWith("newstyleterrain/"))
                {
                    regiondata.Terrain = data;
                }
                else if (filePath.StartsWith("newstylerevertterrain/"))
                {
                    regiondata.RevertTerrain = data;
                }
                else if (filePath.StartsWith("newstylewater/"))
                {
                    regiondata.Water = data;
                }
                else if (filePath.StartsWith("newstylerevertwater/"))
                {
                    regiondata.RevertWater = data;
                }
                else if (filePath.StartsWith("entities/"))
                {
                    groups.Enqueue(data);
                }
                else if (filePath.StartsWith("regioninfo/"))
                {
                    RegionInfo info = new RegionInfo();
                    info.FromOSD((OSDMap)OSDParser.DeserializeLLSDBinary(data));
                    regiondata.RegionInfo = info;
                }
                data = null;
            }
            m_loadStream.Close();
            m_loadStream = null;

            int threadCount = groups.Count > 16 ? 16 : groups.Count;

            System.Threading.Thread[] threads = new System.Threading.Thread[threadCount];
            for (int i = 0; i < threadCount; i++)
            {
                threads[i] = new System.Threading.Thread(() =>
                {
                    byte[] groupData;
                    while (groups.TryDequeue(out groupData))
                    {
                        MemoryStream ms          = new MemoryStream(groupData);
                        ISceneEntity sceneObject =
                            SceneEntitySerializer.SceneObjectSerializer
                            .FromXml2Format(ref ms,
                                            null);
                        ms.Close();
                        ms   = null;
                        data = null;
                        if (sceneObject != null)
                        {
                            foreach (
                                ISceneChildEntity part in
                                sceneObject.ChildrenEntities())
                            {
                                lock (foundLocalIDs)
                                {
                                    if (
                                        !foundLocalIDs.Contains(
                                            part.LocalId))
                                    {
                                        foundLocalIDs.Add(part.LocalId);
                                    }
                                    else
                                    {
                                        part.LocalId = 0;
                                    }
                                    //Reset it! Only use it once!
                                }
                            }
                            regiondata.Groups.Add(
                                sceneObject as SceneObjectGroup);
                        }
                    }
                });
                threads[i].Start();
            }
            for (int i = 0; i < threadCount; i++)
            {
                threads[i].Join();
            }

            foundLocalIDs.Clear();

            return(regiondata);
        }
Ejemplo n.º 25
0
        public void TestSaveMultiRegionOar()
        {
            TestHelpers.InMethod();

            // Create test regions

            int WIDTH  = 2;
            int HEIGHT = 2;

            List <Scene> scenes = new List <Scene>();

            // Maps (Directory in OAR file -> scene)
            Dictionary <string, Scene> regionPaths = new Dictionary <string, Scene>();

            // Maps (Scene -> expected object paths)
            Dictionary <UUID, List <string> > expectedPaths = new Dictionary <UUID, List <string> >();

            // List of expected assets
            List <UUID> expectedAssets = new List <UUID>();

            for (uint y = 0; y < HEIGHT; y++)
            {
                for (uint x = 0; x < WIDTH; x++)
                {
                    Scene scene;
                    if (x == 0 && y == 0)
                    {
                        scene = m_scene;   // this scene was already created in SetUp()
                    }
                    else
                    {
                        scene = m_sceneHelpers.SetupScene(string.Format("Unit test region {0}", (y * WIDTH) + x + 1), UUID.Random(), 1000 + x, 1000 + y);
                        SceneHelpers.SetupSceneModules(scene, new ArchiverModule(), m_serialiserModule, new TerrainModule());
                    }
                    scenes.Add(scene);

                    string dir = String.Format("{0}_{1}_{2}", x + 1, y + 1, scene.RegionInfo.RegionName.Replace(" ", "_"));
                    regionPaths[dir] = scene;

                    SceneObjectGroup sog1;
                    SceneObjectGroup sog2;
                    UUID             ncAssetUuid;

                    CreateTestObjects(scene, out sog1, out sog2, out ncAssetUuid);

                    expectedPaths[scene.RegionInfo.RegionID] = new List <string>();
                    expectedPaths[scene.RegionInfo.RegionID].Add(ArchiveHelpers.CreateObjectPath(sog1));
                    expectedPaths[scene.RegionInfo.RegionID].Add(ArchiveHelpers.CreateObjectPath(sog2));

                    expectedAssets.Add(ncAssetUuid);
                }
            }

            // Save OAR
            MemoryStream archiveWriteStream = new MemoryStream();

            m_scene.EventManager.OnOarFileSaved += SaveCompleted;

            Guid requestId = new Guid("00000000-0000-0000-0000-808080808080");

            Dictionary <string, Object> options = new Dictionary <string, Object>();

            options.Add("all", true);

            lock (this)
            {
                m_archiverModule.ArchiveRegion(archiveWriteStream, requestId, options);
                Monitor.Wait(this, 60000);
            }


            // Check that the OAR contains the expected data
            Assert.That(m_lastRequestId, Is.EqualTo(requestId));

            byte[]           archive           = archiveWriteStream.ToArray();
            MemoryStream     archiveReadStream = new MemoryStream(archive);
            TarArchiveReader tar = new TarArchiveReader(archiveReadStream);

            Dictionary <UUID, List <string> > foundPaths = new Dictionary <UUID, List <string> >();
            List <UUID> foundAssets = new List <UUID>();

            foreach (Scene scene in scenes)
            {
                foundPaths[scene.RegionInfo.RegionID] = new List <string>();
            }

            string filePath;

            TarArchiveReader.TarEntryType tarEntryType;

            byte[] data = tar.ReadEntry(out filePath, out tarEntryType);
            Assert.That(filePath, Is.EqualTo(ArchiveConstants.CONTROL_FILE_PATH));

            Dictionary <string, object> archiveOptions = new Dictionary <string, object>();
            ArchiveReadRequest          arr            = new ArchiveReadRequest(m_scene, (Stream)null, Guid.Empty, archiveOptions);

            arr.LoadControlFile(filePath, data, new DearchiveScenesInfo());

            Assert.That(arr.ControlFileLoaded, Is.True);

            while (tar.ReadEntry(out filePath, out tarEntryType) != null)
            {
                if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH))
                {
                    // Assets are shared, so this file doesn't belong to any specific region.
                    string fileName = filePath.Remove(0, ArchiveConstants.ASSETS_PATH.Length);
                    if (fileName.EndsWith("_notecard.txt"))
                    {
                        foundAssets.Add(UUID.Parse(fileName.Substring(0, fileName.Length - "_notecard.txt".Length)));
                    }
                }
                else
                {
                    // This file belongs to one of the regions. Find out which one.
                    Assert.IsTrue(filePath.StartsWith(ArchiveConstants.REGIONS_PATH));
                    string[] parts = filePath.Split(new Char[] { '/' }, 3);
                    Assert.AreEqual(3, parts.Length);
                    string regionDirectory = parts[1];
                    string relativePath    = parts[2];
                    Scene  scene           = regionPaths[regionDirectory];

                    if (relativePath.StartsWith(ArchiveConstants.OBJECTS_PATH))
                    {
                        foundPaths[scene.RegionInfo.RegionID].Add(relativePath);
                    }
                }
            }

            Assert.AreEqual(scenes.Count, foundPaths.Count);
            foreach (Scene scene in scenes)
            {
                Assert.That(foundPaths[scene.RegionInfo.RegionID], Is.EquivalentTo(expectedPaths[scene.RegionInfo.RegionID]));
            }

            Assert.That(foundAssets, Is.EquivalentTo(expectedAssets));
        }