Exemplo n.º 1
0
        public void SectorCollectionConstructorTest()
        {
            SectorCollection target = new SectorCollection();

            Assert.IsNotNull(target);
            Assert.IsTrue(target.Count == 0);

            Sector s = new Sector(4096);

            target.Add(s);
            Assert.IsTrue(target.Count == 1);
        }
        public void AssignSectorTest()
        {
            var range      = new SectorRange(1000, 2000);
            var sector     = CreateMock <ISector>();
            var collection = new SectorCollection();

            collection.AssignSector(range, sector);

            var sectors = collection.EnumerateSectors().ToList();

            AssertEquals(1, sectors.Count);
            AssertEquals(sector, sectors[0]);
            VerifyNoMoreInteractions();
        }
Exemplo n.º 3
0
        public void AddTest()
        {
            SectorCollection target = new SectorCollection();

            for (int i = 0; i < 579; i++)
            {
                target.Add(null);
            }


            Sector item = new Sector(4096);

            target.Add(item);
            Assert.IsTrue(target.Count == 580);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Builds a directory entry and populates its correct type, children and siblings.
        /// </summary>
        /// <param name="entry">The directory sector entry.</param>
        /// <param name="entries">The current entries.</param>
        /// <param name="sectors">The data sectors.</param>
        /// <param name="fat">The FAT.</param>
        /// <returns>The correct DirectoryEntry object.</returns>
        public static DirectoryEntry CreateEntry(DirectorySectorEntry entry,
                                                 DirectorySectorEntryCollection entries,
                                                 SectorCollection sectors,
                                                 Sect[] fat)
        {
            DirectoryEntry newEntry = null;

            switch (entry.Type)
            {
            case Stgty.Storage:
                newEntry = new StorageEntry(entry.Name);
                break;

            case Stgty.Stream:
                newEntry = new StreamEntry(entry.Name, entry.Size, entry.SectStart, sectors, fat);
                break;

            default:
                newEntry = new GenericDirectoryEntry(entry.Name, entry.Type);
                break;
            }

            if (!entry.LeftSibling.IsEof)
            {
                newEntry.LeftSibling = CreateEntry(entries[entry.LeftSibling],
                                                   entries,
                                                   sectors,
                                                   fat);
            }

            if (!entry.RightSibling.IsEof)
            {
                newEntry.RightSibling = CreateEntry(entries[entry.RightSibling],
                                                    entries,
                                                    sectors,
                                                    fat);
            }

            if (!entry.Child.IsEof)
            {
                newEntry.Child = CreateEntry(entries[entry.Child],
                                             entries,
                                             sectors,
                                             fat);
            }

            return(newEntry);
        }
        public void DeletePastEndDoesNothingTest()
        {
            var initialRange  = new SectorRange(0, 1000);
            var initialSector = CreateMock <ISector>();
            var collection    = new SectorCollection(initialRange.PairValue(initialSector).Wrap());

            collection.DeleteRange(new SectorRange(1000, 2000));

            var pairs = collection.EnumerateSectorPairs();

            AssertEquals(1, pairs.Count);
            AssertEquals(0, pairs[0].Key.startInclusive);
            AssertEquals(1000, pairs[0].Key.endExclusive);
            AssertEquals(initialSector, pairs[0].Value);

            VerifyNoMoreInteractions();
        }
        public void AssignToSectorEndTest()
        {
            var firstRange   = new SectorRange(0, 1000);
            var secondRange  = new SectorRange(1000, 2000);
            var firstSector  = CreateMock <ISector>();
            var secondSector = CreateMock <ISector>();
            var collection   = new SectorCollection();

            collection.AssignSector(firstRange, firstSector);
            collection.AssignSector(secondRange, secondSector);
            var sectorPairs = collection.EnumerateSectorPairs().ToList();

            AssertEquals(2, sectorPairs.Count);
            AssertEquals(new SectorRange(0, 1000), sectorPairs[0].Key);
            AssertEquals(firstSector, sectorPairs[0].Value);
            AssertEquals(new SectorRange(1000, 2000), sectorPairs[1].Key);
            AssertEquals(secondSector, sectorPairs[1].Value);
            VerifyNoMoreInteractions();
        }
Exemplo n.º 7
0
        public void CountTest()
        {
            
            int count = 0;

            SectorCollection target = new SectorCollection(); // TODO: Initialize to an appropriate value
            int actual;
            actual = target.Count;

            Assert.IsTrue(actual == count);
            Sector s = new Sector(4096);

            target.Add(s);
            Assert.IsTrue(target.Count == actual + 1);


            for (int i = 0; i < 5000; i++)
                target.Add(s);

            Assert.IsTrue(target.Count == actual + 1 + 5000);
        }
Exemplo n.º 8
0
        public void ItemTest()
        {
            int count = 37;

            SectorCollection target = new SectorCollection();
            int index = 0;

            Sector expected = new Sector(4096);

            target.Add(null);

            Sector actual;

            target[index] = expected;
            actual        = target[index];

            Assert.AreEqual(expected, actual);
            Assert.IsNotNull(actual);
            Assert.IsTrue(actual.Id == expected.Id);

            actual = null;

            try
            {
                actual = target[count + 100];
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex is CFException);
            }

            try
            {
                actual = target[-1];
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex is CFException);
            }
        }
		/// <summary>
		/// Builds a directory entry and populates its correct type, children and siblings.
		/// </summary>
		/// <param name="entry">The directory sector entry.</param>
		/// <param name="entries">The current entries.</param>
		/// <param name="sectors">The data sectors.</param>
		/// <param name="fat">The FAT.</param>
		/// <returns>The correct DirectoryEntry object.</returns>
		public static DirectoryEntry CreateEntry(DirectorySectorEntry entry, 
			DirectorySectorEntryCollection entries, 
			SectorCollection sectors, 
			Sect[] fat)
		{
			DirectoryEntry newEntry = null;
			switch(entry.Type)
			{
				case Stgty.Storage :
					newEntry = new StorageEntry(entry.Name);
					break;
				case Stgty.Stream :
					newEntry = new StreamEntry(entry.Name, entry.Size, entry.SectStart, sectors, fat);
					break;
				default:
					newEntry = new GenericDirectoryEntry(entry.Name, entry.Type);
					break;
			}

			if(!entry.LeftSibling.IsEof)
				newEntry.LeftSibling = CreateEntry(entries[entry.LeftSibling],
					entries,
					sectors,
					fat);

			if(!entry.RightSibling.IsEof)
				newEntry.RightSibling = CreateEntry(entries[entry.RightSibling],
					entries,
					sectors,
					fat);

			if(!entry.Child.IsEof)
				newEntry.Child = CreateEntry(entries[entry.Child],
					entries,
					sectors,
					fat);

			return newEntry;
		}
