Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
zamgi authored and zamgi committed Sep 9, 2024
1 parent 1185bc1 commit c006efc
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 10 deletions.
2 changes: 1 addition & 1 deletion m3u8.client.tests/m3u8.client.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<!--<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />-->
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
(for live stream)</TextBlock>
<NumericUpDown x:Name="liveStreamMaxSizeInMbNumUpDn" Grid.Row="0" Grid.Column="2"
Minimum="1" Maximum="10000000" Value="250"
AllowSpin="True" ClipValueToMinMax="True"
AllowSpin="True" ClipValueToMinMax="True" FormatString="0"
HorizontalAlignment="Left" Margin="10,0,0,0" Padding="0" />

<DockPanel Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="4" HorizontalAlignment="Center" VerticalAlignment="Bottom">
Expand Down
6 changes: 3 additions & 3 deletions m3u8.download.manager/Avalonia/View/ParallelismForm.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<StackPanel>
<TextBlock>max download threads:</TextBlock>
<NumericUpDown x:Name="maxDegreeOfParallelismNUD" Minimum="1" Maximum="100" Value="1"
AllowSpin="True" ClipValueToMinMax="True"
AllowSpin="True" ClipValueToMinMax="True" FormatString="0"
HorizontalAlignment="Center" Margin="0,5,35,0" Padding="0" />
<CheckBox x:Name="useCrossDownloadInstanceParallelismCheckBox" Background="White" Cursor="Hand"
ToolTip.Tip="checked - share &quot;max download threads&quot; between all downloads-instance &#xA; unchecked - use &quot;max download threads&quot; per each downloads-instance">
Expand All @@ -37,7 +37,7 @@
<TextBlock x:Name="maxCrossDownloadInstanceLabel1">max count of downloads-instance for</TextBlock>
<TextBlock x:Name="maxCrossDownloadInstanceLabel2">simultaneously downloading data:</TextBlock>
<NumericUpDown x:Name="maxCrossDownloadInstanceNUD" Minimum="1" Maximum="100" Value="1"
AllowSpin="True" ClipValueToMinMax="True"
AllowSpin="True" ClipValueToMinMax="True" FormatString="0"
HorizontalAlignment="Center" Margin="0,5,35,0" Padding="0" />
</StackPanel>
</Border>
Expand All @@ -48,7 +48,7 @@
<CheckBox x:Name="isUnlimMaxSpeedThresholdCheckBox" Background="White" Cursor="Hand" Margin="0,0,0,7">Max/Unlimited speed</CheckBox>
<TextBlock x:Name="maxSpeedThresholdLabel">max speed threshold (in Mbps):</TextBlock>
<NumericUpDown x:Name="maxSpeedThresholdNUD" Minimum="1" Maximum="100" Value="20"
AllowSpin="True" ClipValueToMinMax="True"
AllowSpin="True" ClipValueToMinMax="True" FormatString="0"
HorizontalAlignment="Center" Margin="0,5,35,0" Padding="0" />
</StackPanel>
</Border>
Expand Down
2 changes: 1 addition & 1 deletion m3u8.download.manager/Avalonia/View/SettingsForm.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<NumericUpDown Grid.Row="0" Grid.Column="2"
x:Name="attemptRequestCountByPartNUD"
Minimum="1" Maximum="100" Value="1"
AllowSpin="True" ClipValueToMinMax="True"
AllowSpin="True" ClipValueToMinMax="True" FormatString="0"
HorizontalAlignment="Left" Margin="10,0,0,0" Padding="0" />
<TextBlock Grid.Row="1" Grid.Column="1"
x:Name="only4NotRunLabel1" HorizontalAlignment="Right"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<Value Profile="(Default)" />
</Setting>
<Setting Name="AttemptRequestCountByPart" Type="System.Int32" Scope="User">
<Value Profile="(Default)">3</Value>
<Value Profile="(Default)">5</Value>
</Setting>
<Setting Name="RequestTimeoutByPart" Type="System.TimeSpan" Scope="User">
<Value Profile="(Default)">00:00:45</Value>
Expand Down
203 changes: 202 additions & 1 deletion m3u8.download.manager/WinForms/UI/Controls/NumericUpDownEx.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,212 @@
using System.Runtime.InteropServices;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Text;

//using M = System.Runtime.CompilerServices.MethodImplAttribute;
//using O = System.Runtime.CompilerServices.MethodImplOptions;

