@@ -168,21 +168,33 @@ static string cleanup(string _, string val)
168
168
169
169
public static IEnumerable < ComfyUIAPIAbstractBackend > RunningComfyBackends => Program . Backends . RunningBackendsOfType < ComfyUIAPIAbstractBackend > ( ) ;
170
170
171
+ public static string [ ] ExampleWorkflowNames ;
172
+
171
173
public void LoadWorkflowFiles ( )
172
174
{
173
175
CustomWorkflows . Clear ( ) ;
174
- if ( Directory . Exists ( $ "{ FilePath } /CustomWorkflows") )
176
+ Directory . CreateDirectory ( $ "{ FilePath } /CustomWorkflows") ;
177
+ Directory . CreateDirectory ( $ "{ FilePath } /CustomWorkflows/Examples") ;
178
+ string [ ] getCustomFlows ( string path ) => [ .. Directory . EnumerateFiles ( $ "{ FilePath } /{ path } ", "*.*" , new EnumerationOptions ( ) { RecurseSubdirectories = true } ) . Select ( f => f . Replace ( '\\ ' , '/' ) . After ( $ "/{ path } /") ) . Order ( ) ] ;
179
+ ExampleWorkflowNames = getCustomFlows ( "ExampleWorkflows" ) ;
180
+ string [ ] customFlows = getCustomFlows ( "CustomWorkflows" ) ;
181
+ bool anyCopied = false ;
182
+ foreach ( string workflow in ExampleWorkflowNames . Where ( f => f . EndsWith ( ".json" ) ) )
175
183
{
176
- foreach ( string workflow in Directory . EnumerateFiles ( $ "{ FilePath } /CustomWorkflows" , "*.json" , new EnumerationOptions ( ) { RecurseSubdirectories = true } ) . Order ( ) )
184
+ if ( ! customFlows . Contains ( $ "Examples/ { workflow } " ) && ! customFlows . Contains ( $ "Examples/ { workflow } .deleted" ) )
177
185
{
178
- string fileName = workflow . Replace ( '\\ ' , '/' ) . After ( "/CustomWorkflows/" ) ;
179
- if ( fileName . EndsWith ( ".json" ) )
180
- {
181
- string name = fileName . BeforeLast ( '.' ) ;
182
- CustomWorkflows . TryAdd ( name , null ) ;
183
- }
186
+ File . Copy ( $ "{ FilePath } /ExampleWorkflows/{ workflow } ", $ "{ FilePath } /CustomWorkflows/Examples/{ workflow } ") ;
187
+ anyCopied = true ;
184
188
}
185
189
}
190
+ if ( anyCopied )
191
+ {
192
+ customFlows = getCustomFlows ( "CustomWorkflows" ) ;
193
+ }
194
+ foreach ( string workflow in customFlows . Where ( f => f . EndsWith ( ".json" ) ) )
195
+ {
196
+ CustomWorkflows . TryAdd ( workflow . BeforeLast ( '.' ) , null ) ;
197
+ }
186
198
}
187
199
188
200
public static ComfyCustomWorkflow GetWorkflowByName ( string name )
0 commit comments