Esempio n. 1
0
        /// <summary>
        /// Resets the <see cref="SaveFile"/> of the specified index, equal to the Erase option on the title screen.
        /// </summary>
        /// <param name="index">The zero-based index of the save file to reset. Refer to <see cref="SaveUtils.SAVE_FILE_COUNT"/> for the highest index.</param>
        /// <param name="force">
        /// When <c>true</c>, reset the save file regardless of it being the active <see cref="GM.SaveFile"/> or not.
        /// This is a DANGEROUS option and has the potential to corrupt your save file.
        /// </param>
        /// <returns><c>True</c> when the save file was reset, <c>false</c> when it was not found or when it is the active save file and <paramref name="force"/> is <c>false</c>.</returns>
        public static bool ResetSaveFile(int index, bool force = false)
        {
            if (index < 0 || index >= SaveUtils.SAVE_FILE_COUNT)
            {
                throw new ArgumentOutOfRangeException(nameof(index), $"Minimum: 0  Maximum: {SaveUtils.SAVE_FILE_COUNT - 1}");
            }

            if (GM.System != null)
            {
                var saveFile = SaveUtils.GetSaveFile(index);
                if (saveFile != null && (force || saveFile != GM.System.SaveFile))
                {
                    saveFile.ResetFile();
                    SaveUtils.Save();
                    return(true);
                }
            }

            return(false);
        }