diff --git a/MPfm/MPfm.Core/Conversion.cs b/MPfm/MPfm.Core/Conversion.cs index 7872caee..91563b9b 100644 --- a/MPfm/MPfm.Core/Conversion.cs +++ b/MPfm/MPfm.Core/Conversion.cs @@ -264,19 +264,6 @@ public static T TryParse(string input) return default(T); } - /// - /// Returns the value of an enum, as specified in the generics parameter. - /// - /// Enum type - /// Value - /// Enum with value - public static T GetEnumValue(string value) where T : struct - { - T obj = new T(); - Enum.TryParse(value, out obj); - return obj; - } - public static short HighWord(int dWord) { return (short)(dWord >> 16 & 65535); diff --git a/MPfm/MPfm.Library/Database/DatabaseFacade.cs b/MPfm/MPfm.Library/Database/DatabaseFacade.cs index 58108178..0ffad71b 100644 --- a/MPfm/MPfm.Library/Database/DatabaseFacade.cs +++ b/MPfm/MPfm.Library/Database/DatabaseFacade.cs @@ -95,7 +95,7 @@ public List SelectAudioFiles(AudioFileFormat format, string artistNam if(format != AudioFileFormat.All) { count++; - sql.AppendLine(" [FileType] = '" + format.ToString() + "'"); + sql.AppendLine(" [FileType] = '" + FormatSQLValue(format.ToString()) + "'"); } if(!String.IsNullOrEmpty(artistName)) { @@ -104,7 +104,7 @@ public List SelectAudioFiles(AudioFileFormat format, string artistNam { sql.AppendLine(" AND "); } - sql.AppendLine(" [ArtistName] = '" + artistName + "' "); + sql.AppendLine(" [ArtistName] = '" + FormatSQLValue(artistName) + "' "); } if(!String.IsNullOrEmpty(albumTitle)) { @@ -113,7 +113,7 @@ public List SelectAudioFiles(AudioFileFormat format, string artistNam { sql.AppendLine(" AND "); } - sql.AppendLine(" [AlbumTitle] = '" + albumTitle + "' "); + sql.AppendLine(" [AlbumTitle] = '" + FormatSQLValue(albumTitle) + "' "); } if(!String.IsNullOrEmpty(search)) { @@ -197,7 +197,7 @@ public void DeleteAudioFile(Guid audioFileId) /// Base audio file path public void DeleteAudioFiles(string basePath) { - _gateway.Delete("AudioFiles", "FilePath LIKE '" + basePath + "%'"); + _gateway.Delete("AudioFiles", "FilePath LIKE '" + FormatSQLValue(basePath) + "%'"); } /// @@ -274,7 +274,7 @@ public List SelectDistinctArtistNames(AudioFileFormat audioFileFormat) sql.AppendLine("SELECT DISTINCT ArtistName, AlbumTitle FROM AudioFiles "); if (audioFileFormat != AudioFileFormat.All && !String.IsNullOrEmpty(artistName)) { - sql.AppendLine(" WHERE FileType = '" + audioFileFormat.ToString() + "' AND ArtistName = '" + artistName.Replace("'", "''") + "'"); + sql.AppendLine(" WHERE FileType = '" + audioFileFormat.ToString() + "' AND ArtistName = '" + FormatSQLValue(artistName) + "'"); } else if (audioFileFormat != AudioFileFormat.All) { @@ -282,7 +282,7 @@ public List SelectDistinctArtistNames(AudioFileFormat audioFileFormat) } else if(!String.IsNullOrEmpty(artistName)) { - sql.AppendLine(" WHERE ArtistName = '" + artistName.Replace("'", "''").ToString() + "' "); + sql.AppendLine(" WHERE ArtistName = '" + FormatSQLValue(artistName) + "' "); } sql.AppendLine(" ORDER BY ArtistName"); @@ -387,7 +387,7 @@ public void UpdatePlayCount(Guid audioFileId) /// Folder public Folder SelectFolderByPath(string path) { - Folder folder = _gateway.SelectOne("SELECT * FROM Folders WHERE FolderPath = '" + path + "'"); + Folder folder = _gateway.SelectOne("SELECT * FROM Folders WHERE FolderPath = '" + FormatSQLValue(path) + "'"); return folder; } @@ -455,7 +455,7 @@ public List SelectEQPresets() /// EQPreset public EQPreset SelectEQPreset(string name) { - EQPreset preset = _gateway.SelectOne("SELECT * FROM EQPresets WHERE Name = '" + name + "'"); + EQPreset preset = _gateway.SelectOne("SELECT * FROM EQPresets WHERE Name = '" + FormatSQLValue(name) + "'"); return preset; } @@ -804,7 +804,7 @@ public List SelectSettings() /// Setting object public Setting SelectSetting(string name) { - Setting setting = _gateway.SelectOne("SELECT * FROM Settings WHERE SettingName = '" + name + "'"); + Setting setting = _gateway.SelectOne("SELECT * FROM Settings WHERE SettingName = '" + FormatSQLValue(name) + "'"); return setting; } @@ -882,7 +882,7 @@ public void InsertPlaylistFile(PlaylistFile dto) public void DeletePlaylistFile(string filePath) { // Delete loop - _gateway.Delete("PlaylistFiles", "FilePath = '" + filePath + "'"); + _gateway.Delete("PlaylistFiles", "FilePath = '" + FormatSQLValue(filePath) + "'"); } #endregion @@ -1006,5 +1006,10 @@ public void CompactDatabase() { _gateway.CompactDatabase(); } + + private string FormatSQLValue(string value) + { + return value.Replace("'", "''"); + } } } diff --git a/MPfm/MPfm.Library/Database/MonoSQLiteGateway.cs b/MPfm/MPfm.Library/Database/MonoSQLiteGateway.cs index faeee4b7..0db14e86 100644 --- a/MPfm/MPfm.Library/Database/MonoSQLiteGateway.cs +++ b/MPfm/MPfm.Library/Database/MonoSQLiteGateway.cs @@ -453,9 +453,7 @@ public List Select(string sql) where T : new() // Check if the type is an enum if (info.PropertyType.IsEnum) { - // Try to cast dynamically - MethodInfo castMethod = typeof(Conversion).GetMethod("GetEnumValue").MakeGenericMethod(info.PropertyType); - fieldValue = castMethod.Invoke(null, new object[] { fieldValue.ToString() }); + fieldValue = Enum.Parse(info.PropertyType, fieldValue.ToString()); } else if (info.PropertyType.FullName.ToUpper() == "SYSTEM.GUID") { diff --git a/MPfm/MPfm.iOS/MPfm.iOS.csproj b/MPfm/MPfm.iOS/MPfm.iOS.csproj index 7bad4856..0c0059e5 100644 --- a/MPfm/MPfm.iOS/MPfm.iOS.csproj +++ b/MPfm/MPfm.iOS/MPfm.iOS.csproj @@ -50,12 +50,13 @@ prompt 4 False - iPhone Developer + iPhone Developer: Yanick Castonguay (N8WC5U9B3N) True ARMv7 -v -v -v -gcc_flags "-L${ProjectDir}/Lib/ -framework Accelerate -ObjC -lstdc++ -lbass -lbassmix -lbass_fx -lbass_ape -lbass_mpc -lbassflac -lbasswv -all_load" + 1DD1E6B7-C93C-4B7E-BC11-47742877E8E0 none