Exemplo n.º 1
0
        /// <summary>
        /// Changes the XML database file name of all games in a given XML database.
        /// </summary>
        /// <param name="oldDatabaseFilePath">Full path to old database file</param>
        /// <param name="newDatabaseFilePath">Full path to new database file</param>
        private void RenameDatabase(string oldDatabaseFilePath, string newDatabaseFilePath)
        {
            if (oldDatabaseFilePath == null || newDatabaseFilePath == null)
            {
                _logger.Warn("Ignoring null value for path from file watcher.");
                return;
            }
            var databaseOld = Path.GetFileName(oldDatabaseFilePath);
            var databaseNew = Path.GetFileName(newDatabaseFilePath);

            _logger.Info("PinballX database {0} renamed from {1} to {2}.", Name, databaseOld, databaseNew);

            // update properties of concerned games
            Games[databaseOld].ToList().ForEach(g => g.DatabaseFile = databaseNew);

            // update database file list
            _threadManager.MainDispatcher.Invoke(() => {
                DatabaseFiles.Remove(databaseOld);
                DatabaseFiles.Add(databaseNew);
            });

            // rename key
            Games[databaseNew] = Games[databaseOld];
            Games.Remove(databaseOld);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates all games of a given XML database file.
        /// </summary>
        ///
        /// <remarks>
        /// Updating means parsing data from the XML file, saving it in <see cref="Games"/>
        /// and triggering an update through <see cref="GamesUpdated"/>.
        /// </remarks>
        ///
        /// <param name="databaseFilePath">Full path to database file</param>
        private void UpdateGames(string databaseFilePath)
        {
            if (databaseFilePath == null)
            {
                _logger.Warn("Ignoring null value for path from file watcher.");
                return;
            }
            var databaseFile = Path.GetFileName(databaseFilePath);

            // read enabled games from XML
            Games[databaseFile] = ParseGames(databaseFile);

            // update list of database files
            if (!DatabaseFiles.Contains(databaseFile))
            {
                _threadManager.MainDispatcher.Invoke(() => DatabaseFiles.Add(databaseFile));
            }

            // trigger update
            _gamesUpdated.OnNext(new Tuple <string, List <PinballXGame> >(databaseFile, Games[databaseFile]));
        }
        private void Init()
        {
            if (!Directory.Exists(TCManager.BackupLocation))
            {
                Directory.CreateDirectory(TCManager.BackupLocation);
            }

            string[] files = Directory.GetFiles(TCManager.BackupLocation);

            const string format = "MM-dd-yy-hh-mm-ss";

            _backups = new List <Backup>();

            foreach (string file in files)
            {
                string fileName = Path.GetFileName(file);

                DateTime dt;

                string dtStr = Path.GetFileNameWithoutExtension(fileName);

                if (String.IsNullOrEmpty(dtStr))
                {
                    continue;
                }

                Match mat = _dtRegex.Match(dtStr);

                if (!mat.Success)
                {
                    continue;
                }

                if (!DateTime.TryParseExact(mat.Value, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
                {
                    continue;
                }

                string typeSub = dtStr.Substring(dtStr.LastIndexOf("-", StringComparison.Ordinal) + 1);

                BackupType bType = BackupType.Auth;

                switch (typeSub)
                {
                case "auth":

                    bType = BackupType.Auth;

                    break;

                case "char":

                    bType = BackupType.Character;

                    break;

                case "world":

                    bType = BackupType.World;

                    break;

                default:

                    bType = BackupType.Error;

                    break;
                }

                if (bType == BackupType.Error)
                {
                    continue;
                }

                _backups.Add(new Backup()
                {
                    FileName = fileName, BackupType = bType, BackedUpOn = dt
                });
            }

            DatabaseFiles.Clear();

            _backups.Sort((x, y) => y.CompareTo(x));

            foreach (Backup backup in _backups)
            {
                string type;

                switch (backup.BackupType)
                {
                case BackupType.Auth:

                    type = "Auth Database";

                    break;

                case BackupType.Character:

                    type = "Character Database";

                    break;

                case BackupType.World:

                    type = "World Database";

                    break;

                default:

                    type = "ERROR";

                    break;
                }

                backup.BackupText = String.Format("{0} - {1}", backup.BackedUpOn.ToString(CultureInfo.InvariantCulture), type);

                DatabaseFiles.Add(backup.BackupText);
            }
        }