Ejemplo n.º 1
0
        /// <summary>
        /// Closes the archive file once the statistics are no longer needed.
        /// </summary>
        public void Close()
        {
            if ((object)m_archive == null)
            {
                return;
            }

            m_totalFrames.Clear();
            m_missingFrames.Clear();
            m_connectedStats.Clear();
            m_averageLatency.Clear();
            m_actualDataRate.Clear();
            m_dataQualityErrors.Clear();
            m_timeQualityErrors.Clear();

            m_archive.Close();
            m_archive = null;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="StatisticsReader"/> object and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                try
                {
                    // This will be done regardless of whether the object is finalized or disposed.

                    if (disposing)
                    {
                        m_archive?.Close();
                        m_archive = null;
                    }
                }
                finally
                {
                    m_disposed = true;  // Prevent duplicate dispose.
                }
            }
        }
Ejemplo n.º 3
0
        private void decodeHashesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // This will take a long time
            LoadingArchives loaderProgress = new LoadingArchives();

            int fileCount = 0;
            int doneCount = 0;

            // Determine file count
            foreach (Archive a in ArchiveManager.Archives)
            {
                fileCount += (int)a.FileCount;
            }

            loaderProgress.UpdateProgres(fileCount, 0);
            loaderProgress.Show();

            //Dictionary<ulong, string> foundHashes = new Dictionary<ulong, string>();
            object FileLock = new Object();

            Task.Run(() =>
            {
                List <Task> loadTasks = new List <Task>();

                foreach (Archive a in ArchiveManager.Archives)
                {
                    Console.WriteLine("Starting file listing for: " + a.File.Name);

                    loadTasks.Add(a.ListFilesAsync((ArchiveFileInfo file) =>
                    {
                        try
                        {
                            ArchiveFile af = file.OpenRead();

                            try
                            {
                                CR2WFile cr2w = CR2WFile.ReadFile(af);

                                foreach (CR2WImport import in cr2w.Imports)
                                {
                                    ulong hash = FNV1A64HashAlgorithm.HashString(import.Path);
                                    if (ArchiveManager.ResolveFileHash(hash) == "")
                                    {
                                        ArchiveManager.RegisterFilePath(import.Path);
                                        Console.WriteLine($"Found missing hash from imports: {import.Path},{hash}");
                                    }
                                }

                                foreach (CR2WExport export in cr2w.Exports)
                                {
                                    if (export.Data.ContainsKey("resolvedDependencies") && export.Data["resolvedDependencies"].TypeName == "array:raRef:CResource")
                                    {
                                        string[] paths = export.Data["resolvedDependencies"].ToRaRefArray();

                                        foreach (string path in paths)
                                        {
                                            ulong hash = FNV1A64HashAlgorithm.HashString(path);
                                            if (ArchiveManager.ResolveFileHash(hash) == "")
                                            {
                                                ArchiveManager.RegisterFilePath(path);
                                                Console.WriteLine($"Found missing hash from resolved dependencies: {path},{hash}");
                                            }
                                        }
                                    }

                                    if (export.Data.ContainsKey("dependencies") && export.Data["dependencies"].TypeName == "array:raRef:CResource")
                                    {
                                        string[] paths = export.Data["dependencies"].ToRaRefArray();

                                        foreach (string path in paths)
                                        {
                                            ulong hash = FNV1A64HashAlgorithm.HashString(path);
                                            if (ArchiveManager.ResolveFileHash(hash) == "")
                                            {
                                                ArchiveManager.RegisterFilePath(path);
                                                Console.WriteLine($"Found missing hash from cooked dependency: {path},{hash}");
                                            }
                                        }
                                    }

                                    if (export.CName == "appearanceAppearanceDefinition")
                                    {
                                        try
                                        {
                                            BinaryReader reader   = new BinaryReader(new MemoryStream(export.Data["name"].RawData));
                                            string appearanceName = cr2w.CNames[reader.ReadUInt16()];

                                            if (!cr2w.Exports[0].Data.ContainsKey("commonCookData"))
                                            {
                                                continue;
                                            }

                                            // Get name of common cook data
                                            string baseName = Path.GetFileNameWithoutExtension(cr2w.Exports[0].Data["commonCookData"].ToRaRef());
                                            baseName        = baseName.Substring(7, baseName.Length - 7);

                                            string cookedName = $"base\\cookedappearances\\{baseName}_{appearanceName}.cookedapp";

                                            // Search additional cooked data
                                            ulong hash = FNV1A64HashAlgorithm.HashString(cookedName);
                                            if (ArchiveManager.ResolveFileHash(hash) == "")
                                            {
                                                ArchiveManager.RegisterFilePath(cookedName);
                                                Console.WriteLine($"Found missing hash from coocked appearances: {cookedName},{hash}");
                                            }
                                        } catch (Exception) {}
                                    }
                                }
                            } catch (Exception) {}

                            af.Close();
                        } catch (Exception) {}

                        doneCount++;
                        if ((doneCount % 100) == 0)
                        {
                            loaderProgress.UpdateProgres(fileCount, doneCount);
                        }
                    }));
                }

                Task.WaitAll(loadTasks.ToArray());

                loaderProgress.UpdateProgres(fileCount, doneCount);
                loaderProgress.BeginInvoke((MethodInvoker) delegate() { loaderProgress.Close(); });

                this.LoadFileTree();
            });
        }
