Skip to content

Commit

Permalink
Merge pull request #4 from Schokobecher/master
Browse files Browse the repository at this point in the history
Exception Catching + UI Redesign
  • Loading branch information
EvilInsultGenerator authored Nov 7, 2016
2 parents f13f14f + 177af0b commit 7e3b469
Show file tree
Hide file tree
Showing 24 changed files with 119 additions and 580 deletions.
4 changes: 3 additions & 1 deletion EvilInsultGenerator/EvilInsultGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="App.config">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5.2">
Expand Down
162 changes: 76 additions & 86 deletions EvilInsultGenerator/Form1.Designer.cs

Large diffs are not rendered by default.

83 changes: 32 additions & 51 deletions EvilInsultGenerator/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,18 @@ public partial class MainForm : Form
{
public MainForm()
{

InitializeComponent();
// Set the default selection to the 5th entry ('en' at the moment)
combLang.SelectedIndex = 4;
rtxtInsult.SelectionAlignment = HorizontalAlignment.Center;
}

// Get %TEMP% path of current user
public string GetTempPath()
{
string path = Environment.GetEnvironmentVariable("TEMP");
if (!path.EndsWith("\\")) path += "\\";
return path;
}

// Logging Setup
public void LogMessageToFile(string msg)
{
Expand All @@ -47,13 +44,11 @@ public void LogMessageToFile(string msg)


}

// Send our Request to the server
private string SendRequest(string url)
{
try
{

using (WebClient client = new WebClient())
{
// Fixed funky chingchang yellow nigger signs
Expand All @@ -69,7 +64,6 @@ private string SendRequest(string url)
return null;
}
}

// On Form load
private void MainForm_Load(object sender, EventArgs e)
{
Expand All @@ -79,71 +73,48 @@ private void MainForm_Load(object sender, EventArgs e)
// and then delete it.
File.Delete(GetTempPath() + "EIG_Desktop.log");
LogMessageToFile("Info: Found old log file - Removed");

}
LogMessageToFile("Info: EIG started");
}

// Generate Insult Button
// The User wants to generate some insults!
private void btnGenerate_Click(object sender, EventArgs e)
{
// Convert selection to a string
string lang = combLang.SelectedItem.ToString();

//JSON.Net
// string response = SendRequest("https://evilinsult.com/generate_insult.php?type=json&lang=" + lang);

// Send Request to server and save the response as a string
string response = SendRequest("https://evilinsult.com/generate_insult.php?type=xml&lang=" + lang);

// Something broke the language selection? No worries. Default is english.
if (string.IsNullOrWhiteSpace(lang))
{
lang = "en";
LogMessageToFile("Error: Language selection failed");

}
if (response != null)
{
var xmlDoc = new XmlDocument();
xmlDoc.LoadXml(response);
string insult = xmlDoc.DocumentElement.SelectSingleNode("/insult_info/insult").InnerText;

// Who needs JSON when you have XML!
// JObject ob = JObject.Parse(response);
// string insult = (string)ob["insult"];

// Set the Output
rtxtInsult.Text = insult;

LogMessageToFile("Info: Insult: --- " + insult + " --- in language: " + lang + " generated");
try
{
var xmlDoc = new XmlDocument();
xmlDoc.LoadXml(response);
string insult = xmlDoc.DocumentElement.SelectSingleNode("/insult_info/insult").InnerText;
// Set the Output
insult = WebUtility.HtmlDecode(insult);
rtxtInsult.Text = insult;
LogMessageToFile("Info: Insult: --- " + insult + " --- in language: " + lang + " generated");
}
catch (XmlException ex)
{
//this report had an error loading!
LogMessageToFile(ex.Message);
rtxtInsult.Text = "****** **** *** ********";
}
}
else
{
rtxtInsult.Text = "The Server did not provide any data";
LogMessageToFile("Error: The server did not respond with data");
}
}

// Copy to Clipboard Button
private void btnCopy_Click(object sender, EventArgs e)
{
// Hidden Exception Handling - nothing to copy? Just use it as Easter Egg!
if (string.IsNullOrWhiteSpace(rtxtInsult.Text))
{
Clipboard.SetText("3.141592653589793238462643383279502884197169 39937510582097494459230781640628620899862803 48253421170679821480865132823066470938446095 50582231725359408128481117450284102701938521 10555964462294895493038196442881097566593344 61284756482337867831652712019091456485669234 60348610454326648213393607260249141273724587 00660631558817488152092096282925409171536436 78925903600113305305488204665213841469519415 11609433057270365759591953092186117381932611 79310511854807446237996274956735188575272489 12279381830119491298336733624406566430860213 94946395224737190702179860943702770539217176 29317675238467481846766940513200056812714526 35608277857713427577896091736371787214684409 01224953430146549585371050792279689258923542 01995611212902196086403441815981362977477130 99605187072113499999983729780499510597317328 16096318595024459455346908302642522308253344 68503526193118817101000313783875288658753320 83814206171776691473035982534904287554687311 59562863882353787593751957781857780532171226 806613001927876611195909216420198");
LogMessageToFile("Info: Easter Egg found");

}
else
{
Clipboard.SetText(rtxtInsult.Text);
LogMessageToFile("Info: Insult copied to clipboard");

}
}

// ToolStrip Stuff

// "Website" clicked
Expand All @@ -166,7 +137,6 @@ private void gitHubToolStripMenuItem_Click(object sender, EventArgs e)
{
Process.Start("https://github.com/EvilInsultGenerator");
LogMessageToFile("Info: 'GitHub' clicked");

}
// "Propasal" clicked
private void proposalToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -194,7 +164,6 @@ private void legalToolStripMenuItem_Click(object sender, EventArgs e)
{
Process.Start("https://evilinsult.com/legal.html");
LogMessageToFile("Info: 'Legal' clicked");

}
// "Facebook" clicked
private void facebookToolStripMenuItem_Click(object sender, EventArgs e)
Expand All @@ -208,9 +177,7 @@ private void twitterToolStripMenuItem_Click(object sender, EventArgs e)
{
Process.Start("https://twitter.com/__E__I__G__");
LogMessageToFile("Info: 'Twitter' clicked");

}

// "Check Updates" clicked
// Start Update Routine
private void updateCheckToolStripMenuItem_Click(object sender, EventArgs e)
Expand All @@ -227,7 +194,7 @@ private void updateCheckToolStripMenuItem_Click(object sender, EventArgs e)
reader = new XmlTextReader(xmlUrl);
reader.MoveToContent();
string elementName = "";
if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "appinfo"))
if (reader.NodeType == XmlNodeType.Element && reader.Name == "appinfo")
{
while (reader.Read())
{
Expand Down Expand Up @@ -283,7 +250,6 @@ private void updateCheckToolStripMenuItem_Click(object sender, EventArgs e)
}
else
{
;
}
}
else
Expand All @@ -292,5 +258,20 @@ private void updateCheckToolStripMenuItem_Click(object sender, EventArgs e)
LogMessageToFile("Info: No Update was found.");
}
}
// Copy to Clipboard Button
private void btnCopy_Click(object sender, EventArgs e)
{
// Hidden Exception Handling - nothing to copy? Just use it as Easter Egg!
if (string.IsNullOrWhiteSpace(rtxtInsult.Text))
{
Clipboard.SetText("3.141592653589793238462643383279502884197169 39937510582097494459230781640628620899862803 48253421170679821480865132823066470938446095 50582231725359408128481117450284102701938521 10555964462294895493038196442881097566593344 61284756482337867831652712019091456485669234 60348610454326648213393607260249141273724587 00660631558817488152092096282925409171536436 78925903600113305305488204665213841469519415 11609433057270365759591953092186117381932611 79310511854807446237996274956735188575272489 12279381830119491298336733624406566430860213 94946395224737190702179860943702770539217176 29317675238467481846766940513200056812714526 35608277857713427577896091736371787214684409 01224953430146549585371050792279689258923542 01995611212902196086403441815981362977477130 99605187072113499999983729780499510597317328 16096318595024459455346908302642522308253344 68503526193118817101000313783875288658753320 83814206171776691473035982534904287554687311 59562863882353787593751957781857780532171226 806613001927876611195909216420198");
LogMessageToFile("Info: Easter Egg found");
}
else
{
Clipboard.SetText(rtxtInsult.Text);
LogMessageToFile("Info: Insult copied to clipboard");
}
}
}
}
9 changes: 3 additions & 6 deletions EvilInsultGenerator/Form1.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,11 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>132, 17</value>
<metadata name="rtxtInsult.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>287, 17</value>
</metadata>
<metadata name="$this.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
<value>11, 6</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
Expand Down
2 changes: 1 addition & 1 deletion EvilInsultGenerator/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyVersion("1.0.2.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: NeutralResourcesLanguage("en-US")]

21 changes: 0 additions & 21 deletions EvilInsultGenerator/bin/Debug/EvilInsultGenerator.application

This file was deleted.

6 changes: 0 additions & 6 deletions EvilInsultGenerator/bin/Debug/EvilInsultGenerator.exe.config

This file was deleted.

75 changes: 0 additions & 75 deletions EvilInsultGenerator/bin/Debug/EvilInsultGenerator.exe.manifest

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 7e3b469

Please sign in to comment.