Mes documents/Visual Studio 2005/Projects/TES4ModTranslator/TES4ModTranslator/Form1.cs

Go to the documentation of this file.
00001 using System;
00002 using System.IO;
00003 using System.Collections.Generic;
00004 using System.ComponentModel;
00005 using System.Data;
00006 using System.Drawing;
00007 using System.Text;
00008 using System.Windows.Forms;
00009 using Microsoft.Win32;
00010 using TESPluginParser;
00011 
00012 namespace TES4ModTranslator
00013 {
00017     public partial class Form1 : Form
00018     {
00022         public Form1()
00023         {
00024             InitializeComponent();
00025         }
00026 
00027         private void loadPlugin(string pluginName)
00028         {
00029             //delete all pre-existing TabPages from TabControl
00030             tabControl1.TabPages.Clear();
00031             Plugin p = new Plugin(pluginName);
00032             addData(p);
00033         }
00034 
00035         private void addData(Plugin p)
00036         {
00037             foreach (Rec aRec in p.Records)
00038             {
00039                 if (aRec is GroupRecord)
00040                 {
00041                     foreach (Record aRecord in ((GroupRecord)aRec).Records)
00042                     {
00043                         if (aRecord.Name != "SCPT" && aRecord.Name != "DIAL")
00044                         {
00045                             addTabPage(aRecord.Name);
00046                             //foreach (SubRecord sr in aRecord.SubRecords)
00047                             //{
00048                             // insert line with EDID and FULL
00049                             //}
00050                             //if (aRecord.Name == "BOOK")
00051                             //{
00052                             //  do somme more stuff with them
00053                             //}
00054                         }
00055                         else
00056                         {
00057                             // deal with script (SCPT), dialogs (DIAL)
00058                         }
00059                     }
00060                 }
00061             }
00062         }
00063 
00064         private void addTabPage(string name)
00065         {
00066 
00067             TabPage tp = null;
00068             string[] row = new string[] { " ", " ", " ", " " };
00069             List<DataGridView> dgvList = null;
00070             DataGridView dgv = null;
00071 
00072             foreach (TabPage tmp in tabControl1.TabPages)
00073             {
00074                 if (tmp.Name == name)
00075                 {
00076                     tabControl1.SelectedTab = tmp;
00077                     tp = tmp;
00078                     int number = tabControl1.SelectedIndex;
00079                     dgv = dgvList[number];
00080                     row = new string[] { "?", dgv.RowCount.ToString() + number.ToString(), "My very big car", " " };
00081                     break;
00082                 }
00083             }
00084             
00085             if (tp == null)
00086             {
00087                 tp = new TabPage(name);
00088 
00089                 tp.Name = name;
00090                 tabControl1.Controls.Add(tp);
00091                 tabControl1.SelectedTab = tp;
00092 
00093                 DataGridView dgv = new DataGridView();
00094 
00095                 dgvList.Add(dgv);
00096 
00097                 DataGridViewTextBoxColumn flag = new DataGridViewTextBoxColumn();
00098                 DataGridViewTextBoxColumn espId = new DataGridViewTextBoxColumn();
00099                 DataGridViewTextBoxColumn espFull = new DataGridViewTextBoxColumn();
00100                 DataGridViewTextBoxColumn userFull = new DataGridViewTextBoxColumn();
00101 
00102                 flag.HeaderText = "F";
00103                 flag.Name = "FLAG";
00104                 flag.ReadOnly = true;
00105                 espId.HeaderText = "ID";
00106                 espId.Name = "espId";
00107                 espId.ReadOnly = true;
00108                 espFull.HeaderText = "Original Name";
00109                 espFull.Name = "espFull";
00110                 espFull.ReadOnly = true;
00111                 userFull.HeaderText = "Translated Name";
00112                 userFull.Name = "userFull";
00113 
00114                 dgv.AllowUserToAddRows = false;
00115                 dgv.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { flag, espId, espFull, userFull });
00116                 dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
00117 
00118                 tp.Controls.Add(dgv);
00119                 int number = tabControl1.SelectedIndex;
00120                 row = new string[] {"!", dgv.RowCount.ToString() + number.ToString(),"My very old chestnut horse", " "};
00121             }
00122 
00123             dgv.Rows.Add(row);
00124 
00125         }
00126 
00127         private void checkDB(string aType)
00128         {
00129             // check if a DB file exists
00130             bool exists;
00131             string ObliDB = Application.StartupPath + "\\data\\" + aType + ".csv";
00132             string UserDB = Application.StartupPath + "\\extra\\" + aType + ".csv";
00133             exists = File.Exists(ObliDB);
00134             // if not DB must be generated from oblivion.esm
00135             //  1. detect Oblivion path installation
00136             //  2. read oblivion.esm to retrieve TYPE/EDITOR ID/FULL NAME records
00137             //  3. create a CSV file with :
00138             //       col #1 is EDID
00139             //       col #2 is FULLNAME
00140             if (exists == false)
00141             {
00142                 MessageBox.Show("Some database are missing\nConsider rebuilding your database",
00143                     "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
00144             }
00145         }
00146 
00147         private string oblivionInstallPath()
00148         {
00149             // retrieve the oblivon install path from the registry
00150             RegistryKey userKey = Registry.LocalMachine;  // points to HKLM hive
00151             userKey = userKey.OpenSubKey(@"SOFTWARE\Bethesda Softworks\Oblivion", false);  // points to subkey
00152             string obliPath = userKey.GetValue("Installed Path").ToString();
00153             return obliPath;
00154         }
00155 
00156         private void generateDB()
00157         {
00158             string oblivion = oblivionInstallPath() + "data\\Oblivion.esm";
00159             string line;
00160             //MessageBox.Show("Oblivion location: " + oblivion, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
00161             Plugin p = new Plugin(oblivion);
00162             foreach (Rec aRec in p.Records)
00163             {
00164                 if (aRec is GroupRecord)
00165                 {
00166                     foreach (Record aRecord in ((GroupRecord)aRec).Records)
00167                     {
00168                         string filename = Application.StartupPath + "extra\\" + aRecord.Name + ".csv";
00169                         //FileStream fs = new FileStream(filename, FileMode.Append, FileAccess.Write); 
00170                         //StreamWriter sw = new StreamWriter(fs);
00171                         //line = "";
00172                         //foreach (SubRecord sr in aRecord.SubRecords)
00173                         //{
00174                         //    if (sr.Name == "EDID" || sr.Name == "NAME")
00175                         //    {
00176                         //        line += sr.GetData();
00177                         //        line += "\t";
00178                         //    }
00179                         //}
00180                         //sw.Write(line);
00181                     }
00182                 }
00183             }
00184         }
00185 
00186         private void generateToolStripMenuItem_Click(object sender, EventArgs e)
00187         {
00188             generateDB();
00189         }
00190 
00191         private void openToolStripMenuItem_Click(object sender, EventArgs e)
00192         {
00193             string filename;
00194 
00195             openFileDialog.Filter = "ESP files (*.esp)|*.esp";
00196             openFileDialog.FilterIndex = 0;
00197             openFileDialog.FileName = "";
00198 
00199             if (openFileDialog.ShowDialog() == DialogResult.OK)
00200             {
00201                 filename = openFileDialog.FileName;
00202                 try
00203                 {
00204                     loadPlugin(filename);
00205                 }
00206                 catch (Exception ex)
00207                 {
00208                     MessageBox.Show("Error reading ESP file: (" +
00209                     ex.Message + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
00210                     return;
00211                 }
00212             }
00213         }
00214 
00215         private void loadToolStripMenuItem_Click(object sender, EventArgs e)
00216         {
00217             string filename;
00218 
00219             openCSVFileDialog.Title = "Load work from CSV file";
00220             openCSVFileDialog.InitialDirectory = Application.StartupPath + "\\extra";
00221             openCSVFileDialog.Filter = "CSV files (*.csv)|*.csv";
00222             openCSVFileDialog.FilterIndex = 0;
00223             openCSVFileDialog.FileName = "";
00224 
00225             if (openFileDialog.ShowDialog() == DialogResult.OK)
00226             {
00227                 filename = openFileDialog.FileName;
00228                 try
00229                 {
00230                     
00231                 }
00232                 catch (Exception ex)
00233                 {
00234                     MessageBox.Show("Error reading CSV file: (" +
00235                     ex.Message + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
00236                     return;
00237                 }
00238             }
00239         }
00240 
00241         private void saveToolStripMenuItem_Click(object sender, System.EventArgs e)
00242         {
00243             if (MessageBox.Show("Overwritte current ESP ?",
00244                             "WARNING",
00245                             MessageBoxButtons.YesNo,
00246                             MessageBoxIcon.Warning) == DialogResult.Yes)
00247             {
00248                 MessageBox.Show("Overwritting in progress...",
00249                                 "INFO",
00250                                 MessageBoxButtons.OK,
00251                                 MessageBoxIcon.Information);
00252                 return;
00253             }
00254             else
00255             {
00256                 return;
00257             }
00258 
00259         }
00260 
00261         private void saveAsToolStripMenuItem_Click(object sender, System.EventArgs e)
00262         {
00263             saveFileDialog.Filter = "ESP files (*.esp)|*.esp";
00264             saveFileDialog.FilterIndex = 0;
00265             saveFileDialog.FileName = "";
00266             if (saveFileDialog.ShowDialog() == DialogResult.OK)
00267             {
00268                 string filename = saveFileDialog.FileName;
00269                 StreamWriter file = null;
00270                 try
00271                 {
00272                     file = new StreamWriter(filename);
00273                     // write operation
00274                     file.Write("TEST");
00275                 }
00276                 catch (Exception ex)
00277                 {
00278                     MessageBox.Show("Error writing ESP file: (" +
00279                     ex.Message + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
00280                     return;
00281                 }
00282                 finally
00283                 {
00284                     try { file.Close(); }
00285                     catch (Exception) { }
00286                 }
00287             }
00288         }
00289 
00290         private void saveToolStripMenuItem1_Click(object sender, System.EventArgs e)
00291         {
00292             saveCSVFileDialog.Title = "Save work as CSV file";
00293             saveCSVFileDialog.Filter = "CSV files (*.csv)|*.csv";
00294             saveCSVFileDialog.FilterIndex = 0;
00295             saveCSVFileDialog.FileName = "";
00296             saveCSVFileDialog.InitialDirectory = Application.StartupPath + "\\extra";
00297             if (saveCSVFileDialog.ShowDialog() == DialogResult.OK)
00298             {
00299                 string filename = saveCSVFileDialog.FileName;
00300                 StreamWriter file = null;
00301                 try
00302                 {
00303                     file = new StreamWriter(filename);
00304                     // write operation
00305                     file.Write("TEST");
00306                 }
00307                 catch (Exception ex)
00308                 {
00309                     MessageBox.Show("Error writing CSV file: (" +
00310                     ex.Message + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
00311                     return;
00312                 }
00313                 finally
00314                 {
00315                     try { file.Close(); }
00316                     catch (Exception) { }
00317                 }
00318             }
00319         }
00320 
00321         private void closeToolStripMenuItem_Click(object sender, System.EventArgs e)
00322         {
00323             // delete all lines fromm all tabs
00324             //Clipboard = null;
00325             //ClipboardNode = null;
00326             //GC.Collect();
00327         }
00328 
00329         private void dbToolStripMenuItem_Click(object sender, System.EventArgs e)
00330         {
00331             // retrieve oblivion.esm from registry
00332             // load and parse oblivion.esm
00333             MessageBox.Show("Any existing data file will be overwritten",
00334                             "WARNING",
00335                             MessageBoxButtons.OK,
00336                             MessageBoxIcon.Warning);
00337             // populate data directory with files "XXXX.cvs" where XXXX stands for WEAP, AMMO, ...
00338             //foreach (cell)
00339             //{
00340             //}
00341         }
00342 
00343         private void exitToolStripMenuItem_Click(object sender, System.EventArgs e)
00344         {
00345             // confirm quit ?
00346             if (MessageBox.Show("Really quit ?\nAll unsaved data will be lost !",
00347                                 "Warning",
00348                                 MessageBoxButtons.YesNo,
00349                                 MessageBoxIcon.Warning) == DialogResult.Yes)
00350             {
00351                 this.Close();
00352             };
00353         }
00354 
00355         private void aboutToolStripMenuItem_Click(object sender, System.EventArgs e)
00356         {
00357             aboutBox myAboutBox = new aboutBox();
00358             myAboutBox.ShowDialog(this);
00359             myAboutBox.Dispose();
00360         }
00361 
00362         private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
00363         {
00364 
00365         }
00366     }
00367 }

Generated on Fri Jun 23 21:50:04 2006 for OblivionModTranslator by  doxygen 1.4.6-NO