public virtual void Start(ILogger logger)
        {
            Logger = logger;

            OsuMemoryDataProvider.DataProvider.Initalize();
            _memoryReader = OsuMemoryDataProvider.DataProvider.Instance;

            _settings.SettingUpdated += OnSettingsSettingUpdated;

            bool isFallback             = _settings.Get <bool>(_names.OsuFallback);
            bool memoryScannerIsEnabled = _settings.Get <bool>(_names.EnableMemoryScanner);

            MemoryPoolingIsEnabled = _settings.Get <bool>(_names.EnableMemoryPooling);

            if (!memoryScannerIsEnabled)
            {
                return;
            }
            if (isFallback)
            {
                _settings.Add(_names.EnableMemoryScanner.Name, false);
                return;
            }

            lock (_lockingObject)
                _timer = new Timer(TimerCallback, null, 250, Int32.MaxValue);


            _memoryListener              = new MemoryListener(Helpers.GetFullSongsLocation(_settings));
            _memoryListener.NewOsuEvent += (s, args) => NewOsuEvent?.Invoke(this, args);
            _memoryListener.SetHighFrequencyDataHandlers(_highFrequencyDataHandlers);
            _memoryListener.SetSettingsHandle(_settings);

            Started = true;
        }
Beispiel #2
0
        private async Task ConsumerTask(CancellationToken token)
        {
            while (true)
            {
                //Forcefully queue removal of cache entries
                //TODO: more than anything this is a hack, needs proper debounce logic instead of using memorycache.
                memoryCache.Trim(100);

                if (token.IsCancellationRequested)
                {
                    return;
                }
                if (filesChanged.TryDequeue(out var fsArgs))
                {
                    _settings.Add(_names.LoadingRawBeatmaps.Name, true);
                    Interlocked.Increment(ref _numberOfBeatmapsCurrentlyBeingLoaded);
                    _logger.Log($">Processing beatmap located at {fsArgs.FullPath}", LogLevel.Debug);

                    var beatmap = await BeatmapHelpers.ReadBeatmap(fsArgs.FullPath);

                    _databaseController.StoreTempBeatmap(beatmap);

                    _logger.Log(">Added new Temporary beatmap {0} - {1} [{2}]", LogLevel.Information, beatmap.ArtistRoman,
                                beatmap.TitleRoman, beatmap.DiffName);
                    if (Interlocked.Decrement(ref _numberOfBeatmapsCurrentlyBeingLoaded) == 0)
                    {
                        _settings.Add(_names.LoadingRawBeatmaps.Name, false);
                    }

                    if (lastMapSearchArgs != null &&
                        (
                            (lastMapSearchArgs.Artist == beatmap.Artist &&
                             lastMapSearchArgs.Title == beatmap.Title &&
                             lastMapSearchArgs.Diff == beatmap.DiffName
                            ) || lastMapSearchArgs.MapId == beatmap.MapId
                        ))
                    {
                        NewOsuEvent?.Invoke(this, new MapSearchArgs($"OsuMemory-FolderWatcherReplay", OsuEventType.MapChange)
                        {
                            Artist    = beatmap.Artist,
                            MapHash   = beatmap.Md5,
                            Title     = beatmap.Title,
                            Diff      = beatmap.DiffName,
                            EventType = OsuEventType.MapChange,
                            PlayMode  = beatmap.PlayMode,
                            Status    = lastMapSearchArgs.Status,
                            MapId     = beatmap.MapId > 0 ? beatmap.MapId : -123
                        });
                    }
                }
                Thread.Sleep(5);
            }
        }
