using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Xml;
using System.Configuration;
using System.Collections.Specialized;
using System.Globalization;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private string sfp;
private string[] args = Environment.GetCommandLineArgs();
private IniFile ini;
public Form1()
{
InitializeComponent();
ini = new IniFile("lpm.ini");
string df = ini.IniReadValue("Main", "DefaultFolder");
string au = ini.IniReadValue("Main", "Author");
Debug.WriteLine(df);
if (df!=null && df!="")
{
textBox1.Text = df;
folderBrowserDialog1.SelectedPath = (df);
}
else
{
folderBrowserDialog1.SelectedPath = (Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\The Lord of the Rings Online\\Plugins\\");
}
if (au != "")
{
textBox4.Text = au;
}
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked == false)
{
textBox7.Enabled = false;
}
else
{
textBox7.Enabled = true;
}
}
private void button1_Click(object sender, EventArgs e)
{
DialogResult result = folderBrowserDialog1.ShowDialog(); // Show the dialog and get result.
if (result == DialogResult.OK)
{
textBox1.Text = folderBrowserDialog1.SelectedPath;
this.sfp = folderBrowserDialog1.SelectedPath;
}
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
textBox3.Text = textBox2.Text;
textBox7.Text = textBox2.Text;
}
private void HandleKeyPress( object sender, KeyPressEventArgs e )
{
if ( ( char.IsWhiteSpace( e.KeyChar ) ) )
e.Handled = true;
}
public void doPlugin(string path, string folder, string name, string author, string version, string ep, bool doapt, string apt, bool doinit, bool doRes, bool doOpen)
{
string totalpath = path + "\\"+ folder;
if (!Directory.Exists(totalpath))
{
Directory.CreateDirectory(totalpath);
}
ini.IniWriteValue("Main", "DefaultFolder", path);
ini.IniWriteValue("Main", "Author", author);
//do plugin file
XmlDocument plugdoc = new XmlDocument();
string[] pArray = path.Split('\\');
XmlNode plugNode = plugdoc.CreateNode(XmlNodeType.XmlDeclaration, "","");
plugdoc.AppendChild(plugNode);
XmlElement plugElem = plugdoc.CreateElement("", "Plugin", "");
XmlElement infoElem = plugdoc.CreateElement("", "Information", "");
plugElem.AppendChild(infoElem);
XmlElement nameElem = plugdoc.CreateElement("", "Name", "");
XmlText txtVal = plugdoc.CreateTextNode(name);
nameElem.AppendChild(txtVal);
infoElem.AppendChild(nameElem);
XmlElement authorElem = plugdoc.CreateElement("", "Author", "");
txtVal = plugdoc.CreateTextNode(author);
authorElem.AppendChild(txtVal);
infoElem.AppendChild(authorElem);
XmlElement verElem = plugdoc.CreateElement("", "Version", "");
txtVal = plugdoc.CreateTextNode(version);
verElem.AppendChild(txtVal);
infoElem.AppendChild(verElem);
XmlElement packageElem = plugdoc.CreateElement("", "Package", "");
txtVal = plugdoc.CreateTextNode(pArray[pArray.Length-1]+"."+folder+"."+ep);
packageElem.AppendChild(txtVal);
plugElem.AppendChild(packageElem);
if (doapt == true)
{
XmlElement configElem = plugdoc.CreateElement("", "Configuration", "");
configElem.SetAttribute("Apartment", apt);
plugElem.AppendChild(configElem);
}
plugdoc.AppendChild(plugElem);
plugdoc.Save(path + "\\"+ name + ".plugin");
//do ep file
TextWriter tw = new StreamWriter(totalpath + "\\"+ep + ".lua");
tw.WriteLine("import \"Turbine\";");
tw.WriteLine("import \"Turbine.UI\";");
tw.WriteLine("import \"Turbine.UI.Lotro\";");
tw.WriteLine("import \"Turbine.UI.Gameplay\";");
tw.WriteLine("");
tw.WriteLine("--Plugin Starts Here");
tw.Close();
//if init
if (doinit == true)
{
tw = new StreamWriter(totalpath + "\\__init__.lua");
tw.Close();
}
if (doRes == true)
{
Directory.CreateDirectory(totalpath+"\\Resources");
}
if (doOpen == true)
{
if (doinit == true)
{
Process.Start(totalpath + "\\__init__.lua");
}
Process.Start(totalpath + "\\" + ep + ".lua");
}
Environment.Exit(0);
}
private void button2_Click(object sender, EventArgs e)
{
//verify that all necessary values are filled in:
string errorString="";
string titleString="";
int doError = 0;
string ver = textBox2.Text;
if (textBox1.Text == "")
{
titleString = "No Base Path Given";
errorString = "You must select a base path (eg: Documents/The Lord of the Rings Online/plugins/(Author Folder).";
doError = 1;
}
if (textBox2.Text == "")
{
titleString = "No Plugin Folder Given";
errorString = "You must tell me where you want to put this plugin.";
doError = 1;
}
if (string.Equals("InYourAss",textBox2.Text,StringComparison.CurrentCultureIgnoreCase))
{
titleString = "Totally Didn't See That One Coming.";
errorString = "Well, aren't you the funny one? Very well, I'll put this "+textBox2.Text+".";
doError = 2;
}
if (textBox3.Text == "")
{
titleString = "No Plugin Name Given";
errorString = "Although I would be happy to name your plugin for you, it's probably better that I cannot. Please provide your own plugin name.";
doError = 1;
}
if (textBox4.Text == "")
{
titleString = "No Author Name Given";
errorString = "I realize you may be modest, but you need to provide an author name";
doError = 1;
}
if (textBox5.Text == "")
{
textBox5.Text = "1.0";
}
if (textBox6.Text == "")
{
textBox6.Text = "Main";
}
if (checkBox1.Checked == true && textBox7.Text == "")
{
titleString = "No Apartment Given";
errorString = "If you didn't want to provide an apartment, why did you check the box?";
doError = 1;
}
if (doError == 0)
{
doPlugin(textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text, textBox5.Text, textBox6.Text, checkBox1.Checked, textBox7.Text, checkBox2.Checked,checkBox3.Checked,checkBox4.Checked);
}
else if (doError == 1)
{
MessageBox.Show(errorString, titleString, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
MessageBox.Show(errorString, titleString, MessageBoxButtons.OK, MessageBoxIcon.Information);
//user is being a smartass, lets do it.
doPlugin(textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text, textBox5.Text, textBox6.Text, checkBox1.Checked, textBox7.Text, checkBox2.Checked, checkBox3.Checked, checkBox4.Checked);
}
}
}
}