Exemple #1
0
            public bool UndoLastAction()
            {
                Main.LogDebug("Undoing last action type {1} for state {0}", State, LastAction.ToString());
                switch (LastAction)
                {
                case LastActionType.restore:
                    Main.LogDebug("Restoring {0} active mods", ModData.activeMods.Count);
                    SetActiveMods(ModData.activeMods);
                    return(true);

                case LastActionType.backup:
                    if (ModData != null)
                    {
                        Main.LogDebug("Restored {0}'s last state", State);
                        XmlSaverAPI.SaveDataObject((object)ModData, GenBackupStateFile(State));
                    }
                    else
                    {
                        Main.LogDebug("Attempting to delete {0}", State);
                        File.Delete(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);
                }
            }
Exemple #2
0
        /// <summary>
        /// Saves or Loads the state
        /// </summary>
        /// <param name="filepath">The filepath to the state</param>
        private static void ExposeData(string filepath, bool useUndoAction = false)
        {
            try
            {
                if (CurrentMode == Mode.Saving)
                {
                    Main.LogDebug("Saving state to {0}", filepath);

                    Data = new ModsConfigData
                    {
                        buildNumber = RimWorld.VersionControl.CurrentBuild,
                        activeMods  = GetActiveMods()
                    };
                    XmlSaverAPI.SaveDataObject((object)Data, filepath);
                }
                else if (CurrentMode == Mode.Loading)
                {
                    Main.LogDebug("Loading state from {0}", filepath);

                    List <string> current = new List <string>();

                    Data = ReadState(filepath);

                    ClearLoadedMods(true);
                    foreach (string modID in Data.activeMods)
                    {
                        ModsConfigAPI.SetActive(modID, true);
                    }
                }
            }
            catch (System.Exception e)
            {
                //An error occurred, output to log and reset loaded mods
                Main.Log.ReportException(e, Globals.MOD_IDENTIFIER, true, "ExposeData");
                ClearLoadedMods();
            }
        }