namespace System.Windows.Forms
{
/// <summary>
///
/// </summary>
internal class NumericUpDownEx : NumericUpDown
{
private StringBuilder _Buf;
public NumericUpDownEx() => _Buf = new StringBuilder();

//public new int DecimalPlaces
//{
// [M(O.AggressiveInlining)] get => base.DecimalPlaces;
// set
// {
// base.DecimalPlaces = value;
// this.InitialDecimalPlaces = value;
// }
//}

//private int? _InitialDecimalPlaces;
//private int InitialDecimalPlaces
//{
// get => _InitialDecimalPlaces.GetValueOrDefault( base.DecimalPlaces );
// set
// {
// _InitialDecimalPlaces = value;

// this.ValueChanged -= NumericUpDownEx_ValueChanged;
// if ( value != 0 )
// {
// this.ValueChanged += NumericUpDownEx_ValueChanged;
// }
// }
//}

////private static (int trimLength, bool trimDecimalSeparator) TrimEndDecimalPlaces( string s, char decimalSeparator )
////{
//// var trimLength = 0;
//// var trimDecimalSeparator = false;
//// for ( var i = s.Length - 1; 0 <= i; i-- )
//// {
//// var ch = s[ i ];
//// if ( ch != '0' )
//// {
//// if ( ch == '.' || ch == ',' )
//// {
//// trimDecimalSeparator = true;
//// }
//// break;
//// }
//// trimLength++;
//// }
//// return (trimLength, trimDecimalSeparator);
////}
//private static (int trimLength, bool trimDecimalSeparator) TrimEndDecimalPlaces( string s, string decimalSeparator )
//{
// var sep_idx = s.IndexOf( decimalSeparator );
// if ( sep_idx == -1 ) return (0, false);

// var trimLength = 0;
// var trimDecimalSeparator = false;
// for ( var i = s.Length - 1; sep_idx <= i; i-- )
// {
// var ch = s[ i ];
// if ( ch != '0' )
// {
// trimDecimalSeparator = (i == sep_idx);
// break;
// }
// trimLength++;
// }
// return (trimLength, trimDecimalSeparator);
//}
//private static (int trimLength, bool trimDecimalSeparator) TrimEndDecimalPlaces( string s, int decimalSeparatorIndex )
//{
// if ( decimalSeparatorIndex == -1 ) return (0, false);

// var trimLength = 0;
// var trimDecimalSeparator = false;
// for ( var i = s.Length - 1; decimalSeparatorIndex <= i; i-- )
// {
// var ch = s[ i ];
// if ( ch != '0' )
// {
// trimDecimalSeparator = (i == decimalSeparatorIndex);
// break;
// }
// trimLength++;
// }
// return (trimLength, trimDecimalSeparator);
//}
//private static (int count, int decimalSeparatorIndex) GetDigitCountAfterDecimalSeparator( string s, string decimalSeparator )
//{
// var sep_idx = s.IndexOf( decimalSeparator );
// if ( sep_idx == -1 ) return (0, -1);

// var cnt = s.Length - sep_idx - 1;
// return (cnt, sep_idx);
//}
//private void Set_DecimalPlaces_IfChanged( int dp )
//{
// if ( base.DecimalPlaces != dp ) base.DecimalPlaces = dp;
//}
//private void NumericUpDownEx_ValueChanged( object sender, EventArgs e )
//{
// var idp = this.InitialDecimalPlaces;
// if ( idp == 0 )
// {
// this.ValueChanged -= NumericUpDownEx_ValueChanged;
// return;
// }

// var v = this.Value;
// var v_i32 = (int) v;
// if ( v == v_i32 )
// {
// Set_DecimalPlaces_IfChanged( 0 );
// }
// else
// {
// var v_txt = v.ToString();
// var (count, decimalSeparatorIndex) = GetDigitCountAfterDecimalSeparator( v_txt, Application.CurrentCulture.NumberFormat.NumberDecimalSeparator );
// v_txt = v_txt.PadRight( v_txt.Length + Math.Max( 0, idp - count ), '0' );
// var (trimLength, trimDecimalSeparator) = TrimEndDecimalPlaces( v_txt, decimalSeparatorIndex );
// if ( 0 < trimLength )
// {
// Set_DecimalPlaces_IfChanged( trimDecimalSeparator ? 0 : Math.Max( 0, idp - trimLength ) );
// }
// else
// {
// Set_DecimalPlaces_IfChanged( idp );
// }
// }
//}


protected override void UpdateEditText()
{
// If we're initializing, we don't want to update the edit text yet,
// just in case the value is invalid.
//if ( _initializing )
//{
// return;
//}

// If the current value is user-edited, then parse this value before reformatting
if ( UserEdit )
{
ParseEditText();
}

//---base.UpdateEditText();

// Verify that the user is not starting the string with a "-"
// before attempting to set the Value property since a "-" is a valid character with
// which to start a string representing a negative number.
var txt = this.Text;
if ( !string.IsNullOrEmpty( txt ) && !(txt.Length == 1 && txt == "-") )
{
this.ChangingText = true;

this.Text = GetNumberText( this.Value );
}
}
private string GetNumberText( decimal d )
{
string txt;
if ( this.Hexadecimal )
{
txt = ((long) d).ToString( "X", CultureInfo.InvariantCulture );
}
else
{
//---txt = d.ToString( $"{(this.ThousandsSeparator ? "N" : "F")}{base.DecimalPlaces}", CultureInfo.CurrentCulture );
txt = d.ToString( $"F{base.DecimalPlaces}", CultureInfo.CurrentCulture );
txt = TrimEndDecimalPlaces( txt, Application.CurrentCulture.NumberFormat.NumberDecimalSeparator, _Buf );
}
return (txt);
}
private static string TrimEndDecimalPlaces( string s, string decimalSeparator, StringBuilder buf )
{
var sep_idx = s.IndexOf( decimalSeparator );
if ( sep_idx == -1 ) return (s);

var trimLength = 0;
var trimDecimalSeparator = false;
for ( var i = s.Length - 1; sep_idx <= i; i-- )
{
var ch = s[ i ];
if ( ch != '0' )
{
trimDecimalSeparator = (i == sep_idx);
break;
}
trimLength++;
}
var n_s = buf.Clear().Append( s, 0, s.Length - trimLength - (trimDecimalSeparator ? 1 : 0) ).ToString();
return (n_s);
}


public decimal? Increment_MouseWheel { get; set; }
public bool Round2NextTenGroup { get; set; }
public int ValueAsInt32 { get => (int) this.Value; set => this.Value = value; }
Expand Down Expand Up @@ -80,6 +279,8 @@ protected override void WndProc( ref Message m )
}
}

public NumericUpDownEx_Transparent() { }

protected override void OnCreateControl()
{
base.OnCreateControl();
Expand Down

0 comments on commit c006efc

Please sign in to comment.