/// <summary>
 /// Save a state
 /// </summary>
 /// <param name="state">The state to save it into</param>
 internal static void SaveState(int state)
 {
     CurrentMode = Mode.Saving;
     UndoAction  = new UndoActionType(state, LastActionType.backup);
     CanUndo     = true;
     ExposeData(PathHandler.GenBackupStateFile(state));
 }
            public UndoActionType(int state, LastActionType lastAction = LastActionType.none)
            {
                Main.DebugMessage("Creating last action type {1} for state {0}", state, lastAction.ToString());
                State      = state;
                LastAction = lastAction;
                switch (LastAction)
                {
                case LastActionType.restore:
                    ModData = new ModsConfigData
                    {
                        buildNumber = RimWorld.VersionControl.CurrentBuild,
                        activeMods  = GetActiveMods()
                    };
                    break;

                case LastActionType.backup:
                    if (!StateIsSet(state))
                    {
                        ModData = null;
                    }
                    else
                    {
                        ModData = ReadState(PathHandler.GenBackupStateFile(state));
                    }
                    break;

                case LastActionType.none:
                default:
                    Main.Log.Warning("Last Undo Action was not set with a type");
                    break;
                }
            }
            internal bool UndoLastAction()
            {
                Main.DebugMessage("Undoing last action type {1} for state {0}", State, LastAction.ToString());
                switch (LastAction)
                {
                case LastActionType.restore:
                    Main.DebugMessage("Restoring {0} active mods", ModData.activeMods.Count);
                    SetActiveMods(ModData.activeMods);
                    return(true);

                case LastActionType.backup:
                    if (ModData != null)
                    {
                        Main.DebugMessage("Restored {0}'s last state", State);
                        XmlSaverAPI.SaveDataObject((object)ModData, PathHandler.GenBackupStateFile(State));
                    }
                    else
                    {
                        PathHandler.FileDelete(PathHandler.GenBackupStateFile(State));
                    }
                    return(true);

                case LastActionType.none:
                default:
                    Main.Log.Warning("Last Undo Action was not set with a type, cannot undo last action");
                    return(false);
                }
            }
 /// <summary>
 /// Load a state
 /// </summary>
 /// <param name="state">The state to load from</param>
 internal static void LoadState(int state)
 {
     //TODO: check if no mods were loaded
     CurrentMode = Mode.Loading;
     UndoAction  = new UndoActionType(state, LastActionType.restore);
     CanUndo     = true;
     ExposeData(PathHandler.GenBackupStateFile(state));
 }
 /// <summary>
 /// Check if a state is empty
 /// </summary>
 /// <param name="state"></param>
 /// <returns></returns>
 internal static bool StateIsSet(int state)
 {
     return(PathHandler.FileExists(PathHandler.GenBackupStateFile(state)));
 }