@@ -27,8 +27,8 @@ internal static class Global
27
27
{
28
28
public static IConfigurationRoot Configuration ;
29
29
30
- public static string WatchedCodeExtension = "cs" ;
31
- public static string WatchedResXExtension = "resx" ;
30
+ public static List < string > WatchedCodeExtension = new List < string > ( ) { "cs" } ;
31
+ public static List < string > WatchedResXExtension = new List < string > ( ) { "resx" } ;
32
32
33
33
public static List < string > ExcludedExtensions = new List < string > ( ) { "*~" , "tmp" } ;
34
34
public static List < string > IgnorePathsStartingWith = new List < string > ( ) ;
@@ -114,8 +114,8 @@ private static void Main()
114
114
Global . AsyncPath = fileConfig [ "AsyncPath" ] ;
115
115
Global . SyncPath = fileConfig [ "SyncPath" ] ;
116
116
117
- Global . WatchedCodeExtension = fileConfig [ "WatchedCodeExtension" ] ;
118
- Global . WatchedResXExtension = fileConfig [ "WatchedResXExtension" ] ;
117
+ Global . WatchedCodeExtension = fileConfig . GetSection ( "WatchedCodeExtension" ) . GetChildren ( ) . Select ( c => c . Value . ToUpperInvariant ( ) ) . ToList ( ) ;
118
+ Global . WatchedResXExtension = fileConfig . GetSection ( "WatchedResXExtension" ) . GetChildren ( ) . Select ( c => c . Value . ToUpperInvariant ( ) ) . ToList ( ) ;
119
119
120
120
//this would need Microsoft.Extensions.Configuration and Microsoft.Extensions.Configuration.Binder packages
121
121
//Global.ExcludedExtensions = fileConfig.GetSection("ExcludedExtensions").Get<string[]>();
@@ -191,21 +191,19 @@ private static async Task MainTask()
191
191
192
192
193
193
//1. Do initial synchronisation from sync to async folder //TODO: config for enabling and ordering of this operation
194
- foreach ( var fileInfo in ProcessSubDirs ( new DirectoryInfo ( Global . SyncPath ) , "*." + Global . WatchedCodeExtension ) )
194
+ foreach ( var fileInfo in ProcessSubDirs ( new DirectoryInfo ( Global . SyncPath ) , "*.*" ) ) //NB! use *.* in order to sync resx files also
195
195
{
196
- {
197
- await ConsoleWatch . OnAddedAsync
198
- (
199
- new DummyFileSystemEvent ( fileInfo ) ,
200
- new CancellationToken ( )
201
- ) ;
202
- }
196
+ await ConsoleWatch . OnAddedAsync
197
+ (
198
+ new DummyFileSystemEvent ( fileInfo ) ,
199
+ new CancellationToken ( )
200
+ ) ;
203
201
}
204
202
205
203
if ( Global . Bidirectional )
206
204
{
207
205
//2. Do initial synchronisation from async to sync folder //TODO: config for enabling and ordering of this operation
208
- foreach ( var fileInfo in ProcessSubDirs ( new DirectoryInfo ( Global . AsyncPath ) , "*." + Global . WatchedCodeExtension ) )
206
+ foreach ( var fileInfo in ProcessSubDirs ( new DirectoryInfo ( Global . AsyncPath ) , "*.*" ) ) //NB! use *.* in order to sync resx files also
209
207
{
210
208
await ConsoleWatch . OnAddedAsync
211
209
(
@@ -535,9 +533,11 @@ public static async Task FileUpdated(string fullName, Context context)
535
533
var otherFullName = GetOtherFullName ( fullName ) ;
536
534
using ( await Global . FileOperationLocks . LockAsync ( fullName , otherFullName , context . Token ) )
537
535
{
536
+ var fullNameInvariant = fullName . ToUpperInvariant ( ) ;
537
+
538
538
if (
539
- fullName . EndsWith ( "." + Global . WatchedCodeExtension )
540
- || Global . WatchedCodeExtension == "*"
539
+ Global . WatchedCodeExtension . Any ( x => fullNameInvariant . EndsWith ( "." + x . ToUpperInvariant ( ) ) )
540
+ || Global . WatchedCodeExtension . Contains ( "*" )
541
541
)
542
542
{
543
543
if ( fullName . ToUpperInvariant ( ) . StartsWith ( Global . AsyncPath . ToUpperInvariant ( ) ) )
@@ -604,10 +604,10 @@ private static bool IsWatchedFile(string fullName)
604
604
605
605
if (
606
606
(
607
- fullNameInvariant . EndsWith ( "." + Global . WatchedCodeExtension . ToUpperInvariant ( ) )
608
- || fullNameInvariant . EndsWith ( "." + Global . WatchedResXExtension . ToUpperInvariant ( ) )
609
- || Global . WatchedCodeExtension == "*"
610
- || Global . WatchedResXExtension == "*"
607
+ Global . WatchedCodeExtension . Any ( x => fullNameInvariant . EndsWith ( "." + x . ToUpperInvariant ( ) ) )
608
+ || Global . WatchedResXExtension . Any ( x => fullNameInvariant . EndsWith ( "." + x . ToUpperInvariant ( ) ) )
609
+ || Global . WatchedCodeExtension . Contains ( "*" )
610
+ || Global . WatchedResXExtension . Contains ( "*" )
611
611
)
612
612
&&
613
613
Global . ExcludedExtensions . All ( x =>
@@ -812,7 +812,7 @@ public static async Task SaveFileModifications(string fullName, string fileData,
812
812
//NB! detect whether the file actually changed
813
813
var otherFileData = File . Exists ( otherFullName )
814
814
//@"\\?\" prefix is needed for reading from long paths: https://stackoverflow.com/questions/44888844/directorynotfoundexception-when-using-long-paths-in-net-4-7
815
- ? await FileExtensions . ReadAllTextAsync ( @"\\?\" + otherFullName , context . Token )
815
+ ? await FileExtensions . ReadAllTextAsync ( @"\\?\" + otherFullName , context . Token ) //TODO: optimisation: no need to read the bytes in case the file lenghts are different
816
816
: null ;
817
817
818
818
if (
@@ -861,7 +861,7 @@ public static async Task SaveFileModifications(string fullName, byte[] fileData,
861
861
//NB! detect whether the file actually changed
862
862
var otherFileData = File . Exists ( otherFullName )
863
863
//@"\\?\" prefix is needed for reading from long paths: https://stackoverflow.com/questions/44888844/directorynotfoundexception-when-using-long-paths-in-net-4-7
864
- ? await FileExtensions . ReadAllBytesAsync ( @"\\?\" + otherFullName , context . Token )
864
+ ? await FileExtensions . ReadAllBytesAsync ( @"\\?\" + otherFullName , context . Token ) //TODO: optimisation: no need to read the bytes in case the file lenghts are different
865
865
: null ;
866
866
867
867
if (
0 commit comments