diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..8b92c61 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,316 @@ +# see http://editorconfig.org/ for docs on this file + +root = true + +# _ _ _ +# | | | | (_) +# ___ ___ _ __ ___ _ __ ___ ___ _ __ ___ ___| |_| |_ _ _ __ __ _ ___ +# / __/ _ \| '_ ` _ \| '_ ` _ \ / _ \| '_ \ / __|/ _ \ __| __| | '_ \ / _` / __| +# | (_| (_) | | | | | | | | | | | (_) | | | | \__ \ __/ |_| |_| | | | | (_| \__ \ +# \___\___/|_| |_| |_|_| |_| |_|\___/|_| |_| |___/\___|\__|\__|_|_| |_|\__, |___/ +# __/ | +# |___/ + +[*] + +# sanity across platforms +end_of_line = lf + +# this is our general standard: exceptions permitted only when a) required by the format or b) strong de facto convention +indent_style = space +indent_size = 4 + +# prevent files with BOMs on them coming into the repo +charset = utf-8 + +# other common settings +trim_trailing_whitespace = true +insert_final_newline = true + +cpp_space_pointer_reference_alignment = left + +# _ _ +# (_) | | +# _____ _____ _ __ _ __ _ __| | ___ ___ +# / _ \ \ / / _ \ '__| '__| |/ _` |/ _ \/ __| +# | (_) \ V / __/ | | | | | (_| | __/\__ \ +# \___/ \_/ \___|_| |_| |_|\__,_|\___||___/ +# +# + +[{Makefile,makefile}] +indent_style = tab + +[*.{md,markdown,mdx}] +# trailing whitespace is significant in markdown (bad choice, bad!) +trim_trailing_whitespace = false + +# crlf because tool expectations (based on experimentation) +[*.{bat,cmd,xaml,tt,t4,ttinclude}] +end_of_line = crlf + +[*.{json,asmdef}] +indent_size = 2 + +[*.{yaml,yml}] +indent_size = 2 + +# msbuild-related files (these are usually not tool-authored) +[*.{props,targets,msbuildproj,proj}] +indent_size = 2 + +### visual studio + +# these settings are based on experiments to see how vs will modify a file after it has been +# manually edited. the settings are meant to match what vs does to minimize unnecessary diffs. + +# related notes from research: +# +# 1. rider tends to preserve existing file settings, but we must go with the more strict vs. +# +# 2. file-new templates in vs, rider, and `dotnet new` contain bom's (byte order markers) and +# crlf. crlf we must preserve because vs, but bom's must be burned with fire. all editors are +# fine with this. + +[*.sln] +indent_style = tab +end_of_line = crlf +insert_final_newline = false + +[*.{vcxproj,vcxproj.filters}] +indent_size = 2 +end_of_line = crlf +insert_final_newline = false + +[*.vcproj] +indent_style = tab +end_of_line = crlf + +# csproj is a bit more flexible, in part because VS does some preservation of whitespace. however, +# lines it adds will get crlf's, and if the rest of the file has lf, we'll get a mixed file. so we +# must set the whole thing to be crlf. +[*.csproj] +indent_size = 2 +end_of_line = crlf + + +# __ _ _ +# / _| | | | | +# | |_ ___ _ __ _ __ ___ __ _| |_ _ __ _ _| | ___ ___ +# | _/ _ \| '__| '_ ` _ \ / _` | __| | '__| | | | |/ _ \/ __| +# | || (_) | | | | | | | | (_| | |_ | | | |_| | | __/\__ \ +# |_| \___/|_| |_| |_| |_|\__,_|\__| |_| \__,_|_|\___||___/ +# +# + +# http://go/format +# https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-format + + +[*.cs] + +# The entire monorepo has a single standard. +# +# if you want to propose changes to the standard, raise it with the people assigned to .editorconfig in +# .github/UNITY_CODEOWNERS. + +# ___ ___ __ __ __ ___ +# | | |__| | | |__ /__` |__) /\ / ` |__ +# |/\| | | | | |___ .__/ | /~~\ \__, |___ + +# whitespace-only format uses options under IDE0055 (https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0055) +# +# IDE0055 is made up of these formatting options: +# - https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/csharp-formatting-options +# - https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/dotnet-formatting-options + +# to reformat code with these rules, use `dotnet format whitespace --folder`. the rules are exclusively about +# code structure and do not require symbol awareness. they can be run on any file without needing a project or compile +# to be done first. + +# newline options +csharp_new_line_before_open_brace = all +csharp_new_line_before_else = true +csharp_new_line_before_catch = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_between_query_expression_clauses = true + +# indentation options +csharp_indent_case_contents = true +csharp_indent_switch_labels = true +csharp_indent_labels = one_less_than_current +csharp_indent_block_contents = true +csharp_indent_braces = false +csharp_indent_case_contents_when_block = false + +# spacing +csharp_space_after_cast = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_between_parentheses = false +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_around_binary_operators = before_and_after +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_after_comma = true +csharp_space_before_comma = false +csharp_space_after_dot = false +csharp_space_before_dot = false +csharp_space_after_semicolon_in_for_statement = true +csharp_space_before_semicolon_in_for_statement = false +csharp_space_around_declaration_statements = false +csharp_space_before_open_square_brackets = false +csharp_space_between_empty_square_brackets = false +csharp_space_between_square_brackets = false + +# wrap options +csharp_preserve_single_line_statements = true +csharp_preserve_single_line_blocks = true +max_line_length = 120 + +# using directives +dotnet_sort_system_directives_first = true +dotnet_separate_import_directive_groups = false + +# __ ___ ___ +# /__` | \ / | |__ +# .__/ | | |___ |___ + +# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ + +# Code-style naming rules +# https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/naming-rules +# A. dotnet_naming_symbols: specify a symbol group +# B. dotnet_naming_style: specify a naming style +# C. dotnet_naming_rule: specify a rule that applies a naming style to a symbol group + +# 1. General symbol rules +# 1.1 Namespaces, classes, structs, enumerations, methods, and delegates: PascalCase +dotnet_naming_symbols.majority_of_symbols.applicable_kinds = namespace, class, struct, enum, method, delegate +dotnet_naming_symbols.majority_of_symbols.applicable_accessibilities = * +# 1.2 Modifier preferences +dotnet_style_require_accessibility_modifiers = omit_if_default:suggestion +dotnet_style_readonly_field = true:suggestion + +# NOTE camelCase vs PascalCase for public fields/properties/events is the only different between +# UnityEngine/UnityEditor and Unity (non-UnityEngine/UnityEditor to be exact) namespace conventions. +# Search for "NOTE Unity namespace" to find the appropriate places where to do the adjustments. +dotnet_naming_style.camel_case_style.capitalization = camel_case +dotnet_naming_style.pascal_case_style.capitalization = pascal_case + +dotnet_naming_rule.majority_of_symbols_should_be_pascal_case.symbols = majority_of_symbols # The symbol group that the rule applies to +dotnet_naming_rule.majority_of_symbols_should_be_pascal_case.style = pascal_case_style # The naming style to associate with the rule +dotnet_naming_rule.majority_of_symbols_should_be_pascal_case.severity = suggestion # The severity for enforcing the convention + +# 1.2 Interfaces: IPascalCase +dotnet_naming_symbols.interfaces.applicable_kinds = interface +dotnet_naming_symbols.interfaces.applicable_accessibilities = * + +dotnet_naming_style.ipascal_case_style.capitalization = pascal_case +dotnet_naming_style.ipascal_case_style.required_prefix = I + +dotnet_naming_rule.interfaces_should_begin_with_i.symbols = interfaces +dotnet_naming_rule.interfaces_should_begin_with_i.style = ipascal_case_style +dotnet_naming_rule.interfaces_should_begin_with_i.severity = suggestion + +# 1.3 Type parameters: TPascalCase +dotnet_naming_symbols.type_parameters.applicable_kinds = type_parameter +dotnet_naming_symbols.type_parameters.applicable_accessibilities = * + +dotnet_naming_style.tpascal_case_style.capitalization = pascal_case +dotnet_naming_style.tpascal_case_style.required_prefix = T + +dotnet_naming_rule.type_parameters_should_beging_with_t.symbols = type_parameters +dotnet_naming_rule.type_parameters_should_beging_with_t.style = tpascal_case_style +dotnet_naming_rule.type_parameters_should_beging_with_t.severity = suggestion + +# 2. Public fields, including events, all properties: + +# Public fields and properties case depends on the namespace and can't be generalized. +# Public fields and properties in UnityEngine and UnityEditor namespaces should use camelCase, +# and they should PascalCase in other namespaces. + +# To enforce this another .editorconfig file will be needed in the subfolders containing either +# UnityEngine and UnityEditor code or other namespace code. +# See /Modules/HierarchyCore/.editorconfig for an example of overriden rules for specific namespaces. + +# 2.1 fields +dotnet_naming_symbols.public_fields.applicable_kinds = field, event +dotnet_naming_symbols.public_fields.applicable_accessibilities = public + +dotnet_naming_rule.public_fields_use_correct_case.symbols = public_fields +dotnet_naming_rule.public_fields_use_correct_case.style = pascal_case_style +dotnet_naming_rule.public_fields_use_correct_case.severity = none + +# 2.2 properties +dotnet_naming_symbols.properties.applicable_kinds = property +dotnet_naming_symbols.properties.applicable_accessibilities = * + +dotnet_naming_rule.properties_use_correct_case.symbols = properties +dotnet_naming_rule.properties_use_correct_case.style = pascal_case_style +dotnet_naming_rule.properties_use_correct_case.severity = none + +# 3. Non-public fields, including events: m_PascalCase +dotnet_naming_symbols.nonpublic_fields.applicable_kinds = field, event +dotnet_naming_symbols.nonpublic_fields.applicable_accessibilities = internal, private, protected, protected_internal, private_protected + +dotnet_naming_style.m_pascal_case_style.capitalization = pascal_case +dotnet_naming_style.m_pascal_case_style.required_prefix = m_ + +dotnet_naming_rule.nonpublic_fields_must_be_prefixed.symbols = nonpublic_fields +dotnet_naming_rule.nonpublic_fields_must_be_prefixed.style = m_pascal_case_style +dotnet_naming_rule.nonpublic_fields_must_be_prefixed.severity = suggestion + +# 4. Non-public static fields: s_PascalCase +dotnet_naming_symbols.nonpublic_static_fields.applicable_kinds = field, event +dotnet_naming_symbols.nonpublic_static_fields.applicable_accessibilities = internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.nonpublic_static_fields.required_modifiers = static + +dotnet_naming_style.s_pascal_case_style.capitalization = pascal_case +dotnet_naming_style.s_pascal_case_style.required_prefix = s_ + +dotnet_naming_rule.nonpublic_static_fields_must_be_prefixed.symbols = nonpublic_static_fields +dotnet_naming_rule.nonpublic_static_fields_must_be_prefixed.style = s_pascal_case_style +dotnet_naming_rule.nonpublic_static_fields_must_be_prefixed.severity = suggestion + +# 5. Non-public const fields: k_PascalCase +dotnet_naming_symbols.nonpublic_const_fields.applicable_kinds = field, event +dotnet_naming_symbols.nonpublic_const_fields.applicable_accessibilities = internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.nonpublic_const_fields.required_modifiers = const + +dotnet_naming_style.k_pascal_case_style.capitalization = pascal_case +dotnet_naming_style.k_pascal_case_style.required_prefix = k_ + +dotnet_naming_rule.nonpublic_const_fields_must_be_prefixed.symbols = nonpublic_const_fields +dotnet_naming_rule.nonpublic_const_fields_must_be_prefixed.style = k_pascal_case_style +dotnet_naming_rule.nonpublic_const_fields_must_be_prefixed.severity = suggestion + +# 6. Non-public static readonly fields: k_PascalCase +dotnet_naming_symbols.nonpublic_static_readonly_fields.applicable_kinds = field +dotnet_naming_symbols.nonpublic_static_readonly_fields.applicable_accessibilities = internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.nonpublic_static_readonly_fields.required_modifiers = static, readonly + +dotnet_naming_rule.nonpublic_static_readonly_fields_must_be_prefixed.symbols = nonpublic_static_readonly_fields +dotnet_naming_rule.nonpublic_static_readonly_fields_must_be_prefixed.style = k_pascal_case_style +dotnet_naming_rule.nonpublic_static_readonly_fields_must_be_prefixed.severity = suggestion + +# 7. Parameters and local variables: camelCase +# 7.1 parameters +dotnet_naming_symbols.parameters.applicable_kinds = parameter + +dotnet_naming_rule.parameters_must_be_camel_case.symbols = parameters +dotnet_naming_rule.parameters_must_be_camel_case.style = camel_case_style +dotnet_naming_rule.parameters_must_be_camel_case.severity = suggestion + +# 7.2 local variables +dotnet_naming_symbols.local_variables.applicable_kinds = local + +dotnet_naming_rule.local_variables_must_be_camel_case.symbols = local_variables +dotnet_naming_rule.local_variables_must_be_camel_case.style = camel_case_style +dotnet_naming_rule.local_variables_must_be_camel_case.severity = suggestion diff --git a/.gitignore b/.gitignore index 4ffc6cb..e71a9f7 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,9 @@ **/.idea/ **/launchSettings.json **/PublishProfiles/ +**/*.args.json + +.claude UnityFileSystemTestData/AssetBundles/ UnityFileSystemTestData/**/*.csproj diff --git a/Analyzer.Tests/ExpectedDataGenerator.cs b/Analyzer.Tests/ExpectedDataGenerator.cs index 32c008d..33c386c 100644 --- a/Analyzer.Tests/ExpectedDataGenerator.cs +++ b/Analyzer.Tests/ExpectedDataGenerator.cs @@ -16,8 +16,8 @@ public static void Generate(Context context) using var archive = UnityFileSystem.MountArchive(Path.Combine(context.UnityDataFolder, "assetbundle"), "/"); using var serializedFile = UnityFileSystem.OpenSerializedFile("/CAB-5d40f7cad7c871cf2ad2af19ac542994"); - using var fileReader = new UnityFileReader("archive:/CAB-5d40f7cad7c871cf2ad2af19ac542994", 1024*1024); - + using var fileReader = new UnityFileReader("archive:/CAB-5d40f7cad7c871cf2ad2af19ac542994", 1024 * 1024); + AddObject(-4850512016903265157, "Shader", serializedFile, fileReader, context, Shader.Read); AddObject(-9023202112035587373, "Texture1", serializedFile, fileReader, context, Texture2D.Read); AddObject(404836592933730457, "Texture2", serializedFile, fileReader, context, Texture2D.Read); @@ -25,7 +25,7 @@ public static void Generate(Context context) AddObject(4693305862354978555, "Mesh", serializedFile, fileReader, context, Mesh.Read); AddObject(-8074603400156879931, "AudioClip", serializedFile, fileReader, context, AudioClip.Read); AddObject(1, "AssetBundle", serializedFile, fileReader, context, AssetBundle.Read); - + var csprojFolder = Directory.GetParent(context.TestDataFolder).Parent.Parent.Parent.FullName; var outputFolder = Path.Combine(csprojFolder, "ExpectedData", context.UnityDataVersion); @@ -39,7 +39,7 @@ static void AddObject(long id, string name, SerializedFile serializedFile, Un var node = serializedFile.GetTypeTreeRoot(objectInfo.Id); var reader = new RandomAccessReader(serializedFile, node, fileReader, objectInfo.Offset); var obj = creator(reader); - + context.ExpectedData.Add(name, obj); } } diff --git a/Analyzer.Tests/SerializedObjectsTests.cs b/Analyzer.Tests/SerializedObjectsTests.cs index 647dd75..f0ce801 100644 --- a/Analyzer.Tests/SerializedObjectsTests.cs +++ b/Analyzer.Tests/SerializedObjectsTests.cs @@ -21,7 +21,7 @@ public class SerializedObjectsTests : AssetBundleTestFixture public SerializedObjectsTests(Context context) : base(context) { } - + protected override void OnLoadExpectedData(Context context) { // Uncomment to regenerate expected data. @@ -36,9 +36,9 @@ public void OneTimeSetup() var path = Path.Combine(Context.UnityDataFolder, "assetbundle"); m_Archive = UnityFileSystem.MountArchive(path, "archive:/"); m_SerializedFile = UnityFileSystem.OpenSerializedFile("archive:/CAB-5d40f7cad7c871cf2ad2af19ac542994"); - m_FileReader = new UnityFileReader("archive:/CAB-5d40f7cad7c871cf2ad2af19ac542994", 1024*1024); + m_FileReader = new UnityFileReader("archive:/CAB-5d40f7cad7c871cf2ad2af19ac542994", 1024 * 1024); } - + [OneTimeTearDown] public void TearDown() { @@ -48,7 +48,7 @@ public void TearDown() UnityFileSystem.Cleanup(); } - + T ReadObject(long id, Func creator) { var objectInfo = m_SerializedFile.Objects.First(x => x.Id == id); @@ -63,7 +63,7 @@ public void TestTexture2d(string name, long id) { var texture = ReadObject(id, Texture2D.Read); var expectedTexture = (Texture2D)Context.ExpectedData.Get(name); - + Assert.AreEqual(expectedTexture.Name, texture.Name); Assert.AreEqual(expectedTexture.StreamDataSize, texture.StreamDataSize); Assert.AreEqual(expectedTexture.Width, texture.Width); @@ -72,24 +72,24 @@ public void TestTexture2d(string name, long id) Assert.AreEqual(expectedTexture.MipCount, texture.MipCount); Assert.AreEqual(expectedTexture.RwEnabled, texture.RwEnabled); } - + [Test] public void TestAnimationClip() { var clip = ReadObject(2152370074763270995, AnimationClip.Read); var expectedClip = (AnimationClip)Context.ExpectedData.Get("AnimationClip"); - + Assert.AreEqual(expectedClip.Name, clip.Name); Assert.AreEqual(expectedClip.Events, clip.Events); Assert.AreEqual(expectedClip.Legacy, clip.Legacy); } - + [Test] public void TestAudioClip() { var clip = ReadObject(-8074603400156879931, AudioClip.Read); var expectedClip = (AudioClip)Context.ExpectedData.Get("AudioClip"); - + Assert.AreEqual(expectedClip.Name, clip.Name); Assert.AreEqual(expectedClip.Channels, clip.Channels); Assert.AreEqual(expectedClip.Format, clip.Format); @@ -98,13 +98,13 @@ public void TestAudioClip() Assert.AreEqual(expectedClip.BitsPerSample, clip.BitsPerSample); Assert.AreEqual(expectedClip.StreamDataSize, clip.StreamDataSize); } - + [Test] public void TestAssetBundle() { var bundle = ReadObject(1, AssetBundle.Read); var expectedBundle = (AssetBundle)Context.ExpectedData.Get("AssetBundle"); - + Assert.AreEqual(expectedBundle.Name, bundle.Name); Assert.AreEqual(expectedBundle.Assets.Count, bundle.Assets.Count); @@ -112,19 +112,19 @@ public void TestAssetBundle() { var asset = bundle.Assets[i]; var expectedAsset = expectedBundle.Assets[i]; - + Assert.AreEqual(expectedAsset.Name, asset.Name); Assert.AreEqual(expectedAsset.PPtr.FileId, asset.PPtr.FileId); Assert.AreEqual(expectedAsset.PPtr.PathId, asset.PPtr.PathId); } } - + [Test] public void TestMesh() { var mesh = ReadObject(4693305862354978555, Mesh.Read); var expectedMesh = (Mesh)Context.ExpectedData.Get("Mesh"); - + Assert.AreEqual(expectedMesh.Name, mesh.Name); Assert.AreEqual(expectedMesh.Bones, mesh.Bones); Assert.AreEqual(expectedMesh.Compression, mesh.Compression); @@ -133,14 +133,14 @@ public void TestMesh() Assert.AreEqual(expectedMesh.BlendShapes, mesh.BlendShapes); Assert.AreEqual(expectedMesh.RwEnabled, mesh.RwEnabled); Assert.AreEqual(expectedMesh.StreamDataSize, mesh.StreamDataSize); - + Assert.AreEqual(expectedMesh.Channels.Count, mesh.Channels.Count); for (int i = 0; i < mesh.Channels.Count; ++i) { var channel = mesh.Channels[i]; var expectedChannel = expectedMesh.Channels[i]; - + Assert.AreEqual(expectedChannel.Dimension, channel.Dimension); Assert.AreEqual(expectedChannel.Type, channel.Type); Assert.AreEqual(expectedChannel.Usage, channel.Usage); @@ -152,7 +152,7 @@ public void TestShaderReader() { var shader = ReadObject(-4850512016903265157, Shader.Read); var expectedShader = (Shader)Context.ExpectedData.Get("Shader"); - + Assert.AreEqual(expectedShader.Name, shader.Name); Assert.AreEqual(expectedShader.DecompressedSize, shader.DecompressedSize); CollectionAssert.AreEquivalent(expectedShader.Keywords, shader.Keywords); @@ -162,14 +162,14 @@ public void TestShaderReader() { var subShader = shader.SubShaders[i]; var expectedSubShader = shader.SubShaders[i]; - + Assert.AreEqual(expectedSubShader.Passes.Count, subShader.Passes.Count); for (int j = 0; j < subShader.Passes.Count; ++j) { var pass = subShader.Passes[i]; var expectedPass = expectedSubShader.Passes[i]; - + Assert.AreEqual(expectedPass.Name, pass.Name); Assert.AreEqual(expectedPass.Programs.Count, pass.Programs.Count); CollectionAssert.AreEquivalent(expectedPass.Programs.Keys, pass.Programs.Keys); @@ -185,7 +185,7 @@ public void TestShaderReader() { var program = programs[k]; var expectedProgram = expectedPrograms[k]; - + Assert.AreEqual(expectedProgram.Api, program.Api); Assert.AreEqual(expectedProgram.BlobIndex, program.BlobIndex); Assert.AreEqual(expectedProgram.HwTier, program.HwTier); diff --git a/Analyzer/AnalyzerTool.cs b/Analyzer/AnalyzerTool.cs index 2264b31..4fd5364 100644 --- a/Analyzer/AnalyzerTool.cs +++ b/Analyzer/AnalyzerTool.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -29,7 +29,7 @@ public int Analyze( { m_Verbose = verbose; - using SQLiteWriter writer = new (databaseName); + using SQLiteWriter writer = new(databaseName); try { @@ -39,7 +39,7 @@ public int Analyze( parser.Verbose = verbose; parser.SkipReferences = skipReferences; parser.Init(writer.Connection); - + } } catch (Exception e) @@ -63,7 +63,7 @@ public int Analyze( foreach (var file in files) { bool foundParser = false; - foreach(var parser in parsers) + foreach (var parser in parsers) { if (parser.CanParse(file)) { @@ -71,11 +71,11 @@ public int Analyze( try { parser.Parse(file); - ReportProgress(Path.GetRelativePath(path, file), i, files.Length); + ReportProgress(Path.GetRelativePath(path, file), i, files.Length); countSuccess++; } catch (Exception e) - { + { EraseProgressLine(); Console.Error.WriteLine(); Console.Error.WriteLine($"Error processing file: {file}"); @@ -94,7 +94,7 @@ public int Analyze( Console.WriteLine(); Console.WriteLine($"Ignoring {relativePath}"); } - + countIgnored++; } ++i; @@ -142,4 +142,4 @@ void EraseProgressLine() else Console.WriteLine(); } -} \ No newline at end of file +} diff --git a/Analyzer/PPtrAndCrcProcessor.cs b/Analyzer/PPtrAndCrcProcessor.cs index 85e0703..b9d88a1 100644 --- a/Analyzer/PPtrAndCrcProcessor.cs +++ b/Analyzer/PPtrAndCrcProcessor.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Text; @@ -354,4 +354,4 @@ private void ExtractPPtr(string referencedType) m_Crc32 = Crc32Algorithm.Append(m_Crc32, m_pptrBytes); } } -} \ No newline at end of file +} diff --git a/Analyzer/SQLite/Commands/AbstractCommand.cs b/Analyzer/SQLite/Commands/AbstractCommand.cs index 74d65fd..d433949 100644 --- a/Analyzer/SQLite/Commands/AbstractCommand.cs +++ b/Analyzer/SQLite/Commands/AbstractCommand.cs @@ -1,4 +1,4 @@ -using Microsoft.Data.Sqlite; +using Microsoft.Data.Sqlite; using System; using System.Collections.Generic; using System.Text; diff --git a/Analyzer/SQLite/Commands/AddressablesBuildReport/AddressablesBuild.cs b/Analyzer/SQLite/Commands/AddressablesBuildReport/AddressablesBuild.cs index d7ccb30..ad06f1f 100644 --- a/Analyzer/SQLite/Commands/AddressablesBuildReport/AddressablesBuild.cs +++ b/Analyzer/SQLite/Commands/AddressablesBuildReport/AddressablesBuild.cs @@ -1,4 +1,4 @@ -using Microsoft.Data.Sqlite; +using Microsoft.Data.Sqlite; using System.Collections.Generic; namespace UnityDataTools.Analyzer.SQLite.Commands.AddressablesBuildReport @@ -8,7 +8,9 @@ internal class AddressablesBuild : AbstractCommand protected override string TableName { get => "addressables_builds"; } protected override string DDLSource => Properties.Resources.AddrBuilds; - protected override Dictionary Fields { get => new Dictionary + protected override Dictionary Fields + { + get => new Dictionary { { "name", SqliteType.Text }, { "build_target", SqliteType.Integer }, @@ -21,7 +23,8 @@ internal class AddressablesBuild : AbstractCommand { "result_hash", SqliteType.Text }, { "type", SqliteType.Integer }, { "unity_version", SqliteType.Text } - }; } + }; + } public AddressablesBuild() { diff --git a/Analyzer/SQLite/Commands/AddressablesBuildReport/AddressablesBuildExplicitAsset.cs b/Analyzer/SQLite/Commands/AddressablesBuildReport/AddressablesBuildExplicitAsset.cs index 78f93b5..0ca5042 100644 --- a/Analyzer/SQLite/Commands/AddressablesBuildReport/AddressablesBuildExplicitAsset.cs +++ b/Analyzer/SQLite/Commands/AddressablesBuildReport/AddressablesBuildExplicitAsset.cs @@ -1,4 +1,4 @@ -using Microsoft.Data.Sqlite; +using Microsoft.Data.Sqlite; using System.Collections.Generic; namespace UnityDataTools.Analyzer.SQLite.Commands.AddressablesBuildReport diff --git a/Analyzer/SQLite/Commands/SerializedFile/AddAssetBundle.cs b/Analyzer/SQLite/Commands/SerializedFile/AddAssetBundle.cs index cbaac96..4df4623 100644 --- a/Analyzer/SQLite/Commands/SerializedFile/AddAssetBundle.cs +++ b/Analyzer/SQLite/Commands/SerializedFile/AddAssetBundle.cs @@ -25,4 +25,4 @@ internal class AddAssetBundle : AbstractCommand { "file_size", SqliteType.Integer } }; } -} \ No newline at end of file +} diff --git a/Analyzer/SQLite/Commands/SerializedFile/AddAssetDependency.cs b/Analyzer/SQLite/Commands/SerializedFile/AddAssetDependency.cs index 7854f48..aa45367 100644 --- a/Analyzer/SQLite/Commands/SerializedFile/AddAssetDependency.cs +++ b/Analyzer/SQLite/Commands/SerializedFile/AddAssetDependency.cs @@ -24,4 +24,4 @@ internal class AddAssetDependency : AbstractCommand { "dependency", SqliteType.Integer } }; } -} \ No newline at end of file +} diff --git a/Analyzer/SQLite/Commands/SerializedFile/AddObject.cs b/Analyzer/SQLite/Commands/SerializedFile/AddObject.cs index 2fec544..91dfe64 100644 --- a/Analyzer/SQLite/Commands/SerializedFile/AddObject.cs +++ b/Analyzer/SQLite/Commands/SerializedFile/AddObject.cs @@ -35,4 +35,4 @@ internal class AddObject : AbstractCommand { "crc32", SqliteType.Integer } }; } -} \ No newline at end of file +} diff --git a/Analyzer/SQLite/Commands/SerializedFile/AddReference.cs b/Analyzer/SQLite/Commands/SerializedFile/AddReference.cs index e2914ab..235840e 100644 --- a/Analyzer/SQLite/Commands/SerializedFile/AddReference.cs +++ b/Analyzer/SQLite/Commands/SerializedFile/AddReference.cs @@ -28,4 +28,4 @@ internal class AddReference : AbstractCommand { "property_type", SqliteType.Text } }; } -} \ No newline at end of file +} diff --git a/Analyzer/SQLite/Commands/SerializedFile/AddSerializedFile.cs b/Analyzer/SQLite/Commands/SerializedFile/AddSerializedFile.cs index 961ec44..2d616f2 100644 --- a/Analyzer/SQLite/Commands/SerializedFile/AddSerializedFile.cs +++ b/Analyzer/SQLite/Commands/SerializedFile/AddSerializedFile.cs @@ -26,4 +26,4 @@ internal class AddSerializedFile : AbstractCommand { "name", SqliteType.Text } }; } -} \ No newline at end of file +} diff --git a/Analyzer/SQLite/Commands/SerializedFile/AddType.cs b/Analyzer/SQLite/Commands/SerializedFile/AddType.cs index 8d035f0..f155cbc 100644 --- a/Analyzer/SQLite/Commands/SerializedFile/AddType.cs +++ b/Analyzer/SQLite/Commands/SerializedFile/AddType.cs @@ -24,4 +24,4 @@ internal class AddType : AbstractCommand { "name", SqliteType.Text } }; } -} \ No newline at end of file +} diff --git a/Analyzer/SQLite/Handlers/AnimationClipHandler.cs b/Analyzer/SQLite/Handlers/AnimationClipHandler.cs index 6251fe8..04cf62f 100644 --- a/Analyzer/SQLite/Handlers/AnimationClipHandler.cs +++ b/Analyzer/SQLite/Handlers/AnimationClipHandler.cs @@ -1,4 +1,4 @@ -using System; +using System; using Microsoft.Data.Sqlite; using UnityDataTools.Analyzer.SerializedObjects; using UnityDataTools.FileSystem.TypeTreeReaders; @@ -15,7 +15,7 @@ public void Init(SqliteConnection db) using var command = db.CreateCommand(); command.CommandText = Resources.AnimationClip; command.ExecuteNonQuery(); - + m_InsertCommand = db.CreateCommand(); m_InsertCommand.CommandText = "INSERT INTO animation_clips(id, legacy, events) VALUES(@id, @legacy, @events)"; m_InsertCommand.Parameters.Add("@id", SqliteType.Integer); @@ -44,4 +44,4 @@ void IDisposable.Dispose() { m_InsertCommand?.Dispose(); } -} \ No newline at end of file +} diff --git a/Analyzer/SQLite/Handlers/AssetBundleHandler.cs b/Analyzer/SQLite/Handlers/AssetBundleHandler.cs index fa4b3d4..d62695e 100644 --- a/Analyzer/SQLite/Handlers/AssetBundleHandler.cs +++ b/Analyzer/SQLite/Handlers/AssetBundleHandler.cs @@ -93,4 +93,4 @@ void IDisposable.Dispose() m_InsertCommand?.Dispose(); m_InsertDepCommand?.Dispose(); } -} \ No newline at end of file +} diff --git a/Analyzer/SQLite/Handlers/AudioClipHandler.cs b/Analyzer/SQLite/Handlers/AudioClipHandler.cs index 5d9af03..cde7ff2 100644 --- a/Analyzer/SQLite/Handlers/AudioClipHandler.cs +++ b/Analyzer/SQLite/Handlers/AudioClipHandler.cs @@ -1,4 +1,4 @@ -using System; +using System; using Microsoft.Data.Sqlite; using System.Data; using UnityDataTools.Analyzer.SerializedObjects; @@ -51,4 +51,4 @@ void IDisposable.Dispose() { m_InsertCommand?.Dispose(); } -} \ No newline at end of file +} diff --git a/Analyzer/SQLite/Handlers/ISQLiteHandler.cs b/Analyzer/SQLite/Handlers/ISQLiteHandler.cs index 66b0fea..147e15e 100644 --- a/Analyzer/SQLite/Handlers/ISQLiteHandler.cs +++ b/Analyzer/SQLite/Handlers/ISQLiteHandler.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using Microsoft.Data.Sqlite; using UnityDataTools.FileSystem.TypeTreeReaders; @@ -29,4 +29,4 @@ public interface ISQLiteFileParser : IDisposable void Parse(string filename); public bool Verbose { get; set; } public bool SkipReferences { get; set; } -} \ No newline at end of file +} diff --git a/Analyzer/SQLite/Handlers/MeshHandler.cs b/Analyzer/SQLite/Handlers/MeshHandler.cs index 85bb39c..df117d7 100644 --- a/Analyzer/SQLite/Handlers/MeshHandler.cs +++ b/Analyzer/SQLite/Handlers/MeshHandler.cs @@ -1,4 +1,4 @@ -using System; +using System; using Microsoft.Data.Sqlite; using System.Text; using UnityDataTools.Analyzer.SerializedObjects; @@ -54,7 +54,7 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s channels.Append(channel.Dimension); channels.AppendLine("]"); } - + m_InsertCommand.Parameters["@channels"].Value = channels.ToString(); m_InsertCommand.ExecuteNonQuery(); @@ -71,4 +71,4 @@ void IDisposable.Dispose() { m_InsertCommand?.Dispose(); } -} \ No newline at end of file +} diff --git a/Analyzer/SQLite/Handlers/PreloadDataHandler.cs b/Analyzer/SQLite/Handlers/PreloadDataHandler.cs index 75f1420..d0c9d1e 100644 --- a/Analyzer/SQLite/Handlers/PreloadDataHandler.cs +++ b/Analyzer/SQLite/Handlers/PreloadDataHandler.cs @@ -29,7 +29,7 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s { var fileId = ctx.LocalToDbFileId[asset.FileId]; var objId = ctx.ObjectIdProvider.GetId((fileId, asset.PathId)); - + m_InsertDepCommand.Parameters["@dependency"].Value = objId; m_InsertDepCommand.ExecuteNonQuery(); } @@ -46,4 +46,4 @@ void IDisposable.Dispose() { m_InsertDepCommand?.Dispose(); } -} \ No newline at end of file +} diff --git a/Analyzer/SQLite/Handlers/ShaderHandler.cs b/Analyzer/SQLite/Handlers/ShaderHandler.cs index dd2602b..b1eb520 100644 --- a/Analyzer/SQLite/Handlers/ShaderHandler.cs +++ b/Analyzer/SQLite/Handlers/ShaderHandler.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using Microsoft.Data.Sqlite; using UnityDataTools.FileSystem.TypeTreeReaders; @@ -11,7 +11,7 @@ public class ShaderHandler : ISQLiteHandler private SqliteCommand m_InsertSubProgramCommand; private SqliteCommand m_InsertKeywordCommand; private SqliteCommand m_InsertSubProgramKeywordsCommand; - + static long s_SubProgramId = 0; static Dictionary s_GlobalKeywords = new(); @@ -19,7 +19,7 @@ public void Init(SqliteConnection db) { s_SubProgramId = 0; s_GlobalKeywords.Clear(); - + using var command = db.CreateCommand(); command.CommandText = Resources.Shader; command.ExecuteNonQuery(); @@ -62,7 +62,7 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s for (int i = 0; i < shader.Keywords.Count; ++i) { var keyword = shader.Keywords[i]; - var id = GetKeywordId(keyword,ctx.Transaction); + var id = GetKeywordId(keyword, ctx.Transaction); localToGlobalKeywords[i] = id; } @@ -78,7 +78,7 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s for (int passIndex = 0; passIndex < subShader.Passes.Count; ++passIndex) { var pass = subShader.Passes[passIndex]; - m_InsertSubProgramCommand.Transaction = ctx.Transaction; + m_InsertSubProgramCommand.Transaction = ctx.Transaction; m_InsertSubProgramCommand.Parameters["@shader"].Value = objectId; m_InsertSubProgramCommand.Parameters["@pass"].Value = passIndex; m_InsertSubProgramCommand.Parameters["@pass_name"].Value = pass.Name; @@ -87,7 +87,7 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s { var progType = kv.Key; var programs = kv.Value; - + m_InsertSubProgramCommand.Parameters["@shader_type"].Value = progType; for (int programIndex = 0; programIndex < programs.Count; ++programIndex) @@ -95,13 +95,13 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s var program = programs[programIndex]; uniquePrograms.Add(program.BlobIndex); - + m_InsertSubProgramCommand.Parameters["@id"].Value = s_SubProgramId; m_InsertSubProgramCommand.Parameters["@sub_program"].Value = programIndex; m_InsertSubProgramCommand.Parameters["@hw_tier"].Value = program.HwTier; m_InsertSubProgramCommand.Parameters["@api"].Value = program.Api; m_InsertSubProgramCommand.ExecuteNonQuery(); - + m_InsertSubProgramKeywordsCommand.Transaction = ctx.Transaction; m_InsertSubProgramKeywordsCommand.Parameters["@subprogram_id"].Value = s_SubProgramId; foreach (var keyword in program.Keywords) @@ -115,11 +115,11 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s } } } - + m_InsertCommand.Parameters["@id"].Value = objectId; m_InsertCommand.Parameters["@decompressed_size"].Value = shader.DecompressedSize; m_InsertCommand.Parameters["@unique_programs"].Value = uniquePrograms.Count; - + m_InsertCommand.ExecuteNonQuery(); name = shader.Name; @@ -149,7 +149,7 @@ public void Finalize(SqliteConnection db) command.Connection = db; command.CommandText = "CREATE INDEX shader_subprograms_shader_index ON shader_subprograms(shader)"; command.ExecuteNonQuery(); - + command.CommandText = "CREATE INDEX shader_subprogram_keywords_subprogram_id_index ON shader_subprogram_keywords(subprogram_id)"; command.ExecuteNonQuery(); } @@ -161,4 +161,4 @@ void IDisposable.Dispose() m_InsertKeywordCommand?.Dispose(); m_InsertSubProgramKeywordsCommand?.Dispose(); } -} \ No newline at end of file +} diff --git a/Analyzer/SQLite/Handlers/Texture2DHandler.cs b/Analyzer/SQLite/Handlers/Texture2DHandler.cs index 0fc9499..5cdb6d9 100644 --- a/Analyzer/SQLite/Handlers/Texture2DHandler.cs +++ b/Analyzer/SQLite/Handlers/Texture2DHandler.cs @@ -1,4 +1,4 @@ -using System; +using System; using Microsoft.Data.Sqlite; using UnityDataTools.Analyzer.SerializedObjects; using UnityDataTools.FileSystem.TypeTreeReaders; @@ -49,4 +49,4 @@ void IDisposable.Dispose() { m_InsertCommand?.Dispose(); } -} \ No newline at end of file +} diff --git a/Analyzer/SQLite/Parsers/AddressablesBuildLayoutParser.cs b/Analyzer/SQLite/Parsers/AddressablesBuildLayoutParser.cs index 4390d16..0dab3ad 100644 --- a/Analyzer/SQLite/Parsers/AddressablesBuildLayoutParser.cs +++ b/Analyzer/SQLite/Parsers/AddressablesBuildLayoutParser.cs @@ -1,4 +1,4 @@ -using Microsoft.Data.Sqlite; +using Microsoft.Data.Sqlite; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; diff --git a/Analyzer/SQLite/Parsers/SerializedFileParser.cs b/Analyzer/SQLite/Parsers/SerializedFileParser.cs index 2773f1a..68df441 100644 --- a/Analyzer/SQLite/Parsers/SerializedFileParser.cs +++ b/Analyzer/SQLite/Parsers/SerializedFileParser.cs @@ -1,4 +1,4 @@ -using Microsoft.Data.Sqlite; +using Microsoft.Data.Sqlite; using System; using System.Collections.Generic; using System.IO; diff --git a/Analyzer/SQLite/Writers/AddressablesBuildLayoutSQLWriter.cs b/Analyzer/SQLite/Writers/AddressablesBuildLayoutSQLWriter.cs index 704a8be..0161706 100644 --- a/Analyzer/SQLite/Writers/AddressablesBuildLayoutSQLWriter.cs +++ b/Analyzer/SQLite/Writers/AddressablesBuildLayoutSQLWriter.cs @@ -1,4 +1,4 @@ -using Microsoft.Data.Sqlite; +using Microsoft.Data.Sqlite; using Newtonsoft.Json; using System; using System.IO; diff --git a/Analyzer/SQLite/Writers/SQLiteWriter.cs b/Analyzer/SQLite/Writers/SQLiteWriter.cs index db37f68..87c229a 100644 --- a/Analyzer/SQLite/Writers/SQLiteWriter.cs +++ b/Analyzer/SQLite/Writers/SQLiteWriter.cs @@ -1,4 +1,4 @@ -using Microsoft.Data.Sqlite; +using Microsoft.Data.Sqlite; using System; using System.Collections.Generic; using System.IO; @@ -13,7 +13,7 @@ public class SQLiteWriter : IDisposable private SqliteConnection m_Database; public SqliteConnection Connection => m_Database; private string m_DatabaseName; - + public SQLiteWriter(string databaseName) { diff --git a/Analyzer/SerializedObjects/AnimationClip.cs b/Analyzer/SerializedObjects/AnimationClip.cs index dbbc7ce..4d3fd03 100644 --- a/Analyzer/SerializedObjects/AnimationClip.cs +++ b/Analyzer/SerializedObjects/AnimationClip.cs @@ -7,8 +7,8 @@ public class AnimationClip public string Name { get; init; } public bool Legacy { get; init; } public int Events { get; init; } - - private AnimationClip() {} + + private AnimationClip() { } public static AnimationClip Read(RandomAccessReader reader) { @@ -19,4 +19,4 @@ public static AnimationClip Read(RandomAccessReader reader) Events = reader["m_Events"].GetArraySize() }; } -} \ No newline at end of file +} diff --git a/Analyzer/SerializedObjects/AssetBundle.cs b/Analyzer/SerializedObjects/AssetBundle.cs index 20d20f1..bd8b58d 100644 --- a/Analyzer/SerializedObjects/AssetBundle.cs +++ b/Analyzer/SerializedObjects/AssetBundle.cs @@ -4,7 +4,7 @@ namespace UnityDataTools.Analyzer.SerializedObjects; public class AssetBundle -{ +{ public string Name { get; init; } public IReadOnlyList Assets { get; init; } public IReadOnlyList PreloadTable { get; init; } @@ -17,7 +17,7 @@ public class Asset public int PreloadIndex { get; init; } public int PreloadSize { get; init; } - private Asset() {} + private Asset() { } public static Asset Read(RandomAccessReader reader) { @@ -30,21 +30,21 @@ public static Asset Read(RandomAccessReader reader) }; } } - - private AssetBundle() {} - + + private AssetBundle() { } + public static AssetBundle Read(RandomAccessReader reader) { var name = reader["m_Name"].GetValue(); var assets = new List(reader["m_Container"].GetArraySize()); var preloadTable = new List(reader["m_PreloadTable"].GetArraySize()); var isSceneAssetBundle = reader["m_IsStreamedSceneAssetBundle"].GetValue(); - + foreach (var pptr in reader["m_PreloadTable"]) { preloadTable.Add(PPtr.Read(pptr)); } - + foreach (var asset in reader["m_Container"]) { assets.Add(Asset.Read(asset)); @@ -58,4 +58,4 @@ public static AssetBundle Read(RandomAccessReader reader) IsSceneAssetBundle = isSceneAssetBundle }; } -} \ No newline at end of file +} diff --git a/Analyzer/SerializedObjects/AudioClip.cs b/Analyzer/SerializedObjects/AudioClip.cs index 2aae772..d228b81 100644 --- a/Analyzer/SerializedObjects/AudioClip.cs +++ b/Analyzer/SerializedObjects/AudioClip.cs @@ -12,7 +12,7 @@ public class AudioClip public int LoadType { get; init; } public int Format { get; init; } - private AudioClip() {} + private AudioClip() { } public static AudioClip Read(RandomAccessReader reader) { @@ -27,4 +27,4 @@ public static AudioClip Read(RandomAccessReader reader) StreamDataSize = reader["m_Resource"]["m_Size"].GetValue() }; } -} \ No newline at end of file +} diff --git a/Analyzer/SerializedObjects/Mesh.cs b/Analyzer/SerializedObjects/Mesh.cs index 8df6a72..4f0076a 100644 --- a/Analyzer/SerializedObjects/Mesh.cs +++ b/Analyzer/SerializedObjects/Mesh.cs @@ -23,7 +23,7 @@ public enum ChannelUsage BlendWeights, BlendIndices, }; - + public enum ChannelType { Float, @@ -56,11 +56,11 @@ public class Channel public int Vertices { get; init; } public int Compression { get; init; } public bool RwEnabled { get; init; } - + public IReadOnlyList Channels { get; init; } - + public int VertexSize { get; init; } - + private static readonly int[] s_ChannelTypeSizes = { 4, // Float @@ -77,7 +77,7 @@ public class Channel 4, // SInt32 }; - private Mesh() {} + private Mesh() { } public static Mesh Read(RandomAccessReader reader) { @@ -95,7 +95,7 @@ public static Mesh Read(RandomAccessReader reader) indices = reader["m_IndexBuffer"].GetArraySize() / bytesPerIndex; vertices = reader["m_VertexData"]["m_VertexCount"].GetValue(); - + // If vertex data size is 0, data is stored in a stream file. if (reader["m_VertexData"]["m_DataSize"].GetArraySize() == 0) { @@ -123,7 +123,7 @@ public static Mesh Read(RandomAccessReader reader) Type = (ChannelType)channel["format"].GetValue(), Usage = (ChannelUsage)i, }; - + channels.Add(c); vertexSize += dimension * s_ChannelTypeSizes[(int)c.Type]; } @@ -136,7 +136,7 @@ public static Mesh Read(RandomAccessReader reader) vertices = reader["m_CompressedMesh"]["m_Vertices"]["m_NumItems"].GetValue() / 3; indices = reader["m_CompressedMesh"]["m_Triangles"]["m_NumItems"].GetValue(); } - + return new Mesh() { Name = name, @@ -151,4 +151,4 @@ public static Mesh Read(RandomAccessReader reader) VertexSize = vertexSize, }; } -} \ No newline at end of file +} diff --git a/Analyzer/SerializedObjects/PPtr.cs b/Analyzer/SerializedObjects/PPtr.cs index c44054c..f024997 100644 --- a/Analyzer/SerializedObjects/PPtr.cs +++ b/Analyzer/SerializedObjects/PPtr.cs @@ -6,8 +6,8 @@ public class PPtr { public int FileId { get; init; } public long PathId { get; init; } - - private PPtr() {} + + private PPtr() { } public static PPtr Read(RandomAccessReader reader) { diff --git a/Analyzer/SerializedObjects/PreloadData.cs b/Analyzer/SerializedObjects/PreloadData.cs index 429c0cb..f010dc4 100644 --- a/Analyzer/SerializedObjects/PreloadData.cs +++ b/Analyzer/SerializedObjects/PreloadData.cs @@ -6,13 +6,13 @@ namespace UnityDataTools.Analyzer.SerializedObjects; public class PreloadData { public IReadOnlyList Assets { get; init; } - - private PreloadData() {} + + private PreloadData() { } public static PreloadData Read(RandomAccessReader reader) { var assets = new List(reader["m_Assets"].GetArraySize()); - + foreach (var pptr in reader["m_Assets"]) { assets.Add(PPtr.Read(pptr)); diff --git a/Analyzer/SerializedObjects/Shader.cs b/Analyzer/SerializedObjects/Shader.cs index 4fb495a..c53a568 100644 --- a/Analyzer/SerializedObjects/Shader.cs +++ b/Analyzer/SerializedObjects/Shader.cs @@ -10,29 +10,29 @@ public class Shader public IReadOnlyList SubShaders { get; init; } public IReadOnlyList Keywords { get; init; } - private Shader() {} + private Shader() { } public class SubShader { public IReadOnlyList Passes { get; init; } - + public class Pass { public string Name { get; init; } // The key is the program type (vertex, fragment...) - public IReadOnlyDictionary> Programs { get; init; } - + public IReadOnlyDictionary> Programs { get; init; } + public class SubProgram { public int HwTier { get; init; } public int Api { get; init; } public uint BlobIndex { get; init; } - + // Keyword index in ShaderData.Keywords public IReadOnlyList Keywords { get; init; } - - private SubProgram() {} + + private SubProgram() { } public static SubProgram Read(KeywordSet keywordSet, RandomAccessReader reader, Dictionary keywordNames, int hwTier = -1) { @@ -71,8 +71,8 @@ public static SubProgram Read(KeywordSet keywordSet, RandomAccessReader reader, } } } - - return new SubProgram() { Api = api, BlobIndex = blobIndex, HwTier = hwTier , Keywords = keywords }; + + return new SubProgram() { Api = api, BlobIndex = blobIndex, HwTier = hwTier, Keywords = keywords }; } } @@ -80,7 +80,7 @@ public static Pass Read(KeywordSet keywordSet, RandomAccessReader reader, Dictio { string name = null; Dictionary> programsPerType = new(); - + if (keywordNames == null) { keywordNames = new(); @@ -144,12 +144,12 @@ public static Pass Read(KeywordSet keywordSet, RandomAccessReader reader, Dictio if (subPrograms.Count > 0) { var programs = new List(subPrograms.GetArraySize()); - + foreach (var subProgram in subPrograms) { programs.Add(SubProgram.Read(keywordSet, subProgram, keywordNames)); } - + programsPerType[progType.typeName] = programs; } } @@ -163,13 +163,13 @@ public static SubShader Read(KeywordSet keywordSet, RandomAccessReader reader, D { var passesReader = reader["m_Passes"]; var passes = new List(passesReader.GetArraySize()); - + foreach (var pass in passesReader) { passes.Add(Pass.Read(keywordSet, pass, keywordNames)); } - return new SubShader() {Passes = passes}; + return new SubShader() { Passes = passes }; } } @@ -192,13 +192,13 @@ public static Shader Read(RandomAccessReader reader) } var subShadersReader = parsedForm["m_SubShaders"]; - List subShaders = new (subShadersReader.GetArraySize()); - + List subShaders = new(subShadersReader.GetArraySize()); + foreach (var subShader in subShadersReader) { subShaders.Add(SubShader.Read(keywordSet, subShader, keywordNames)); } - + int decompressedSize = 0; if (reader["decompressedLengths"].IsArrayOfObjects) @@ -244,11 +244,11 @@ public class KeywordSet private List m_Keywords = new(); private Dictionary m_KeywordToIndex = new(); - + public int GetKeywordIndex(string name) { int index; - + if (m_KeywordToIndex.TryGetValue(name, out index)) { return index; @@ -261,4 +261,4 @@ public int GetKeywordIndex(string name) return index; } } -} \ No newline at end of file +} diff --git a/Analyzer/SerializedObjects/Texture2D.cs b/Analyzer/SerializedObjects/Texture2D.cs index ddd7630..bc8eeeb 100644 --- a/Analyzer/SerializedObjects/Texture2D.cs +++ b/Analyzer/SerializedObjects/Texture2D.cs @@ -12,8 +12,8 @@ public class Texture2D public int MipCount { get; init; } public bool RwEnabled { get; init; } - private Texture2D() {} - + private Texture2D() { } + public static Texture2D Read(RandomAccessReader reader) { return new Texture2D() diff --git a/Analyzer/Util/IdProvider.cs b/Analyzer/Util/IdProvider.cs index cd5fefb..82ad30f 100644 --- a/Analyzer/Util/IdProvider.cs +++ b/Analyzer/Util/IdProvider.cs @@ -21,7 +21,7 @@ public IdProvider(bool bidirectional = false, IEqualityComparer comparer = public int GetId(Key key) { int id; - + if (m_Ids.TryGetValue(key, out id)) { return id; @@ -51,5 +51,5 @@ public Key GetKey(int id) public class ObjectIdProvider : IdProvider<(int fileId, long pathId)> { - public ObjectIdProvider(bool bidirectional = false) : base(bidirectional) {} + public ObjectIdProvider(bool bidirectional = false) : base(bidirectional) { } } diff --git a/ReferenceFinder/ReferenceFinderTool.cs b/ReferenceFinder/ReferenceFinderTool.cs index 8569f13..886b25f 100644 --- a/ReferenceFinder/ReferenceFinderTool.cs +++ b/ReferenceFinder/ReferenceFinderTool.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Data; using Microsoft.Data.Sqlite; @@ -12,7 +12,7 @@ public ReferenceTreeNode(long id) { Id = id; } - + public readonly long Id; public Dictionary<(long id, string propertyPath), ReferenceTreeNode> Children = new Dictionary<(long, string), ReferenceTreeNode>(); } @@ -267,4 +267,4 @@ ReferenceTreeNode ProcessReferences(long id, bool findAll) return wasUsed ? node : null; } -} \ No newline at end of file +} diff --git a/TestCommon/Context.cs b/TestCommon/Context.cs index 3450e2f..80601ca 100644 --- a/TestCommon/Context.cs +++ b/TestCommon/Context.cs @@ -1,4 +1,4 @@ -using System.IO; +using System.IO; using NUnit.Framework; namespace UnityDataTools.TestCommon; @@ -7,27 +7,27 @@ public class Context { // e.g. /bin/Debug/net6.0/Data/AssetBundles/2021.1.0f1 public string UnityDataFolder { get; } - + // e.g. 2021.1.0f1 public string UnityDataVersion { get; } - + // e.g. /bin/Debug/net6.0/Data public string TestDataFolder { get; } - + // e.g. /bin/Debug/net6.0/ExpectedData/2021.1.0f1 public string ExpectedDataFolder { get; } - + public ExpectedData ExpectedData { get; } = new(); public Context(string folder) { var di = new DirectoryInfo(folder); - + UnityDataFolder = folder; UnityDataVersion = di.Name; TestDataFolder = di.Parent.Parent.FullName; ExpectedDataFolder = Path.Combine(di.Parent.Parent.Parent.FullName, "ExpectedData", UnityDataVersion); - + ExpectedData.Load(ExpectedDataFolder); } diff --git a/TestCommon/ExpectedData.cs b/TestCommon/ExpectedData.cs index fcfd93f..92f2a15 100644 --- a/TestCommon/ExpectedData.cs +++ b/TestCommon/ExpectedData.cs @@ -17,12 +17,12 @@ public object Get(string key) { return m_ExpectedValues[key]; } - + public void Save(string path) { var settings = new JsonSerializerSettings(); settings.TypeNameHandling = TypeNameHandling.All; - + File.WriteAllText(Path.Combine(path, "ExpectedValues.json"), JsonConvert.SerializeObject(m_ExpectedValues, Formatting.Indented, settings)); } @@ -34,10 +34,10 @@ public void Load(string path) { return; } - + var settings = new JsonSerializerSettings(); settings.TypeNameHandling = TypeNameHandling.All; - + m_ExpectedValues = JsonConvert.DeserializeObject>(File.ReadAllText(path), settings); } } diff --git a/TestCommon/TestFixtures.cs b/TestCommon/TestFixtures.cs index b9c0c17..87dbdce 100644 --- a/TestCommon/TestFixtures.cs +++ b/TestCommon/TestFixtures.cs @@ -9,7 +9,7 @@ public class BaseTestFixture protected Context Context { get; } private static Dictionary> m_Cache = new(); - + public BaseTestFixture(Context context) { Context = context; @@ -25,7 +25,7 @@ public void LoadExpectedData() OnLoadExpectedData(Context); Context.ExpectedData.Load(Context.ExpectedDataFolder); } - + protected static IEnumerable GetContexts(string dataFolder) { if (m_Cache.TryGetValue(dataFolder, out var cases)) @@ -35,9 +35,9 @@ protected static IEnumerable GetContexts(string dataFolder) cases = new List(); m_Cache[TestContext.CurrentContext.TestDirectory] = cases; - + var subfolder = Path.Combine(TestContext.CurrentContext.TestDirectory, "Data", dataFolder); - + foreach (var folder in Directory.EnumerateDirectories(subfolder)) { cases.Add(new Context(folder)); @@ -53,7 +53,7 @@ public class AssetBundleTestFixture : BaseTestFixture public AssetBundleTestFixture(Context context) : base(context) { } - + public static IEnumerable GetContexts() { return BaseTestFixture.GetContexts("AssetBundles"); @@ -66,7 +66,7 @@ public class PlayerDataTestFixture : BaseTestFixture public PlayerDataTestFixture(Context context) : base(context) { } - + public static IEnumerable GetContexts() { return BaseTestFixture.GetContexts("PlayerData"); diff --git a/TextDumper/TextDumperTool.cs b/TextDumper/TextDumperTool.cs index 218dcc2..4846c71 100644 --- a/TextDumper/TextDumperTool.cs +++ b/TextDumper/TextDumperTool.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Text; using UnityDataTools.FileSystem; @@ -234,7 +234,7 @@ void DumpManagedReferenceRegistry(TypeTreeNode node, ref long offset, int level) int i = 0; while (DumpManagedReferenceData(refTypeNode, refObjData, ref offset, level, i++)) - {} + { } } else if (version == 2) { @@ -446,4 +446,4 @@ Array ReadBasicTypeArray(TypeTreeNode node, long offset, int arraySize) return array; } } -} \ No newline at end of file +} diff --git a/UnityDataTool.Tests/ExpectedDataGenerator.cs b/UnityDataTool.Tests/ExpectedDataGenerator.cs index 46323bb..888ba7c 100644 --- a/UnityDataTool.Tests/ExpectedDataGenerator.cs +++ b/UnityDataTool.Tests/ExpectedDataGenerator.cs @@ -10,12 +10,12 @@ public static class ExpectedDataGenerator public static void Generate(Context context) { var expectedData = context.ExpectedData; - + UnityFileSystem.Init(); using (var archive = UnityFileSystem.MountArchive(Path.Combine(context.UnityDataFolder, "assetbundle"), "/")) { expectedData.Add("NodeCount", archive.Nodes.Count); - + foreach (var n in archive.Nodes) { expectedData.Add(n.Path + "-Size", n.Size); @@ -23,9 +23,9 @@ public static void Generate(Context context) } } UnityFileSystem.Cleanup(); - + Program.Main(new string[] { "analyze", Path.Combine(context.UnityDataFolder), "-r" }); - + using var db = new SqliteConnection($"Data Source={Path.Combine(Directory.GetCurrentDirectory(), "database.db")};Version=3;New=True;Foreign Keys=False;"); db.Open(); @@ -67,7 +67,7 @@ public static void Generate(Context context) expectedData.Add("textures_count", reader.GetInt32(12)); expectedData.Add("types_count", reader.GetInt32(13)); } - + var csprojFolder = Directory.GetParent(context.TestDataFolder).Parent.Parent.Parent.FullName; var outputFolder = Path.Combine(csprojFolder, "ExpectedData", context.UnityDataVersion); @@ -76,11 +76,11 @@ public static void Generate(Context context) var dumpPath = Path.Combine(outputFolder, "dump"); Directory.CreateDirectory(dumpPath); Program.Main(new string[] { "dump", Path.Combine(context.UnityDataFolder, "assetbundle"), "-o", dumpPath }); - + dumpPath = Path.Combine(outputFolder, "dump-s"); Directory.CreateDirectory(dumpPath); Program.Main(new string[] { "dump", Path.Combine(context.UnityDataFolder, "assetbundle"), "-o", dumpPath, "-s" }); - + expectedData.Save(outputFolder); } } diff --git a/UnityDataTool.Tests/GlobalSetup.cs b/UnityDataTool.Tests/GlobalSetup.cs index 0e18907..9ff332b 100644 --- a/UnityDataTool.Tests/GlobalSetup.cs +++ b/UnityDataTool.Tests/GlobalSetup.cs @@ -15,4 +15,4 @@ public void RunBeforeAnyTests() // TODO: Fix test data to be culture agnostic. Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); } -} \ No newline at end of file +} diff --git a/UnityDataTool.Tests/UnityDataToolTests.cs b/UnityDataTool.Tests/UnityDataToolTests.cs index 6b5799f..ba57e54 100644 --- a/UnityDataTool.Tests/UnityDataToolTests.cs +++ b/UnityDataTool.Tests/UnityDataToolTests.cs @@ -395,7 +395,7 @@ public async Task Analyze_PlayerData_DatabaseCorrect() ForeignKeys = false, }.ConnectionString); db.Open(); - + using var cmd = db.CreateCommand(); cmd.CommandText = diff --git a/UnityDataTool/Archive.cs b/UnityDataTool/Archive.cs index d45fe63..ba4e720 100644 --- a/UnityDataTool/Archive.cs +++ b/UnityDataTool/Archive.cs @@ -79,7 +79,8 @@ struct WebBundleFileDescription public string Path; } - static void ExtractWebBundle(FileInfo filename, DirectoryInfo outputFolder) { + static void ExtractWebBundle(FileInfo filename, DirectoryInfo outputFolder) + { Console.WriteLine($"Extracting web bundle: {filename}"); using var fileStream = File.Open(filename.ToString(), FileMode.Open); using var stream = GetStream(filename, fileStream); @@ -91,7 +92,8 @@ static void ExtractWebBundle(FileInfo filename, DirectoryInfo outputFolder) { } } - static Stream GetStream(FileInfo filename, FileStream fileStream) { + static Stream GetStream(FileInfo filename, FileStream fileStream) + { var fileExtension = Path.GetExtension(filename.ToString()); return fileExtension switch { @@ -106,7 +108,8 @@ static List ParseWebBundleHeader(BinaryReader reader) { var result = new List(); var prefix = ReadBytes(reader, WebBundlePrefix.Length); - if (!prefix.SequenceEqual(WebBundlePrefix)) { + if (!prefix.SequenceEqual(WebBundlePrefix)) + { throw new FileFormatException("File is not a valid web bundle."); } uint headerSize = ReadUInt32(reader); @@ -117,8 +120,9 @@ static List ParseWebBundleHeader(BinaryReader reader) var fileByteOffset = ReadUInt32(reader); var fileSize = ReadUInt32(reader); var filePathLength = ReadUInt32(reader); - var filePath = Encoding.UTF8.GetString(ReadBytes(reader, (int) filePathLength)); - result.Add(new WebBundleFileDescription() { + var filePath = Encoding.UTF8.GetString(ReadBytes(reader, (int)filePathLength)); + result.Add(new WebBundleFileDescription() + { ByteOffset = fileByteOffset, Size = fileSize, Path = filePath, @@ -135,12 +139,13 @@ static void ExtractFileFromWebBundle(WebBundleFileDescription description, Binar Console.WriteLine($"... Extracting {description.Path}"); var path = Path.Combine(outputFolder.ToString(), description.Path); Directory.CreateDirectory(Path.GetDirectoryName(path)); - File.WriteAllBytes(path, ReadBytes(reader, (int) description.Size)); + File.WriteAllBytes(path, ReadBytes(reader, (int)description.Size)); } static uint ReadUInt32(BinaryReader reader) { - try { + try + { return reader.ReadUInt32(); } catch (EndOfStreamException) diff --git a/UnityDataTool/Program.cs b/UnityDataTool/Program.cs index 4774d9c..bf95060 100644 --- a/UnityDataTool/Program.cs +++ b/UnityDataTool/Program.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.CommandLine; using System.IO; using System.Threading.Tasks; @@ -74,7 +74,7 @@ public static async Task Main(string[] args) var pathArg = new Argument("filename", "The path of the file to dump").ExistingOnly(); var fOpt = new Option(aliases: new[] { "--output-format", "-f" }, description: "Output format", getDefaultValue: () => DumpFormat.Text); var sOpt = new Option(aliases: new[] { "--skip-large-arrays", "-s" }, description: "Do not dump large arrays of basic data types"); - var oOpt = new Option(aliases: new[] { "--output-path", "-o"}, description: "Output folder", getDefaultValue: () => new DirectoryInfo(Environment.CurrentDirectory)); + var oOpt = new Option(aliases: new[] { "--output-path", "-o" }, description: "Output folder", getDefaultValue: () => new DirectoryInfo(Environment.CurrentDirectory)); var objectIdOpt = new Option(aliases: new[] { "--objectid", "-i" }, () => 0, "Only dump the object with this signed 64-bit id (default: 0, dump all objects)"); var dumpCommand = new Command("dump", "Dump the contents of an AssetBundle or SerializedFile.") diff --git a/UnityFileSystem.Tests/DllWrapperTests.cs b/UnityFileSystem.Tests/DllWrapperTests.cs index 3693985..f011ad1 100644 --- a/UnityFileSystem.Tests/DllWrapperTests.cs +++ b/UnityFileSystem.Tests/DllWrapperTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Text; using NUnit.Framework; @@ -111,7 +111,7 @@ public class DllMountUnmountTests : AssetBundleTestFixture public DllMountUnmountTests(Context context) : base(context) { } - + [OneTimeSetUp] public void Setup() { @@ -429,7 +429,7 @@ public class DllSerializedFileTests : AssetBundleTestFixture public DllSerializedFileTests(Context context) : base(context) { } - + [OneTimeSetUp] public void Setup() { @@ -527,11 +527,11 @@ public void GetExternalReference_ValidSerializedFile_ReturnExpectedExternalRefer DllWrapper.GetExternalReferenceCount(file, out var count); var path = new StringBuilder(256); var guid = new StringBuilder(32); - + for (int i = 0; i < count; ++i) { var r = DllWrapper.GetExternalReference(file, i, path, 256, guid, out var refType); - + Assert.AreEqual(ReturnCode.Success, r); Assert.AreEqual(Context.ExpectedData.Get($"CAB-5d40f7cad7c871cf2ad2af19ac542994-ExtRef{i}-Guid"), guid.ToString()); Assert.AreEqual(Context.ExpectedData.Get($"CAB-5d40f7cad7c871cf2ad2af19ac542994-ExtRef{i}-Path"), path.ToString()); @@ -584,10 +584,10 @@ public void GetObjectInfo_ValidSerializedFile_ReturnExpectedObjectInfo() Assert.AreEqual(Context.ExpectedData.Get("CAB-5d40f7cad7c871cf2ad2af19ac542994-FirstObj-Size"), objectInfo[0].Size); Assert.AreEqual(Context.ExpectedData.Get("CAB-5d40f7cad7c871cf2ad2af19ac542994-FirstObj-TypeId"), objectInfo[0].TypeId); - Assert.AreEqual(Context.ExpectedData.Get("CAB-5d40f7cad7c871cf2ad2af19ac542994-LastObj-Id"), objectInfo[count-1].Id); - Assert.AreEqual(Context.ExpectedData.Get("CAB-5d40f7cad7c871cf2ad2af19ac542994-LastObj-Offset"), objectInfo[count-1].Offset); - Assert.AreEqual(Context.ExpectedData.Get("CAB-5d40f7cad7c871cf2ad2af19ac542994-LastObj-Size"), objectInfo[count-1].Size); - Assert.AreEqual(Context.ExpectedData.Get("CAB-5d40f7cad7c871cf2ad2af19ac542994-LastObj-TypeId"), objectInfo[count-1].TypeId); + Assert.AreEqual(Context.ExpectedData.Get("CAB-5d40f7cad7c871cf2ad2af19ac542994-LastObj-Id"), objectInfo[count - 1].Id); + Assert.AreEqual(Context.ExpectedData.Get("CAB-5d40f7cad7c871cf2ad2af19ac542994-LastObj-Offset"), objectInfo[count - 1].Offset); + Assert.AreEqual(Context.ExpectedData.Get("CAB-5d40f7cad7c871cf2ad2af19ac542994-LastObj-Size"), objectInfo[count - 1].Size); + Assert.AreEqual(Context.ExpectedData.Get("CAB-5d40f7cad7c871cf2ad2af19ac542994-LastObj-TypeId"), objectInfo[count - 1].TypeId); file.Dispose(); } @@ -602,14 +602,14 @@ public void GetObjectInfo_InvalidHandle_ReturnError() public class DllTypeTreeTests : AssetBundleTestFixture { - private UnityArchiveHandle m_Archive; - private SerializedFileHandle m_SerializedFile; - private ObjectInfo[] m_Objects; + private UnityArchiveHandle m_Archive; + private SerializedFileHandle m_SerializedFile; + private ObjectInfo[] m_Objects; public DllTypeTreeTests(Context context) : base(context) { } - + [OneTimeSetUp] public void Setup() { @@ -781,4 +781,4 @@ public void GetTypeTreeNodeInfo_RefTypeTypeTree_ReturnExpectedValues() Assert.AreEqual("string", type.ToString()); Assert.AreEqual("m_Description", name.ToString()); } -} \ No newline at end of file +} diff --git a/UnityFileSystem.Tests/ExpectedDataGenerator.cs b/UnityFileSystem.Tests/ExpectedDataGenerator.cs index 38796e3..f183e7a 100644 --- a/UnityFileSystem.Tests/ExpectedDataGenerator.cs +++ b/UnityFileSystem.Tests/ExpectedDataGenerator.cs @@ -60,12 +60,12 @@ public static void Generate(Context context) } UnityFileSystem.Cleanup(); - + var csprojFolder = Directory.GetParent(context.TestDataFolder).Parent.Parent.Parent.FullName; var outputFolder = Path.Combine(csprojFolder, "ExpectedData", context.UnityDataVersion); Directory.CreateDirectory(outputFolder); - + expectedData.Save(outputFolder); } } diff --git a/UnityFileSystem.Tests/UnityFileSystemTests.cs b/UnityFileSystem.Tests/UnityFileSystemTests.cs index 900a43e..47fd784 100644 --- a/UnityFileSystem.Tests/UnityFileSystemTests.cs +++ b/UnityFileSystem.Tests/UnityFileSystemTests.cs @@ -16,19 +16,19 @@ public class ArchiveTests : AssetBundleTestFixture public ArchiveTests(Context context) : base(context) { } - + protected override void OnLoadExpectedData(Context context) { // Uncomment to regenerate expected data. //ExpectedDataGenerator.Generate(context); } - + [OneTimeSetUp] public void Setup() { UnityFileSystem.Init(); } - + [OneTimeTearDown] public void TearDown() { @@ -50,7 +50,7 @@ public void MountArchive_InvalidArchive_ThrowsException() var ex = Assert.Throws(() => UnityFileSystem.MountArchive(path, "archive:/")); Assert.AreEqual($"Invalid file format reading {path}.", ex.Message); } - + public void MountArchive_ValidArchive_ReturnsArchive() { var path = Path.Combine(Context.UnityDataFolder, "assetbundle"); @@ -61,7 +61,7 @@ public void MountArchive_ValidArchive_ReturnsArchive() archive.Dispose(); } - + [Ignore("This test doesn't return the expected error, this condition is probably not handled correctly in Unity")] public void DisposeArchive_ValidArchive_UnmountsArchive() { @@ -74,16 +74,16 @@ public void DisposeArchive_ValidArchive_UnmountsArchive() archive.Dispose(); } - + public void Nodes_Disposed_ThrowsException() { var path = Path.Combine(Context.UnityDataFolder, "assetbundle"); var archive = UnityFileSystem.MountArchive(path, "archive:/"); archive.Dispose(); - + Assert.Throws(() => { var _ = archive.Nodes; }); } - + public void Nodes_ValidArchive_ExpectedContent(string testFolder) { var path = Path.Combine(testFolder, "AssetBundles", "assetbundle"); @@ -121,7 +121,7 @@ public UnityFileTests(Context context) : base(context) public void Setup() { UnityFileSystem.Init(); - + var path = Path.Combine(Context.UnityDataFolder, "assetbundle"); m_Archive = UnityFileSystem.MountArchive(path, "archive:/"); } @@ -130,7 +130,7 @@ public void Setup() public void TearDown() { m_Archive.Dispose(); - + UnityFileSystem.Cleanup(); } @@ -282,7 +282,7 @@ public SerializedFileTests(Context context) : base(context) public void Setup() { UnityFileSystem.Init(); - + var path = Path.Combine(Context.UnityDataFolder, "assetbundle"); m_Archive = UnityFileSystem.MountArchive(path, "archive:/"); } @@ -291,7 +291,7 @@ public void Setup() public void TearDown() { m_Archive.Dispose(); - + UnityFileSystem.Cleanup(); } @@ -314,7 +314,7 @@ public void OpenSerializedFile_NotSerializedFile_ThrowsException() public void OpenSerializedFile_ValidSerializedFile_ReturnsFile() { SerializedFile file = null; - + Assert.DoesNotThrow(() => file = UnityFileSystem.OpenSerializedFile("archive:/CAB-5d40f7cad7c871cf2ad2af19ac542994")); Assert.IsNotNull(file); @@ -419,7 +419,7 @@ public TypeTreeTests(Context context) : base(context) public void Setup() { UnityFileSystem.Init(); - + var path = Path.Combine(Context.UnityDataFolder, "assetbundle"); m_Archive = UnityFileSystem.MountArchive(path, "archive:/"); @@ -431,7 +431,7 @@ public void TearDown() { m_SerializedFile.Dispose(); m_Archive.Dispose(); - + UnityFileSystem.Cleanup(); } @@ -509,7 +509,7 @@ public void GetRefTypeTypeTree_InvalidFQN_ThrowsException() public void GetRefTypeTree_ValidSerializedFile_ReturnNode() { TypeTreeNode node = null; - + Assert.DoesNotThrow(() => node = m_SerializedFile.GetRefTypeTypeTreeRoot("SerializeReferencePolymorphismExample/Apple", "", "Assembly-CSharp")); Assert.NotNull(node); } @@ -523,11 +523,11 @@ public void GetTypeTreeNodeInfo_RefTypeTypeTree_ReturnExpectedValues() Assert.AreEqual(2, node.Children.Count); Assert.AreEqual("Apple", node.Type); Assert.AreEqual("Base", node.Name); - + Assert.AreEqual("int", node.Children[0].Type); Assert.AreEqual("m_Data", node.Children[0].Name); Assert.AreEqual(4, node.Children[0].Size); - + Assert.AreEqual("string", node.Children[1].Type); Assert.AreEqual("m_Description", node.Children[1].Name); } @@ -552,7 +552,7 @@ public void Setup() m_Archive = UnityFileSystem.MountArchive(path, "archive:/"); m_SerializedFile = UnityFileSystem.OpenSerializedFile("archive:/CAB-5d40f7cad7c871cf2ad2af19ac542994"); - m_Reader = new UnityFileReader("archive:/CAB-5d40f7cad7c871cf2ad2af19ac542994", 1024*1024); + m_Reader = new UnityFileReader("archive:/CAB-5d40f7cad7c871cf2ad2af19ac542994", 1024 * 1024); } [OneTimeTearDown] @@ -573,13 +573,13 @@ ObjectInfo GetObjectInfo(long id) for (i = 0; i < m_SerializedFile.Objects.Count; ++i) { obj = m_SerializedFile.Objects[i]; - + if (obj.Id == id) { break; } } - + Assert.Less(i, m_SerializedFile.Objects.Count); return obj; @@ -589,31 +589,31 @@ ObjectInfo GetObjectInfo(long id) public void AccessProperty_ValidProperty_ReturnExpectedValues() { var obj = GetObjectInfo(-7865028809519950684); - + var root = m_SerializedFile.GetTypeTreeRoot(obj.Id); var reader = new TypeTreeReaders.RandomAccessReader(m_SerializedFile, root, m_Reader, obj.Offset); - + Assert.AreEqual("Lame", reader["m_Name"].GetValue()); Assert.AreEqual(228, reader["m_SubMeshes"][0]["vertexCount"].GetValue()); Assert.AreEqual(false, reader["m_IsReadable"].GetValue()); } - + [Test] public void AccessProperty_InvalidProperty_ThrowException() { var obj = GetObjectInfo(-7865028809519950684); - + var root = m_SerializedFile.GetTypeTreeRoot(obj.Id); var reader = new TypeTreeReaders.RandomAccessReader(m_SerializedFile, root, m_Reader, obj.Offset); - + Assert.Throws(() => reader["ThisIsAnUnexistingPropertyName"].GetValue()); } - + [Test] public void AccessReferencedObject_ValidProperty_ReturnExpectedValues() { var obj = GetObjectInfo(-4606375687431940004); - + var root = m_SerializedFile.GetTypeTreeRoot(obj.Id); var reader = new TypeTreeReaders.RandomAccessReader(m_SerializedFile, root, m_Reader, obj.Offset); @@ -632,10 +632,10 @@ public void AccessReferencedObject_ValidProperty_ReturnExpectedValues() id0 = reader["m_Item"]["rid"].GetValue(); id1 = reader["m_Item2"]["rid"].GetValue(); } - + Assert.IsTrue(reader["references"].HasChild($"rid({id0})")); Assert.IsTrue(reader["references"].HasChild($"rid({id1})")); - + Assert.AreEqual(1, reader["references"][$"rid({id0})"]["data"]["m_Data"].GetValue()); Assert.AreEqual("Ripe", reader["references"][$"rid({id0})"]["data"]["m_Description"].GetValue()); Assert.AreEqual(1, reader["references"][$"rid({id1})"]["data"]["m_Data"].GetValue()); diff --git a/UnityFileSystem/DllWrapper.cs b/UnityFileSystem/DllWrapper.cs index ea16660..0917bf2 100644 --- a/UnityFileSystem/DllWrapper.cs +++ b/UnityFileSystem/DllWrapper.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Runtime.InteropServices; using System.Text; @@ -83,10 +83,10 @@ public enum ReturnCode [Flags] public enum ArchiveNodeFlags { - None = 0, - Directory = 1 << 0, - Deleted = 1 << 1, - SerializedFile = 1 << 2, + None = 0, + Directory = 1 << 0, + Deleted = 1 << 1, + SerializedFile = 1 << 2, } public enum CompressionType @@ -123,19 +123,19 @@ public struct ObjectInfo [Flags] public enum TypeTreeFlags { - None = 0, - IsArray = 1 << 0, - IsManagedReference = 1 << 1, - IsManagedReferenceRegistry = 1 << 2, - IsArrayOfRefs = 1 << 3, + None = 0, + IsArray = 1 << 0, + IsManagedReference = 1 << 1, + IsManagedReferenceRegistry = 1 << 2, + IsArrayOfRefs = 1 << 3, } [Flags] public enum TypeTreeMetaFlags { - None = 0, - AlignBytes = 1 << 14, - AnyChildUsesAlignBytes = 1 << 15, + None = 0, + AlignBytes = 1 << 14, + AnyChildUsesAlignBytes = 1 << 15, } public static class DllWrapper @@ -250,4 +250,4 @@ public static extern ReturnCode GetTypeTreeNodeInfo(TypeTreeHandle handle, int n StringBuilder name, int nameLen, out int offset, out int size, [MarshalAs(UnmanagedType.U4)] out TypeTreeFlags flags, [MarshalAs(UnmanagedType.U4)] out TypeTreeMetaFlags metaFlags, out int firstChildNode, out int nextNode); -} \ No newline at end of file +} diff --git a/UnityFileSystem/SerializedFile.cs b/UnityFileSystem/SerializedFile.cs index 829ea37..6791b6f 100644 --- a/UnityFileSystem/SerializedFile.cs +++ b/UnityFileSystem/SerializedFile.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Text; @@ -103,4 +103,4 @@ public void Dispose() m_Handle.Dispose(); } } -} \ No newline at end of file +} diff --git a/UnityFileSystem/TypeTreeNode.cs b/UnityFileSystem/TypeTreeNode.cs index 220ab68..9a3ab49 100644 --- a/UnityFileSystem/TypeTreeNode.cs +++ b/UnityFileSystem/TypeTreeNode.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Text; @@ -29,7 +29,7 @@ public class TypeTreeNode // Child nodes container. public List Children => m_Children.Value; - + // True if the field has no child. public bool IsLeaf => m_FirstChildNodeIndex == 0; @@ -38,7 +38,7 @@ public class TypeTreeNode // True if the field is an array. public bool IsArray => ((int)Flags & (int)TypeTreeFlags.IsArray) != 0; - + // True if the field is a ManagedReferenceRegistry public bool IsManagedReferenceRegistry => ((int)Flags & (int)TypeTreeFlags.IsManagedReferenceRegistry) != 0; @@ -192,4 +192,4 @@ Type GetCSharpType() throw new Exception($"Unknown type {Type}"); } -} \ No newline at end of file +} diff --git a/UnityFileSystem/TypeTreeReaders/RandomAccessReader.cs b/UnityFileSystem/TypeTreeReaders/RandomAccessReader.cs index 366f97b..4537a84 100644 --- a/UnityFileSystem/TypeTreeReaders/RandomAccessReader.cs +++ b/UnityFileSystem/TypeTreeReaders/RandomAccessReader.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Linq; @@ -79,7 +79,7 @@ public RandomAccessReader(SerializedFile serializedFile, TypeTreeNode node, Unit { // Create the referenced object reader. var refObjReader = new RandomAccessReader(m_SerializedFile, refObjNode, reader, curOffset, true); - + // A referenced object with null data means that we reached the end of the referenced objects. if (refObjReader["data"] == null) { @@ -94,7 +94,7 @@ public RandomAccessReader(SerializedFile serializedFile, TypeTreeNode node, Unit else if (version == 2) { // In version 2, referenced objects are stored in a vector. - + // Second child is the RefIds vector. var refIdsVectorNode = node.Children[1]; // RefIds vector's child is the Array. @@ -236,7 +236,7 @@ RandomAccessReader GetChild(string name) if (m_ChildrenCacheObject.TryGetValue(name, out var nodeReader)) return nodeReader; - + if (m_TypeTreeNode.IsManagedReferenceRegistry) { // ManagedReferenceRegistry are handled differently. The children @@ -487,4 +487,4 @@ IEnumerator IEnumerable.GetEnumerator() { return new Enumerator(this); } -} \ No newline at end of file +} diff --git a/UnityFileSystem/UnityArchive.cs b/UnityFileSystem/UnityArchive.cs index d518bd2..3ceb20e 100644 --- a/UnityFileSystem/UnityArchive.cs +++ b/UnityFileSystem/UnityArchive.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Text; @@ -55,4 +55,4 @@ public void Dispose() m_Nodes = new Lazy>(() => GetArchiveNodes()); } } -} \ No newline at end of file +} diff --git a/UnityFileSystem/UnityFile.cs b/UnityFileSystem/UnityFile.cs index ebd5ca3..12e317a 100644 --- a/UnityFileSystem/UnityFile.cs +++ b/UnityFileSystem/UnityFile.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace UnityDataTools.FileSystem; @@ -43,4 +43,4 @@ public void Dispose() m_Handle.Dispose(); } } -} \ No newline at end of file +} diff --git a/UnityFileSystem/UnityFileReader.cs b/UnityFileSystem/UnityFileReader.cs index e287fd2..bf46145 100644 --- a/UnityFileSystem/UnityFileReader.cs +++ b/UnityFileSystem/UnityFileReader.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Text; using Force.Crc32; @@ -8,10 +8,10 @@ namespace UnityDataTools.FileSystem; // This class can be used to read typed data from a UnityFile. Is uses a buffer for better performance. public class UnityFileReader : IDisposable { - UnityFile m_File; - byte[] m_Buffer; - long m_BufferStartInFile; - long m_BufferEndInFile; + UnityFile m_File; + byte[] m_Buffer; + long m_BufferStartInFile; + long m_BufferEndInFile; public long Length { get; } @@ -50,7 +50,7 @@ public void ReadArray(long fileOffset, int size, Array dest) var offset = GetBufferOffset(fileOffset, size); Buffer.BlockCopy(m_Buffer, offset, dest, 0, size); } - + public string ReadString(long fileOffset, int size) { var offset = GetBufferOffset(fileOffset, size); @@ -121,7 +121,7 @@ public uint ComputeCRC(long fileOffset, int size, uint crc32 = 0) { var readSize = size > m_Buffer.Length ? m_Buffer.Length : size; var readBytes = 0; - + while (readBytes < size) { var offset = GetBufferOffset(fileOffset, readSize); @@ -136,4 +136,4 @@ public void Dispose() { m_File.Dispose(); } -} \ No newline at end of file +} diff --git a/UnityFileSystem/UnityFileSystem.cs b/UnityFileSystem/UnityFileSystem.cs index a0abe7f..92612bf 100644 --- a/UnityFileSystem/UnityFileSystem.cs +++ b/UnityFileSystem/UnityFileSystem.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; namespace UnityDataTools.FileSystem; @@ -16,7 +16,7 @@ public static void Init() HandleErrors(r); } } - + public static void Cleanup() { // Uninitialize the native library. @@ -85,9 +85,9 @@ internal static void HandleErrors(ReturnCode returnCode, string filename = "") case ReturnCode.FileError: throw new IOException("File operation error."); - + case ReturnCode.TypeNotFound: throw new ArgumentException("Type not found."); } } -} \ No newline at end of file +} diff --git a/UnityFileSystemTestData/Assets/Editor/BuildAssetBundles.cs b/UnityFileSystemTestData/Assets/Editor/BuildAssetBundles.cs index 6b6b643..afce564 100644 --- a/UnityFileSystemTestData/Assets/Editor/BuildAssetBundles.cs +++ b/UnityFileSystemTestData/Assets/Editor/BuildAssetBundles.cs @@ -4,22 +4,22 @@ public class BuildAssetBundles { - [MenuItem ("Tools/Generate AssetBundles")] - static void GenerateAssetBundles () + [MenuItem("Tools/Generate AssetBundles")] + static void GenerateAssetBundles() { Directory.CreateDirectory("AssetBundles"); - BuildPipeline.BuildAssetBundles ("AssetBundles", BuildAssetBundleOptions.None, BuildTarget.StandaloneOSX); - + BuildPipeline.BuildAssetBundles("AssetBundles", BuildAssetBundleOptions.None, BuildTarget.StandaloneOSX); + var outPath = Path.Combine(Directory.GetParent(Application.dataPath).Parent.FullName, "TestCommon", "Data", "AssetBundles", Application.unityVersion); - + Directory.CreateDirectory(outPath); File.Copy(Path.Combine("AssetBundles", "assetbundle"), Path.Combine(outPath, "assetbundle"), true); File.Copy(Path.Combine("AssetBundles", "scenes"), Path.Combine(outPath, "scenes"), true); } - - [MenuItem ("Tools/Generate PlayerData")] - static void GeneratePlayerData () + + [MenuItem("Tools/Generate PlayerData")] + static void GeneratePlayerData() { if (!EditorUtility.DisplayDialog("Warning!", "Make sure that the \"ForceAlwaysWriteTypeTrees\" Diagnostic Switch is enabled in the Editor Preferences (Diagnostic/Editor section)", @@ -27,12 +27,12 @@ static void GeneratePlayerData () { return; } - - string[] levels = new string[] {"Assets/Scenes/OtherScene.unity"}; + + string[] levels = new string[] { "Assets/Scenes/OtherScene.unity" }; BuildPipeline.BuildPlayer(levels, Path.Combine(Path.GetDirectoryName(Application.dataPath), "build", "game"), BuildTarget.StandaloneOSX, BuildOptions.None); - + var outPath = Path.Combine(Directory.GetParent(Application.dataPath).Parent.FullName, "TestCommon", "Data", "PlayerData", Application.unityVersion); - + Directory.CreateDirectory(outPath); File.Copy(Path.Combine("build", "game.app", "Contents", "Resources", "Data", "level0"), outPath, true); }