예제 #1
1
        public void test000_FirstPack()
        {
            FileInfo packFile = getPack("pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.pack");
            Stream @is = packFile.Open(System.IO.FileMode.Open, FileAccess.Read);
            try
            {
                FileInfo tmppack = new FileInfo(Path.Combine(trash.ToString(), "tmp_pack1"));
                FileInfo idxFile = new FileInfo(Path.Combine(trash.ToString(), "tmp_pack1.idx"));
                FileInfo tmpPackFile = new FileInfo(Path.Combine(trash.ToString(), "tmp_pack1.pack"));

                tmppack.Create().Close();
                idxFile.Create().Close();
                tmpPackFile.Create().Close();

                IndexPack pack = new IndexPack(db, @is, tmppack);
                pack.index(new TextProgressMonitor());
                PackFile file = new PackFile(idxFile, tmpPackFile);

                Assert.IsTrue(file.HasObject(ObjectId.FromString("4b825dc642cb6eb9a060e54bf8d69288fbee4904")));
                Assert.IsTrue(file.HasObject(ObjectId.FromString("540a36d136cf413e4b064c2b0e0a4db60f77feab")));
                Assert.IsTrue(file.HasObject(ObjectId.FromString("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259")));
                Assert.IsTrue(file.HasObject(ObjectId.FromString("6ff87c4664981e4397625791c8ea3bbb5f2279a3")));
                Assert.IsTrue(file.HasObject(ObjectId.FromString("82c6b885ff600be425b4ea96dee75dca255b69e7")));
                Assert.IsTrue(file.HasObject(ObjectId.FromString("902d5476fa249b7abc9d84c611577a81381f0327")));
                Assert.IsTrue(file.HasObject(ObjectId.FromString("aabf2ffaec9b497f0950352b3e582d73035c2035")));
                Assert.IsTrue(file.HasObject(ObjectId.FromString("c59759f143fb1fe21c197981df75a7ee00290799")));
            }
            finally
            {
                @is.Close();
            }
        }
예제 #2
0
        /*
         * Query user for a pack to open to import data from, then open pack browser to
         * let user select the packed files he wants to start off with.
         * Selected packed files will be added to given pack.
         */
        private void ImportDataFromGame(PackFile newFile)
        {
            // open existing CA pack or create new pack
            string gamePath = GameManager.Instance.CurrentGame.GameDirectory;

            if (gamePath != null && Directory.Exists(gamePath))
            {
                OpenFileDialog packOpenFileDialog = new OpenFileDialog {
                    InitialDirectory = Path.Combine(gamePath, "data"),
                    Filter           = IOFunctions.PACKAGE_FILTER,
                    Title            = "Open pack to extract basic data from"
                };
                if (packOpenFileDialog.ShowDialog() == DialogResult.OK)
                {
                    try {
                        PackBrowseDialog browser = new PackBrowseDialog {
                            PackFile = new PackFileCodec().Open(packOpenFileDialog.FileName)
                        };
                        if (browser.ShowDialog() == DialogResult.OK)
                        {
                            foreach (PackedFile packed in browser.SelectedFiles)
                            {
                                newFile.Add(packed, false);
                            }
                        }
                    } catch (Exception e) {
                        MessageBox.Show(string.Format("Failed to import data: {0}", e));
                    }
                }
            }
        }
        public AnimationReference FindAnimationRefFromPackFile(PackFile animation, PackFileService pfs)
        {
            var fullPath = pfs.GetFullPath(animation);

            foreach (var entry in _skeletonNameToAnimationMap.Values)
            {
                foreach (var s in entry)
                {
                    var res = String.Compare(s.AnimationFile, fullPath, StringComparison.InvariantCultureIgnoreCase);
                    if (res == 0)
                    {
                        return(s);
                    }
                }
            }

            var f = pfs.FindFile(fullPath);

            if (f != null)
            {
                var pf = pfs.GetPackFileContainer(animation);
                return(new AnimationReference(fullPath, pf));
            }
            return(null);
        }
예제 #4
0
        public void SimpleWriteRead()
        {
            PackFile file1 = new PackFile("test.pck");

            Assert.IsTrue(file1.AddFile("test1", TestData1), "AddFile returned false");
            VerifyFile(file1, "test1", TestData1, "before file1 save");
            try
            {
                file1.Save();
            }
            catch (Exception ex)
            {
                Assert.Fail("Exception when saving file1: " + ex.Message);
                return;
            }
            file1 = null;


            PackFile file2 = new PackFile("test.pck");

            try
            {
                file2.Load();
            }
            catch (Exception ex)
            {
                Assert.Fail("Exception when loading file2: " + ex.Message);
                return;
            }
            VerifyFile(file2, "test1", TestData1, "after file2 load");
        }
예제 #5
0
        public void AddFolderContent(PackFileContainer container, string path, string folderDir)
        {
            var originalFilePaths = Directory.GetFiles(folderDir, "*", SearchOption.AllDirectories);
            var filePaths         = originalFilePaths.Select(x => x.Replace(folderDir + "\\", "")).ToList();

            if (!string.IsNullOrWhiteSpace(path))
            {
                path += "\\";
            }

            var filesAdded = new List <PackFile>();

            for (int i = 0; i < filePaths.Count; i++)
            {
                var currentPath = filePaths[i];
                var filename    = Path.GetFileName(currentPath);

                var source = MemorySource.FromFile(originalFilePaths[i]);
                var file   = new PackFile(filename, source);
                filesAdded.Add(file);

                container.FileList[path.ToLower() + currentPath.ToLower()] = file;
            }

            _skeletonAnimationLookUpHelper.UnloadAnimationFromContainer(this, container);
            _skeletonAnimationLookUpHelper.LoadFromPackFileContainer(this, container);

            Database.TriggerPackFileAdded(container, filesAdded);
        }
