2014-12-29 23:44:39 +00:00
using System ;
using System.Collections.Generic ;
using System.ComponentModel ;
using System.Data ;
using System.Drawing ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
using System.Windows.Forms ;
namespace Pithos
{
public partial class mainWindow : Form
{
private decode decoder = new decode ( ) ;
public bool adminMode = false ;
public mainWindow ( )
{
InitializeComponent ( ) ;
}
public void display ( string text , Color colour ) {
2015-01-04 22:25:01 +00:00
/ * Message Color Codes :
2015-01-10 23:17:04 +00:00
* Light Green : User Messages ( Mainly Echo )
2015-01-04 22:25:01 +00:00
* Orange : Admin Commands
* Black : General text / Date
* Red : Error Messages
* Blue : Messages from Program
* /
2014-12-29 23:44:39 +00:00
if ( output . TextLength ! = 0 ) { output . AppendText ( "\n[" + DateTime . Now . ToString ( "hh:mm:ss" ) + "] " ) ; } //so that the first line isnt a new line for no reason. (although its extra code)
else { output . AppendText ( "[" + DateTime . Now . ToString ( "hh:mm:ss" ) + "] " ) ; }
int length = output . TextLength ;
2015-01-04 22:25:01 +00:00
text = decoder . injectVariables ( text ) ;
2014-12-29 23:44:39 +00:00
output . AppendText ( text ) ;
output . SelectionStart = length ;
output . SelectionLength = text . Length ;
output . SelectionColor = colour ;
output . SelectionStart = length + text . Length ;
2015-01-10 23:17:04 +00:00
output . SelectionColor = Color . White ;
2014-12-29 23:44:39 +00:00
}
private void mainWindow_Load ( object sender , EventArgs e )
{
2015-01-10 23:17:04 +00:00
display ( "Currently Logged in as: " + Environment . UserDomainName + "\\" + Environment . UserName , Color . White ) ;
2014-12-29 23:44:39 +00:00
}
2015-01-10 23:17:04 +00:00
private void executeButton_Click ( object sender , EventArgs e ) {
bool valid = false ;
2014-12-29 23:44:39 +00:00
string input = inputBox . Text ;
2015-01-04 22:25:01 +00:00
if ( input = = "" ) { display ( "Error: No command given." , Color . Red ) ; return ; } //if its empty, dont bother decoding
2014-12-29 23:44:39 +00:00
string initChar = input . Substring ( 0 , 1 ) ; //gets the first character in the input
string [ ] args = input . Substring ( 1 ) . Split ( ' ' ) ; //splits the input by spaces, and removes init character
2015-01-10 23:17:04 +00:00
inputBox . Text = "" ; //clear the contents after execution
try
2014-12-29 23:44:39 +00:00
{
2015-01-10 23:17:04 +00:00
switch ( initChar )
{
case "/" :
if ( args [ 0 ] = = "exec" ) //runs a pithos program
{
valid = pithosPrograms . decodeInput ( input ) ;
return ;
}
else if ( args [ 0 ] = = "start" ) //runs a program (using cmd)
{
2014-12-29 23:44:39 +00:00
2015-01-10 23:17:04 +00:00
}
else { valid = decoder . command ( input ) ; } //decode other commands
break ;
case "¦" : //admin commands
if ( ! adminMode ) {
display ( "Access Denied: Admin commands are currently disabled." , Color . Orange ) ;
return ;
}
valid = privateFunctions . adminCommands ( input ) ;
break ;
default :
break ;
}
} catch {
displayError ( input ) ;
return ;
2014-12-29 23:44:39 +00:00
}
2015-01-10 23:17:04 +00:00
if ( ! valid ) { displayError ( input ) ; }
}
private void displayError ( string input )
{
display ( "Error: Command '" + input + "' is not recognised." , Color . Red ) ;
}
private void mainWindow_FormClosing ( object sender , FormClosingEventArgs e )
{
Application . Exit ( ) ;
2014-12-29 23:44:39 +00:00
}
}
}