Exemplo n.º 1
0
        //! Patch: SavedProfile.LoadProfile
        internal static void LoadProfile(ProfileV07 original)
        {
            string realPath = Path.Combine(SavePath, PROFILE_FILENAME);

            if (!File.Exists(realPath))
            {
                return;
            }
            GuuCore.LOGGER.Log($"Attempting to load modded profile file {PROFILE_FILENAME}");

            using (FileStream fileStream = File.Open(realPath, FileMode.Open))
            {
                using (MemoryStream dataStream = new MemoryStream())
                {
                    CopyStream(fileStream, dataStream);
                    dataStream.Seek(0, SeekOrigin.Begin);
                    ProfileV07 profile = new ProfileV07();
                    try
                    {
                        profile.Load(dataStream);
                        original.achievements.progress.counts.AddRange(profile.achievements.progress.counts);
                        original.achievements.progress.events.AddRange(profile.achievements.progress.events);
                        original.achievements.progress.lists.AddRange(profile.achievements.progress.lists);
                        original.achievements.earnedAchievements.AddRange(profile.achievements.earnedAchievements);
                    }
                    catch (Exception e)
                    {
                        GuuCore.LOGGER.LogError("Failed to load modded profile file.");
                        GuuCore.LOGGER.LogError(e.ParseTrace());
                    }
                }
            }

            GuuCore.LOGGER.Log($"Loaded modded profile file {PROFILE_FILENAME}");
        }
Exemplo n.º 2
0
        //! Patch: SavedProfile.SaveProfile
        internal static void SaveProfile(ProfileV07 original)
        {
            string realPath = Path.Combine(SavePath, PROFILE_FILENAME);

            GuuCore.LOGGER.Log($"Saving modded profile file {PROFILE_FILENAME}");

            ProfileV07 profile = new ProfileV07();

            // TODO: Strip content from the original

            using (MemoryStream dataStream = new MemoryStream())
            {
                profile.Write(dataStream);
                dataStream.Seek(0, SeekOrigin.Begin);
                using (FileStream fileStream = File.Create(realPath))
                {
                    try
                    {
                        CopyStream(dataStream, fileStream);
                    }
                    catch (Exception e)
                    {
                        GuuCore.LOGGER.LogError("Failed to save modded profile file.");
                        GuuCore.LOGGER.LogError(e.ParseTrace());
                    }
                }
            }

            GuuCore.LOGGER.Log($"Saved modded profile file {PROFILE_FILENAME}");
        }