Exemplo n.º 10
0
		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="name">The entry Name.</param>
		/// <param name="length">The stream length.</param>
		/// <param name="dataOffset">Data offset.</param>
		/// <param name="sectors">The sectors.</param>
		/// <param name="fat">The FAT.</param>
		public StreamEntry(string name, long length, Sect dataOffset, SectorCollection sectors, Sect[] fat) : base(name)
		{
			_length = length;
			_data = new byte[length];

			if(!dataOffset.IsEndOfChain)
			{
				int left = (int)length;
				MemoryStream stream = new MemoryStream(_data);
				Sect sect = dataOffset;

				do
				{
					try
					{
						StorageSector sector = (StorageSector)sectors[sect];

						int toWrite = Math.Min(sector.Data.Length, left);
						Debug.Assert(toWrite <= 512);
						stream.Write(sector.Data, 0, toWrite);
						left -= toWrite;

						sect = fat[sect.ToInt()];
					}
					catch(Exception err)
					{
						Debug.WriteLine("Stream name is " + name);
						Debug.WriteLine(err.Message);
						Debug.WriteLine(err.StackTrace);

						return;
					}
				} while(!sect.IsEndOfChain);

				Debug.Assert(left == 0);
				Debug.Assert(stream.Length == stream.Position);
			}
		}
