Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using HtmlAgilityPack;
- namespace TestConsole
- {
- internal class Program
- {
- static string OpenFile()
- {
- string path = string.Empty;
- OpenFileDialog ofd = new OpenFileDialog();
- DialogResult result = ofd.ShowDialog();
- if(result == DialogResult.OK)
- {
- path = ofd.FileName;
- }
- if(path == "")
- {
- Console.WriteLine("Something went wrong");
- }
- return path;
- }
- [STAThread]
- static void Main(string[] args)
- {
- try
- {
- //get HTML Path
- Console.WriteLine("Please Select Modpack file the (.html) file: ");
- string htmlFilePath = OpenFile();
- //get TXT Path
- Console.WriteLine("Please Select Server Installed mods file the (.txt) file: ");
- string textFilePath = OpenFile();
- // Step 1: Load and parse the HTML file to extract data from <td data-type="DisplayName">
- HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument();
- htmlDocument.Load(htmlFilePath);
- var tdNodes = htmlDocument.DocumentNode.SelectNodes("//td[@data-type='DisplayName']");
- string[] htmlDataArray = tdNodes != null
- ? tdNodes.Select(node => node.InnerText.Trim()).ToArray()
- : Array.Empty<string>();
- Console.WriteLine("Extracted Data from HTML File:");
- // Step 2: Read the text file and load its content into an array
- string[] txtDataArray = File.ReadAllLines(textFilePath);
- Console.WriteLine("Extracted Data from Text File:");
- // Step 3: Compare elements and create a new array with matches
- var matchingElements = htmlDataArray
- .Where(htmlItem => txtDataArray.Any(txtItem => txtItem.Contains(htmlItem)))
- .Select(htmlItem =>
- {
- // Find the matching text file line and rename the HTML item accordingly
- var matchingLine = txtDataArray.FirstOrDefault(txtItem => txtItem.Contains(htmlItem));
- return matchingLine ?? htmlItem; // Use the matching line or keep the HTML item
- })
- .Select(item => item + ";")
- .ToArray();
- // Step 4: Output the results
- Console.WriteLine("Generated Output with Matches:");
- string outPutString = string.Join("", matchingElements);
- Console.WriteLine(outPutString);
- Console.WriteLine();
- // Step 5: Copy Output to clipboard.
- Clipboard.SetText(outPutString);
- Console.WriteLine("\nThe output has been copied to the clipboard!");
- Console.ReadKey();
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement