예제 #1
0
        public void RemoveNotExistingFiles(WindowProgressForm dbprog, object args)
        {
            Changed = true;
            var count       = 0;
            var totalBlocks = ChunkList.Count;

            dbprog.Invoke((Action) delegate
            {
                dbprog.Text                = "Cleaning toc.bin";
                dbprog.lblCommand.Text     = "Removing not existing files from PCConsoleTOC.bin";
                dbprog.progressBar.Maximum = totalBlocks;
                dbprog.progressBar.Value   = 0;
            });

            foreach (var element in ChunkList)
            {
                dbprog.Invoke((Action) delegate
                {
                    dbprog.progressBar.Value = count++;
                    dbprog.richTextBox.Text  = "Cleaning block " + count + " of " + totalBlocks;
                });

                if (element.FileList != null)
                {
                    element.FileList = element.FileList.Where(x => x.Exist).ToList();
                }

                //element.countNextFiles = (element.fileList == null) ? 0 : element.fileList.Count/*(x => x.exist)*/;
            }
        }
예제 #2
0
        public void FixAll(WindowProgressForm dbprog, object args)
        {
            Changed = true;

            var count = 0;
            var total = ChunkList.Count;

            dbprog.Invoke((Action) delegate
            {
                dbprog.Text                = "Fixing toc.bin";
                dbprog.lblCommand.Text     = "Updating PCConsoleTOC.bin";
                dbprog.progressBar.Maximum = total;
                dbprog.progressBar.Value   = 0;
            });

            using (File.OpenWrite(TocFilePath))
            {
                var tocPath = Path.GetDirectoryName(TocFilePath);

                foreach (var entry in ChunkList)
                {
                    dbprog.Invoke((Action) delegate
                    {
                        dbprog.progressBar.Value = count++;
                        dbprog.richTextBox.Text  = "Fixing block " + count + " of " + total;
                    });

                    if (entry.FileList == null)
                    {
                        continue;
                    }

                    foreach (var fileStruct in entry.FileList)
                    {
                        var filePath = tocPath + "\\" + fileStruct.FilePath;

                        if (!File.Exists(filePath))
                        {
                            filePath = GamePath + "\\" + fileStruct.FilePath;
                        }

                        if (!File.Exists(filePath) || fileStruct.FilePath == "BioGame\\PCConsoleTOC.bin" || fileStruct.FilePath.EndsWith("PCConsoleTOC.bin", StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }

                        using (var fileStream = File.OpenRead(filePath))
                        {
                            if (fileStruct.FileSize == fileStream.Length)
                            {
                                continue;
                            }

                            fileStruct.FileSize = (int)fileStream.Length;

                            using (var sha = SHA1.Create())
                            {
                                sha.Initialize();
                                var buffer     = new byte[fileStream.Length];
                                var inputCount = fileStream.Read(buffer, 0, buffer.Length);
                                sha.TransformBlock(buffer, 0, inputCount, null, 0);
                                sha.TransformFinalBlock(buffer, 0, 0);
                                fileStruct.Sha1 = sha.Hash;
                            }
                        }
                    }
                }
            }
        }