Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
zamgi authored and zamgi committed Feb 5, 2025
1 parent 252acdf commit 4088448
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 28 deletions.
10 changes: 5 additions & 5 deletions m3u8.download.manager/WinForms/Infrastructure/WinApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ public enum GetWindowEnum : uint
//*/
#endregion

#region [..]
[DllImport(USER32_DLL)][return:MarshalAs(UnmanagedType.Bool)] private static extern bool ClipCursor( IntPtr lpRect );
public static bool RemoveClipCursor() => ClipCursor( IntPtr.Zero );
#endregion

#region [.SetForceForegroundWindow.]
[ DllImport(USER32_DLL)] public static extern IntPtr GetForegroundWindow();
[DllImport(USER32_DLL)] private static extern uint GetWindowThreadProcessId( IntPtr hWnd, IntPtr processId );
Expand Down Expand Up @@ -179,5 +174,10 @@ public static bool ShellExploreAndSelectFile( string filePath, out Exception err
return (false);
}
#endregion

#region [.ClipCursor.]
[DllImport(USER32_DLL)][return:MarshalAs(UnmanagedType.Bool)] private static extern bool ClipCursor( IntPtr lpRect );
public static bool RemoveClipCursor() => ClipCursor( IntPtr.Zero );
#endregion
}
}
41 changes: 18 additions & 23 deletions m3u8.download.manager/WinForms/UI/UC/LogUC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using CellStyle = System.Windows.Forms.DataGridViewCellStyle;
using M = System.Runtime.CompilerServices.MethodImplAttribute;
using O = System.Runtime.CompilerServices.MethodImplOptions;
using static m3u8.download.manager.ui.DefaultColors;

