/// <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); }
/// <summary> /// Removes all games of a given XML database file. /// </summary> /// /// <remarks> /// This means that the database file was deleted. /// </remarks> /// /// <param name="databaseFilePath">Full path to database file</param> private void RemoveGames(string databaseFilePath) { if (databaseFilePath == null) { _logger.Warn("Ignoring null value for path from file watcher."); return; } var databaseFile = Path.GetFileName(databaseFilePath); // update database files _threadManager.MainDispatcher.Invoke(() => DatabaseFiles.Remove(databaseFile)); _gamesUpdated.OnNext(new Tuple <string, List <PinballXGame> >(databaseFile, new List <PinballXGame>())); }
public void searchDatabase(string[] data) { try { dataGrid.Rows.Clear(); string[] keyWords = Regex.Split(txtFilesSearchBox.Text, @"\s+"); foreach (string file in data) { var dataJson = DatabaseFiles.FromJson(file); if (GetWords(txtFilesSearchBox.Text.ToLower()).Any(x => dataJson.URL.ToLower().Contains(x))) { dataGrid.Rows.Add(dataJson.Title, dataJson.Type, dataJson.Host, dataJson.URL); } } tab.SelectedTab = tabFiles; } catch { MessageBox.Show("Unable to search database. Please try again in a moment."); } }
private void titleFilesSubtitles_ClickButtonArea(object Sender, MouseEventArgs e) { selectedFiles = "Subtitles"; titleFilesMovies.ColorFillSolid = Color.Transparent; titleFilesMovies.BorderColor = Color.Transparent; titleFilesSeries.ColorFillSolid = Color.Transparent; titleFilesSeries.BorderColor = Color.Transparent; titleFilesAnime.ColorFillSolid = Color.Transparent; titleFilesAnime.BorderColor = Color.Transparent; titleFilesSubtitles.ColorFillSolid = Color.FromArgb(27, 27, 27); titleFilesSubtitles.BorderColor = Color.FromArgb(27, 27, 27); titleFilesTorrents.ColorFillSolid = Color.Transparent; titleFilesTorrents.BorderColor = Color.Transparent; dataGrid.Rows.Clear(); foreach (string file in dataFilesSubtitles) { var data = DatabaseFiles.FromJson(file); dataGrid.Rows.Add(data.Title, data.Type, data.Host, data.URL); } }
/// <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 btnSearchFiles_ClickButtonArea(object Sender, MouseEventArgs e) { if (selectedFiles == "Series") { if (!(txtFilesSearchBox.Text == "")) { searchDatabase(dataFilesSeries); } else { foreach (string file in dataFilesSeries) { var data = DatabaseFiles.FromJson(file); dataGrid.Rows.Add(data.Title, data.Type, data.Host, data.URL); } } } else if (selectedFiles == "Movies") { if (!(txtFilesSearchBox.Text == "")) { searchDatabase(dataFilesMovies); } else { foreach (string file in dataFilesMovies) { var data = DatabaseFiles.FromJson(file); dataGrid.Rows.Add(data.Title, data.Type, data.Host, data.URL); } } } else if (selectedFiles == "Anime") { if (!(txtFilesSearchBox.Text == "")) { searchDatabase(dataFilesAnime); } else { foreach (string file in dataFilesAnime) { var data = DatabaseFiles.FromJson(file); dataGrid.Rows.Add(data.Title, data.Type, data.Host, data.URL); } } } else if (selectedFiles == "Subtitles") { if (!(txtFilesSearchBox.Text == "")) { searchDatabase(dataFilesSubtitles); } else { foreach (string file in dataFilesSubtitles) { var data = DatabaseFiles.FromJson(file); dataGrid.Rows.Add(data.Title, data.Type, data.Host, data.URL); } } } else if (selectedFiles == "Torrents") { if (!(txtFilesSearchBox.Text == "")) { searchDatabase(dataFilesTorrents); } else { foreach (string file in dataFilesTorrents) { var data = DatabaseFiles.FromJson(file); dataGrid.Rows.Add(data.Title, data.Type, data.Host, data.URL); } } } }
void worker_DoWork(object sender, DoWorkEventArgs e) { try { // if (File.Exists(pathData + "open-movies.json")) { if (IsBelowThreshold(pathData + "open-movies.json", 12) == true) // if anime db older than 12 hours then write db { client.DownloadFile(new Uri(linkMovies), pathData + "open-movies.json"); } } else { client.DownloadFile(new Uri(linkMovies), pathData + "open-movies.json"); } dataMoviesJson = File.ReadAllLines(pathData + "open-movies.json"); // // if (File.Exists(pathData + "open-movies-files.json")) { if (IsBelowThreshold(pathData + "open-movies-files.json", 12) == true) // if movies db older than 12 hours then write db { client.DownloadFile(new Uri(linkFilesMovies), pathData + "open-movies-files.json"); } } else { client.DownloadFile(new Uri(linkFilesMovies), pathData + "open-movies-files.json"); } dataFilesMovies = File.ReadAllLines(pathData + "open-movies-files.json"); // // if (File.Exists(pathData + "open-series-files.json")) { if (IsBelowThreshold(pathData + "open-series-files.json", 12) == true) // if series db older than 12 hours then write db { client.DownloadFile(new Uri(linkFilesSeries), pathData + "open-series-files.json"); } } else { client.DownloadFile(new Uri(linkFilesSeries), pathData + "open-series-files.json"); } dataFilesSeries = File.ReadAllLines(pathData + "open-series-files.json"); // // if (File.Exists(pathData + "open-anime-files.json")) { if (IsBelowThreshold(pathData + "open-anime-files.json", 12) == true) // if anime db older than 12 hours then write db { client.DownloadFile(new Uri(linkFilesAnime), pathData + "open-anime-files.json"); } } else { client.DownloadFile(new Uri(linkFilesAnime), pathData + "open-anime-files.json"); } dataFilesAnime = File.ReadAllLines(pathData + "open-anime-files.json"); // // if (File.Exists(pathData + "open-subtitles-files.json")) { if (IsBelowThreshold(pathData + "open-subtitles-files.json", 12) == true) // if anime db older than 12 hours then write db { client.DownloadFile(new Uri(linkFilesSubtitles), pathData + "open-subtitles-files.json"); } } else { client.DownloadFile(new Uri(linkFilesSubtitles), pathData + "open-subtitles-files.json"); } dataFilesSubtitles = File.ReadAllLines(pathData + "open-subtitles-files.json"); // // if (File.Exists(pathData + "open-torrents-files.json")) { if (IsBelowThreshold(pathData + "open-torrents-files.json", 12) == true) // if anime db older than 12 hours then write db { client.DownloadFile(new Uri(linkFilesTorrents), pathData + "open-torrents-files.json"); } } else { client.DownloadFile(new Uri(linkFilesTorrents), pathData + "open-torrents-files.json"); } dataFilesTorrents = File.ReadAllLines(pathData + "open-torrents-files.json"); // foreach (string file in dataFilesMovies.Take(10000)) { var data = DatabaseFiles.FromJson(file); dataGrid.Rows.Add(data.Title, data.Type, data.Host, data.URL); } } catch (Exception ex) { MessageBox.Show("Unable to load movies.\n\n" + ex.Message); } }
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); } }