Exemplo n.º 11
0
        public void CountTest()
        {
            int count = 0;

            SectorCollection target = new SectorCollection(); // TODO: Initialize to an appropriate value
            int actual;

            actual = target.Count;

            Assert.IsTrue(actual == count);
            Sector s = new Sector(4096);

            target.Add(s);
            Assert.IsTrue(target.Count == actual + 1);


            for (int i = 0; i < 5000; i++)
            {
                target.Add(s);
            }

            Assert.IsTrue(target.Count == actual + 1 + 5000);
        }
        public void DeleteRangeTest()
        {
            var initialRange                = new SectorRange(0, 1000);
            var initialSector               = CreateMock <ISector>();
            var chopRange                   = new SectorRange(250, 750);
            var leftSector                  = CreateMock <ISector>();
            var leftRange                   = new SectorRange(0, 250);
            var rightSector                 = CreateMock <ISector>();
            var rightRange                  = new SectorRange(750, 1000);
            var leftAndRightRange           = new[] { leftRange, rightRange };
            var leftAndRightSectors         = new[] { leftSector, rightSector };
            var leftAndRightRangeAndSectors = new[] { leftRange.PairValue(leftSector), rightRange.PairValue(rightSector) };

            When(initialSector.Segment(Eq(initialRange), EqSequence(leftAndRightRange))).ThenReturn(leftAndRightRangeAndSectors);

            var collection = new SectorCollection(new KeyValuePair <SectorRange, ISector>(initialRange, initialSector).Wrap());

            collection.DeleteRange(chopRange);

            Verify(initialSector).Segment(Eq(initialRange), Any <IEnumerable <SectorRange> >(x => x.SequenceEqual(leftAndRightRange)));
            VerifyNoMoreInteractions();

            AssertTrue(leftAndRightSectors.SequenceEqual(collection.EnumerateSectors()));
        }
Exemplo n.º 13
0
        public void GetEnumeratorTest()
        {
            SectorCollection target = new SectorCollection();

            for (int i = 0; i < 579; i++)
            {
                target.Add(null);
            }


            Sector item = new Sector(4096);

            target.Add(item);
            Assert.IsTrue(target.Count == 580);

            int cnt = 0;

            foreach (Sector s in target)
            {
                cnt++;
            }

            Assert.IsTrue(cnt == target.Count);
        }
Exemplo n.º 14
0
        public void SectorCollectionConstructorTest()
        {

            SectorCollection target = new SectorCollection();

            Assert.IsNotNull(target);
            Assert.IsTrue(target.Count == 0);

            Sector s = new Sector(4096);
            target.Add(s);
            Assert.IsTrue(target.Count == 1);
        }
Exemplo n.º 15
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="entries">The directory sector entries.</param>
 /// <param name="sectors">All the sectors.</param>
 /// <param name="fat">The FAT.</param>
 public Directory(DirectorySectorEntryCollection entries, SectorCollection sectors, Sect[] fat)
 {
     _root = DirectoryEntryFactory.CreateEntry(entries[Sid.ZERO], entries, sectors, fat);
 }
