static OutputInfo AnalyzeLatestNetLogData() { string[] netLogFolders = System.IO.Directory.GetDirectories(@"C:\Riot Games\League of Legends\Logs\GameLogs"); DateTime latestDate = new DateTime(0); string latestFolder = ""; foreach (string folder in netLogFolders) { //Console.WriteLine(folder); //string[] folderFiles = Directory.GetFiles(folder); string lastDirectory = new DirectoryInfo(folder).Name; //Console.WriteLine(lastDirectory); DateTime gameDate = DateTime.ParseExact(lastDirectory, "yyyy-MM-ddTHH-mm-ss", CultureInfo.InvariantCulture); //Console.WriteLine(gameDate.ToString()); if (gameDate > latestDate) { latestDate = gameDate; latestFolder = folder; } //Console.WriteLine(gameDate.ToString("yyyy-MM-dd")); } if (!String.IsNullOrEmpty(latestFolder)) { //Console.WriteLine($"Ping data from latest game:"); Console.WriteLine($"Analyzing ping data from latest game on {latestDate.ToString("yyyy-MM-dd")}"); List <PingData> pingDatas = AnalyzeNetworkData(GetNetLogContents(latestFolder)); OutputInfo outputInfo = new OutputInfo { GameDate = latestDate, PingDatas = pingDatas }; Console.WriteLine("Ping data analyzed!"); return(outputInfo); } else { Console.WriteLine("No network data available to analyze!"); return(null); } }
static string CreateOutputPage(OutputInfo outputInfo) { string htmlBase = $"<h1>Ping Data for League of Legends game on {outputInfo.GameDate.ToString("g", CultureInfo.CreateSpecificCulture("en-US"))}</h1>"; htmlBase += "<table>"; htmlBase += "<tr><th>Time (min)</th><th>Ping (ms)</th></tr>"; foreach (var pingData in outputInfo.PingDatas) { htmlBase += $"<tr><td>{pingData.Time.ToString(@"mm\:ss" , new CultureInfo("en-US"))}</td><td>{pingData.Ping}</td></tr>"; } htmlBase += "</table>"; string currDir = Directory.GetCurrentDirectory(); string outputDirectory = Path.Combine(currDir, "Output"); try { if (!Directory.Exists(outputDirectory)) { Directory.CreateDirectory(outputDirectory); } string outputFile = Path.Combine(outputDirectory, "ping_data.html"); File.WriteAllText(outputFile, htmlBase); //Console.WriteLine(projectDirectory); return(outputFile); } catch (Exception e) { Console.WriteLine($"The process failed: {e.ToString()}"); return(""); } }
static void Main(string[] args) { //string testFolder = @"C:\Riot Games\League of Legends\Logs\GameLogs\2020-10-12T23-00-17"; //AnalyzeNetworkData(GetNetLogContents(testFolder)); OutputInfo outputInfo = AnalyzeLatestNetLogData(); if (outputInfo != null) { string pingWebpage = CreateOutputPage(outputInfo); if (String.IsNullOrEmpty(pingWebpage)) { Console.WriteLine("Error creating output data page."); } else { Console.WriteLine($"Open The file here at: {pingWebpage}"); } Console.WriteLine("Press any key to exit."); Console.ReadKey(); } }