private void RegValueKind(TFunctionData _sframe) { _sframe.AssertParamCount(3); using (RegistryKey key = OpenKey(_sframe.GetParameter <string>(1), false)) { _sframe.Data = key.GetValueKind(_sframe.GetParameter <string>(2)).ToString(); } }
private static void RegEnumKeys(TFunctionData _sframe) { _sframe.AssertParamCount(2); using (RegistryKey key = OpenKey(_sframe.GetParameter <string>(1), false)) { _sframe.Data = key.GetSubKeyNames(); } }
private void FileWriteAll(TFunctionData _sframe) { _sframe.AssertParamCount(3); string path = _sframe.GetParameter <string>(1); object data = _sframe.GetParameter(2); string sData = data as string; if (sData != null) { File.WriteAllText(path, sData); } string[] saData = data as string[]; if (saData != null) { File.WriteAllLines(path, saData); } byte[] bData = data as byte[]; if (bData != null) { File.WriteAllBytes(path, bData); } _sframe.Status = ErrorSuccess.Warnings; // data is written, but not necessarily useful File.WriteAllText(path, data + ""); }
internal void DIM(TFunctionData stackFrame) { if (stackFrame.ParameterCount < 2) { stackFrame.AssertParamCount(2); } StringSegment text = new StringSegment(stackFrame.Text); Scanner scanner = new Scanner(text); scanner.IntPosition += stackFrame.Name.Length; scanner.SkipWhiteSpace(); Variable v; if (!scanner.NextVariable(stackFrame.StackExecuter, out v)) { throw ThrowHelper.InvalidVariableName(); } string name = v.Name.ToString(); ObjectContext context = stackFrame.Context.FindVariableContext(name); if (context == null) { stackFrame.Context.SetVariable(name, array_alloc(v.Indices, 0)); } else { object obj = context.GetVariable(name); array_realloc(ref obj, v.Indices, 0); context.SetVariable(name, obj); } NULL(stackFrame); }
private void WinList(TFunctionData parameters) { if (parameters.ParameterCount == 1) { parameters.AddParameter(WindowFlag.Existing); } parameters.AssertParamCount(2); WindowFlag state = parameters.GetParameter <WindowFlag>(1); IntPtr[] hwnds = WinList(state).ToArray(); if (hwnds.Length > 0) { object[][] windows = new object[hwnds.Length][]; for (int index = 0; index < windows.Length; index++) { windows[index] = new object[] { Evaluator.ConvertToObject(hwnds[index]), WinGetTitle(hwnds[index]) }; } parameters.Data = windows; } else { parameters.Status = ErrorSuccess.NoContent; } }
private void ArrayLastIndexOf(TFunctionData stackFrame) { object[] arr = stackFrame.GetParameter <object[]>(1); if (stackFrame.ParameterCount == 3) { stackFrame.AddParameter(0); } if (stackFrame.ParameterCount == 4) { stackFrame.AddParameter(arr.Length); } stackFrame.AssertParamCount(5); int i = stackFrame.GetParameter <int>(3); object o = stackFrame.GetParameter(2); int count = stackFrame.GetParameter <int>(5); for (; i >= 0 && i > count; i--) { if (arr[i] == o) { stackFrame.Data = i; return; } } stackFrame.Data = -1; }
private void GetScreen(TFunctionData parameters) { parameters.AssertParamCount(2); int compression = parameters.GetFromIntRange(1, 0, 100); parameters.Data = GetScreen(compression); }
private void MouseClick(TFunctionData _sframe) { if (_sframe.ParameterCount == 4) { _sframe.AddParameter(1); _sframe.AddParameter(1); } if (_sframe.ParameterCount == 5) { _sframe.AddParameter(5); } _sframe.AssertParamCount(6); int x = _sframe.GetParameter <int>(2), y = _sframe.GetParameter <int>(3), clicks = _sframe.GetParameter <int>(4), speed = _sframe.GetParameter <int>(5); MouseButton button; if (_sframe.GetFromEnum(1, "button", "LEFT", "RIGHT").EqualsIgnoreCase("LEFT")) { button = MouseButton.Left; } else { button = MouseButton.Right; } MouseClick(button, x, y, clicks, speed); }
private void RegDeleteKey(TFunctionData _sframe) { _sframe.AssertParamCount(2); using (RegistryKey key = GetRootKey(_sframe.GetParameter <string>(1))) { key.DeleteSubKeyTree(RemoveKeyRoot(_sframe.GetParameter <string>(1))); } }
private void RegRenameKey(TFunctionData _sframe) { _sframe.AssertParamCount(3); using (RegistryKey key = OpenParentKey(_sframe.GetParameter <string>(1), true)) { RegistryUtilities.RenameSubKey(key, RemoveKeyRoot(_sframe.GetParameter <string>(1)), _sframe.GetParameter <string>(2)); } }
private void Shell(TFunctionData _sframe) { _sframe.AssertParamCount(2); string output; _sframe.Status = Shell(_sframe.GetParameter <string>(1), out output); _sframe.Data = output; }
private void FileGetAttributes(TFunctionData _sframe) { _sframe.AssertParamCount(2); string path = _sframe.GetParameter <string>(1); FileAttributes current = File.GetAttributes(path); _sframe.Data = GetStringFromAttributes(current); }
private void IsDefined(TFunctionData stackFrame) { stackFrame.AssertParamCount(2); string name = stackFrame.GetParameter <string>(1); ObjectContext context = stackFrame.Context.FindContext(name); stackFrame.Data = context != null; }
private void WinPicture(TFunctionData parameters) { parameters.AssertParamCount(3); int compression = parameters.GetFromIntRange(2, 0, 100); IntPtr hwnd = new IntPtr(parameters.GetParameter <long>(1)); parameters.Data = WinPicture(hwnd, compression); }
private void WinActivate(TFunctionData parameters) { parameters.AssertParamCount(2); if (!WinActivate(new IntPtr(parameters.GetParameter <long>(1)))) { throw new TbasicException(ErrorServer.GenericError, "Unable to activate window"); } }
private void RegCreateKey(TFunctionData _sframe) { _sframe.AssertParamCount(3); using (RegistryKey key = OpenKey(_sframe.GetParameter <string>(1), true)) { key.CreateSubKey(_sframe.GetParameter <string>(2)); _sframe.Status = ErrorSuccess.Created; } }
private void BlockInput(TFunctionData _sframe) { _sframe.AssertParamCount(2); _sframe.SetAll(_sframe.GetParameter(0), _sframe.GetParameter(1).ToString().Replace("1", "true").Replace("0", "false")); if (!BlockInput(_sframe.GetParameter <bool>(1))) { _sframe.Status = ErrorClient.Forbidden; } }
private void Round(TFunctionData stackFrame) { if (stackFrame.ParameterCount == 2) { stackFrame.AddParameter(2); } stackFrame.AssertParamCount(3); stackFrame.Data = Round(stackFrame.GetParameter <double>(1), stackFrame.GetParameter <int>(2)); }
private void RegWrite(TFunctionData _sframe) { _sframe.AssertParamCount(5); object value = _sframe.GetParameter(3); RegistryValueKind kind; switch (_sframe.GetParameter <string>(4).ToLower()) { case "binary": kind = RegistryValueKind.Binary; List <string> slist = new List <string>(); slist.AddRange(_sframe.GetParameter <string>(3).Split(' ')); value = slist.ConvertAll(s => Convert.ToByte(s, 16)).ToArray(); break; case "dword": kind = RegistryValueKind.DWord; break; case "expandstring": kind = RegistryValueKind.ExpandString; break; case "multistring": kind = RegistryValueKind.MultiString; if (value is string) { value = _sframe.GetParameter <string>(3).Replace("\r\n", "\n").Split('\n'); } else if (value is string[]) { value = _sframe.GetParameter <string[]>(3); } else { throw new ArgumentException("Parameter is not a valid multi-string"); } break; case "qword": kind = RegistryValueKind.QWord; break; case "string": kind = RegistryValueKind.String; break; default: throw new ArgumentException("Unknown registry type '" + _sframe.GetParameter(4) + "'"); } using (RegistryKey key = OpenKey(_sframe.GetParameter <string>(1), true)) { key.SetValue(_sframe.GetParameter <string>(2), value, kind); } }
private void VolumeDown(TFunctionData _sframe) { if (_sframe.ParameterCount == 1) { _sframe.SetAll(_sframe.GetParameter(0), "1"); } _sframe.AssertParamCount(2); VolumeDown(_sframe.GetParameter <int>(1)); }
private void RegDelete(TFunctionData _sframe) { _sframe.AssertParamCount(3); RegistryKey key = GetRootKey(_sframe.GetParameter <string>(1)); using (key = key.OpenSubKey(RemoveKeyRoot(_sframe.GetParameter <string>(1)), true)) { key.DeleteValue(_sframe.GetParameter <string>(2), true); } }
private void ToInt(TFunctionData stackFrame) { stackFrame.AssertParamCount(2); try { stackFrame.Data = stackFrame.GetParameter <int>(1); } catch (InvalidCastException) { throw new TbasicException(ErrorClient.BadRequest, "Parameter cannot be int"); } }
private void WinSetTrans(TFunctionData parameters) { parameters.AssertParamCount(3); IntPtr hwnd = new IntPtr(parameters.GetParameter <long>(1)); if (!WinSetTrans(hwnd, parameters.GetParameter <byte>(2))) { throw new TbasicException(ErrorServer.GenericError, "Unable to set window transparency"); } }
private void WinKill(TFunctionData parameters) { parameters.AssertParamCount(2); long hwnd = parameters.GetParameter <long>(1); if (!WinKill(new IntPtr(hwnd))) { throw new TbasicException(ErrorServer.GenericError, "Unable to kill window"); } }
private void WinSize(TFunctionData parameters) { parameters.AssertParamCount(4); IntPtr hwnd = new IntPtr(parameters.GetParameter <long>(1)); if (!WinSize(hwnd, parameters.GetParameter <int>(2), parameters.GetParameter <int>(3))) { throw new TbasicException(ErrorServer.GenericError, "Unable to resize window"); } }
private void WinSetState(TFunctionData parameters) { parameters.AssertParamCount(3); uint flag = parameters.GetParameter <uint>(2); if (!WinSetState(new IntPtr(parameters.GetParameter <long>(1)), flag)) { throw new TbasicException(ErrorServer.GenericError, "Unable to set window state"); } }
private void WinSetTitle(TFunctionData parameters) { parameters.AssertParamCount(3); IntPtr hwnd = new IntPtr(parameters.GetParameter <long>(1)); if (!User32.SetWindowText(hwnd, parameters.GetParameter <string>(2))) { throw new TbasicException(ErrorServer.GenericError, "Unable to set window title"); } }
private void Eval(TFunctionData stackFrame) { stackFrame.AssertParamCount(2); try { stackFrame.Data = Eval(stackFrame.GetParameter <string>(1)); } catch (Exception ex) { throw TbasicException.WrapException(ex); } }
public FuncBlock(int index, LineCollection code) { LoadFromCollection( code.ParseBlock( index, c => c.Name.EqualsIgnoreCase("FUNCTION"), c => c.Text.EqualsIgnoreCase("END FUNCTION") )); Template = new TFunctionData(null); Template.SetAll(ParseFunction(Header.Text.Substring(Header.Name.Length))); }
private void CharsToString(TFunctionData stackFrame) { stackFrame.AssertParamCount(2); StringBuilder hanz = new StringBuilder(); foreach (char c in stackFrame.GetParameter <char[]>(1)) { hanz.Append(c); } stackFrame.Data = hanz.ToString(); }