protected override void ProcessRecord()
		{
			var index = new FileIndex();

			foreach (var item in Items)
				index.UpdateFile(item);

			index.WriteIndex(Notify, Index);
		} // proc ProcessRecord
Beispiel #2
0
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if (_fileIndex != null)
            {
                _fileIndex.Close();
                _fileIndex = null;
            }
        }
Beispiel #3
0
        public void EnumeratesFilesFromOneIndex()
        {
            var indexFile = new IndexFile();

            indexFile.Files.Add(@"C:\pmllib\foo.pmlobj");
            indexFile.Files.Add(@"C:\pmllib\bar.pmlfrm");
            var index = new FileIndex(indexFile);

            Assert.That(index, Is.EquivalentTo(indexFile.Files));
        }
Beispiel #4
0
        public override void Initialize()
        {
            base.Initialize();

            InstallLocation install = Install;

            _fileIndex =
                install.IsUOPFormat
                    ? install.CreateFileIndex("artLegacyMUL.uop")
                    : install.CreateFileIndex("artidx.mul", "art.mul");
        }
Beispiel #5
0
        public Option <FolderPath> EndPathMonitor(CorrelationToken MonitorToken)
        {
            if (FolderIndex.TryRemove(MonitorToken, out FolderTree tree))
            {
                FileIndex.TryRemove(MonitorToken, out Dictionary <FilePath, FileDescription> content);
                Listeners.TryRemove(MonitorToken, out Action <FileChangeDescription> listener);
                return(tree.Root);
            }

            return(none <FolderPath>());
        }
Beispiel #6
0
        public override int GetHashCode()
        {
            int hash = 149;

            unchecked
            {
                hash = hash + 181 * FileIndex.GetHashCode();
                hash = hash * 173 + PathID.GetHashCode();
            }
            return(hash);
        }
Beispiel #7
0
        public override void Initialize()
        {
            base.Initialize();

            var install = Install;

            _fileIndex =
                install.IsUOPFormat
                    ? install.CreateFileIndex("gumpartLegacyMUL.uop")
                    : install.CreateFileIndex("gumpidx.mul", "gumpart.mul");
        }
Beispiel #8
0
        /// <summary>
        /// Unlocks (i.e. decrypts) the archive with the given <see cref="UserKey"/>.
        /// </summary>
        /// <param name="userKey">The <see cref="UserKey"/> to use to unlock the archive.</param>
        public void Unlock(UserKey userKey)
        {
            ArgCheck.NotNull(userKey, nameof(userKey));

            // Setting the ArchiveKey property puts the archive into the "unlocked" state.
            // Wait to set the property until after everything is properly unlocked.
            var archiveKey = this.DecryptArchiveKey(userKey);

            this.FileIndex = this.ArchiveMetadata.EncryptedFileIndex is null || this.ArchiveMetadata.EncryptedFileIndex.IsEmpty()
                ? new FileIndex()
                : FileIndex.DecryptFrom(this.ArchiveMetadata.EncryptedFileIndex, archiveKey, this.ArchiveMetadata.SecuritySettings);

            this.ArchiveKey = archiveKey;
        }
Beispiel #9
0
        public static Skill GetSkill(int index)
        {
            if (List[index] != null)
            {
                return(List[index]);
            }
            var r = FileIndex.Seek(index, out int length, out int extra, out bool patched);

            if (r == null)
            {
                return(List[index] = new Skill(SkillVars.NullV));
            }
            return(List[index] = LoadSkill(index, r));
        }
Beispiel #10
0
        public static HybridDirectoryInfo ToDirectoryInfo(this FileIndex file)
        {
            var info = new HybridDirectoryInfo();

            info.Id               = file.Id;
            info.Path             = file.Path;
            info.DirectoryPath    = file.DirectoryPath;
            info.Name             = file.Name;
            info.Length           = file.Length;
            info.LastModifiedUtc  = file.LastModifiedUtc;
            info.Visits           = file.Visits;
            info.LastVisitTimeUtc = file.LastVisitTimeUtc;

            return(info);
        }
Beispiel #11
0
        private void ParseFile()
        {
            AlternateHeader alternate = rawStream.ByteToType <AlternateHeader>();

            if (alternate.First == 0)
            {
                bool IsDigest    = (alternate.Second & 0x01) != 0;
                bool IsEncrypted = (alternate.Second & 0x02) != 0;

                MemoryStream fileIndexStream;

                if (IsEncrypted)
                {
                    fileIndexStream = DecryptHeader(4, out dataStart);
                }
                else
                {
                    fileIndexStream = new MemoryStream(rawStream.ReadBytes(fileHeader.Size * Marshal.SizeOf(typeof(FileIndex))));
                }

                fileHeader = fileIndexStream.ByteToType <FileHeader>();

                if (rawStream.Length >= dataStart + fileHeader.Size)
                {
                    this.IsValid = true;

                    // parse the index
                    for (int f = 0; f < fileHeader.Count; f++)
                    {
                        // read index
                        FileIndex fileIndex = fileIndexStream.ByteToType <FileIndex>();

                        // find file in known names
                        if (MIXDatabase.ValidFileNames.ContainsKey(fileIndex.CRC))
                        {
                            SubFile newSubFile = new SubFile
                            {
                                Name   = MIXDatabase.ValidFileNames[fileIndex.CRC],
                                Offset = fileIndex.Offset,
                                Size   = fileIndex.Size
                            };

                            Files.Add(newSubFile);
                        }
                    }
                }
            }
        }
        public void CreateArchive(string filename)
        {
            BinaryWriter bw       = new BinaryWriter(new FileStream(filename, FileMode.Create));
            FileHeader   tempHead = new FileHeader();

            tempHead.Write(bw);
            FileIndex tempFileIndex = new FileIndex();

            tempFileIndex.TotalEntries = 0;
            tempFileIndex.Write(bw);
            FolderIndex tempFolderIndex = new FolderIndex();

            tempFolderIndex.TotalEntries = 0;
            tempFolderIndex.Write(bw);
            bw.Close();
        }
        public unsafe Texture2D GetLand(int index)
        {
            index &= 0x3FFF;

            int    length, extra;
            Stream stream = FileIndex.Seek(index, out length, out extra);

            Texture2D     texture = new Texture2D(_context, 44, 44, 0, Usage.None, Format.A1R5G5B5, Pool.Managed);
            DataRectangle rect    = texture.LockRectangle(0, LockFlags.None);
            BinaryReader  bin     = new BinaryReader(stream);

            int xOffset = 21;
            int xRun    = 2;

            ushort *line  = (ushort *)rect.DataPointer;
            int     delta = rect.Pitch >> 1;

            for (int y = 0; y < 22; ++y, --xOffset, xRun += 2, line += delta)
            {
                ushort *cur = line + xOffset;
                ushort *end = cur + xRun;

                while (cur < end)
                {
                    *cur++ = (ushort)(bin.ReadUInt16() | 0x8000);
                }
            }

            xOffset = 0;
            xRun    = 44;

            for (int y = 0; y < 22; ++y, ++xOffset, xRun -= 2, line += delta)
            {
                ushort *cur = line + xOffset;
                ushort *end = cur + xRun;

                while (cur < end)
                {
                    *cur++ = (ushort)(bin.ReadUInt16() | 0x8000);
                }
            }

            texture.UnlockRectangle(0);

            return(texture);
        }
Beispiel #14
0
        public void CallsTestCaseParserWithObjectName()
        {
            var parser = new Mock <TestCaseParser>(MockBehavior.Strict);

            parser.Setup(mock => mock.Parse(@"C:\testing\path\to\some\tests\pmlrandomtest.pmlobj")).Returns(TestCase);

            var indexFile = new IndexFile();

            indexFile.Files.Add(@"C:\testing\path\to\some\tests\pmlrandomtest.pmlobj");
            var index = new FileIndex(indexFile);

            var provider = new FileIndexTestCaseProvider(index, parser.Object);
            var result   = provider.GetTestCases();

            Assert.That(result, Is.EquivalentTo(Enumerable.Repeat(TestCase, 1)));

            parser.Verify();
        }
Beispiel #15
0
        /// <summary>
        /// Creates a FileIndex with all available MMAT Files
        /// </summary>
        /// <returns>the FileIndex</returns>
        /// <remarks>
        /// The Tags of the FileDescriptions contain the MMATCachItem Object,
        /// the FileNames of the FileDescriptions contain the Name of the package File
        /// </remarks>
        public void LoadMemTable()
        {
            fi            = new FileIndex(new ArrayList());
            fi.Duplicates = false;

            foreach (CacheContainer cc in Containers)
            {
                if (cc.Type == ContainerType.Memory && cc.Valid)
                {
                    foreach (MemoryCacheItem mci in cc.Items)
                    {
                        Interfaces.Files.IPackedFileDescriptor pfd = mci.FileDescriptor;
                        pfd.Filename = cc.FileName;
                        fi.AddIndexFromPfd(pfd, null, FileIndex.GetLocalGroup(pfd.Filename));
                    }
                }
            }            //foreach
        }
        /// <summary>
        /// ファイルインデックスをロード
        /// </summary>
        /// <param name="fileIndexPath"></param>
        /// <returns></returns>
        public static IList <FileIndex> FileIndexLoader(string fileIndexPath)
        {
            var list = new List <FileIndex>();

            foreach (var l in File.ReadAllLines(fileIndexPath))
            {
                KCVDBRow row;
                if (KCVDBRow.TryParse(l, out row))
                {
                    FileIndex index;
                    if (FileIndex.TryParse(l, out index))
                    {
                        list.Add(index);
                    }
                }
            }
            return(list);
        }
Beispiel #17
0
        public Option <CorrelationToken> MonitorPath(FolderPath Path)
        {
            var token = CorrelationToken.Create(Path);

            if (FolderIndex.TryAdd(token, new FolderTree(Path)))
            {
                FolderIndex.TryFind(token)
                .OnNone(Notify)
                .OnSome(tree =>
                {
                    var index = ToMutableIndex(tree);
                    FileIndex.TryAdd(token, index);
                    iter(index.Keys, file => Notify(inform($"Indexed {file}")));
                });
            }

            C.Notify(inform($"{AgentRuntimeId} completed indexing {token}"));
            return(token);
        }
Beispiel #18
0
        /// <inheritdoc/>
        public async Task <bool> TryCreateDirectoryAsync(string path)
        {
            try
            {
                if (string.IsNullOrEmpty(path))
                {
                    return(true);
                }

                // 检查文件夹记录是否完整
                var index = await _context.FileIndexs.Where(c => c.Path == path).FirstOrDefaultAsync();

                if (index != null)
                {
                    return(true);
                }

                index = new FileIndex();

                index.Id            = IdHelper.GetLongId();
                index.Path          = PathHelper.NormalizePath(path);
                index.DirectoryPath = PathHelper.NormalizePath(Path.GetDirectoryName(path));
                index.IsDirectory   = true;

                var nowTime = DateTime.UtcNow;
                index.LastModifiedUtc  = nowTime;
                index.Visits           = 0;
                index.LastVisitTimeUtc = nowTime;

                _context.FileIndexs.Add(index);

                await _context.SaveChangesAsync();

                await TryCreateDirectoryAsync(index.DirectoryPath);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public SimpleArchiveFileSystem(string filename)
        {
            if (!File.Exists(filename))
            {
                CreateArchive(filename);
            }
            stream = new FileStream(filename, FileMode.Open);
            BinaryReader br = new BinaryReader(stream);

            header = new FileHeader();
            header.Read(br);

            br.BaseStream.Position = header.FileIndexOffset;
            fileIndex = new FileIndex();
            fileIndex.Read(br);

            br.BaseStream.Position = header.FolderIndexOffset;
            folderIndex            = new FolderIndex();
            folderIndex.Read(br);
        }
        protected override bool ClearImageImpl(CheckImageClear by)
        {
            string filter = "";

            if (by == CheckImageClear.FileId)
            {
                filter = "*@" + FileId + "@*.bmp";
            }
            else if (by == CheckImageClear.FileIndex)
            {
                filter = FileIndex.ToString(CultureInfo.InvariantCulture) + "@*.bmp";
            }
            else if (by == CheckImageClear.ImageTagData)
            {
                filter = "*@" + ImageTagData + ".bmp";
            }
            else if (by == CheckImageClear.All)
            {
                filter = "*@*@*.bmp";
            }

            string [] files = Directory.GetFiles(ImageDirectory, filter);

            if (files.Length == 0 && by != CheckImageClear.All)
            {
                //throw new PosControlException("File not found with filter: " + filter, ErrorCode.Illegal, 0);
                return(false);
            }

            if (files.Length != 1 && by != CheckImageClear.All)
            {
                throw new PosControlException("More than 1 file was found with filter: " + filter, ErrorCode.Failure, 0);
            }

            foreach (string file in files)
            {
                File.Delete(ImageDirectory + @"\" + file);
            }

            return(true);
        }
Beispiel #21
0
        public void ScanPackage(ScannerItem si, SimPe.Cache.PackageState ps, System.Windows.Forms.ListViewItem lvi)
        {
            SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = si.Package.FindFiles(Data.MetaData.MMAT);
            //ArrayList list = new ArrayList();

            ps.State = TriState.True;
            //FileTable.FileIndex.StoreCurrentState();
            if (!FileTable.FileIndex.ContainsPath(System.IO.Path.GetDirectoryName(si.FileName)))
            {
                FileIndex.AddIndexFromFolder(System.IO.Path.GetDirectoryName(si.FileName));
            }

            FileIndex.AddIndexFromPackage(si.Package);
            foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in pfds)
            {
                SimPe.Plugin.MmatWrapper mmat = new MmatWrapper();
                mmat.ProcessData(pfd, si.Package, false);

                string m = mmat.ModelName.Trim().ToLower();
                if (!m.EndsWith("_cres"))
                {
                    m += "_cres";
                }

                //Add the current package
                SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem item = FileTable.FileIndex.FindFileByName(m, Data.MetaData.CRES, Data.MetaData.LOCAL_GROUP, true);

                if (item == null)
                {
                    ps.State = TriState.False;
                }

                item = null;
                mmat.Dispose();
                m = null;
            }
            //FileTable.FileIndex.RestoreLastState();

            UpdateState(si, ps, lvi);
        }
Beispiel #22
0
        public void EnumeratesFilesFromMultipleIndices()
        {
            var first = new IndexFile();

            first.Files.Add(@"C:\pmllib\first\duplicate.pmlobj");
            first.Files.Add(@"C:\pmllib\first\unique.pmlfnc");
            var second = new IndexFile();

            second.Files.Add(@"C:\pmllib\second\duplicate.pmlobj");
            second.Files.Add(@"C:\pmllib\second\stuff.txt");
            var index = new FileIndex(new List <IndexFile>()
            {
                first, second
            });

            Assert.That(index, Is.EquivalentTo(new List <string>()
            {
                @"C:\pmllib\first\duplicate.pmlobj",
                @"C:\pmllib\first\unique.pmlfnc",
                @"C:\pmllib\second\stuff.txt"
            }));
        }
Beispiel #23
0
        public void IgnoresTestFilesThatCannotBeParsed()
        {
            var parser = new Mock <TestCaseParser>(MockBehavior.Strict);

            parser.Setup(mock => mock.Parse(@"C:\testing\path\to\tests\pmlfirsttest.pmlobj")).Throws <ParserException>();
            parser.Setup(mock => mock.Parse(@"C:\testing\path\to\tests\pmlsecondtest.pmlobj")).Returns(TestCase);
            parser.Setup(mock => mock.Parse(@"C:\testing\path\to\tests\pmlthirdtest.pmlobj")).Throws <FileNotFoundException>();

            var indexFile = new IndexFile();

            indexFile.Files.Add(@"C:\testing\path\to\tests\pmlfirsttest.pmlobj");
            indexFile.Files.Add(@"C:\testing\path\to\tests\pmlsecondtest.pmlobj");
            indexFile.Files.Add(@"C:\testing\path\to\tests\pmlthirdtest.pmlobj");
            var index = new FileIndex(indexFile);

            var prodivder = new FileIndexTestCaseProvider(index, parser.Object);
            var result    = prodivder.GetTestCases();

            Assert.That(result, Is.EquivalentTo(Enumerable.Repeat(TestCase, 1)));

            parser.Verify();
        }
            /// <summary>
            /// KCVDBログをファイルインデックスにパースを試みます。戻り値は成功したかどうかを示します
            /// </summary>
            /// <param name="tsvRowString">KCVDBの行単位の文字列</param>
            /// <param name="indexItem"></param>
            /// <returns></returns>
            public static bool TryParse(string tsvRowString, out FileIndex indexItem)
            {
                indexItem = new FileIndex();

                if (tsvRowString == null)
                {
                    return(false);
                }
                var cell = tsvRowString.Split('\t');

                if (cell.Length < 5)
                {
                    return(false);
                }

                indexItem.IndexString = cell[0];
                indexItem.DateString  = cell[1];
                indexItem.SessionId   = cell[2];
                indexItem.AgentId     = cell[3];
                indexItem.FileName    = cell[4];

                return(true);
            }
        protected override CheckScannerImage RetrieveMemoryImpl(CheckImageLocate by)
        {
            string filter = "";

            if (by == CheckImageLocate.FileId)
            {
                filter = "*@" + FileId + "@*.bmp";
            }
            else if (by == CheckImageLocate.FileIndex)
            {
                filter = FileIndex.ToString(CultureInfo.InvariantCulture) + "@*.bmp";
            }
            else if (by == CheckImageLocate.ImageTagData)
            {
                filter = "*@" + ImageTagData + ".bmp";
            }

            string [] files = Directory.GetFiles(ImageDirectory, filter);

            if (files.Length == 0)
            {
                throw new PosControlException("File not found with filter: " + filter, ErrorCode.Illegal, 0);
            }

            if (files.Length != 1)
            {
                throw new PosControlException("More than 1 file was found with filter: " + filter, ErrorCode.Failure, 0);
            }

            WorkingStorage = new Bitmap(files[0]);

            FileInfo f = new FileInfo(files[0]);

            string [] props = f.Name.Split("@.".ToCharArray());

            return(new CheckScannerImage(WorkingStorage, props[1], Int32.Parse(props[0], CultureInfo.InvariantCulture), props[2]));
        }
        public async Task FileExclusion()
        {
            // Arrange
            // Prepare DB & files
            Assert.IsTrue(PrepareDirectories());
            Assert.IsTrue(await ResetDatabase(), "Could not create database");

            var targetDir  = Path.Combine(testDirD, "dir1");
            var targetDir2 = Path.Combine(testDirD, @"dir2\subdir1");

            // should be scanned
            File.Copy(Path.GetFullPath(Path.Combine(testFileDir, "KeyMap.txt")), Path.Combine(targetDir, "KeyMap.txt"));

            // should not be scanned
            File.Copy(Path.GetFullPath(Path.Combine(testFileDir, "randomExe.exe")), Path.Combine(targetDir, "randomExe.exe"));
            File.Copy(Path.GetFullPath(Path.Combine(testFileDir, "0266554465.jpeg")), Path.Combine(targetDir2, "0266554465.jpeg"));
            File.Copy(Path.GetFullPath(Path.Combine(testFileDir, "Nikon-1-V3-sample-photo.jpg")), Path.Combine(targetDir2, "Nikon-1-V3-sample-photo.jpg"));
            File.Copy(Path.GetFullPath(Path.Combine(testFileDir, "umlaut_äü(&テスト.txt")), Path.Combine(targetDir2, "umlaut_äü(&テスト.txt"));

            // Act
            var diffFi = new FileIndex();
            await diffFi.AddFileExclusionAsync(@"\.exe", true);

            await diffFi.AddFileExclusionAsync(@".*\\subdir1", true);

            await diffFi.CreateArchiveAsync(new DirectoryInfo(testDirD), new CancellationTokenSource().Token, new Progress <int>(), new Progress <string>(), "FileExclusionArchive");

            // Assert
            Assert.AreEqual(1, diffFi.Hashes.Count, "FileHash count incorrect.");

            var hash = diffFi.Hashes.FirstOrDefault();

            Assert.AreEqual(1, hash.NodeCount, "Node count incorrect.");
            var node = hash.Nodes.FirstOrDefault();

            Assert.AreEqual(Path.Combine(targetDir, "KeyMap.txt"), node.FullSessionName, "Node count incorrect.");
        }
        private Skill ReadSkill(FileIndex fileIndex, int index)
        {
            int    length, extra;
            Stream stream = fileIndex.Seek(index, out length, out extra);

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

            BinaryReader bin        = new BinaryReader(stream);
            int          nameLength = length - 2;

            byte useBtn = bin.ReadByte();

            byte[] nameBuffer = new byte[nameLength];
            bin.Read(nameBuffer, 0, nameLength);
            byte unk = bin.ReadByte();

            StringBuilder sb = new StringBuilder(nameBuffer.Length);

            for (int i = 0; i < nameBuffer.Length; i++)
            {
                sb.Append((char)nameBuffer[i]);
            }

            SkillCategory category = _categories[0];

            if (index < _categoryLookup.Length)
            {
                category = _categories[_categoryLookup[index]];
            }

            Skill skill = new Skill(new SkillData(index, sb.ToString(), useBtn > 0, extra, unk, category));

            return(skill);
        }
Beispiel #28
0
        /// <inheritdoc/>
        public async Task CopyFileAsync(string srcPath, string dstPath)
        {
            var src = await _context.FileIndexs.Where(c => c.Path == srcPath).FirstOrDefaultAsync();

            if (src == null)
            {
                return;
            }

            var dst = new FileIndex();

            dst.Id            = IdHelper.GetLongId();
            dst.Path          = PathHelper.NormalizePath(dstPath);
            dst.DirectoryPath = PathHelper.NormalizePath(Path.GetDirectoryName(dstPath));

            // 检查并创建目录
            await TryCreateDirectoryAsync(dst.DirectoryPath);

            dst.Name        = Path.GetFileName(dstPath);
            dst.Extension   = Path.GetExtension(dstPath);
            dst.Length      = src.Length;
            dst.IsDirectory = false;

            var nowTime = DateTime.UtcNow;

            dst.LastModifiedUtc  = nowTime;
            dst.Visits           = 0;
            dst.LastVisitTimeUtc = nowTime;

            dst.MD5         = src.MD5;
            dst.FileEntryId = src.Id;

            _context.FileIndexs.Add(dst);

            await _context.SaveChangesAsync();
        }
		protected override void ProcessRecord()
		{
			const string zipArchivePlaceHolder = "#";

			using (var bar = Notify.CreateStatus("Erzeuge Backup", $"Sicherung von {Source}..."))
			{
				var totalBytes = 0L;
				//var position = 0L;
				var itemsModified = 0;
				var itemsUnmodified = 0;
				var itemsZipped = 0;
				var archiveUsed = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);

				// Lade Index-Datei
				bar.StatusDescription = "Lese Index...";
				var targetPath = new DirectoryInfo(Target);
				var targetIndex = Path.Combine(targetPath.FullName, "index.txt.gz");
				var index = new FileIndex();
				if (String.IsNullOrEmpty(ShadowIndex)) // Kein lokaler Index, also lade dem vom Target
					index.ReadIndex(Notify, targetIndex);
				else
					index.ReadIndex(Notify, ShadowIndex);

				// Gleiche die Daten ab und erzeuge die Statistik
				bar.StatusDescription = "Vergleiche Dateien mit Index...";
				var swFileStopWatch = Stopwatch.StartNew();
				var files = new FileList(Notify, new DirectoryInfo(Source), Excludes);
				foreach (var c in files)
				{
					var indexItem = index.UpdateFile(c);
					var tmp = 0;

					// Gib einen zwischen Bericht
					if (swFileStopWatch.ElapsedMilliseconds > 500)
					{
						bar.StatusDescription = $"Vergleiche {c.RelativePath} mit Index...";
						swFileStopWatch = Stopwatch.StartNew();
					}

					switch (indexItem.State)
					{
						case FileIndexState.Modified:
							// Erzeuge den Eintrag im Index
							if (c.FileInfo.Length < ZipArchiveBorder)
							{
								itemsZipped++;
								indexItem.ArchiveName = zipArchivePlaceHolder;
							}
							else
							{
								if (String.IsNullOrEmpty(indexItem.ArchiveName))
									indexItem.ArchiveName = Guid.NewGuid().ToString("N") + Path.GetExtension(indexItem.RelativePath) + (ZipFile(indexItem.RelativePath) ? ".gz" : ".nopack");
							}

							// Statistik für den Progress
							totalBytes += c.FileInfo.Length;
							itemsModified++;

							// Erhöhe den Zugriff
							if (archiveUsed.TryGetValue(indexItem.ArchiveName, out tmp))
								archiveUsed[indexItem.ArchiveName] = tmp + 1;
							break;
						case FileIndexState.Unmodified:
							// Prüfe die existens den Archives
							if (Force || (String.IsNullOrEmpty(ShadowIndex) && !File.Exists(Path.Combine(targetPath.FullName, indexItem.ArchiveName))))
							{
								indexItem.Update(c.FileInfo);
								goto case FileIndexState.Modified;
							}
							itemsUnmodified++;

							// Erhöhe den Zugriff
							if (archiveUsed.TryGetValue(indexItem.ArchiveName, out tmp))
								archiveUsed[indexItem.ArchiveName] = tmp + 1;
							break;
						case FileIndexState.None:
							if (archiveUsed.ContainsKey(indexItem.ArchiveName))
								archiveUsed[indexItem.ArchiveName] = 0;
							break;
					}
				}

				// Schreibe das neue Archiv
				if (itemsModified > 0)
				{
					string currentArchiveName = null;
					FileWrite zipStream = null;
					ZipOutputStream zip = null;
					try
					{
						bar.StartRemaining();
						bar.Maximum = totalBytes;

						var removeItems = new List<FileIndexItem>();
						foreach (var c in index)
						{
							switch (c.State)
							{
								case FileIndexState.Modified: // Kopiere die Datei
									using (var src = Stuff.OpenRead(new FileInfo(Path.Combine(Source, c.RelativePath)), Notify, allowEmpty: true))
									{
										if (c.ArchiveName == zipArchivePlaceHolder)
										{
											// Schließe das Archiv, wenn genug Inhalt
											if (zipStream != null && zipStream.Stream.Position > 512 << 20)
											{
												zipStream.Commit();
												CloseZipStream(zipStream, zip);
												currentArchiveName = null;
											}

											// Erzeuge das Archiv
											if (currentArchiveName == null)
											{
												currentArchiveName = Guid.NewGuid().ToString("N") + ".zip";
												CreateZipStream(targetPath, currentArchiveName, out zipStream, out zip);
											}

											// Kopiere die Daten
											ZipFileItem(Notify, bar, src, zip, c);
											c.ArchiveName = currentArchiveName;
										}
										else
											GZipFileItem(Notify, bar, src, targetPath, c);
									}
									break;
								case FileIndexState.None: // Lösche den Index
									removeItems.Remove(c);
									break;
							}
						}

						// Entferne die Einträge aus dem Index
						foreach (var c in removeItems)
							index.RemoveEntry(c);

						if (zipStream != null)
							zipStream.Commit();
					}
					finally
					{
						CloseZipStream(zipStream, zip);
					}

					// Schreibe den Index
					bar.StopRemaining();
					bar.StatusDescription = "Schreibe Index...";
					if (!String.IsNullOrEmpty(ShadowIndex))
						index.WriteIndex(Notify, ShadowIndex);
					index.WriteIndex(Notify, targetIndex);

					// Lösche ungenutzte Archive
					if (String.IsNullOrEmpty(ShadowIndex))
					{
						foreach (var c in archiveUsed)
							if (c.Value == 0)
							{
								var file = new FileInfo(Path.Combine(targetPath.FullName, c.Key));
								bar.StatusDescription = $"Nicht mehr benötigtes Archiv '{c.Key}'...";
								Notify.SafeIO(file.Delete, bar.StatusDescription);
							}
					}
					else // Erzeuge nur eine Löschdatei
					{
						bar.StatusDescription = "Nicht mehr benötigte Archive werden gelöscht...";
						using (var sw = new StreamWriter(Stuff.OpenWrite(new FileInfo(Path.Combine(targetPath.FullName, "index_rm.txt")), Notify, CompressMode.Stored)))
						{
							sw.BaseStream.Position = sw.BaseStream.Length;
							foreach (var c in archiveUsed)
								if (c.Value == 0)
									sw.WriteLine(c.Key);
						}
					}
				}
			}
		} // proc ProcessRecord
Beispiel #30
0
 /// <summary>
 /// Get the <see cref="MMFile"/> at a <see cref="FileIndex"/>.
 /// </summary>
 /// <param name="index">File index.</param>
 /// <returns></returns>
 static MMFile GetFile(FileIndex index)
 {
     RomUtils.CheckCompressed((int)index);
     return(RomData.MMFileList[(int)index]);
 }
Beispiel #31
0
        private void InternalCompare()
        {
            if (_usesIdx)
            {
                byte[] buffOne = new byte[0xFFFF];
                byte[] buffTwo = new byte[0xFFFF];

                FileInfo infoOne = new FileInfo(_pathOneIdx);
                FileInfo infoTwo = new FileInfo(_pathTwoIdx);

                long lengthOne = infoOne.Length;
                long lengthTwo = infoTwo.Length;

                int maxIndexes = (int)Math.Min(lengthOne / 12, lengthTwo / 12);

                FileIndex indexOne = new FileIndex(Path.GetDirectoryName(_pathOneMul), Path.GetFileName(_pathOneIdx), Path.GetFileName(_pathOneMul), maxIndexes);
                FileIndex indexTwo = new FileIndex(Path.GetDirectoryName(_pathTwoMul), Path.GetFileName(_pathTwoIdx), Path.GetFileName(_pathTwoMul), maxIndexes);

                for (int i = 0; i < maxIndexes; i++)
                {
                    Stream       streamOne = indexOne.Seek(i);
                    Stream       streamTwo = indexTwo.Seek(i);
                    BinaryReader readerOne = null;
                    BinaryReader readerTwo = null;

                    if (streamOne == null && streamTwo == null)
                    {
                        continue;
                    }

                    if (streamOne != null)
                    {
                        readerOne = new BinaryReader(streamOne);
                    }

                    if (streamTwo != null)
                    {
                        readerTwo = new BinaryReader(streamTwo);
                    }

                    if (readerOne != null && readerTwo == null)
                    {
                        CreatePatchFromIdxMul(readerOne, indexOne.Index[i]);
                    }
                    else if (readerOne == null && readerTwo != null)
                    {
                        CreatePatchFromIdxMul(readerTwo, indexTwo.Index[i]);
                    }
                    else
                    {
                        Entry3D entryOne = indexOne.Index[i];
                        Entry3D entryTwo = indexTwo.Index[i];

                        if (entryOne.length != entryTwo.length)
                        {
                            CreatePatchFromIdxMul(readerOne, entryOne);
                            CreatePatchFromIdxMul(readerTwo, entryTwo);
                        }
                        else
                        {
                            while (readerOne.BaseStream.Position != readerOne.BaseStream.Length)
                            {
                                int toRead = Math.Min(buffOne.Length, (int)(readerOne.BaseStream.Length - readerOne.BaseStream.Position));

                                readerOne.Read(buffOne, 0, toRead);
                                readerTwo.Read(buffTwo, 0, toRead);

                                bool match = true;

                                for (int a = 0; a < buffOne.Length; a++)
                                {
                                    if (buffOne[a] != buffTwo[a])
                                    {
                                        match = false;
                                        break;
                                    }
                                }

                                if (!match)
                                {
                                    CreatePatchFromIdxMul(readerOne, entryOne);
                                    CreatePatchFromIdxMul(readerTwo, entryTwo);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
            }
        }
 /// <summary>
 /// Initializer
 /// </summary>
 public void Init(EnvDTE80.DTE2 theVsAppObject, FileIndex theFileIndex)
 {
     // Initialize the control we host that does the actual work
     OpenFileCtrl.Init(theVsAppObject, theFileIndex, true);
 }
 public FileIndexWriteTransaction(FileIndex fileIndex)
 {
     _fileIndex = fileIndex;
     _transactionWrites = new List<WriteEntry>();
 }
Beispiel #34
0
 public Hate()
 {
     _spongeFileIndex = new FileIndex(_spongeFile);
     _ppLFileIndex    = new FileIndex(_ppFile);
 }
 public void TestFileIndexCase(FileIndex fileIndex, string substr, string[] expectedResults)
 {
     List<FileMatch> results;
     results = fileIndex.FindSubstringMatches(substr);
     CheckFileIndexResults(results, expectedResults);
 }
        public void TestBasicFileIndex()
        {
            FileIndex fileIndex = new FileIndex();

            string[] fileList = {
                    @"c:\bah\humbug\foo\bar\123.txt",
                    @"c:\bah\humbug\foo\bar\humbug.txt",
                    @"c:\bah\humbug\foo\bar\cat.txt",
                    @"c:\bah\humbug\cat\dog.txt",
                    @"c:\bah\humbug\cat\dog\animals.txt",
                    @"c:\bah\dog\manyanimals.jpg",
                    @"c:\bah\cat\manyanimals.jpg",
                    @"c:\project\Thing1\obj\output.obj",
                    @"c:\project\Thing2\obj\output.obj",
                    @"c:\project\Thing2\obj\cacaca.obj",
                    @"c:\project\Thing2\obj\bubu.obj",
            };

            foreach (string file in fileList)
            {
                fileIndex.AddFile(file);
            }

            TestFileIndexCase(fileIndex, "123", new string[] { @"c:\bah\humbug\foo\bar\123.txt" });

            TestFileIndexCase(fileIndex, "humbugster", new string[] { });

            TestFileIndexCase(fileIndex, ".t", new string[] {
                    @"c:\bah\humbug\foo\bar\123.txt",
                    @"c:\bah\humbug\foo\bar\cat.txt",
                    @"c:\bah\humbug\cat\dog.txt",
                    @"c:\bah\humbug\foo\bar\humbug.txt",
                    @"c:\bah\humbug\cat\dog\animals.txt" });

            TestFileIndexCase(fileIndex, "anIM", new string[] {
                    @"c:\bah\humbug\cat\dog\animals.txt",
                    @"c:\bah\cat\manyanimals.jpg",
                    @"c:\bah\dog\manyanimals.jpg" });

            TestFileIndexCase(fileIndex, "bu", new string[] {
                    @"c:\project\Thing2\obj\bubu.obj",
                    @"c:\bah\humbug\foo\bar\humbug.txt",
                    @"c:\bah\humbug\cat\dog.txt",
                    @"c:\bah\humbug\cat\dog\animals.txt",
                    @"c:\bah\humbug\foo\bar\123.txt",
                    @"c:\bah\humbug\foo\bar\cat.txt" });

            TestFileIndexCase(fileIndex, "obj", new string[] {
                    @"c:\project\Thing2\obj\bubu.obj" ,
                    @"c:\project\Thing2\obj\cacaca.obj",
                    @"c:\project\Thing1\obj\output.obj",
                    @"c:\project\Thing2\obj\output.obj" });

            TestFileIndexCase(fileIndex, "ing", new string[] {
                    @"c:\project\Thing1\obj\output.obj",
                    @"c:\project\Thing2\obj\bubu.obj",
                    @"c:\project\Thing2\obj\cacaca.obj",
                    @"c:\project\Thing2\obj\output.obj" });

            TestFileIndexCase(fileIndex, "cat\\", new string[] {
                    @"c:\bah\cat\manyanimals.jpg",
                    @"c:\bah\humbug\cat\dog.txt",
                    @"c:\bah\humbug\cat\dog\animals.txt" });

            TestFileIndexCase(fileIndex, "humbug\\cat\\", new string[] {
                    @"c:\bah\humbug\cat\dog.txt",
                    @"c:\bah\humbug\cat\dog\animals.txt" });

            TestFileIndexCase(fileIndex, "at\\", new string[] {
                    @"c:\bah\cat\manyanimals.jpg",
                    @"c:\bah\humbug\cat\dog.txt",
                    @"c:\bah\humbug\cat\dog\animals.txt" });

            TestFileIndexCase(fileIndex, "cat\\d", new string[] {
                    @"c:\bah\humbug\cat\dog.txt",
                    @"c:\bah\humbug\cat\dog\animals.txt" });

            TestFileIndexCase(fileIndex, "cat\\a", new string[] {} );

            TestFileIndexCase(fileIndex, "dfgdfgsdgsdgsdfgsdgqrsdfasfadsfgdsg\\humbu", new string[] { });

            TestFileIndexCase(fileIndex, @"Thing1\o", new string[] {
                    @"c:\project\Thing1\obj\output.obj" } );

            TestFileIndexCase(fileIndex, @"thing2", new string[] {
                    @"c:\project\Thing2\obj\bubu.obj",
                    @"c:\project\Thing2\obj\cacaca.obj",
                    @"c:\project\Thing2\obj\output.obj"  });

            TestFileIndexCase(fileIndex, @"Thing2\", new string[] {
                    @"c:\project\Thing2\obj\bubu.obj",
                    @"c:\project\Thing2\obj\cacaca.obj",
                    @"c:\project\Thing2\obj\output.obj"  });

            TestFileIndexCase(fileIndex, @"Thing2", new string[] {
                    @"c:\project\Thing2\obj\bubu.obj",
                    @"c:\project\Thing2\obj\cacaca.obj",
                    @"c:\project\Thing2\obj\output.obj"  });

            TestFileIndexCase(fileIndex, @"Thing2\ob", new string[] {
                    @"c:\project\Thing2\obj\bubu.obj",
                    @"c:\project\Thing2\obj\cacaca.obj",
                    @"c:\project\Thing2\obj\output.obj"  });

            TestFileIndexCase(fileIndex, @"thing2\obj", new string[] {
                    @"c:\project\Thing2\obj\bubu.obj",
                    @"c:\project\Thing2\obj\cacaca.obj",
                    @"c:\project\Thing2\obj\output.obj"  });

            TestFileIndexCase(fileIndex, @"Thing2\obJ\", new string[] {
                    @"c:\project\Thing2\obj\bubu.obj",
                    @"c:\project\Thing2\obj\cacaca.obj",
                    @"c:\project\Thing2\obj\output.obj"  });

            TestFileIndexCase(fileIndex, @"Thing2\OBJ\B", new string[] {
                    @"c:\project\Thing2\obj\bubu.obj" });

            TestFileIndexCase(fileIndex, "", new string[] {
                    @"c:\bah\cat\manyanimals.jpg",
                    @"c:\bah\dog\manyanimals.jpg",
                    @"c:\bah\humbug\cat\dog.txt",
                    @"c:\bah\humbug\cat\dog\animals.txt",
                    @"c:\bah\humbug\foo\bar\123.txt",
                    @"c:\bah\humbug\foo\bar\cat.txt",
                    @"c:\bah\humbug\foo\bar\humbug.txt",
                    @"c:\project\Thing1\obj\output.obj",
                    @"c:\project\Thing2\obj\bubu.obj",
                    @"c:\project\Thing2\obj\cacaca.obj",
                    @"c:\project\Thing2\obj\output.obj" });

            fileIndex.RemoveAll();

            TestFileIndexCase(fileIndex, "obj", new string[] { });
        }
 protected override void ProcessRecord()
 {
     var index = new FileIndex();
     index.ReadIndex(Notify, Index);
     WriteObject((from c in index select FormPSObject(c, "RelativePath", "ArchiveName", "Length", "LastWriteTimeUtc")), true);
 }