Esempio n. 1
0
        public void CreateSpoilerLogs()
        {
            int step_size     = 11; // Calculation: 100 / (8 categories + savepath)
            int curr_progress = 0;  //

            string spoilersPath = Path.Combine(Environment.CurrentDirectory, "Spoilers");

            //if (Directory.Exists(spoilersPath)) { Directory.Delete(spoilersPath, true); }
            Directory.CreateDirectory(spoilersPath);

            //var timestamp = DateTime.Now.ToString("yy-MM-dd_HH-mm-ss");
            var timestamp = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
            var filename  = $"{timestamp}, Seed {Properties.Settings.Default.Seed}.xlsx";
            var path      = Path.Combine(spoilersPath, filename);

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            try
            {
                using (var workbook = new XLWorkbook())
                {
                    curr_task = "Creating Spoilers - Item";
                    bwSpoilers.ReportProgress(curr_progress);
                    ItemRando.CreateSpoilerLog(workbook);

                    curr_task = "Creating Spoilers - Model";
                    bwSpoilers.ReportProgress(curr_progress += step_size);
                    ModelRando.CreateSpoilerLog(workbook);

                    curr_task = "Creating Spoilers - Module";
                    bwSpoilers.ReportProgress(curr_progress += step_size);
                    ModuleRando.CreateSpoilerLog(workbook);

                    curr_task = "Creating Spoilers - Music / Sound";
                    bwSpoilers.ReportProgress(curr_progress += step_size);
                    SoundRando.CreateSpoilerLog(workbook);

                    curr_task = "Creating Spoilers - Other";
                    bwSpoilers.ReportProgress(curr_progress += step_size);
                    OtherRando.CreateSpoilerLog(workbook);

                    curr_task = "Creating Spoilers - Text";
                    bwSpoilers.ReportProgress(curr_progress += step_size);
                    TextRando.CreateSpoilerLog(workbook);

                    curr_task = "Creating Spoilers - Texture";
                    bwSpoilers.ReportProgress(curr_progress += step_size);
                    TextureRando.CreateSpoilerLog(workbook);

                    curr_task = "Creating Spoilers - 2DA";
                    bwSpoilers.ReportProgress(curr_progress += step_size);
                    TwodaRandom.CreateSpoilerLog(workbook);

                    curr_task = "Creating Spoilers - Saving File";
                    bwSpoilers.ReportProgress(curr_progress += step_size);

                    // If any worksheets have been added, save the spoiler log.
                    if (workbook.Worksheets.Count > 0)
                    {
                        StringBuilder wsList = new StringBuilder();
                        foreach (var sheet in workbook.Worksheets)
                        {
                            wsList.Append($"{sheet.Name}, ");
                        }

                        wsList.Remove(wsList.Length - 2, 2);
                        workbook.SaveAs(path);

                        SpoilerCreated = true;
                    }
                    else
                    {
                        SpoilerCreated = false;
                        SpoilerMessage = $"No spoilers created. Either the game has not been randomized, or the selected randomizations do not generate spoilers.";
                    }
                }
            }
            catch (Exception e)
            {
                SpoilerCreated = false;
                SpoilerMessage = $"Exception caught while creating spoilers: {e.ToString()}";
            }
        }