예제 #6
0
        public void CreateModPackFile()
        {
            PackFileService packFileService = new PackFileService(new PackFileDataBase(), null);
            var             packContainer   = packFileService.CreateNewPackFileContainer("MyTestPackFile", PackFileCAType.MOD);


            var packFile = new PackFile("ExampleFile.txt", new FileSystemSource(@"Data\FolderData\SubFolder0\Subfolder_0_file0.txt"));

            packFileService.AddFileToPack(packContainer, @"data\content\files", packFile);

            //var packFileContent = Encoding.UTF8.GetString(packFile.DataSource.ReadData());

            using (MemoryStream ms0 = new MemoryStream())
            {
                using (BinaryWriter writer = new BinaryWriter(ms0))
                    packFileService.Save(packContainer, writer);

                // Load it again
                var orgData = ms0.ToArray();
                using (MemoryStream ms1 = new MemoryStream(orgData))
                {
                    Assert.AreEqual(ms1.Length, orgData.Length);

                    using (BinaryReader reader = new BinaryReader(ms1))
                    {
                        var loadedPackFile = new PackFileContainer("File", reader);

                        Assert.AreEqual(packContainer.Header.Version, loadedPackFile.Header.Version);
                        Assert.AreEqual(packContainer.Header.FileType, loadedPackFile.Header.FileType);
                        Assert.AreEqual(1, loadedPackFile.Header.FileCount);
                        Assert.AreEqual(0, loadedPackFile.Header.ReferenceFileCount);
                    }
                }
            }
        }
예제 #7
0
        private void VerifyOpenPack(bool thin)
        {
            IndexPack indexer;
            Stream    @is;

            if (thin)
            {
                @is     = new MemoryStream(_os.ToArray());
                indexer = new IndexPack(db, @is, _packBase);
                try
                {
                    indexer.index(new TextProgressMonitor());
                    Assert.Fail("indexer should grumble about missing object");
                }
                catch (IOException)
                {
                    // expected
                }
            }

            @is     = new MemoryStream(_os.ToArray());
            indexer = new IndexPack(db, @is, _packBase);
            indexer.setKeepEmpty(true);
            indexer.setFixThin(thin);
            indexer.setIndexVersion(2);
            indexer.index(new TextProgressMonitor());
            _pack = new PackFile(_indexFile, _packFile);
        }
예제 #8
0
 private void OptimizePack(object sender, EventArgs e)
 {
     if (!DBTypeMap.Instance.Initialized)
     {
         DBTypeMap.Instance.InitializeTypeMap(Path.GetDirectoryName(Application.ExecutablePath));
     }
     if (SelectedMod != null)
     {
         if (!File.Exists(SelectedMod.PackFilePath))
         {
             MessageBox.Show(string.Format("Pack file for mod \"{0}\" not found ", SelectedMod.Name));
             return;
         }
         else if (!QueryIgnoreEditedModPack())
         {
             return;
         }
         InputBox box = new InputBox {
             Text = "Enter prefix for rename"
         };
         PackFileCodec codec    = new PackFileCodec();
         PackFile      packFile = codec.Open(SelectedMod.PackFilePath);
         if (box.ShowDialog() == DialogResult.OK)
         {
             PackedFileRenamer renamer = new PackedFileRenamer(box.Input);
             renamer.Rename(packFile.Files);
         }
         statusLabel.Text = "Optimizing DB files...";
         Refresh();
         new DbFileOptimizer(Game.STW).CreateOptimizedFile(packFile);
         codec.Save(packFile);
         SetInstallDirectoryLabelText();
     }
 }
예제 #9
0
 public void ExecuteLine(string line)
 {
     if (line.StartsWith("open"))
     {
         SourcePack = new PackFileCodec().Open(line.Substring(5));
         commands.ForEach(c => { c.PackedFiles = SourcePack; });
     }
     else if (line.StartsWith("schema"))
     {
         TypeMapFile = line.Substring(7);
     }
     else if (line.StartsWith("commit"))
     {
         Commit();
     }
     else if (line.StartsWith("save"))
     {
         string filename = line.Substring(5);
         if (File.Exists(filename))
         {
             TargetPack = new PackFileCodec().Open(filename);
         }
         else
         {
             TargetPack = new PackFile(filename, new PFHeader("PFH4")
             {
                 Type = PackType.Mod
             });
         }
     }
     else if (line.StartsWith("script"))
     {
         string filename = line.Substring(7);
         if (File.Exists(filename))
         {
             Script included = new Script {
                 SourcePack = this.SourcePack,
                 TargetPack = this.TargetPack
             };
             included.commands.AddRange(commands);
             foreach (string fileLine in File.ReadAllLines(filename))
             {
                 included.ExecuteLine(fileLine);
             }
             SourcePack = included.SourcePack;
             TargetPack = included.TargetPack;
             commands   = included.commands;
         }
     }
     else if (!line.StartsWith("#") && !string.IsNullOrEmpty(line.Trim()))
     {
         try {
             SqlCommand command = ParseCommand(line);
             command.Execute();
             commands.Add(command);
         } catch (Exception e) {
             Console.WriteLine("Failed to execute '{0}': {1}", line, e);
         }
     }
 }
예제 #10
0
        public void test1()
        {
            FileInfo packFile = GetPack("pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.pack");

            using (Stream @is = packFile.Open(System.IO.FileMode.Open, FileAccess.Read))
            {
                var tmppack = new FileInfo(Path.Combine(trash.FullName, "tmp_pack1"));
                var pack    = new IndexPack(db, @is, tmppack);
                pack.index(new TextProgressMonitor());

                var idxFile     = new FileInfo(Path.Combine(trash.FullName, "tmp_pack1.idx"));
                var tmpPackFile = new FileInfo(Path.Combine(trash.FullName, "tmp_pack1.pack"));
                //return;
                using (var file = new PackFile(idxFile, tmpPackFile))
                {
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("4b825dc642cb6eb9a060e54bf8d69288fbee4904")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("540a36d136cf413e4b064c2b0e0a4db60f77feab")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("6ff87c4664981e4397625791c8ea3bbb5f2279a3")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("82c6b885ff600be425b4ea96dee75dca255b69e7")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("902d5476fa249b7abc9d84c611577a81381f0327")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("aabf2ffaec9b497f0950352b3e582d73035c2035")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("c59759f143fb1fe21c197981df75a7ee00290799")));
                }
            }
        }
예제 #11
0
        public void test2()
        {
            FileInfo packFile = GetPack("pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.pack");

            using (Stream @is = packFile.Open(System.IO.FileMode.Open, FileAccess.Read))
            {
                var tmppack = new FileInfo(Path.Combine(trash.FullName, "tmp_pack2"));
                var pack    = new IndexPack(db, @is, tmppack);
                pack.index(new TextProgressMonitor());

                var idxFile     = new FileInfo(Path.Combine(trash.FullName, "tmp_pack2.idx"));
                var tmpPackFile = new FileInfo(Path.Combine(trash.FullName, "tmp_pack2.pack"));
                using (var file = new PackFile(idxFile, tmpPackFile))
                {
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("02ba32d3649e510002c21651936b7077aa75ffa9")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("0966a434eb1a025db6b71485ab63a3bfbea520b6")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("09efc7e59a839528ac7bda9fa020dc9101278680")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("0a3d7772488b6b106fb62813c4d6d627918d9181")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("1004d0d7ac26fbf63050a234c9b88a46075719d3")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("10da5895682013006950e7da534b705252b03be6")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("1203b03dc816ccbb67773f28b3c19318654b0bc8")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("15fae9e651043de0fd1deef588aa3fbf5a7a41c6")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("16f9ec009e5568c435f473ba3a1df732d49ce8c3")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("1fd7d579fb6ae3fe942dc09c2c783443d04cf21e")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("20a8ade77639491ea0bd667bf95de8abf3a434c8")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("2675188fd86978d5bc4d7211698b2118ae3bf658")));
                    // and lots more...
                }
            }
        }
예제 #12
0
                async Task <bool> getDataPacks()
                {
                    string dataPath;

                    if (!GameDirSetting.getDataPath(out dataPath))
                    {
                        return(false);
                    }

                    if (!DBTypeMap.Instance.Initialized)
                    {
                        DBTypeMap.Instance.InitializeTypeMap(AppDomain.CurrentDomain.BaseDirectory);
                    }

                    PackFile[] locPackFiles = await Task.WhenAll(GameInfo.locDataPacks.Select
                                                                     (dataPack => {
                        return(Task <PackFile> .Run(() => {
                            return getPackFile(progressUpdater, dataPath, dataPack);
                        }));
                    }));

                    PackFile[] dataPackFiles = await Task <PackFile> .WhenAll(GameInfo.dataPacks.Select
                                                                                  (dataPack => {
                        return(Task <PackFile> .Run(() => {
                            return getPackFile(progressUpdater, dataPath, dataPack);
                        }));
                    }));

                    locDBs = locPackFiles.OfType <PackFile>().Select(PackFile =>
                                                                     PackFile.GetDirByPath(GameInfo.locpath)).OfType <VirtualDirectory>().ToArray();
                    dataDBs = dataPackFiles.OfType <PackFile>().Select(PackFile =>
                                                                       PackFile.GetDirByPath(GameInfo.dbPath)).OfType <VirtualDirectory>().ToArray();
                    return(true);
                }
예제 #13
0
        public virtual void Test1()
        {
            FilePath packFile = JGitTestUtil.GetTestResourceFile("pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.pack"
                                                                 );
            InputStream @is = new FileInputStream(packFile);

            try
            {
                IndexPack pack = new IndexPack(db, @is, new FilePath(trash, "tmp_pack1"));
                pack.Index(new TextProgressMonitor());
                PackFile file = new PackFile(new FilePath(trash, "tmp_pack1.idx"), new FilePath(trash
                                                                                                , "tmp_pack1.pack"));
                NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("4b825dc642cb6eb9a060e54bf8d69288fbee4904"
                                                                                 )));
                NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("540a36d136cf413e4b064c2b0e0a4db60f77feab"
                                                                                 )));
                NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259"
                                                                                 )));
                NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("6ff87c4664981e4397625791c8ea3bbb5f2279a3"
                                                                                 )));
                NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("82c6b885ff600be425b4ea96dee75dca255b69e7"
                                                                                 )));
                NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("902d5476fa249b7abc9d84c611577a81381f0327"
                                                                                 )));
                NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("aabf2ffaec9b497f0950352b3e582d73035c2035"
                                                                                 )));
                NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("c59759f143fb1fe21c197981df75a7ee00290799"
                                                                                 )));
            }
            finally
            {
                @is.Close();
            }
        }
예제 #14
0
파일: PackFile.cs 프로젝트: xyfc/MackLib
        public void Save()
        {
            var path     = Path.Combine(PackReader.GetMabinogiDirectory(), "package", "language.pack");
            var contents = File.ReadAllBytes(path);
            var tempPath = Path.GetTempFileName();

            using (var pf = new PackFile(path))
            {
                pf.Save(tempPath);
            }

            using (var pf = new PackFile(tempPath))
            {
                var entry = pf.GetEntry(@"data\local\xml\auctioncategory.english.txt");
                Assert.NotEqual(null, entry);

                using (var sr = new StreamReader(entry.GetDataAsFileStream()))
                {
                    Assert.Equal(sr.ReadLine(), "1\tMelee Weapon");
                    Assert.Equal(sr.ReadLine(), "2\tOne-Handed");
                    Assert.Equal(sr.ReadLine(), "3\tTwo-Handed");
                }
            }

            File.Delete(tempPath);
        }