namespace m3u8.download.manager.ui
{
Expand Down Expand Up @@ -694,20 +693,17 @@ private void DGV_MouseClick( object sender, MouseEventArgs e )
switch ( e.Button )
{
case MouseButtons.Left:
if ( AllowDrawDownloadButtonForM3u8Urls )
if ( AllowDrawDownloadButtonForM3u8Urls && (0 <= hti.RowIndex) )
{
var row_rc = DGV.GetRowDisplayRectangle( hti.RowIndex, cutOverflow: true );
var m3u8_Url_ButtonRect = Get_M3u8_Url_ButtonRect( row_rc );
if ( m3u8_Url_ButtonRect.Contains( e.Location ) )
{
var m3u8FileUrl = _Model[ hti.RowIndex ].RequestText;
if ( !UrlHelper.TryGetM3u8FileUrl( m3u8FileUrl, out var x ) )
if ( Is_M3u8_Url( m3u8FileUrl ) && UrlHelper.TryGetM3u8FileUrl( m3u8FileUrl, out var x ) )
{
//---this.FindForm().MessageBox_ShowError( x.error.ToString(), "Download Additional '.m3u8' url" );
return;
DownloadAdditionalM3u8Url?.Invoke( x.m3u8FileUrl );
}

DownloadAdditionalM3u8Url?.Invoke( x.m3u8FileUrl );
}
}
break;
Expand All @@ -720,20 +716,20 @@ private void DGV_MouseClick( object sender, MouseEventArgs e )
private void DGV_MouseMove( object sender, MouseEventArgs e )
{
var hti = DGV.HitTest( e.X, e.Y );
if ( (0 <= hti.RowIndex) || (0 <= hti.ColumnIndex) )
if ( (0 <= hti.RowIndex) && (0 <= hti.ColumnIndex) )
{
var row_rc = DGV.GetRowDisplayRectangle( hti.RowIndex, cutOverflow: true );
var m3u8_Url_ButtonRect = Get_M3u8_Url_ButtonRect( row_rc );
if ( m3u8_Url_ButtonRect.Contains( e.Location ) )
{
var m3u8FileUrl = _Model[ hti.RowIndex ].RequestText;
if ( UrlHelper.TryGetM3u8FileUrl( m3u8FileUrl, out var x ) )
if ( Is_M3u8_Url( m3u8FileUrl ) && UrlHelper.TryGetM3u8FileUrl( m3u8FileUrl, out var x ) )
{
DGV.Cursor = Cursors.Hand;
DGV.ShowCellErrors = DGV.ShowRowErrors = false;
DGV.ShowCellToolTips = false;
var f = this.FindForm();
toolTip.Show( $"Download Additional '.m3u8' url: '{m3u8FileUrl}')", f, f.PointToClient( DGV.PointToScreen( e.Location ) ), duration: 1_500 );
toolTip.Show( $"Download Additional '.m3u8' url: '{Ellipsis.MinimizePath( x.m3u8FileUrl.ToString(), 50 )}'", f, f.PointToClient( DGV.PointToScreen( e.Location ) ), duration: 1_500 );
return;
}
}
Expand Down Expand Up @@ -879,19 +875,6 @@ private void DGV_CellPainting( object sender, DataGridViewCellPaintingEventArgs
}
}
}
private static Rectangle Get_M3u8_Url_ButtonRect( in Rectangle rc )
{
var h = rc.Height - 4;
return (new Rectangle( rc.Right - h - 2, rc.Y + 2, h, h ));
}
private static bool Is_M3u8_Url( string text )
{
Debug.Assert( text != null );
var suc = (text.StartsWith( "http://", StringComparison.OrdinalIgnoreCase ) ||
text.StartsWith( "https://", StringComparison.OrdinalIgnoreCase )) &&
text.Split( '?' ).First().Split( '.' ).LastOrDefault().EqualIgnoreCase( "m3u8" );
return (suc);
}
private void DGV_RowDividerDoubleClick( object sender, DataGridViewRowDividerDoubleClickEventArgs e )
{
e.Handled = true;
Expand Down Expand Up @@ -928,6 +911,18 @@ private void DGV_RowDividerDoubleClick( object sender, DataGridViewRowDividerDou
var font = arg.CellStyle.Font;
sz = gr.MeasureString( text, font, DGV.Columns[ columnIndex ].Width, _SF );
}
[M(O.AggressiveInlining)] private static Rectangle Get_M3u8_Url_ButtonRect( in Rectangle rc )
{
var h = rc.Height - 4;
return (new Rectangle( rc.Right - h - 2, rc.Y + 2, h, h ));
}
[M(O.AggressiveInlining)] private static bool Is_M3u8_Url( string text )
{
var suc = (text != null) &&
(text.StartsWithOrdinalIgnoreCase( "http://" ) || text.StartsWithOrdinalIgnoreCase( "https://" )) &&
text.Split( '?' ).First().Split( '.' ).LastOrDefault().EqualIgnoreCase( "m3u8" );
return (suc);
}
#endregion
}
}
1 change: 1 addition & 0 deletions m3u8.download.manager/[Common]/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ internal static partial class Extensions
[M(O.AggressiveInlining)] public static T? Try2Enum< T >( this string s ) where T : struct => (Enum.TryParse< T >( s, true, out var t ) ? t : null);
[M(O.AggressiveInlining)] public static bool EqualIgnoreCase( this string s1, string s2 ) => (string.Compare( s1, s2, true ) == 0);
[M(O.AggressiveInlining)] public static bool ContainsIgnoreCase( this string s1, string s2 ) => ((s1 != null) && (s1.IndexOf( s2, StringComparison.InvariantCultureIgnoreCase ) != -1));
[M(O.AggressiveInlining)] public static bool StartsWithOrdinalIgnoreCase( this string s1, string s2 ) => /*(s1 != null) &&*/ s1.StartsWith( s2, StringComparison.OrdinalIgnoreCase );
public static void Remove< T >( this HashSet< T > hs, IEnumerable< T > seq )
{
if ( seq != null )
Expand Down

0 comments on commit 4088448

Please sign in to comment.