public static void AssertFilePathParts(
            string path,
            string machine,
            string share,
            string drive,
            string directory,
            string file,
            string extension)
        {
            ParsedFilePath pp = new ParsedFilePath(path);

            #if MACOS
            // We have to compare to OS specific paths
            machine = machine.Replace(@"\", "/");
            share = share.Replace(@"\", "/");
            directory = directory.Replace(@"\", "/");
            #endif

            Assert.AreEqual(machine, pp.Machine.ToString());
            Assert.AreEqual(share, pp.Share.ToString());
            Assert.AreEqual(drive, pp.Drive.ToString());
            Assert.AreEqual(directory, pp.Directory.ToString());
            Assert.AreEqual(file, pp.File.ToString());
            Assert.AreEqual(extension, pp.Extension.ToString());
        }
Exemple #2
0
        private bool TryGetFileDatOffset(ParsedFilePath path, out byte dataFileId, out long offset)
        {
            if (!Index.IsIndex2)
            {
                if (IndexHashTableEntries.TryGetValue(path.IndexHash, out var hashTableEntry))
                {
                    dataFileId = hashTableEntry.DataFileId;
                    offset     = hashTableEntry.Offset;
                    return(true);
                }
            }
            else
            {
                if (Index2HashTableEntries.TryGetValue(path.Index2Hash, out var hashTableEntry2))
                {
                    dataFileId = hashTableEntry2.DataFileId;
                    offset     = hashTableEntry2.Offset;
                    return(true);
                }
            }

            dataFileId = 0;
            offset     = 0;

            return(false);
        }
Exemple #3
0
        public bool FileExists(string catName, ParsedFilePath path)
        {
            if (!CategoryNameToIdMap.TryGetValue(catName, out var catId))
            {
                return(false);
            }

            var categories = Categories[catId];

            foreach (var cat in categories)
            {
                // nb: keep these as separate checks because it'll run both otherwise which is a bit pointless
                if (cat.FileExists(path.IndexHash))
                {
                    return(true);
                }

                if (cat.FileExists(path.Index2Hash))
                {
                    return(true);
                }
            }

            return(false);
        }
        public void TestGoodConversion()
        {
            var path = new ParsedFilePath("a/b.txt");

            path = new ParsedFilePath(path.MakeFullPath(new ParsedDirectoryPath("/x/y")));

            AssertFilePathParts(path, "", "", "", "/x/y/a/", "b", ".txt");
        }
Exemple #5
0
        public SqPackFileInfo?GetFileMetadata(string cat, ParsedFilePath path)
        {
            if (CategoryNameToIdMap.TryGetValue(cat, out var catId))
            {
                return(GetFileMetadata(catId, path));
            }

            return(null);
        }
Exemple #6
0
        public T GetFile <T>(string cat, ParsedFilePath path) where T : FileResource
        {
            if (CategoryNameToIdMap.TryGetValue(cat, out var catId))
            {
                return(GetFile <T>(catId, path));
            }

            return(null);
        }
Exemple #7
0
        public bool TryGetFileDatOffset(ParsedFilePath path, out byte dataFileId, out long offset)
        {
            if (!Index.IsIndex2)
            {
                return(TryGetFileDatOffset(path.IndexHash, out dataFileId, out offset));
            }

            return(TryGetFileDatOffset(path.Index2Hash, out dataFileId, out offset));
        }
 public static void AssertBadFilePath(string path)
 {
     try
     {
         ParsedFilePath pp = new ParsedFilePath(path);
         Assert.IsNotNull(pp);
         Assert.Fail("Badly formed path not caught");
     }
     catch (Exception e)
     {
         Assert.IsTrue(e is ArgumentException);
     }
 }
Exemple #9
0
        public SqPackFileInfo?GetFileMetadata(ParsedFilePath path)
        {
            var status = TryGetFileDatOffset(path, out var dataFileId, out var offset);

            if (!status)
            {
                return(null);
            }

            // get dat
            var dat = DatFiles[dataFileId];

            return(dat.GetFileMetadata(offset));
        }
Exemple #10
0
        public T?GetFile <T>(ParsedFilePath path) where T : FileResource
        {
            var status = TryGetFileDatOffset(path, out var dataFileId, out var offset);

            if (!status)
            {
                return(null);
            }

            var file = GetFile <T>(dataFileId, offset);

            file.FilePath = path;

            return(file);
        }
Exemple #11
0
        public T GetFile <T>(byte cat, ParsedFilePath path) where T : FileResource
        {
            if (Categories.TryGetValue(cat, out var categories))
            {
                foreach (var category in categories)
                {
                    var file = category.GetFile <T>(path);
                    if (file != null)
                    {
                        return(file);
                    }
                }
            }

            return(null);
        }
Exemple #12
0
        public SqPackFileInfo?GetFileMetadata(byte cat, ParsedFilePath path)
        {
            if (Categories.TryGetValue(cat, out var categories))
            {
                foreach (var category in categories)
                {
                    var file = category.GetFileMetadata(path);
                    if (file != null)
                    {
                        return(file);
                    }
                }
            }

            return(null);
        }
Exemple #13
0
        public T GetFile <T>(ParsedFilePath path) where T : FileResource
        {
            var status = TryGetFileDatOffset(path, out var dataFileId, out var offset);

            if (!status)
            {
                return(null);
            }

            // get dat
            var dat  = DatFiles[dataFileId];
            var file = dat.ReadFile <T>(offset);

            file.FilePath = path;

            return(file);
        }
Exemple #14
0
        public bool FileExists(string catName, ParsedFilePath path)
        {
            if (!CategoryNameToIdMap.TryGetValue(catName, out var catId))
            {
                return(false);
            }

            var categories = Categories[catId];

            foreach (var cat in categories)
            {
                if (!cat.Index.IsIndex2 && cat.FileExists(path.IndexHash))
                {
                    return(true);
                }

                if (cat.Index.IsIndex2 && cat.FileExists(path.Index2Hash))
                {
                    return(true);
                }
            }

            return(false);
        }