public void Collect() { if (String.IsNullOrEmpty(sourceDir)) { return; } DirectoryInfo di = new DirectoryInfo(sourceDir); FileInfo[] infos = di.GetFiles(); if (infos.Length == 0) { return; } string extension; AppResourceFileInfo arfi; AppResourceFileKind kind; foreach (FileInfo fi in infos) { extension = fi.Extension; if (Acceptable(extension, out kind)) { arfi = new AppResourceFileInfo(fi, kind); } else { continue; } files.Add(arfi); } if (isGlobal && files.Count == 0) { return; } AppResourcesLengthComparer <AppResourceFileInfo> lcFiles = new AppResourcesLengthComparer <AppResourceFileInfo> (); files.Sort(lcFiles); }
List <string>[] GroupGlobalFiles() { List <AppResourceFileInfo> files = this.files.Files; List <List <string> > groups = new List <List <string> > (); AppResourcesLengthComparer <List <string> > lcList = new AppResourcesLengthComparer <List <string> > (); string tmp, s, basename; uint basedots, filedots; AppResourceFileInfo defaultFile; foreach (AppResourceFileInfo arfi in files) { if (arfi.Kind != AppResourceFileKind.ResX && arfi.Kind != AppResourceFileKind.Resource) { continue; } s = arfi.Info.FullName; basename = Path.GetFileNameWithoutExtension(s); basedots = CountChars('.', basename); defaultFile = null; // If there are any files that start with this baseName, we have a default file foreach (AppResourceFileInfo fi in files) { if (fi.Seen) { continue; } string s2 = fi.Info.FullName; if (s2 == null || s == s2) { continue; } tmp = Path.GetFileNameWithoutExtension(s2); filedots = CountChars('.', tmp); if (filedots == basedots + 1 && tmp.StartsWith(basename)) { if (IsFileCultureValid(s2) != null) { // A valid translated file for this name defaultFile = arfi; break; } else { // This file shares the base name, but the culture is invalid - we must // ignore it since the name of the generated strongly typed class for this // resource will clash with the one generated from the default file with // the given basename. fi.Seen = true; } } } if (defaultFile != null) { List <string> al = new List <string> (); al.Add(GetResourceFile(arfi, false)); arfi.Seen = true; groups.Add(al); } } groups.Sort(lcList); string tmp2; // Now find their translated counterparts foreach (List <string> al in groups) { s = al [0]; tmp = Path.GetFileNameWithoutExtension(s); if (tmp.StartsWith("Resources.")) { tmp = tmp.Substring(10); } foreach (AppResourceFileInfo arfi in files) { if (arfi.Seen) { continue; } s = arfi.Info.FullName; if (s == null) { continue; } tmp2 = arfi.Info.Name; if (tmp2.StartsWith(tmp)) { al.Add(GetResourceFile(arfi, false)); arfi.Seen = true; } } } // Anything that's left here might be orphans or lone default files. // For those files we check the part following the last dot // before the .resx/.resource extensions and test whether it's a registered // culture or not. If it is not a culture, then we have a // default file that doesn't have any translations. Otherwise, // the file is ignored (it's the same thing MS.NET does) foreach (AppResourceFileInfo arfi in files) { if (arfi.Seen) { continue; } if (IsFileCultureValid(arfi.Info.FullName) != null) { continue; // Culture found, we reject the file } // A single default file, create a group List <string> al = new List <string> (); al.Add(GetResourceFile(arfi, false)); groups.Add(al); } groups.Sort(lcList); return(groups.ToArray()); }