Beispiel #3
0
        private void ConsumerTask()
        {
            try
            {
                while (true)
                {
                    memoryCache.Get("dummy");
                    if (filesChanged.TryDequeue(out var fsArgs))
                    {
                        _settings.Add(_names.LoadingRawBeatmaps.Name, true);
                        Interlocked.Increment(ref _numberOfBeatmapsCurrentlyBeingLoaded);
                        _logger.Log($">Processing beatmap located at {fsArgs.FullPath}", LogLevel.Debug);

                        var beatmap = BeatmapHelpers.ReadBeatmap(fsArgs.FullPath);

                        _databaseController.StoreTempBeatmap(beatmap);

                        _logger.Log(">Added new Temporary beatmap {0} - {1} [{2}]", LogLevel.Information, beatmap.ArtistRoman,
                                    beatmap.TitleRoman, beatmap.DiffName);
                        if (Interlocked.Decrement(ref _numberOfBeatmapsCurrentlyBeingLoaded) == 0)
                        {
                            _settings.Add(_names.LoadingRawBeatmaps.Name, false);
                        }

                        if (fsArgs.ChangeType == WatcherChangeTypes.Changed && lastMapSearchArgs != null &&
                            (
                                (lastMapSearchArgs.Artist == beatmap.Artist &&
                                 lastMapSearchArgs.Title == beatmap.Title &&
                                 lastMapSearchArgs.Diff == beatmap.DiffName
                                ) || lastMapSearchArgs.MapId == beatmap.MapId
                            ))
                        {
                            NewOsuEvent?.Invoke(this, new MapSearchArgs($"OsuMemory-FolderWatcherReplay", OsuEventType.MapChange)
                            {
                                Artist    = beatmap.Artist,
                                MapHash   = beatmap.Md5,
                                Title     = beatmap.Title,
                                Diff      = beatmap.DiffName,
                                EventType = OsuEventType.MapChange,
                                PlayMode  = beatmap.PlayMode,
                                Status    = lastMapSearchArgs.Status,
                                MapId     = beatmap.MapId > 0 ? beatmap.MapId : -123
                            });
                        }
                    }
                    Thread.Sleep(5);
                }
            }
            catch (ThreadAbortException)
            {
            }
        }
        public OsuMemoryEventSourceBase(IContextAwareLogger logger, ISettings settings,
                                        IDatabaseController databaseControler, IModParser modParser,
                                        List <IHighFrequencyDataConsumer> highFrequencyDataConsumers, ISaver saver)
        {
            _settings                   = settings;
            _databaseController         = databaseControler;
            _modParser                  = modParser;
            _highFrequencyDataConsumers = highFrequencyDataConsumers;
            Logger          = logger;
            LiveTokenSetter = Tokens.CreateTokenSetter(Name);
            TokenSetter     = Tokens.CreateTokenSetter($"{Name}-Regular");
            _memoryReader   = OsuMemoryReader.Instance;

            _settings.SettingUpdated += OnSettingsSettingUpdated;

            bool isFallback             = _settings.Get <bool>(_names.OsuFallback);
            bool memoryScannerIsEnabled = _settings.Get <bool>(_names.EnableMemoryScanner);

            MemoryPoolingIsEnabled = _settings.Get <bool>(_names.EnableMemoryPooling);

            _poolingMsDelay = _settings.Get <int>(_names.MemoryPoolingFrequency);
            if (!memoryScannerIsEnabled)
            {
                return;
            }
            if (isFallback)
            {
                _settings.Add(_names.EnableMemoryScanner.Name, false);
                return;
            }

            lock (_lockingObject)
                _timer = new Timer(TimerCallback, null, 250, Int32.MaxValue);


            _memoryListener              = new MemoryListener(settings, saver, logger);
            _memoryListener.NewOsuEvent += async(s, args) =>
            {
                while (NewOsuEvent == null)
                {
                    await Task.Delay(5);
                }

                NewOsuEvent.Invoke(this, args);
            };
            _memoryListener.SetHighFrequencyDataHandlers(_highFrequencyDataConsumers);

            Started = true;
        }
        private void ConsumerTask()
        {
            try
            {
                while (true)
                {
                    if (_filesChanged.TryDequeue(out var fsArgs))
                    {
                        Beatmap beatmap = null;
                        _settings.Add(_names.LoadingRawBeatmaps.Name, true);
                        Interlocked.Increment(ref _numberOfBeatmapsCurrentlyBeingLoaded);
                        _logger.Log("Processing new beatmap", LogLevel.Debug);
                        beatmap = BeatmapHelpers.ReadBeatmap(fsArgs.FullPath);

                        _sqliteControler.StoreTempBeatmap(beatmap);

                        _logger.Log("Added new Temporary beatmap {0} - {1} [{2}]", LogLevel.Debug, beatmap.ArtistRoman,
                                    beatmap.TitleRoman, beatmap.DiffName);
                        if (Interlocked.Decrement(ref _numberOfBeatmapsCurrentlyBeingLoaded) == 0)
                        {
                            _settings.Add(_names.LoadingRawBeatmaps.Name, false);
                        }

                        if (fsArgs.ChangeType == WatcherChangeTypes.Changed && lastMapSearchArgs != null)
                        {
                            var l = lastMapSearchArgs;
                            NewOsuEvent?.Invoke(this, new MapSearchArgs($"OsuMemory-FolderWatcherReplay")
                            {
                                Artist    = beatmap.Artist,
                                MapHash   = beatmap.Md5,
                                Title     = beatmap.Title,
                                Diff      = beatmap.DiffName,
                                EventType = OsuEventType.MapChange,
                                PlayMode  = beatmap.PlayMode,
                                Status    = l.Status,
                                MapId     = -123//bogus id to force string search
                            });
                        }
                    }
                    Thread.Sleep(5);
                }
            }
            catch (ThreadAbortException)
            {
                return;
            }
        }