Exemplo n.º 16
0
		private void Init(Stream stream)
		{
			// stream size sanity checker
			// compound files are always blocks of 512 bytes
			Debug.Assert((stream.Length % 512) == 0);
			
			// read in the first sector
			StorageSector sector = new StorageSector(stream);
			// interpret sector as header sector
			HeaderSector header = new HeaderSector(sector.GetStream());

			// read in all remaining sectors
			SectorCollection sectors = new SectorCollection((int)(stream.Length / Constants.SECTOR_SIZE));
			while(stream.Position != stream.Length)
			{
				sector = new StorageSector(stream);
				sectors.Add(sector);
			}

			// build the fat index
			List<Sect> index = new List<Sect>((int)(Constants.MAX_SECT * header.SectFatCount));

			// read first 109 fat entries
			for(int i = 0; i < header.SectFat.Length; ++i)
			{
				Sect fatSect = header.SectFat[i];
				if(!fatSect.IsFree)
				{
					FatSector fat = new FatSector(((StorageSector)sectors[fatSect]).GetStream());
					index.AddRange(fat.SectFat);
					sectors[fatSect] = fat;
				}
			}

			// read remaining fat entries
			int difCount;
			Sect difIndex;									 
			for(difIndex = header.SectDifStart, difCount = 0;
				!difIndex.IsEndOfChain && difCount < header.SectDifCount; 
				++difCount)
			{
				DifSector dif = new DifSector(((StorageSector)sectors[difIndex]).GetStream());
				sectors[difIndex] = dif;

				for(int i = 0; i < dif.SectFat.Length; ++i)
				{
					Sect fatSect = dif.SectFat[i];

					if(!fatSect.IsFree)
					{
						FatSector fat = new FatSector(((StorageSector)sectors[fatSect]).GetStream());
						index.AddRange(fat.SectFat);
						sectors[fatSect] = fat;
					}
				}
				
				difIndex = dif.NextDif;
			}
			Debug.Assert(difCount == header.SectDifCount);

			// read in mini fat sectors
			Debug.Assert(index.Count == (header.SectFatCount * Constants.MAX_SECT));
			Debug.Assert(index.Capacity == index.Count);

			Sect[] fatSects = index.ToArray();

			Sect miniFatSect;
			int miniFatCount;
			for(miniFatSect = header.SectMiniFatStart, miniFatCount = 0;
				!miniFatSect.IsEndOfChain && miniFatCount < header.SectMiniFatCount;
				miniFatSect = fatSects[miniFatSect.ToInt()], ++miniFatCount)
			{
				MiniFatSector miniFat = new MiniFatSector(((StorageSector)sectors[miniFatSect]).GetStream());
				sectors[miniFatSect] = miniFat;
			}

			Debug.Assert(miniFatCount == header.SectMiniFatCount);

			// read in directory sectors
			DirectorySectorEntryCollection dirs = new DirectorySectorEntryCollection();

			for(Sect dirSect = header.SectDirStart;
				!dirSect.IsEndOfChain;
				dirSect = fatSects[dirSect.ToInt()])
			{
				DirectorySector dir = new DirectorySector(((StorageSector)sectors[dirSect]).GetStream());
				
				foreach(DirectorySectorEntry entry in dir.Entries)
					dirs.Add(entry);

				sectors[dirSect] = dir;
			}

			_directory = new Directory(dirs, sectors, fatSects);
		}
Exemplo n.º 17
0
        public void ItemTest()
        {
            int count = 37;

            SectorCollection target = new SectorCollection();
            int index = 0;

            Sector expected = new Sector(4096);
            target.Add(null);

            Sector actual;
            target[index] = expected;
            actual = target[index];

            Assert.AreEqual(expected, actual);
            Assert.IsNotNull(actual);
            Assert.IsTrue(actual.Id == expected.Id);

            actual = null;

            try
            {
                actual = target[count + 100];
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex is ArgumentOutOfRangeException);
            }

            try
            {
                actual = target[-1];
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex is ArgumentOutOfRangeException);
            }
        }
Exemplo n.º 18
0
        private void Init(Stream stream)
        {
            // stream size sanity checker
            // compound files are always blocks of 512 bytes
            Debug.Assert((stream.Length % 512) == 0);

            // read in the first sector
            StorageSector sector = new StorageSector(stream);
            // interpret sector as header sector
            HeaderSector header = new HeaderSector(sector.GetStream());

            // read in all remaining sectors
            SectorCollection sectors = new SectorCollection((int)(stream.Length / Constants.SECTOR_SIZE));

            while (stream.Position != stream.Length)
            {
                sector = new StorageSector(stream);
                sectors.Add(sector);
            }

            // build the fat index
            List <Sect> index = new List <Sect>((int)(Constants.MAX_SECT * header.SectFatCount));

            // read first 109 fat entries
            for (int i = 0; i < header.SectFat.Length; ++i)
            {
                Sect fatSect = header.SectFat[i];
                if (!fatSect.IsFree)
                {
                    FatSector fat = new FatSector(((StorageSector)sectors[fatSect]).GetStream());
                    index.AddRange(fat.SectFat);
                    sectors[fatSect] = fat;
                }
            }

            // read remaining fat entries
            int  difCount;
            Sect difIndex;

            for (difIndex = header.SectDifStart, difCount = 0;
                 !difIndex.IsEndOfChain && difCount < header.SectDifCount;
                 ++difCount)
            {
                DifSector dif = new DifSector(((StorageSector)sectors[difIndex]).GetStream());
                sectors[difIndex] = dif;

                for (int i = 0; i < dif.SectFat.Length; ++i)
                {
                    Sect fatSect = dif.SectFat[i];

                    if (!fatSect.IsFree)
                    {
                        FatSector fat = new FatSector(((StorageSector)sectors[fatSect]).GetStream());
                        index.AddRange(fat.SectFat);
                        sectors[fatSect] = fat;
                    }
                }

                difIndex = dif.NextDif;
            }
            Debug.Assert(difCount == header.SectDifCount);

            // read in mini fat sectors
            Debug.Assert(index.Count == (header.SectFatCount * Constants.MAX_SECT));
            Debug.Assert(index.Capacity == index.Count);

            Sect[] fatSects = index.ToArray();

            Sect miniFatSect;
            int  miniFatCount;

            for (miniFatSect = header.SectMiniFatStart, miniFatCount = 0;
                 !miniFatSect.IsEndOfChain && miniFatCount < header.SectMiniFatCount;
                 miniFatSect = fatSects[miniFatSect.ToInt()], ++miniFatCount)
            {
                MiniFatSector miniFat = new MiniFatSector(((StorageSector)sectors[miniFatSect]).GetStream());
                sectors[miniFatSect] = miniFat;
            }

            Debug.Assert(miniFatCount == header.SectMiniFatCount);

            // read in directory sectors
            DirectorySectorEntryCollection dirs = new DirectorySectorEntryCollection();

            for (Sect dirSect = header.SectDirStart;
                 !dirSect.IsEndOfChain;
                 dirSect = fatSects[dirSect.ToInt()])
            {
                DirectorySector dir = new DirectorySector(((StorageSector)sectors[dirSect]).GetStream());

                foreach (DirectorySectorEntry entry in dir.Entries)
                {
                    dirs.Add(entry);
                }

                sectors[dirSect] = dir;
            }

            _directory = new Directory(dirs, sectors, fatSects);
        }
