/// <summary>
        /// Saves the data into the given <paramref name="stream"/>.
        /// </summary>
        /// <param name="stream">The <see cref="Stream"/> to save the data to.</param>
        public void Save(Stream stream)
        {
            // Before saving all the instances, allow references to be resolved.
            Areas?.ForEach(x => x.SerializeReferences(this));

            EnemyPaths?.ForEach(x => x.SerializeReferences(this));
            GCameraPaths?.ForEach(x => x.SerializeReferences(this));
            GlidePaths?.ForEach(x => x.SerializeReferences(this));
            GravityPaths?.ForEach(x => x.SerializeReferences(this));
            ItemPaths?.ForEach(x => x.SerializeReferences(this));
            JugemPaths?.ForEach(x => x.SerializeReferences(this));
            LapPaths?.ForEach(x => x.SerializeReferences(this));
            PullPaths?.ForEach(x => x.SerializeReferences(this));

            Objs.ForEach(x => x.SerializeReferences(this));

            ReplayCameras?.ForEach(x => x.SerializeReferences(this));

            // Save the serialized values.
            ByamlSerializer serializer = new ByamlSerializer(new ByamlSerializerSettings()
            {
                SupportPaths = true,
                Version = ByamlVersion.Version1
            });
            serializer.Serialize(stream, this);
        }
        // ---- METHODS(PUBLIC) ---------------------------------------------------------------------------------------

        /// <summary>
        /// Loads the data from the given <paramref name="stream"/>.
        /// </summary>
        /// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
        public void Load(Stream stream)
        {
            // Load all the values from the stream.
            ByamlSerializer serializer = new ByamlSerializer(new ByamlSerializerSettings()
            {
                SupportPaths = true,
                Version = ByamlVersion.Version1
            });
            serializer.Deserialize(stream, this);

            // After loading all the instances, allow references to be resolved.
            Areas?.ForEach(x => x.DeserializeReferences(this));

            EnemyPaths?.ForEach(x => x.DeserializeReferences(this));
            GCameraPaths?.ForEach(x => x.DeserializeReferences(this));
            GlidePaths?.ForEach(x => x.DeserializeReferences(this));
            GravityPaths?.ForEach(x => x.DeserializeReferences(this));
            ItemPaths?.ForEach(x => x.DeserializeReferences(this));
            JugemPaths?.ForEach(x => x.DeserializeReferences(this));
            LapPaths?.ForEach(x => x.DeserializeReferences(this));
            ObjPaths?.ForEach(x => x.DeserializeReferences(this));
            Paths?.ForEach(x => x.DeserializeReferences(this));
            PullPaths?.ForEach(x => x.DeserializeReferences(this));

            Objs.ForEach(x => x.DeserializeReferences(this));

            ReplayCameras?.ForEach(x => x.DeserializeReferences(this));
        }
Exemplo n.º 3
0
        public static void Initialize()
        {
            if (!Configuration.LoadedConfiguration.FirstRunCompleted)
            {
                throw new Exception("Cannot initialize FileCache if the first run is not complete");
            }

            // Create a ByamlSerializer
            ByamlSerializer byamlSerializer = new ByamlSerializer(new ByamlSerializerSettings()
            {
                ByteOrder    = Syroot.BinaryData.ByteOrder.LittleEndian,
                SupportPaths = false,
                Version      = ByamlVersion.Version1
            });

            // Create the FestivalSettings dictionary
            FestivalSettings = new Dictionary <RomType, List <FestivalSetting> >();

            // Populate the FestivalSettings dictionary with RomTypes and lists
            foreach (RomType romType in Program.BcatPairs.Keys)
            {
                // Create a list for this RomType
                FestivalSettings[romType] = new List <FestivalSetting>();

                // Get all FestivalSetting byamls for this RomType
                string[] festPaths = Directory.GetFiles(Path.Combine(LOCAL_DIRECTORY, "Festival", romType.ToString()), "*.byaml");

                // Loop over every path
                foreach (string festPath in festPaths)
                {
                    // Deserialize the byaml
                    FestivalSetting festivalSetting = byamlSerializer.Deserialize <FestivalSetting>(festPath);

                    // Add this to the list
                    FestivalSettings[romType].Add(festivalSetting);
                }

                // Sort in ascending order
                FestivalSettings[romType].Sort((x, y) => x.Times.Start.CompareTo(y.Times.Start));
            }

            // Create the VersusSettings dictionary
            VersusSettings = new Dictionary <RomType, VersusSetting>();

            // Get all VersusSetting byamls
            string[] versusPaths = Directory.GetFiles(Path.Combine(LOCAL_DIRECTORY, "VSSetting"));

            // Loop over every path
            foreach (string versusPath in versusPaths)
            {
                // Get the RomType
                RomType romType = (RomType)EnumUtil.GetEnumValueFromString(typeof(RomType), Path.GetFileNameWithoutExtension(versusPath));

                // Deserialize the byaml
                VersusSettings[romType] = byamlSerializer.Deserialize <VersusSetting>(versusPath);
            }

            // Deserialize the CoopSetting byaml
            CoopSetting = byamlSerializer.Deserialize <CoopSetting>(COOP_SETTING_PATH);
        }
