Skip to content

Commit

Permalink
UI Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
weespin committed Jun 1, 2021
1 parent 26e6453 commit 46aa7e1
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 50 deletions.
1 change: 1 addition & 0 deletions Form1.Designer.cs

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

60 changes: 53 additions & 7 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -17,7 +18,8 @@ namespace KhinsiderDownloader
{
public partial class Form1 : Form
{


public static string programName = "KhinsiderDownloader";
class UpdateTagResult
{
public string tag_name { get; set; }
Expand Down Expand Up @@ -48,7 +50,7 @@ private void checkUpdates()
{
label1.Invoke(new Action(() =>
{
label1.Text = "BETA " + label1.Text;
label1.Text = "DEV " + label1.Text;
}));

}
Expand All @@ -61,9 +63,10 @@ public Form1()
InitializeComponent();
Program.MainForm = this;
lbl_path.Text = Downloader.sDownloadPath;
Downloader.g_parralelopt.MaxDegreeOfParallelism = 2;
num_threads.Value = 2;
LoadConfig();
Task.Run(() => { checkUpdates(); });
num_threads.Value = 2;
}

public void Log(string textIn)
Expand Down Expand Up @@ -118,6 +121,9 @@ void SaveConfig()
private void button1_Click(object sender, EventArgs e)
{
btn_download.Enabled = false;
radio_betterquality.Enabled = false;
radio_mp3only.Enabled = false;
btn_selectpath.Enabled = false;
List<string> urls = txt_urllist.Text.Split(new string[] {Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToList();
Task.Run(() =>
{
Expand All @@ -132,6 +138,10 @@ private void button1_Click(object sender, EventArgs e)
btn_download.Invoke(new Action(() =>
{
btn_download.Enabled = true;
radio_betterquality.Enabled = true;
radio_mp3only.Enabled = true;
btn_selectpath.Enabled = true;

}));
}
}));
Expand Down Expand Up @@ -182,8 +192,24 @@ private void num_threads_ValueChanged(object sender, EventArgs e)

static class Downloader
{
public static ParallelOptions g_parralelopt = new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount };
public static ParallelOptions g_parralelopt = new ParallelOptions()
{MaxDegreeOfParallelism = Environment.ProcessorCount};
static void UpdateTitle(int value,int max)
{
Program.MainForm.Invoke(new Action(() =>
{
Program.MainForm.Text = $"{Form1.programName} ({value}/{max})";
}));

}

static void ResetTitle()
{
Program.MainForm.Invoke(new Action(() =>
{
Program.MainForm.Text = $"{Form1.programName}";
}));
}
public enum EDownloadQuality : byte
{
QUALITY_MP3_ONLY,
Expand All @@ -192,9 +218,11 @@ public enum EDownloadQuality : byte

public static EDownloadQuality eQuality = EDownloadQuality.QUALITY_MP3_ONLY;
public static string sDownloadPath = Directory.GetCurrentDirectory() + "\\Downloads\\";
public static CancellationTokenSource cancelTokenSource;

public static void DownloadAlbum(string sUrl)
{
cancelTokenSource = new CancellationTokenSource();
if (!Directory.Exists(Downloader.sDownloadPath))
{
Directory.CreateDirectory(Downloader.sDownloadPath);
Expand Down Expand Up @@ -257,6 +285,8 @@ public static void DownloadAlbum(string sUrl)
System.Net.ServicePointManager.DefaultConnectionLimit = Int32.MaxValue;
//foreach (var song in songNodes)
//{
int tasknum = songNodes.Count;
int currentnum = 0;
Parallel.ForEach(songNodes, g_parralelopt,song=>
{
var songPageURL = "https://downloads.khinsider.com" + song.ChildNodes[0].Attributes["href"].Value;
Expand Down Expand Up @@ -313,7 +343,12 @@ public static void DownloadAlbum(string sUrl)
Task currentTask = downloadClient.DownloadFileTaskAsync(new Uri(songFileURL), filename);
currentTasks.Add(currentTask);
currentTask.ContinueWith((
task => { Program.MainForm.Log($"{name} has been downloaded!"); }));
task =>
{
++currentnum;
UpdateTitle(currentnum, tasknum);
Program.MainForm.Log($"{name} has been downloaded!");
}));
}
catch (Exception e)
{
Expand All @@ -328,8 +363,19 @@ public static void DownloadAlbum(string sUrl)
}
//}// for foreach
});
Task.WaitAll(currentTasks.ToArray());
Program.MainForm.Log($"Finished downloading {albumName}!");
Task.WaitAll(currentTasks.ToArray(), cancelTokenSource.Token);
if (cancelTokenSource.IsCancellationRequested)
{
Program.MainForm.Log($"Download was cancelled!");

}
else
{
Program.MainForm.Log($"Finished downloading {albumName}!");

}

ResetTitle();
}


Expand Down
1 change: 1 addition & 0 deletions KhinsiderDownloader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
</ItemGroup>
<ItemGroup>
<Content Include="icon.ico" />
<None Include="Resources\no-image.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
8 changes: 4 additions & 4 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
[assembly: AssemblyTitle("KhinsiderDownloader")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCompany("Weespin")]
[assembly: AssemblyProduct("KhinsiderDownloader")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyCopyright("Weespin 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.2.1.0")]
[assembly: AssemblyFileVersion("2.2.1.0")]
[assembly: AssemblyVersion("2.3.0.0")]
[assembly: AssemblyFileVersion("2.3.0.0")]
10 changes: 10 additions & 0 deletions Properties/Resources.Designer.cs

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

17 changes: 12 additions & 5 deletions Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
Expand All @@ -60,6 +60,7 @@
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
Expand All @@ -68,9 +69,10 @@
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
Expand All @@ -85,9 +87,10 @@
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
Expand All @@ -109,9 +112,13 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="no_image" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\no-image.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
Binary file added Resources/no-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 46aa7e1

Please sign in to comment.