{"TotalCount":4,"Files":[{"Ident":"sturnus.imagetomaterial","Path":"MyLibraryComponent.cs","FileName":"MyLibraryComponent.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":379602,"IsPrivate":false,"Code":"using Sandbox;\r\n\r\n/// \u003Csummary\u003E\r\n/// This is a component - in your library!\r\n/// \u003C/summary\u003E\r\n[Title( \u0022Image to Material - My Component\u0022 )]\r\npublic class MyLibraryComponent : Component\r\n{\r\n\r\n}\r\n"},{"Ident":"sturnus.imagetomaterial","Path":"Code/MyLibraryComponent.cs","FileName":"MyLibraryComponent.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":379602,"IsPrivate":false,"Code":"using Sandbox;\r\n\r\n/// \u003Csummary\u003E\r\n/// This is a component - in your library!\r\n/// \u003C/summary\u003E\r\n[Title( \u0022Image to Material - My Component\u0022 )]\r\npublic class MyLibraryComponent : Component\r\n{\r\n\r\n}\r\n"},{"Ident":"sturnus.imagetomaterial","Path":".obj/__compiler_extra.cs","FileName":"__compiler_extra.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":379602,"IsPrivate":false,"Code":"global using static Sandbox.Internal.GlobalGameNamespace;\r\nglobal using Microsoft.AspNetCore.Components;\r\nglobal using Microsoft.AspNetCore.Components.Rendering;\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022AddonTitle\u0022, \u0022Image to Material\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022AddonIdent\u0022, \u0022imagetomaterial\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022OrgIdent\u0022, \u0022sturnus\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022Ident\u0022, \u0022sturnus.imagetomaterial\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022EngineVersion\u0022, \u002229\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022EngineMinorVersion\u0022, \u00221\u0022 )]\r\n\r\n[assembly: System.Runtime.Versioning.TargetFramework( \u0022.NETCoreApp,Version=v9.0\u0022, FrameworkDisplayName = \u0022.NET 9.0\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022CompileTime\u0022, \u00222026-09-10T22:21:33.6626465Z\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyVersion(\u00220.0.112.0\u0022)]\r\n[assembly: global::System.Reflection.AssemblyFileVersion(\u00220.0.112.0\u0022)]"},{"Ident":"sturnus.imagetomaterial","Path":"Editor/ImagetoMaterial.cs","FileName":"ImagetoMaterial.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":379602,"IsPrivate":false,"Code":"using System;\nusing System.Collections.Generic;\nusing System.ComponentModel.DataAnnotations;\nusing System.IO;\nusing System.Linq;\nusing System.Numerics;\nusing System.Reflection;\nusing System.Reflection.Emit;\nusing System.Runtime.CompilerServices;\nusing System.Security.Cryptography.X509Certificates;\nusing Editor;\nusing Editor.ShaderGraph;\nusing Editor.ShaderGraph.Nodes;\nusing Editor.Widgets;\nusing Sandbox;\nusing Sandbox.Engine.Shaders;\nusing Sandbox.Utility;\nusing static Sandbox.Material;\n\n[EditorApp( \u0022Image to Material\u0022, \u0022transform\u0022, \u0022Tool for converting images to materials in bulk.\u0022 )]\n\npublic class ImagetoMaterial : BaseWindow\n{\n\n\tpublic string GenerationPath { get; set; } = Editor.FileSystem.Content.GetFullPath( \u0022\u0022 ) \u002B \u0022\\\\ImageToMaterial\\\\\u0022;\n\tpublic string GenerationPathInput { get; set; } = Editor.FileSystem.Content.GetFullPath( \u0022\u0022 ) \u002B \u0022\\\\ImageToMaterial\\\\Input\u0022;\n\tpublic string GenerationPathOutput { get; set; } = Editor.FileSystem.Content.GetFullPath( \u0022\u0022 ) \u002B \u0022\\\\ImageToMaterial\\\\Output\u0022;\n\n\tpublic string GenerationLocalPath { get; set; } = \u0022\\\\ImageToMaterial\\\\\u0022;\n\tpublic string ExportPath { get; set; } = Project.Current.RootDirectory \u002B \u0022\\\\Assets\\\\\u0022;\n\n\n\tTestClass instance;\n\n\tprivate static readonly HashSet\u003Cstring\u003E ImageFileExtensions = new HashSet\u003Cstring\u003E\n\t{\n\t\t\u0022.psd\u0022, \u0022.tga\u0022, \u0022.tif\u0022, \u0022.pkm\u0022, \u0022.mks\u0022, \u0022.png\u0022, \u0022.jpg\u0022, \u0022.exr\u0022\n\t};\n\n\tprivate static readonly HashSet\u003Cstring\u003E ShaderLayerSuffix = new HashSet\u003Cstring\u003E\n\t{\n\t\t\u0022_color\u0022, \u0022_normal\u0022, \u0022_rough\u0022, \u0022_ao\u0022, \u0022_trans\u0022, \u0022_refl\u0022, \u0022_gloss\u0022, \u0022_metal\u0022\n\t};\n\n\tpublic class TestClass\n\t{\n\t\t[ResourceType( \u0022shader\u0022 )]\n\t\tpublic string Shader { get; set; } = \u0022shaders/generic.shader\u0022;\n\n\t\tpublic bool Color = true;\n\t\tpublic bool Normal = false;\n\t\tpublic bool Roughness = false;\n\t\tpublic bool AmbientOcclusion = false;\n\n\t\t[Category( \u0022Advanced\u0022 )] public bool Translucent = false;\n\n\t\tpublic string OutputFilePrefix = \u0022\u0022;\n\t\tpublic string OutputFileSuffix = \u0022\u0022;\n\t\t[Display( Name = \u0022Output Folder\u0022 )]\n\t\tpublic OutputLocation Output = OutputLocation.SameFolder;\n\t}\n\n\tpublic enum OutputLocation\n\t{\n\t\t[Display( Name = \u0022Same folder\u0022 )]\n\t\tSameFolder,\n\t\t[Display( Name = \u0022One folder up\u0022 )]\n\t\tParentFolder\n\t}\n\n\n\n\tpublic ImagetoMaterial()\n\t{\n\n\t\tWindowTitle = \u0022Image to Material\u0022;\n\t\tSetWindowIcon( \u0022transform\u0022 );\n\t\tSize = new Vector2( 800,650 );\n\n\t\tLayout = Layout.Column();\n\n\t\t///\n\t\t/// Create Directories\n\t\t/// \n\t\t/*Directory.CreateDirectory( GenerationPath );\n\t\tDirectory.CreateDirectory( GenerationPathInput );\n\t\tDirectory.CreateDirectory( GenerationPathOutput );*/\n\n\t\t///\n\t\t/// Header\n\t\t///\n\t\tvar Header = Layout.Column();\n\t\tHeader.Spacing = 0;\n\t\tHeader.Margin = 20;\n\t\tvar Title = new Editor.Label.Subtitle( \u0022Image to Material\u0022 );\n\t\tHeader.Add( Title, 0 );\n\t\tvar SubTitle = new Editor.Label.Body( \u0022Tool for converting images to materials in bulk.\u0022 );\n\t\tHeader.Add( SubTitle, 0 );\n\n\t\t///\n\t\t/// Body\n\t\t///\n\t\tvar Body = Layout.Column();\n\t\tBody.Margin = 20;\n\t\tvar BodySections = Layout.Row();\n\n\t\tBody.Add(BodySections, 0 );\n\n\t\tvar BodySectionsLeft = Layout.Column();\n\t\tvar BodySectionsCenter = Layout.Column();\n\n\t\tBodySectionsLeft.Add( new Editor.Label.Subtitle( \u0022Source\u0022 ) );\n\t\t\n\t\t\n\t\tBodySectionsLeft.Alignment = Sandbox.TextFlag.CenterHorizontally;\n\n\t\tvar BodySectionsLeftCanvas = new Widget( null );\n\t\tBodySectionsLeftCanvas.Layout = Layout.Row();\n\t\tBodySectionsLeftCanvas.Layout.Spacing = 32;\n\n\t\tvar BodySectionsLeftView = new Editor.TreeView( BodySectionsLeftCanvas );\n\t\tBodySectionsLeftView.HorizontalSizeMode = SizeMode.CanGrow;\n\t\tBodySectionsLeftView.SmoothScrolling = true;\n\t\tBodySectionsLeftView.MultiSelect = false;\n\t\tstring sourceRoot = Project.Current.GetAssetsPath();\n\t\tvar BodySectionsLeftFolder = BodySectionsLeftView.AddItem( new FilesystemTreeNode( sourceRoot ) );\n\n\t\tBodySectionsLeftView.Open( BodySectionsLeftFolder );\n\n\t\tBodySectionsLeft.Add( BodySectionsLeftView, 0 );\n\t\tvar SourceWarning = new WarningBox( \u0022Please select source\u0022 );\n\t\tBodySectionsLeft.Add( SourceWarning );\n\n\n\t\tBodySectionsCenter.Add( new Editor.Label.Subtitle( \u0022Material Settings\u0022 ) );\n\t\tBodySectionsCenter.Alignment = Sandbox.TextFlag.CenterHorizontally;\n\n\t\tinstance = new TestClass();\n\t\tvar so = instance.GetSerialized();\n\n\t\t// Default: Generic //////////////////\n\t\tinstance.Color = true;\n\t\tinstance.Normal = true;\n\t\tinstance.Roughness = false;\n\t\tinstance.AmbientOcclusion = false;\n\t\t//instance.Metalness = false;\n\t\tinstance.Translucent = false;\n\t\t//////////////////////////////////////\n\t\tso.OnPropertyChanged \u002B= _ =\u003E\n\t\t{\n\t\t\t// Clear any shader-driven layer defaults the user might still see\n\t\t};\n\n\t\tvar property = new Editor.ControlSheet();\n\t\tproperty.AddObject( so, x =\u003E x.Name is not \u0022Output\u0022 and not \u0022OutputFilePrefix\u0022 and not \u0022OutputFileSuffix\u0022 );\n\n\t\tBodySectionsCenter.Add( property,1 );\n\n\t\tvar OutputSection = Layout.Column();\n\t\tOutputSection.Margin = new Sandbox.UI.Margin( 0, 16, 0, 0 );\n\t\tOutputSection.Add( new Editor.Label.Subtitle( \u0022Output\u0022 ) );\n\t\tvar outputProperty = new Editor.ControlSheet();\n\t\toutputProperty.AddObject( so, x =\u003E x.Name is \u0022Output\u0022 or \u0022OutputFilePrefix\u0022 or \u0022OutputFileSuffix\u0022 );\n\t\tOutputSection.Add( outputProperty, 1 );\n\t\tBodySectionsCenter.Add( OutputSection, 1 );\n\n\t\tBodySections.Add( BodySectionsLeft, 1 );\n\t\tBodySections.Add( BodySectionsCenter, 1 );\n\n\t\t///\n\t\t/// Actions\n\t\t///\n\t\tvar Actions = Layout.Column();\n\t\tActions.Margin = 20;\n\t\tvar ConvertButton = new Editor.Button.Primary( \u0022Convert\u0022, \u0022autorenew\u0022 );\n\t\tConvertButton.Enabled = false;\n\t\tvoid UpdateConvertButtonState()\n\t\t{\n\t\t\tConvertButton.Enabled = BodySectionsLeftView.Selection.Count != 0;\n\t\t}\n\t\tvoid UpdateSourceError()\n\t\t{\n\t\t\tSourceWarning.Visible = BodySectionsLeftView.Selection.Count == 0;\n\t\t}\n\n\t\tBodySectionsLeftView.Selection.OnItemAdded \u002B= _ =\u003E { UpdateConvertButtonState(); UpdateSourceError(); };\n\t\tBodySectionsLeftView.Selection.OnItemRemoved \u002B= _ =\u003E { UpdateConvertButtonState(); UpdateSourceError(); };\n\t\tConvertButton.Clicked \u002B= () =\u003E\n\t\t{\n\t\t\tConvertFiles( BodySectionsLeftView.Selection );\n\n\t\t\tvar PopUp = new PopupWindow( \u0022Export Complete\u0022, \u0022Materials exported to the folder selected in Material Settings.\u0022, \u0022Okay\u0022 );\n\t\t\tPopUp.Show();\n\t\t};\n\n\t\tActions.Add( ConvertButton );\n\n\t\tvar helpdocs = new WebWidget( null );\n\n\t\thelpdocs.Surface.Url = \u0022https://sbox.game/sturnus\u0022;\n\n\t\tvar HelpButton = new Editor.Button( \u0022Documentation\u0022 );\n\t\tHelpButton.Tint = \u0022#8c7ae6\u0022;\n\t\tHelpButton.Clicked = () =\u003E\n\t\t{\n\t\t\tvar PopUp = new PopupWindow( \u0022Help\u0022, $\u0022This tool allows you to bulk convert images to materials.\\n\u0022 \u002B\n\t\t\t\t$\u0022\\nPrep: Create folders for each material you want to create, once the folders are created, rename each image to it\u0027s appropriate layer ie(_color.png, _normal.png, etc...)\\n\u0022 \u002B\n\t\t\t\t$\u0022\\nSource: Select the parent folder where all of your material folders live\\n\u0022 \u002B\n\t\t\t\t$\u0022\\nOutput: In Material Settings, choose if the material file is saved in the same folder as the source images, or one folder up\\n\u0022 \u002B\n\t\t\t\t$\u0022\u0022, \u0022Okay\u0022\n\t\t\t);\n\t\t\tPopUp.Show();\n\t\t};\n\n\n\t\t///\n\t\t/// Footer\n\t\t///\n\t\tvar Footer = Layout.Row();\n\t\tFooter.Margin = 5;\n\t\tFooter.Add( new Editor.Label.Body( \u0022\uD83D\uDD28 with \u2764\uFE0F by \u003Ca href=\\\u0022https://sbox.game/u/AustinDotCodes\\\u0022\u003EAustin\u003C/a\u003E\u0022 ) );\n\t\tFooter.Add( HelpButton );\n\n\t\tLayout.Add( Header, 0 );\n\t\tLayout.Add( Body, 0 );\n\t\tLayout.Add( Actions, 0 );\n\t\tLayout.Add( Footer, 0 );\n\n}\n\tpublic HashSet\u003Cstring\u003E GetValidImageFiles( IEnumerable\u003Cobject\u003E selection )\n\t{\n\t\tvar imageFiles = new HashSet\u003Cstring\u003E();\n\t\tforeach ( var obj in selection )\n\t\t{\n\t\t\tif ( obj is FilesystemTreeNode node )\n\t\t\t{\n\t\t\t\tif ( node.Info is DirectoryInfo directory )\n\t\t\t\t{\n\t\t\t\t\tforeach ( var file in directory.GetFiles( \u0022*\u0022, SearchOption.AllDirectories ) )\n\t\t\t\t\t{\n\t\t\t\t\t\tvar relativePath = file.FullName.Replace( Project.Current.RootDirectory.ToString(), \u0022\u0022 ).TrimStart( Path.DirectorySeparatorChar );\n\t\t\t\t\t\tif ( ImageFileExtensions.Contains( file.Extension.ToLower() ) )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\timageFiles.Add( relativePath );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse if ( node.Info is FileInfo file )\n\t\t\t\t{\n\t\t\t\t\tvar relativePath = file.FullName.Replace( Project.Current.RootDirectory.ToString(), \u0022\u0022 ).TrimStart( Path.DirectorySeparatorChar );\n\t\t\t\t\tif ( ImageFileExtensions.Contains( file.Extension.ToLower() ) )\n\t\t\t\t\t{\n\t\t\t\t\t\timageFiles.Add( relativePath );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn imageFiles;\n\t}\n\n\tpublic void ConvertFiles( IEnumerable\u003Cobject\u003E source )\n\t{\n\n\t\tif ( instance == null )\n\t\t{\n\t\t\tLog.Error( \u0022Instance is null. Ensure it is initialized before using.\u0022 );\n\t\t\treturn;\n\t\t}\n\n\t\tif ( source == null || !source.Any() )\n\t\t{\n\t\t\tLog.Warning( \u0022Source selection is empty or null.\u0022 );\n\t\t\treturn;\n\t\t}\n\n\t\tvar selectedNode = source.OfType\u003CFilesystemTreeNode\u003E().FirstOrDefault();\n\t\tif ( selectedNode == null || selectedNode.Info == null )\n\t\t{\n\t\t\tLog.Warning( \u0022Source selection is not a valid directory.\u0022 );\n\t\t\treturn;\n\t\t}\n\n\t\t// Allow selecting a single image file - use its containing folder\n\t\tDirectoryInfo selectedDir;\n\t\tif ( selectedNode.Info is DirectoryInfo dirInfo )\n\t\t{\n\t\t\tselectedDir = dirInfo;\n\t\t}\n\t\telse if ( selectedNode.Info is FileInfo fileInfo \u0026\u0026 fileInfo.Directory != null )\n\t\t{\n\t\t\tselectedDir = fileInfo.Directory;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tLog.Warning( \u0022Source selection is not a valid directory.\u0022 );\n\t\t\treturn;\n\t\t}\n\n\t\tstring assetsRoot = Project.Current.GetAssetsPath()?.TrimEnd( \u0027\\\\\u0027 ) ?? Path.Combine( Project.Current.GetRootPath(), \u0022Assets\u0022 );\n\t\tvar materialFolders = GetMaterialFolders( selectedDir );\n\n\t\tforeach ( var folder in materialFolders )\n\t\t{\n\t\t\tvar imageFiles = folder.GetFiles()\n\t\t\t\t.Where( f =\u003E ImageFileExtensions.Contains( f.Extension.ToLower() ) )\n\t\t\t\t.ToList();\n\n\t\t\tif ( !imageFiles.Any() )\n\t\t\t{\n\t\t\t\tLog.Warning( $\u0022No valid image files found in {folder.FullName}\u0022 );\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tstring relativeFolderPath = folder.FullName.Replace( assetsRoot \u002B \u0022\\\\\u0022, \u0022\u0022 ).Replace( \u0027\\\\\u0027, \u0027/\u0027 );\n\t\t\tstring materialName = folder.Name;\n\t\t\tstring fileExtension = imageFiles[0].Extension;\n\n\t\t\tforeach ( var imageFile in imageFiles )\n\t\t\t{\n\t\t\t\tstring relativeTexturePath = imageFile.FullName.Replace( assetsRoot \u002B \u0022\\\\\u0022, \u0022\u0022 ).Replace( \u0027\\\\\u0027, \u0027/\u0027 );\n\t\t\t\tif ( !File.Exists( imageFile.FullName ) || Texture.Load( relativeTexturePath ) == null )\n\t\t\t\t{\n\t\t\t\t\tLog.Warning( $\u0022Failed to load texture: {imageFile.FullName}\u0022 );\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tstring outputPath = instance.Output == OutputLocation.ParentFolder\n\t\t\t\t? folder.Parent?.FullName ?? folder.FullName\n\t\t\t\t: folder.FullName;\n\n\t\t\tSaveMaterial( materialName, relativeFolderPath, folder.FullName, fileExtension, outputPath );\n\t\t}\n\t}\n\n\tIEnumerable\u003CDirectoryInfo\u003E GetMaterialFolders( DirectoryInfo directory )\n\t{\n\t\tforeach ( var subDirectory in directory.GetDirectories() )\n\t\t{\n\t\t\tforeach ( var folder in GetMaterialFolders( subDirectory ) )\n\t\t\t{\n\t\t\t\tyield return folder;\n\t\t\t}\n\t\t}\n\n\t\tif ( directory.GetFiles().Any( f =\u003E ImageFileExtensions.Contains( f.Extension.ToLower() ) ) )\n\t\t{\n\t\t\tyield return directory;\n\t\t}\n\t}\n\n\tpublic void SaveMaterial( string materialName, string relativeFolderPath, string folderPath, string destinationExtension, string destinationPath )\n\t{\n\t\tstring TextureRef( string suffix )\n\t\t{\n\t\t\tstring fullFile = Path.Combine( folderPath, suffix \u002B destinationExtension );\n\t\t\treturn File.Exists( fullFile ) ? $\u0022{relativeFolderPath}/{suffix}{destinationExtension}\u0022 : null;\n\t\t}\n\n\t\tstring materialContent = $@\u0022\n\t\tLayer0\n\t\t{{\n\t\t\t\u0022\u0022shader\u0022\u0022 \u0022\u0022{instance.Shader}\u0022\u0022\n\t\t\t{(instance.Color ? (TextureRef( \u0022_color\u0022 ) != null ? $\u0022\\t\\\u0022TextureColor\\\u0022 \\\u0022{TextureRef( \u0022_color\u0022 )}\\\u0022\u0022 : $\u0022\\t\\\u0022TextureColor\\\u0022 \\\u0022materials/default/default_color.tga\\\u0022\u0022) : \u0022\u0022)}\n\t\t\t{(instance.Normal ? (TextureRef( \u0022_normal\u0022 ) != null ? $\u0022\\t\\\u0022TextureNormal\\\u0022 \\\u0022{TextureRef( \u0022_normal\u0022 )}\\\u0022\u0022 : $\u0022\\t\\\u0022TextureNormal\\\u0022 \\\u0022materials/default/default_normal.tga\\\u0022\u0022) : \u0022\u0022)}\n\t\t\t{(instance.Roughness ? (TextureRef( \u0022_rough\u0022 ) != null ? $\u0022\\t\\\u0022TextureRoughness\\\u0022 \\\u0022{TextureRef( \u0022_rough\u0022 )}\\\u0022\u0022 : $\u0022\\t\\\u0022TextureRoughness\\\u0022 \\\u0022materials/default/default_rough.tga\\\u0022\u0022) : \u0022\u0022)}\n\t\t\t{(instance.AmbientOcclusion ? (TextureRef( \u0022_ao\u0022 ) != null ? $\u0022\\t\\\u0022TextureAmbientOcclusion\\\u0022 \\\u0022{TextureRef( \u0022_ao\u0022 )}\\\u0022\u0022 : $\u0022\\t\\\u0022TextureAmbientOcclusion\\\u0022 \\\u0022materials/default/default_ao.tga\\\u0022\u0022) : \u0022\u0022)}\n\n\t\t\t{(instance.Translucent ? $\u0022//---- Translucent ----\u0022 : \u0022\u0022)}\n\t\t\t{(instance.Translucent ? $\u0022F_TRANSLUCENT 1\u0022 : \u0022\u0022)}\n\t\t\t{(instance.Translucent ? $\u0022g_flOpacityScale \\\u00221.000\\\u0022\u0022 : \u0022\u0022)}\n\t\t\t{(instance.Translucent ? (TextureRef( \u0022_trans\u0022 ) != null ? $\u0022\\t\\\u0022TextureTranslucency\\\u0022 \\\u0022{TextureRef( \u0022_trans\u0022 )}\\\u0022\u0022 : $\u0022\\t\\\u0022TextureTranslucency\\\u0022 \\\u0022materials/default/default_trans.tga\\\u0022\u0022) : \u0022\u0022)}\n\t\t}}\n\t\t\u0022;\n\t\tDirectory.CreateDirectory( destinationPath );\n\t\tstring savePath = Path.Combine( destinationPath, instance.OutputFilePrefix\u002BmaterialName \u002B instance.OutputFileSuffix\u002B\u0022.vmat\u0022 );\n\t\tFile.WriteAllText( savePath, materialContent );\n\t}\n\n\n\n\n\tclass FilesystemTreeNode : Editor.TreeNode\n\t{\n\t\tpublic System.IO.FileSystemInfo Info;\n\n\t\tbool IsFolder =\u003E Info is System.IO.DirectoryInfo;\n\n\t\tpublic FilesystemTreeNode( string path )\n\t\t{\n\t\t\tif ( System.IO.Directory.Exists( path ) ) Info = new System.IO.DirectoryInfo( path );\n\t\t\telse if ( System.IO.File.Exists( path ) ) Info = new System.IO.FileInfo( path );\n\t\t\telse throw new Exception( \u0022Invalid path\u0022 );\n\t\t}\n\n\t\tpublic override void OnPaint( Editor.VirtualWidget item )\n\t\t{\n\t\t\tPaintSelection( item );\n\n\t\t\tPaint.SetPen( IsFolder ? Theme.Yellow : Theme.Text );\n\t\t\tPaint.DrawIcon( item.Rect, IsFolder ? \u0022folder\u0022 : \u0022description\u0022, 18, TextFlag.LeftCenter );\n\n\t\t\tPaint.SetPen( Theme.Text );\n\t\t\tPaint.DrawText( item.Rect.Shrink( 24, 0, 0, 0 ), $\u0022{Info.Name}\u0022, TextFlag.LeftCenter );\n\t\t}\n\n\t\tpublic int Order =\u003E Info is System.IO.DirectoryInfo ? 0 : 1;\n\n\t\tprotected override void BuildChildren()\n\t\t{\n\t\t\tif ( Info is not System.IO.DirectoryInfo dirInfo )\n\t\t\t\treturn;\n\n\t\t\tClear();\n\n\t\t\tvar infos = dirInfo.GetFileSystemInfos().Select( x =\u003E new FilesystemTreeNode( x.FullName ) );\n\t\t\tinfos = infos.OrderBy( x =\u003E x.Order ).ThenBy( x =\u003E x.Info.Name );\n\n\t\t\tAddItems( infos );\n\t\t}\n\t}\n}\n"}]}