Skip to content

Commit a8ef6be

Browse files
committed
Handling few invalid inputs
1 parent c7e726a commit a8ef6be

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

GHUI/BuildHtmlUiComponent.cs

+6
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ protected override void SolveInstance(IGH_DataAccess da)
5656
List<string> jsScripts = new List<string>();
5757

5858
if (!da.GetData(0, ref path)) return;
59+
if(!System.IO.File.Exists(path))
60+
{
61+
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"File path: \"{path}\" not found on this computer");
62+
da.SetData(0, false);
63+
return;
64+
}
5965
if (!da.GetData(1, ref htmlString)) return;
6066
da.GetData(2, ref title);
6167
da.GetDataList(3, stylesheets);

GHUI/Classes/WebView2Wrapper.cs

+2
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ private void OnDocumentUpdated(object sender, DOM.DocumentUpdatedEventArgs args)
248248
/// </summary>
249249
public void SubscribeToHtmlChanged()
250250
{
251+
if (!System.IO.Directory.Exists(Directory))
252+
throw new System.IO.DirectoryNotFoundException($"Can not find: \"{Directory}\" on this computer");
251253
_watcher = new FileSystemWatcher(Directory)
252254
{
253255
NotifyFilter = NotifyFilters.LastAccess

GHUI/HtmlUiComponent.cs

+5
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ protected override void SolveInstance(IGH_DataAccess da)
6363

6464
// get input
6565
if (!da.GetData(0, ref path)) return;
66+
if (!System.IO.File.Exists(path))
67+
{
68+
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"File path: \"{path}\" not found on this computer");
69+
return;
70+
}
6671
if (!da.GetData<bool>(1, ref show)) return;
6772
da.GetData(2, ref title);
6873
da.GetData(3, ref _height);

GHUI/SettersDefineComponent.cs

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ protected override void SolveInstance(IGH_DataAccess da)
3939
if (!da.GetDataList(0, ids)) return;
4040
if (!da.GetDataList(1, vals)) return;
4141

42+
if(ids.Count != vals.Count)
43+
{
44+
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Amount of IDs and Values must be equal");
45+
return;
46+
}
47+
4248
//List<DomSetValueModelGoo> setValueModels =
4349
// ids.Select((t, i) => new DomSetValueModelGoo() {id = t, value = vals[i]}).ToList();
4450

GHUI/Web UI/createdInput.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<div style=''><input type='range' id='mySlider' name='mySlider' value='50' min='0' max='100'></div><div style='width:100%; height:200px; background:lightgray;'><input type='range' id='mySlider2' name='mySlider2' value='50' min='0' max='100'></div>
1+
<!DOCTYPE html><html lang=en><meta charset=utf-8><title>UI</title><!DOCTYPE html><html lang=en><meta charset=utf-8><title>UI</title><!DOCTYPE html><html lang=en xmlns=http://www.w3.org/1999/xhtml><div id=app><h1>HELLO THERE</h1></div>

0 commit comments

Comments
 (0)