Пример #1
0
        private async Task ReadKunosGuidsAsync()
        {
            if (_guidsRegex == null)
            {
                _guidsRegex = new Regex(@"^\{(\w{8}(?:-\w{4}){3}-\w{12})\}\s+event:/cars/(\w+)/e", RegexOptions.Compiled);
            }

            _kunosGuids = new Dictionary <string, string>();

            var filename = AcPaths.GetSfxGuidsFilename(AcRootDirectory.Instance.RequireValue);

            if (File.Exists(filename))
            {
                var lines = await FileUtils.ReadAllLinesAsync(filename).ConfigureAwait(false);

                for (var i = 0; i < lines.Length; i++)
                {
                    var m = _guidsRegex.Match(lines[i]);
                    if (m.Success)
                    {
                        _kunosGuids[m.Groups[1].Value] = m.Groups[2].Value;
                    }
                }
            }
        }
Пример #2
0
        public static void ReplaceSound(CarObject donor, [NotNull] string target)
        {
            var guids     = donor.GuidsFilename;
            var soundbank = donor.SoundbankFilename;

            var id           = Path.GetFileName(target);
            var newGuids     = Path.Combine(target, @"sfx", @"GUIDs.txt");
            var newSoundbank = Path.Combine(target, @"sfx", $@"{id}.bank");

            FileUtils.EnsureDirectoryExists(Path.Combine(target, @"sfx"));

            using (var putGuids = FileUtils.RecycleOriginal(newGuids))
                using (var putSoundbank = FileUtils.RecycleOriginal(newSoundbank)) {
                    if (File.Exists(guids) && File.Exists(soundbank))
                    {
                        FileUtils.HardLinkOrCopy(soundbank, putSoundbank.Filename);
                        File.WriteAllText(putGuids.Filename, File.ReadAllText(guids).Replace(donor.Id, id));
                    }
                    else if (File.Exists(soundbank) && donor.Author == AuthorKunos)
                    {
                        FileUtils.HardLinkOrCopy(soundbank, putSoundbank.Filename);
                        File.WriteAllText(putGuids.Filename, File.ReadAllLines(AcPaths.GetSfxGuidsFilename(AcRootDirectory.Instance.RequireValue))
                                          .Where(x => !x.Contains(@"} bank:/") || x.Contains(@"} bank:/common") ||
                                                 x.EndsWith(@"} bank:/" + donor.Id))
                                          .Where(x => !x.Contains(@"} event:/") || x.Contains(@"} event:/cars/" + donor.Id + @"/"))
                                          .JoinToString(Environment.NewLine).Replace(donor.Id, id));
                    }
                    else
                    {
                        throw new InformativeException(ToolsStrings.Car_ReplaceSound_WrongCar, ToolsStrings.Car_ReplaceSound_WrongCar_Commentary);
                    }
                }
        }
Пример #3
0
        private bool TestIfKunosUsingGuids(string id)
        {
            if (_kunosCarsIds == null)
            {
                try {
                    _kunosCarsIds = File.ReadAllLines(AcPaths.GetSfxGuidsFilename(_acRoot))
                                    .Select(x => x.Split('/'))
                                    .Where(x => x.Length > 3 && x[1] == "cars" && x[0].EndsWith("event:"))
                                    .Select(x => x[2].ToLowerInvariant())
                                    .Distinct()
                                    .ToArray();
                } catch (Exception) {
                    _kunosCarsIds = new string[] { };
                }
            }

            return(_kunosCarsIds.Contains(id));
        }
Пример #4
0
        private static bool TestIfKunosUsingGuids(string id)
        {
            if (_kunosCarsIds == null)
            {
                try {
                    _kunosCarsIds = File.ReadAllLines(AcPaths.GetSfxGuidsFilename(AcRootDirectory.Instance.RequireValue))
                                    .Select(x => x.Split('/'))
                                    .Where(x => x.Length > 3 && x[1] == @"cars" && x[0].EndsWith(@"event:"))
                                    .Select(x => x[2].ToLowerInvariant())
                                    .Distinct()
                                    .ToArray();
                } catch (Exception e) {
                    Logging.Warning("Can’t get IDs from GUIDs.txt: " + e);
                    _kunosCarsIds = new string[] {};
                }
            }

            return(_kunosCarsIds.Contains(id));
        }