using System;
using System.IO;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace Support_pedagogique_numerique
{
	/// <summary>
	/// Description résumée de Form_intro.
	/// </summary>
	public class Form_intro : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.PictureBox pictureBox1;
		private System.Windows.Forms.Button btn_suivant;
		private System.Windows.Forms.Button btn_annuler;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		/// <summary>
		/// Variable nécessaire au concepteur.
		/// </summary>
		private System.ComponentModel.Container components = null;

		// Formulaires qui s'affichent successivement
		public static Form_intro frm_intro;
		public static Form_docbook frm_docbook;
		public static Form_params frm_params;
		public static Form_arbo frm_arbo;
		private System.Windows.Forms.CheckBox chkbx_prefixe;
		private System.Windows.Forms.CheckBox chkbx_regenerer;
		public static Form_index_htm frm_index_htm;

		public Form_intro()
		{
			//
			// Requis pour la prise en charge du Concepteur Windows Forms
			//
			InitializeComponent();

			//
			// TODO : ajoutez le code du constructeur après l'appel à InitializeComponent
			//
		}

		/// <summary>
		/// Nettoyage des ressources utilisées.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Code généré par le Concepteur Windows Form
		/// <summary>
		/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
		/// le contenu de cette méthode avec l'éditeur de code.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form_intro));
			this.panel1 = new System.Windows.Forms.Panel();
			this.label1 = new System.Windows.Forms.Label();
			this.pictureBox1 = new System.Windows.Forms.PictureBox();
			this.btn_suivant = new System.Windows.Forms.Button();
			this.btn_annuler = new System.Windows.Forms.Button();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.chkbx_prefixe = new System.Windows.Forms.CheckBox();
			this.chkbx_regenerer = new System.Windows.Forms.CheckBox();
			this.panel1.SuspendLayout();
			this.SuspendLayout();
			// 
			// panel1
			// 
			this.panel1.BackColor = System.Drawing.Color.White;
			this.panel1.Controls.Add(this.label1);
			this.panel1.Location = new System.Drawing.Point(0, 0);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(744, 48);
			this.panel1.TabIndex = 1;
			// 
			// label1
			// 
			this.label1.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label1.Location = new System.Drawing.Point(8, 16);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(432, 24);
			this.label1.TabIndex = 0;
			this.label1.Text = "Documentation index generation tool";
			// 
			// pictureBox1
			// 
			this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
			this.pictureBox1.Location = new System.Drawing.Point(32, 72);
			this.pictureBox1.Name = "pictureBox1";
			this.pictureBox1.Size = new System.Drawing.Size(296, 312);
			this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
			this.pictureBox1.TabIndex = 2;
			this.pictureBox1.TabStop = false;
			// 
			// btn_suivant
			// 
			this.btn_suivant.Location = new System.Drawing.Point(536, 440);
			this.btn_suivant.Name = "btn_suivant";
			this.btn_suivant.Size = new System.Drawing.Size(80, 24);
			this.btn_suivant.TabIndex = 5;
			this.btn_suivant.Text = "Next >";
			this.btn_suivant.Click += new System.EventHandler(this.btn_suivant_Click);
			// 
			// btn_annuler
			// 
			this.btn_annuler.Location = new System.Drawing.Point(632, 440);
			this.btn_annuler.Name = "btn_annuler";
			this.btn_annuler.Size = new System.Drawing.Size(80, 24);
			this.btn_annuler.TabIndex = 6;
			this.btn_annuler.Text = "Cancel";
			this.btn_annuler.Click += new System.EventHandler(this.btn_annuler_Click);
			// 
			// groupBox1
			// 
			this.groupBox1.Location = new System.Drawing.Point(8, 416);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(720, 8);
			this.groupBox1.TabIndex = 7;
			this.groupBox1.TabStop = false;
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(400, 104);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(208, 24);
			this.label2.TabIndex = 8;
			this.label2.Text = "Generation tool v 1.0";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(400, 160);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(248, 23);
			this.label3.TabIndex = 9;
			this.label3.Text = "Click Next to start";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(416, 128);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(200, 24);
			this.label4.TabIndex = 10;
			this.label4.Text = "ENM 2005";
			// 
			// label5
			// 
			this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label5.ImageAlign = System.Drawing.ContentAlignment.TopRight;
			this.label5.Location = new System.Drawing.Point(400, 120);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(16, 24);
			this.label5.TabIndex = 11;
			this.label5.Text = "©";
			this.label5.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
			// 
			// chkbx_prefixe
			// 
			this.chkbx_prefixe.Location = new System.Drawing.Point(400, 328);
			this.chkbx_prefixe.Name = "chkbx_prefixe";
			this.chkbx_prefixe.Size = new System.Drawing.Size(280, 24);
			this.chkbx_prefixe.TabIndex = 12;
			this.chkbx_prefixe.Text = "3-digit prefix to file names";
			// 
			// chkbx_regenerer
			// 
			this.chkbx_regenerer.Location = new System.Drawing.Point(400, 360);
			this.chkbx_regenerer.Name = "chkbx_regenerer";
			this.chkbx_regenerer.Size = new System.Drawing.Size(328, 24);
			this.chkbx_regenerer.TabIndex = 13;
			this.chkbx_regenerer.Text = "Regenerate entirely (do not detect previous index files)";
			// 
			// Form_intro
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(742, 478);
			this.Controls.Add(this.chkbx_regenerer);
			this.Controls.Add(this.chkbx_prefixe);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.btn_suivant);
			this.Controls.Add(this.btn_annuler);
			this.Controls.Add(this.pictureBox1);
			this.Controls.Add(this.panel1);
			this.Name = "Form_intro";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Documentation index generation tool";
			this.Load += new System.EventHandler(this.Form_intro_Load);
			this.panel1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// Point d'entrée principal de l'application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			frm_intro = new Form_intro();
			Application.Run(frm_intro);
		}

		private void btn_annuler_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void btn_suivant_Click(object sender, System.EventArgs e)
		{
			// Pas de préfixe de 3 chiffres aux noms de fichiers
			if (chkbx_prefixe.Checked==false) 
			{
				Config.docbookgen_xsl="docbookgen2.xsl";
				Config.dcgen_xsl="dcgen2.xsl";
			}
			
			// Régénération complète
			if (chkbx_regenerer.Checked==true) 
			{
				try {
					// Suppression du fichier index.htm et index.docbook
					if (File.Exists(Config.index_docbook)) 
					{
						File.Delete(Config.index_docbook);
					}
					if (File.Exists(Config.index_htm)) 
					{
						File.Delete(Config.index_htm);
					}
				}   
				catch  (Exception ex)
				{ 
					MessageBox.Show ("Exception lors de la suppression des fichiers index existants : "+ ex.ToString());
					Application.Exit();
				}
			}

			// Chargement du Form suivant
			frm_docbook = new Form_docbook();
			this.Hide();
			frm_docbook.Show();
			frm_docbook.Activate();
			frm_docbook.Refresh();

			// Détection d'un index docbook déjà existant
			if (File.Exists(Config.index_docbook)) 
			{
				Config.docbook_existant=true;
				frm_docbook.docbookExistant();
			}
			else 
			{
				// Création à partir de zéro
				frm_docbook.demarrerGeneration();
			}
		}

		private void Form_intro_Load(object sender, System.EventArgs e)
		{
			btn_suivant.Focus();
		}
	}

}
