Skip to content

Commit

Permalink
Merge branch 'pr/10'
Browse files Browse the repository at this point in the history
  • Loading branch information
torshy committed Jan 19, 2015
2 parents 0693546 + caac3d9 commit 92a31b1
Show file tree
Hide file tree
Showing 19 changed files with 37 additions and 45 deletions.
6 changes: 6 additions & 0 deletions src/Torshify.Shell/Program.cs
Expand Up @@ -132,6 +132,12 @@ protected void SearchMenu()
ConsoleEx.Write("Query >> ", ConsoleColor.Green);
string query = Console.ReadLine();

if (string.IsNullOrEmpty(query))
{
ConsoleEx.WriteLine("Query string for search can't be empty", ConsoleColor.Red);
return;
}

ConsoleEx.WriteLine("Searching..", ConsoleColor.Yellow);
ISearch search = Session
.Search(query, 0, 25, 0, 25, 0, 25, 0, 25, SearchType.Standard)
Expand Down
1 change: 0 additions & 1 deletion src/Torshify/Core/Native/NativeAlbum.cs
Expand Up @@ -153,7 +153,6 @@ protected override void Dispose(bool disposing)
finally
{
AlbumManager.Remove(Handle);
Handle = IntPtr.Zero;
}

Debug.WriteLine("Album disposed");
Expand Down
3 changes: 1 addition & 2 deletions src/Torshify/Core/Native/NativeAlbumBrowse.cs
Expand Up @@ -176,8 +176,7 @@ protected override void Dispose(bool disposing)
{
lock (Spotify.Mutex)
{
Spotify.sp_albumbrowse_release(Handle);
Handle = IntPtr.Zero;
Ensure(() => Spotify.sp_albumbrowse_release(Handle));
}
}
catch
Expand Down
3 changes: 1 addition & 2 deletions src/Torshify/Core/Native/NativeArtist.cs
Expand Up @@ -86,7 +86,7 @@ protected override void Dispose(bool disposing)
{
lock (Spotify.Mutex)
{
Spotify.sp_artist_release(Handle);
Ensure(() => Spotify.sp_artist_release(Handle));
}
}
catch
Expand All @@ -95,7 +95,6 @@ protected override void Dispose(bool disposing)
finally
{
ArtistManager.Remove(Handle);
Handle = IntPtr.Zero;
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/Torshify/Core/Native/NativeArtistBrowse.cs
Expand Up @@ -202,8 +202,7 @@ protected override void Dispose(bool disposing)
{
lock (Spotify.Mutex)
{
Spotify.sp_artistbrowse_release(Handle);
Handle = IntPtr.Zero;
Ensure(() => Spotify.sp_artistbrowse_release(Handle));
}

GC.KeepAlive(_browseCompleteCallback);
Expand Down
10 changes: 4 additions & 6 deletions src/Torshify/Core/Native/NativeImage.cs
Expand Up @@ -177,17 +177,15 @@ protected override void Dispose(bool disposing)
{
lock (Spotify.Mutex)
{
Spotify.sp_image_remove_load_callback(Handle, _imageLoaded, IntPtr.Zero);
Spotify.sp_image_release(Handle);
Ensure(() => {
Spotify.sp_image_remove_load_callback(Handle, _imageLoaded, IntPtr.Zero);
Spotify.sp_image_release(Handle);
});
}
}
catch
{
}
finally
{
Handle = IntPtr.Zero;
}
}

base.Dispose(disposing);
Expand Down
3 changes: 1 addition & 2 deletions src/Torshify/Core/Native/NativeLink.cs
Expand Up @@ -103,7 +103,7 @@ protected override void Dispose(bool disposing)
{
lock (Spotify.Mutex)
{
Spotify.sp_link_release(Handle);
Ensure(() => Spotify.sp_link_release(Handle));
}
}
catch
Expand All @@ -112,7 +112,6 @@ protected override void Dispose(bool disposing)
finally
{
LinkManager.Remove(Handle);
Handle = IntPtr.Zero;
}

#if DEBUG_VERBOSE
Expand Down
3 changes: 1 addition & 2 deletions src/Torshify/Core/Native/NativePlaylist.cs
Expand Up @@ -387,7 +387,7 @@ protected override void Dispose(bool disposing)

try
{
Spotify.sp_playlist_release(Handle);
Ensure(() => Spotify.sp_playlist_release(Handle));
}
catch
{
Expand All @@ -396,7 +396,6 @@ protected override void Dispose(bool disposing)
{
PlaylistTrackManager.RemoveAll(this);
PlaylistManager.Remove(Handle);
Handle = IntPtr.Zero;
Debug.WriteLine("Playlist disposed");
}
}
Expand Down
1 change: 0 additions & 1 deletion src/Torshify/Core/Native/NativePlaylistContainer.cs
Expand Up @@ -146,7 +146,6 @@ protected override void Dispose(bool disposing)
finally
{
PlaylistContainerManager.Remove(Handle);
Handle = IntPtr.Zero;
Debug.WriteLine("Playlist container disposed");
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/Torshify/Core/Native/NativeSearch.cs
Expand Up @@ -311,8 +311,7 @@ protected override void Dispose(bool disposing)

lock (Spotify.Mutex)
{
Spotify.sp_search_release(Handle);
Handle = IntPtr.Zero;
Ensure(() => Spotify.sp_search_release(Handle));
}
}
catch
Expand Down
3 changes: 1 addition & 2 deletions src/Torshify/Core/Native/NativeSession.cs
Expand Up @@ -951,9 +951,8 @@ protected override void Dispose(bool disposing)
Debug.WriteLineIf(error != Error.OK, error.GetMessage());
}

