view ABFile.cs @ 5:ec77b60e5369 default tip

Re #121: Migrate to AGPL license * Update all Army Builder API files to AGPL license * Include AGPL license and remove GPL/LGPL documents
author IBBoard <dev@ibboard.co.uk>
date Sat, 15 Aug 2009 10:51:59 +0000
parents 1a54f6afafe7
children
line wrap: on
line source

//  This file (ABFile.cs) is a part of the IBBoard.ArmyBuilder.API project and is copyright 2009 IBBoard
// 
// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. 

using System;
using System.IO;
using System.Collections.Generic;
using IBBoard.IO;
using IBBoard.ArmyBuilder.API.Loaders;

namespace IBBoard.ArmyBuilder.API
{
	/// <summary>
	/// A .ab file (Army Builder's main data definition file). .ab files contain details of the application requirements for a game system,
	/// details of the game system, and all of the data files for that game system (including race data).
	/// </summary>
	public abstract class ABFile
	{
		private FileInfo file;
		private string header = "";
		private string comment = "";
		private int fileTablePosition = 0;
		private List<FileTableEntry> files;
		
		public ABFile(String filePath) : this(new FileInfo(filePath))
		{
		}

		public ABFile(FileInfo file)
		{
			this.file = file;
			files = new List<FileTableEntry>();
		}

		public FileInfo File
		{
			get { return file; }
		}

		public FileStream GetFileStream()
		{
			return file.OpenRead();
		}

		public void AddFileTableEntry(FileTableEntry tableEntry)
		{
			if (tableEntry!=null && !files.Contains(tableEntry))
			{
				files.Add(tableEntry);
				tableEntry.ParentFile = this;
			}
		}

		public void RemoveFileTableEntry(FileTableEntry tableEntry)
		{
			if (tableEntry !=null && files.Contains(tableEntry))
			{
				files.Remove(tableEntry);
				tableEntry.ParentFile = null;
			}
		}

		public FileTableEntry[] Files
		{
			get
			{
				return files.ToArray();
			}
		}

		public string Header
		{
			//This may actually be three values - a standard header ("LWDExport"), a count of the number of header parts (? seemingly always 0A)
			// and an app name ("Army Builder" or "Card Value")
			get
			{
				return header;
			}
			set
			{
				header = value;
			}
		}

		public string Comment
		{
			get
			{
				return comment;
			}
			set
			{
				comment = value;
			}
		}

		public int FileTablePosition
		{
			get
			{
				return fileTablePosition;
			}
			set
			{
				fileTablePosition = value;
			}
		}			
	}
}