Example #1
0
        /// <summary>
        /// Writes mod settings (title, priority, enabled) to file
        /// </summary>
        /// <returns></returns>
        public static bool WriteModSettings()
        {
            try
            {
                if (ModManager.Instance.Mods == null || ModManager.instance.Mods.Count <= 0)
                {
                    return(false);
                }

                FullSerializer.fsData sdata = null;
                var result = _serializer.TrySerialize <List <Mod> >(ModManager.instance.Mods, out sdata);

                if (result.Failed)
                {
                    return(false);
                }

                File.WriteAllText(Path.Combine(ModManager.instance.modDirectory, MODCONFIGFILENAME), FullSerializer.fsJsonPrinter.PrettyJson(sdata));
                return(true);
            }
            catch (Exception ex)
            {
                Debug.LogError(string.Format("Failed to write mod settings: {0}", ex.Message));
                return(false);
            }
        }
            private string _toJSON <T>(T obj)
            {
                string serialized = null;

                FullSerializer.fsData   fsData;
                FullSerializer.fsResult fsResult;

                fsResult = _mSerializer.TrySerialize <T>(obj, out fsData);

                if (fsResult.Succeeded)
                {
#if SS_DEBUG
                    serialized = FullSerializer.fsJsonPrinter.PrettyJson(fsData);
#else
                    serialized = FullSerializer.fsJsonPrinter.CompressedJson(fsData);
#endif
                }
                else
                {
                    throw new System.Exception("Failed serializing object: " + obj.ToString());
                }

                return(serialized);
            }