public void ShxmlException(XmlNode token) { XmlAttributeCollection attributes = token.Attributes; int?id = null; foreach (XmlAttribute attribute in attributes) { switch (attribute.Name) { case "ID": case "Id": case "id": try { Convert.ToInt32(attribute.Value); } catch (FormatException) { ShellCore.ElmThrowException(52); } continue; } } if (id == null) { ShellCore.ElmThrowException(53); } }
public string ShxmlRunFunction(XmlNode node) { XmlAttributeCollection attributes = node.Attributes; foreach (XmlAttribute attribute in attributes) { switch (attribute.Name) { case "path": path = attribute.Value; return(path); } } if (path == null) { ShellCore.ElmThrowException(26); return(Convert.ToString("27")); // this code never runs so we don't have a problem!!!! yay!!!! } return(""); }
public void XmlParseScriptNodes(XmlNodeList children) { foreach (XmlNode token in children) { switch (token.Name) { default: ShellCore.ElmThrowException(0); return; case "#document": continue; case "#comment": continue; case "shellxml": case "Shellxml": case "shellXML": case "ShellXML": ShellCore.ElmThrowException(3); return; case "var": case "Var": ShxmlDeclareVariable(token); continue; case "operation": case "Operation": case "op": case "Op": ShxmlPerformOperation(token); continue; case "input": case "Input": ShxmlConsoleInput(token); continue; case "output": case "Output": ShxmlConsoleOutput(token); continue; case "function": case "Function": string fpath = ShxmlRunFunction(token); XmlParseScript(fpath, 1); continue; case "exception": case "Exception": ShxmlException(token); continue; case "if": case "If": ShxmlHandleIfStatement(token); continue; /* Coming Soon * case "Else":*/ } } }
public Module GetModule(string uri, string path) { Console.WriteLine($"Installing module from the Internet at {uri}..."); // displays a message ShellCore.DownloadFileEx(uri, path); ShellCore.ExtractZipFile("Module.zip", "Modules"); XmlDocument ModuleXml = ShellCore.XmlOpenFile("Modules/Module.xml"); Console.WriteLine($"Reading Module XML file..."); XmlNode moduleRoot = ModuleXml.FirstChild; string Name = moduleRoot.Name; if (Name == "#comment") { while (Name == "#comment") { moduleRoot = moduleRoot.NextSibling; // get the next node. Name = moduleRoot.Name; // get the next node until we have an actual node. } } if (Name != "Module") { ShellCore.ElmThrowException(55); } Module Module = new Module(); foreach (XmlNode attribute in moduleRoot.ChildNodes) { switch (attribute.Name) { case "Name": // module name Module.Name = attribute.InnerText; continue; case "Author": // module author Module.Author = attribute.InnerText; continue; case "Version": // module version Module.Version = attribute.InnerText; continue; case "Copyright": // module copyright Module.Copyright = attribute.InnerText; continue; case "Website": // module website Module.Website = attribute.InnerText; continue; case "Dll": // module dll Module.Dll = attribute.InnerText; continue; case "Extends": // which dll does this module extend string trimmedExtends = attribute.InnerText.Trim(); switch (trimmedExtends) { case "shlcore": case "Shlcore": case "shlCore": case "ShlCore": case "shellcore": case "Shellcore": case "shellCore": case "ShellCore": Module.Extends = Extends.ShellCore; continue; case "shlui": case "Shlui": case "shlUi": case "ShlUi": case "ShlUI": case "shellui": case "ShellUi": case "shellUI": case "ShellUI": case "shellUi": case "Shellui": case "shelluI": Module.Extends = Extends.ShellUI; continue; default: ShellCore.ElmThrowException(57); return(Module); } } } return(Module); }
public void ShxmlConsoleOutput(XmlNode token) // pass { string text = ""; StringBuilder buildit = new StringBuilder(); // the final string. string[] text_s = null; int posx = -0xd15ea5e; int posy = -0xd15ea5e; XmlAttributeCollection attributes = token.Attributes; foreach (XmlAttribute attribute in attributes) { // check for what we want switch (attribute.Name) { case "text": text = attribute.Value; int count = 0; text_s = text.Split('+'); foreach (string text_t in text_s) { foreach (ShxmlVariable xvar in Varlist) { if (text_t == xvar.Name) { if (text_s.Count() - count > 0) { switch (xvar.Type) { // convert to string and add case 0: text_s[count] = Convert.ToString(xvar.varint); continue; case 1: text_s[count] = xvar.varstring; continue; case 2: text_s[count] = Convert.ToString(xvar.varchar); continue; case 3: text_s[count] = Convert.ToString(xvar.vardouble); continue; case 4: text_s[count] = Convert.ToString(xvar.varfloat); continue; case 5: text_s[count] = Convert.ToString(xvar.varbool); continue; } } } } count++; } foreach (string text_t in text_s) { buildit.Append(text_t); } continue; case "posx": try { if (posx == -0xd15ea5e) { posx = Convert.ToInt32(attribute.Value); // x position (in char cells from 0) } } catch (FormatException) { ShellCore.ElmThrowException(16); } if (posx == -0xd15ea5e) { ShellCore.ElmThrowException(18); } continue; case "posy": try { if (posy == -0xd15ea5e) { posy = Convert.ToInt32(attribute.Value); // y position (in char cells from 0) } } catch (FormatException) { ShellCore.ElmThrowException(17); } if (posy == -0xd15ea5e) { ShellCore.ElmThrowException(18); } continue; default: ShellCore.ElmThrowException(19); continue; } } if (posx != -0xd15ea5e & posy != -0xd15ea5e) { UiSetCursorPosition(posx, posy); // yeah } //todo: + to separate variables in <Input>?? // Should've used delegates here. Oh well. Console.WriteLine(buildit); // since we're not done... return; }
public void ShxmlHandleIfStatement(XmlNode token) // v0.5.6+ (actually functional in v0.6.0)+ { XmlAttributeCollection attributes = token.Attributes; // no attributes but yeahhhhhhhhhhhhhhhhhhhhhhhhh if (!token.HasChildNodes) { ShellCore.ElmThrowException(33); //Empty if statement } int count = 0; double result = 0; string x = null; ShxmlVariable svar = new ShxmlVariable(); OperandList = new List <string>(); OpList = new List <char>(); foreach (XmlAttribute attribute in attributes) { switch (attribute.Name) { case "condition": case "Condition": case "cond": case "Cond": x = attribute.Value; char[] thebits = attribute.Value.ToCharArray(); // This works because the first operand is after the first part of the string. Thus we get the correct operands. foreach (char bit in thebits) { switch (bit) { case '=': case '!': OpList.Add(bit); continue; } count++; } continue; default: ShellCore.ElmThrowException(19); return; } } if (OpList.Count == 0) { ShellCore.ElmThrowException(41); } char[] OperatorListA = OpList.ToArray(); // convert to array cleancut = x.Split(OperatorListA); count = 0; // reset the count foreach (string bit2 in cleancut) { foreach (ShxmlVariable shvar in Varlist) { if (cleancut[count] == shvar.Name) { if (shvar.Type == 1) { ShellCore.ElmThrowException(14); // Can't do stuff to strings...yet. } else if (shvar.Type == 5) { ShellCore.ElmThrowException(15); // Can't add booleans. } else { OperandList.Add(Convert.ToString(shvar.vardouble)); // convert it to string count++; continue; } } } OperandList.Add(bit2); count++; } List <ShxmlVariable> vars = new List <ShxmlVariable>(); List <double> bit3 = new List <double>(); List <double> bit3c = new List <double>(); count = 0; //set count back to 0 foreach (string bit2 in cleancut) { string bit2a = bit2.Trim(); int isVar = 0; foreach (ShxmlVariable sxvar in Varlist) { if (sxvar.Name == bit2a & bit2a != svar.Name) { isVar = 1; vars.Add(sxvar); bit3.Add(sxvar.vardouble); } } if (isVar == 0) { try { if (bit2a != svar.Name) { double bit2b = Convert.ToDouble(bit2a); bit3.Add(bit2b); } } catch (FormatException) { // error 12 removed from here due to changes in how this works in Shell Development Release } } isVar = 0; } // so it's easier double[] bit3b = bit3.ToArray(); ShxmlVariable[] varsb = vars.ToArray(); // local list converted to an array. // jesus f*****g christ this code is getting worse! foreach (ShxmlVariable varsb2 in varsb) { bit3c.Add(varsb2.vardouble); } // this actually parses the stuff foreach (double bit3a in bit3b) { // This is awaiting changes to adding an overload in ShellCore to perform operations on a single int instead of a collection. switch (OpList[count]) { case '=': if (bit3a == bit3b[count + 1]) { XmlParseScriptNodes(token.ChildNodes); } continue; case '!': if (bit3a != bit3b[count + 1]) { XmlParseScriptNodes(token.ChildNodes); } continue; } count++; } count = 0; foreach (ShxmlVariable ShxVar in varsb) { if (OpList.Count - count > 1) { switch (OpList[count]) { case '=': if (result == bit3c[count]) { XmlParseScriptNodes(token.ChildNodes); return; } count++; continue; case '!': if (result == bit3c[count]) { XmlParseScriptNodes(token.ChildNodes); return; } count++; continue; } count++; } } count = 0; //return svar; return; }
public ShxmlVariable ShxmlEvaluateStatement(XmlNode token, int mode = 0) { int count = 0; double result = 0; XmlAttributeCollection attributes = token.Attributes; ShxmlVariable svar = new ShxmlVariable(); string x = null; OperandList = new List <string>(); OpList = new List <char>(); foreach (XmlAttribute attribute in attributes) { switch (attribute.Name) { case "op": case "Op": case "operation": case "Operation": x = attribute.Value; char[] thebits = attribute.Value.ToCharArray(); // This works because the first operand is after the first part of the string. Thus we get the correct operands. foreach (char bit in thebits) { switch (bit) { case '+': case '-': case '*': case '/': case '%': OpList.Add(bit); continue; } count++; } continue; case "var": case "Var": case "variable": case "Variable": svar.Name = attribute.Value; svar.Type = 3; // double by default continue; default: ShellCore.ElmThrowException(19); return(svar); } } if (svar.Name == null) { ShellCore.ElmThrowException(40); } if (OpList.Count == 0) { ShellCore.ElmThrowException(41); } char[] OperatorListA = OpList.ToArray(); // convert to array cleancut = x.Split(OperatorListA); count = 0; // reset the count foreach (string bit2 in cleancut) { foreach (ShxmlVariable shvar in Varlist) { if (cleancut[count] == shvar.Name) { if (shvar.Type == 1) { ShellCore.ElmThrowException(14); // Can't do stuff to strings...yet. } else if (shvar.Type == 5) { ShellCore.ElmThrowException(15); // Can't add booleans. } else { OperandList.Add(Convert.ToString(shvar.vardouble)); // convert it to string count++; continue; } } } OperandList.Add(bit2); count++; } List <ShxmlVariable> vars = new List <ShxmlVariable>(); List <double> bit3 = new List <double>(); List <double> bit3c = new List <double>(); count = 0; //set count back to 0 foreach (string bit2 in cleancut) { string bit2a = bit2.Trim(); int isVar = 0; foreach (ShxmlVariable sxvar in Varlist) { if (sxvar.Name == bit2a & bit2a != svar.Name) { isVar = 1; vars.Add(sxvar); bit3.Add(sxvar.vardouble); } } if (isVar == 0) { try { if (bit2a != svar.Name) { double bit2b = Convert.ToDouble(bit2a); bit3.Add(bit2b); } } catch (FormatException) { // error 12 removed from here due to changes in how this works in Shell Development Release } } isVar = 0; } // so it's easier double[] bit3b = bit3.ToArray(); ShxmlVariable[] varsb = vars.ToArray(); // local list converted to an array. // jesus f*****g christ this code is getting worse! foreach (ShxmlVariable varsb2 in varsb) { bit3c.Add(varsb2.vardouble); } // this actually parses the stuff foreach (double bit3a in bit3b) { // This is awaiting changes to adding an overload in ShellCore to perform operations on a single int instead of a collection. switch (OpList[count]) { case '+': result = bit3a + bit3b[count + 1]; continue; case '-': result = bit3a - bit3b[count + 1]; continue; case '*': result = bit3a * bit3b[count + 1]; continue; case '/': result = bit3a / bit3b[count + 1]; continue; case '%': result = bit3a % bit3b[count + 1]; continue; } count++; } count = 0; foreach (ShxmlVariable ShxVar in varsb) { if (OpList.Count - count > 1) { switch (OpList[count]) { case '+': result = result + bit3c[count]; count++; continue; case '-': result = result - bit3c[count]; count++; continue; case '*': result = result * bit3c[count]; count++; continue; case '/': result = result / bit3c[count]; count++; continue; case '%': result = result % bit3c[count]; count++; continue; } count++; } } count = 0; //update the main list svar.vardouble = result; return(svar); }
static void Main(string[] args) { ShellTest ShellTest = new ShellTest(); ShellCore ShellCore = new ShellCore(); ShellUI ShellUI = new ShellUI(); // initalize shellui List <double> arguments = new List <double> { 4, 3 }; // v5.5+ FileVersionInfo shellcore_ver = ShellCore.GetVersion(); if (shellcore_ver.ProductMajorPart < 8) // version check { ShellTest.SorryIncompatible(); } else if (shellcore_ver.ProductMajorPart < 8 & shellcore_ver.ProductBuildPart < 87) { ShellTest.SorryIncompatible(); } ShellCore.InitShellCore(); ShellCore.ElmInitExceptionManager(); Console.Title = "Shell Test Application"; Console.WriteLine("This is an automated testing application designed for testing Shell. This will bring up standard Windows dialogs and create registry keys to verify the functionality of the Shell DLLs. Press enter to continue."); Console.ReadKey(); // V2+, last modified v7.0 build 24 iirc double result = ShellCore.BaseMath(ShellCore.BaseMathOperation.Add, 1, arguments); double result2 = ShellCore.BaseMath(ShellCore.BaseMathOperation.Subtract, 1, arguments); double result3 = ShellCore.BaseMath(ShellCore.BaseMathOperation.Divide, 1, arguments); double result4 = ShellCore.BaseMath(ShellCore.BaseMathOperation.Multiply, 1, arguments); double result5 = ShellCore.BaseMath(ShellCore.BaseMathOperation.Modulus, 1, arguments); double result6 = ShellCore.BaseMath(ShellCore.BaseMathOperation.Sqrt, 1, arguments); double result7 = ShellCore.BaseMath(ShellCore.BaseMathOperation.Sin, 1, arguments); double result8 = ShellCore.BaseMath(ShellCore.BaseMathOperation.Cos, 1, arguments); double result9 = ShellCore.BaseMath(ShellCore.BaseMathOperation.Tan, 1, arguments); double result10 = ShellCore.BaseMath(ShellCore.BaseMathOperation.Asin, 1, arguments); double result11 = ShellCore.BaseMath(ShellCore.BaseMathOperation.Acos, 1, arguments); double result12 = ShellCore.BaseMath(ShellCore.BaseMathOperation.Atan, 1, arguments); double result13 = ShellCore.Power(4, 3); List <double> result14 = ShellCore.Ratio(6, 4, 3); // v7+ Console.WriteLine($"Basic Math arg 0 result: {result}"); Console.WriteLine($"Basic Math arg 1 result: {result2}"); Console.WriteLine($"Basic Math arg 2 result: {result3}"); Console.WriteLine($"Basic Math arg 3 result: {result4}"); Console.WriteLine($"Basic Math arg 4 result: {result5}"); Console.WriteLine($"Basic Math arg 5 result: {result6}"); Console.WriteLine($"Basic Math arg 6 result: {result7}"); Console.WriteLine($"Basic Math arg 7 result: {result8}"); Console.WriteLine($"Basic Math arg 8 result: {result9}"); Console.WriteLine($"Basic Math arg 9 result: {result10}"); Console.WriteLine($"Basic Math arg 10 result: {result11}"); Console.WriteLine($"Basic Math arg 11 result: {result12}"); Console.WriteLine($"Power result: {result13}"); Console.WriteLine($"Ratio result: {result14[0]}, {result14[1]}"); ShellCore.WinMsgBox("Shell", "This is a message box!"); // v6+ string openResult = ShellCore.WinOpenDialog("ShellCore Version 6 open dialog", ".txt", "Text documents (.txt)|*.txt"); // v6+ if (openResult == null) { Console.WriteLine("No file selected."); } else { Console.WriteLine(openResult); } string saveResult = ShellCore.WinSaveDialog("ShellCore Version 6 save dialog", ".txt", "Text documents (.txt)|*.txt"); // v6+ if (saveResult == null) { Console.WriteLine("No file selected."); } ShellCore.ShlBeep(1000, 400); ShellCore.CreateFileEx("dummy.tmp"); ShellCore.CopyFileEx("dummy.tmp", "dummy2.tmp"); ShellCore.MoveFileEx("dummy2.tmp", "dummy3.tmp"); ShellCore.CreateFileEx("dummy4.tmp"); ShellCore.CreateFolderEx("TestFolder"); // v0.8.7x+ ShellCore.SetFileHiddenEx("dummy4.tmp"); // v7+ Console.WriteLine("Now testing ShellUI..."); ShellUI.UiDrawMultiple('T', 8); ShellUI.UiDrawBlankSpace(16); ShellUI.UiSetConsoleColour(ConsoleColor.Black, ConsoleColor.White); ShellUI.UiSetWindowSize(25, 10); ShellUI.UiSetWindowSize(100, 63); ShellUI.UiSetCursorPosition(24, 24); ShellUI.UiSetCursorSize(5); ShellCore.WinPlaySound("tada.wav"); // v8.0.50+ ShellUI.UiSetWindowTitle("ddddddddddddddddddddddddd"); Console.WriteLine("Now testing ShellCore ExceptionsLite"); ShellCore.ShlWriteLog("ShellLog.txt", "This is a test"); // v6+ ShellCore.ShlCloseLog(); // v6+ ShellCore.WinCreateRegKey(RegistryHive.CurrentUser, "ShellTest"); // v7+ ShellCore.WinCreateRegKey(RegistryHive.CurrentUser, "ShellTest2"); // v7+ RegistryKey Reg = ShellCore.WinOpenRegKey(RegistryHive.CurrentUser, "ShellTest"); // v7+ ShellCore.WinSetRegValue(Reg, "Test", "TestThis"); // v7+ ShellCore.WinSetRegValue(Reg, "Test3", "This"); // v7+ ShellCore.WinDeleteRegValue(Reg, "Test3"); // v7+ ShellCore.WinDeleteRegKey(RegistryHive.CurrentUser, "ShellTest2"); // v7+ ShellCore.DownloadFileEx("http://shell.x10.mx/dummy.txt", "dummy2.txt"); // v8.0.62+ ShellCore.ElmRegisterExceptionP("ErrorTestException", 3001, "This is a test.", 0); // v4+ ShellCore.ElmRegisterExceptionP("ErrorTestException", 3002, "This is a test.", 1); // v4+ ShellCore.ElmRegisterExceptionP("ErrorTestException", 3003, "This is a test.", 2); // v4+ ShellCore.ElmThrowException(3001); // v4+ ShellCore.ElmThrowException(3002); // v4+ ShellCore.ElmThrowException(3003); // v4+ XmlDocument XmlTest = ShellCore.XmlCreateFile("Test.xml"); // v8.0.8x+ XmlTest = ShellCore.XmlAddNode(XmlTest, "ShellCoreXMLServicesTest", "test"); ShellCore.XmlSaveFile(XmlTest, "Test.xml"); // clean up Console.WriteLine("Testing complete. If it didn't crash or display any exceptions (excluding the test exceptions triggered, #3001, 3002, and 3003), that means it's all good. Press enter to exit."); Console.ReadKey(); ShellCore.DeleteFileEx("dummy.tmp"); // v4+ ShellCore.DeleteFileEx("dummy2.tmp"); // v4+ ShellCore.DeleteFileEx("dummy2.txt"); // v4+ ShellCore.DeleteFileEx("dummy3.tmp"); // v4+ ShellCore.DeleteFileEx("dummy4.tmp"); // v4+ ShellCore.DeleteFolderEx("TestFolder"); // v8.0.7x+ ShellCore.DeleteFileEx("Test.xml"); // v4/v8.0.94+ Environment.Exit(0xD15EA5E); }
//TODO: Clean up this function. It blows ass and sucks dick right now. public ShxmlVariable ShxmlDeclareVariable(XmlNode node) // Automatically determines the type. Internal? { ShxmlVariable xmlvar = new ShxmlVariable(); XmlAttributeCollection XmlAttrs = node.Attributes; string var_name = null; string var_type = null; string var_value = null; foreach (XmlAttribute Attribute in XmlAttrs) { if (Attribute.Name == "name") { var_name = Attribute.Value; } // get it! if (Attribute.Name == "type") { var_type = Attribute.Value; } if (Attribute.Name == "value") { var_value = Attribute.Value; } } foreach (ShxmlVariable var in Varlist) { //Console.WriteLine(var.Name); if (var.Name == var_name) { //var = null; ShellCore.ElmThrowException(11); return(xmlvar); // silently return if duplicate } } xmlvar.Name = var_name; //todo: sometimes for some reason (doubles) it doesn't set the variable // split this? -- for function parameters maybe?? try { switch (var_type) { case null: xmlvar.Type = -1; try { xmlvar.Type = 3; xmlvar.vardouble = Convert.ToDouble(var_value); // this deliberately triggers an exception } catch (FormatException) // use an exception handler to set the type { xmlvar.Type = 1; // ITS A STRING xmlvar.varstring = var_value; } if (xmlvar.Type == -1) { ShellCore.ElmThrowException(5); return(xmlvar); } if (var_value == "true" || var_value == "false") { xmlvar.Type = 5; xmlvar.varbool = Convert.ToBoolean(var_value); } Varlist.Add(xmlvar); return(xmlvar); case "int": case "Int": ShxmlInitVariable(var_name, Convert.ToInt32(var_value)); return(xmlvar); case "str": case "Str": case "string": case "String": //xmlvar.Name = var_name; ShxmlInitVariable(var_name, var_value); return(xmlvar); case "letter": case "char": case "character": case "Char": case "Character": case "Letter": ShxmlInitVariable(var_name, Convert.ToChar(var_value)); return(xmlvar); case "double": case "Double": case "number": case "Number": ShxmlInitVariable(var_name, Convert.ToDouble(var_value)); return(xmlvar); case "float": case "Float": ShxmlInitVariable(var_name, Convert.ToSingle(var_value)); return(xmlvar); case "bool": case "Bool": case "BOOL": case "Boolean": case "boolean": case "truefalse": case "true/false": case "true false": case "falsetrue": case "false/true": case "false or true": case "true or false": ShxmlInitVariable(var_name, Convert.ToBoolean(var_value)); return(xmlvar); // floats not supported default: ShellCore.ElmThrowException(5); return(xmlvar); } } catch (FormatException) { ShellCore.ElmThrowException(7); return(xmlvar); } //return xmlvar; }
public void ShxmlConsoleInput(XmlNode Token) { string text = ""; int posx = -0xd15ea5e; int posy = -0xd15ea5e; char chr = ' '; ShxmlVariable svar = new ShxmlVariable(); //TODO: Clean up the code. svar.Name = "ddddddddddddddddddddddddddddddddddddddddddddddddddd"; XmlAttributeCollection attributes = Token.Attributes; foreach (XmlAttribute attribute in attributes) { switch (attribute.Name) { case "text": text = attribute.Value; continue; case "posx": try { posx = Convert.ToInt32(attribute.Value); } catch (FormatException) { ShellCore.ElmThrowException(16); } if (posx == -0xd15ea5e) { ShellCore.ElmThrowException(18); } continue; case "posy": try { posy = Convert.ToInt32(attribute.Value); } catch (FormatException) { ShellCore.ElmThrowException(17); } if (posx == -0xd15ea5e) { ShellCore.ElmThrowException(18); } continue; case "char": try { chr = Convert.ToChar(attribute.Value); } catch (FormatException) { ShellCore.ElmThrowException(20); } continue; case "variable": case "var": svar.Name = attribute.Value; if (svar.Name == "") { ShellCore.ElmThrowException(21); } svar.Type = 1; // string continue; } } if (svar.Name == "ddddddddddddddddddddddddddddddddddddddddddddddddddd") { ShellCore.ElmThrowException(22); // exception 22 - no variable } if (posx != -0xd15ea5e & posy != 0xd15ea5e) { UiSetCursorPosition(posx, posy); // set the cursor position if it is not a default value } Console.Write($"{text} {chr}"); svar.varstring = Console.ReadLine(); Varlist.Add(svar); // add it to the global master variable listash }