Ejemplo n.º 4
0
        private void AppendFileBrowser(ArchiveFileInfo[] files)
        {
            foreach (ArchiveFileInfo f in files)
            {
                if (f.IsNamed)
                {
                    TreeNode folderNode = this.CreateTreeNodeFolder(Path.GetDirectoryName(f.Name));
                    nodeTree[folderNode].Add(this.CreateTreeNodeFromFile(f));
                }
                else
                {
                    try
                    {
                        ArchiveFile file = f.OpenRead();

                        try
                        {
                            CR2WFile cr2w = CR2WFile.ReadFile(file);

                            TreeNode typeNode;

                            if (!this.unknownFilesType.ContainsKey(cr2w.Exports[0].CName))
                            {
                                typeNode = new TreeNode(cr2w.Exports[0].CName);
                                this.unknownFilesType.Add(cr2w.Exports[0].CName, typeNode);
                                this.nodeTree[this.treeNode_Unknown].Add(typeNode);
                                this.nodeTree.Add(typeNode, new List <TreeNode>());
                            }
                            else
                            {
                                typeNode = this.unknownFilesType[cr2w.Exports[0].CName];
                            }

                            this.nodeTree[typeNode].Add(this.CreateTreeNodeFromFile(f));
                        } catch (Exception e) {
                            TreeNode blobNode;

                            if (!this.unknownFilesType.ContainsKey("BLOB"))
                            {
                                blobNode = new TreeNode("- BINARY FILE -");
                                this.unknownFilesType.Add("BLOB", blobNode);
                                this.nodeTree[this.treeNode_Unknown].Add(blobNode);
                                this.nodeTree.Add(blobNode, new List <TreeNode>());
                            }
                            else
                            {
                                blobNode = this.unknownFilesType["BLOB"];
                            }

                            this.nodeTree[blobNode].Add(this.CreateTreeNodeFromFile(f));
                        }

                        file.Close();
                    } catch (Exception e) {
                        TreeNode brokenNode;

                        if (!this.unknownFilesType.ContainsKey("BROKEN"))
                        {
                            brokenNode = new TreeNode("- BROKEN FILE -");
                            this.unknownFilesType.Add("BROKEN", brokenNode);
                            this.nodeTree[this.treeNode_Unknown].Add(brokenNode);
                            this.nodeTree.Add(brokenNode, new List <TreeNode>());
                        }
                        else
                        {
                            brokenNode = this.unknownFilesType["BROKEN"];
                        }

                        this.nodeTree[brokenNode].Add(this.CreateTreeNodeFromFile(f));
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void containerTreeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeNode selected = this.containerTreeView.SelectedNode;

            if (selected == null)
            {
                return;
            }

            ArchiveFileInfo file = (ArchiveFileInfo)selected.Tag;

            if (this.containerTreeView.ContextMenu != null)
            {
                this.containerTreeView.ContextMenu.MenuItems.Clear();
            }

            if (file != null)
            {
                this.OpenFile(file, true);

                ContextMenu itemMenu   = new ContextMenu();
                MenuItem    exportFile = new MenuItem("Export", (EventHandler) delegate(object s, EventArgs evt)
                {
                    SaveFileDialog dialog = new SaveFileDialog();
                    dialog.FileName       = Path.GetFileName(file.Name);

                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        TreeNode selected_ = this.containerTreeView.SelectedNode;
                        if (selected_ == null)
                        {
                            return;
                        }
                        ArchiveFileInfo file_ = (ArchiveFileInfo)selected.Tag;
                        if (file_ == null)
                        {
                            return;
                        }

                        FileInfo exportFileInfo = new FileInfo(dialog.FileName);

                        FileStream targetStream = exportFileInfo.OpenWrite();
                        ArchiveFile archiveFile = file.OpenRead();

                        while (archiveFile.Position < archiveFile.Length)
                        {
                            byte[] buffer = new byte[512];
                            int read      = archiveFile.Read(buffer, 0, buffer.Length);
                            targetStream.Write(buffer, 0, read);
                        }

                        targetStream.Close();
                        archiveFile.Close();

                        MessageBox.Show("Export completed!");
                    }
                });

                itemMenu.MenuItems.Add(exportFile);
                this.containerTreeView.ContextMenu = itemMenu;
            }
        }