Skip to content
This repository has been archived by the owner on Mar 31, 2021. It is now read-only.

Steam collection functionality #81

Open
whistleman opened this issue Feb 2, 2020 · 1 comment
Open

Steam collection functionality #81

whistleman opened this issue Feb 2, 2020 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@whistleman
Copy link

Is your feature request related to a problem? Please describe.
To distribute mods with my friends i made a steam collection. However, when i want to add the steam collection to FASTER i need to add each mod seperately. It isn't that much work, but it could be easier.

Describe the solution you'd like
Copy the steam collection url and paste it in the Steam mods > Add Steam Mods. Maybe there is a checkbox to tell FASTER that this url is supposed to be a collection instead of a single mod.
FASTER will scrape the steam collection webpage and gets all mods in the collection, and adds which mods do not already exist.

Describe alternatives you've considered
None

Additional context
I have been working on this myself and have a bit of code that you could use. I'm a hobby programmer so please take into account that my code can be a bit unusual..

To scrape i used HtmlAgilityPack. I downloaded the .html with this method

public void DownloadFile(string steamurl)
        {
            // Download the webpage into a string
            WebClient client = new WebClient();
            string html = client.DownloadString(steamurl);

            // From the string create an Html documents
            var doc = new HtmlDocument();
            doc.LoadHtml(html);

            ScrapeHtmlFile(doc);
        }

After that I scrape the contents of the page with the following function

private void ScrapeHtmlFile(HtmlDocument doc)
        {
            List<WorkshopItem> items = new List<WorkshopItem>();

            // Loop through each collectionitem //doc.DocumentNode
            foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//div[@class='collectionItemDetails']"))
            {
                // Get link
                HtmlNode link = node.SelectSingleNode("a[@href]");
                string hrefValue = link.GetAttributeValue("href", string.Empty);

                // Get name
                HtmlNode winame = node.SelectSingleNode("a/div[@class='workshopItemTitle']");
                string name = winame.InnerText;
                
                // Get short description of mod
                HtmlNode shortdescriptionnode = node.SelectSingleNode("div[@class='workshopItemShortDesc']");
                HtmlNode bb_h1 = shortdescriptionnode.SelectSingleNode("div[@class='bb_h1']");
                string description = "";
                // If header of short description returns null add empty string
                if (null != bb_h1)
                {
                    description = bb_h1.InnerText;
                }

                // Get id
                int stringlength = hrefValue.Length;
                int startposition = hrefValue.IndexOf("?id=");
                int lastposition = stringlength - startposition;
                string id = hrefValue.Substring(startposition + 4, lastposition - 4);

                // If the href containts the right string, then go ahead and create a class with the data inside.
                if (hrefValue.Contains("https://steamcommunity.com/sharedfiles/filedetails/?id="))
                {
                    // Add all relavent details to the workshopitem class
                    var item = new WorkshopItem(name, Convert.ToInt32(id), hrefValue, description);
                    items.Add(item);
                }
            }
            // Add to listview or datagrid, whatever you want.
        }

In my c# app I use a listview to show the mods, so you see that I loop through each item and put it in a list, to be used later for my listview. Maybe some parts of the code above do not apply as you might have a more sophisticated design pattern than i use.

Thanks,

Whistle

@Foxlider
Copy link
Owner

Foxlider commented Feb 2, 2020

Ok. This IS impressive. I haven't thought about steam collections.
However, you could create an Arma preset file with all the mods and import them all at once.
I'll check with steamcmd if steam collections can be imported or if I find another alternative.

Also, nice code ! If you have any other idea for FASTER please let me know. and if you want to contribute, feel free to do so. It's open source after all

@Foxlider Foxlider self-assigned this Feb 2, 2020
@Foxlider Foxlider added the enhancement New feature or request label Feb 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants