コード例 #1
0
        public static void Load()
        {
            string idxPath = Path.Combine("Saves/FriendLists", "FriendLists.idx");
            string binPath = Path.Combine("Saves/FriendLists", "FriendLists.bin");

            if (File.Exists(idxPath) && File.Exists(binPath))
            {
                // Declare and initialize reader objects.
                FileStream       idx       = new FileStream(idxPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                FileStream       bin       = new FileStream(binPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                BinaryReader     idxReader = new BinaryReader(idx);
                BinaryFileReader binReader = new BinaryFileReader(new BinaryReader(bin));

                // Start by reading the number of duels from an index file
                int orderCount = idxReader.ReadInt32();

                for (int i = 0; i < orderCount; ++i)
                {
                    FriendList fl = new FriendList();
                    // Read start-position and length of current order from index file
                    long startPos = idxReader.ReadInt64();
                    int  length   = idxReader.ReadInt32();
                    // Point the reading stream to the proper position
                    binReader.Seek(startPos, SeekOrigin.Begin);

                    try
                    {
                        fl.Deserialize(binReader);

                        if (binReader.Position != (startPos + length))
                        {
                            throw new Exception(String.Format("***** Bad serialize on FriendList[{0}] *****", i));
                        }
                    }
                    catch
                    {
                        //handle
                    }
                    if (fl != null && fl.m_Mobile != null)
                    {
                        FriendLists.Add(fl.m_Mobile, fl);
                    }
                }
                // Remember to close the streams
                idxReader.Close();
                binReader.Close();
            }
        }
コード例 #2
0
		public static void Load()
		{
			string idxPath = Path.Combine( "Saves/FriendLists", "FriendLists.idx" );
			string binPath = Path.Combine( "Saves/FriendLists", "FriendLists.bin" );

			if (File.Exists(idxPath) && File.Exists(binPath))
			{
				// Declare and initialize reader objects.
				FileStream idx = new FileStream(idxPath, FileMode.Open, FileAccess.Read, FileShare.Read);
				FileStream bin = new FileStream(binPath, FileMode.Open, FileAccess.Read, FileShare.Read);
				BinaryReader idxReader = new BinaryReader(idx);
				BinaryFileReader binReader = new BinaryFileReader(new BinaryReader(bin));

				// Start by reading the number of duels from an index file
				int orderCount = idxReader.ReadInt32();

				for (int i = 0; i < orderCount; ++i)
				{

					FriendList fl = new FriendList();
					// Read start-position and length of current order from index file
					long startPos = idxReader.ReadInt64();
					int length = idxReader.ReadInt32();
					// Point the reading stream to the proper position
					binReader.Seek(startPos, SeekOrigin.Begin);

					try
					{
						fl.Deserialize(binReader);

						if (binReader.Position != (startPos + length))
							throw new Exception(String.Format("***** Bad serialize on FriendList[{0}] *****", i));
					}
					catch
					{
						//handle
					}
					if ( fl != null && fl.m_Mobile != null )
						FriendLists.Add( fl.m_Mobile, fl );
				}
				// Remember to close the streams
				idxReader.Close();
				binReader.Close();
			}

		}