/* * L9CutForm.cs - Dialog frontend for the L9cut utility. * * Copyright (C) 2004 - 2011 Andreas Scherrer * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. */ using System; using System.IO; using System.Drawing; using System.Windows.Forms; namespace Level9 { /// /// Dialog frontend for the L9cut utility. /// public partial class L9CutForm : Form { // -- Constants ------------------------------------------------------ /// /// The default L9Cut output file. /// const string DEFAULT_OUTPUT_FILE = "\\output.dat"; // -- Attributes ----------------------------------------------------- /// /// This property indicates whether the selected arguments are valid /// for an execution of L9cut. /// bool checkExecute = true; // -- Constructors --------------------------------------------------- /// /// Initializes a new instance of the L9CutForm class. /// public L9CutForm() { InitializeComponent(); // // Set button and label images // buttonExecute.Image = Images.Get(Images.Stock.Execute_16x16); buttonClose.Image = Images.Get(Images.Stock.Close_16x16); labelL9Cut.Image = Images.Get(Images.Stock.L9cut_48x48); } // -- Event handling ------------------------------------------------- /// /// Invoked when the input file changes. /// /// the object that originated the event /// an EventArgs that contains the event data void TextBoxInputTextChanged(object sender, EventArgs e) { if (checkExecute) { CheckExecuteExtract(); } } /// /// Invoked when the output file changes. /// /// the object that originated the event /// an EventArgs that contains the event data void TextBoxOutputTextChanged(object sender, EventArgs e) { if (checkExecute) { CheckExecuteExtract(); } } /// /// Invoked when the 'Detected datafiles' button changes its state. /// /// the object that originated the event /// an EventArgs that contains the event data void RadioButtonDetectedDatafilesCheckedChanged(object sender, EventArgs e) { if (checkExecute) { CheckExecuteLists(); } } /// /// Invoked when the 'Missing datafiles' button changes its state. /// /// the object that originated the event /// an EventArgs that contains the event data void RadioButtonMissingDatafilesCheckedChanged(object sender, EventArgs e) { if (checkExecute) { CheckExecuteLists(); } } /// /// Invoked when the 'Missing patches' button changes its state. /// /// the object that originated the event /// an EventArgs that contains the event data void RadioButtonMissingPatchesCheckedChanged(object sender, EventArgs e) { if (checkExecute) { CheckExecuteLists(); } } /// /// Invoked when the 'Execute' button has been pressed. /// /// the object that originated the event /// an EventArgs that contains the event data void ButtonExecuteClick(object sender, EventArgs e) { if (radioButtonDetectedDatafiles.Checked) { richTextBoxOutput.Text = L9Cut.GetDetectedDatafiles(); } else if (radioButtonMissingDatafiles.Checked) { richTextBoxOutput.Text = L9Cut.GetMissingDatafiles(); } else if (radioButtonMissingPatches.Checked) { richTextBoxOutput.Text = L9Cut.GetMissingPatches(); } else { richTextBoxOutput.Text = L9Cut.ExtractDatafile( textBoxInput.Text, textBoxOutput.Text, checkBoxProtection.Checked ? true : false); } if (richTextBoxOutput.Text != null) { richTextBoxOutput.SelectionStart = 0; richTextBoxOutput.ScrollToCaret(); } } /// /// Invoked when the 'Close' button has been pressed. /// /// the object that originated the event /// an EventArgs that contains the event data void ButtonCloseClick(object sender, EventArgs e) { this.DialogResult = DialogResult.OK; this.Close(); } /// /// Invoked when the 'Browse' button has been pressed (input file). /// /// the object that originated the event /// an EventArgs that contains the event data void ButtonBrowseInputClick(object sender, EventArgs e) { string filename = FileUtils.OFDDataFiles(labelInputFile.Text); if (filename == null) { return; } textBoxInput.Text = filename; textBoxInput.SelectionStart = textBoxInput.TextLength - 1; textBoxOutput.Text = Path.GetDirectoryName(filename) + DEFAULT_OUTPUT_FILE; textBoxOutput.SelectionStart = textBoxOutput.TextLength - 1; } /// /// Invoked when the 'Browse' button has been pressed (output file). /// /// the object that originated the event /// event arguments void ButtonBrowseOutputClick(object sender, EventArgs e) { string filename = FileUtils.SFDDataFiles(labelOutputFile.Text); if (filename == null) { return; } textBoxOutput.Text = filename; textBoxOutput.SelectionStart = textBoxOutput.TextLength - 1; } // -- Methods -------------------------------------------------------- /// /// Checks the selected arguments if the detected datafiles or the /// missing datafiles or the missing patches are to be displayed. /// void CheckExecuteLists() { checkExecute = false; if (radioButtonDetectedDatafiles.Checked || radioButtonMissingDatafiles.Checked || radioButtonMissingPatches.Checked) { textBoxInput.Clear(); textBoxOutput.Clear(); checkBoxProtection.Checked = false; buttonExecute.Enabled = true; } else { buttonExecute.Enabled = false; } checkExecute = true; } /// /// Checks the selected arguments if a datafile is to be extracted. /// void CheckExecuteExtract() { checkExecute = false; radioButtonDetectedDatafiles.Checked = false; radioButtonMissingDatafiles.Checked = false; radioButtonMissingPatches.Checked = false; if (textBoxInput.TextLength > 0 && textBoxOutput.TextLength > 0) { buttonExecute.Enabled = true; } else { buttonExecute.Enabled = false; } checkExecute = true; } } }