error = Spotify.sp_session_release(Handle);
Ensure(() => error = Spotify.sp_session_release(Handle));
Debug.WriteLineIf(error != Error.OK, error.GetMessage());
Handle = IntPtr.Zero;
}
}
catch
Expand Down
4 changes: 0 additions & 4 deletions src/Torshify/Core/Native/NativeToplistBrowse.cs
Expand Up @@ -178,10 +178,6 @@ protected override void Dispose(bool disposing)
catch
{
}
finally
{
Handle = IntPtr.Zero;
}
}

base.Dispose(disposing);
Expand Down
3 changes: 1 addition & 2 deletions src/Torshify/Core/Native/NativeTrack.cs
Expand Up @@ -289,7 +289,7 @@ protected override void Dispose(bool disposing)
{
lock (Spotify.Mutex)
{
Spotify.sp_track_release(Handle);
Ensure(() => Spotify.sp_track_release(Handle));
}
}
catch
Expand All @@ -298,7 +298,6 @@ protected override void Dispose(bool disposing)
finally
{
TrackManager.Remove(Handle);
Handle = IntPtr.Zero;
Debug.WriteLine("Track disposed");
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/Torshify/Core/Native/NativeUser.cs
Expand Up @@ -83,16 +83,12 @@ protected override void Dispose(bool disposing)
{
lock (Spotify.Mutex)
{
Spotify.sp_user_release(Handle);
Ensure(() => Spotify.sp_user_release(Handle));
}
}
catch
{
}
finally
{
Handle = IntPtr.Zero;
}
}

base.Dispose(disposing);
Expand Down
1 change: 1 addition & 0 deletions src/Torshify/Core/Native/Spotify.Error.cs
Expand Up @@ -11,6 +11,7 @@ internal partial class Spotify
/// <param name="error">The error code.</param>
/// <returns>The text-representation of the error.</returns>
[DllImport("libspotify")]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(MarshalPtrToUtf8))]
public static extern string sp_error_message(Error error);
}
}
3 changes: 3 additions & 0 deletions src/Torshify/Core/Native/Spotify.Search.cs
Expand Up @@ -195,6 +195,7 @@ internal partial class Spotify
/// <param name="index"></param>
/// <returns></returns>
[DllImport("libspotify")]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(MarshalPtrToUtf8))]
internal static extern string sp_search_playlist_name(IntPtr searchPtr, int index);

/// <summary>
Expand All @@ -204,6 +205,7 @@ internal partial class Spotify
/// <param name="index"></param>
/// <returns></returns>
[DllImport("libspotify")]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(MarshalPtrToUtf8))]
internal static extern string sp_search_playlist_uri(IntPtr searchPtr, int index);

/// <summary>
Expand All @@ -213,6 +215,7 @@ internal partial class Spotify
/// <param name="index"></param>
/// <returns></returns>
[DllImport("libspotify")]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(MarshalPtrToUtf8))]
internal static extern string sp_search_playlist_image_uri(IntPtr searchPtr, int index);
}
}
1 change: 1 addition & 0 deletions src/Torshify/Core/Native/Spotify.Session.cs
Expand Up @@ -12,6 +12,7 @@ internal partial class Spotify
/// </summary>
/// <returns></returns>
[DllImport("libspotify")]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(MarshalPtrToUtf8))]
internal static extern string sp_build_id();

/// <summary>
Expand Down
12 changes: 0 additions & 12 deletions src/Torshify/Core/Native/Spotify.cs
Expand Up @@ -16,18 +16,6 @@ internal static partial class Spotify

#endregion Fields

#region Constructors

static Spotify()
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("torshify uses SPOTIFY(R) CORE");
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine(sp_build_id());
}

#endregion Constructors

#region Enumerations

internal enum SpotifySampletype
Expand Down
13 changes: 13 additions & 0 deletions src/Torshify/Core/NativeObject.cs
Expand Up @@ -89,6 +89,8 @@ protected virtual void Dispose(bool disposing)
}

// get rid of unmanaged resources

Handle = IntPtr.Zero;
}

protected void AssertHandle()
Expand All @@ -99,6 +101,17 @@ protected void AssertHandle()
}
}

public void Ensure(Action action)
{
if ((Session is NativeObject) && !(Session as NativeObject).IsInvalid)
{
if (action != null)
{
action();
}
}
}

#endregion Protected Methods
}
}

0 comments on commit 92a31b1

Please sign in to comment.