1010using System . Diagnostics ;
1111using System . IO ;
1212using System . Linq ;
13+ using System . Reflection ;
1314using System . Text ;
1415using System . Text . RegularExpressions ;
1516using System . Windows ;
@@ -2128,8 +2129,10 @@ private void ExportToVisualStudio_Click(object sender, RoutedEventArgs e)
21282129 string projectFile = Path . Combine ( projectDirectory , $ "{ projectName } .csproj") ;
21292130 string entryFile = Path . Combine ( projectDirectory , "Program.cs" ) ;
21302131 string replaceFile = Path . Combine ( projectDirectory , "CSharpReplaceContainer.cs" ) ;
2131- string textSourceFile = Path . Combine ( projectDirectory , "TextSourceContainer.cs" ) ;
2132+ string csharpTextSourceFile = Path . Combine ( projectDirectory , "TextSourceContainer.cs" ) ;
2133+ string textSourceFile = Path . Combine ( projectDirectory , "TextSource.txt" ) ;
21322134 string projectGuid = Guid . NewGuid ( ) . ToString ( ) ;
2135+ string resourcesForCsProj = string . Empty ;
21332136 string options = regExOptionViewModelsList . Count ( option => option . Selected ) == 0
21342137 ? "RegexOptions.None"
21352138 : string . Join ( " | " ,
@@ -2145,6 +2148,33 @@ private void ExportToVisualStudio_Click(object sender, RoutedEventArgs e)
21452148
21462149 Directory . CreateDirectory ( projectDirectory ) ;
21472150
2151+ if ( Config . Instance . CSharpReplaceMode )
2152+ {
2153+ File . WriteAllText ( replaceFile , ReplaceScriptForMatch ) ;
2154+ }
2155+
2156+ // Write text source as specific cs file if in CSharpScript
2157+ if ( Config . Instance . TextSourceOn == RegexTextSource . CSharpScript )
2158+ {
2159+ File . WriteAllText ( csharpTextSourceFile , CSharpTextSourceScript ) ;
2160+ }
2161+ // Write text source as text file in resources
2162+ else
2163+ {
2164+ File . WriteAllText ( textSourceFile , GetCurrentText ( ) ) ;
2165+ resourcesForCsProj += Res . TextSourceAsResourceInCsProj ;
2166+ }
2167+
2168+ // Write Entry file
2169+ if ( ! File . Exists ( entryFile )
2170+ || MessageBox . Show ( $ "The entry file \" { entryFile } \" already exists.\r \n Do you want to override it ?",
2171+ "Entry file override" ,
2172+ MessageBoxButton . YesNo ,
2173+ MessageBoxImage . Question ) == MessageBoxResult . Yes )
2174+ {
2175+ File . WriteAllText ( entryFile , programCode ) ;
2176+ }
2177+
21482178 // Write solution file
21492179 if ( ! File . Exists ( projectFile )
21502180 || MessageBox . Show ( $ "The solution file \" { solutionFile } \" already exists.\r \n Do you want to override it ?",
@@ -2167,27 +2197,8 @@ private void ExportToVisualStudio_Click(object sender, RoutedEventArgs e)
21672197 MessageBoxButton . YesNo ,
21682198 MessageBoxImage . Question ) == MessageBoxResult . Yes )
21692199 {
2170- File . WriteAllText ( projectFile , Res . VSProject ) ;
2171- }
2172-
2173- if ( Config . Instance . CSharpReplaceMode )
2174- {
2175- File . WriteAllText ( replaceFile , ReplaceScriptForMatch ) ;
2176- }
2177-
2178- if ( Config . Instance . TextSourceOn == RegexTextSource . CSharpScript )
2179- {
2180- File . WriteAllText ( textSourceFile , CSharpTextSourceScript ) ;
2181- }
2182-
2183- // Write Entry file
2184- if ( ! File . Exists ( entryFile )
2185- || MessageBox . Show ( $ "The entry file \" { entryFile } \" already exists.\r \n Do you want to override it ?",
2186- "Entry file override" ,
2187- MessageBoxButton . YesNo ,
2188- MessageBoxImage . Question ) == MessageBoxResult . Yes )
2189- {
2190- File . WriteAllText ( entryFile , programCode ) ;
2200+ File . WriteAllText ( projectFile , Res . VSProject
2201+ . Replace ( "<!-- Resources -->" , resourcesForCsProj ) ) ;
21912202 }
21922203
21932204 Process . Start ( $ "\" { solutionFile } \" ") ;
0 commit comments