private void DumpBufferInfo() { var gameDirectory = Environment.GetEnvironmentVariable("CP77_DIR", EnvironmentVariableTarget.User); var exe = new FileInfo(Path.Combine(gameDirectory, "bin", "x64", Constants.Red4Exe)); _archiveManager.LoadGameArchives(exe, false); var groupedFiles = _archiveManager.GetGroupedFiles(); _logger.LogInformation("ArchiveManager loaded"); var exclude = new List <String>() { ".wem" }; foreach (var(key, fileEntries) in groupedFiles) { if (exclude.Contains(key)) { continue; } InspectFiles(groupedFiles, _archiveManager, key); } void InspectFiles(Dictionary <string, IEnumerable <FileEntry> > groupedFiles, IArchiveManager bm, string ext) { var fileslist = groupedFiles[ext].ToList(); _logger.LogInformation("Loaded {fileslist.Count} {ext} files", fileslist.Count, ext); var logpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "logs", $"blog_{ext.TrimStart('.')}.csv"); using var fs = new FileStream(logpath, FileMode.Create, FileAccess.Write); using var sw = new StreamWriter(fs); sw.WriteLine($"name;flags"); int latest = 0; int unknown = 0; int pre = 0; for (var i = 1; i < fileslist.Count + 1; i++) { var file = fileslist[i - 1]; var ar = bm.Archives.Lookup(file.Archive.ArchiveAbsolutePath).Value as Archive; using var ms = new MemoryStream(); ar.CopyFileToStreamWithoutBuffers(ms, file.NameHash64); var c = new CR2WFile { FileName = file.NameOrHash }; ms.Seek(0, SeekOrigin.Begin); using var br = new BinaryReader(ms); try { var readResult = c.ReadHeaders(br); } catch (FormatException) { continue; } var buffers = c.Buffers; foreach (var buffer in buffers) { sw.WriteLine($"{file.Name};{buffer.Flags.ToString("X")}"); } var percf = (float)i / (float)fileslist.Count * 100; Console.Write($"\r{i}/{fileslist.Count}-{(int)percf}%"); } _logger.LogInformation("[{ext}] unknown: {unknown}, pre: {pre}, latest: {latest}, ", ext, unknown, pre, latest); } }
protected static void Setup(TestContext context) { #region cp77 game dir // Init Console.WriteLine("BaseTestClass.BaseTestInitialize()"); s_config = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build(); s_writeToFile = bool.Parse(s_config.GetSection(s_writeToFileSetting).Value); // overrides hardcoded appsettings.json var cp77Dir = Environment.GetEnvironmentVariable("CP77_DIR", EnvironmentVariableTarget.User); if (!string.IsNullOrEmpty(cp77Dir) && new DirectoryInfo(cp77Dir).Exists) { s_gameDirectoryPath = cp77Dir; } else { s_gameDirectoryPath = s_config.GetSection(s_gameDirectorySetting).Value; } if (string.IsNullOrEmpty(s_gameDirectoryPath)) { throw new ConfigurationErrorsException($"'{s_gameDirectorySetting}' is not configured"); } var gameDirectory = new DirectoryInfo(s_gameDirectoryPath); if (!gameDirectory.Exists) { throw new ConfigurationErrorsException($"'{s_gameDirectorySetting}' is not a valid directory"); } #endregion #region oodle var gameBinDir = new DirectoryInfo(Path.Combine(gameDirectory.FullName, "bin", "x64")); var oodleInfo = new FileInfo(Path.Combine(gameBinDir.FullName, "oo2ext_7_win64.dll")); if (!oodleInfo.Exists) { Assert.Fail("Could not find oo2ext_7_win64.dll."); } var ass = AppDomain.CurrentDomain.BaseDirectory; var appOodleFileName = Path.Combine(ass, "oo2ext_7_win64.dll"); if (!File.Exists(appOodleFileName)) { oodleInfo.CopyTo(appOodleFileName); } if (!OodleLoadLib.Load(appOodleFileName)) { Assert.Fail("Could not load oo2ext_7_win64.dll."); } #endregion //protobuf RuntimeTypeModel.Default[typeof(IGameArchive)].AddSubType(20, typeof(Archive)); // IoC ServiceLocator.Default.RegisterInstance <ILoggerService>(new CatelLoggerService(false)); ServiceLocator.Default.RegisterType <IHashService, HashService>(); ServiceLocator.Default.RegisterType <IProgressService <double>, ProgressService <double> >(); ServiceLocator.Default.RegisterType <Red4ParserService>(); ServiceLocator.Default.RegisterType <MeshTools>(); //RIG, Cp77FileService ServiceLocator.Default.RegisterType <IArchiveManager, ArchiveManager>(); ServiceLocator.Default.RegisterType <IModTools, ModTools>(); //Cp77FileService, ILoggerService, IProgress, IHashService, Mesh, Target var hashService = ServiceLocator.Default.ResolveType <IHashService>(); s_bm = ServiceLocator.Default.ResolveType <IArchiveManager>(); var archivedir = new DirectoryInfo(Path.Combine(gameDirectory.FullName, "archive", "pc", "content")); s_bm.LoadFromFolder(archivedir); s_groupedFiles = s_bm.GetGroupedFiles(); var keyes = s_groupedFiles.Keys.ToList(); var keystring = string.Join(',', keyes); //Console.WriteLine(keystring); }