Exemplo n.º 1
0
        private static void LoadWorkshopItems(SteamGame game)
        {
            if (game.WorkshopItems == null)
            {
                game.WorkshopItems = new List <SteamWorkshopItem>();
            }

            var workshop = Path.Combine(game.Universe, "workshop");

            if (!Directory.Exists(workshop))
            {
                return;
            }

            Directory.EnumerateFiles(workshop, "*.acf", SearchOption.TopDirectoryOnly).Where(File.Exists).Do(f =>
            {
                if (Path.GetFileName(f) != $"appworkshop{game.ID}.acf")
                {
                    return;
                }

                Utils.Log($"Found Steam Workshop item file {f} for \"{game.Name}\"");

                var lines                  = File.ReadAllLines(f);
                var end                    = false;
                var foundAppID             = false;
                var workshopItemsInstalled = 0;
                var workshopItemDetails    = 0;
                var bracketStart           = 0;
                var bracketEnd             = 0;

                var currentItem = new SteamWorkshopItem();

                lines.Do(l =>
                {
                    if (end)
                    {
                        return;
                    }
                    if (currentItem == null)
                    {
                        currentItem = new SteamWorkshopItem();
                    }

                    var currentLine = lines.IndexOf(l);
                    if (l.ContainsCaseInsensitive("\"appid\"") && !foundAppID)
                    {
                        if (!int.TryParse(GetVdfValue(l), out var appID))
                        {
                            return;
                        }

                        foundAppID = true;

                        if (appID != game.ID)
                        {
                            return;
                        }
                    }

                    if (!foundAppID)
                    {
                        return;
                    }

                    if (l.ContainsCaseInsensitive("\"SizeOnDisk\""))
                    {
                        if (!int.TryParse(GetVdfValue(l), out var sizeOnDisk))
                        {
                            return;
                        }

                        game.WorkshopItemsSize += sizeOnDisk;
                    }

                    if (l.ContainsCaseInsensitive("\"WorkshopItemsInstalled\""))
                    {
                        workshopItemsInstalled = currentLine;
                    }

                    if (l.ContainsCaseInsensitive("\"WorkshopItemDetails\""))
                    {
                        workshopItemDetails = currentLine;
                    }

                    if (workshopItemsInstalled == 0)
                    {
                        return;
                    }

                    if (currentLine <= workshopItemsInstalled + 1 && currentLine >= workshopItemDetails - 1)
                    {
                        return;
                    }

                    if (currentItem.ItemID == 0)
                    {
                        if (!int.TryParse(GetSingleVdfValue(l), out currentItem.ItemID))
                        {
                            return;
                        }
                    }

                    if (currentItem.ItemID == 0)
                    {
                        return;
                    }

                    if (bracketStart == 0 && l.Contains("{"))
                    {
                        bracketStart = currentLine;
                    }

                    if (bracketEnd == 0 && l.Contains("}"))
                    {
                        bracketEnd = currentLine;
                    }

                    if (bracketStart == 0)
                    {
                        return;
                    }

                    if (currentLine == bracketStart + 1)
                    {
                        if (!int.TryParse(GetVdfValue(l), out currentItem.Size))
                        {
                            return;
                        }
                    }

                    if (bracketStart == 0 || bracketEnd == 0 || currentItem.ItemID == 0 || currentItem.Size == 0)
                    {
                        return;
                    }

                    bracketStart     = 0;
                    bracketEnd       = 0;
                    currentItem.Game = game;
                    game.WorkshopItems.Add(currentItem);

                    Utils.Log($"Found Steam Workshop item {currentItem.ItemID}");

                    currentItem = null;
                    end         = true;
                });
            });
        }
Exemplo n.º 2
0
        private static void LoadWorkshopItems(SteamGame game)
        {
            var workshop = new RelativePath("workshop").RelativeTo(game.Universe);

            if (!workshop.Exists)
            {
                return;
            }

            workshop.EnumerateFiles(false, "*.acf")
            .Where(f => f.Exists)
            .Where(f => f.IsFile)
            .Do(f =>
            {
                if (f.FileName.ToString() != $"appworkshop_{game.ID}.acf")
                {
                    return;
                }

                Utils.Log($"Found Steam Workshop item file {f} for \"{game.Name}\"");

                var lines                  = f.ReadAllLines().ToList();
                var end                    = false;
                var foundAppID             = false;
                var workshopItemsInstalled = 0;
                var workshopItemDetails    = 0;
                var bracketStart           = 0;
                var bracketEnd             = 0;

                SteamWorkshopItem?currentItem = new SteamWorkshopItem(game);

                lines.Do(l =>
                {
                    if (end)
                    {
                        return;
                    }

                    currentItem ??= new SteamWorkshopItem(game);

                    var currentLine = lines.IndexOf(l);
                    if (l.ContainsCaseInsensitive("\"appid\"") && !foundAppID)
                    {
                        if (!int.TryParse(GetVdfValue(l), out var appID))
                        {
                            return;
                        }

                        foundAppID = true;

                        if (appID != game.ID)
                        {
                            return;
                        }
                    }

                    if (!foundAppID)
                    {
                        return;
                    }

                    if (l.ContainsCaseInsensitive("\"SizeOnDisk\""))
                    {
                        if (!int.TryParse(GetVdfValue(l), out var sizeOnDisk))
                        {
                            return;
                        }

                        game.WorkshopItemsSizeOnDisk += sizeOnDisk;
                    }

                    if (l.ContainsCaseInsensitive("\"WorkshopItemsInstalled\""))
                    {
                        workshopItemsInstalled = currentLine;
                    }

                    if (l.ContainsCaseInsensitive("\"WorkshopItemDetails\""))
                    {
                        workshopItemDetails = currentLine;
                    }

                    if (workshopItemsInstalled == 0)
                    {
                        return;
                    }

                    if (currentLine <= workshopItemsInstalled + 1 && currentLine >= workshopItemDetails - 1)
                    {
                        return;
                    }

                    if (currentItem.ItemID == 0)
                    {
                        if (!int.TryParse(GetSingleVdfValue(l), out currentItem.ItemID))
                        {
                            return;
                        }
                    }

                    if (currentItem.ItemID == 0)
                    {
                        return;
                    }

                    if (bracketStart == 0 && l.Contains("{"))
                    {
                        bracketStart = currentLine;
                    }

                    if (bracketEnd == 0 && l.Contains("}"))
                    {
                        bracketEnd = currentLine;
                    }

                    if (bracketStart == 0)
                    {
                        return;
                    }

                    if (currentLine == bracketStart + 1)
                    {
                        if (!long.TryParse(GetVdfValue(l), out currentItem.Size))
                        {
                            return;
                        }
                    }

                    if (bracketStart == 0 || bracketEnd == 0 || currentItem.ItemID == 0 || currentItem.Size == 0)
                    {
                        return;
                    }

                    bracketStart = 0;
                    bracketEnd   = 0;
                    game.WorkshopItems.Add(currentItem);

                    Utils.Log($"Found Steam Workshop item {currentItem.ItemID}");

                    currentItem = null;
                    end         = true;
                });
            });
        }