/*********************************************************************************************
 * Copyright 2002 - Volian Enterprises, Inc. All rights reserved.
 * Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
 * ------------------------------------------------------------------------------
 * $Workfile: Form1.cs $     $Revision: 7 $
 * $Author: Jsj $   $Date: 1/06/03 12:53p $
 *
 * $History: Form1.cs $
 * 
 * *****************  Version 7  *****************
 * User: Jsj          Date: 1/06/03    Time: 12:53p
 * Updated in $/EXE/RefObj/ParadoxConversion
 * cleanup
 * 
 * *****************  Version 6  *****************
 * User: Jsj          Date: 1/06/03    Time: 11:35a
 * Updated in $/EXE/RefObj/ParadoxConversion
 * When called from the RO Editor, hide the Find RO Directory button
 * 
 * *****************  Version 5  *****************
 * User: Jsj          Date: 12/18/02   Time: 12:47p
 * Updated in $/EXE/RefObj/ParadoxConversion
 * new icons
 * 
 * *****************  Version 4  *****************
 * User: Jsj          Date: 12/06/02   Time: 3:21p
 * Updated in $/EXE/RefObj/ParadoxConversion
 * added command line argument (DEBUG) to turn on writing debug message to
 * a file
 * 
 * *****************  Version 3  *****************
 * User: Jsj          Date: 10/04/02   Time: 2:02p
 * Updated in $/EXE/RefObj/ParadoxConversion
 * added better user interface
 * 
 * *****************  Version 2  *****************
 * User: Jsj          Date: 9/25/02    Time: 10:19a
 * Updated in $/EXE/RefObj/ParadoxConversion
 * added header
 *********************************************************************************************/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace ParadoxConversion
{
	/// 
	/// Summary description for Form1.
	/// 
	public class Form1 : System.Windows.Forms.Form
	{
		bool DidConvert = false;
		bool ShowBtnFndRO = true;
		public Form MainForm;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Label StatWindow;
		private string PassedInDirPath;
		private System.Windows.Forms.Button btnFndRO;
		private System.Windows.Forms.Button btnExit;
		private bool DoDebugFile;
		/// 
		/// Required designer variable.
		/// 
		private System.ComponentModel.Container components = null;
		public void StatusWindow(String Message1,String Message2, String Message3)
		{
			StatWindow.Text = Message1 + Message2 + Message3;
		}
		public Form1(string Connpath, bool doingDebug)
		{
			//
			// Required for Windows Form Designer support
			//
//			Icon = new Icon(typeof(Form1),"V.ico");
			InitializeComponent();
			PassedInDirPath = Connpath;
			if (!Connpath.Equals(""))
				ShowBtnFndRO = false;
			DoDebugFile = doingDebug;
			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}
		/// 
		/// Clean up any resources being used.
		/// 
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}
		#region Windows Form Designer generated code
		/// 
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// 
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
			this.button1 = new System.Windows.Forms.Button();
			this.StatWindow = new System.Windows.Forms.Label();
			this.btnFndRO = new System.Windows.Forms.Button();
			this.btnExit = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// button1
			// 
			this.button1.Font = new System.Drawing.Font("Tahoma", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.button1.Location = new System.Drawing.Point(176, 152);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(80, 40);
			this.button1.TabIndex = 0;
			this.button1.Text = "Convert";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// StatWindow
			// 
			this.StatWindow.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.StatWindow.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.StatWindow.Location = new System.Drawing.Point(8, 16);
			this.StatWindow.Name = "StatWindow";
			this.StatWindow.Size = new System.Drawing.Size(368, 112);
			this.StatWindow.TabIndex = 1;
			this.StatWindow.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// btnFndRO
			// 
			this.btnFndRO.Font = new System.Drawing.Font("Tahoma", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnFndRO.Location = new System.Drawing.Point(8, 152);
			this.btnFndRO.Name = "btnFndRO";
			this.btnFndRO.Size = new System.Drawing.Size(152, 40);
			this.btnFndRO.TabIndex = 2;
			this.btnFndRO.Text = "Find RO Directory";
			this.btnFndRO.Click += new System.EventHandler(this.btnFndRO_Click);
			// 
			// btnExit
			// 
			this.btnExit.Font = new System.Drawing.Font("Tahoma", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnExit.Location = new System.Drawing.Point(288, 152);
			this.btnExit.Name = "btnExit";
			this.btnExit.Size = new System.Drawing.Size(80, 40);
			this.btnExit.TabIndex = 3;
			this.btnExit.Text = "Exit";
			this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(384, 197);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.btnExit,
																		  this.btnFndRO,
																		  this.StatWindow,
																		  this.button1});
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "Form1";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Referenced Object Database Conversion";
			this.Load += new System.EventHandler(this.Form1_Load);
			this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
			this.ResumeLayout(false);
		}
		#endregion
		/// 
		/// The main entry point for the application.
		/// 
		static bool ValidateConnectionPath(string ConPath)
		{
			bool validPath = true;
			string tmpstr = "";
			if (ConPath.Equals(""))
				validPath = false;
			else
			{
				// make sure we are in a directory named "RO"
				if (ConPath.IndexOf("\\") != -1)
				{
					tmpstr = ConPath.Substring(ConPath.LastIndexOf("\\"));
					tmpstr = tmpstr.ToUpper();
				}
				else 
					tmpstr = ConPath;
				if (!tmpstr.Equals("\\RO"))
				{
					string tstr = "This is not an RO directory:\n\n" + ConPath;
					MessageBox.Show(tstr,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
					//				Application.Exit();
					validPath = false;
				}
				// make sure there is at least an ROMASTER file
				if (validPath && !File.Exists("ROMASTER.db"))
				{
					string tstr = "This RO directory is empty:" + ConPath;
					MessageBox.Show(tstr,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
					//				Application.Exit();
					validPath = false;
				}
			}
			return validPath;
		}
		static string GetRODirPath(string ConPath)
		{
			string rtnstr = "";
			string tmpstr = "";
			OpenFileDialog ofDlg = new OpenFileDialog();
			ofDlg.Title = "Navigate to the Referenced Objects (RO) directory";
			ofDlg.Filter = "Referenced Objects|ROMASTER.DB;|All Files|*.*";
			if (ConPath.Equals(""))
				tmpstr = "c:\\";
			ofDlg.CheckPathExists = true;
			ofDlg.FileName = "ROMASTER.DB";
			ofDlg.InitialDirectory = tmpstr;
			if (ofDlg.ShowDialog() == DialogResult.OK)
			{
				tmpstr = ofDlg.FileName;
				rtnstr = Path.GetDirectoryName(tmpstr);
			}
			else
			{
				string tstr = "Cannot convert Referenced Objects data.\n\nInvalid RO directory:\n\n" + ConPath;
				MessageBox.Show(tstr,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
				rtnstr = null;
			}
		return rtnstr;
		}
		[STAThread]
		static void Main(string[] args) 
		{
			string ConnectionPath = "";
			bool DebugFile = false;
			// if an RO directory path was passed in, then change the
			//  current working directory to it.
			// this path will also be used to generate a connection string
			// to the Access database.
			if (args.Length > 0)
			{
				string tmpstr;
				for (int i = 0; i