Exemplo n.º 19
0
        public CommandList LinkGameModifications(IReadOnlyList <Modification> modifications)
        {
            var archiveLoader = new RiotArchiveLoader(leagueConfiguration.RadsPath);
            Dictionary <uint, List <KeyValuePair <RiotArchive, SectorCollection> > > archivePairsById = new Dictionary <uint, List <KeyValuePair <RiotArchive, SectorCollection> > >();

            var riotSolution = riotSolutionLoader.Load(leagueConfiguration.RadsPath, RiotProjectType.GameClient);
            var gameProject  = riotSolution.ProjectsByType[RiotProjectType.GameClient];
            var gameManifest = gameProject.ReleaseManifest;

            foreach (var modification in modifications)
            {
                var resolutionTableComponent = modification.GetComponent <LeagueResolutionTableComponent>();
                var resolutionTable          = resolutionTableComponent.Table;
                var contentPath          = Path.Combine(modification.RepositoryPath, "content");
                var contentDirectory     = fileSystemProxy.GetDirectoryInfo(contentPath);
                var contentFiles         = contentDirectory.EnumerateFiles("*", SearchOption.AllDirectories);
                var contentRelativePaths = contentFiles.Select(f => f.FullName.Substring(contentPath.Length + 1));
                var objectsPath          = Path.Combine(modification.RepositoryPath, "objects");

                foreach (var contentRelativePath in contentRelativePaths)
                {
                    LeagueResolutionTableValue resolutionTableValue;
                    if (!resolutionTable.TryGetValue(contentRelativePath, out resolutionTableValue))
                    {
                        logger?.Warn($"Not linking {contentRelativePath}: resolution table lookup failed");
                        continue;
                    }
                    if (resolutionTableValue.Target != LeagueModificationTarget.Game)
                    {
                        logger?.Warn($"Not linking {contentRelativePath}: does not target game client.");
                        continue;
                    }
                    var manifestEntry = gameManifest.Root.GetRelativeOrNull <ReleaseManifestFileEntry>(resolutionTableValue.ResolvedPath);
                    if (manifestEntry == null)
                    {
                        logger?.Warn($"Not linking {contentRelativePath}: could not find {resolutionTableValue.ResolvedPath} in manifest.");
                        continue;
                    }

                    List <KeyValuePair <RiotArchive, SectorCollection> > archivePairs;
                    if (!archivePairsById.TryGetValue(manifestEntry.ArchiveId, out archivePairs))
                    {
                        archivePairs = new List <KeyValuePair <RiotArchive, SectorCollection> >();
                        IReadOnlyList <RiotArchive> archives;
                        if (!archiveLoader.TryLoadArchives(manifestEntry.ArchiveId, out archives))
                        {
                            logger?.Error($"Not linking {contentRelativePath}: could not load archives for {manifestEntry.ArchiveId}!");
                            continue;
                        }
                        archives.ForEach(archive => {
                            var datLength = new FileInfo(archive.DatFilePath).Length;
                            SectorCollection sectorCollection = new SectorCollection();
                            sectorCollection.AssignSector(new SectorRange(0, datLength), new FileSector(archive.DatFilePath, 0, datLength));
                            archivePairs.Add(archive.PairValue(sectorCollection));
                        });
                        archivePairsById.Add(manifestEntry.ArchiveId, archivePairs);
                    }

                    var rafPath = RAFUtil.FormatPathToRAFPath(resolutionTableValue.ResolvedPath);
                    RAFFileListEntry rafEntry = null;
                    SectorCollection sectors  = null;
                    foreach (var archivePair in archivePairs)
                    {
                        rafEntry = archivePair.Key.GetDirectoryFile().GetFileList().GetFileEntryOrNull(rafPath);
                        if (rafEntry != null)
                        {
                            sectors = archivePair.Value;
                            break;
                        }
                    }
                    if (rafEntry == null)
                    {
                        logger?.Warn($"Not linking {contentRelativePath}: could not find {resolutionTableValue.ResolvedPath} in {manifestEntry.ArchiveId} archives.");
                        continue;
                    }

                    var vfmEndOffset = sectors.EnumerateSectorPairs().Last().Key.endExclusive;

                    sectors.DeleteRange(rafEntry.FileOffset, rafEntry.FileOffset + rafEntry.FileSize);

                    var objectsFilePath   = Path.Combine(objectsPath, contentRelativePath);
                    var objectsFileLength = new FileInfo(objectsFilePath).Length;

                    rafEntry.FileOffset = (uint)vfmEndOffset;
                    rafEntry.FileSize   = (uint)objectsFileLength;

                    sectors.AssignSector(new SectorRange(vfmEndOffset, vfmEndOffset + objectsFileLength), new FileSector(objectsFilePath, 0, objectsFileLength));

                    var originalFileLength = new FileInfo(Path.Combine(contentPath, contentRelativePath)).Length;
                    manifestEntry.CompressedSize   = (uint)objectsFileLength;
                    manifestEntry.DecompressedSize = (uint)originalFileLength;

                    logger?.Warn("Successfully linked " + resolutionTableValue.ResolvedPath + " in archive " + manifestEntry.ArchiveId + ".");
                }
            }

            var commandList            = new DefaultCommandList();
            var versionStringUtilities = new VersionStringUtilities();
            var tempDir = temporaryFileService.AllocateTemporaryDirectory(TimeSpan.FromMinutes(1));

            logger?.Info("Allocated temporary directory " + tempDir);
            foreach (var archivePair in archivePairsById)
            {
                string versionString = versionStringUtilities.GetVersionString(archivePair.Key);

                foreach (var archiveData in archivePair.Value)
                {
                    // Get archive name (e.g. archive_2.raf or archive_12930813.raf)
                    string archiveFileName = archiveData.Key.RAFFilePath.With(x => x.Substring(x.LastIndexOfAny(new[] { '/', '\\' }) + 1));

                    // Serialize the VFM
                    var vfmSerializer = new SectorCollectionSerializer();
                    var vfmFileName   = versionString + "/" + archiveFileName + ".dat.vfm";
                    var vfmPath       = temporaryFileService.AllocateTemporaryFile(tempDir, vfmFileName);
                    using (var vfmFileStream = File.Open(vfmPath, FileMode.Create, FileAccess.Write, FileShare.None))
                        using (var writer = new BinaryWriter(vfmFileStream)) {
                            vfmSerializer.Serialize(archiveData.Value, writer);
                            commandList.Add(commandFactory.CreateFileRemappingCommand(archiveData.Key.DatFilePath, vfmFileStream.Name));
                        }
                    logger?.Info("Wrote VFM " + vfmFileName + " to " + tempDir);

                    // Serialize the RAF
                    var rafFileName = versionString + "/" + archiveFileName;
                    var rafPath     = temporaryFileService.AllocateTemporaryFile(tempDir, rafFileName);
                    using (var rafFileStream = File.Open(rafPath, FileMode.Create, FileAccess.Write, FileShare.None))
                        using (var writer = new BinaryWriter(rafFileStream)) {
                            writer.Write(archiveData.Key.GetDirectoryFile().GetBytes());
                            commandList.Add(commandFactory.CreateFileRedirectionCommand(archiveData.Key.RAFFilePath, rafFileStream.Name));
                        }
                    logger?.Info("Wrote RAF " + rafFileName + " to " + tempDir);
                }
            }

            // Serialize the Release Manifest
            var manifestPath = temporaryFileService.AllocateTemporaryFile(tempDir, "releasemanifest");

            using (var manifestFileStream = File.Open(manifestPath, FileMode.Create, FileAccess.Write, FileShare.None))
                using (var writer = new BinaryWriter(manifestFileStream)) {
                    new ReleaseManifestWriter(gameManifest).Save(writer);
                    commandList.Add(commandFactory.CreateFileRedirectionCommand(gameManifest.Path, manifestFileStream.Name));
                }
            logger?.Info("Wrote release manifest to " + tempDir);
            return(commandList);
        }
