示例#1
0
        private static void ProcessFile(string[] actions, string filepath)
        {
            Console.WriteLine(filepath);
            string text = Path.ChangeExtension(filepath, "uasset");

            if (!File.Exists(text))
            {
                Console.WriteLine("Unable to open " + text);
                return;
            }
            UAsset.Options = new UAParserOptions(actions.Contains("-verbose"), actions.Contains("-force"), actions.Contains("-instnums"), actions.Contains("-fullinst"), actions.Contains("-newentries"));
            using (FileStream uassetStream = File.OpenRead(text))
            {
                UAsset uAsset = new UAsset(uassetStream);
                for (int i = 0; i < actions.Length; i++)
                {
                    switch (actions[i])
                    {
                    case "-tojson":
                    {
                        Dictionary <string, object>[] array = (from x in uAsset.Summary.Exports.SelectMany((FObjectExport x) => x.Objects)
                                                               select x.ToDictionary()).ToArray();
                        File.WriteAllText(Path.ChangeExtension(filepath, "json"), JsonConvert.SerializeObject((array.Length >= 2) ? array : (uAsset.Summary.Exports.FirstOrDefault()?.Objects.FirstOrDefault()?.ObjectData?.Serialize() ?? array), Formatting.Indented, new JsonSerializerSettings
                            {
                                ContractResolver = new IgnoreDataBinding()
                            }));
                        break;
                    }

                    case "-dumpmeta":
                        DumpMeta(uAsset, filepath);
                        break;

                    case "-dumpnames":
                        File.WriteAllLines(Path.ChangeExtension(filepath, "names"), uAsset.Summary.Names.Select((FNameEntry x) => x.Name));
                        break;

                    case "-tobin":
                    {
                        if (uAsset.Summary.ExportCount > 1)
                        {
                            throw new NotImplementedException("Export Count > 1 is not supported!");
                        }
                        string text2 = Path.ChangeExtension(filepath, "json");
                        if (!File.Exists(text2))
                        {
                            Console.WriteLine("Unable to open " + text2);
                            break;
                        }
                        new UAParserOptions(actions.Contains("-verbose"), actions.Contains("-force"));
                        uAsset.UpdateFromJSON(File.ReadAllText(text2, Encoding.UTF8));
                        uAsset.SerializeToBinary(text2);
                        break;
                    }
                    }
                }
            }
        }
        public void WriteModifiedUassetFile(string modifiedJson, byte[] uassetData, FilePath outputFileInfo)
        {
            string outputFolder   = outputFileInfo.DirectoryPath;
            string outputFileName = outputFileInfo.FileName;
            var    uAsset         = new UAsset(new MemoryStream(uassetData));

            uAsset.UpdateFromJSON(modifiedJson);
            uAsset.SerializeToBinary(outputFileInfo.FullPath);

            string uassetFilePath = Path.Combine(outputFolder, FileUtil.GetUassetFileName(outputFileName));
            string binFilePath    = Path.Combine(outputFolder, FileUtil.GetBinFileName(outputFileName));

            File.Move(binFilePath, uassetFilePath, true);
        }