internal static void GetBMEInfo(string file) { var commands = new Dictionary <string, string>(); foreach (var line in File.ReadLines(file)) { if (!line.StartsWith("#")) { continue; } var command = line.ToUpper().Substring(1).Split(" ").ToList(); if (command.Count > 1) { commands.Add(command[0], string.Join(" ", command.GetRange(1, command.Count - 1))); } } if (commands["PLAYER"] == "1") { SongInfo songInfo = new SongInfo(); songInfo.Artist = commands["ARTIST"]; songInfo.BPM = float.Parse(commands["BPM"]); songInfo.Difficulty = (Difficulty)int.Parse(commands["DIFFICULTY"]); songInfo.Genre = commands["GENRE"]; songInfo.Path = file; songInfo.PlayLevel = byte.Parse(commands["PLAYLEVEL"]); songInfo.Title = commands["TITLE"]; songInfo.Total = float.Parse(commands["TOTAL"]); Songs.Add(songInfo); } }
public static void HtmlScoring(string text) //Outputs input above "</ul>" { string location = @"C:\\Dynamix\\score_report.html"; string lineToFind = " <!--correct-->"; List <string> lines = File.ReadLines(location).ToList(); int index = lines.IndexOf(lineToFind); lines.Insert(index, "<li>" + text + "</li>"); File.WriteAllLines(location, lines); Console.WriteLine(text); //Just a debug }
/// <summary> /// Reads file contents as text line by line. /// </summary> /// <param name="path">The path of the file.</param> /// <param name="encoding">The encoding to use.</param> /// <returns> /// An enumerable of strings, each representing one line of text. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="path" /> is <see langword="null" /> (<see langword="Nothing" /> in Visual Basic). /// </exception> /// <remarks> /// This operation always requires an encoding to be used. If <paramref name="encoding" /> is set to /// <see langword="null" />, an implementation-specific /// encoding will be used. /// </remarks> public IEnumerable <string> ReadLines( string path, Encoding?encoding = null) { _ = Requires.NotNullOrWhiteSpace( path, nameof(path)); return(encoding == null ? FSFile.ReadLines(path) : FSFile.ReadLines( path, encoding)); }
public static void EditHTML() { string location = @"C:\Dynamix\score_report.html"; string lineToFind = " <!--issues-->"; List <string> lines = File.ReadLines(location).ToList(); int index = lines.IndexOf(lineToFind); lines.Insert(index, "<li class=\"issuesTitle\">Security Issues (" + currentVulns + " out of " + TotalVulns() + " resolved)</li>"); File.WriteAllLines(location, lines); string lineToFind2 = " <!--scored-->"; int index2 = lines.IndexOf(lineToFind2); lines.Insert(index, "<li>" + currentVulns + " out of " + TotalVulns() + " security issues resolved</li>"); File.WriteAllLines(location, lines); currentVulns = 0; }
/// <summary> /// /// </summary> /// <param name="fileName"></param> /// <returns></returns> private static Dictionary <string, Dictionary <string, string> > loadIniFile(string fileName) { Dictionary <string, Dictionary <string, string> > sectionContents = new Dictionary <string, Dictionary <string, string> >(); var fileContent = File.ReadLines(fileName); Dictionary <string, string> sectionContent = null; foreach (string content in fileContent) { if (string.IsNullOrEmpty(content)) { continue; } if (regularExpressionSectionName.Match(content).Success) { string section = regularExpressionSectionName.Match(content).Groups[2].Value; if (!sectionContents.TryGetValue(section, out sectionContent)) { sectionContent = new Dictionary <string, string>(); sectionContents[section] = sectionContent; } continue; } if (sectionContent == null) { continue; } // キーと値の「~=~」の判定 if (regularExpressionKeyValue.Match(content).Success) { string key = regularExpressionKeyValue.Match(content).Groups[1].Value; string value = regularExpressionKeyValue.Match(content).Groups[3].Value; sectionContent[key] = value; } } return(sectionContents); }
public IEnumerable <string> ReadLines([NotNull] Encoding encoding) => F.ReadLines(this.FullName, encoding);
public IEnumerable <string> ReadLines() => F.ReadLines(this.FullName);
public static void ConvertJSON(string path) { if (File.Exists(path)) { try { int totalLines = File.ReadLines(path).Count(); string jsonPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Employees.json"); using (StreamReader fileReader = File.OpenText(path)) { string title = Path.GetFileNameWithoutExtension(path).ToLower(); string line; string[] titles = new string[] { }; int counter = 0; //using (StreamWriter fileWriter = File.CreateText(jsonPath)) using (StreamWriter fileWriter = File.CreateText(jsonPath + "/" + title + ".json")) { //apriamo le parentesi fileWriter.WriteLine("{"); fileWriter.WriteLine("\"" + title + "\":["); while ((line = fileReader.ReadLine()) != null) { if (counter == 0) { line = line.ToLower(); titles = line.Split(","); counter++; } else { string[] data = new string[] { }; data = line.Split(","); fileWriter.Write("{"); for (int i = 0; i < titles.Length; i++) { if (i == title.Length - 1) // se è l'ultimo { fileWriter.Write("\"" + titles[i] + "\":\"" + data[i] + "\""); } else { fileWriter.Write("\"" + titles[i] + "\":\"" + data[i] + "\","); } } if (counter != totalLines - 1) // se non è l'ultima riga { fileWriter.Write("},\n"); } else { fileWriter.Write("}\n"); } } } fileWriter.WriteLine("]}"); } } } catch (Exception e) { Console.WriteLine(e.Message); } } }
public static int TotalVulns() { int lineCount = File.ReadLines(@"C:\Dynamix\answers.xml").Count(); return(lineCount - 3); }
public static bool LoadMaps(string mapPath) { EventLogMaps = new Dictionary <string, EventLogMap>(); /* var f = new DirectoryEnumerationFilters(); * f.InclusionFilter = fsei => fsei.Extension.ToUpperInvariant() == ".MAP"; * * f.RecursionFilter = null; //entryInfo => !entryInfo.IsMountPoint && !entryInfo.IsSymbolicLink; * * f.ErrorFilter = (errorCode, errorMessage, pathProcessed) => true;*/ /* var dirEnumOptions = * DirectoryEnumerationOptions.Files | * DirectoryEnumerationOptions.SkipReparsePoints | DirectoryEnumerationOptions.ContinueOnException | * DirectoryEnumerationOptions.BasicSearch;*/ var mapFiles = Directory.EnumerateFileSystemEntries(mapPath, "*.map").ToList(); var l = LogManager.GetLogger("LoadMaps"); var deserializer = new DeserializerBuilder() .Build(); var validator = new EventLogMapValidator(); var errorMaps = new List <string>(); foreach (var mapFile in mapFiles.OrderBy(t => t)) { try { var eventMapFile = deserializer.Deserialize <EventLogMap>(File.ReadAllText(mapFile)); l.Trace(eventMapFile.Dump); var validate = validator.Validate(eventMapFile); if (DisplayValidationResults(validate, mapFile)) { if (EventLogMaps.ContainsKey( $"{eventMapFile.EventId}-{eventMapFile.Channel.ToUpperInvariant()}") == false) { l.Debug($"'{Path.GetFileName(mapFile)}' is valid. Adding to maps..."); EventLogMaps.Add($"{eventMapFile.EventId}-{eventMapFile.Channel.ToUpperInvariant()}", eventMapFile); } else { l.Warn( $"A map for event id '{eventMapFile.EventId}' with Channel '{eventMapFile.Channel}' already exists. Map '{Path.GetFileName(mapFile)}' will be skipped"); } } else { errorMaps.Add(Path.GetFileName(mapFile)); } } catch (SyntaxErrorException se) { errorMaps.Add(Path.GetFileName(mapFile)); Console.WriteLine(); l.Warn($"Syntax error in '{mapFile}':"); l.Fatal(se.Message); var lines = File.ReadLines(mapFile).ToList(); var fileContents = mapFile.ReadAllText(); var badLine = lines[se.Start.Line - 1]; Console.WriteLine(); l.Fatal( $"Bad line (or close to it) '{badLine}' has invalid data at column '{se.Start.Column}'"); if (fileContents.Contains('\t')) { Console.WriteLine(); l.Error( "Bad line contains one or more tab characters. Replace them with spaces"); Console.WriteLine(); l.Info(fileContents.Replace("\t", "<TAB>")); } } catch (YamlException ye) { errorMaps.Add(Path.GetFileName(mapFile)); Console.WriteLine(); l.Warn($"Syntax error in '{mapFile}':"); var fileContents = mapFile.ReadAllText(); l.Info(fileContents); if (ye.InnerException != null) { l.Fatal(ye.InnerException.Message); } Console.WriteLine(); l.Fatal("Verify all properties against example files or manual and try again."); } catch (Exception e) { l.Error($"Error loading map file '{mapFile}': {e.Message}"); } } if (errorMaps.Count > 0) { l.Error("\r\nThe following maps had errors. Scroll up to review errors, correct them, and try again."); foreach (var errorMap in errorMaps) { l.Info(errorMap); } l.Info(""); } return(errorMaps.Count > 0); }
internal static SongData GetBMEData(SongInfo info) { var file = info.Path; var data = new SongData(); data.TimeSections = new List <TimeSection>(); data.Audio = new Dictionary <int, Source>(); var lines = new List <string> [1000]; var path = Directory.GetParent(file); foreach (var line in File.ReadLines(file)) { if (!line.StartsWith("#")) { continue; } if (int.TryParse(line.Substring(1, 3), out var barIndex)) { if (lines[barIndex] == null) { lines[barIndex] = new List <string>(); } lines[barIndex].Add(line); } else if (line.StartsWith("#WAV")) { var audio = $"{path}\\{line.Substring(7)}"; if (!File.Exists(audio)) { if (!File.Exists($"{Directory.GetParent(audio)}\\{Path.GetFileNameWithoutExtension(audio)}.ogg")) { continue; } audio = $"{Directory.GetParent(audio)}\\{Path.GetFileNameWithoutExtension(audio)}.ogg"; } Program.Log($"Loading audio file : {audio}"); data.Audio.Add(line.Substring(4, 2).FromBase36(), Resource.NewSource(audio, SourceType.Static)); } } foreach (var lineGroup in lines) { if (lineGroup == null) { continue; } var timeSection = new TimeSection(0); foreach (var line in lineGroup) { var measure = int.Parse(line.Substring(1, 3)); var channel = (Channel)line.Substring(4, 2).FromBase16(); if (channel == Channel.BGM) { var split = line.Substring(7).Split(2); for (var index = 0; index < split.Length; index++) { var audio = split[index]; if (audio.FromBase36() > 0) { timeSection.BGM.Add(new TimedAudio((measure + (float)index / (split.Length)).BarToSeconds(info.BPM), data.Audio[audio.FromBase36()].Clone())); } } } if (channel >= Channel.P1Key1 && channel <= Channel.P1Key7) { var split = line.Substring(7).Split(2); for (var index = 0; index < split.Length; index++) { var audio = split[index]; if (audio.FromBase36() > 0) { timeSection.Notes.Add(new Note((measure + (float)index / (split.Length)).BarToSeconds(info.BPM), channel.ToLane(), data.Audio[audio.FromBase36()].Clone(), true)); } } } } data.TimeSections.Add(timeSection); } return(data); }