Exemplo n.º 20
0
        public void GetEnumeratorTest()
        {
            SectorCollection target = new SectorCollection();
            for (int i = 0; i < 579; i++)
            {
                target.Add(null);
            }

            
            Sector item = new Sector(4096);
            target.Add(item);
            Assert.IsTrue(target.Count == 580);

            int cnt = 0;
            foreach (Sector s in target)
            {
                cnt++;
            }

            Assert.IsTrue(cnt == target.Count);
        }
Exemplo n.º 21
0
        public void AddTest()
        {
            SectorCollection target = new SectorCollection();
            for (int i = 0; i < 579; i++)
            {
                target.Add(null);
            }


            Sector item = new Sector(4096);
            target.Add(item);
            Assert.IsTrue(target.Count == 580);
        }
        /// <summary>
        ///     When called from user code, release all resources, otherwise, in the case runtime called it,
        ///     only unmanagd resources are released.
        /// </summary>
        /// <param name="disposing">If true, method has been called from User code, if false it's been called from .net runtime</param>
        protected virtual void Dispose(bool disposing)
        {
            try
            {
                if (!IsClosed)
                {
                    lock (_lockObject)
                    {
                        if (disposing)
                        {
                            // Call from user code...

                            if (_sectors != null)
                            {
                                _sectors.Clear();
                                _sectors = null;
                            }

                            RootStorage = null; // Some problem releasing resources...
                            _header = null;
                            _directoryEntries.Clear();
                            _directoryEntries = null;
                            _lockObject = null;
                            _buffer = null;
                        }

                        if (SourceStream != null)
                            SourceStream.Close();
                    }
                }
            }
            finally
            {
                IsClosed = true;
            }
        }
        /// <summary>
        ///     Load compound file from an existing stream.
        /// </summary>
        /// <param name="stream">Stream to load compound file from</param>
        private void Load(Stream stream)
        {
            try
            {
                _header = new Header();
                _directoryEntries = new List<IDirectoryEntry>();

                SourceStream = stream;

                _header.Read(stream);

                var numberOfSectors = Ceiling(((stream.Length - GetSectorSize())/(double) GetSectorSize()));

                if (stream.Length > 0x7FFFFF0)
                    TransactionLockAllocated = true;

                _sectors = new SectorCollection();
                for (var i = 0; i < numberOfSectors; i++)
                    _sectors.Add(null);

                LoadDirectories();

                RootStorage = new CFStorage(this, _directoryEntries[0]);
            }
            catch (Exception)
            {
                if (stream != null)
                    stream.Close();

                throw;
            }
        }