Пример #1
0
        public static void ExportUsed(bool exportAllUsed)
        {
            // get steam id of all workship assets
            HashSet <ulong> steamIds = new HashSet <ulong>();

            if (exportAllUsed)
            {
                foreach (Asset asset in AssetTagList.instance.assets.Values)
                {
                    if (!asset.prefab.m_isCustomContent)
                    {
                        continue;
                    }
                    if (asset.steamID == 0)
                    {
                        continue;
                    }
                    steamIds.Add(asset.steamID);
                }
            }

            else // only export assets from last search
            {
                foreach (Asset asset in UISearchBox.instance.matches)
                {
                    if (!asset.prefab.m_isCustomContent)
                    {
                        continue;
                    }
                    if (asset.steamID == 0)
                    {
                        continue;
                    }
                    steamIds.Add(asset.steamID);
                }
            }

            // update instance count
            AssetTagList.instance.UpdatePrefabInstanceCount(UISearchBox.DropDownOptions.All);
            if (FindIt.isPOEnabled)
            {
                ProceduralObjectsTool.UpdatePOInfoList();
            }

            // filter out unused assets
            Dictionary <ulong, int> usedIDs = new Dictionary <ulong, int>();

            foreach (Asset asset in AssetTagList.instance.assets.Values)
            {
                if (!asset.prefab.m_isCustomContent)
                {
                    continue;
                }
                if (asset.steamID == 0)
                {
                    continue;
                }
                AssetTagList.instance.UpdateAssetInstanceCount(asset, true);
                if (asset.instanceCount > 0 || asset.poInstanceCount > 0)
                {
                    if (usedIDs.ContainsKey(asset.steamID))
                    {
                        usedIDs[asset.steamID] += 1;
                    }
                    else
                    {
                        usedIDs.Add(asset.steamID, 1);
                    }
                }
            }

            string currentTime = GetFormattedDateTime();
            string path        = Path.Combine(DataLocation.localApplicationData, $"FindItExportUsedWorkshopID_{currentTime}.html");

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            using (System.IO.StreamWriter file = new System.IO.StreamWriter(path, true))
            {
                file.WriteLine($"City Name: {GetCityName()}<br>");
                file.WriteLine($"Export Date: {currentTime}<br>");
                file.WriteLine($"<br>This list only considers asset types that are monitored by Find It 2<br>");
                file.WriteLine($"<br>Some mods are bundled with assets for other purpose. Ignore mods in the list<br>");
                file.WriteLine($"<br>If you ever copied assets from the workshop download folder to the local asset folder, the information here can be inaccurate<br>");
                if (FindIt.isPOEnabled)
                {
                    file.WriteLine($"<br>It seems like you're using Procedural Objects. This list already considers POs<br>");
                }

                foreach (ulong id in steamIds)
                {
                    if (usedIDs.ContainsKey(id))
                    {
                        file.WriteLine($"<br><a href=\"https://steamcommunity.com/sharedfiles/filedetails/?id={id}\">{id}</a><br>\n");
                        file.WriteLine($"This workshop ID contains {usedIDs[id]} used asset(s).<br>\n");
                    }
                }

                if (steamIds.Count == 0)
                {
                    file.WriteLine($"Can't find any used workshop asset.<br>\n");
                }
            }

            ExceptionPanel panel = UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel");

            panel.SetMessage("Find It 2", $"FindItExportUsedWorkshopID.html is exported.\n\nIt only considers asset types that are monitored by Find It 2.\n\n{path}", false);
        }
