Beispiel #1
0
        ///========================================================================
        /// Static Method : FindCourseNameOffsets
        ///
        /// <summary>
        ///     Find the locations in the CD image of all the course names.
        ///
        ///   This only finds course names that are coded into the MMCD class.
        /// </summary>
        /// <param name="xiCDImage"></param>
        /// <returns></returns>
        ///========================================================================
        private static int FindCourseNameOffsets(FileInfo xiCDImage)
        {
            CDImage lCDImage = new CDImage(xiCDImage);

            foreach (MMCD.Course lCourse in MMCD.Courses)
            {
                if (lCourse.CourseName == "")
                {
                    continue;
                }

                byte[] lBytes = Encoding.ASCII.GetBytes(lCourse.CourseNameWithLineBreaks);

                long lIndex = 0;
                bool lFound = false;
                while ((lIndex = lCDImage.Find(lBytes, lIndex)) > 0)
                {
                    WriteLine("{0}: {1}", lCourse.FileName, lIndex++, lCourse.CourseName);
                    lFound = true;
                }

                if (!lFound)
                {
                    WriteLine("{0}: Not found", lCourse.FileName, lCourse.CourseName);
                }
            }

            return(0);
        }
Beispiel #2
0
        ///========================================================================
        /// Static Method : FindCDOffsets
        ///
        /// <summary>
        ///     Find the offsets in the CD image of all the courses in the given
        ///   directory (and subdirectories).
        /// </summary>
        /// <param name="xiCDImage"></param>
        /// <param name="xiRootDir"></param>
        /// <returns></returns>
        ///========================================================================
        private static int FindCDOffsets(FileInfo xiCDImage, DirectoryInfo xiRootDir)
        {
            CDImage lCDImage = new CDImage(xiCDImage);

            //=======================================================================
            // Find all the levels
            //=======================================================================
            Regex lLevelNameRegex = new Regex("[A-Z]+\\\\[A-Z]+[0-9]\\.DAT$", RegexOptions.IgnoreCase);

            foreach (FileInfo lFile in xiRootDir.GetFiles("*.DAT", SearchOption.AllDirectories))
            {
                //=====================================================================
                // Read the entire level into memory
                //=====================================================================
                byte[] lLevelBytes = new byte[lFile.Length];
                using (FileStream lFileStream = lFile.OpenRead())
                {
                    lFileStream.Read(lLevelBytes, 0, lLevelBytes.Length);
                }

                //=====================================================================
                // Find the level in the CD image and output
                //=====================================================================
                long lIndex = lCDImage.Find(lLevelBytes, 0);

                if (lIndex > -1)
                {
                    WriteLine("{0}: {1}", lFile.Name, lIndex);
                }
                else
                {
                    WriteLine("{0}: Not found", lFile.Name);
                }
            }

            return(0);
        }