AcTools.Render.Tests.AcRootFinder.Find C# (CSharp) Метод

Find() публичный статический Метод

public static Find ( ) : string
Результат string
        public static string Find() {
            if (!_found) {
                _found = true;

                try {
                    var regKey = Registry.CurrentUser.OpenSubKey(@"Software\Valve\Steam");
                    if (regKey == null) return null;

                    var searchCandidates = new List<string>();

                    var installPath = Path.GetDirectoryName(regKey.GetValue("SourceModInstallPath").ToString());
                    searchCandidates.Add(installPath);

                    var steamPath = regKey.GetValue("SteamPath").ToString();
                    var config = File.ReadAllText(Path.Combine(steamPath, @"config", @"config.vdf"));

                    var match = Regex.Match(config, "\"BaseInstallFolder_\\d\"\\s+\"(.+?)\"");
                    while (match.Success) {
                        if (match.Groups.Count > 1) {
                            var candidate = Path.Combine(match.Groups[1].Value.Replace(@"\\", @"\"), "SteamApps");
                            searchCandidates.Add(candidate);
                        }
                        match = match.NextMatch();
                    }

                    _value = (from searchCandidate in searchCandidates
                              where searchCandidate != null && Directory.Exists(searchCandidate)
                              select Path.Combine(searchCandidate, @"common", @"assettocorsa")).FirstOrDefault(Directory.Exists);
                } catch (Exception) {
                    // ignored
                }
            }

            return _value;
        }
    }

Usage Example

Пример #1
0
        public async Task ATest()
        {
            var path = AcRootFinder.Find();

            if (!Directory.Exists(path))
            {
                Debug.WriteLine("REQUIRED ASSET IS MISSING, TEST CANNOT BE DONE");
                return;
            }

            var cars = Directory.GetDirectories(Path.Combine(path, "content", "cars"), "ks_*").Select(x => new {
                CarId    = Path.GetFileName(x),
                SkinsIds = Directory.GetDirectories(Path.Combine(x, "skins")).Select(Path.GetFileName).ToList()
            }).Where(x => Regex.IsMatch(x.CarId, @"^ks_[a]")).ToList();

            var sw = Stopwatch.StartNew();
            var i  = 0;

            using (var updater = new DarkPreviewsUpdater(path)) {
                foreach (var car in cars)
                {
                    foreach (var skin in car.SkinsIds)
                    {
                        await updater.ShotAsync(car.CarId, skin);

                        i++;
                    }
                }
            }

            Console.WriteLine($"Done: {i} skins ({sw.Elapsed.TotalMilliseconds / i:F1} ms per skin)");
        }
All Usage Examples Of AcTools.Render.Tests.AcRootFinder::Find
AcRootFinder