Exemplo n.º 4
0
        // ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------

        private void Load(Stream stream)
        {
            ByamlSerializer serializer = new ByamlSerializer(new ByamlSerializerSettings()
            {
                SupportPaths = true,
                Version      = ByamlVersion.Version1
            });

            Definitions = serializer.Deserialize <List <ObjDefinition> >(stream);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Saves the definitions into the the given stream.
        /// </summary>
        /// <param name="stream">The stream in which the definitions will be stored.</param>
        public void Save(Stream stream)
        {
            ByamlSerializer serializer = new ByamlSerializer(new ByamlSerializerSettings()
            {
                SupportPaths = true,
                Version      = ByamlVersion.Version1
            });

            serializer.Serialize(stream, Definitions);
        }
Exemplo n.º 6
0
        private static T LoadByamlSerialized <T>(ByamlSettings settings, Stream stream)
        {
            // Create a ByamlSerializer instance
            ByamlSerializer serializer = new ByamlSerializer(new ByamlSerializerSettings()
            {
                ByteOrder    = settings.byteOrder,
                SupportPaths = settings.supportsPaths,
                Version      = ByamlVersion.Version1 // unused, version is ignored
            });

            // Deserialize the byaml
            return(serializer.Deserialize <T>(stream));
        }
Exemplo n.º 7
0
        public async Task Execute(IJobExecutionContext context)
        {
            try
            {
                foreach (KeyValuePair <RomType, BcatPair> bcatPairEntry in Program.BcatPairs)
                {
                    // Log that we're about to begin a check
                    await DiscordBot.LoggingChannel.SendMessageAsync("**[BCAT]** Beginning topic download for " + bcatPairEntry.Key.ToString());

                    // Download the latest Topic
                    Topic topic = await BcatApi.GetDataTopic(bcatPairEntry.Value.TitleId, bcatPairEntry.Value.Passphrase);

                    // Create the target folder name
                    string targetFolder = string.Format(Program.LOCAL_OLD_DATA_DIRECTORY, DateTime.Now.ToString(Program.FOLDER_DATE_TIME_FORMAT), bcatPairEntry.Key.ToString());

                    // Format the old Topic path
                    string oldTopicPath = string.Format(Program.LOCAL_LAST_TOPIC, bcatPairEntry.Key.ToString());

                    // Load the old Topic
                    Topic oldTopic = MessagePackSerializer.Deserialize <Topic>(File.ReadAllBytes(oldTopicPath));

    #if DEBUG
                    if (!Configuration.LoadedConfiguration.IsProduction)
                    {
                        /*foreach (Nintendo.Bcat.Directory dir in oldTopic.Directories)
                         * {
                         *  if (dir.Name == "fesdata")
                         *  {
                         *      Data dbgData = dir.Data.Where(x => x.Name == "Festival.byaml").FirstOrDefault();
                         *      dbgData.Digest = "deadbeef";
                         *  }
                         * }*/
                    }
    #endif

                    // Get the differences
                    List <KeyValuePair <DifferenceType, string> > differences = BcatCheckerUtils.GetTopicChanges(oldTopic, topic);

                    // Check if there aren't any
                    if (differences.Count == 0)
                    {
                        // Nothing to do here
                        goto finished;
                    }

                    // Download all data
                    Dictionary <string, byte[]> data = await BcatCheckerUtils.DownloadAllData(topic, bcatPairEntry.Value.TitleId, bcatPairEntry.Value.Passphrase, targetFolder);

                    // Loop over every difference
                    foreach (KeyValuePair <DifferenceType, string> differencePair in differences)
                    {
                        // Log the difference
                        await DiscordBot.LoggingChannel.SendMessageAsync("**[BCAT]** diff: ``" + differencePair.Value + "`` (" + differencePair.Key.ToString() + ")");

                        // Get the FileType
                        FileType fileType = FileTypeExtensions.GetTypeFromFilePath(differencePair.Value);

                        // Create a ByamlSerializer instance
                        ByamlSerializer serializer = new ByamlSerializer(new ByamlSerializerSettings()
                        {
                            ByteOrder    = ByteOrder.LittleEndian,
                            SupportPaths = false,
                            Version      = ByamlVersion.Version1
                        });

                        // Create the difference handler parameters based off the FileType and difference type
                        object[] parameters;

                        if (differencePair.Key != DifferenceType.Removed)
                        {
                            // Get the raw file
                            byte[] rawFile = data[differencePair.Value];

                            // Deserialize the object from byaml if necessary
                            object deserializedObject;
                            using (MemoryStream memoryStream = new MemoryStream(rawFile))
                            {
                                switch (fileType)
                                {
                                case FileType.VersusSetting:
                                    deserializedObject = serializer.Deserialize <VersusSetting>(memoryStream);
                                    break;

                                case FileType.CoopSetting:
                                    deserializedObject = serializer.Deserialize <CoopSetting>(memoryStream);
                                    break;

                                case FileType.FestivalByaml:
                                    deserializedObject = serializer.Deserialize <FestivalSetting>(memoryStream);
                                    break;

                                default:
                                    deserializedObject = data[differencePair.Value];
                                    break;
                                }
                            }

                            if (differencePair.Key == DifferenceType.Added)
                            {
                                parameters = new object[] { bcatPairEntry.Key, data, deserializedObject, rawFile };
                            }
                            else // Changed
                            {
                                // Get the previous file
                                object previousFile;
                                switch (fileType)
                                {
                                case FileType.VersusSetting:
                                    previousFile = FileCache.GetVersusSettingForRomType(bcatPairEntry.Key);
                                    break;

                                case FileType.CoopSetting:
                                    previousFile = FileCache.GetCoopSetting();
                                    break;

                                case FileType.FestivalByaml:
                                    previousFile = FileCache.GetLatestFestivalSettingForRomType(bcatPairEntry.Key);
                                    break;

                                default:
                                    // Construct the previous file path
                                    string previousPath = Path.Combine((Configuration.LoadedConfiguration as JelonzoBotConfiguration).LastDownloadPaths[bcatPairEntry.Key], differencePair.Value.Replace('/', Path.DirectorySeparatorChar));

                                    // Load it
                                    previousFile = File.ReadAllBytes(previousPath);;
                                    break;
                                }

                                // Create the parameters
                                parameters = new object[] { bcatPairEntry.Key, data, previousFile, deserializedObject, rawFile };
                            }
                        }
                        else
                        {
                            parameters = new object[] { bcatPairEntry.Key, data };
                        }

                        // Call every difference handler
                        await BcatCheckerUtils.CallDifferenceHandlers((int)fileType, differencePair.Key, parameters);
                    }

                    // Write out the Topic
                    File.WriteAllBytes(oldTopicPath, MessagePackSerializer.Serialize(topic));

                    // Set the last download path
                    (Configuration.LoadedConfiguration as JelonzoBotConfiguration).LastDownloadPaths[bcatPairEntry.Key] = targetFolder;

finished:
                    await DiscordBot.LoggingChannel.SendMessageAsync("**[BCAT]** Check complete for " + bcatPairEntry.Key.ToString());
                }
            }
            catch (Exception exception)
            {
                // Notify the logging channel
                await DiscordUtil.HandleException(exception, $"in ``BcatCheckerJob``");
            }
        }