mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-11 02:52:35 +02:00
65ef92d7f0
* **Scripting:** * Add scripting capability, this allow to run external scripts inside the GUI and take advantage of visual layout to display user input fields * Scripts run under the "Roslyn Scripting API" and can make use of the whole C# language, this mean a huge boost compared to PowerShell scripts * Scripts are written in the same way UVtools is, by learning and programing scripts you are learning the UVtools core * For more information see the script sample: https://github.com/sn4k3/UVtools/tree/master/UVtools.ScriptSample * To run scripts go to: Tools - Scripting * **File formats:** * Add a check and warning when opening an file that have a diferent layer and file resolution * **Issues:** * Add "Print height" as new type of issue detection, all layers that goes beyond maximum printer Z height will be flagged as PrintHeight issue * Print height issues will not be automatical fixed, however user can fix it by remove some layers to counter the problem, still is recommended to resize object on slicer * Fix unable to compute issues when only islands or overhangs are selected to be detected alone (#177) * **Settings:** * Add default directory for scripts on "General - File dialogs" * Add checkbox on "Issues - Compute - Print height" to enable or disable this type of detection * Add numerical on "Issues - Print height - Offset" to define a custom offset from Z top * Fix default directories input width to not grow with text, it was overflowing on large strings * **Menu - Help:** * Add web link to "Wiki & tutorials" * Add web link to "Facebook group" * Add web link to "Report a issue" * Add web link to "Ask a question" * Add web link to "Suggest an improvement or new features"
61 lines
2.3 KiB
C#
61 lines
2.3 KiB
C#
/*
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE
|
|
* Version 3, 19 November 2007
|
|
* Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
* Everyone is permitted to copy and distribute verbatim copies
|
|
* of this license document, but changing it is not allowed.
|
|
*/
|
|
|
|
using System;
|
|
using System.IO;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace UVtools.Core.Scripting
|
|
{
|
|
public static class ScriptParser
|
|
{
|
|
public static string ParseScriptFromFile(string path)
|
|
{
|
|
return ParseScriptFromText(File.ReadAllText(path));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Parse the script and clean forbidden keywords
|
|
/// </summary>
|
|
/// <param name="text">Text to parse</param>
|
|
/// <returns>The parsed text</returns>
|
|
public static string ParseScriptFromText(string text)
|
|
{
|
|
if(!Regex.Match(text, @"(void\s*ScriptInit\s*\(\s*\))").Success)
|
|
{
|
|
throw new ArgumentException("The method \"void ScriptInit()\" was not found on script, please verify the script.");
|
|
}
|
|
if (!Regex.Match(text, @"(string\s*ScriptValidate\s*\(\s*\))").Success)
|
|
{
|
|
throw new ArgumentException("The method \"string ScriptValidate()\" was not found on script, please verify the script.");
|
|
}
|
|
if (!Regex.Match(text, @"(bool\s*ScriptExecute\s*\(\s*\))").Success)
|
|
{
|
|
throw new ArgumentException("The method \"bool ScriptExecute()\" was not found on script, please verify the script.");
|
|
}
|
|
|
|
var textLength = text.Length;
|
|
sbyte bracketsToRemove = 0;
|
|
text = Regex.Replace(text, @"(namespace .*\n*.*{)", string.Empty);
|
|
if (textLength != text.Length) bracketsToRemove++;
|
|
textLength = text.Length;
|
|
text = Regex.Replace(text, "(.*class .*\n*.*{)", string.Empty);
|
|
if (textLength != text.Length) bracketsToRemove++;
|
|
|
|
if (bracketsToRemove <= 0) return text;
|
|
|
|
for (textLength = text.Length - 1; textLength >= 0 && bracketsToRemove > 0; textLength--)
|
|
{
|
|
if (text[textLength] == '}') bracketsToRemove--;
|
|
}
|
|
|
|
return text.Substring(0, textLength);
|
|
}
|
|
}
|
|
}
|