예제 #1
0
        public static void Initialize()
        {
            // Create a new dictionary
            MsbtHolders = new Dictionary <Language, MsbtHolder>();

            // Loop over every language
            foreach (Language language in BlitzUtil.SupportedLanguages)
            {
                // Load the corresponding common szs file
                using (Stream stream = RomResourceLoader.GetRomFile($"/Message/CommonMsg_{language.GetSeadCode()}.release.szs"))
                {
                    // Get the Sarc archive
                    Sarc sarc = new Sarc(stream);

                    // Create a MsbtHolder
                    MsbtHolders.Add(language, new MsbtHolder(sarc));
                }
            }

            // Load MapInfo
            MapInfoEntries = ByamlLoader.GetByamlDeserialized <List <MapInfoEntry> >("/Mush/MapInfo.release.byml");

            // Load WeaponInfo_Main
            WeaponInfoEntries = ByamlLoader.GetByamlDeserialized <List <WeaponInfoEntry> >("/Mush/WeaponInfo_Main.release.byml");
        }
예제 #2
0
        protected override void ShutdownAppSpecificItems()
        {
            // Shutdown the RomReasourceLoader
            RomResourceLoader.Dispose();

            // Shutdown the FileCache
            FileCache.Dispose();
        }
        protected override async Task RunAppSpecificBootTasks()
        {
            // Initialize the FileCache if first run is complete
            if (Configuration.LoadedConfiguration.FirstRunCompleted)
            {
                FileCache.Initialize();
            }

            // Initialize the RomResourceLoader
            RomResourceLoader.Initialize();

            // Initialize the BlitzLocalizer
            BlitzLocalizer.Initialize();

            // Load GameConfigSetting
            XDocument gameConfig = XDocument.Load(RomResourceLoader.GetRomFile("/System/GameConfigSetting.xml"));

            // Get the application version
            int appVersion = int.Parse(gameConfig.Root
                                       .Elements("category").Where(e => e.Attribute("name").Value == "Root").First()
                                       .Elements("category").Where(e => e.Attribute("name").Value == "Project").First()
                                       .Elements("category").Where(e => e.Attribute("name").Value == "Version").First()
                                       .Elements("parameter").Where(e => e.Attribute("name").Value == "AppVersion").First()
                                       .Attribute("defaultValue").Value);

            // Output the ROM version
            await DiscordBot.LoggingChannel.SendMessageAsync($"**[JelonzoBotBootHousekepingJob]** ROM version {appVersion} was loaded by RomResourceLoader");

            // Get the ROM config
            RomConfig romConfig = (Configuration.LoadedConfiguration as JelonzoBotConfiguration).RomConfig;

            // Check if this version is new compared to the last boot
            if (romConfig.LastRomVersion < appVersion)
            {
                // Create a JobDataMap to hold the version
                JobDataMap dataMap = new JobDataMap();
                dataMap.Add("version", appVersion);

                // Upload necessary ROM data after everything is initalized
                await QuartzScheduler.ScheduleJob <RomDataUploadJob>("Normal", DateTime.Now.AddSeconds(5), dataMap);
            }
        }
예제 #4
0
        public async Task Execute(IJobExecutionContext context)
        {
            try
            {
                // Log that we're about to begin uploading data
                await DiscordBot.LoggingChannel.SendMessageAsync("**[RomDataUploadJob]** Beginning ROM data upload");

                // Create a list of paths whose cache needs to be cleared
                List <string> clearPaths = new List <string>();

                // Create the MSBT S3 path format string
                string msbtS3BasePath = "/splatoon/blitz_rom/Message/CommonMsg_{0}";

                // Loop over every language
                foreach (Language language in BlitzUtil.SupportedLanguages)
                {
                    // Log the language
                    await DiscordBot.LoggingChannel.SendMessageAsync($"**[RomDataUploadJob]** Uploading {language.ToString()}'s MSBTs");

                    // Get the MsbtHolder
                    MsbtHolder msbtHolder = BlitzLocalizer.MsbtHolders[language];

                    // Loop over every MSBT
                    foreach (KeyValuePair <string, Dictionary <string, string> > pair in msbtHolder.Msbts)
                    {
                        // Construct the path
                        string msbtPath = string.Format(msbtS3BasePath, language.GetSeadCode());

                        // Construct the file name
                        string fileName = $"{pair.Key}.json";

                        // Serialize to JSON
                        string json = JsonConvert.SerializeObject(pair.Value);

                        // Upload to S3
                        S3Api.TransferFile(Encoding.UTF8.GetBytes(json), msbtPath, fileName, "application/json");

                        // Add to the cache list
                        clearPaths.Add($"{msbtPath}/{fileName}");
                    }
                }

                // Log MSBT upload
                await DiscordBot.LoggingChannel.SendMessageAsync("**[RomDataUploadJob]** Uploading Mush");

                // Create the Mush S3 path string
                string mushS3Path = "/splatoon/blitz_rom/Mush";

                // Get every file in Mush
                foreach (string path in RomResourceLoader.GetFilesInDirectory("/Mush"))
                {
                    // Get the BYAML
                    dynamic byaml = ByamlLoader.GetByamlDynamic(path);

                    // Construct the file name
                    string fileName = $"{Path.GetFileNameWithoutExtension(path)}.json";

                    // Serialize to JSON
                    string json = JsonConvert.SerializeObject(byaml);

                    // Upload to S3
                    S3Api.TransferFile(Encoding.UTF8.GetBytes(json), mushS3Path, fileName, "application/json");

                    // Add to the paths to clear
                    clearPaths.Add($"{mushS3Path}/{fileName}");
                }

                // Log CDN cache purge starting
                await DiscordBot.LoggingChannel.SendMessageAsync($"**[RomDataUploadJob]** Requesting CDN cache purge ({clearPaths.Count} of {clearPaths.Count} files left)");

                IEnumerable <string> pathsEnumerable = (IEnumerable <string>)clearPaths;

                while (pathsEnumerable.Any())
                {
                    // Tell DigitalOcean to clear the cache
                    await DoApi.SendRequest(new DoCdnCachePurgeRequest(Configuration.LoadedConfiguration.DoConfig.EndpointId, pathsEnumerable.Take(15).ToList()));

                    // Advance to the next set
                    pathsEnumerable = pathsEnumerable.Skip(15);

                    // Log files left
                    await DiscordBot.LoggingChannel.SendMessageAsync($"**[RomDataUploadJob]** Requesting CDN cache purge ({pathsEnumerable.Count()} of {clearPaths.Count} files left)");
                }

                // Write the app version
                await DiscordBot.LoggingChannel.SendMessageAsync("**[RomDataUploadJob]** Saving new ROM version to configuration");

                (Configuration.LoadedConfiguration as JelonzoBotConfiguration).RomConfig.LastRomVersion = (int)context.JobDetail.JobDataMap["version"];
                Configuration.LoadedConfiguration.Write();

                // Log that it's complete
                await DiscordBot.LoggingChannel.SendMessageAsync("**[RomDataUploadJob]** ROM data upload complete");
            }
            catch (Exception e)
            {
                await DiscordUtil.HandleException(e, "in ``RomDataUploadJob``");
            }
        }