public ResourceFile(string filename) { if (!File.Exists(filename)) { throw new Exception("File not found or invalid filename specified"); } FilePath = filename; Entries = new List <ResourceFileEntry>(); string parserType = SupportedFileTypes.ParserToUse(filename); switch (parserType) { case ".resx": ResXFile tempResX = new ResXFile(filename); foreach (ResourceFileEntry cfe in tempResX.Entries) { Entries.Add(cfe); } break; case ".strings": AppleStringsFile tempAppleStringsFile = new AppleStringsFile(filename); foreach (ResourceFileEntry cfe in tempAppleStringsFile.Entries) { Entries.Add(cfe); } break; default: throw new Exception("FileType not supported"); } }
static void Main(string[] args) { CustomFormatConsoleTraceListener traceListener = new CustomFormatConsoleTraceListener(); Trace.AutoFlush = true; Trace.Listeners.Add(traceListener); if (args.Length != 2) { Trace.TraceError("Usage is ResourceStaticAnalysisExecutor.exe <Rules Path directory> <Path to file to be scanned>"); return; } string checksDirectory = args[0]; if (Directory.Exists(checksDirectory)) { if ( Directory.GetFiles(checksDirectory) .Any( fileName => Path.GetExtension(fileName).Equals(".dll", StringComparison.CurrentCultureIgnoreCase)) == false) { Trace.TraceError("Cannot find dll with compiled rules"); return; } } else { Trace.TraceError("Cannot find the Rules Path directory"); return; } string file = args[1]; if (!File.Exists(file)) { Trace.TraceError("Cannot find file to be scanned: {0}", file); return; } FileInfo fi = new FileInfo(file); string outputDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "ResourceStaticAnalysisOutput" + fi.DirectoryName.Remove(0, 2)); string outputFile = Path.Combine(outputDirectory, fi.Name + ".xml"); // Write configuration to Console Trace.TraceInformation("checksDirectory={0}", checksDirectory); Trace.TraceInformation("FileToBeScanned={0}", file); Trace.TraceInformation("OutputFile={0}", outputFile); try { if (!Directory.GetFiles(checksDirectory).Any(assembly => assembly.EndsWith(".dll") || assembly.EndsWith(".exe"))) { Trace.TraceError("Checks directory does not contain a rules assembly: {0}", checksDirectory); return; } } catch (Exception ex) { Trace.TraceError("Failed to validate rules assemblies in {0}. Exception:{1}", checksDirectory, ex.ToString()); return; } bool parserAvailable = !string.IsNullOrEmpty(SupportedFileTypes.ParserToUse(file)); if (parserAvailable) { try { ResourceStaticAnalysisApplication ResourceStaticAnalysisApplication = ResourceStaticAnalysisApplication.Instance; List <Exception> exceptions = new List <Exception>(); ResourceStaticAnalysisApplication.Initialize(new List <string>() { checksDirectory }); ResourceStaticAnalysisApplication.ConfigureOutput(outputFile); ResourceStaticAnalysisApplication.Execute(file, true, out exceptions); if (exceptions != null) { foreach (Exception ex in exceptions) { Trace.TraceError("{0}", ex.ToString()); } return; } } catch (Exception ex) { Trace.TraceError("Exception implementing ResourceStaticAnalysisApplication", ex.ToString()); return; } } else { Trace.TraceError("Unsupported File Type"); } }