ALERT!
Click here to register with a few steps and explore all our cool stuff we have to offer!

Jump to content



Photo

[sunjester tuts] Combolist Management in C#: Part 1


  • Please log in to reply
[sunjester tuts] Combolist Management in C#: Part 1

#1

sunjester
sunjester
    Offline
    2
    Rep
    26
    Likes

    Underwurld Admin

  • PipPipPipPip
Posts: 104
Threads: 90
Joined: Dec 27, 2018
Credits: 0
#1
[hide]

Introduction
You can follow along by reading the first tutorial about loading/running C# on Linux here. If you have already read that one or know how to do it, please feel free to continue. You can read my other combolist management thread (in bash/shell script) here. All of my tutorials are written under Linux, and I will not pander to the Windows kiddies. I have been developing software since before .NET was around and normally don't even use an IDE, I either use SublimeText, vi, or nano. Nothing wrong with using a full IDE, especially if you're new.

Combo Lists
You can get a shit ton of combo lists from my old github repo (https://github.com/t...unjester/combos) that has 17 million combos. You can use any of those to practice your skills and use the code presented here. Most of the combo lists people are using are huge. When you are dealing with a large amount of data, reading line by line into a string[] array is just stupid, it will slow your computer down and probably crash your software. The lists in my repo shouldn't have duplicates in them and they should all be a colon delimited format.
 
We can read a list (the list im using has 8,000 lines) into a generic list:

public void RemoveDupes(string fileName)
{
    var file = File.ReadAllLines(fileName);
    var lines = new List<string>(file);

In the code above we are reading a file named fileName into a generic string list named lines. Two libraries are needed for this: System.Collections.Generic and System.IO.
 
Removing Duplicates
When removing duplicates you can use Linq's Distinct method since we are using a generic list to hold the combos. It requires a simple addition to one of our lines of code.

var lines = new List<string>(file).Distinct();

That's it, you have removed all the duplicates from that generic list. So now that we have remove the duplicates we can write it back out to a new file named "no_dupes". So let's put it all together.
 

public void RemoveDupes(string fileName)
{
    var file = File.ReadAllLines(fileName);
    var lines = new List<string>(file).Distinct();
    TextWriter tw = new StreamWriter("no_dupes");

    foreach(string line in lines)
    {
            tw.WriteLine(line);
    }

    tw.Close();
}

Dealing with HUGE Combo Lists

When dealing with large combo lists the best thing to do is read a bit at a time. There is no reason to ever store that much in a single file but if you do (and you know who you are) we can use a temporary file and read a little bit at a time. This will keep your software from locking up and your computer free from dying. This is a 24mb flat file with 800k+ combos https://github.com/t...master/815K.txt. This is not something you should load into a string[] or even a generic list all at once.

 

So what do we do? Chunk it up into smaller sections.

public void ReadLargeCombo(string fileName, int start, int howMany)
{
    List<string> lines = new List<string>(File.ReadLines(fileName).Skip(start).Take(howMany));
    foreach(string line in lines)
    {
            Console.WriteLine(line);
    }
}

So to use the method we would supply the name of the file, which line to start with and then how many to return from the line we started at, for example:

combos.ReadLargeCombo("combolist1", 50, 100);

We are starting at line 50 in the file and returning 100 lines.

 

Conclusion

I am stopping here and going to provide you with the class I've written so far. I changed the ReadLargeCombo method to return the array of lines instead of printing them out on the spot (since that would be bad OOP practice). If you have suggestions for the next tutorials, let me know. If you have problems with your combo lists and would like to have a solution to the problem, let me know, I will add it to the next tutorial.

class ComboSun
{
        public ComboSun() {}

        public void RemoveDupes(string fileName)
        {
                var file = File.ReadAllLines(fileName);
                var lines = new List<string>(file).Distinct();

                TextWriter tw = new StreamWriter("no_dupes");

                foreach(string line in lines)
                {
                        tw.WriteLine(line);
                }

                tw.Close();
        }

        public List<string> ReadLargeCombo(string fileName, int start, int howMany)
        {
                List<string> lines = new List<string>(File.ReadLines(fileName).Skip(start).Take(howMany));
                return lines;
        }
}

[/hide]


Edited by sunjester, 12 March 2019 - 10:15 PM.

  • 1

#2

nzshooter
nzshooter
    Offline
    0
    Rep
    0
    Likes

    Lurker

Posts: 5
Threads: 0
Joined: Mar 17, 2019
Credits: 0
Five years registered
#2

when is the second one i love all your stuffs


  • 0


 Users browsing this thread: and 1 guests