Beispiel #1
0
        public bool HaveNamesChanged(ChaFile chaFile)
        {
            //return trackedRegistrationIDs.Contains(chaFile.GetRegistrationID());
            var current = HashSetPool <string> .Get();

            try
            {
                foreach (var name in GetNamesToRegister(chaFile))
                {
                    current.Add(name.Key);
                }

                lock (_lock)
                {
                    if (!_regIDtoNamesMap.TryGetValue(chaFile.GetRegistrationID(), out var registered))
                    {
                        registered = new HashSet <string>();
                    }

                    return(!registered.SetEquals(current));
                }
            }
            finally
            {
                HashSetPool <string> .Release(current);
            }
        }
Beispiel #2
0
 public bool IsTracked(ChaFile chaFile)
 {
     //return trackedRegistrationIDs.Contains(chaFile.GetRegistrationID());
     lock (_lock)
     {
         return(_regIDtoCardMap.ContainsKey(chaFile.GetRegistrationID()));
     }
 }
Beispiel #3
0
        public void Untrack(ChaFile chaFile)
        {
            UpdateLastBusyTime();

            var regID = chaFile.GetRegistrationID();
            //Logger.LogDebug($"Attempting to unregister translation replacements: {regID} {chaFile.GetFullName()}");
            var toClean = HashSetPool <string> .Get();

            try
            {
                lock (_lock)
                {
                    // make a copy of current entries in _regIDtoNamesMap
                    var namesToCheck = ListPool <string> .Get();

                    try
                    {
                        if (_regIDtoNamesMap.TryGetValue(regID, out var tmp))
                        {
                            namesToCheck.AddRange(tmp);
                        }
                        foreach (var name in namesToCheck)
                        {
                            if (string.IsNullOrEmpty(name))
                            {
                                continue;
                            }
                            CounterRemove(name, regID);

                            if (CounterCount(name) != 0 || !_currentlyRegisteredReplacements.Contains(name))
                            {
                                continue;
                            }
                            toClean.Add(name);
                        }
                    }
                    finally
                    {
                        ListPool <string> .Release(namesToCheck);
                    }

                    _regIDtoCardMap.Remove(regID);
                }

                foreach (var name in toClean)
                {
                    CheckNamesForCleanup(name);
                }
            }
            finally
            {
                HashSetPool <string> .Release(toClean);
            }
        }
Beispiel #4
0
        public bool HaveNamesChanged(ChaFile chaFile)
        {
            //return trackedRegistrationIDs.Contains(chaFile.GetRegistrationID());
            var current = new HashSet <string>(GetNamesToRegister(chaFile));

            lock (_lock)
            {
                if (!_regIDtoNamesMap.TryGetValue(chaFile.GetRegistrationID(), out var registered))
                {
                    registered = new HashSet <string>();
                }

                return(!registered.SetEquals(current));
            }
        }
Beispiel #5
0
        public void Track(ChaFile chaFile)
        {
            UpdateLastBusyTime();

            _inUse = true;
            var regID = chaFile.GetRegistrationID();

            lock (_lock)
            {
                if (_regIDtoCardMap.ContainsKey(regID))
                {
                    return;
                }

                _regIDtoCardMap[regID] = new WeakReference(chaFile);
                //Logger.LogDebug($"Attempting to register translation replacement: {regID} {chaFile.GetFullName()}");
                var replacements = GetReplacements();
                if (replacements == null)
                {
                    return;
                }

                foreach (var name in GetNamesToRegister(chaFile))
                {
                    if (name.IsNullOrEmpty())
                    {
                        continue;
                    }
                    if (name.Length < (StringUtils.ContainsJapaneseChar(name) ? MinLengthJP : MinLength))
                    {
                        continue;
                    }
                    if (!replacements.ContainsKey(name))
                    {
                        Logger.LogDebug($"Registering as translation replacement: {name}");
                        replacements.Add(name, name);
                        _currentlyRegisteredReplacements.Add(name);
                    }

                    CounterAdd(name, regID);
                }
            }
        }
Beispiel #6
0
        public IEnumerator WaitOnCard(ChaFile file)
        {
            if (file == null)
            {
                yield break;
            }
            var regId = file.GetRegistrationID();

            bool NotDone() => _cardsInProgress.Contains(regId);

            // delay once if card does not appear active yet
            if (!NotDone())
            {
                yield return(null);
            }

            yield return(new WaitWhile(NotDone));

            ApplyTranslations(file);
            Logger.DebugLogDebug($"TranslateCardNames: {file}: card done: {regId}");
        }
Beispiel #7
0
        public void Track(ChaFile chaFile)
        {
            UpdateLastBusyTime();

            _inUse = true;
            var regID = chaFile.GetRegistrationID();

            lock (_lock)
            {
                if (_regIDtoCardMap.ContainsKey(regID))
                {
                    return;
                }

                _regIDtoCardMap[regID] = new WeakReference(chaFile);
                //Logger.LogDebug($"Attempting to register translation replacement: {regID} {chaFile.GetFullName()}");
                var replacements = GetReplacements();
                if (replacements == null)
                {
                    return;
                }

                foreach (var nameEntry in GetNamesToRegister(chaFile))
                {
                    var name = nameEntry.Key;
                    if (name.IsNullOrEmpty() || !NameQualifiesForRegistration(name))
                    {
                        continue;
                    }
                    if (!replacements.ContainsKey(name))
                    {
                        Logger.DebugLogDebug($"Registering as translation replacement: {name} => {nameEntry.Value}");
                        replacements.Add(name, nameEntry.Value);
                        _currentlyRegisteredReplacements.Add(name);
                    }

                    CounterAdd(name, regID);
                }
            }
        }
Beispiel #8
0
        public IEnumerator TranslateCardNames(ChaFile file)
        {
            var regId = file.GetRegistrationID();

            // if it's in progress and the controller is available then
            // the outstanding job will handle things
            if (_cardsInProgress.Contains(regId))
            {
                yield break;
            }

            _cardsInProgress.Add(regId);

            if (CardNeedsTranslation(file))
            {
                file.StartMonitoredCoroutine(new CardJob(file, CardComplete).Start());
            }
            else
            {
                CardComplete(file);
            }
        }
Beispiel #9
0
 private static string GetTrackingKey(ChaFile chaFile, string filename)
 {
     return(StringUtils.JoinStrings("|||", chaFile.GetRegistrationID(), Path.GetFileName(filename)));
 }
Beispiel #10
0
        private void CardComplete(ChaFile chaFile)
        {
            var regId = chaFile.GetRegistrationID();

            _cardsInProgress.Remove(regId);
        }