<commit_before>﻿using Scripts.Game.Serialization;
using Scripts.Game.Serialized;
using Scripts.Model.Characters;
using Scripts.Model.Interfaces;
using Scripts.Model.Pages;
using Scripts.Model.Processes;
using Scripts.Model.SaveLoad.SaveObjects;
using Scripts.Model.TextBoxes;
using Scripts.Presenter;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Scripts.Game.Pages {
    public class LoadPages : PageGroup {
        private const int PASTEBIN_USAGE_COOLDOWN = 60;
        private const int IMPORT = 1;
        private static float nextTimePastebinAvailable;
        private bool isUploadingToPastebin;

        public LoadPages(Page previous) : base(new Page("Load Game")) {
            SetupRoot(previous);
        }

        private void SetupRoot(Page previous) {
            Page p = Get(ROOT_INDEX);
            p.Icon = Util.GetSprite("load");
            p.OnEnter = () => {
                p.Left.Clear();
                p.Right.Clear();
                List<IButtonable> buttons = new List<IButtonable>();
                buttons.Add(PageUtil.GenerateBack(previous));
                for (int i = 0; i < SaveLoad.MAX_SAVE_FILES; i++) {
                    if (SaveLoad.IsSaveUsed(i)) {
                        buttons.Add(GetSpecificLoadPage(p, i));
                    } else {
                        buttons.Add(SetupImport(p, i));
                    }
                }

                p.Actions = buttons;
            };
        }

        private Page GetSpecificLoadPage(Page previous, int index) {
            Party party;
            Camp camp;
            string saveName;
            RestoreCamp(SaveLoad.Load(index, index.ToString()), out camp, out party, out saveName);
            Page page = new Page(saveName);
            page.Body = string.Format("What would you like to do with file {0}?", index);
            page.Actions = new IButtonable[] {
                PageUtil.GenerateBack(previous).SetCondition(() => !isUploadingToPastebin),
                GetLoadProcess(camp, index).SetCondition(() => !isUploadingToPastebin),
                PageUtil.GetConfirmationGrid(
                    previous,
                    previous,
                    GetDeleteProcess(previous, index),
                    "Delete",
                    string.Format("Delete file {0}.", index),
                    string.Format("Are you sure you want to delete file {0}?\n{1}", index, saveName)
                    ).SetCondition(() => !isUploadingToPastebin),
                GetExportProcess(previous, SaveLoad.GetSaveValue(index)),
            };
            page.AddCharacters(Side.RIGHT, party.Collection);
            return page;
        }
<commit_msg>now (should) delete corrupted saves.<commit_after>﻿using Scripts.Game.Serialization;
using Scripts.Game.Serialized;
using Scripts.Model.Characters;
using Scripts.Model.Interfaces;
using Scripts.Model.Pages;
using Scripts.Model.Processes;
using Scripts.Model.SaveLoad.SaveObjects;
using Scripts.Model.TextBoxes;
using Scripts.Presenter;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Scripts.Game.Pages {
    public class LoadPages : PageGroup {
        private const int PASTEBIN_USAGE_COOLDOWN = 60;
        private const int IMPORT = 1;
        private static float nextTimePastebinAvailable;
        private bool isUploadingToPastebin;

        public LoadPages(Page previous) : base(new Page("Load Game")) {
            SetupRoot(previous);
        }

        private void SetupRoot(Page previous) {
            Page p = Get(ROOT_INDEX);
            p.Icon = Util.GetSprite("load");
            p.OnEnter = () => {
                p.Left.Clear();
                p.Right.Clear();
                List<IButtonable> buttons = new List<IButtonable>();
                buttons.Add(PageUtil.GenerateBack(previous));
                for (int i = 0; i < SaveLoad.MAX_SAVE_FILES; i++) {
                    if (SaveLoad.IsSaveUsed(i)) {
                        buttons.Add(GetSpecificLoadPage(p, i));
                    } else {
                        buttons.Add(SetupImport(p, i));
                    }
                }

                p.Actions = buttons;
            };
        }

        private Page GetSpecificLoadPage(Page previous, int index) {
            Party party;
            Camp camp;
            string saveName;
            try {
                RestoreCamp(SaveLoad.Load(index, index.ToString()), out camp, out party, out saveName);
            } catch (Exception e) {
                previous.AddText(string.Format("Save {0} is corrupted, deleting...\n{1}", index, e.Message));
                SaveLoad.DeleteSave(index);
                return SetupImport(previous, index);
            }
            Page page = new Page(saveName);
            page.Body = string.Format("What would you like to do with file {0}?", index);
            page.Actions = new IButtonable[] {
                PageUtil.GenerateBack(previous).SetCondition(() => !isUploadingToPastebin),
                GetLoadProcess(camp, index).SetCondition(() => !isUploadingToPastebin),
                PageUtil.GetConfirmationGrid(
                    previous,
                    previous,
                    GetDeleteProcess(previous, index),
                    "Delete",
                    string.Format("Delete file {0}.", index),
                    string.Format("Are you sure you want to delete file {0}?\n{1}", index, saveName)
                    ).SetCondition(() => !isUploadingToPastebin),
                GetExportProcess(previous, SaveLoad.GetSaveValue(index)),
            };
            page.AddCharacters(Side.RIGHT, party.Collection);
            return page;
        }

{'fraction_non_alphanumeric': 0.10263522884882108, 'fraction_numerical': 0.0031206657420249652, 'mean_word_length': 1.8658718330849478, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6629740', 'n_tokens_mistral': 1535, 'n_tokens_neox': 1460, 'n_words': 341}