Пример #1
0
		public ReplayReader()
		{
			replay = new Replay();
		}
Пример #2
0
		public ReplayReader(string Filename)
		{
			filename = Filename;
			replay = new Replay();
			replay.Filename = filename;
		}
Пример #3
0
		/// <summary>
		/// Renames the replays' internal name
		/// </summary>
		/// <param name="newName">New name to use for the replay</param>
		public bool RenameReplay(Replay replay, string newName)
		{
			try
			{
				//load the replay data
				FileStream fsreader = File.OpenRead(replay.Filename);
				byte[] data = new byte[fsreader.Length];
				fsreader.Read(data, 0, data.Length);
				fsreader.Close();

				//create a buffer for the adjusted file
				int new_replaysize = replay.FileSize + ((newName.Length - replay.Name.Length) * 2);
				byte[] buffer = new byte[new_replaysize];
				System.IO.MemoryStream writer = new MemoryStream(buffer);
 
				//calculate the new db & foldinfo len
				int database_len = replay.DATABASE + ((newName.Length - replay.Name.Length) * 2);
				int foldinfo_len = replay.FOLDINFO + ((newName.Length - replay.Name.Length) * 2);

				//write everything into the new buffer up to the foldinfo len
				writer.Write(data, 0, replay.FOLDINFOPOS);
				byte[] foldinfo_byte = BitConverter.GetBytes(foldinfo_len);
				writer.Write(foldinfo_byte, 0, foldinfo_byte.Length);

				writer.Write(data, replay.FOLDINFOPOS + 4, (replay.DATABASEPOS - replay.FOLDINFOPOS - 4));
				byte[] database_byte = BitConverter.GetBytes(database_len);
				writer.Write(database_byte, 0, database_byte.Length);

				writer.Write(data, replay.DATABASEPOS + 4, (replay.REPLAYLENPOS - replay.DATABASEPOS - 4));
				byte[] replay_byte = BitConverter.GetBytes(newName.Length);
				writer.Write(replay_byte, 0, replay_byte.Length);

				//get the new name in bytes
				System.Text.UnicodeEncoding encoder = new System.Text.UnicodeEncoding();
				byte[] byte_name = encoder.GetBytes(newName);
				writer.Write(byte_name, 0, byte_name.Length);

				writer.Write(data, (replay.REPLAYLENPOS + 4 + (replay.Name.Length * 2)), 
					(replay.FileSize - ((replay.REPLAYLENPOS + 4) + replay.Name.Length * 2)));

				writer.Close();

				BinaryWriter binwriter = new BinaryWriter(File.Create(replay.Filename));
				binwriter.Write(buffer);
				binwriter.Close();

				return true;
			}
			catch
			{
				return false;
			}
		}