public TransformConverter(string fileName) { if (!File.Exists(fileName)) { throw new FileNotFoundException(string.Format("Transformer file({0}) not found", fileName)); } try { _file = TransformerFile.Load(fileName); } catch { throw new Exception(string.Format("Failed to parse transformer file: {0}", fileName)); } }
public static TransformerFile Load(string fileName) { if (!File.Exists(fileName)) { throw new FileNotFoundException("Can't find transformer file..."); } var file = new TransformerFile(); var stream = File.OpenRead(fileName); var reader = new StreamReader(stream); string line = ""; int i = 0; while ((line = reader.ReadLine()) != null) { i++; if (line.Contains("#")) { line = line.Substring(0, line.IndexOf("#")); } if (line.Length <= 0) { continue; } var parts = line.Split(new[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries); if (parts.Length > 2) { Console.WriteLine("[ERROR] Invalid config file line {0}", i); continue; } var modifier = new Modifier(); modifier.AccessTarget = parts[0].Trim(); var descriptor = parts[1].Trim().Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries); if (descriptor.Length == 1) { modifier.ModifyClassVisibility = true; } else { var nameReference = descriptor[1].Trim(); int parenIdx = nameReference.IndexOf('('); if (parenIdx > 0) { modifier.Desc = nameReference.Substring(parenIdx); modifier.Name = nameReference.Substring(0, parenIdx); } else { modifier.Name = nameReference; } } modifier.Descriptor = descriptor[0].Trim(); file.Modifiers.Add(modifier); } reader.Close(); reader.Dispose(); stream.Close(); stream.Dispose(); return file; }