352 lines
10 KiB
C#
352 lines
10 KiB
C#
/*********************************************************************************************
|
|
* 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>
|
|
/// Summary description for Form1.
|
|
/// </summary>
|
|
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;
|
|
|
|
/// <summary>
|
|
/// Required designer variable.
|
|
/// </summary>
|
|
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
|
|
//
|
|
}
|
|
|
|
/// <summary>
|
|
/// Clean up any resources being used.
|
|
/// </summary>
|
|
protected override void Dispose( bool disposing )
|
|
{
|
|
if( disposing )
|
|
{
|
|
if (components != null)
|
|
{
|
|
components.Dispose();
|
|
}
|
|
}
|
|
base.Dispose( disposing );
|
|
}
|
|
|
|
#region Windows Form Designer generated code
|
|
/// <summary>
|
|
/// Required method for Designer support - do not modify
|
|
/// the contents of this method with the code editor.
|
|
/// </summary>
|
|
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
|
|
|
|
/// <summary>
|
|
/// The main entry point for the application.
|
|
/// </summary>
|
|
|
|
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<args.Length; i++)
|
|
{
|
|
tmpstr = args[0];
|
|
if (tmpstr.Equals("DEBUG"))
|
|
DebugFile = true;
|
|
else
|
|
{
|
|
ConnectionPath = tmpstr;
|
|
Directory.SetCurrentDirectory(ConnectionPath);
|
|
ConnectionPath = Directory.GetCurrentDirectory();
|
|
}
|
|
}
|
|
}
|
|
Form MainForm = new Form1(ConnectionPath,DebugFile);
|
|
Application.Run(MainForm);
|
|
}
|
|
|
|
private void button1_Click(object sender, System.EventArgs e)
|
|
{
|
|
if (!DidConvert)
|
|
{
|
|
StatWindow.Text = "";
|
|
ConvertParadoxROs CvrtROs = new ConvertParadoxROs(StatWindow,DoDebugFile);
|
|
CvrtROs.ConvertParadoxRODb(PassedInDirPath);
|
|
StatWindow.Text = " *** Conversion Complete ****";
|
|
DidConvert = true;
|
|
button1.Enabled = false;
|
|
this.Refresh();
|
|
}
|
|
else
|
|
{
|
|
Application.Exit();
|
|
}
|
|
}
|
|
|
|
private void Form1_Load(object sender, System.EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void btnFndRO_Click(object sender, System.EventArgs e)
|
|
{
|
|
while ((PassedInDirPath != null) && !ValidateConnectionPath(PassedInDirPath))
|
|
{
|
|
PassedInDirPath = GetRODirPath(PassedInDirPath);
|
|
}
|
|
|
|
if (PassedInDirPath == null)
|
|
{
|
|
Application.Exit();
|
|
}
|
|
DidConvert = false;
|
|
|
|
}
|
|
|
|
private void btnExit_Click(object sender, System.EventArgs e)
|
|
{
|
|
Application.Exit();
|
|
}
|
|
|
|
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
|
|
{
|
|
string msgtxt = "";
|
|
if (!DidConvert)
|
|
{
|
|
if ((PassedInDirPath == null) || !ValidateConnectionPath(PassedInDirPath))
|
|
{
|
|
button1.Enabled = false;
|
|
btnFndRO.Enabled = true;
|
|
msgtxt = "Press the Find RO Directory button to locate the Referened Objects you want to Convert.";
|
|
}
|
|
else
|
|
{
|
|
if (PassedInDirPath != null)
|
|
button1.Enabled = true;
|
|
if (!ShowBtnFndRO)
|
|
btnFndRO.Hide();
|
|
msgtxt = "Current RO directory selected:\n\n" + PassedInDirPath;
|
|
}
|
|
|
|
StatWindow.Text = msgtxt;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|