Пример #2
0
        /// <summary>
        /// main backend search method. called by UISearchBox's search method
        /// </summary>
        public List <Asset> Find(string text, UISearchBox.DropDownOptions filter)
        {
            matches.Clear();
            text = text.ToLower().Trim();

            // if showing instance counts, refresh
            try
            {
                bool usingUsedUnusedFilterFlag = UISearchBox.instance?.extraFiltersPanel != null && (UISearchBox.instance.extraFiltersPanel.optionDropDownMenu.selectedIndex == (int)UIFilterExtra.DropDownOptions.UnusedAssets ||
                                                                                                     UISearchBox.instance.extraFiltersPanel.optionDropDownMenu.selectedIndex == (int)UIFilterExtra.DropDownOptions.UsedAssets);

                if (Settings.showInstancesCounter || usingUsedUnusedFilterFlag)
                {
                    UpdatePrefabInstanceCount(filter);

                    if ((filter != UISearchBox.DropDownOptions.Tree) && (filter != UISearchBox.DropDownOptions.Network))
                    {
                        if (FindIt.isPOEnabled && (Settings.includePOinstances || usingUsedUnusedFilterFlag))
                        {
                            ProceduralObjectsTool.UpdatePOInfoList();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debugging.LogException(ex);
            }

            // if there is something in the search input box
            if (!text.IsNullOrWhiteSpace())
            {
                string[] keywords = Regex.Split(text, @"([^\w!#+%]|[-]|\s)+", RegexOptions.IgnoreCase);
                bool     matched, orSearch;
                float    score, orScore;

                foreach (Asset asset in assets.Values)
                {
                    asset.RefreshRico();
                    if (asset.prefab != null)
                    {
                        if (!CheckAssetFilters(asset, filter))
                        {
                            continue;
                        }
                        matched     = true;
                        asset.score = 0;
                        score       = 0;
                        orSearch    = false;
                        orScore     = 0;
                        foreach (string keyword in keywords)
                        {
                            if (!keyword.IsNullOrWhiteSpace())
                            {
                                if (keyword == "!" || keyword == "#" || keyword == "+" || keyword == "%")
                                {
                                    continue;
                                }
                                if (keyword.StartsWith("!") && keyword.Length > 1) // exclude search
                                {
                                    score = GetOverallScore(asset, keyword.Substring(1), filter);
                                    if (score > 0)
                                    {
                                        matched = false;
                                        break;
                                    }
                                }
                                else if (keyword.StartsWith("#") && keyword.Length > 1) // search for custom tag only
                                {
                                    foreach (string tag in asset.tagsCustom)
                                    {
                                        score = GetScore(keyword.Substring(1), tag, tagsCustomDictionary);
                                    }
                                    if (score <= 0)
                                    {
                                        matched = false;
                                        break;
                                    }
                                }
                                else if (keyword.StartsWith("+") && keyword.Length > 1) // OR search
                                {
                                    orSearch     = true;
                                    score        = GetOverallScore(asset, keyword.Substring(1), filter);
                                    orScore     += score;
                                    asset.score += score;
                                }
                                else if (keyword.StartsWith("%") && keyword.Length > 1) // search by workshop id
                                {
                                    if (asset.prefab.m_isCustomContent && asset.steamID != 0)
                                    {
                                        score = GetScore(keyword.Substring(1), asset.steamID.ToString(), null);
                                        if (score <= 0)
                                        {
                                            matched = false;
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        matched = false;
                                        break;
                                    }
                                }

                                else
                                {
                                    // Calculate relevance score. Algorithm decided by Sam. Unchanged.
                                    score = GetOverallScore(asset, keyword, filter);
                                    if (score <= 0)
                                    {
                                        matched = false;
                                        break;
                                    }
                                    else
                                    {
                                        asset.score += score;
                                    }
                                }
                            }
                        }
                        if (orSearch && orScore <= 0)
                        {
                            continue;
                        }
                        if (matched)
                        {
                            matches.Add(asset);
                            if (Settings.instanceCounterSort != 0)
                            {
                                UpdateAssetInstanceCount(asset);
                            }
                        }
                    }
                }
            }

            // if there isn't anything in the search input box
            else
            {
                foreach (Asset asset in assets.Values)
                {
                    asset.RefreshRico();
                    if (asset.prefab != null)
                    {
                        if (!CheckAssetFilters(asset, filter))
                        {
                            continue;
                        }
                        matches.Add(asset);
                        if (Settings.instanceCounterSort != 0)
                        {
                            UpdateAssetInstanceCount(asset);
                        }
                    }
                }
            }

            return(matches);
        }