예제 #15
0
        public static MetaDataFile ParseFile(PackFile file, PackFileService pf)
        {
            var fileContent   = file.DataSource.ReadData();
            var contentLength = fileContent.Count();


            MetaDataFile outputFile = new MetaDataFile()
            {
                FileName = pf.GetFullPath(file),
                Version  = BitConverter.ToInt32(fileContent, 0)
            };

            if (outputFile.Version != 2)
            {
                throw new Exception($"Unknown version - {outputFile.Version} for {outputFile.FileName}");
            }

            if (contentLength > 8)
            {
                MetaDataTagItem currentElement = null;
                int             numElements    = BitConverter.ToInt32(fileContent, 4);
                int             currentIndex   = 0 + 8; // First 4 bytes is the number of elements, next 2 is unknown
                while (currentIndex != contentLength && (currentElement = GetElement(currentIndex, fileContent, outputFile.FileName, out currentIndex)) != null)
                {
                    outputFile.TagItems.Add(currentElement);
                }

                if (numElements != outputFile.TagItems.Count)
                {
                    throw new Exception($"Not the expected amount elements. Expected {numElements}, got {outputFile.TagItems.Count}");
                }
            }

            return(outputFile);
        }
예제 #16
0
        private void CleanUp(object sender, EventArgs e)
        {
            if (SelectedMod != null)
            {
                if (!QueryIgnoreEditedModPack())
                {
                    return;
                }

                if (MessageBox.Show("This will delete the directories 'battleterrain' and 'variantmodels' from your pack. " +
                                    "Do not do this if you changed anything there.\nContinue?", "Confirm cleanup",
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
                {
                    return;
                }

                PackFileCodec codec   = new PackFileCodec();
                PackFile      modPack = codec.Open(SelectedMod.PackFilePath);
                foreach (VirtualDirectory dir in modPack.Root.Subdirectories)
                {
                    if (dir.Name.Equals("battleterrain") || dir.Name.Equals("variantmodels"))
                    {
                        dir.Deleted = true;
                    }
                }
                if (modPack.Root.Modified)
                {
                    string tempFilePath = Path.GetTempFileName();
                    codec.WriteToFile(tempFilePath, modPack);
                    File.Delete(SelectedMod.PackFilePath);
                    File.Move(tempFilePath, SelectedMod.PackFilePath);
                }
            }
        }
예제 #17
0
 // write files that failed to filesystem individually for later inspection
 void ExtractFiles(string dir, PackFile pack, ICollection <Tuple <string, int> > toExtract)
 {
     if (toExtract.Count != 0)
     {
         string path = Path.Combine(dir, "failed");
         Directory.CreateDirectory(path);
         foreach (Tuple <string, int> failed in toExtract)
         {
             string     failType = failed.Item1;
             string     failPath = string.Format("db\\{0}_tables\\{0}", failType);
             PackedFile found    = null;
             foreach (PackedFile packed in pack.Files)
             {
                 if (packed.FullPath.Equals(failPath))
                 {
                     found = packed;
                     break;
                 }
             }
             if (found != null)
             {
                 string filePath = Path.Combine(path, string.Format("{0}_{1}", failType, failed.Item2));
                 File.WriteAllBytes(Path.Combine(dir, filePath), found.Data);
             }
             else
             {
                 Console.WriteLine("cant extract {0}", failPath);
             }
         }
     }
 }
        public ISceneNode Load(PackFile file, ISceneNode parent, AnimationPlayer player, ref string skeletonName)
        {
            if (file == null)
            {
                throw new Exception("File is null in SceneLoader::Load");
            }

            _logger.Here().Information($"Attempting to load file {file.Name}");

            //string _refSkeletonName = null;
            switch (file.Extention)
            {
            case ".variantmeshdefinition":
                LoadVariantMesh(file, ref parent, player, ref skeletonName);
                break;

            case ".rigid_model_v2":
                LoadRigidMesh(file, ref parent, player, ref skeletonName);
                break;

            case ".wsmodel":
                LoadWsModel(file, ref parent, player, ref skeletonName);
                break;

            default:
                throw new Exception("Unknown mesh extention");
            }
            //if (!string.IsNullOrWhiteSpace(_refSkeletonName))
            //    skeletonName = _refSkeletonName;
            //else
            //    skeletonName = skeletonName;
            return(parent);
        }
        private void SkeletonChanged(string selectedSkeletonPath)
        {
            HeaderText                   = "";
            _skeletonPackFile            = null;
            Skeleton                     = null;
            AnimationsForCurrentSkeleton = new ObservableCollection <AnimationReference>();
            if (!string.IsNullOrWhiteSpace(selectedSkeletonPath))
            {
                _skeletonPackFile = _packFileService.FindFile(selectedSkeletonPath) as PackFile;
                if (_skeletonPackFile == null)
                {
                    HeaderText = "No skeleton";
                }
                else
                {
                    HeaderText = _skeletonPackFile.Name + " - No Animation";
                    AnimationsForCurrentSkeleton = _skeletonAnimationLookUpHelper.GetAnimationsForSkeleton(Path.GetFileNameWithoutExtension(_skeletonPackFile.Name));

                    var skeletonAnimationFile = AnimationFile.Create(_skeletonPackFile);
                    Skeleton = new GameSkeleton(skeletonAnimationFile, Player);
                }
            }

            SelectedAnimation = null;
        }
예제 #20
0
        public void LoadReference(PackFile file, bool updateSkeleton = false)
        {
            _logger.Here().Information($"Loading reference model - {_packFileService.GetFullPath(file)}");

            SceneLoader loader          = new SceneLoader(_packFileService, _resourceLibary);
            var         outSkeletonName = "";
            var         result          = loader.Load(file, null, _animationView.Player, ref outSkeletonName);

            if (result == null)
            {
                _logger.Here().Error("Unable to load model");
                return;
            }

            result.ForeachNode((node) =>
            {
                node.IsEditable = false;
                if (node is ISelectable selectable)
                {
                    selectable.IsSelectable = false;
                }
            });
            ReferenceMeshRoot.AddObject(result);

            //_animationView.SetActiveSkeleton(result.f.Header.SkeletonName);
        }
        public static AnimationFile Create(PackFile file)
        {
            ILogger logger = Logging.Create <AnimationFile>();
            var     data   = file.DataSource.ReadData();

            logger.Here().Information($"Loading animation: {file} Size:{data.Length}");
            return(Create(new ByteChunk(data)));
        }
예제 #22
0
 public void PackFileLoaded(PackFile packedFile)
 {
     progressReporter.ReportProgressAsync(() =>
     {
         label.Text = string.Format("Finished opening {0} - {1} files loaded", packedFile, codecFileCount);
     });
     Disconnect(packedFile.Filepath);
 }
예제 #23
0
        public void LoadEditableModel(PackFile file)
        {
            var rmv = new RmvRigidModel(file.DataSource.ReadData(), file.Name);

            EditableMeshNode.SetModel(rmv, _resourceLibary, _animationView.Player, GeometryGraphicsContextFactory.CreateInstance(_resourceLibary.GraphicsDevice));

            _animationView.SetActiveSkeleton(rmv.Header.SkeletonName);
        }
예제 #24
0
파일: PackFile.cs 프로젝트: xyfc/MackLib
 public void OpenReaderWithInvalidPath()
 {
     Assert.Throws(typeof(ArgumentException), () =>
     {
         using (var pr = new PackFile("some/path/that/hopefully/doesn't/exist"))
         {
         }
     });
 }
예제 #25
0
		internal static LocalObjectRepresentation NewWhole(PackFile f, long p, long length
			)
		{
			LocalObjectRepresentation r = new _LocalObjectRepresentation_53();
			r.pack = f;
			r.offset = p;
			r.length = length;
			return r;
		}
예제 #26
0
파일: PackFile.cs 프로젝트: xyfc/MackLib
        public void OpenReader()
        {
            var path = Path.Combine(PackReader.GetMabinogiDirectory(), "package", "language.pack");

            using (var pf = new PackFile(path))
            {
                Assert.InRange(pf.Count, 1, 100000);
            }
        }
예제 #27
0
		/// <exception cref="System.IO.IOException"></exception>
		internal PackInputStream(PackFile pack, long pos, WindowCursor wc)
		{
			this.pack = pack;
			this.pos = pos;
			this.wc = wc;
			// Pin the first window, to ensure the pack is open and valid.
			//
			wc.Pin(pack, pos);
		}
예제 #28
0
파일: PackFile.cs 프로젝트: xyfc/MackLib
        public void GetEntry()
        {
            var path = Path.Combine(PackReader.GetMabinogiDirectory(), "package", "language.pack");

            using (var pf = new PackFile(path))
            {
                var entry = pf.GetEntry(@"data\local\xml\arbeit.english.txt");
                Assert.NotEqual(null, entry);
            }
        }
예제 #29
0
 private void GetUsedTypes(PackFile pack)
 {
     foreach (PackedFile packed in pack.Files)
     {
         if (packed.FullPath.StartsWith("db"))
         {
             AddFromPacked(packed);
         }
     }
 }
예제 #30
0
		internal static LocalObjectRepresentation NewDelta(PackFile f, long p, long n, ObjectId
			 @base)
		{
			LocalObjectRepresentation r = new LocalObjectRepresentation.Delta();
			r.pack = f;
			r.offset = p;
			r.length = n;
			r.baseId = @base;
			return r;
		}
예제 #31
0
		internal LargePackedWholeObject(int type, long size, long objectOffset, int headerLength
			, PackFile pack, FileObjectDatabase db)
		{
			this.type = type;
			this.size = size;
			this.objectOffset = objectOffset;
			this.headerLength = headerLength;
			this.pack = pack;
			this.db = db;
		}
예제 #32
0
		internal LargePackedDeltaObject(long objectOffset, long baseOffset, int headerLength
			, PackFile pack, FileObjectDatabase db)
		{
			this.type = Constants.OBJ_BAD;
			this.size = SIZE_UNKNOWN;
			this.objectOffset = objectOffset;
			this.baseOffset = baseOffset;
			this.headerLength = headerLength;
			this.pack = pack;
			this.db = db;
		}
예제 #33
0
 public void test003_lookupCompressedObject()
 {
     ObjectId id = ObjectId.FromString("902d5476fa249b7abc9d84c611577a81381f0327");
     var pr = new PackFile(TestIdx, TestPack);
     PackedObjectLoader or = pr.Get(new WindowCursor(), id);
     Assert.IsNotNull(or);
     Assert.AreEqual(Constants.OBJ_TREE, or.Type);
     Assert.AreEqual(35, or.Size);
     Assert.AreEqual(7738, or.DataOffset);
     pr.Close();
 }
예제 #34
0
 /**
  * <summary>Finds the <see cref="PackedFile"/> with the given <see cref="PackedFile.FullPath">Path</see> in the given <see cref="PackFile"/>.</summary>
  *
  * <param name="pack">The <see cref="PackFile"/> to be searched.</param>
  * <param name="name">The <see cref="PackedFile.FullPath"/> of the <see cref="PackedFile"/> to search for.</param>
  * <returns>The <see cref="PackedFile"/> that was being searched for or null if it was not found.</returns>
  */
 PackedFile FindInPack(PackFile pack, string name)
 {
     foreach (PackedFile file in pack)
     {
         if (file.FullPath.Equals(name))
         {
             return(file);
         }
     }
     return(null);
 }
예제 #35
0
파일: PackFile.cs 프로젝트: xyfc/MackLib
        public void GetEntriesByFileName()
        {
            var path = Path.Combine(PackReader.GetMabinogiDirectory(), "package", "language.pack");

            using (var pf = new PackFile(path))
            {
                var entries = pf.GetEntriesByFileName(@"auctioncategory.english.txt");
                Assert.True(entries.Count > 0);
                Assert.Single(entries, a => a.RelativePath == @"xml\auctioncategory.english.txt");
            }
        }
예제 #36
0
        public void CreatePack()
        {
            Pack          pack = new Pack();
            PackContainer po   = pack.Containers.AddItem("#ProjectOutput");

            po.Files.AddItem("bin/release/QQnUtils.dll").FileHash         = "qwqq";
            po.Files.AddItem("bin/release/QQnUtils.pdb").FileSize         = long.MaxValue;
            po.Files.AddItem("bin/release/QQnUtils.xml").LastWriteTimeUtc = DateTime.Now;

            PackContainer pc = pack.Containers.AddItem("#ProjectContent");

            po.Files.AddItem("QQnUtils.doc").FileHash = "q";
            po.Files.AddItem("QQnDef.xsd").FileSize   = 123456;

            PackContainer ps = pack.Containers.AddItem("#Scripts");

            ps.Files.AddItem("Setup/QQnUtils.wxs").LastWriteTimeUtc = DateTime.Now;

            XmlDocument doc = new XmlDocument();

            using (XmlWriter xw = doc.CreateNavigator().AppendChild())
            {
                xw.WriteStartElement("Pack", "");                 // Place al elements in default namespace for easy quering

                Tokenizer.TryWriteXml(xw, pack);
            }

            Assert.That(doc.SelectSingleNode("/*"), Is.Not.Null);
            Assert.That(doc.SelectNodes("//Item").Count, Is.EqualTo(6));

            Pack pack2;

            Tokenizer.TryParseXml(doc.DocumentElement, out pack2);

            foreach (PackContainer ipc in pack.Containers)
            {
                PackContainer ipc2 = pack2.Containers[ipc.Name];
                Assert.That(ipc2, Is.Not.Null);

                Assert.That(ipc2.Name, Is.EqualTo(ipc.Name));


                foreach (PackFile ipf in ipc.Files)
                {
                    PackFile ipf2 = ipc2.Files[ipf.Name];

                    Assert.That(ipf2.Name, Is.EqualTo(ipf.Name));
                    Assert.That(ipf2.FileHash, Is.EqualTo(ipf.FileHash));
                    Assert.That(ipf2.FileSize, Is.EqualTo(ipf.FileSize));
                    Assert.That(ipf2.LastWriteTimeUtc, Is.EqualTo(ipf.LastWriteTimeUtc));                     // This also checks time normalization
                }
            }
        }
        void CheckPack(PackFile pack)
        {
            PackedFile referenced = null;
            Dictionary <PackedFile, List <string> > referencing = new Dictionary <PackedFile, List <string> >();

            foreach (PackedFile packed in pack)
            {
                if (packed.FullPath.StartsWith("db"))
                {
                    if (DBFile.Typename(packed.FullPath).Equals(ReferencedTable))
                    {
                        referenced = packed;
                    }
                    foreach (string referenceFrom in referencesFrom)
                    {
                        if (referenceFrom.Split('.')[0].Equals(DBFile.Typename(packed.FullPath)))
                        {
                            List <string> referencingList;
                            if (!referencing.TryGetValue(packed, out referencingList))
                            {
                                referencingList = new List <string>();
                                referencing.Add(packed, referencingList);
                            }
                            referencingList.Add(referenceFrom);
                        }
                    }
                }
            }
            if (referenced != null)
            {
                foreach (PackedFile referencingFile in referencing.Keys)
                {
                    foreach (string fieldReference in referencing[referencingFile])
                    {
                        CheckResult result = new CheckResult {
                            ReferencingTable     = referencingFile,
                            ReferencingFieldName = fieldReference.Split('.')[1],
                            ReferencedTable      = referenced,
                            ReferencedFieldName  = this.ReferencedFieldName
                        };
                        if (result.UnfulfilledReferences.Count > 0)
                        {
                            FailedResults.Add(pack, result);
                            break;
                        }
                    }
                    if (FailedResults.ContainsKey(pack))
                    {
                        break;
                    }
                }
            }
        }
예제 #38
0
		public virtual void Test003_lookupCompressedObject()
		{
			PackFile pr;
			ObjectId id;
			ObjectLoader or;
			id = ObjectId.FromString("902d5476fa249b7abc9d84c611577a81381f0327");
			pr = new PackFile(TEST_IDX, TEST_PACK);
			or = pr.Get(new WindowCursor(null), id);
			NUnit.Framework.Assert.IsNotNull(or);
			NUnit.Framework.Assert.AreEqual(Constants.OBJ_TREE, or.GetType());
			NUnit.Framework.Assert.AreEqual(35, or.GetSize());
			pr.Close();
		}
예제 #39
0
 public static Entry get(PackFile pack, long position)
 {
     Slot e = Cache[Hash(position)];
     if (e.provider == pack && e.position == position)
     {
         Entry buf = e.data.get();
         if (buf != null)
         {
             MoveToHead(e);
             return buf;
         }
     }
     return null;
 }
예제 #40
0
 /// <summary>
 /// Copy bytes from the window to a caller supplied buffer.
 /// </summary>
 /// <param name="pack">The file the desired window is stored within.</param>
 /// <param name="position">Position within the file to read from.</param>
 /// <param name="dstbuf">Destination buffer to copy into.</param>
 /// <param name="dstoff">Offset within <paramref name="dstbuf"/> to start copying into.</param>
 /// <param name="cnt">
 /// The number of bytes to copy. This value may exceed the number of
 /// bytes remaining in the window starting at offset <paramref name="position"/>.
 /// </param>
 /// <returns>
 /// number of bytes actually copied; this may be less than
 /// <paramref name="cnt"/> if <paramref name="cnt"/> exceeded the number of
 /// bytes available.
 /// </returns>
 /// <remarks>
 /// This cursor does not match the provider or id and the proper 
 /// window could not be acquired through the provider's cache.
 /// </remarks>
 public int Copy(PackFile pack, long position, byte[] dstbuf, int dstoff, int cnt)
 {
     long length = pack.Length;
     int need = cnt;
     while (need > 0 && position < length)
     {
         Pin(pack, position);
         int r = _byteWindow.copy(position, dstbuf, dstoff, need);
         position += r;
         dstoff += r;
         need -= r;
     }
     return cnt - need;
 }
예제 #41
0
        public void test003_lookupCompressedObject()
        {
            PackFile pr;
            ObjectId id;
            PackedObjectLoader or;

            id = ObjectId.FromString("902d5476fa249b7abc9d84c611577a81381f0327");
            pr = new PackFile(TEST_IDX, TEST_PACK);
            or = pr.Get(new WindowCursor(), id);
            Assert.IsNotNull(or);
            Assert.AreEqual(Constants.OBJ_TREE, or.getType());
            Assert.AreEqual(35, or.getSize());
            Assert.AreEqual(7738, or.getDataOffset());
            pr.Close();
        }
예제 #42
0
 private PackFile[] scanPacks(PackFile[] original)
 {
     lock (packList)
     {
         PackFile[] o, n;
         do
         {
             o = packList.get();
             if (o != original)
             {
                 // Another thread did the scan for us, while we
                 // were blocked on the monitor above.
                 //
                 return o;
             }
             n = scanPacksImpl(o != null ? o : NO_PACKS);
         } while (!packList.compareAndSet(o, n));
         return n;
     }
 }
예제 #43
0
        private void removePack(PackFile deadPack)
        {
            PackFile[] o, n;
            do
            {
                o = packList.get();
                if (o == null || !inList(o, deadPack))
                {
                    break;

                }
                else if (o.Length == 1)
                {
                    n = NO_PACKS;

                }
                else
                {
                    n = new PackFile[o.Length - 1];
                    int j = 0;
                    foreach (PackFile p in o)
                    {
                        if (p != deadPack)
                        {
                            n[j++] = p;
                        }
                    }
                }
            } while (!packList.compareAndSet(o, n));
            deadPack.Close();
        }
예제 #44
0
 private void insertPack(PackFile pf)
 {
     PackFile[] o, n;
     do
     {
         o = packs();
         n = new PackFile[1 + o.Length];
         n[0] = pf;
         Array.Copy(o, 0, n, 1, o.Length);
     } while (!packList.compareAndSet(o, n));
 }
예제 #45
0
        private static Dictionary<string, PackFile> reuseMap(PackFile[] old)
        {
            Dictionary<string, PackFile> forReuse = new Dictionary<string, PackFile>();
            foreach (PackFile p in old)
            {
                if (p.IsInvalid)
                {
                    // The pack instance is corrupted, and cannot be safely used
                    // again. Do not include it in our reuse map.
                    //
                    p.Close();
                    continue;
                }

                PackFile prior = forReuse[p.File.Name] = p;
                if (prior != null)
                {
                    // This should never occur. It should be impossible for us
                    // to have two pack files with the same name, as all of them
                    // came out of the same directory. If it does, we promised to
                    // close any PackFiles we did not reuse, so close the one we
                    // just evicted out of the reuse map.
                    //
                    prior.Close();
                }
            }
            return forReuse;
        }
예제 #46
0
 private static bool inList(PackFile[] list, PackFile pack)
 {
     foreach (PackFile p in list)
     {
         if (p == pack)
         {
             return true;
         }
     }
     return false;
 }
예제 #47
0
 protected ByteWindow(PackFile p, long s, long n)
 {
     _pack = p;
     _start = s;
     _end = _start + n;
 }
예제 #48
0
            private volatile LongWrapper _lastRead = new LongWrapper();

            #endregion Fields

            #region Constructors

            public PackList(long lastRead, long lastModified, PackFile[] packs)
예제 #49
0
                Repository db = RepositoryCache.open(RepositoryCache.FileKey.exact(parent));
                return new AlternateRepositoryDatabase(db);
            }
            return new ObjectDirectory(objdir, null);
        }

        private void RemovePack(PackFile deadPack)
        {
            PackList o, n;
            do
            {
                o = _packList.get();
                PackFile[] oldList = o.packs;
                int j = indexOf(oldList, deadPack);
                if (j < 0)
                    break;
                var newList = new PackFile[oldList.Length - 1];
예제 #50
0
        {
            string d = objectName.Slice(0, 2);
            string f = objectName.Substring(2);
            return new FileInfo(_objects.FullName + "/" + d + "/" + f);
        }

        private void InsertPack(PackFile pf)
        {
            PackList o, n;
            do
            {
                o = _packList.get();
                PackFile[] oldList = o.packs;
예제 #51
0
 public WholePackedObjectLoader(PackFile pr, long dataOffset, long objectOffset, int type, int size)
     : base(pr, dataOffset, objectOffset)
 {
     Type = type;
     Size = size;
 }
예제 #52
0
        private PackFile[] ScanPacks(PackFile[] original)
        {
            lock (_packList)
            {
                PackFile[] o, n;
                do
                {
                    o = _packList.get();
                    if (o != original)
                    {
                        // Another thread did the scan for us, while we
                        // were blocked on the monitor above.
                        //
                        return o;
                    }
                    n = ScanPacksImpl(o ?? NoPacks);

                } while (!_packList.compareAndSet(o, n));

                return n;
            }
        }
예제 #53
0
 private static bool InList(IEnumerable<PackFile> list, PackFile pack)
 {
     return list != null && list.Contains(pack);
 }
예제 #54
0
        private PackFile[] scanPacksImpl(PackFile[] old)
        {
            Dictionary<string, PackFile> forReuse = reuseMap(old);
            string[] idxList = listPackIdx();
            List<PackFile> list = new List<PackFile>(idxList.Length);
            foreach (string indexName in idxList)
            {
                string @base = indexName.Slice(0, indexName.Length - 4);
                string packName = @base + ".pack";

                PackFile oldPack = null;
                forReuse.TryGetValue(packName, out oldPack);
                forReuse.Remove(packName);
                if (oldPack != null)
                {
                    list.Add(oldPack);
                    continue;
                }

                var packFile = new FileInfo(packDirectory.FullName + "/" + packName);
                if (!packFile.Exists)
                {
                    // Sometimes C Git's HTTP fetch transport leaves a
                    // .idx file behind and does not download the .pack.
                    // We have to skip over such useless indexes.
                    //
                    continue;
                }

                var idxFile = new FileInfo(packDirectory + "/" + indexName);
                list.Add(new PackFile(idxFile, packFile));
            }

            foreach (PackFile p in forReuse.Values)
            {
                p.Close();
            }

            if (list.Count == 0)
            {
                return NO_PACKS;
            }
            PackFile[] r = list.ToArray();
            Array.Sort(r, PackFile.SORT);
            return r;
        }
예제 #55
0
		internal ByteBufferWindow(PackFile pack, long o, ByteBuffer b) : base(pack, o, b.
			Capacity())
		{
			buffer = b;
		}
 public DeltaOfsPackedObjectLoader(PackFile pr, long dataOffset, long objectOffset, int deltaSz, long @base)
     : base(pr, dataOffset, objectOffset, deltaSz)
 {
     _deltaBase = @base;
 }
예제 #57
0
        public void test001_SecondPack()
        {
            FileInfo packFile = getPack("pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.pack");
            Stream @is = packFile.Open(System.IO.FileMode.Open, FileAccess.Read);
            try
            {
                FileInfo tmppack = new FileInfo(Path.Combine(trash.ToString(), "tmp_pack2"));
                FileInfo idxFile = new FileInfo(Path.Combine(trash.ToString(), "tmp_pack2.idx"));
                FileInfo tmpPackFile = new FileInfo(Path.Combine(trash.ToString(), "tmp_pack2.pack"));

                tmppack.Create().Close();
                idxFile.Create().Close();
                tmpPackFile.Create().Close();

                IndexPack pack = new IndexPack(db, @is, tmppack);
                pack.index(new TextProgressMonitor());
                PackFile file = new PackFile(idxFile, tmpPackFile);

                Assert.IsTrue(file.HasObject(ObjectId.FromString("02ba32d3649e510002c21651936b7077aa75ffa9")));
                Assert.IsTrue(file.HasObject(ObjectId.FromString("0966a434eb1a025db6b71485ab63a3bfbea520b6")));
                Assert.IsTrue(file.HasObject(ObjectId.FromString("09efc7e59a839528ac7bda9fa020dc9101278680")));
                Assert.IsTrue(file.HasObject(ObjectId.FromString("0a3d7772488b6b106fb62813c4d6d627918d9181")));
                Assert.IsTrue(file.HasObject(ObjectId.FromString("1004d0d7ac26fbf63050a234c9b88a46075719d3")));
                Assert.IsTrue(file.HasObject(ObjectId.FromString("10da5895682013006950e7da534b705252b03be6")));
                Assert.IsTrue(file.HasObject(ObjectId.FromString("1203b03dc816ccbb67773f28b3c19318654b0bc8")));
                Assert.IsTrue(file.HasObject(ObjectId.FromString("15fae9e651043de0fd1deef588aa3fbf5a7a41c6")));
                Assert.IsTrue(file.HasObject(ObjectId.FromString("16f9ec009e5568c435f473ba3a1df732d49ce8c3")));
                Assert.IsTrue(file.HasObject(ObjectId.FromString("1fd7d579fb6ae3fe942dc09c2c783443d04cf21e")));
                Assert.IsTrue(file.HasObject(ObjectId.FromString("20a8ade77639491ea0bd667bf95de8abf3a434c8")));
                Assert.IsTrue(file.HasObject(ObjectId.FromString("2675188fd86978d5bc4d7211698b2118ae3bf658")));
                // and lots more...
            }
            finally
            {
                @is.Close();
            }
        }
예제 #58
0
		internal ByteArrayWindow(PackFile pack, long o, byte[] b) : base(pack, o, b.Length
			)
		{
			array = b;
		}
예제 #59
0
 public ByteBufferWindow(PackFile pack, long o, Stream b)
     : base(pack, o, b.Length)
 {
     _stream = b;
 }
예제 #60
0
                return NoAlternates;
            }

            return l.ToArray();
        }

        private static int indexOf(PackFile[] list, PackFile pack)
        {
            for (int i = 0; i < list.Length; i++)