/*********************************************************************************************
 * Copyright 2004 - Volian Enterprises, Inc. All rights reserved.
 * Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
 * ------------------------------------------------------------------------------
 * $Workfile: FmtFiles.cs $     $Revision: 2 $
 * $Author: Jsj $   $Date: 5/17/05 11:51a $
 *
 * $History: FmtFiles.cs $
 * 
 * *****************  Version 2  *****************
 * User: Jsj          Date: 5/17/05    Time: 11:51a
 * Updated in $/LibSource/Utils
 * cleanup
 * 
 * *****************  Version 1  *****************
 * User: Kathy        Date: 7/27/04    Time: 8:34a
 * Created in $/LibSource/Utils
 *********************************************************************************************/

using System;
using System.IO;
using System.Windows.Forms;

namespace Utils
{
	/// <summary>
	/// Summary description for FmtFiles.
	/// </summary>
	public class FmtFile
	{
		public string FmtFileName;
		public FmtFile(string fname)
		{
			if (fname.IndexOf(".fmt",0) > -1)
				FmtFileName = fname;
			else
				FmtFileName = fname + ".fmt";
		}

		public string GetFormatTitle(UserRunTime usrRT)
		{
			string fmtpath = usrRT.syspath + "\\format\\" + FmtFileName;
			FileStream fs;
			FileInfo fi = new FileInfo(fmtpath);
			try
			{
				fs = fi.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite );
			}
			catch (Exception e)
			{
				MessageBox.Show(e.ToString(),"Format File Read Error");
				return null;
			}

			BinaryReader bw = new BinaryReader(fs,System.Text.ASCIIEncoding.ASCII);

			ushort len;
			len = bw.ReadUInt16();
			string retTitle = null;
			if (len > 1)
				retTitle = new string(bw.ReadChars(len-1));   // -1: remove the null
			else
				retTitle = "Format not found";
			
			return retTitle;
		}
	}

	public class DocFile
	{
		public DocFile()
		{
		}
	}
}
