Ejemplo n.º 1
0
        private void exportHashesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LoadingArchives loaderProgress = new LoadingArchives();

            SaveFileDialog saveHashListDialog = new SaveFileDialog();

            saveHashListDialog.Filter = "Hashlist (*.txt) | *.txt";
            if (saveHashListDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            FileStream outputFile = new FileStream(saveHashListDialog.FileName, FileMode.OpenOrCreate);

            outputFile.SetLength(0);

            StreamWriter hashWriter = new StreamWriter(outputFile);

            int fileCount   = 0;
            int loadedCount = 0;

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

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

            Task.Run(() =>
            {
                // Start loading
                SynchronizedCollection <ArchiveFileInfo> appendFiles = new SynchronizedCollection <ArchiveFileInfo>();

                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) =>
                    {
                        lock (hashWriter)
                        {
                            hashWriter.WriteLine(file.NameHash.ToString());
                        }
                    }));
                }

                Task.WaitAll(loadTasks.ToArray());

                outputFile.Close();

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

                Console.WriteLine("Hashes exported");
            });
        }
Ejemplo n.º 2
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.º 3
0
        public Task LoadFileTree()
        {
            this.treeNode_Folders = new Dictionary <string, TreeNode>();
            this.treeNode_Root    = new List <TreeNode>();

            this.nodeTree = new Dictionary <TreeNode, List <TreeNode> >();
            this.nodeTree.Add(this.treeNode_Unknown, new List <TreeNode>());

            this.unknownFilesType = new Dictionary <string, TreeNode>();

            LoadingArchives loaderProgress = new LoadingArchives();

            int fileCount   = 0;
            int loadedCount = 0;

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

            loaderProgress.UpdateProgres(fileCount, 0);

            if (this.Visible)
            {
                loaderProgress.Parent = this;
                loaderProgress.Show();
            }
            else
            {
                loaderProgress.Show();
            }

            return(Task.Run(() =>
            {
                // Start loading
                SynchronizedCollection <ArchiveFileInfo> appendFiles = new SynchronizedCollection <ArchiveFileInfo>();

                List <Task> loadTasks = new List <Task>();
                IAsyncResult updateCall = null;

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

                    loadTasks.Add(a.ListFilesAsync((ArchiveFileInfo file) =>
                    {
                        appendFiles.Add(file);
                        loadedCount++;

                        if (appendFiles.Count >= 100)
                        {
                            lock (appendFiles.SyncRoot)
                            {
                                ArchiveFileInfo[] files = appendFiles.ToArray();
                                appendFiles.Clear();

                                this.AppendFileBrowser(files);
                                loaderProgress.UpdateProgres(fileCount, loadedCount);

                                /*if (updateCall == null || updateCall.IsCompleted)
                                 * {
                                 *  updateCall = this.BeginInvoke((MethodInvoker)delegate ()
                                 *  {
                                 *      this.UpdateFileBrowser();
                                 *  });
                                 * }*/
                            }
                        }
                    }));
                }

                Task.WaitAll(loadTasks.ToArray());

                loaderProgress.UpdateProgres(fileCount, loadedCount);

                this.AppendFileBrowser(appendFiles.ToArray());

                this.BeginInvoke((MethodInvoker) delegate()
                {
                    this.UpdateFileBrowser();
                    this.Show();
                }).AsyncWaitHandle.WaitOne();;

                loaderProgress.BeginInvoke((MethodInvoker) delegate() { loaderProgress.Close(); });

                Console.WriteLine("All files added");
            }));
        }