예제 #1
0
        ///========================================================================
        /// Method : GetLevel
        ///
        /// <summary>
        ///     Get the level from a particular Version
        /// </summary>
        /// <param name="xiVersion"></param>
        /// <returns></returns>
        ///========================================================================
        public Level GetLevel(Version xiVersion)
        {
            if (xiVersion.SerialisedLevel != null)
            {
                return(xiVersion.GetLevel(null));
            }

            int lIndex = Versions.IndexOf(xiVersion);

            if (lIndex == -1)
            {
                throw new Exception("Cannot retrieve Level from Version - Version does not appear to be in the VersionList");
            }

            return(GetVersion(lIndex).GetLevel(null));
        }
예제 #2
0
        ///========================================================================
        /// Method : GetVersion
        ///
        /// <summary>
        ///     Get a particular level in the list
        /// </summary>
        /// <param name="xiIndex"></param>
        /// <returns></returns>
        /// <remarks>
        ///   The fact that we have to call GetLevel like this is a bit confused -
        ///   should tidy this up really.
        /// </remarks>
        ///========================================================================
        private Version GetVersion(int xiIndex)
        {
            Version lVersion = Versions[xiIndex];

            if (lVersion.SerialisedLevel == null)
            {
                if (xiIndex == 0)
                {
                    throw new InvalidOperationException("Error: First level in the version list was differentially serialised, but there's no previous version to compare the diff against");
                }

                lVersion.GetLevel(GetVersion(xiIndex - 1));
            }

            return(lVersion);
        }
예제 #3
0
        ///========================================================================
        /// Constructor : Version
        /// 
        /// <summary>
        /// 	Create a new version
        /// </summary>
        /// <param name="xiLevel"></param>
        /// <param name="xiPreviousVersion"></param>
        /// <param name="xiStoreAsDiff"></param>
        /// <param name="xiExpectedSize"></param>
        ///========================================================================
        internal Version(Level xiLevel, Version xiPreviousVersion, bool xiStoreAsDiff, long xiExpectedSize)
        {
            CreationDate = DateTime.Now;

              //=======================================================================
              // Serialise the level
              //=======================================================================
              while (true)
              {
            using (MemoryStream lLevelStream = new MemoryStream())
            {
              xiLevel.Serialise(lLevelStream);
              lLevelStream.Seek(0, SeekOrigin.Begin);
              SerialisedLevel = new byte[lLevelStream.Length];
              lLevelStream.Read(SerialisedLevel, 0, SerialisedLevel.Length);
            }

            if (xiExpectedSize > 0 && SerialisedLevel.Length != xiExpectedSize)
            {
              long lSizeAdjustment = SerialisedLevel.Length - xiExpectedSize;

              if (lSizeAdjustment > 0 && xiLevel.SHET.TrailingZeroByteCount < lSizeAdjustment)
              {
            MessageBox.Show(string.Format(@"WARNING: The level is too large to fit in the expected size of file. Please remove some content from the level. Your level can be saved, but attempts to play the course will fail.

            Expected size: {0} bytes
            Actual size: {1} bytes
            Spare space: {2} bytes
            Space required: {3} bytes",
                         xiExpectedSize,
                         SerialisedLevel.Length,
                         xiLevel.SHET.TrailingZeroByteCount,
                         lSizeAdjustment - xiLevel.SHET.TrailingZeroByteCount), "MMEd", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
              }
              else if (MessageBox.Show("WARNING: The level is not of the expected size for this course. Do you want to adjust the file size to match? This can be done without corrupting the level.", "MMEd", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
              {
            xiLevel.SHET.TrailingZeroByteCount -= (int)lSizeAdjustment;
            continue;
              }
            }

            break;
              }

              //=======================================================================
              // Calculate differences, and store as a diff if appropriate
              //=======================================================================
              if (xiPreviousVersion != null)
              {
            Changes = string.Join("\r\n", xiLevel.GetDifferences(xiPreviousVersion.GetLevel(null)).ToArray());
              }
              else
              {
            Changes = "";
              }

              if (xiStoreAsDiff)
              {
            DifferentialLevel = DiffBlock.GetDifferences(xiPreviousVersion.SerialisedLevel, SerialisedLevel);
              }
        }
예제 #4
0
        ///========================================================================
        /// Method : GetLevel
        /// 
        /// <summary>
        /// 	Get the level from a particular Version
        /// </summary>
        /// <param name="xiVersion"></param>
        /// <returns></returns>
        ///========================================================================
        public Level GetLevel(Version xiVersion)
        {
            if (xiVersion.SerialisedLevel != null)
              {
            return xiVersion.GetLevel(null);
              }

              int lIndex = Versions.IndexOf(xiVersion);

              if (lIndex == -1)
              {
            throw new Exception("Cannot retrieve Level from Version - Version does not appear to be in the VersionList");
              }

              return GetVersion(lIndex).GetLevel(null);
        }
예제 #5
0
        ///========================================================================
        /// Constructor : Version
        ///
        /// <summary>
        ///     Create a new version
        /// </summary>
        /// <param name="xiLevel"></param>
        /// <param name="xiPreviousVersion"></param>
        /// <param name="xiStoreAsDiff"></param>
        /// <param name="xiExpectedSize"></param>
        ///========================================================================
        internal Version(Level xiLevel, Version xiPreviousVersion, bool xiStoreAsDiff, long xiExpectedSize)
        {
            CreationDate = DateTime.Now;

            //=======================================================================
            // Serialise the level
            //=======================================================================
            while (true)
            {
                using (MemoryStream lLevelStream = new MemoryStream())
                {
                    xiLevel.Serialise(lLevelStream);
                    lLevelStream.Seek(0, SeekOrigin.Begin);
                    SerialisedLevel = new byte[lLevelStream.Length];
                    lLevelStream.Read(SerialisedLevel, 0, SerialisedLevel.Length);
                }

                if (xiExpectedSize > 0 && SerialisedLevel.Length != xiExpectedSize)
                {
                    long lSizeAdjustment = SerialisedLevel.Length - xiExpectedSize;

                    if (lSizeAdjustment > 0 && xiLevel.SHET.TrailingZeroByteCount < lSizeAdjustment)
                    {
                        MessageBox.Show(string.Format(@"WARNING: The level is too large to fit in the expected size of file. Please remove some content from the level. Your level can be saved, but attempts to play the course will fail.

Expected size: {0} bytes
Actual size: {1} bytes
Spare space: {2} bytes
Space required: {3} bytes",
                                                      xiExpectedSize,
                                                      SerialisedLevel.Length,
                                                      xiLevel.SHET.TrailingZeroByteCount,
                                                      lSizeAdjustment - xiLevel.SHET.TrailingZeroByteCount), "MMEd", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else if (MessageBox.Show("WARNING: The level is not of the expected size for this course. Do you want to adjust the file size to match? This can be done without corrupting the level.", "MMEd", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        xiLevel.SHET.TrailingZeroByteCount -= (int)lSizeAdjustment;
                        continue;
                    }
                }

                break;
            }

            //=======================================================================
            // Calculate differences, and store as a diff if appropriate
            //=======================================================================
            if (xiPreviousVersion != null)
            {
                Changes = string.Join("\r\n", xiLevel.GetDifferences(xiPreviousVersion.GetLevel(null)).ToArray());
            }
            else
            {
                Changes = "";
            }

            if (xiStoreAsDiff)
            {
                DifferentialLevel = DiffBlock.GetDifferences(xiPreviousVersion.SerialisedLevel, SerialisedLevel);
            }
        }