public List <string> CompareLocalToSharedMappings(LocalMappingProfile localMapping, List <string> sharedMapping)
        {
            _logger.Info("comparing local to shared");
            List <string> output = new List <string>();

            foreach (var item in sharedMapping)
            {
                if (!localMapping.LocalMappings.Any(g => g.FileName == item))
                {
                    output.Add(item);
                }
            }

            return(output);
        }
        private void MenuLoop()
        {
            ReadNewSaves();

            //TODO this may be better handled with something more readable than a key
            var choiceKey = _menus.MainMenuKeyChoice();

            switch (choiceKey)
            {
            case ConsoleKey.S:
                _messages.WaitingToPush();
                _messages.PushStatusDisplay(_sharedRepoManager.PushWithStatus(_currentLocalMappingProfile.LocalMappings, _folderPathManager.LocalRepoPath));
                break;

            case ConsoleKey.A:
                AddGameMenu();
                break;

            case ConsoleKey.T:
                try
                {
                    if (_currentLocalMappingProfile == null)
                    {
                        _currentLocalMappingProfile = _mappingManager.ReadLocalMappingProfile();
                    }
                }
                catch (Exception e)
                {
                    _logger.Error(e, "The application cant find any games that could be tracked");
                    break;
                }
                if (_applicationTrackingManager.SetTrackingOnApplications(_currentLocalMappingProfile.LocalMappings, out var appsTracked))
                {
                    List <LocalMapping> changedMappings = _currentLocalMappingProfile.LocalMappings.Where(i => appsTracked.Contains(i.FileName)).ToList();
                    _sharedRepoManager.PushWithStatus(changedMappings, _folderPathManager.LocalRepoPath);
                }
                break;

            case ConsoleKey.Escape:
                return;

            default:
                break;
            }
            ;

            MenuLoop();
        }
        public void ApplicationRun()
        {
            if (!_folderPathManager.IsAppConfigValid())
            {
                _logger.Info("Config was identified as invalid");
                _messages.InvalidConfigConfirmation();
                return;
            }
            var setRepoLocation = _folderPathManager.SetLocalRepoFolder(AppDomain.CurrentDomain.BaseDirectory);

            var localRepoLocation = _sharedRepoManager.CloneRepo(setRepoLocation);

            _folderPathManager.SetBaseFolder(localRepoLocation);

            _messages.WaitingToPull();
            _messages.PullStatusDisplay(_sharedRepoManager.PullWithStatus(localRepoLocation));

            try
            {
                _currentSharedMappings      = _mappingManager.ReadSharedMappings();
                _currentLocalMappingProfile = _mappingManager.ReadLocalMappingProfile();
            }
            catch (Exception e)
            {
                _logger.Error(e, "Failed to get mappings");
                if (_currentSharedMappings != null)
                {
                    if (!_currentSharedMappings.Any())
                    {
                        _currentSharedMappings = new List <string>();
                    }
                }

                _currentLocalMappingProfile = new LocalMappingProfile();
            }

            MenuLoop();
        }
        private void ReadNewSaves()
        {
            if (_currentSharedMappings == null)
            {
                return;
            }
            if (!MappingUtility.ValidateLocalMappingProfile(_currentLocalMappingProfile))
            {
                _currentLocalMappingProfile = new LocalMappingProfile()
                {
                    LocalMappings = new List <LocalMapping>()
                }
            }
            ;

            var updatedMappings = _mappingManager.CompareLocalToSharedMappings(_currentLocalMappingProfile, _currentSharedMappings);

            if (!updatedMappings.Any())
            {
                return;
            }
            _messages.NewSavesMessage(updatedMappings);
        }
    }
 private void WriteLocalMappingProfile(LocalMappingProfile gameGitRepoMapping) =>
 File.WriteAllText($"{_folderPathManager.ExePath}{Constants.SaveConfigFileName}.json", JsonConvert.SerializeObject(gameGitRepoMapping));
Beispiel #6
0
 public static bool ValidateLocalMappingProfile(LocalMappingProfile localMappingProfile) =>
 (localMappingProfile != null && localMappingProfile.LocalMappings != null && localMappingProfile.LocalMappings.Any());