2323 . Replace ( "bin\\ Debug\\ net8.0" , "" )
2424 . Replace ( "bin\\ Release\\ net8.0" , "" )
2525 . Replace ( "bin\\ Debug" , "" )
26- . Replace ( "bin\\ Release" , "" ) ;
26+ . Replace ( "bin\\ Release" , "" )
27+ . Replace ( "ADOGenerator\\ " , "ADOGenerator\\ " ) ;
2728
2829do
2930{
31+ if ( currentPath . EndsWith ( "ADOGenerator" ) )
32+ currentPath = currentPath + "\\ " ;
3033 string id = Guid . NewGuid ( ) . ToString ( ) . Split ( '-' ) [ 0 ] ;
3134 Console . ForegroundColor = ConsoleColor . Cyan ;
3235 Console . WriteLine ( "Do you want to create a new template or create a new project using the demo generator project template?" ) ;
103106
104107void HandleTemplateAndArtifactsUpdate ( string template , string id , Project model , string currentPath )
105108{
109+ var templatePathBin = Path . Combine ( Directory . GetCurrentDirectory ( ) , "Templates" , "TemplateSetting.json" ) ;
110+ var templatePathOriginal = Path . Combine ( currentPath , "Templates" , "TemplateSetting.json" ) ;
111+ if ( UpdateTemplateSettings ( template , id , templatePathOriginal ) )
112+ {
113+ id . AddMessage ( Environment . NewLine + "Template settings updated successfully at " + templatePathOriginal ) ;
114+ }
115+ else
116+ {
117+ id . ErrorId ( ) . AddMessage ( Environment . NewLine + "Template settings update failed at " + templatePathOriginal ) ;
118+ }
119+ if ( templatePathBin . Equals ( templatePathOriginal ) )
120+ {
121+ id . AddMessage ( Environment . NewLine + "Template path is same as original." ) ;
122+ return ;
123+ }
106124 id . AddMessage ( Environment . NewLine + "Do you want to update the template settings and move the artifacts to the executable directory? (yes/no): press enter to confirm" ) ;
107125 var updateTemplateSettings = Console . ReadLine ( ) ;
108-
109126 if ( string . IsNullOrWhiteSpace ( updateTemplateSettings ) || updateTemplateSettings . Equals ( "yes" , StringComparison . OrdinalIgnoreCase ) || updateTemplateSettings . Equals ( "y" , StringComparison . OrdinalIgnoreCase ) )
110127 {
111128 id . AddMessage ( Environment . NewLine + "Updating template settings..." ) ;
112- var templatePathBin = Path . Combine ( Directory . GetCurrentDirectory ( ) , "Templates" , "TemplateSetting.json" ) ;
113- var templatePathOriginal = Path . Combine ( currentPath , "Templates" , "TemplateSetting.json" ) ;
114-
115- if ( UpdateTemplateSettings ( template , id , templatePathOriginal ) )
116- {
117- id . AddMessage ( Environment . NewLine + "Template settings updated successfully at " + templatePathOriginal ) ;
118- }
119- else
120- {
121- id . ErrorId ( ) . AddMessage ( Environment . NewLine + "Template settings update failed at " + templatePathOriginal ) ;
122- }
123-
129+
124130 CopyFileIfExists ( id , templatePathOriginal , templatePathBin ) ;
125131
126132 id . AddMessage ( Environment . NewLine + "Template settings copied to the current directory and updated successfully." ) ;
127133 id . AddMessage ( Environment . NewLine + "Moving artifacts to the current directory..." ) ;
128134
129135 var artifactsPathOriginal = Path . Combine ( currentPath , "Templates" , $ "CT-{ model . ProjectName . Replace ( " " , "-" ) } ") ;
130136 var artifactsPath = Path . Combine ( Directory . GetCurrentDirectory ( ) , "Templates" , $ "CT-{ model . ProjectName . Replace ( " " , "-" ) } ") ;
131-
137+
132138 MoveArtifacts ( artifactsPathOriginal , artifactsPath , id ) ;
133139 }
134140 else
@@ -139,18 +145,26 @@ void HandleTemplateAndArtifactsUpdate(string template, string id, Project model,
139145
140146void CopyFileIfExists ( string id , string sourcePath , string destinationPath )
141147{
142- if ( File . Exists ( sourcePath ) )
148+ try
143149 {
144- File . Copy ( sourcePath , destinationPath , true ) ;
150+ if ( File . Exists ( sourcePath ) )
151+ {
152+ File . Copy ( sourcePath , destinationPath , true ) ;
153+ }
154+ else
155+ {
156+ Console . ForegroundColor = ConsoleColor . Green ;
157+ id . AddMessage ( Environment . NewLine + $ "Source file '{ sourcePath } ' does not exist. Creating a new file at the destination.") ;
158+ string fileContents = File . ReadAllText ( sourcePath ) ;
159+ File . WriteAllText ( destinationPath , fileContents ) ;
160+ id . AddMessage ( Environment . NewLine + $ "New file created at '{ destinationPath } '.") ;
161+ Console . ResetColor ( ) ;
162+ }
145163 }
146- else
164+ catch ( Exception ex )
147165 {
148- Console . ForegroundColor = ConsoleColor . Green ;
149- id . AddMessage ( Environment . NewLine + $ "Source file '{ sourcePath } ' does not exist. Creating a new file at the destination.") ;
150- string fileContents = File . ReadAllText ( sourcePath ) ;
151- File . WriteAllText ( destinationPath , fileContents ) ;
152- id . AddMessage ( Environment . NewLine + $ "New file created at '{ destinationPath } '.") ;
153- Console . ResetColor ( ) ;
166+ id . ErrorId ( ) . AddMessage ( Environment . NewLine + "Error copying file: " + ex . Message ) ;
167+ return ;
154168 }
155169}
156170
0 commit comments