public WatchList() { _watchItemList = new List <WatchItem>(); //_seriesList = new List<SeriesItem>(); _sqlClient = new SQLiteClient(Config.GetFile(Config.Dir.Database, "MyTorrents.db3")); DatabaseUtility.SetPragmas(_sqlClient); if (!DatabaseUtility.TableExists(_sqlClient, "WatchList")) { SQLiteResultSet result = _sqlClient.Execute("CREATE TABLE WatchList (Search CHAR(256), Added BIGINT, Label CHAR(256) );"); } if (!DatabaseUtility.TableExists(_sqlClient, "SeriesWatchList")) { SQLiteResultSet result = _sqlClient.Execute("CREATE TABLE SeriesWatchList (SeriesName CHAR(256), OriginalSeriesName CHAR(256), SeriesID CHAR(256), Added BIGINT, Quality CHAR(256), Tracker CHAR(256), Type CHAR(256), Source CHAR(256), Folder CHAR(256), IncludeSpecials CHAR (256));"); } RSSChannelManager channelManager = RSSChannelManager.Instance(); channelManager.RSSChannelUpdated += new RSSChannelUpdated(channelManager_RSSChannelUpdated); System.Timers.Timer SearchTimer = new System.Timers.Timer(30 * 60 * 1000); SearchTimer.Elapsed += new ElapsedEventHandler(SearchTimer_Elapsed); SearchTimer.Start(); if (IsMPTVSeriesAvailable()) { MPTVSeriesWorker.DoWork += new DoWorkEventHandler(MPTVSeriesWorker_DoWork); MPTVSeriesWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(MPTVSeriesWorker_Completed); MPTVSeriesWorker.RunWorkerAsync(); } }
//get next available id in table string getNextID(string tableName, string idColumn) { if (tableName == Game.TABLE_NAME) { if (MediaPortal.Database.DatabaseUtility.GetAsInt(DB.Instance.ExecuteWithoutLock("SELECT COUNT(gameid) FROM {0}", Game.TABLE_NAME), 0, 0) > 0) { return(MediaPortal.Database.DatabaseUtility.GetAsInt(DB.Instance.Execute("SELECT seq + 1 FROM sqlite_sequence WHERE name='{0}'", Game.TABLE_NAME), 0, 0).ToString()); } DB.Instance.Execute("DELETE FROM sqlite_sequence WHERE name='{0}'", Game.TABLE_NAME); return("1"); } SQLiteResultSet result = DB.Instance.Execute("SELECT MAX({0})+1 FROM {1}", idColumn, tableName); if (result.Rows.Count > 0) { string id = result.Rows[0].fields[0]; if (!string.IsNullOrEmpty(id)) { return(id); } } return("0"); }
private bool verifyIntegrity(SQLiteClient client) { string query = "PRAGMA integrity_check;"; logger.Info("Executing SQL integrity check"); try { SQLiteResultSet results = client.Execute(query); if (results != null) { if (results.Rows.Count == 1) { SQLiteResultSet.Row arr = results.Rows[0]; if (arr.fields.Count == 1) { if (arr.fields[0] == "ok") { logger.Info("Database integrity check succeeded"); return(true); } } } } } catch (Exception e) { logger.Info("Integrity check failed, database is corrupt. Reason = '{0}', Filename = '{1}'", e.Message, client.DatabaseName); return(false); } logger.Info("Integrity check failed, database is corrupt. Filename = '{0}'", client.DatabaseName); return(false); }
private void verifyRelationTables(Type primaryType) { foreach (DBRelation currRelation in DBRelation.GetRelations(primaryType)) { try { // check if the table exists in the database, if not, create it SQLiteResultSet resultSet = dbClient.Execute("select * from sqlite_master where type='table' and name = '" + currRelation.TableName + "'"); if (resultSet.Rows.Count == 0) { // create table string createQuery = "create table " + currRelation.TableName + " (id INTEGER primary key, " + currRelation.PrimaryColumnName + " INTEGER, " + currRelation.SecondaryColumnName + " INTEGER)"; resultSet = dbClient.Execute(createQuery); // create index1 resultSet = dbClient.Execute("create index " + currRelation.TableName + "__index1 on " + currRelation.TableName + " (" + currRelation.PrimaryColumnName + ")"); // create index2 resultSet = dbClient.Execute("create index " + currRelation.TableName + "__index2 on " + currRelation.TableName + " (" + currRelation.SecondaryColumnName + ")"); logger.Debug("Created " + currRelation.TableName + " sub-table."); } } catch (SQLiteException e) { logger.FatalException("Error verifying " + currRelation.TableName + " subtable.", e); } } }
public List <EmulatorProfile> GetProfiles(Game game) { if (!game.ParentEmulator.IsPc()) { return(GetProfiles(game.ParentEmulator)); } List <EmulatorProfile> profiles = new List <EmulatorProfile>(); SQLiteResultSet result = Execute("SELECT * FROM {0} WHERE emulator_id=-1 AND game_id={1} ORDER BY defaultprofile DESC", EmulatorProfile.TABLE_NAME, game.GameID); if (result.Rows.Count > 0) { foreach (SQLiteResultSet.Row row in result.Rows) { profiles.Add(EmulatorProfile.CreateProfile(row)); } } else { profiles.Add(new EmulatorProfile(true) { EmulatorID = -1, GameId = game.GameID, Arguments = game.Arguments, SuspendMP = true, UseQuotes = false, StopEmulationOnKey = false }); } return(profiles); }
// Returns a list of objects of the specified type, based on the specified criteria. public List <DatabaseTable> Get(Type tableType, ICriteria criteria) { verifyTable(tableType); // if this is a request for all object of this type, if we already have done this // type of request, just return the cached objects. This assumes no one else is changing // the DB. if (criteria == null) { if (doneFullRetrieve.ContainsKey(tableType)) { return(new List <DatabaseTable>(cache.GetAll(tableType))); } doneFullRetrieve[tableType] = true; } lock (lockObject) { List <DatabaseTable> rtn = new List <DatabaseTable>(); try { // build and execute the query string query = getSelectQuery(tableType); if (criteria != null) { query += criteria.GetWhereClause(); } SQLiteResultSet resultSet = dbClient.Execute(query); // store each one foreach (SQLiteResultSet.Row row in resultSet.Rows) { // create the new entry DatabaseTable newRecord = (DatabaseTable)tableType.GetConstructor(System.Type.EmptyTypes).Invoke(null); newRecord.DBManager = this; newRecord.LoadByRow(row); // if it is already cached, just use the cached object if (cache.Get(tableType, (int)newRecord.ID) != null) { rtn.Add(cache.Get(tableType, (int)newRecord.ID)); } // otherwise use the new record and cache it else { newRecord = cache.Add(newRecord); getAllRelationData(newRecord); rtn.Add(newRecord); } } } catch (SQLiteException e) { logger.ErrorException("Error retrieving with criteria from " + tableType.Name + " table.", e); } return(rtn); } }
public ArtistItem GetArtist(YouTubeEntry entry) { ArtistItem artistItem = new ArtistItem(); string lsSQL = string.Format("select distinct ARTIST_ID from VIDEOS WHERE VIDEO_ID=\"{0}\" ", Youtube2MP.GetVideoId(entry)); SQLiteResultSet loResultSet = m_db.Execute(lsSQL); for (int iRow = 0; iRow < loResultSet.Rows.Count; iRow++) { artistItem = ArtistManager.Instance.GetArtistsById(DatabaseUtility.Get(loResultSet, iRow, "ARTIST_ID")); break; } if (string.IsNullOrEmpty(artistItem.Name)) { artistItem.Name = ArtistManager.Instance.GetArtistName(entry.Title.Text); } ArtistItem artistItemLocal = GetArtistsByName(artistItem.Name); if (artistItemLocal != null) { artistItem.Bio = artistItemLocal.Bio; artistItem.Id = string.IsNullOrEmpty(artistItem.Id) ? artistItemLocal.Id : artistItem.Id; artistItem.Img_url = !string.IsNullOrEmpty(artistItemLocal.Img_url) ? artistItemLocal.Img_url : artistItem.Img_url; artistItem.Name = string.IsNullOrEmpty(artistItem.Name) ? artistItemLocal.Name : artistItem.Name; artistItem.Tags = string.IsNullOrEmpty(artistItem.Tags) ? artistItemLocal.Tags : artistItem.Tags; artistItem.User = string.IsNullOrEmpty(artistItem.User) ? artistItemLocal.User : artistItem.User; } return(artistItem); }
public SQLiteResultSet ExecuteWithoutLock(string query, params object[] args) { if (!isInit) { Logger.LogError("Database has not initialised correctly"); return(new SQLiteResultSet()); } try { string exeQuery = string.Format(System.Globalization.CultureInfo.InvariantCulture, query, args); SQLiteResultSet result = sqlClient.Execute(exeQuery); return(result); } catch (Exception ex) { if (supressExceptions) { Logger.LogError(ex); return(new SQLiteResultSet()); } else { throw (ex); } } }
/// <summary> /// Check if column exists in Database table /// </summary> /// <param name="table"></param> /// <param name="field"></param> /// <returns></returns> public static bool ColumnExists(string table, string field) { string sql = "select * from sqlite_master where type='table' and tbl_name='" + table + "' and sql like '%" + field + "%'"; SQLiteResultSet results = DBTVSeries.Execute(sql); return(results.Rows.Count > 0); }
public void Save(YouTubeEntry entry) { try { string id = Youtube2MP.GetVideoId(entry); string lsSQL = string.Format("select distinct VIDEO_ID from VIDEOS WHERE VIDEO_ID=\"{0}\"", id); SQLiteResultSet loResultSet = m_db.Execute(lsSQL); if (loResultSet.Rows.Count == 0) { int duration = 0; if (entry.Duration != null && entry.Duration.Seconds != null) { duration = Convert.ToInt32(entry.Duration.Seconds); } bool ishd = entry.ExtensionElements.Any( extensionElementFactory => extensionElementFactory.XmlPrefix == "yt" && extensionElementFactory.XmlName == "hd"); lsSQL = string.Format( "insert into VIDEOS (VIDEO_ID,TITLE ,LENGTH,IMG_URL, hd ) VALUES (\"{0}\",\"{1}\",{2},\"{3}\",{4})", Youtube2MP.GetVideoId(entry), DatabaseUtility.RemoveInvalidChars(entry.Title.Text.Replace('"', '`')), duration, YoutubeGUIBase.GetBestUrl(entry.Media.Thumbnails), ishd ? 1 : 0); m_db.Execute(lsSQL); } } catch (Exception exception) { Log.Error(exception); } }
public static string Get(SQLiteResultSet results, int iRecord, int column) { if (null == results) { Log.Error("DatabaseUtility.Get: Results=null"); return(string.Empty); } if (results.Rows.Count < iRecord) { Log.Error("DatabaseUtility.Get: Recordnr {0} not found", iRecord); return(string.Empty); } if (column < 0 || column >= results.ColumnNames.Count) { Log.Error("DatabaseUtility.Get: Columnr {0} out of range", column); return(string.Empty); } SQLiteResultSet.Row arr = results.Rows[iRecord]; if (arr.fields[column] == null) { Log.Error("DatabaseUtility.Get: Field {0} = null", column); return(string.Empty); } string strLine = (arr.fields[column]).Trim(); //strLine = strLine.Replace("''","'"); return(strLine); ; }
public static DateTime GetAsDateTime(SQLiteResultSet results, int iRecord, string aTimestampColum) { DateTime finalResult = DateTime.MinValue; if (results == null || string.IsNullOrEmpty(aTimestampColum) || results.Rows.Count < 1 || results.Rows.Count < iRecord) { return(finalResult); } try { SQLiteResultSet.Row arr = results.Rows[iRecord]; int?iCol = (int?)results.ColumnIndices[aTimestampColum]; if (iCol.HasValue) { if (arr.fields[iCol.Value] != null) { finalResult = Convert.ToDateTime((arr.fields[iCol.Value])); } } } catch (Exception ex) { Log.Error("DatabaseUtility:GetAsDateTime: {0}", ex.Message); } return(finalResult); }
public ArtistItem GetArtistsByName(string name) { ArtistItem res = new ArtistItem(); res = DatabaseProvider.InstanInstance.GetArtistsByName(name); if (res != null) { return(res); } res = new ArtistItem(); string lsSQL = string.Format("select * from ARTISTS WHERE ARTIST_NAME like '{0}' order by ARTIST_NAME", DatabaseUtility.RemoveInvalidChars(name)); SQLiteResultSet loResultSet = m_db.Execute(lsSQL); for (int iRow = 0; iRow < loResultSet.Rows.Count; iRow++) { res.Id = DatabaseUtility.Get(loResultSet, iRow, "ARTIST_ID"); res.Name = DatabaseUtility.Get(loResultSet, iRow, "ARTIST_NAME"); res.Img_url = DatabaseUtility.Get(loResultSet, iRow, "ARTIST_IMG"); res.User = DatabaseUtility.Get(loResultSet, iRow, "ARTIST_USER"); res.Tags = DatabaseUtility.Get(loResultSet, iRow, "ARTIST_TAG"); break; } return(res); }
public List <string> GetArtistsLetters(string letter) { List <string> res = new List <string>(); string lsSQL = string.Format( "select distinct upper(substr(ARTIST_NAME,1,{0})) AS LETTER from ARTISTS WHERE ARTIST_NAME like '{1}%' order by upper(ARTIST_NAME)", letter.Length + 1, letter); SQLiteResultSet loResultSet = m_db.Execute(lsSQL); string oldvalue = ""; for (int iRow = 0; iRow < loResultSet.Rows.Count; iRow++) { string l = DatabaseUtility.Get(loResultSet, iRow, "LETTER"); if (l.Length == 1) { l += " "; } if (l != oldvalue) { res.Add(l); } oldvalue = l; } return(res); }
public void AddArtist(ArtistItem artistItem) { try { if (string.IsNullOrEmpty(artistItem.Name)) { return; } string lsSQL = string.Format("select distinct ARTIST_ID,ARTIST_IMG from ARTISTS WHERE ARTIST_NAME like '{0}'", artistItem.Name); SQLiteResultSet loResultSet = m_db.Execute(lsSQL); if (loResultSet.Rows.Count > 0) { Save(artistItem); return; } lsSQL = string.Format( "insert into ARTISTS (ARTIST_ID,ARTIST_NAME ,ARTIST_IMG, ARTIST_USER, ARTIST_TAG, ARTIST_BIO) VALUES ('{0}','{1}','{2}','{3}','{4}','{5}')", artistItem.Id, DatabaseUtility.RemoveInvalidChars(artistItem.Name), artistItem.Img_url, artistItem.User, DatabaseUtility.RemoveInvalidChars(artistItem.Tags), DatabaseUtility.RemoveInvalidChars(artistItem.Bio)); m_db.Execute(lsSQL); artistItem.Db_id = m_db.LastInsertID(); } catch (Exception exception) { } }
public static DBView[] getTaggedViews() { try { // Make sure the table is created - create a dummy object DBView dummy = new DBView(); // Only get Tagged Views String sqlQuery = "select * from " + cTableName + " where " + cTaggedView + " = 1"; SQLiteResultSet results = DBTVSeries.Execute(sqlQuery); if (results.Rows.Count > 0) { DBView[] views = new DBView[results.Rows.Count]; for (int index = 0; index < results.Rows.Count; index++) { views[index] = new DBView(); views[index].Read(ref results, index); } return(views); } } catch (Exception ex) { MPTVSeriesLog.Write("Error in retrieving Tagged Views (" + ex.Message + ")."); } return(new DBView[0]); }
public string GetPlayedArtistIds(int numPlay) { List <string> ids = new List <string>(); string lsSQL = string.Format( "select * from (SELECT VIDEOS.VIDEO_ID AS VIDEO_ID, ARTIST_ID, TITLE, IMG_URL, count(PLAY_HISTORY.VIDEO_ID) as num_play FROM VIDEOS, PLAY_HISTORY WHERE VIDEOS.VIDEO_ID=PLAY_HISTORY.VIDEO_ID group by VIDEOS.VIDEO_ID, ARTIST_ID, TITLE, IMG_URL order by count(PLAY_HISTORY.VIDEO_ID) desc)where num_play>" + numPlay.ToString()); SQLiteResultSet loResultSet = m_db.Execute(lsSQL); for (int iRow = 0; iRow < loResultSet.Rows.Count; iRow++) { string id = DatabaseUtility.Get(loResultSet, iRow, "ARTIST_ID"); if (!string.IsNullOrEmpty(id) && !ids.Contains(id)) { ids.Add(id); } } string ret = ""; for (int i = 0; i < ids.Count; i++) { ret += "'" + ids[i] + "'"; if (i != ids.Count - 1) { ret += ","; } } return(ret); }
public List <Emulator> GetEmulators(bool forcePC = false) { List <Emulator> emus = new List <Emulator>(); SQLiteResultSet result = Execute("SELECT * FROM {0} ORDER BY position ASC", Emulator.TABLE_NAME); foreach (SQLiteResultSet.Row row in result.Rows) { emus.Add(Emulator.CreateEmulator(row)); } Emulator pc = Emulator.GetPC(); if (forcePC || GetGames(pc).Count > 0) { //sanitise position just in case if (pc.Position < 0) { pc.Position = 0; } else if (pc.Position > emus.Count) { pc.Position = emus.Count; } emus.Insert(pc.Position, pc); //Insert PC into correct position in list } return(emus); }
public static DBView[] getAll(bool includeDisabled) { try { // make sure the table is created - create a dummy object DBView dummy = new DBView(); // retrieve all fields in the table String sqlQuery = "select * from " + cTableName + (includeDisabled ? string.Empty : " where " + cEnabled + " = 1") + " order by " + cSort; SQLiteResultSet results = DBTVSeries.Execute(sqlQuery); if (results.Rows.Count > 0) { DBView[] views = new DBView[results.Rows.Count]; for (int index = 0; index < results.Rows.Count; index++) { views[index] = new DBView(); views[index].Read(ref results, index); } return(views); } } catch (Exception ex) { MPTVSeriesLog.Write("Error in DBView.Get (" + ex.Message + ")."); } return(new DBView[0]); }
public static DBImportPath[] GetAll() { try { // make sure the table is created - create a dummy object DBImportPath dummy = new DBImportPath(); // retrieve all fields in the table String sqlQuery = "select * from " + cTableName + " order by " + cIndex; SQLiteResultSet results = DBTVSeries.Execute(sqlQuery); if (results.Rows.Count > 0) { DBImportPath[] importPathes = new DBImportPath[results.Rows.Count]; for (int index = 0; index < results.Rows.Count; index++) { importPathes[index] = new DBImportPath(); importPathes[index].Read(ref results, index); } return(importPathes); } } catch (Exception ex) { MPTVSeriesLog.Write("Error in DBImportPath.Get (" + ex.Message + ")."); } return(null); }
public void AddArtist(ArtistItem artistItem) { try { if (string.IsNullOrEmpty(artistItem.Id)) { return; } string lsSQL = string.Format("select distinct ARTIST_ID,ARTIST_IMG from ARTISTS WHERE ARTIST_ID=\"{0}\"", artistItem.Id); SQLiteResultSet loResultSet = m_db.Execute(lsSQL); if (loResultSet.Rows.Count > 0) { for (int iRow = 0; iRow < loResultSet.Rows.Count; iRow++) { artistItem.Img_url = DatabaseUtility.Get(loResultSet, iRow, "ARTIST_IMG"); artistItem.Tags = DatabaseUtility.Get(loResultSet, iRow, "ARTIST_TAG"); } return; } lsSQL = string.Format( "insert into ARTISTS (ARTIST_ID,ARTIST_NAME,ARTIST_IMG, ARTIST_USER, ARTIST_TAG) VALUES ('{0}','{1}','{2}','{3}','{4}')", artistItem.Id, DatabaseUtility.RemoveInvalidChars(artistItem.Name), artistItem.Img_url, artistItem.User, DatabaseUtility.RemoveInvalidChars(artistItem.Tags)); m_db.Execute(lsSQL); artistItem.Db_id = m_db.LastInsertID(); } catch (Exception) { } }
public static string Get(SQLiteResultSet results, int iRecord, int column) { if (null == results) { return(string.Empty); } if (results.Rows.Count < iRecord) { return(string.Empty); } if (column < 0 || column >= results.ColumnNames.Count) { return(string.Empty); } SQLiteResultSet.Row arr = results.Rows[iRecord]; if (arr.fields[column] == null) { return(string.Empty); } string strLine = (arr.fields[column]).Trim(); //strLine = strLine.Replace("''","'"); return(strLine); ; }
public int GetRotation(string strPicture) { if (m_db == null) { return(-1); } try { string strPic = strPicture; int iRotation = 0; DatabaseUtility.RemoveInvalidChars(ref strPic); SQLiteResultSet results = m_db.Execute(String.Format("select strFile, iRotation from picture where strFile like '{0}'", strPic)); if (results != null && results.Rows.Count > 0) { iRotation = Int32.Parse(DatabaseUtility.Get(results, 0, 1)); return(iRotation); } AddPicture(strPicture, iRotation); return(iRotation); } catch (Exception ex) { Log.Error("MediaPortal.Picture.Database exception err:{0} stack:{1}", ex.Message, ex.StackTrace); Open(); } return(0); }
public static long GetAsInt64(SQLiteResultSet results, int iRecord, string strColum) { string result = Get(results, iRecord, strColum); if (result == null) { return(0); } if (result.Length == 0) { return(0); } long returnValue = -1; try { returnValue = Int64.Parse(result); } catch (Exception) { Log.Info("DatabaseUtility:GetAsInt64() column:{0} record:{1} value:{2} is not an Int64", strColum, iRecord, result); } return(returnValue); }
public static DateTime GetAsDateTime(SQLiteResultSet results, int iRecord, string aTimestampColum) { DateTime finalResult = DateTime.MinValue; if (results == null || string.IsNullOrEmpty(aTimestampColum) || results.Rows.Count < 1 || results.Rows.Count < iRecord) { return(finalResult); } try { SQLiteResultSet.Row arr = results.Rows[iRecord]; int iCol = 0; if (results.ColumnIndices.ContainsKey(aTimestampColum)) { iCol = (int)results.ColumnIndices[aTimestampColum]; if (arr.fields[iCol] != null) { finalResult = Convert.ToDateTime((arr.fields[iCol])); } } } catch (Exception) {} return(finalResult); }
private string Get(SQLiteResultSet results, int iRecord, string strColum) { if (null == results) { return(string.Empty); } if (results.Rows.Count < iRecord) { return(string.Empty); } SQLiteResultSet.Row arr = results.Rows[iRecord]; int iCol = 0; foreach (string columnName in results.ColumnNames) { if (strColum == columnName) { string strLine = arr.fields[iCol].Trim(); strLine = strLine.Replace("''", "'"); return(strLine); } iCol++; } return(string.Empty); }
public void GetPath(string strPath, ref ArrayList strPathList, string strKey) { if (string.IsNullOrEmpty(strKey)) { return; } if (m_db == null) { return; } try { string sql = string.Format( "SELECT strPath from tblPath where strPath like '{0}%' and idPath in (SELECT idPath from tblSetting where tblSetting.idPath = tblPath.idPath and tblSetting.tagName = '{1}')" , strPath, strKey); SQLiteResultSet results = m_db.Execute(sql); if (results.Rows.Count == 0) { return; } for (int iRow = 0; iRow < results.Rows.Count; iRow++) { strPathList.Add(DatabaseUtility.Get(results, iRow, "strPath")); } } catch (Exception ex) { Log.Error("FolderDatabase.GetPath() exception err:{0} stack:{1}", ex.Message, ex.StackTrace); } }
public static bool CheckIntegrity() { string query = "PRAGMA integrity_check;"; MPTVSeriesLog.Write("Executing SQL integrity check"); SQLiteResultSet results = Execute(query); if (results != null) { if (results.Rows.Count == 1) { SQLiteResultSet.Row arr = results.Rows[0]; if (arr.fields.Count == 1) { if (arr.fields[0] == "ok") { MPTVSeriesLog.Write("Database integrity check succeeded"); return(true); } } } } MPTVSeriesLog.Write("Integrity check failed, database is corrupt. Filename = '{0}'", m_db.DatabaseName); return(false); }
public static Game[] getGamesFromDB(Emulator emulator, bool showHidden) { List <Game> items = new List <Game>(); SQLiteResultSet result = dbExecute("SELECT * FROM Games WHERE parentemu = " + emulator.UID.ToString() + @" ORDER BY parentemu, title"); for (int i = 0; i < result.Rows.Count; i++) { //Game item = getGame(DatabaseUtility.Get(result, i, 0), emulator); Game item = createGame(result, i, emulator); if (item.Visible || showHidden) { items.Add(item); } } String[] keys = new String[items.Count]; for (int i = 0; i < items.Count; i++) { keys[i] = items[i].Title; } Game[] listToReturn = items.ToArray(); Array.Sort(keys, listToReturn); return(listToReturn); }
public static Game[] getGames(String path, Emulator emulator, SearchOption recursive, bool showHidden) { List <Game> items = new List <Game>(); SQLiteResultSet result = dbExecute("SELECT * FROM Games WHERE parentemu = " + emulator.UID.ToString()); List <string> dbPaths = new List <string>(); for (int i = 0; i < result.Rows.Count; i++) { dbPaths.Add(DatabaseUtility.Get(result, i, 1)); //store list of paths already in DB } if (!Directory.Exists(path)) //Rom directory doesn't exist, skip { Logger.LogError("Error locating Rom directory for '{0}'", emulator.Title); return(items.ToArray()); } foreach (String filter in emulator.Filter.Split(';')) //search directory against each filter { string[] gamePaths; try { gamePaths = Directory.GetFiles(path, filter, recursive); //get list of matches } catch (Exception ex) { Logger.LogError("Error getting files from '{0}' rom directory - {1}", emulator, ex.Message); continue; } foreach (String gamePath in gamePaths) { Game item; if (dbPaths.Contains(gamePath)) //already in database { item = createGame(result, dbPaths.IndexOf(gamePath), emulator); } else { item = getGame(gamePath, emulator); //add new item to database } if (item.Visible || showHidden) { items.Add(item); } } } String[] keys = new String[items.Count]; for (int i = 0; i < items.Count; i++) { keys[i] = items[i].Title; //Sort items by title } Game[] listToReturn = items.ToArray(); Array.Sort(keys, listToReturn); return(listToReturn); }