Beispiel #6
0
        public OsuMemoryEventSourceBase(IContextAwareLogger logger, ISettings settings,
                                        IDatabaseController databaseControler, IModParser modParser,
                                        List <Lazy <IHighFrequencyDataConsumer> > highFrequencyDataConsumers, ISaver saver, Delegates.Exit exiter)
        {
            _settings                   = settings;
            _databaseController         = databaseControler;
            _modParser                  = modParser;
            _highFrequencyDataConsumers = highFrequencyDataConsumers;
            Logger          = logger;
            LiveTokenSetter = Tokens.CreateTokenSetter(Name);
            TokenSetter     = Tokens.CreateTokenSetter($"{Name}-Regular");
            var clientCount = _settings.Get <bool>(TourneyMode)
                ? _settings.Get <int>(ClientCount)
                : 1;

            if (_settings.Get <bool>(TourneyMode))
            {
                string exitReason = null;
                if (clientCount < 2)
                {
                    exitReason = $"{ClientCount.Name} setting value is invalid. Set value equal or bigger than 2";
                }

                if (_settings.Get <int>(DataClientId) > clientCount - 1)
                {
                    exitReason = $"{DataClientId.Name} can't be bigger than {ClientCount.Name}. Client ids are 0-indexed";
                }

                if (!string.IsNullOrWhiteSpace(exitReason))
                {
                    Logger.Log(exitReason, LogLevel.Warning);
                    MessageBox.Show(exitReason, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    exiter(exitReason);
                    return;
                }

                _clientMemoryReaders.AddRange(Enumerable.Range(0, clientCount)
                                              .Select(i =>
                {
                    var instance = StructuredOsuMemoryReader.Instance.GetInstanceForWindowTitleHint(
                        $" Tournament Client {i}");
                    instance.OsuMemoryAddresses.GeneralData.KeyOverlay = null;
                    return(instance);
                }));

                //TODO: provide tournament-manager specific data via tokens
                var _tournamentManagerMemoryReader = OsuMemoryReader.Instance.GetInstanceForWindowTitleHint("Tournament Manager");

                Logger.Log($"{_clientMemoryReaders.Count} client readers prepared", LogLevel.Information);
            }
            else
            {
                _clientMemoryReaders.Add(StructuredOsuMemoryReader.Instance);
                StructuredOsuMemoryReader.Instance.OsuMemoryAddresses.GeneralData.KeyOverlay = null;
                StructuredOsuMemoryReader.Instance.InvalidRead += OnInvalidMemoryRead;
            }

            _settings.SettingUpdated += OnSettingsSettingUpdated;

            bool isFallback             = _settings.Get <bool>(_names.OsuFallback);
            bool memoryScannerIsEnabled = _settings.Get <bool>(_names.EnableMemoryScanner);

            MemoryPoolingIsEnabled = _settings.Get <bool>(_names.EnableMemoryPooling);

            _poolingMsDelay = _settings.Get <int>(_names.MemoryPoolingFrequency);
            if (!memoryScannerIsEnabled)
            {
                return;
            }
            if (isFallback)
            {
                _settings.Add(_names.EnableMemoryScanner.Name, false);
                return;
            }

            memoryListener              = new MemoryListener(settings, saver, logger, clientCount);
            memoryListener.NewOsuEvent += async(s, args) =>
            {
                while (NewOsuEvent == null)
                {
                    await Task.Delay(5);
                }

                NewOsuEvent.Invoke(this, args);
            };
            memoryListener.SetHighFrequencyDataHandlers(_highFrequencyDataConsumers);

            MemoryWorkerTask = Task.Run(MemoryWorker, cts.Token).HandleExceptions();

            Started = true;
        }