diff --git a/Source/AaxDecrypter/NetworkFileStream.cs b/Source/AaxDecrypter/NetworkFileStream.cs index 54b351c5..259b3526 100644 --- a/Source/AaxDecrypter/NetworkFileStream.cs +++ b/Source/AaxDecrypter/NetworkFileStream.cs @@ -9,435 +9,435 @@ using System.Threading; namespace AaxDecrypter { - /// - /// A for a single Uri. - /// - public class SingleUriCookieContainer : CookieContainer - { - private Uri baseAddress; - public Uri Uri - { - get => baseAddress; - set - { - baseAddress = new UriBuilder(value.Scheme, value.Host).Uri; - } - } - - public CookieCollection GetCookies() - { - return GetCookies(Uri); - } - } - - /// - /// A resumable, simultaneous file downloader and reader. - /// - public class NetworkFileStream : Stream, IUpdatable - { - public event EventHandler Updated; - - #region Public Properties - - /// - /// Location to save the downloaded data. - /// - [JsonProperty(Required = Required.Always)] - public string SaveFilePath { get; } - - /// - /// Http(s) address of the file to download. - /// - [JsonProperty(Required = Required.Always)] - public Uri Uri { get; private set; } - - /// - /// All cookies set by caller or by the remote server. - /// - [JsonProperty(Required = Required.Always)] - public SingleUriCookieContainer CookieContainer { get; } - - /// - /// Http headers to be sent to the server with the request. - /// - [JsonProperty(Required = Required.Always)] - public WebHeaderCollection RequestHeaders { get; private set; } - - /// - /// The position in that has been written and flushed to disk. - /// - [JsonProperty(Required = Required.Always)] - public long WritePosition { get; private set; } - - /// - /// The total length of the file to download. - /// - [JsonProperty(Required = Required.Always)] - public long ContentLength { get; private set; } - - #endregion - - #region Private Properties - private HttpWebRequest HttpRequest { get; set; } - private FileStream _writeFile { get; } - private FileStream _readFile { get; } - private Stream _networkStream { get; set; } - private bool hasBegunDownloading { get; set; } - public bool IsCancelled { get; private set; } - private EventWaitHandle downloadEnded { get; set; } - private EventWaitHandle downloadedPiece { get; set; } - - #endregion - - #region Constants - - //Download buffer size - private const int DOWNLOAD_BUFF_SZ = 4 * 1024; - - //NetworkFileStream will flush all data in _writeFile to disk after every - //DATA_FLUSH_SZ bytes are written to the file stream. - private const int DATA_FLUSH_SZ = 1024 * 1024; - - #endregion - - #region Constructor - - /// - /// A resumable, simultaneous file downloader and reader. - /// - /// Path to a location on disk to save the downloaded data from - /// Http(s) address of the file to download. - /// The position in to begin downloading. - /// Http headers to be sent to the server with the . - /// A with cookies to send with the . It will also be populated with any cookies set by the server. - public NetworkFileStream(string saveFilePath, Uri uri, long writePosition = 0, WebHeaderCollection requestHeaders = null, SingleUriCookieContainer cookies = null) - { - ArgumentValidator.EnsureNotNullOrWhiteSpace(saveFilePath, nameof(saveFilePath)); - ArgumentValidator.EnsureNotNullOrWhiteSpace(uri?.AbsoluteUri, nameof(uri)); - ArgumentValidator.EnsureGreaterThan(writePosition, nameof(writePosition), -1); - - if (!Directory.Exists(Path.GetDirectoryName(saveFilePath))) - throw new ArgumentException($"Specified {nameof(saveFilePath)} directory \"{Path.GetDirectoryName(saveFilePath)}\" does not exist."); - - SaveFilePath = saveFilePath; - Uri = uri; - WritePosition = writePosition; - RequestHeaders = requestHeaders ?? new WebHeaderCollection(); - CookieContainer = cookies ?? new SingleUriCookieContainer { Uri = uri }; - - _writeFile = new FileStream(SaveFilePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite) - { - Position = WritePosition - }; - - _readFile = new FileStream(SaveFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - - SetUriForSameFile(uri); - } - - #endregion - - #region Downloader - - /// - /// Update the . - /// - private void Update() - { - RequestHeaders = HttpRequest.Headers; - Updated?.Invoke(this, EventArgs.Empty); - } - - /// - /// Set a different to the same file targeted by this instance of - /// - /// New host must match existing host. - public void SetUriForSameFile(Uri uriToSameFile) - { - ArgumentValidator.EnsureNotNullOrWhiteSpace(uriToSameFile?.AbsoluteUri, nameof(uriToSameFile)); - - if (uriToSameFile.Host != Uri.Host) - throw new ArgumentException($"New uri to the same file must have the same host.\r\n Old Host :{Uri.Host}\r\nNew Host: {uriToSameFile.Host}"); - if (hasBegunDownloading) - throw new InvalidOperationException("Cannot change Uri after download has started."); - - Uri = uriToSameFile; - HttpRequest = WebRequest.CreateHttp(Uri); - - HttpRequest.CookieContainer = CookieContainer; - HttpRequest.Headers = RequestHeaders; - //If NetworkFileStream is resuming, Header will already contain a range. - HttpRequest.Headers.Remove("Range"); - HttpRequest.AddRange(WritePosition); - } - - /// - /// Begins downloading to in a background thread. - /// - private void BeginDownloading() - { - downloadEnded = new EventWaitHandle(false, EventResetMode.ManualReset); - - if (ContentLength != 0 && WritePosition == ContentLength) - { - hasBegunDownloading = true; - downloadEnded.Set(); - return; - } - - if (ContentLength != 0 && WritePosition > ContentLength) - throw new WebException($"Specified write position (0x{WritePosition:X10}) is larger than {nameof(ContentLength)} (0x{ContentLength:X10})."); - - var response = HttpRequest.GetResponse() as HttpWebResponse; - - if (response.StatusCode != HttpStatusCode.PartialContent) - throw new WebException($"Server at {Uri.Host} responded with unexpected status code: {response.StatusCode}."); - - //Content length is the length of the range request, and it is only equal - //to the complete file length if requesting Range: bytes=0- - if (WritePosition == 0) - ContentLength = response.ContentLength; - - _networkStream = response.GetResponseStream(); - downloadedPiece = new EventWaitHandle(false, EventResetMode.AutoReset); - - //Download the file in the background. - new Thread(() => DownloadFile()) - { IsBackground = true } - .Start(); - - hasBegunDownloading = true; - return; - } - - /// - /// Downlod to . - /// - private void DownloadFile() - { - var downloadPosition = WritePosition; - var nextFlush = downloadPosition + DATA_FLUSH_SZ; - - var buff = new byte[DOWNLOAD_BUFF_SZ]; - do - { - var bytesRead = _networkStream.Read(buff, 0, DOWNLOAD_BUFF_SZ); - _writeFile.Write(buff, 0, bytesRead); - - downloadPosition += bytesRead; - - if (downloadPosition > nextFlush) - { - _writeFile.Flush(); - WritePosition = downloadPosition; - Update(); - nextFlush = downloadPosition + DATA_FLUSH_SZ; - downloadedPiece.Set(); - } - - } while (downloadPosition < ContentLength && !IsCancelled); - - _writeFile.Close(); - _networkStream.Close(); - WritePosition = downloadPosition; - Update(); - - downloadedPiece.Set(); - downloadEnded.Set(); - - if (!IsCancelled && WritePosition < ContentLength) - throw new WebException($"Downloaded size (0x{WritePosition:X10}) is less than {nameof(ContentLength)} (0x{ContentLength:X10})."); - - if (WritePosition > ContentLength) - throw new WebException($"Downloaded size (0x{WritePosition:X10}) is greater than {nameof(ContentLength)} (0x{ContentLength:X10})."); - - } - - #endregion - - #region Json Connverters - - public static JsonSerializerSettings GetJsonSerializerSettings() - { - var settings = new JsonSerializerSettings(); - settings.Converters.Add(new CookieContainerConverter()); - settings.Converters.Add(new WebHeaderCollectionConverter()); - return settings; - } - - internal class CookieContainerConverter : JsonConverter - { - public override bool CanConvert(Type objectType) - => objectType == typeof(SingleUriCookieContainer); - - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - var jObj = JObject.Load(reader); - - var result = new SingleUriCookieContainer() - { - Uri = new Uri(jObj["Uri"].Value()), - Capacity = jObj["Capacity"].Value(), - MaxCookieSize = jObj["MaxCookieSize"].Value(), - PerDomainCapacity = jObj["PerDomainCapacity"].Value() - }; - - var cookieList = jObj["Cookies"].ToList(); - - foreach (var cookie in cookieList) - { - result.Add( - new Cookie - { - Comment = cookie["Comment"].Value(), - HttpOnly = cookie["HttpOnly"].Value(), - Discard = cookie["Discard"].Value(), - Domain = cookie["Domain"].Value(), - Expired = cookie["Expired"].Value(), - Expires = cookie["Expires"].Value(), - Name = cookie["Name"].Value(), - Path = cookie["Path"].Value(), - Port = cookie["Port"].Value(), - Secure = cookie["Secure"].Value(), - Value = cookie["Value"].Value(), - Version = cookie["Version"].Value(), - }); - } - - return result; - } - - public override bool CanWrite => true; - - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - var cookies = value as SingleUriCookieContainer; - var obj = (JObject)JToken.FromObject(value); - var container = cookies.GetCookies(); - var propertyNames = container.Select(c => JToken.FromObject(c)); - obj.AddFirst(new JProperty("Cookies", new JArray(propertyNames))); - obj.WriteTo(writer); - } - } - - internal class WebHeaderCollectionConverter : JsonConverter - { - public override bool CanConvert(Type objectType) - => objectType == typeof(WebHeaderCollection); - - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - var jObj = JObject.Load(reader); - var result = new WebHeaderCollection(); - - foreach (var kvp in jObj) - result.Add(kvp.Key, kvp.Value.Value()); - - return result; - } - - public override bool CanWrite => true; - - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - var jObj = new JObject(); - var type = value.GetType(); - var headers = value as WebHeaderCollection; - var jHeaders = headers.AllKeys.Select(k => new JProperty(k, headers[k])); - jObj.Add(jHeaders); - jObj.WriteTo(writer); - } - } - - #endregion - - #region Download Stream Reader - - [JsonIgnore] - public override bool CanRead => true; - - [JsonIgnore] - public override bool CanSeek => true; - - [JsonIgnore] - public override bool CanWrite => false; - - [JsonIgnore] - public override long Length - { - get - { - if (!hasBegunDownloading) - BeginDownloading(); - return ContentLength; - } - } - - [JsonIgnore] - public override long Position { get => _readFile.Position; set => Seek(value, SeekOrigin.Begin); } - - [JsonIgnore] - public override bool CanTimeout => false; - - [JsonIgnore] - public override int ReadTimeout { get => base.ReadTimeout; set => base.ReadTimeout = value; } - - [JsonIgnore] - public override int WriteTimeout { get => base.WriteTimeout; set => base.WriteTimeout = value; } - - public override void Flush() => throw new NotImplementedException(); - public override void SetLength(long value) => throw new NotImplementedException(); - public override void Write(byte[] buffer, int offset, int count) => throw new NotImplementedException(); - - public override int Read(byte[] buffer, int offset, int count) - { - if (!hasBegunDownloading) - BeginDownloading(); - - var toRead = Math.Min(count, Length - Position); - WaitToPosition(Position + toRead); - return _readFile.Read(buffer, offset, count); - } - - public override long Seek(long offset, SeekOrigin origin) - { - var newPosition = origin switch + /// + /// A for a single Uri. + /// + public class SingleUriCookieContainer : CookieContainer + { + private Uri baseAddress; + public Uri Uri + { + get => baseAddress; + set + { + baseAddress = new UriBuilder(value.Scheme, value.Host).Uri; + } + } + + public CookieCollection GetCookies() + { + return GetCookies(Uri); + } + } + + /// + /// A resumable, simultaneous file downloader and reader. + /// + public class NetworkFileStream : Stream, IUpdatable + { + public event EventHandler Updated; + + #region Public Properties + + /// + /// Location to save the downloaded data. + /// + [JsonProperty(Required = Required.Always)] + public string SaveFilePath { get; } + + /// + /// Http(s) address of the file to download. + /// + [JsonProperty(Required = Required.Always)] + public Uri Uri { get; private set; } + + /// + /// All cookies set by caller or by the remote server. + /// + [JsonProperty(Required = Required.Always)] + public SingleUriCookieContainer CookieContainer { get; } + + /// + /// Http headers to be sent to the server with the request. + /// + [JsonProperty(Required = Required.Always)] + public WebHeaderCollection RequestHeaders { get; private set; } + + /// + /// The position in that has been written and flushed to disk. + /// + [JsonProperty(Required = Required.Always)] + public long WritePosition { get; private set; } + + /// + /// The total length of the file to download. + /// + [JsonProperty(Required = Required.Always)] + public long ContentLength { get; private set; } + + #endregion + + #region Private Properties + private HttpWebRequest HttpRequest { get; set; } + private FileStream _writeFile { get; } + private FileStream _readFile { get; } + private Stream _networkStream { get; set; } + private bool hasBegunDownloading { get; set; } + public bool IsCancelled { get; private set; } + private EventWaitHandle downloadEnded { get; set; } + private EventWaitHandle downloadedPiece { get; set; } + + #endregion + + #region Constants + + //Download buffer size + private const int DOWNLOAD_BUFF_SZ = 32 * 1024; + + //NetworkFileStream will flush all data in _writeFile to disk after every + //DATA_FLUSH_SZ bytes are written to the file stream. + private const int DATA_FLUSH_SZ = 1024 * 1024; + + #endregion + + #region Constructor + + /// + /// A resumable, simultaneous file downloader and reader. + /// + /// Path to a location on disk to save the downloaded data from + /// Http(s) address of the file to download. + /// The position in to begin downloading. + /// Http headers to be sent to the server with the . + /// A with cookies to send with the . It will also be populated with any cookies set by the server. + public NetworkFileStream(string saveFilePath, Uri uri, long writePosition = 0, WebHeaderCollection requestHeaders = null, SingleUriCookieContainer cookies = null) + { + ArgumentValidator.EnsureNotNullOrWhiteSpace(saveFilePath, nameof(saveFilePath)); + ArgumentValidator.EnsureNotNullOrWhiteSpace(uri?.AbsoluteUri, nameof(uri)); + ArgumentValidator.EnsureGreaterThan(writePosition, nameof(writePosition), -1); + + if (!Directory.Exists(Path.GetDirectoryName(saveFilePath))) + throw new ArgumentException($"Specified {nameof(saveFilePath)} directory \"{Path.GetDirectoryName(saveFilePath)}\" does not exist."); + + SaveFilePath = saveFilePath; + Uri = uri; + WritePosition = writePosition; + RequestHeaders = requestHeaders ?? new WebHeaderCollection(); + CookieContainer = cookies ?? new SingleUriCookieContainer { Uri = uri }; + + _writeFile = new FileStream(SaveFilePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite) + { + Position = WritePosition + }; + + _readFile = new FileStream(SaveFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + + SetUriForSameFile(uri); + } + + #endregion + + #region Downloader + + /// + /// Update the . + /// + private void Update() + { + RequestHeaders = HttpRequest.Headers; + Updated?.Invoke(this, EventArgs.Empty); + } + + /// + /// Set a different to the same file targeted by this instance of + /// + /// New host must match existing host. + public void SetUriForSameFile(Uri uriToSameFile) + { + ArgumentValidator.EnsureNotNullOrWhiteSpace(uriToSameFile?.AbsoluteUri, nameof(uriToSameFile)); + + if (uriToSameFile.Host != Uri.Host) + throw new ArgumentException($"New uri to the same file must have the same host.\r\n Old Host :{Uri.Host}\r\nNew Host: {uriToSameFile.Host}"); + if (hasBegunDownloading) + throw new InvalidOperationException("Cannot change Uri after download has started."); + + Uri = uriToSameFile; + HttpRequest = WebRequest.CreateHttp(Uri); + + HttpRequest.CookieContainer = CookieContainer; + HttpRequest.Headers = RequestHeaders; + //If NetworkFileStream is resuming, Header will already contain a range. + HttpRequest.Headers.Remove("Range"); + HttpRequest.AddRange(WritePosition); + } + + /// + /// Begins downloading to in a background thread. + /// + private void BeginDownloading() + { + downloadEnded = new EventWaitHandle(false, EventResetMode.ManualReset); + + if (ContentLength != 0 && WritePosition == ContentLength) + { + hasBegunDownloading = true; + downloadEnded.Set(); + return; + } + + if (ContentLength != 0 && WritePosition > ContentLength) + throw new WebException($"Specified write position (0x{WritePosition:X10}) is larger than {nameof(ContentLength)} (0x{ContentLength:X10})."); + + var response = HttpRequest.GetResponse() as HttpWebResponse; + + if (response.StatusCode != HttpStatusCode.PartialContent) + throw new WebException($"Server at {Uri.Host} responded with unexpected status code: {response.StatusCode}."); + + //Content length is the length of the range request, and it is only equal + //to the complete file length if requesting Range: bytes=0- + if (WritePosition == 0) + ContentLength = response.ContentLength; + + _networkStream = response.GetResponseStream(); + downloadedPiece = new EventWaitHandle(false, EventResetMode.AutoReset); + + //Download the file in the background. + new Thread(() => DownloadFile()) + { IsBackground = true } + .Start(); + + hasBegunDownloading = true; + return; + } + + /// + /// Downlod to . + /// + private void DownloadFile() + { + var downloadPosition = WritePosition; + var nextFlush = downloadPosition + DATA_FLUSH_SZ; + + var buff = new byte[DOWNLOAD_BUFF_SZ]; + do + { + var bytesRead = _networkStream.Read(buff, 0, DOWNLOAD_BUFF_SZ); + _writeFile.Write(buff, 0, bytesRead); + + downloadPosition += bytesRead; + + if (downloadPosition > nextFlush) + { + _writeFile.Flush(); + WritePosition = downloadPosition; + Update(); + nextFlush = downloadPosition + DATA_FLUSH_SZ; + downloadedPiece.Set(); + } + + } while (downloadPosition < ContentLength && !IsCancelled); + + _writeFile.Close(); + _networkStream.Close(); + WritePosition = downloadPosition; + Update(); + + downloadedPiece.Set(); + downloadEnded.Set(); + + if (!IsCancelled && WritePosition < ContentLength) + throw new WebException($"Downloaded size (0x{WritePosition:X10}) is less than {nameof(ContentLength)} (0x{ContentLength:X10})."); + + if (WritePosition > ContentLength) + throw new WebException($"Downloaded size (0x{WritePosition:X10}) is greater than {nameof(ContentLength)} (0x{ContentLength:X10})."); + + } + + #endregion + + #region Json Connverters + + public static JsonSerializerSettings GetJsonSerializerSettings() + { + var settings = new JsonSerializerSettings(); + settings.Converters.Add(new CookieContainerConverter()); + settings.Converters.Add(new WebHeaderCollectionConverter()); + return settings; + } + + internal class CookieContainerConverter : JsonConverter + { + public override bool CanConvert(Type objectType) + => objectType == typeof(SingleUriCookieContainer); + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + var jObj = JObject.Load(reader); + + var result = new SingleUriCookieContainer() + { + Uri = new Uri(jObj["Uri"].Value()), + Capacity = jObj["Capacity"].Value(), + MaxCookieSize = jObj["MaxCookieSize"].Value(), + PerDomainCapacity = jObj["PerDomainCapacity"].Value() + }; + + var cookieList = jObj["Cookies"].ToList(); + + foreach (var cookie in cookieList) + { + result.Add( + new Cookie + { + Comment = cookie["Comment"].Value(), + HttpOnly = cookie["HttpOnly"].Value(), + Discard = cookie["Discard"].Value(), + Domain = cookie["Domain"].Value(), + Expired = cookie["Expired"].Value(), + Expires = cookie["Expires"].Value(), + Name = cookie["Name"].Value(), + Path = cookie["Path"].Value(), + Port = cookie["Port"].Value(), + Secure = cookie["Secure"].Value(), + Value = cookie["Value"].Value(), + Version = cookie["Version"].Value(), + }); + } + + return result; + } + + public override bool CanWrite => true; + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + var cookies = value as SingleUriCookieContainer; + var obj = (JObject)JToken.FromObject(value); + var container = cookies.GetCookies(); + var propertyNames = container.Select(c => JToken.FromObject(c)); + obj.AddFirst(new JProperty("Cookies", new JArray(propertyNames))); + obj.WriteTo(writer); + } + } + + internal class WebHeaderCollectionConverter : JsonConverter + { + public override bool CanConvert(Type objectType) + => objectType == typeof(WebHeaderCollection); + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + var jObj = JObject.Load(reader); + var result = new WebHeaderCollection(); + + foreach (var kvp in jObj) + result.Add(kvp.Key, kvp.Value.Value()); + + return result; + } + + public override bool CanWrite => true; + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + var jObj = new JObject(); + var type = value.GetType(); + var headers = value as WebHeaderCollection; + var jHeaders = headers.AllKeys.Select(k => new JProperty(k, headers[k])); + jObj.Add(jHeaders); + jObj.WriteTo(writer); + } + } + + #endregion + + #region Download Stream Reader + + [JsonIgnore] + public override bool CanRead => true; + + [JsonIgnore] + public override bool CanSeek => true; + + [JsonIgnore] + public override bool CanWrite => false; + + [JsonIgnore] + public override long Length + { + get + { + if (!hasBegunDownloading) + BeginDownloading(); + return ContentLength; + } + } + + [JsonIgnore] + public override long Position { get => _readFile.Position; set => Seek(value, SeekOrigin.Begin); } + + [JsonIgnore] + public override bool CanTimeout => false; + + [JsonIgnore] + public override int ReadTimeout { get => base.ReadTimeout; set => base.ReadTimeout = value; } + + [JsonIgnore] + public override int WriteTimeout { get => base.WriteTimeout; set => base.WriteTimeout = value; } + + public override void Flush() => throw new NotImplementedException(); + public override void SetLength(long value) => throw new NotImplementedException(); + public override void Write(byte[] buffer, int offset, int count) => throw new NotImplementedException(); + + public override int Read(byte[] buffer, int offset, int count) + { + if (!hasBegunDownloading) + BeginDownloading(); + + var toRead = Math.Min(count, Length - Position); + WaitToPosition(Position + toRead); + return _readFile.Read(buffer, offset, count); + } + + public override long Seek(long offset, SeekOrigin origin) + { + var newPosition = origin switch { SeekOrigin.Current => Position + offset, SeekOrigin.End => ContentLength + offset, _ => offset, }; - WaitToPosition(newPosition); - return _readFile.Position = newPosition; - } + WaitToPosition(newPosition); + return _readFile.Position = newPosition; + } - /// - /// Blocks until the file has downloaded to at least , then returns. - /// - /// The minimum required flished data length in . - private void WaitToPosition(long requiredPosition) + /// + /// Blocks until the file has downloaded to at least , then returns. + /// + /// The minimum required flished data length in . + private void WaitToPosition(long requiredPosition) { - while (requiredPosition > WritePosition && !IsCancelled && hasBegunDownloading && !downloadedPiece.WaitOne(1000)) ; - } + while (requiredPosition > WritePosition && !IsCancelled && hasBegunDownloading && !downloadedPiece.WaitOne(1000)) ; + } - public override void Close() - { - IsCancelled = true; + public override void Close() + { + IsCancelled = true; - while (downloadEnded is not null && !downloadEnded.WaitOne(1000)) ; + while (downloadEnded is not null && !downloadEnded.WaitOne(1000)) ; - _readFile.Close(); - _writeFile.Close(); - _networkStream?.Close(); - Update(); - } + _readFile.Close(); + _writeFile.Close(); + _networkStream?.Close(); + Update(); + } - #endregion - ~NetworkFileStream() - { - downloadEnded?.Close(); - downloadedPiece?.Close(); - } - } + #endregion + ~NetworkFileStream() + { + downloadEnded?.Close(); + downloadedPiece?.Close(); + } + } } diff --git a/Source/FileLiberator/ConvertToMp3.cs b/Source/FileLiberator/ConvertToMp3.cs index 35f3411e..09eb1b1e 100644 --- a/Source/FileLiberator/ConvertToMp3.cs +++ b/Source/FileLiberator/ConvertToMp3.cs @@ -17,17 +17,24 @@ namespace FileLiberator public override string Name => "Convert to Mp3"; private Mp4File m4bBook; - private long fileSize; + private long fileSize; private static string Mp3FileName(string m4bPath) => Path.ChangeExtension(m4bPath ?? "", ".mp3"); - public override void Cancel() => m4bBook?.Cancel(); + private bool cancelled = false; + public override void Cancel() + { + m4bBook?.Cancel(); + cancelled = true; + } - public override bool Validate(LibraryBook libraryBook) - { + public static bool ValidateMp3(LibraryBook libraryBook) + { var path = AudibleFileStorage.Audio.GetPath(libraryBook.Book.AudibleProductId); return path?.ToLower()?.EndsWith(".m4b") == true && !File.Exists(Mp3FileName(path)); } + public override bool Validate(LibraryBook libraryBook) => ValidateMp3(libraryBook); + public override async Task ProcessAsync(LibraryBook libraryBook) { OnBegin(libraryBook); @@ -57,12 +64,12 @@ namespace FileLiberator var realMp3Path = FileUtility.SaferMoveToValidPath(mp3File.Name, proposedMp3Path); OnFileCreated(libraryBook, realMp3Path); - var statusHandler = new StatusHandler(); - if (result == ConversionResult.Failed) - statusHandler.AddError("Conversion failed"); - - return statusHandler; + return new StatusHandler { "Conversion failed" }; + else if (result == ConversionResult.Cancelled) + return new StatusHandler { "Cancelled" }; + else + return new StatusHandler(); } finally { diff --git a/Source/LibationWinForms/Form1.Designer.cs b/Source/LibationWinForms/Form1.Designer.cs index b54990b3..66f1cb4e 100644 --- a/Source/LibationWinForms/Form1.Designer.cs +++ b/Source/LibationWinForms/Form1.Designer.cs @@ -72,24 +72,25 @@ this.pdfsCountsLbl = new System.Windows.Forms.ToolStripStatusLabel(); this.addQuickFilterBtn = new System.Windows.Forms.Button(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); - this.processBookQueue1 = new LibationWinForms.ProcessQueue.ProcessBookQueue(); + this.hideQueueBtn = new System.Windows.Forms.Button(); + this.panel1 = new System.Windows.Forms.Panel(); + this.processBookQueue1 = new LibationWinForms.ProcessQueue.ProcessQueueControl(); this.menuStrip1.SuspendLayout(); this.statusStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.SuspendLayout(); + this.panel1.SuspendLayout(); this.SuspendLayout(); // // gridPanel // - this.gridPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.gridPanel.Location = new System.Drawing.Point(15, 60); + this.gridPanel.Dock = System.Windows.Forms.DockStyle.Fill; + this.gridPanel.Location = new System.Drawing.Point(0, 0); this.gridPanel.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.gridPanel.Name = "gridPanel"; - this.gridPanel.Size = new System.Drawing.Size(865, 556); + this.gridPanel.Size = new System.Drawing.Size(864, 560); this.gridPanel.TabIndex = 5; // // filterHelpBtn @@ -106,8 +107,8 @@ // filterBtn // this.filterBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.filterBtn.Location = new System.Drawing.Point(792, 27); - this.filterBtn.Margin = new System.Windows.Forms.Padding(4, 3, 15, 3); + this.filterBtn.Location = new System.Drawing.Point(750, 27); + this.filterBtn.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.filterBtn.Name = "filterBtn"; this.filterBtn.Size = new System.Drawing.Size(88, 27); this.filterBtn.TabIndex = 2; @@ -119,10 +120,10 @@ // this.filterSearchTb.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.filterSearchTb.Location = new System.Drawing.Point(220, 30); + this.filterSearchTb.Location = new System.Drawing.Point(194, 30); this.filterSearchTb.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.filterSearchTb.Name = "filterSearchTb"; - this.filterSearchTb.Size = new System.Drawing.Size(564, 23); + this.filterSearchTb.Size = new System.Drawing.Size(548, 23); this.filterSearchTb.TabIndex = 1; this.filterSearchTb.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.filterSearchTb_KeyPress); // @@ -140,7 +141,7 @@ this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Padding = new System.Windows.Forms.Padding(7, 2, 0, 2); - this.menuStrip1.Size = new System.Drawing.Size(895, 24); + this.menuStrip1.Size = new System.Drawing.Size(894, 24); this.menuStrip1.TabIndex = 0; this.menuStrip1.Text = "menuStrip1"; // @@ -396,7 +397,7 @@ this.statusStrip1.Location = new System.Drawing.Point(0, 619); this.statusStrip1.Name = "statusStrip1"; this.statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 16, 0); - this.statusStrip1.Size = new System.Drawing.Size(895, 22); + this.statusStrip1.Size = new System.Drawing.Size(894, 22); this.statusStrip1.TabIndex = 6; this.statusStrip1.Text = "statusStrip1"; // @@ -409,7 +410,7 @@ // springLbl // this.springLbl.Name = "springLbl"; - this.springLbl.Size = new System.Drawing.Size(436, 17); + this.springLbl.Size = new System.Drawing.Size(435, 17); this.springLbl.Spring = true; // // backupsCountsLbl @@ -429,7 +430,7 @@ this.addQuickFilterBtn.Location = new System.Drawing.Point(49, 27); this.addQuickFilterBtn.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.addQuickFilterBtn.Name = "addQuickFilterBtn"; - this.addQuickFilterBtn.Size = new System.Drawing.Size(163, 27); + this.addQuickFilterBtn.Size = new System.Drawing.Size(137, 27); this.addQuickFilterBtn.TabIndex = 4; this.addQuickFilterBtn.Text = "Add To Quick Filters"; this.addQuickFilterBtn.UseVisualStyleBackColor = true; @@ -443,8 +444,9 @@ // // splitContainer1.Panel1 // + this.splitContainer1.Panel1.Controls.Add(this.hideQueueBtn); + this.splitContainer1.Panel1.Controls.Add(this.panel1); this.splitContainer1.Panel1.Controls.Add(this.menuStrip1); - this.splitContainer1.Panel1.Controls.Add(this.gridPanel); this.splitContainer1.Panel1.Controls.Add(this.filterSearchTb); this.splitContainer1.Panel1.Controls.Add(this.addQuickFilterBtn); this.splitContainer1.Panel1.Controls.Add(this.filterBtn); @@ -455,17 +457,42 @@ // this.splitContainer1.Panel2.Controls.Add(this.processBookQueue1); this.splitContainer1.Size = new System.Drawing.Size(1231, 641); - this.splitContainer1.SplitterDistance = 895; + this.splitContainer1.SplitterDistance = 894; this.splitContainer1.SplitterWidth = 8; this.splitContainer1.TabIndex = 7; // + // hideQueueBtn + // + this.hideQueueBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.hideQueueBtn.Location = new System.Drawing.Point(846, 27); + this.hideQueueBtn.Margin = new System.Windows.Forms.Padding(4, 3, 15, 3); + this.hideQueueBtn.Name = "hideQueueBtn"; + this.hideQueueBtn.Size = new System.Drawing.Size(33, 27); + this.hideQueueBtn.TabIndex = 8; + this.hideQueueBtn.Text = "❰❰❰"; + this.hideQueueBtn.UseVisualStyleBackColor = true; + this.hideQueueBtn.Click += new System.EventHandler(this.HideQueueBtn_Click); + // + // panel1 + // + this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.panel1.Controls.Add(this.gridPanel); + this.panel1.Location = new System.Drawing.Point(15, 59); + this.panel1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(864, 560); + this.panel1.TabIndex = 7; + // // processBookQueue1 // this.processBookQueue1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.processBookQueue1.Dock = System.Windows.Forms.DockStyle.Fill; this.processBookQueue1.Location = new System.Drawing.Point(0, 0); + this.processBookQueue1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.processBookQueue1.Name = "processBookQueue1"; - this.processBookQueue1.Size = new System.Drawing.Size(328, 641); + this.processBookQueue1.Size = new System.Drawing.Size(329, 641); this.processBookQueue1.TabIndex = 0; // // Form1 @@ -489,6 +516,7 @@ this.splitContainer1.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); this.splitContainer1.ResumeLayout(false); + this.panel1.ResumeLayout(false); this.ResumeLayout(false); } @@ -538,6 +566,8 @@ private System.Windows.Forms.ToolStripMenuItem removeToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem liberateVisible2ToolStripMenuItem; private System.Windows.Forms.SplitContainer splitContainer1; - private LibationWinForms.ProcessQueue.ProcessBookQueue processBookQueue1; + private LibationWinForms.ProcessQueue.ProcessQueueControl processBookQueue1; + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.Button hideQueueBtn; } } diff --git a/Source/LibationWinForms/Form1.Liberate.cs b/Source/LibationWinForms/Form1.Liberate.cs index 43f91546..d1369d7a 100644 --- a/Source/LibationWinForms/Form1.Liberate.cs +++ b/Source/LibationWinForms/Form1.Liberate.cs @@ -1,4 +1,6 @@ using System; +using System.Linq; +using System.Threading.Tasks; using System.Windows.Forms; namespace LibationWinForms @@ -7,11 +9,14 @@ namespace LibationWinForms { private void Configure_Liberate() { } + //GetLibrary_Flat_NoTracking() may take a long time on a hugh library. so run in new thread private async void beginBookBackupsToolStripMenuItem_Click(object sender, EventArgs e) - => await BookLiberation.ProcessorAutomationController.BackupAllBooksAsync(); + => await Task.Run(() => processBookQueue1.AddDownloadDecrypt(ApplicationServices.DbContexts.GetLibrary_Flat_NoTracking() + .Where(lb => lb.Book.UserDefinedItem.PdfStatus is DataLayer.LiberatedStatus.NotLiberated || lb.Book.UserDefinedItem.BookStatus is DataLayer.LiberatedStatus.NotLiberated))); private async void beginPdfBackupsToolStripMenuItem_Click(object sender, EventArgs e) - => await BookLiberation.ProcessorAutomationController.BackupAllPdfsAsync(); + => await Task.Run(() => processBookQueue1.AddDownloadPdf(ApplicationServices.DbContexts.GetLibrary_Flat_NoTracking() + .Where(lb => lb.Book.UserDefinedItem.PdfStatus is DataLayer.LiberatedStatus.NotLiberated))); private async void convertAllM4bToMp3ToolStripMenuItem_Click(object sender, EventArgs e) { @@ -24,7 +29,9 @@ namespace LibationWinForms MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) - await BookLiberation.ProcessorAutomationController.ConvertAllBooksAsync(); + await Task.Run(() => processBookQueue1.AddConvertMp3(ApplicationServices.DbContexts.GetLibrary_Flat_NoTracking() + .Where(lb=>lb.Book.UserDefinedItem.BookStatus is DataLayer.LiberatedStatus.Liberated))); + //Only Queue Liberated books for conversion. This isn't a perfect filter, but it's better than nothing. } } } diff --git a/Source/LibationWinForms/Form1.ProcessQueue.cs b/Source/LibationWinForms/Form1.ProcessQueue.cs index 2cdd7e72..acf4ac66 100644 --- a/Source/LibationWinForms/Form1.ProcessQueue.cs +++ b/Source/LibationWinForms/Form1.ProcessQueue.cs @@ -1,19 +1,41 @@ -using System; -using System.Collections.Generic; +using ApplicationServices; +using LibationFileManager; +using LibationWinForms.ProcessQueue; +using System; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; -using LibationFileManager; -using LibationWinForms.ProcessQueue; namespace LibationWinForms { - public partial class Form1 - { - private void Configure_ProcessQueue() - { - //splitContainer1.Panel2Collapsed = true; - processBookQueue1.popoutBtn.Click += ProcessBookQueue1_PopOut; + public partial class Form1 + { + private void Configure_ProcessQueue() + { + productsGrid.LiberateClicked += (_, lb) => processBookQueue1.AddDownloadDecrypt(lb); + processBookQueue1.popoutBtn.Click += ProcessBookQueue1_PopOut; + } + + int WidthChange = 0; + private void HideQueueBtn_Click(object sender, EventArgs e) + { + if (splitContainer1.Panel2Collapsed) + { + WidthChange = WidthChange == 0 ? splitContainer1.Panel2.Width + splitContainer1.SplitterWidth : WidthChange; + Width += WidthChange; + splitContainer1.Panel2.Controls.Add(processBookQueue1); + splitContainer1.Panel2Collapsed = false; + processBookQueue1.popoutBtn.Visible = true; + hideQueueBtn.Text = "❰❰❰"; + } + else + { + WidthChange = splitContainer1.Panel2.Width + splitContainer1.SplitterWidth; + splitContainer1.Panel2.Controls.Remove(processBookQueue1); + splitContainer1.Panel2Collapsed = true; + Width -= WidthChange; + hideQueueBtn.Text = "❱❱❱"; + } } private void ProcessBookQueue1_PopOut(object sender, EventArgs e) @@ -28,6 +50,10 @@ namespace LibationWinForms dockForm.PassControl(processBookQueue1); dockForm.Show(); this.Width -= dockForm.WidthChange; + hideQueueBtn.Visible = false; + int deltax = filterBtn.Margin.Right + hideQueueBtn.Width + hideQueueBtn.Margin.Left; + filterBtn.Location= new System.Drawing.Point(filterBtn.Location.X + deltax, filterBtn.Location.Y); + filterSearchTb.Location = new System.Drawing.Point(filterSearchTb.Location.X + deltax, filterSearchTb.Location.Y); } private void DockForm_FormClosing(object sender, FormClosingEventArgs e) @@ -40,6 +66,10 @@ namespace LibationWinForms processBookQueue1.popoutBtn.Visible = true; dockForm.SaveSizeAndLocation(Configuration.Instance); this.Focus(); + hideQueueBtn.Visible = true; + int deltax = filterBtn.Margin.Right + hideQueueBtn.Width + hideQueueBtn.Margin.Left; + filterBtn.Location = new System.Drawing.Point(filterBtn.Location.X - deltax, filterBtn.Location.Y); + filterSearchTb.Location = new System.Drawing.Point(filterSearchTb.Location.X - deltax, filterSearchTb.Location.Y); } } } diff --git a/Source/LibationWinForms/ProcessQueue/ProcessBook.cs b/Source/LibationWinForms/ProcessQueue/ProcessBook.cs index df142e56..75cb21e9 100644 --- a/Source/LibationWinForms/ProcessQueue/ProcessBook.cs +++ b/Source/LibationWinForms/ProcessQueue/ProcessBook.cs @@ -5,7 +5,10 @@ using LibationFileManager; using LibationWinForms.BookLiberation; using System; using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; using System.Linq; +using System.Runtime.CompilerServices; using System.Threading.Tasks; using System.Windows.Forms; @@ -16,153 +19,283 @@ namespace LibationWinForms.ProcessQueue None, Success, Cancelled, + ValidationFail, FailedRetry, FailedSkip, FailedAbort } - internal enum QueuePosition + public enum ProcessBookStatus { - Absent, - Current, - Fisrt, - OneUp, - OneDown, - Last + Queued, + Cancelled, + Working, + Completed, + Failed } - internal delegate QueuePosition ProcessControlReorderHandler(ProcessBook sender, QueuePosition arg); - internal delegate void ProcessControlEventArgs(ProcessBook sender, T arg); - internal delegate void ProcessControlEventArgs(ProcessBook sender, EventArgs arg); - - internal class ProcessBook + /// + /// This is the viewmodel for queued processables + /// + public class ProcessBook : INotifyPropertyChanged { public event EventHandler Completed; - public event ProcessControlEventArgs Cancelled; - public event ProcessControlReorderHandler RequestMove; - public GridEntry Entry { get; } - public ILiberationBaseForm BookControl { get; } + public event PropertyChangedEventHandler PropertyChanged; - private Func _makeFirstProc; - private Processable _firstProcessable; - private bool cancelled = false; - private bool running = false; - public Processable FirstProcessable => _firstProcessable ??= _makeFirstProc?.Invoke(); + private ProcessBookResult _result = ProcessBookResult.None; + private ProcessBookStatus _status = ProcessBookStatus.Queued; + private string _bookText; + private int _progress; + private TimeSpan _timeRemaining; + private Image _cover; + + public ProcessBookResult Result { get => _result; private set { _result = value; NotifyPropertyChanged(); } } + public ProcessBookStatus Status { get => _status; private set { _status = value; NotifyPropertyChanged(); } } + public string BookText { get => _bookText; private set { _bookText = value; NotifyPropertyChanged(); } } + public int Progress { get => _progress; private set { _progress = value; NotifyPropertyChanged(); } } + public TimeSpan TimeRemaining { get => _timeRemaining; private set { _timeRemaining = value; NotifyPropertyChanged(); } } + public Image Cover { get => _cover; private set { _cover = value; NotifyPropertyChanged(); } } + + public LibraryBook LibraryBook { get; private set; } + private Processable CurrentProcessable => _currentProcessable ??= Processes.Dequeue().Invoke(); + private Processable NextProcessable() => _currentProcessable = null; + private Processable _currentProcessable; + private Func GetCoverArtDelegate; private readonly Queue> Processes = new(); + private readonly LogMe Logger; - LogMe Logger; + public void NotifyPropertyChanged([CallerMemberName] string propertyName = "") + => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - public ProcessBook(GridEntry entry, LogMe logme) + public ProcessBook(LibraryBook libraryBook, LogMe logme) { - Entry = entry; - BookControl = new ProcessBookControl(Entry.Title, Entry.Cover); - BookControl.CancelAction = Cancel; - BookControl.MoveUpAction = MoveUp; - BookControl.MoveDownAction = MoveDown; + LibraryBook = libraryBook; Logger = logme; + + title = LibraryBook.Book.Title; + authorNames = LibraryBook.Book.AuthorNames(); + narratorNames = LibraryBook.Book.NarratorNames(); + _bookText = $"{title}\r\nBy {authorNames}\r\nNarrated by {narratorNames}"; + + (bool isDefault, byte[] picture) = PictureStorage.GetPicture(new PictureDefinition(LibraryBook.Book.PictureId, PictureSize._80x80)); + + if (isDefault) + PictureStorage.PictureCached += PictureStorage_PictureCached; + _cover = Dinah.Core.Drawing.ImageReader.ToImage(picture); + } - public QueuePosition? MoveUp() + private void PictureStorage_PictureCached(object sender, PictureCachedEventArgs e) { - return RequestMove?.Invoke(this, QueuePosition.OneUp); - } - public QueuePosition? MoveDown() - { - return RequestMove?.Invoke(this, QueuePosition.OneDown); - } - - public void Cancel() - { - cancelled = true; - try + if (e.Definition.PictureId == LibraryBook.Book.PictureId) { - if (FirstProcessable is AudioDecodable audioDecodable) - audioDecodable.Cancel(); + Cover = Dinah.Core.Drawing.ImageReader.ToImage(e.Picture); + PictureStorage.PictureCached -= PictureStorage_PictureCached; } - catch(Exception ex) - { - Logger.Error(ex, "Error while cancelling"); - } - - if (!running) - Cancelled?.Invoke(this, EventArgs.Empty); } public async Task ProcessOneAsync() { - running = true; - ProcessBookResult result = ProcessBookResult.None; + string procName = CurrentProcessable.Name; try { - var firstProc = FirstProcessable; - - LinkProcessable(firstProc); - - var statusHandler = await firstProc.ProcessSingleAsync(Entry.LibraryBook, validate: true); + LinkProcessable(CurrentProcessable); + var statusHandler = await CurrentProcessable.ProcessSingleAsync(LibraryBook, validate: true); if (statusHandler.IsSuccess) - return result = ProcessBookResult.Success; - else if (cancelled) + return Result = ProcessBookResult.Success; + else if (statusHandler.Errors.Contains("Cancelled")) { - Logger.Info($"Process was cancelled {Entry.LibraryBook.Book}"); - return result = ProcessBookResult.Cancelled; + Logger.Info($"{procName}: Process was cancelled {LibraryBook.Book}"); + return Result = ProcessBookResult.Cancelled; + } + else if (statusHandler.Errors.Contains("Validation failed")) + { + Logger.Info($"{procName}: Validation failed {LibraryBook.Book}"); + return Result = ProcessBookResult.ValidationFail; } foreach (var errorMessage in statusHandler.Errors) - Logger.Error(errorMessage); + Logger.Error($"{procName}: {errorMessage}"); } catch (Exception ex) { - Logger.Error(ex); + Logger.Error(ex, procName); } finally { - if (result == ProcessBookResult.None) - result = showRetry(Entry.LibraryBook); + if (Result == ProcessBookResult.None) + Result = showRetry(LibraryBook); - BookControl.SetResult(result); + Status = Result switch + { + ProcessBookResult.Success => ProcessBookStatus.Completed, + ProcessBookResult.Cancelled => ProcessBookStatus.Cancelled, + ProcessBookResult.FailedRetry => ProcessBookStatus.Queued, + _ => ProcessBookStatus.Failed, + }; } - return result; + return Result; } - public void AddPdfProcessable() => AddProcessable(); - public void AddDownloadDecryptProcessable() => AddProcessable(); - public void AddConvertMp3Processable() => AddProcessable(); + public async Task Cancel() + { + try + { + if (CurrentProcessable is AudioDecodable audioDecodable) + { + //There's some threadding bug that causes this to hang if executed synchronously. + await Task.Run(audioDecodable.Cancel); + } + } + catch (Exception ex) + { + Logger.Error(ex, $"{CurrentProcessable.Name}: Error while cancelling"); + } + } + + public void AddDownloadPdf() => AddProcessable(); + public void AddDownloadDecryptBook() => AddProcessable(); + public void AddConvertToMp3() => AddProcessable(); private void AddProcessable() where T : Processable, new() { - if (FirstProcessable == null) - { - _makeFirstProc = () => new T(); - } - else - Processes.Enqueue(() => new T()); + Processes.Enqueue(() => new T()); } - private void LinkProcessable(Processable strProc) + public override string ToString() => LibraryBook.ToString(); + + #region Subscribers and Unsubscribers + + private void LinkProcessable(Processable processable) { - strProc.Begin += Processable_Begin; - strProc.Completed += Processable_Completed; + processable.Begin += Processable_Begin; + processable.Completed += Processable_Completed; + processable.StreamingProgressChanged += Streamable_StreamingProgressChanged; + processable.StreamingTimeRemaining += Streamable_StreamingTimeRemaining; + + if (processable is AudioDecodable audioDecodable) + { + audioDecodable.RequestCoverArt += AudioDecodable_RequestCoverArt; + audioDecodable.TitleDiscovered += AudioDecodable_TitleDiscovered; + audioDecodable.AuthorsDiscovered += AudioDecodable_AuthorsDiscovered; + audioDecodable.NarratorsDiscovered += AudioDecodable_NarratorsDiscovered; + audioDecodable.CoverImageDiscovered += AudioDecodable_CoverImageDiscovered; + } } + private void UnlinkProcessable(Processable processable) + { + processable.Begin -= Processable_Begin; + processable.Completed -= Processable_Completed; + processable.StreamingProgressChanged -= Streamable_StreamingProgressChanged; + processable.StreamingTimeRemaining -= Streamable_StreamingTimeRemaining; + + if (processable is AudioDecodable audioDecodable) + { + audioDecodable.RequestCoverArt -= AudioDecodable_RequestCoverArt; + audioDecodable.TitleDiscovered -= AudioDecodable_TitleDiscovered; + audioDecodable.AuthorsDiscovered -= AudioDecodable_AuthorsDiscovered; + audioDecodable.NarratorsDiscovered -= AudioDecodable_NarratorsDiscovered; + audioDecodable.CoverImageDiscovered -= AudioDecodable_CoverImageDiscovered; + } + } + + #endregion + + #region AudioDecodable event handlers + + private string title; + private string authorNames; + private string narratorNames; + private void AudioDecodable_TitleDiscovered(object sender, string title) + { + this.title = title; + updateBookInfo(); + } + + private void AudioDecodable_AuthorsDiscovered(object sender, string authors) + { + authorNames = authors; + updateBookInfo(); + } + + private void AudioDecodable_NarratorsDiscovered(object sender, string narrators) + { + narratorNames = narrators; + updateBookInfo(); + } + + private void updateBookInfo() + { + BookText = $"{title}\r\nBy {authorNames}\r\nNarrated by {narratorNames}"; + } + + public void AudioDecodable_RequestCoverArt(object sender, Action setCoverArtDelegate) + { + byte[] coverData = GetCoverArtDelegate(); + setCoverArtDelegate(coverData); + AudioDecodable_CoverImageDiscovered(this, coverData); + } + + private void AudioDecodable_CoverImageDiscovered(object sender, byte[] coverArt) + { + Cover = Dinah.Core.Drawing.ImageReader.ToImage(coverArt); + } + + #endregion + + #region Streamable event handlers + private void Streamable_StreamingTimeRemaining(object sender, TimeSpan timeRemaining) + { + TimeRemaining = timeRemaining; + } + + private void Streamable_StreamingProgressChanged(object sender, Dinah.Core.Net.Http.DownloadProgress downloadProgress) + { + if (!downloadProgress.ProgressPercentage.HasValue) + return; + + if (downloadProgress.ProgressPercentage == 0) + TimeRemaining = TimeSpan.Zero; + else + Progress = (int)downloadProgress.ProgressPercentage; + } + + #endregion + + #region Processable event handlers + private void Processable_Begin(object sender, LibraryBook libraryBook) { - BookControl.RegisterFileLiberator((Processable)sender, Logger); - BookControl.Processable_Begin(sender, libraryBook); + Status = ProcessBookStatus.Working; + + Logger.Info($"{Environment.NewLine}{((Processable)sender).Name} Step, Begin: {libraryBook.Book}"); + + GetCoverArtDelegate = () => PictureStorage.GetPictureSynchronously( + new PictureDefinition( + libraryBook.Book.PictureId, + PictureSize._500x500)); + + title = libraryBook.Book.Title; + authorNames = libraryBook.Book.AuthorNames(); + narratorNames = libraryBook.Book.NarratorNames(); + updateBookInfo(); } - private async void Processable_Completed(object sender, LibraryBook e) + private async void Processable_Completed(object sender, LibraryBook libraryBook) { - ((Processable)sender).Begin -= Processable_Begin; + + Logger.Info($"{((Processable)sender).Name} Step, Completed: {libraryBook.Book}"); + UnlinkProcessable((Processable)sender); if (Processes.Count > 0) { - var nextProcessFunc = Processes.Dequeue(); - var nextProcess = nextProcessFunc(); - LinkProcessable(nextProcess); - var result = await nextProcess.ProcessSingleAsync(e, true); + NextProcessable(); + LinkProcessable(CurrentProcessable); + var result = await CurrentProcessable.ProcessSingleAsync(libraryBook, validate: true); if (result.HasErrors) { @@ -170,16 +303,18 @@ namespace LibationWinForms.ProcessQueue Logger.Error(errorMessage); Completed?.Invoke(this, EventArgs.Empty); - running = false; } } else { Completed?.Invoke(this, EventArgs.Empty); - running = false; } } + #endregion + + #region Failure Handler + private ProcessBookResult showRetry(LibraryBook libraryBook) { Logger.Error("ERROR. All books have not been processed. Most recent book: processing failed"); @@ -232,7 +367,7 @@ $@" Title: {libraryBook.Book.Title} } - protected string SkipDialogText => @" + private string SkipDialogText => @" An error occurred while trying to process this book. {0} @@ -242,8 +377,10 @@ An error occurred while trying to process this book. - IGNORE: Permanently ignore this book. Continue processing books. (Will not try this book again later.) ".Trim(); - protected MessageBoxButtons SkipDialogButtons => MessageBoxButtons.AbortRetryIgnore; - protected MessageBoxDefaultButton SkipDialogDefaultButton => MessageBoxDefaultButton.Button1; - protected DialogResult SkipResult => DialogResult.Ignore; + private MessageBoxButtons SkipDialogButtons => MessageBoxButtons.AbortRetryIgnore; + private MessageBoxDefaultButton SkipDialogDefaultButton => MessageBoxDefaultButton.Button1; + private DialogResult SkipResult => DialogResult.Ignore; } + + #endregion } diff --git a/Source/LibationWinForms/ProcessQueue/ProcessBookControl.Designer.cs b/Source/LibationWinForms/ProcessQueue/ProcessBookControl.Designer.cs index ee395dd3..8a3db3dd 100644 --- a/Source/LibationWinForms/ProcessQueue/ProcessBookControl.Designer.cs +++ b/Source/LibationWinForms/ProcessQueue/ProcessBookControl.Designer.cs @@ -30,13 +30,16 @@ { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ProcessBookControl)); this.pictureBox1 = new System.Windows.Forms.PictureBox(); - this.bookInfoLbl = new System.Windows.Forms.Label(); this.progressBar1 = new System.Windows.Forms.ProgressBar(); this.remainingTimeLbl = new System.Windows.Forms.Label(); - this.label1 = new System.Windows.Forms.Label(); + this.etaLbl = new System.Windows.Forms.Label(); this.cancelBtn = new System.Windows.Forms.Button(); + this.statusLbl = new System.Windows.Forms.Label(); + this.bookInfoLbl = new System.Windows.Forms.Label(); this.moveUpBtn = new System.Windows.Forms.Button(); this.moveDownBtn = new System.Windows.Forms.Button(); + this.moveFirstBtn = new System.Windows.Forms.Button(); + this.moveLastBtn = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.SuspendLayout(); // @@ -49,23 +52,12 @@ this.pictureBox1.TabIndex = 0; this.pictureBox1.TabStop = false; // - // bookInfoLbl - // - this.bookInfoLbl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.bookInfoLbl.Font = new System.Drawing.Font("Segoe UI", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.bookInfoLbl.Location = new System.Drawing.Point(89, 3); - this.bookInfoLbl.Name = "bookInfoLbl"; - this.bookInfoLbl.Size = new System.Drawing.Size(255, 56); - this.bookInfoLbl.TabIndex = 1; - this.bookInfoLbl.Text = "[multi-\r\nline\r\nbook\r\n info]"; - // // progressBar1 // this.progressBar1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.progressBar1.Location = new System.Drawing.Point(88, 65); + this.progressBar1.MarqueeAnimationSpeed = 0; this.progressBar1.Name = "progressBar1"; this.progressBar1.Size = new System.Drawing.Size(212, 17); this.progressBar1.TabIndex = 2; @@ -81,17 +73,17 @@ this.remainingTimeLbl.Text = "--:--"; this.remainingTimeLbl.TextAlign = System.Drawing.ContentAlignment.TopRight; // - // label1 + // etaLbl // - this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.label1.AutoSize = true; - this.label1.Font = new System.Drawing.Font("Segoe UI", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.label1.Location = new System.Drawing.Point(304, 66); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(28, 13); - this.label1.TabIndex = 3; - this.label1.Text = "ETA:"; - this.label1.TextAlign = System.Drawing.ContentAlignment.TopRight; + this.etaLbl.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.etaLbl.AutoSize = true; + this.etaLbl.Font = new System.Drawing.Font("Segoe UI", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.etaLbl.Location = new System.Drawing.Point(304, 66); + this.etaLbl.Name = "etaLbl"; + this.etaLbl.Size = new System.Drawing.Size(28, 13); + this.etaLbl.TabIndex = 3; + this.etaLbl.Text = "ETA:"; + this.etaLbl.TextAlign = System.Drawing.ContentAlignment.TopRight; // // cancelBtn // @@ -101,45 +93,96 @@ this.cancelBtn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.cancelBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.cancelBtn.ForeColor = System.Drawing.SystemColors.Control; - this.cancelBtn.Location = new System.Drawing.Point(352, 3); + this.cancelBtn.Location = new System.Drawing.Point(348, 6); this.cancelBtn.Margin = new System.Windows.Forms.Padding(0); this.cancelBtn.Name = "cancelBtn"; this.cancelBtn.Size = new System.Drawing.Size(20, 20); this.cancelBtn.TabIndex = 4; this.cancelBtn.UseVisualStyleBackColor = false; - this.cancelBtn.Click += new System.EventHandler(this.cancelBtn_Click); + // + // statusLbl + // + this.statusLbl.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.statusLbl.AutoSize = true; + this.statusLbl.Font = new System.Drawing.Font("Segoe UI", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.statusLbl.Location = new System.Drawing.Point(89, 66); + this.statusLbl.Name = "statusLbl"; + this.statusLbl.Size = new System.Drawing.Size(50, 13); + this.statusLbl.TabIndex = 3; + this.statusLbl.Text = "[STATUS]"; + this.statusLbl.TextAlign = System.Drawing.ContentAlignment.TopRight; + // + // bookInfoLbl + // + this.bookInfoLbl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.bookInfoLbl.Font = new System.Drawing.Font("Segoe UI", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.bookInfoLbl.Location = new System.Drawing.Point(89, 6); + this.bookInfoLbl.Name = "bookInfoLbl"; + this.bookInfoLbl.Size = new System.Drawing.Size(219, 56); + this.bookInfoLbl.TabIndex = 1; + this.bookInfoLbl.Text = "[multi-\r\nline\r\nbook\r\n info]"; // // moveUpBtn // - this.moveUpBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.moveUpBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Right))); this.moveUpBtn.BackColor = System.Drawing.Color.Transparent; this.moveUpBtn.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("moveUpBtn.BackgroundImage"))); - this.moveUpBtn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.moveUpBtn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.moveUpBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.moveUpBtn.ForeColor = System.Drawing.SystemColors.Control; - this.moveUpBtn.Location = new System.Drawing.Point(347, 39); - this.moveUpBtn.Margin = new System.Windows.Forms.Padding(0); + this.moveUpBtn.Location = new System.Drawing.Point(314, 24); this.moveUpBtn.Name = "moveUpBtn"; - this.moveUpBtn.Size = new System.Drawing.Size(25, 10); - this.moveUpBtn.TabIndex = 4; + this.moveUpBtn.Size = new System.Drawing.Size(30, 17); + this.moveUpBtn.TabIndex = 5; this.moveUpBtn.UseVisualStyleBackColor = false; - this.moveUpBtn.Click += new System.EventHandler(this.moveUpBtn_Click); // // moveDownBtn // - this.moveDownBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.moveDownBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Right))); this.moveDownBtn.BackColor = System.Drawing.Color.Transparent; this.moveDownBtn.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("moveDownBtn.BackgroundImage"))); - this.moveDownBtn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.moveDownBtn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.moveDownBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.moveDownBtn.ForeColor = System.Drawing.SystemColors.Control; - this.moveDownBtn.Location = new System.Drawing.Point(347, 49); - this.moveDownBtn.Margin = new System.Windows.Forms.Padding(0); + this.moveDownBtn.Location = new System.Drawing.Point(314, 40); this.moveDownBtn.Name = "moveDownBtn"; - this.moveDownBtn.Size = new System.Drawing.Size(25, 10); + this.moveDownBtn.Size = new System.Drawing.Size(30, 17); this.moveDownBtn.TabIndex = 5; this.moveDownBtn.UseVisualStyleBackColor = false; - this.moveDownBtn.Click += new System.EventHandler(this.moveDownBtn_Click); + // + // moveFirstBtn + // + this.moveFirstBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Right))); + this.moveFirstBtn.BackColor = System.Drawing.Color.Transparent; + this.moveFirstBtn.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("moveFirstBtn.BackgroundImage"))); + this.moveFirstBtn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.moveFirstBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.moveFirstBtn.ForeColor = System.Drawing.SystemColors.Control; + this.moveFirstBtn.Location = new System.Drawing.Point(314, 3); + this.moveFirstBtn.Name = "moveFirstBtn"; + this.moveFirstBtn.Size = new System.Drawing.Size(30, 17); + this.moveFirstBtn.TabIndex = 5; + this.moveFirstBtn.UseVisualStyleBackColor = false; + // + // moveLastBtn + // + this.moveLastBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Right))); + this.moveLastBtn.BackColor = System.Drawing.Color.Transparent; + this.moveLastBtn.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("moveLastBtn.BackgroundImage"))); + this.moveLastBtn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.moveLastBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.moveLastBtn.ForeColor = System.Drawing.SystemColors.Control; + this.moveLastBtn.Location = new System.Drawing.Point(314, 63); + this.moveLastBtn.Name = "moveLastBtn"; + this.moveLastBtn.Size = new System.Drawing.Size(30, 17); + this.moveLastBtn.TabIndex = 5; + this.moveLastBtn.UseVisualStyleBackColor = false; // // ProcessBookControl // @@ -147,15 +190,18 @@ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.SystemColors.ControlLight; this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.Controls.Add(this.moveLastBtn); this.Controls.Add(this.moveDownBtn); + this.Controls.Add(this.moveFirstBtn); this.Controls.Add(this.moveUpBtn); this.Controls.Add(this.cancelBtn); - this.Controls.Add(this.label1); + this.Controls.Add(this.statusLbl); + this.Controls.Add(this.etaLbl); this.Controls.Add(this.remainingTimeLbl); this.Controls.Add(this.progressBar1); this.Controls.Add(this.bookInfoLbl); this.Controls.Add(this.pictureBox1); - this.Margin = new System.Windows.Forms.Padding(2, 1, 2, 1); + this.Margin = new System.Windows.Forms.Padding(4, 2, 4, 2); this.Name = "ProcessBookControl"; this.Size = new System.Drawing.Size(375, 86); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); @@ -167,12 +213,15 @@ #endregion private System.Windows.Forms.PictureBox pictureBox1; - private System.Windows.Forms.Label bookInfoLbl; private System.Windows.Forms.ProgressBar progressBar1; private System.Windows.Forms.Label remainingTimeLbl; - private System.Windows.Forms.Label label1; - private System.Windows.Forms.Button cancelBtn; - private System.Windows.Forms.Button moveUpBtn; - private System.Windows.Forms.Button moveDownBtn; + private System.Windows.Forms.Label etaLbl; + private System.Windows.Forms.Label statusLbl; + private System.Windows.Forms.Label bookInfoLbl; + public System.Windows.Forms.Button cancelBtn; + public System.Windows.Forms.Button moveUpBtn; + public System.Windows.Forms.Button moveDownBtn; + public System.Windows.Forms.Button moveFirstBtn; + public System.Windows.Forms.Button moveLastBtn; } } diff --git a/Source/LibationWinForms/ProcessQueue/ProcessBookControl.cs b/Source/LibationWinForms/ProcessQueue/ProcessBookControl.cs index f0875715..7eee6913 100644 --- a/Source/LibationWinForms/ProcessQueue/ProcessBookControl.cs +++ b/Source/LibationWinForms/ProcessQueue/ProcessBookControl.cs @@ -1,302 +1,175 @@ using System; using System.Drawing; using System.Windows.Forms; -using DataLayer; -using Dinah.Core.Net.Http; -using Dinah.Core.Threading; -using FileLiberator; -using LibationFileManager; -using LibationWinForms.BookLiberation; -using LibationWinForms.ProcessQueue; namespace LibationWinForms.ProcessQueue { - internal interface ILiberationBaseForm + internal partial class ProcessBookControl : UserControl { - Action CancelAction { get; set; } - Func MoveUpAction { get; set; } - Func MoveDownAction { get; set; } - void SetResult(ProcessBookResult status); - void SetQueuePosition(QueuePosition status); - void RegisterFileLiberator(Processable streamable, LogMe logMe); - void Processable_Begin(object sender, LibraryBook libraryBook); - int Width { get; set; } - int Height { get; set; } - Padding Margin { get; set; } - } + private static int ControlNumberCounter = 0; + + /// + /// The contol's position within + /// + public int ControlNumber { get; } + private ProcessBookStatus Status { get; set; } = ProcessBookStatus.Queued; + private readonly int CancelBtnDistanceFromEdge; + private readonly int ProgressBarDistanceFromEdge; + + public static Color FailedColor = Color.LightCoral; + public static Color CancelledColor = Color.Khaki; + public static Color QueuedColor = SystemColors.Control; + public static Color SuccessColor = Color.PaleGreen; - internal partial class ProcessBookControl : UserControl, ILiberationBaseForm - { - public Action CancelAction { get; set; } - public Func MoveUpAction { get; set; } - public Func MoveDownAction { get; set; } - public string DecodeActionName { get; } = "Decoding"; - private Func GetCoverArtDelegate; - protected Processable Processable { get; private set; } - protected LogMe LogMe { get; private set; } public ProcessBookControl() { InitializeComponent(); - label1.Text = "Queued"; + statusLbl.Text = "Queued"; remainingTimeLbl.Visible = false; progressBar1.Visible = false; + etaLbl.Visible = false; + + CancelBtnDistanceFromEdge = Width - cancelBtn.Location.X; + ProgressBarDistanceFromEdge = Width - progressBar1.Location.X - progressBar1.Width; + ControlNumber = ControlNumberCounter++; } - public void SetResult(ProcessBookResult status) - { - var statusTxt = status switch - { - ProcessBookResult.Success => "Finished", - ProcessBookResult.Cancelled => "Cancelled", - ProcessBookResult.FailedRetry => "Error, Retry", - ProcessBookResult.FailedSkip => "Error, Skip", - ProcessBookResult.FailedAbort => "Error, Abort", - _ => throw new NotImplementedException(), - }; - - Color backColor = status switch - { - ProcessBookResult.Success => Color.PaleGreen, - ProcessBookResult.Cancelled => Color.Khaki, - ProcessBookResult.FailedRetry => Color.LightCoral, - ProcessBookResult.FailedSkip => Color.LightCoral, - ProcessBookResult.FailedAbort => Color.Firebrick, - _ => throw new NotImplementedException(), - }; - - this.UIThreadAsync(() => - { - cancelBtn.Visible = false; - moveDownBtn.Visible = false; - moveUpBtn.Visible = false; - remainingTimeLbl.Visible = false; - progressBar1.Visible = false; - label1.Text = statusTxt; - BackColor = backColor; - }); - } - - public ProcessBookControl(string title, Image cover) : this() + public void SetCover(Image cover) { pictureBox1.Image = cover; + } + + public void SetBookInfo(string title) + { bookInfoLbl.Text = title; } - public void RegisterFileLiberator(Processable processable, LogMe logMe = null) + public void SetProgrss(int progress) { - if (processable is null) return; - - Processable = processable; - LogMe = logMe; - - Subscribe((Streamable)processable); - Subscribe(processable); - if (processable is AudioDecodable audioDecodable) - Subscribe(audioDecodable); + //Disable slow fill + //https://stackoverflow.com/a/5332770/3335599 + if (progress < progressBar1.Maximum) + progressBar1.Value = progress + 1; + progressBar1.Value = progress; } - - #region Event Subscribers and Unsubscribers - private void Subscribe(Streamable streamable) + public void SetRemainingTime(TimeSpan remaining) { - UnsubscribeStreamable(this, EventArgs.Empty); - - streamable.StreamingProgressChanged += Streamable_StreamingProgressChanged; - streamable.StreamingTimeRemaining += Streamable_StreamingTimeRemaining; - - Disposed += UnsubscribeStreamable; - } - private void Subscribe(Processable processable) - { - UnsubscribeProcessable(this, null); - - processable.Begin += Processable_Begin; - processable.Completed += Processable_Completed; - - //Don't unsubscribe from Dispose because it fires when - //Streamable.StreamingCompleted closes the form, and - //the Processable events need to live past that event. - processable.Completed += UnsubscribeProcessable; - } - private void Subscribe(AudioDecodable audioDecodable) - { - UnsubscribeAudioDecodable(this, EventArgs.Empty); - - audioDecodable.RequestCoverArt += AudioDecodable_RequestCoverArt; - audioDecodable.TitleDiscovered += AudioDecodable_TitleDiscovered; - audioDecodable.AuthorsDiscovered += AudioDecodable_AuthorsDiscovered; - audioDecodable.NarratorsDiscovered += AudioDecodable_NarratorsDiscovered; - audioDecodable.CoverImageDiscovered += AudioDecodable_CoverImageDiscovered; - - Disposed += UnsubscribeAudioDecodable; - } - private void UnsubscribeStreamable(object sender, EventArgs e) - { - Disposed -= UnsubscribeStreamable; - - Processable.StreamingProgressChanged -= Streamable_StreamingProgressChanged; - Processable.StreamingTimeRemaining -= Streamable_StreamingTimeRemaining; - } - private void UnsubscribeProcessable(object sender, LibraryBook e) - { - Processable.Completed -= UnsubscribeProcessable; - Processable.Begin -= Processable_Begin; - Processable.Completed -= Processable_Completed; - } - private void UnsubscribeAudioDecodable(object sender, EventArgs e) - { - if (Processable is not AudioDecodable audioDecodable) - return; - - Disposed -= UnsubscribeAudioDecodable; - audioDecodable.RequestCoverArt -= AudioDecodable_RequestCoverArt; - audioDecodable.TitleDiscovered -= AudioDecodable_TitleDiscovered; - audioDecodable.AuthorsDiscovered -= AudioDecodable_AuthorsDiscovered; - audioDecodable.NarratorsDiscovered -= AudioDecodable_NarratorsDiscovered; - audioDecodable.CoverImageDiscovered -= AudioDecodable_CoverImageDiscovered; - - audioDecodable.Cancel(); - } - #endregion - - #region Streamable event handlers - public void Streamable_StreamingProgressChanged(object sender, DownloadProgress downloadProgress) - { - if (!downloadProgress.ProgressPercentage.HasValue) - return; - - if (downloadProgress.ProgressPercentage == 0) - updateRemainingTime(0); - else - progressBar1.UIThreadAsync(() => progressBar1.Value = (int)downloadProgress.ProgressPercentage); + remainingTimeLbl.Text = $"{remaining:mm\\:ss}"; } - public void Streamable_StreamingTimeRemaining(object sender, TimeSpan timeRemaining) + public void SetResult(ProcessBookResult result) { - updateRemainingTime((int)timeRemaining.TotalSeconds); - } - - private void updateRemainingTime(int remaining) - => remainingTimeLbl.UIThreadAsync(() => remainingTimeLbl.Text = formatTime(remaining)); - - private string formatTime(int seconds) - { - var timeSpan = TimeSpan.FromSeconds(seconds); - return $"{timeSpan:mm\\:ss}"; - } - - #endregion - - #region Processable event handlers - public void Processable_Begin(object sender, LibraryBook libraryBook) - { - LogMe.Info($"{Environment.NewLine}{Processable.Name} Step, Begin: {libraryBook.Book}"); - - this.UIThreadAsync(() => + string statusText = default; + switch (result) { - label1.Text = "ETA:"; - remainingTimeLbl.Visible = true; - progressBar1.Visible = true; - }); - - GetCoverArtDelegate = () => PictureStorage.GetPictureSynchronously( - new PictureDefinition( - libraryBook.Book.PictureId, - PictureSize._500x500)); - - //Set default values from library - AudioDecodable_TitleDiscovered(sender, libraryBook.Book.Title); - AudioDecodable_AuthorsDiscovered(sender, libraryBook.Book.AuthorNames()); - AudioDecodable_NarratorsDiscovered(sender, libraryBook.Book.NarratorNames()); - AudioDecodable_CoverImageDiscovered(sender, - PictureStorage.GetPicture( - new PictureDefinition( - libraryBook.Book.PictureId, - PictureSize._80x80)).bytes); - } - - public void Processable_Completed(object sender, LibraryBook libraryBook) - { - LogMe.Info($"{Processable.Name} Step, Completed: {libraryBook.Book}"); - } - - #endregion - - #region AudioDecodable event handlers - - private string title; - private string authorNames; - private string narratorNames; - public void AudioDecodable_TitleDiscovered(object sender, string title) - { - this.UIThreadAsync(() => this.Text = DecodeActionName + " " + title); - this.title = title; - updateBookInfo(); - } - - public void AudioDecodable_AuthorsDiscovered(object sender, string authors) - { - authorNames = authors; - updateBookInfo(); - } - - public void AudioDecodable_NarratorsDiscovered(object sender, string narrators) - { - narratorNames = narrators; - updateBookInfo(); - } - - private void updateBookInfo() - => bookInfoLbl.UIThreadAsync(() => bookInfoLbl.Text = $"{title}\r\nBy {authorNames}\r\nNarrated by {narratorNames}"); - - public void AudioDecodable_RequestCoverArt(object sender, Action setCoverArtDelegate) - { - setCoverArtDelegate(GetCoverArtDelegate?.Invoke()); - } - - public void AudioDecodable_CoverImageDiscovered(object sender, byte[] coverArt) - { - pictureBox1.UIThreadAsync(() => pictureBox1.Image = Dinah.Core.Drawing.ImageReader.ToImage(coverArt)); - } - #endregion - - private void cancelBtn_Click(object sender, EventArgs e) - { - CancelAction?.Invoke(); - } - - private void moveUpBtn_Click(object sender, EventArgs e) - { - HandleMovePositionResult(MoveUpAction?.Invoke()); - } - - - private void moveDownBtn_Click(object sender, EventArgs e) - { - HandleMovePositionResult(MoveDownAction?.Invoke()); - } - - private void HandleMovePositionResult(QueuePosition? result) - { - if (result.HasValue) - SetQueuePosition(result.Value); - else - SetQueuePosition(QueuePosition.Absent); - } - - public void SetQueuePosition(QueuePosition status) - { - if (status is QueuePosition.Absent or QueuePosition.Current) - { - moveUpBtn.Visible = false; - moveDownBtn.Visible = false; + case ProcessBookResult.Success: + statusText = "Finished"; + Status = ProcessBookStatus.Completed; + break; + case ProcessBookResult.Cancelled: + statusText = "Cancelled"; + Status = ProcessBookStatus.Cancelled; + break; + case ProcessBookResult.FailedRetry: + statusText = "Queued"; + Status = ProcessBookStatus.Queued; + break; + case ProcessBookResult.FailedSkip: + statusText = "Error, Skippping"; + Status = ProcessBookStatus.Failed; + break; + case ProcessBookResult.FailedAbort: + statusText = "Error, Abort"; + Status = ProcessBookStatus.Failed; + break; + case ProcessBookResult.ValidationFail: + statusText = "Validion fail"; + Status = ProcessBookStatus.Failed; + break; + case ProcessBookResult.None: + statusText = "UNKNOWN"; + Status = ProcessBookStatus.Failed; + break; } - if (status == QueuePosition.Absent) - cancelBtn.Enabled = false; + SetStatus(Status, statusText); + } - moveUpBtn.Enabled = status != QueuePosition.Fisrt; - moveDownBtn.Enabled = status != QueuePosition.Last; + public void SetStatus(ProcessBookStatus status, string statusText = null) + { + Color backColor = default; + switch (status) + { + case ProcessBookStatus.Completed: + backColor = SuccessColor; + Status = ProcessBookStatus.Completed; + break; + case ProcessBookStatus.Cancelled: + backColor = CancelledColor; + Status = ProcessBookStatus.Cancelled; + break; + case ProcessBookStatus.Queued: + backColor = QueuedColor; + Status = ProcessBookStatus.Queued; + break; + case ProcessBookStatus.Working: + backColor = QueuedColor; + Status = ProcessBookStatus.Working; + break; + case ProcessBookStatus.Failed: + backColor = FailedColor; + Status = ProcessBookStatus.Failed; + break; + } + + SuspendLayout(); + + cancelBtn.Visible = Status is ProcessBookStatus.Queued or ProcessBookStatus.Working; + moveLastBtn.Visible = Status == ProcessBookStatus.Queued; + moveDownBtn.Visible = Status == ProcessBookStatus.Queued; + moveUpBtn.Visible = Status == ProcessBookStatus.Queued; + moveFirstBtn.Visible = Status == ProcessBookStatus.Queued; + remainingTimeLbl.Visible = Status == ProcessBookStatus.Working; + progressBar1.Visible = Status == ProcessBookStatus.Working; + etaLbl.Visible = Status == ProcessBookStatus.Working; + statusLbl.Visible = Status != ProcessBookStatus.Working; + statusLbl.Text = statusText ?? Status.ToString(); + BackColor = backColor; + + int deltaX = Width - cancelBtn.Location.X - CancelBtnDistanceFromEdge; + + if (Status is ProcessBookStatus.Queued or ProcessBookStatus.Working && deltaX != 0) + { + //If the last book to occupy this control before resizing was not + //queued, the buttons were not Visible so the Anchor property was + //ignored. Manually resize and reposition everyhting + + cancelBtn.Location = new Point(cancelBtn.Location.X + deltaX, cancelBtn.Location.Y); + moveFirstBtn.Location = new Point(moveFirstBtn.Location.X + deltaX, moveFirstBtn.Location.Y); + moveUpBtn.Location = new Point(moveUpBtn.Location.X + deltaX, moveUpBtn.Location.Y); + moveDownBtn.Location = new Point(moveDownBtn.Location.X + deltaX, moveDownBtn.Location.Y); + moveLastBtn.Location = new Point(moveLastBtn.Location.X + deltaX, moveLastBtn.Location.Y); + etaLbl.Location = new Point(etaLbl.Location.X + deltaX, etaLbl.Location.Y); + remainingTimeLbl.Location = new Point(remainingTimeLbl.Location.X + deltaX, remainingTimeLbl.Location.Y); + progressBar1.Width = Width - ProgressBarDistanceFromEdge - progressBar1.Location.X; + } + + if (status == ProcessBookStatus.Working) + { + bookInfoLbl.Width = cancelBtn.Location.X - bookInfoLbl.Location.X - bookInfoLbl.Padding.Left + cancelBtn.Padding.Right; + } + else + { + bookInfoLbl.Width = moveLastBtn.Location.X - bookInfoLbl.Location.X - bookInfoLbl.Padding.Left + moveLastBtn.Padding.Right; + } + + ResumeLayout(); + } + + public override string ToString() + { + return bookInfoLbl.Text ?? "[NO TITLE]"; } } } diff --git a/Source/LibationWinForms/ProcessQueue/ProcessBookControl.resx b/Source/LibationWinForms/ProcessQueue/ProcessBookControl.resx index 180633dc..83921ba7 100644 --- a/Source/LibationWinForms/ProcessQueue/ProcessBookControl.resx +++ b/Source/LibationWinForms/ProcessQueue/ProcessBookControl.resx @@ -60,16 +60,13 @@ True - - True - True True - + True @@ -737,31 +734,40 @@ /x9W31o+WFcHNAAAAABJRU5ErkJggg== + + True + + + True + True - iVBORw0KGgoAAAANSUhEUgAAAKoAAABXCAYAAACUet5FAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1 - MAAA6mAAADqYAAAXb5JfxUYAAAAJcEhZcwAACwwAAAsMAT9AIsgAAAQvSURBVHhe7dJLbutGFEVRtzKO - DCFDzhAzA4d5cCWKvSTxSvxUFU9jdQ7AugCxPz4/PyO6xzGiNxwrPj5/i59+xxagpoRjhY5f3J+LvxZ/ - 3Gxxh5oSjhU6fmH/RLr8mF8S6wpqSjhW6PhF3UbaJNYn1JRwrNDxC1KkTWJ9QE0Jxwodv5hHkTaJ9Q41 - JRwrdPxC1kTaJFZQU8KxQscvohJpk1i/UVPCsULHL+CVSJvEekNNCccKHZ/cO5E2ifWLmhKOFTo+sS0i - bRLrQk0Jxwodn9SWkTaXj1VNCccKHZ/QHpE2l45VTQnHCh2fzJ6RNpeNVU0Jxwodn8gRkTaXjFVNCccK - HZ/EkZE2l4tVTQnHCh2fwBmRNpeKVU0JxwodH9yZkTaXiVVNCccKHR9YD5E2l4hVTQnHCh0fVE+RNtPH - qqaEY4WOD6jHSJupY1VTwrFCxwfTc6TNtLGqKeFYoeMDGSHSZspY1ZRwrNDxQYwUaTNdrGpKOFbo+ABG - jLSZKlY1JRwrdLxzI0faTBOrmhKOFTresRkibaaIVU0Jxwod79RMkTbDx6qmhGOFjndoxkiboWNVU8Kx - Qsc7M3OkzbCxqinhWKHjHblCpM2Qsaop4Vih4524UqTNcLGqKeFYoeMduGKkzVCxqinhWKHjJ7typM0w - saop4Vih4ydKpP8ZIlY1JRwrdPwkifSn7mNVU8K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T4xsQdu + DmAuphjw35gM8RmIPXBzAHOik0inUfuhP0W9Pu+ZMBOxB+7hF7AUOpF0KrUluMmfzRdMmJG2B62HX8CS + 6FTSydSWIfrAZIgvQNuD1sMvrq7u679F3Jn32x60Hn5BQXCfUhDEQgqCWEhBEAspCGIhBUEspCCIhRQE + sZCCIBZSEMRCCoJYSEEQCykIYiEFQSykIIiFFASxkIIgFlIQxEIKglhIQRALKQhiIQVBLKQgiIU3FOT6 + 6l8KOJAbKVKmPQAAAABJRU5ErkJggg== diff --git a/Source/LibationWinForms/ProcessQueue/ProcessBookForm.Designer.cs b/Source/LibationWinForms/ProcessQueue/ProcessBookForm.Designer.cs index 036022fb..548f06d2 100644 --- a/Source/LibationWinForms/ProcessQueue/ProcessBookForm.Designer.cs +++ b/Source/LibationWinForms/ProcessQueue/ProcessBookForm.Designer.cs @@ -37,7 +37,7 @@ this.ClientSize = new System.Drawing.Size(522, 638); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow; this.Name = "ProcessBookForm"; - this.Text = "ProcessBookForm"; + this.Text = "Book Processing Queue"; this.ResumeLayout(false); } diff --git a/Source/LibationWinForms/ProcessQueue/ProcessBookForm.cs b/Source/LibationWinForms/ProcessQueue/ProcessBookForm.cs index ebdf2784..b1444c84 100644 --- a/Source/LibationWinForms/ProcessQueue/ProcessBookForm.cs +++ b/Source/LibationWinForms/ProcessQueue/ProcessBookForm.cs @@ -1,12 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; +using System.Windows.Forms; namespace LibationWinForms.ProcessQueue { diff --git a/Source/LibationWinForms/ProcessQueue/ProcessBookQueue.Designer.cs b/Source/LibationWinForms/ProcessQueue/ProcessBookQueue.Designer.cs deleted file mode 100644 index 62848fbe..00000000 --- a/Source/LibationWinForms/ProcessQueue/ProcessBookQueue.Designer.cs +++ /dev/null @@ -1,235 +0,0 @@ -namespace LibationWinForms.ProcessQueue -{ - partial class ProcessBookQueue - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Component Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.statusStrip1 = new System.Windows.Forms.StatusStrip(); - this.toolStripProgressBar1 = new System.Windows.Forms.ToolStripProgressBar(); - this.tabControl1 = new System.Windows.Forms.TabControl(); - this.tabPage1 = new System.Windows.Forms.TabPage(); - this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); - this.panel1 = new System.Windows.Forms.Panel(); - this.btnCleanFinished = new System.Windows.Forms.Button(); - this.cancelAllBtn = new System.Windows.Forms.Button(); - this.tabPage2 = new System.Windows.Forms.TabPage(); - this.panel2 = new System.Windows.Forms.Panel(); - this.clearLogBtn = new System.Windows.Forms.Button(); - this.logMeTbox = new System.Windows.Forms.TextBox(); - this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); - this.statusStrip1.SuspendLayout(); - this.tabControl1.SuspendLayout(); - this.tabPage1.SuspendLayout(); - this.panel1.SuspendLayout(); - this.tabPage2.SuspendLayout(); - this.panel2.SuspendLayout(); - this.SuspendLayout(); - // - // statusStrip1 - // - this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripProgressBar1, - this.toolStripStatusLabel1}); - this.statusStrip1.Location = new System.Drawing.Point(0, 486); - this.statusStrip1.Name = "statusStrip1"; - this.statusStrip1.Size = new System.Drawing.Size(359, 22); - this.statusStrip1.TabIndex = 1; - this.statusStrip1.Text = "statusStrip1"; - // - // toolStripProgressBar1 - // - this.toolStripProgressBar1.Name = "toolStripProgressBar1"; - this.toolStripProgressBar1.Size = new System.Drawing.Size(100, 16); - // - // tabControl1 - // - this.tabControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.tabControl1.Controls.Add(this.tabPage1); - this.tabControl1.Controls.Add(this.tabPage2); - this.tabControl1.Location = new System.Drawing.Point(0, 0); - this.tabControl1.Margin = new System.Windows.Forms.Padding(0); - this.tabControl1.Name = "tabControl1"; - this.tabControl1.SelectedIndex = 0; - this.tabControl1.Size = new System.Drawing.Size(360, 486); - this.tabControl1.TabIndex = 3; - // - // tabPage1 - // - this.tabPage1.Controls.Add(this.flowLayoutPanel1); - this.tabPage1.Controls.Add(this.panel1); - this.tabPage1.Location = new System.Drawing.Point(4, 24); - this.tabPage1.Name = "tabPage1"; - this.tabPage1.Padding = new System.Windows.Forms.Padding(3); - this.tabPage1.Size = new System.Drawing.Size(352, 458); - this.tabPage1.TabIndex = 0; - this.tabPage1.Text = "Process Queue"; - this.tabPage1.UseVisualStyleBackColor = true; - // - // flowLayoutPanel1 - // - this.flowLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.flowLayoutPanel1.AutoScroll = true; - this.flowLayoutPanel1.BackColor = System.Drawing.SystemColors.ControlDarkDark; - this.flowLayoutPanel1.Location = new System.Drawing.Point(3, 3); - this.flowLayoutPanel1.Name = "flowLayoutPanel1"; - this.flowLayoutPanel1.Size = new System.Drawing.Size(346, 419); - this.flowLayoutPanel1.TabIndex = 0; - this.flowLayoutPanel1.ClientSizeChanged += new System.EventHandler(this.flowLayoutPanel1_ClientSizeChanged); - this.flowLayoutPanel1.Layout += new System.Windows.Forms.LayoutEventHandler(this.flowLayoutPanel1_Layout); - // - // panel1 - // - this.panel1.BackColor = System.Drawing.SystemColors.ControlDark; - this.panel1.Controls.Add(this.btnCleanFinished); - this.panel1.Controls.Add(this.cancelAllBtn); - this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom; - this.panel1.Location = new System.Drawing.Point(3, 425); - this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(346, 30); - this.panel1.TabIndex = 2; - // - // btnCleanFinished - // - this.btnCleanFinished.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Right))); - this.btnCleanFinished.Location = new System.Drawing.Point(253, 3); - this.btnCleanFinished.Name = "btnCleanFinished"; - this.btnCleanFinished.Size = new System.Drawing.Size(90, 23); - this.btnCleanFinished.TabIndex = 3; - this.btnCleanFinished.Text = "Clear Finished"; - this.btnCleanFinished.UseVisualStyleBackColor = true; - this.btnCleanFinished.Click += new System.EventHandler(this.btnCleanFinished_Click); - // - // cancelAllBtn - // - this.cancelAllBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left))); - this.cancelAllBtn.Location = new System.Drawing.Point(3, 3); - this.cancelAllBtn.Name = "cancelAllBtn"; - this.cancelAllBtn.Size = new System.Drawing.Size(75, 23); - this.cancelAllBtn.TabIndex = 2; - this.cancelAllBtn.Text = "Cancel All"; - this.cancelAllBtn.UseVisualStyleBackColor = true; - this.cancelAllBtn.Click += new System.EventHandler(this.cancelAllBtn_Click); - // - // tabPage2 - // - this.tabPage2.Controls.Add(this.panel2); - this.tabPage2.Controls.Add(this.logMeTbox); - this.tabPage2.Location = new System.Drawing.Point(4, 24); - this.tabPage2.Name = "tabPage2"; - this.tabPage2.Padding = new System.Windows.Forms.Padding(3); - this.tabPage2.Size = new System.Drawing.Size(352, 458); - this.tabPage2.TabIndex = 1; - this.tabPage2.Text = "Log"; - this.tabPage2.UseVisualStyleBackColor = true; - // - // panel2 - // - this.panel2.BackColor = System.Drawing.SystemColors.ControlDark; - this.panel2.Controls.Add(this.clearLogBtn); - this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom; - this.panel2.Location = new System.Drawing.Point(3, 425); - this.panel2.Name = "panel2"; - this.panel2.Size = new System.Drawing.Size(346, 30); - this.panel2.TabIndex = 1; - // - // clearLogBtn - // - this.clearLogBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left))); - this.clearLogBtn.Location = new System.Drawing.Point(3, 3); - this.clearLogBtn.Name = "clearLogBtn"; - this.clearLogBtn.Size = new System.Drawing.Size(75, 23); - this.clearLogBtn.TabIndex = 0; - this.clearLogBtn.Text = "Clear Log"; - this.clearLogBtn.UseVisualStyleBackColor = true; - this.clearLogBtn.Click += new System.EventHandler(this.clearLogBtn_Click); - // - // logMeTbox - // - this.logMeTbox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.logMeTbox.Location = new System.Drawing.Point(3, 3); - this.logMeTbox.Margin = new System.Windows.Forms.Padding(3, 3, 3, 0); - this.logMeTbox.MaxLength = 10000000; - this.logMeTbox.Multiline = true; - this.logMeTbox.Name = "logMeTbox"; - this.logMeTbox.ReadOnly = true; - this.logMeTbox.ScrollBars = System.Windows.Forms.ScrollBars.Both; - this.logMeTbox.Size = new System.Drawing.Size(346, 419); - this.logMeTbox.TabIndex = 0; - // - // toolStripStatusLabel1 - // - this.toolStripStatusLabel1.Name = "toolStripStatusLabel1"; - this.toolStripStatusLabel1.Size = new System.Drawing.Size(211, 17); - this.toolStripStatusLabel1.Spring = true; - // - // ProcessBookQueue - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.Controls.Add(this.tabControl1); - this.Controls.Add(this.statusStrip1); - this.Name = "ProcessBookQueue"; - this.Size = new System.Drawing.Size(359, 508); - this.statusStrip1.ResumeLayout(false); - this.statusStrip1.PerformLayout(); - this.tabControl1.ResumeLayout(false); - this.tabPage1.ResumeLayout(false); - this.panel1.ResumeLayout(false); - this.tabPage2.ResumeLayout(false); - this.tabPage2.PerformLayout(); - this.panel2.ResumeLayout(false); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - private System.Windows.Forms.StatusStrip statusStrip1; - private System.Windows.Forms.ToolStripProgressBar toolStripProgressBar1; - private System.Windows.Forms.TabControl tabControl1; - private System.Windows.Forms.TabPage tabPage1; - private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; - private System.Windows.Forms.Panel panel1; - private System.Windows.Forms.TabPage tabPage2; - private System.Windows.Forms.TextBox logMeTbox; - private System.Windows.Forms.Button btnCleanFinished; - private System.Windows.Forms.Button cancelAllBtn; - private System.Windows.Forms.Panel panel2; - private System.Windows.Forms.Button clearLogBtn; - private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1; - } -} diff --git a/Source/LibationWinForms/ProcessQueue/ProcessBookQueue.cs b/Source/LibationWinForms/ProcessQueue/ProcessBookQueue.cs deleted file mode 100644 index af748764..00000000 --- a/Source/LibationWinForms/ProcessQueue/ProcessBookQueue.cs +++ /dev/null @@ -1,343 +0,0 @@ -using DataLayer; -using Dinah.Core.Threading; -using LibationWinForms.BookLiberation; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace LibationWinForms.ProcessQueue -{ - internal partial class ProcessBookQueue : UserControl, ILogForm - { - private ProcessBook CurrentBook; - private readonly LinkedList BookQueue = new(); - private readonly List CompletedBooks = new(); - private readonly LogMe Logger; - private readonly object lockObject = new(); - - - public Task QueueRunner { get; private set; } - public bool Running => !QueueRunner?.IsCompleted ?? false; - - public ToolStripButton popoutBtn = new(); - - public ProcessBookQueue() - { - InitializeComponent(); - Logger = LogMe.RegisterForm(this); - - - this.popoutBtn.DisplayStyle = ToolStripItemDisplayStyle.Text; - this.popoutBtn.Name = "popoutBtn"; - this.popoutBtn.Text = "Pop Out"; - this.popoutBtn.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.popoutBtn.Alignment = ToolStripItemAlignment.Right; - this.popoutBtn.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - - statusStrip1.Items.Add(popoutBtn); - } - public async Task AddDownloadDecrypt(IEnumerable entries) - { - foreach (var entry in entries) - await AddDownloadDecryptAsync(entry); - } - - public async Task AddDownloadDecryptAsync(GridEntry gridEntry) - { - if (BookExists(gridEntry.LibraryBook)) - return; - - ProcessBook pbook = new ProcessBook(gridEntry, Logger); - pbook.Completed += Pbook_Completed; - pbook.Cancelled += Pbook_Cancelled; - pbook.RequestMove += (o,d) => RequestMove(o, d); - - var libStatus = gridEntry.Liberate; - - if (libStatus.BookStatus != LiberatedStatus.Liberated) - pbook.AddDownloadDecryptProcessable(); - - if (libStatus.PdfStatus != LiberatedStatus.Liberated) - pbook.AddPdfProcessable(); - - EnqueueBook(pbook); - - await AddBookControlAsync(pbook.BookControl); - - if (!Running) - { - QueueRunner = QueueLoop(); - } - } - - private async void Pbook_Cancelled(ProcessBook sender, EventArgs e) - { - lock (lockObject) - { - if (BookQueue.Contains(sender)) - BookQueue.Remove(sender); - } - await RemoveBookControlAsync(sender.BookControl); - } - - /// - /// Handles requests by to change its order in the queue - /// - /// The requesting - /// The requested position - /// The resultant position - private QueuePosition RequestMove(ProcessBook sender, QueuePosition direction) - { - var node = BookQueue.Find(sender); - - if (node == null || direction == QueuePosition.Absent) - return QueuePosition.Absent; - if (CurrentBook != null && CurrentBook == sender) - return QueuePosition.Current; - if ((direction == QueuePosition.Fisrt || direction == QueuePosition.OneUp) && BookQueue.First.Value == sender) - return QueuePosition.Fisrt; - if ((direction == QueuePosition.Last || direction == QueuePosition.OneDown) && BookQueue.Last.Value == sender) - return QueuePosition.Last; - - if (direction == QueuePosition.OneUp) - { - var oneUp = node.Previous; - BookQueue.Remove(node); - BookQueue.AddBefore(oneUp, node.Value); - } - else if (direction == QueuePosition.OneDown) - { - var oneDown = node.Next; - BookQueue.Remove(node); - BookQueue.AddAfter(oneDown, node.Value); - } - else if (direction == QueuePosition.Fisrt) - { - BookQueue.Remove(node); - BookQueue.AddFirst(node); - } - else - { - BookQueue.Remove(node); - BookQueue.AddLast(node); - } - - var index = flowLayoutPanel1.Controls.IndexOf((Control)sender.BookControl); - - index = direction switch - { - QueuePosition.Fisrt => 0, - QueuePosition.OneUp => index - 1, - QueuePosition.OneDown => index + 1, - QueuePosition.Last => flowLayoutPanel1.Controls.Count - 1, - _ => throw new NotImplementedException(), - }; - - flowLayoutPanel1.Controls.SetChildIndex((Control)sender.BookControl, index); - - if (index == 0) return QueuePosition.Fisrt; - if (index == flowLayoutPanel1.Controls.Count - 1) return QueuePosition.Last; - return direction; - } - - private async Task QueueLoop() - { - while (MoreInQueue()) - { - var nextBook = NextBook(); - nextBook.BookControl.SetQueuePosition(QueuePosition.Current); - PeekBook()?.BookControl.SetQueuePosition(QueuePosition.Fisrt); - - var result = await nextBook.ProcessOneAsync(); - - AddCompletedBook(nextBook); - - switch (result) - { - case ProcessBookResult.FailedRetry: - EnqueueBook(nextBook); - break; - case ProcessBookResult.FailedAbort: - return; - } - } - } - - private bool BookExists(LibraryBook libraryBook) - { - lock (lockObject) - { - return CurrentBook?.Entry?.AudibleProductId == libraryBook.Book.AudibleProductId || - CompletedBooks.Union(BookQueue).Any(p => p.Entry.AudibleProductId == libraryBook.Book.AudibleProductId); - } - } - - private ProcessBook NextBook() - { - lock (lockObject) - { - CurrentBook = BookQueue.First.Value; - BookQueue.RemoveFirst(); - return CurrentBook; - } - } - private ProcessBook PeekBook() - { - lock (lockObject) - return BookQueue.Count > 0 ? BookQueue.First.Value : default; - } - - private void EnqueueBook(ProcessBook pbook) - { - lock (lockObject) - BookQueue.AddLast(pbook); - } - - private void AddCompletedBook(ProcessBook pbook) - { - lock (lockObject) - CompletedBooks.Add(pbook); - } - - private bool MoreInQueue() - { - lock (lockObject) - return BookQueue.Count > 0; - } - - - private void Pbook_Completed(object sender, EventArgs e) - { - if (CurrentBook == sender) - CurrentBook = default; - } - - private async void cancelAllBtn_Click(object sender, EventArgs e) - { - List l1 = new(); - lock (lockObject) - { - l1.AddRange(BookQueue); - BookQueue.Clear(); - } - CurrentBook?.Cancel(); - CurrentBook = default; - - await RemoveBookControlsAsync(l1.Select(l => l.BookControl)); - } - - private async void btnCleanFinished_Click(object sender, EventArgs e) - { - List l1 = new(); - lock (lockObject) - { - l1.AddRange(CompletedBooks); - CompletedBooks.Clear(); - } - - await RemoveBookControlsAsync(l1.Select(l => l.BookControl)); - } - - private async Task AddBookControlAsync(ILiberationBaseForm control) - { - await Task.Run(() => Invoke(() => - { - SetBookControlWidth((Control)control); - flowLayoutPanel1.Controls.Add((Control)control); - flowLayoutPanel1.SetFlowBreak((Control)control, true); - Refresh(); - })); - } - - private async Task RemoveBookControlAsync(ILiberationBaseForm control) - { - await Task.Run(() => Invoke(() => - { - flowLayoutPanel1.Controls.Remove((Control)control); - })); - } - - private async Task RemoveBookControlsAsync(IEnumerable control) - { - await Task.Run(() => Invoke(() => - { - SuspendLayout(); - foreach (var l in control) - flowLayoutPanel1.Controls.Remove((Control)l); - ResumeLayout(); - })); - } - - public void WriteLine(string text) - { - if (!IsDisposed) - logMeTbox.UIThreadAsync(() => logMeTbox.AppendText($"{DateTime.Now} {text}{Environment.NewLine}")); - } - - private void clearLogBtn_Click(object sender, EventArgs e) - { - logMeTbox.Clear(); - } - - [DllImport("user32.dll", EntryPoint = "GetWindowLong")] - private static extern long GetWindowLongPtr(IntPtr hWnd, int nIndex); - - [DllImport("user32.dll")] - private static extern bool ShowScrollBar(IntPtr hWnd, SBOrientation bar, bool show); - - public const int WS_VSCROLL = 0x200000; - public const int WS_HSCROLL = 0x100000; - enum SBOrientation : int - { - SB_HORZ = 0, - SB_VERT = 1, - SB_CTL = 2, - SB_BOTH = 3 - } - - private void flowLayoutPanel1_ClientSizeChanged(object sender, EventArgs e) - { - ReorderControls(); - } - - private void flowLayoutPanel1_Layout(object sender, LayoutEventArgs e) - { - ReorderControls(); - } - - bool V_SHOWN = false; - - private void ReorderControls() - { - bool hShown = (GetWindowLongPtr(flowLayoutPanel1.Handle, -16) & WS_HSCROLL) != 0; - bool vShown = (GetWindowLongPtr(flowLayoutPanel1.Handle, -16) & WS_VSCROLL) != 0; - - if (hShown) - ShowScrollBar(flowLayoutPanel1.Handle, SBOrientation.SB_HORZ, false); - - if (vShown != V_SHOWN) - { - flowLayoutPanel1.SuspendLayout(); - - foreach (Control c in flowLayoutPanel1.Controls) - SetBookControlWidth(c); - - flowLayoutPanel1.ResumeLayout(); - V_SHOWN = vShown; - } - } - - private void SetBookControlWidth(Control book) - { - book.Width = flowLayoutPanel1.ClientRectangle.Width - book.Margin.Left - book.Margin.Right; - } - - private void toolStripSplitButton1_ButtonClick(object sender, EventArgs e) - { - - } - } -} diff --git a/Source/LibationWinForms/ProcessQueue/ProcessQueueControl.Designer.cs b/Source/LibationWinForms/ProcessQueue/ProcessQueueControl.Designer.cs new file mode 100644 index 00000000..3e99394f --- /dev/null +++ b/Source/LibationWinForms/ProcessQueue/ProcessQueueControl.Designer.cs @@ -0,0 +1,341 @@ +namespace LibationWinForms.ProcessQueue +{ + partial class ProcessQueueControl + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ProcessQueueControl)); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); + this.statusStrip1 = new System.Windows.Forms.StatusStrip(); + this.toolStripProgressBar1 = new System.Windows.Forms.ToolStripProgressBar(); + this.queueNumberLbl = new System.Windows.Forms.ToolStripStatusLabel(); + this.completedNumberLbl = new System.Windows.Forms.ToolStripStatusLabel(); + this.errorNumberLbl = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); + this.runningTimeLbl = new System.Windows.Forms.ToolStripStatusLabel(); + this.tabControl1 = new System.Windows.Forms.TabControl(); + this.tabPage1 = new System.Windows.Forms.TabPage(); + this.panel3 = new System.Windows.Forms.Panel(); + this.virtualFlowControl2 = new LibationWinForms.ProcessQueue.VirtualFlowControl(); + this.panel1 = new System.Windows.Forms.Panel(); + this.btnCleanFinished = new System.Windows.Forms.Button(); + this.cancelAllBtn = new System.Windows.Forms.Button(); + this.tabPage2 = new System.Windows.Forms.TabPage(); + this.logDGV = new System.Windows.Forms.DataGridView(); + this.timestampColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.logEntryColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.panel4 = new System.Windows.Forms.Panel(); + this.panel2 = new System.Windows.Forms.Panel(); + this.clearLogBtn = new System.Windows.Forms.Button(); + this.counterTimer = new System.Windows.Forms.Timer(this.components); + this.logCopyBtn = new System.Windows.Forms.Button(); + this.statusStrip1.SuspendLayout(); + this.tabControl1.SuspendLayout(); + this.tabPage1.SuspendLayout(); + this.panel1.SuspendLayout(); + this.tabPage2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.logDGV)).BeginInit(); + this.panel2.SuspendLayout(); + this.SuspendLayout(); + // + // statusStrip1 + // + this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); + this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripProgressBar1, + this.queueNumberLbl, + this.completedNumberLbl, + this.errorNumberLbl, + this.toolStripStatusLabel1, + this.runningTimeLbl}); + this.statusStrip1.Location = new System.Drawing.Point(0, 483); + this.statusStrip1.Name = "statusStrip1"; + this.statusStrip1.Size = new System.Drawing.Size(404, 25); + this.statusStrip1.TabIndex = 1; + this.statusStrip1.Text = "baseStatusStrip"; + // + // toolStripProgressBar1 + // + this.toolStripProgressBar1.Name = "toolStripProgressBar1"; + this.toolStripProgressBar1.Size = new System.Drawing.Size(100, 19); + // + // queueNumberLbl + // + this.queueNumberLbl.Image = ((System.Drawing.Image)(resources.GetObject("queueNumberLbl.Image"))); + this.queueNumberLbl.Name = "queueNumberLbl"; + this.queueNumberLbl.Size = new System.Drawing.Size(51, 20); + this.queueNumberLbl.Text = "[Q#]"; + // + // completedNumberLbl + // + this.completedNumberLbl.Image = ((System.Drawing.Image)(resources.GetObject("completedNumberLbl.Image"))); + this.completedNumberLbl.Name = "completedNumberLbl"; + this.completedNumberLbl.Size = new System.Drawing.Size(56, 20); + this.completedNumberLbl.Text = "[DL#]"; + // + // errorNumberLbl + // + this.errorNumberLbl.Image = ((System.Drawing.Image)(resources.GetObject("errorNumberLbl.Image"))); + this.errorNumberLbl.Name = "errorNumberLbl"; + this.errorNumberLbl.Size = new System.Drawing.Size(62, 20); + this.errorNumberLbl.Text = "[ERR#]"; + // + // toolStripStatusLabel1 + // + this.toolStripStatusLabel1.Name = "toolStripStatusLabel1"; + this.toolStripStatusLabel1.Size = new System.Drawing.Size(77, 20); + this.toolStripStatusLabel1.Spring = true; + // + // runningTimeLbl + // + this.runningTimeLbl.AutoSize = false; + this.runningTimeLbl.Name = "runningTimeLbl"; + this.runningTimeLbl.Size = new System.Drawing.Size(41, 20); + this.runningTimeLbl.Text = "[TIME]"; + // + // tabControl1 + // + this.tabControl1.Controls.Add(this.tabPage1); + this.tabControl1.Controls.Add(this.tabPage2); + this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill; + this.tabControl1.Location = new System.Drawing.Point(0, 0); + this.tabControl1.Margin = new System.Windows.Forms.Padding(0); + this.tabControl1.Name = "tabControl1"; + this.tabControl1.SelectedIndex = 0; + this.tabControl1.Size = new System.Drawing.Size(404, 483); + this.tabControl1.TabIndex = 3; + // + // tabPage1 + // + this.tabPage1.Controls.Add(this.panel3); + this.tabPage1.Controls.Add(this.virtualFlowControl2); + this.tabPage1.Controls.Add(this.panel1); + this.tabPage1.Location = new System.Drawing.Point(4, 24); + this.tabPage1.Name = "tabPage1"; + this.tabPage1.Padding = new System.Windows.Forms.Padding(3); + this.tabPage1.Size = new System.Drawing.Size(396, 455); + this.tabPage1.TabIndex = 0; + this.tabPage1.Text = "Process Queue"; + this.tabPage1.UseVisualStyleBackColor = true; + // + // panel3 + // + this.panel3.Dock = System.Windows.Forms.DockStyle.Bottom; + this.panel3.Location = new System.Drawing.Point(3, 422); + this.panel3.Name = "panel3"; + this.panel3.Size = new System.Drawing.Size(390, 5); + this.panel3.TabIndex = 4; + // + // virtualFlowControl2 + // + this.virtualFlowControl2.AccessibleRole = System.Windows.Forms.AccessibleRole.None; + this.virtualFlowControl2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.virtualFlowControl2.Dock = System.Windows.Forms.DockStyle.Fill; + this.virtualFlowControl2.Location = new System.Drawing.Point(3, 3); + this.virtualFlowControl2.Name = "virtualFlowControl2"; + this.virtualFlowControl2.Size = new System.Drawing.Size(390, 424); + this.virtualFlowControl2.TabIndex = 3; + this.virtualFlowControl2.VirtualControlCount = 0; + // + // panel1 + // + this.panel1.BackColor = System.Drawing.SystemColors.Control; + this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.panel1.Controls.Add(this.btnCleanFinished); + this.panel1.Controls.Add(this.cancelAllBtn); + this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom; + this.panel1.Location = new System.Drawing.Point(3, 427); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(390, 25); + this.panel1.TabIndex = 2; + // + // btnCleanFinished + // + this.btnCleanFinished.Dock = System.Windows.Forms.DockStyle.Right; + this.btnCleanFinished.Location = new System.Drawing.Point(298, 0); + this.btnCleanFinished.Name = "btnCleanFinished"; + this.btnCleanFinished.Size = new System.Drawing.Size(90, 23); + this.btnCleanFinished.TabIndex = 3; + this.btnCleanFinished.Text = "Clear Finished"; + this.btnCleanFinished.UseVisualStyleBackColor = true; + this.btnCleanFinished.Click += new System.EventHandler(this.btnClearFinished_Click); + // + // cancelAllBtn + // + this.cancelAllBtn.Dock = System.Windows.Forms.DockStyle.Left; + this.cancelAllBtn.Location = new System.Drawing.Point(0, 0); + this.cancelAllBtn.Name = "cancelAllBtn"; + this.cancelAllBtn.Size = new System.Drawing.Size(75, 23); + this.cancelAllBtn.TabIndex = 2; + this.cancelAllBtn.Text = "Cancel All"; + this.cancelAllBtn.UseVisualStyleBackColor = true; + this.cancelAllBtn.Click += new System.EventHandler(this.cancelAllBtn_Click); + // + // tabPage2 + // + this.tabPage2.Controls.Add(this.logDGV); + this.tabPage2.Controls.Add(this.panel4); + this.tabPage2.Controls.Add(this.panel2); + this.tabPage2.Location = new System.Drawing.Point(4, 24); + this.tabPage2.Name = "tabPage2"; + this.tabPage2.Padding = new System.Windows.Forms.Padding(3); + this.tabPage2.Size = new System.Drawing.Size(396, 455); + this.tabPage2.TabIndex = 1; + this.tabPage2.Text = "Log"; + this.tabPage2.UseVisualStyleBackColor = true; + // + // logDGV + // + this.logDGV.AllowUserToAddRows = false; + this.logDGV.AllowUserToDeleteRows = false; + this.logDGV.AllowUserToOrderColumns = true; + this.logDGV.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells; + this.logDGV.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.logDGV.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.timestampColumn, + this.logEntryColumn}); + this.logDGV.Dock = System.Windows.Forms.DockStyle.Fill; + this.logDGV.Location = new System.Drawing.Point(3, 3); + this.logDGV.Name = "logDGV"; + this.logDGV.RowHeadersVisible = false; + this.logDGV.RowTemplate.Height = 40; + this.logDGV.Size = new System.Drawing.Size(390, 419); + this.logDGV.TabIndex = 3; + this.logDGV.Resize += new System.EventHandler(this.LogDGV_Resize); + // + // timestampColumn + // + this.timestampColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells; + this.timestampColumn.HeaderText = "Timestamp"; + this.timestampColumn.Name = "timestampColumn"; + this.timestampColumn.ReadOnly = true; + this.timestampColumn.Width = 91; + // + // logEntryColumn + // + dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.logEntryColumn.DefaultCellStyle = dataGridViewCellStyle1; + this.logEntryColumn.HeaderText = "Log"; + this.logEntryColumn.Name = "logEntryColumn"; + this.logEntryColumn.ReadOnly = true; + // + // panel4 + // + this.panel4.Dock = System.Windows.Forms.DockStyle.Bottom; + this.panel4.Location = new System.Drawing.Point(3, 422); + this.panel4.Name = "panel4"; + this.panel4.Size = new System.Drawing.Size(390, 5); + this.panel4.TabIndex = 2; + // + // panel2 + // + this.panel2.BackColor = System.Drawing.SystemColors.Control; + this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.panel2.Controls.Add(this.logCopyBtn); + this.panel2.Controls.Add(this.clearLogBtn); + this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom; + this.panel2.Location = new System.Drawing.Point(3, 427); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(390, 25); + this.panel2.TabIndex = 1; + // + // clearLogBtn + // + this.clearLogBtn.Dock = System.Windows.Forms.DockStyle.Left; + this.clearLogBtn.Location = new System.Drawing.Point(0, 0); + this.clearLogBtn.Name = "clearLogBtn"; + this.clearLogBtn.Size = new System.Drawing.Size(60, 23); + this.clearLogBtn.TabIndex = 0; + this.clearLogBtn.Text = "Clear"; + this.clearLogBtn.UseVisualStyleBackColor = true; + this.clearLogBtn.Click += new System.EventHandler(this.clearLogBtn_Click); + // + // counterTimer + // + this.counterTimer.Interval = 950; + this.counterTimer.Tick += new System.EventHandler(this.CounterTimer_Tick); + // + // logCopyBtn + // + this.logCopyBtn.Dock = System.Windows.Forms.DockStyle.Right; + this.logCopyBtn.Location = new System.Drawing.Point(331, 0); + this.logCopyBtn.Name = "logCopyBtn"; + this.logCopyBtn.Size = new System.Drawing.Size(57, 23); + this.logCopyBtn.TabIndex = 1; + this.logCopyBtn.Text = "Copy"; + this.logCopyBtn.UseVisualStyleBackColor = true; + this.logCopyBtn.Click += new System.EventHandler(this.LogCopyBtn_Click); + // + // ProcessQueueControl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.Controls.Add(this.tabControl1); + this.Controls.Add(this.statusStrip1); + this.Name = "ProcessQueueControl"; + this.Size = new System.Drawing.Size(404, 508); + this.statusStrip1.ResumeLayout(false); + this.statusStrip1.PerformLayout(); + this.tabControl1.ResumeLayout(false); + this.tabPage1.ResumeLayout(false); + this.panel1.ResumeLayout(false); + this.tabPage2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.logDGV)).EndInit(); + this.panel2.ResumeLayout(false); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private System.Windows.Forms.StatusStrip statusStrip1; + private System.Windows.Forms.ToolStripProgressBar toolStripProgressBar1; + private System.Windows.Forms.TabControl tabControl1; + private System.Windows.Forms.TabPage tabPage1; + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.TabPage tabPage2; + private System.Windows.Forms.Button btnCleanFinished; + private System.Windows.Forms.Button cancelAllBtn; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.Button clearLogBtn; + private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1; + private VirtualFlowControl virtualFlowControl2; + private System.Windows.Forms.ToolStripStatusLabel queueNumberLbl; + private System.Windows.Forms.ToolStripStatusLabel completedNumberLbl; + private System.Windows.Forms.ToolStripStatusLabel errorNumberLbl; + private System.Windows.Forms.Panel panel3; + private System.Windows.Forms.Panel panel4; + private System.Windows.Forms.ToolStripStatusLabel runningTimeLbl; + private System.Windows.Forms.Timer counterTimer; + private System.Windows.Forms.DataGridView logDGV; + private System.Windows.Forms.DataGridViewTextBoxColumn timestampColumn; + private System.Windows.Forms.DataGridViewTextBoxColumn logEntryColumn; + private System.Windows.Forms.Button logCopyBtn; + } +} diff --git a/Source/LibationWinForms/ProcessQueue/ProcessQueueControl.cs b/Source/LibationWinForms/ProcessQueue/ProcessQueueControl.cs new file mode 100644 index 00000000..b0fa7aa3 --- /dev/null +++ b/Source/LibationWinForms/ProcessQueue/ProcessQueueControl.cs @@ -0,0 +1,361 @@ +using LibationWinForms.BookLiberation; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace LibationWinForms.ProcessQueue +{ + internal partial class ProcessQueueControl : UserControl, ILogForm + { + private TrackedQueue Queue = new(); + private readonly LogMe Logger; + private int QueuedCount + { + set + { + queueNumberLbl.Text = value.ToString(); + queueNumberLbl.Visible = value > 0; + } + } + private int ErrorCount + { + set + { + errorNumberLbl.Text = value.ToString(); + errorNumberLbl.Visible = value > 0; + } + } + + private int CompletedCount + { + set + { + completedNumberLbl.Text = value.ToString(); + completedNumberLbl.Visible = value > 0; + } + } + + public Task QueueRunner { get; private set; } + public bool Running => !QueueRunner?.IsCompleted ?? false; + public ToolStripButton popoutBtn = new(); + + public ProcessQueueControl() + { + InitializeComponent(); + Logger = LogMe.RegisterForm(this); + + runningTimeLbl.Text = string.Empty; + popoutBtn.DisplayStyle = ToolStripItemDisplayStyle.Text; + popoutBtn.Name = "popoutBtn"; + popoutBtn.Text = "Pop Out"; + popoutBtn.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + popoutBtn.Alignment = ToolStripItemAlignment.Right; + popoutBtn.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + + statusStrip1.Items.Add(popoutBtn); + + virtualFlowControl2.RequestData += VirtualFlowControl1_RequestData; + virtualFlowControl2.ButtonClicked += VirtualFlowControl2_ButtonClicked; + + Queue.QueuededCountChanged += Queue_QueuededCountChanged; + Queue.CompletedCountChanged += Queue_CompletedCountChanged; + + QueuedCount = 0; + ErrorCount = 0; + CompletedCount = 0; + } + + public void AddDownloadPdf(IEnumerable entries) + { + foreach (var entry in entries) + AddDownloadPdf(entry); + } + + public void AddDownloadDecrypt(IEnumerable entries) + { + foreach (var entry in entries) + AddDownloadDecrypt(entry); + } + + public void AddConvertMp3(IEnumerable entries) + { + foreach (var entry in entries) + AddConvertMp3(entry); + } + + public void AddDownloadPdf(DataLayer.LibraryBook libraryBook) + { + if (Queue.Any(b => b?.LibraryBook?.Book?.AudibleProductId == libraryBook.Book.AudibleProductId)) + return; + + ProcessBook pbook = new(libraryBook, Logger); + pbook.PropertyChanged += Pbook_DataAvailable; + pbook.AddDownloadPdf(); + AddToQueue(pbook); + } + + public void AddDownloadDecrypt(DataLayer.LibraryBook libraryBook) + { + if (Queue.Any(b => b?.LibraryBook?.Book?.AudibleProductId == libraryBook.Book.AudibleProductId)) + return; + + ProcessBook pbook = new(libraryBook, Logger); + pbook.PropertyChanged += Pbook_DataAvailable; + pbook.AddDownloadDecryptBook(); + pbook.AddDownloadPdf(); + AddToQueue(pbook); + } + + public void AddConvertMp3(DataLayer.LibraryBook libraryBook) + { + if (Queue.Any(b => b?.LibraryBook?.Book?.AudibleProductId == libraryBook.Book.AudibleProductId)) + return; + + ProcessBook pbook = new(libraryBook, Logger); + pbook.PropertyChanged += Pbook_DataAvailable; + pbook.AddConvertToMp3(); + AddToQueue(pbook); + } + + private void AddToQueue(ProcessBook pbook) + { + BeginInvoke(() => + { + Queue.Enqueue(pbook); + if (!Running) + QueueRunner = QueueLoop(); + }); + } + + DateTime StartintTime; + private async Task QueueLoop() + { + StartintTime = DateTime.Now; + counterTimer.Start(); + + while (Queue.MoveNext()) + { + var nextBook = Queue.Current; + + var result = await nextBook.ProcessOneAsync(); + + if (result == ProcessBookResult.FailedRetry) + Queue.Enqueue(nextBook); + else if (result == ProcessBookResult.ValidationFail) + Queue.ClearCurrent(); + else if (result == ProcessBookResult.FailedAbort) + return; + } + Queue_CompletedCountChanged(this, 0); + counterTimer.Stop(); + virtualFlowControl2.VirtualControlCount = Queue.Count; + UpdateAllControls(); + } + + public void WriteLine(string text) + { + if (IsDisposed) return; + + var timeStamp = DateTime.Now; + logDGV.Rows.Add(timeStamp, text.Trim()); + } + + #region Control event handlers + + private void Queue_CompletedCountChanged(object sender, int e) + { + int errCount = Queue.Completed.Count(p => p.Result is ProcessBookResult.FailedAbort or ProcessBookResult.FailedSkip or ProcessBookResult.ValidationFail); + int completeCount = Queue.Completed.Count(p => p.Result is ProcessBookResult.Success); + + ErrorCount = errCount; + CompletedCount = completeCount; + UpdateProgressBar(); + } + private void Queue_QueuededCountChanged(object sender, int cueCount) + { + QueuedCount = cueCount; + virtualFlowControl2.VirtualControlCount = Queue.Count; + UpdateProgressBar(); + } + private void UpdateProgressBar() + { + toolStripProgressBar1.Maximum = Queue.Count; + toolStripProgressBar1.Value = Queue.Completed.Count; + } + + private void cancelAllBtn_Click(object sender, EventArgs e) + { + Queue.ClearQueue(); + Queue.Current?.Cancel(); + virtualFlowControl2.VirtualControlCount = Queue.Count; + UpdateAllControls(); + } + + private void btnClearFinished_Click(object sender, EventArgs e) + { + Queue.ClearCompleted(); + virtualFlowControl2.VirtualControlCount = Queue.Count; + UpdateAllControls(); + + if (!Running) + runningTimeLbl.Text = string.Empty; + } + + private void CounterTimer_Tick(object sender, EventArgs e) + { + string timeToStr(TimeSpan time) + { + string minsSecs = $"{time:mm\\:ss}"; + if (time.TotalHours >= 1) + return $"{time.TotalHours:F0}:{minsSecs}"; + return minsSecs; + } + + if (Running) + runningTimeLbl.Text = timeToStr(DateTime.Now - StartintTime); + } + + private void clearLogBtn_Click(object sender, EventArgs e) + { + logDGV.Rows.Clear(); + } + + private void LogCopyBtn_Click(object sender, EventArgs e) + { + string logText = string.Join("\r\n", logDGV.Rows.Cast().Select(r => $"{r.Cells[0].Value}\t{r.Cells[1].Value}")); + Clipboard.SetDataObject(logText, false, 5, 150); + } + + private void LogDGV_Resize(object sender, EventArgs e) + { + logDGV.Columns[1].Width = logDGV.Width - logDGV.Columns[0].Width; + } + + #endregion + + #region View-Model update event handling + + /// + /// Index of the first visible in the + /// + private int FirstVisible = 0; + /// + /// Number of visible in the + /// + private int NumVisible = 0; + /// + /// Controls displaying the state, starting with + /// + private IReadOnlyList Panels; + + /// + /// Updates the display of a single at within + /// + /// index of the within the + private void UpdateControl(int queueIndex, string propertyName = null) + { + int i = queueIndex - FirstVisible; + + if (i > NumVisible || i < 0) return; + + var proc = Queue[queueIndex]; + + Panels[i].Invoke(() => + { + Panels[i].SuspendLayout(); + if (propertyName is null || propertyName == nameof(proc.Cover)) + Panels[i].SetCover(proc.Cover); + if (propertyName is null || propertyName == nameof(proc.BookText)) + Panels[i].SetBookInfo(proc.BookText); + + if (proc.Result != ProcessBookResult.None) + { + Panels[i].SetResult(proc.Result); + return; + } + + if (propertyName is null || propertyName == nameof(proc.Status)) + Panels[i].SetStatus(proc.Status); + if (propertyName is null || propertyName == nameof(proc.Progress)) + Panels[i].SetProgrss(proc.Progress); + if (propertyName is null || propertyName == nameof(proc.TimeRemaining)) + Panels[i].SetRemainingTime(proc.TimeRemaining); + Panels[i].ResumeLayout(); + }); + } + + private void UpdateAllControls() + { + int numToShow = Math.Min(NumVisible, Queue.Count - FirstVisible); + + for (int i = 0; i < numToShow; i++) + UpdateControl(FirstVisible + i); + } + + + /// + /// View notified the model that a botton was clicked + /// + /// index of the within + /// The clicked control to update + private async void VirtualFlowControl2_ButtonClicked(int queueIndex, string buttonName, ProcessBookControl panelClicked) + { + ProcessBook item = Queue[queueIndex]; + if (buttonName == nameof(panelClicked.cancelBtn)) + { + await item.Cancel(); + Queue.RemoveQueued(item); + virtualFlowControl2.VirtualControlCount = Queue.Count; + } + else if (buttonName == nameof(panelClicked.moveFirstBtn)) + { + Queue.MoveQueuePosition(item, QueuePosition.Fisrt); + UpdateAllControls(); + } + else if (buttonName == nameof(panelClicked.moveUpBtn)) + { + Queue.MoveQueuePosition(item, QueuePosition.OneUp); + UpdateControl(queueIndex); + if (queueIndex > 0) + UpdateControl(queueIndex - 1); + } + else if (buttonName == nameof(panelClicked.moveDownBtn)) + { + Queue.MoveQueuePosition(item, QueuePosition.OneDown); + UpdateControl(queueIndex); + if (queueIndex + 1 < Queue.Count) + UpdateControl(queueIndex + 1); + } + else if (buttonName == nameof(panelClicked.moveLastBtn)) + { + Queue.MoveQueuePosition(item, QueuePosition.Last); + UpdateAllControls(); + } + } + + /// + /// View needs updating + /// + private void VirtualFlowControl1_RequestData(int firstIndex, int numVisible, IReadOnlyList panelsToFill) + { + FirstVisible = firstIndex; + NumVisible = numVisible; + Panels = panelsToFill; + UpdateAllControls(); + } + + /// + /// Model updates the view + /// + private void Pbook_DataAvailable(object sender, PropertyChangedEventArgs e) + { + int index = Queue.IndexOf((ProcessBook)sender); + UpdateControl(index, e.PropertyName); + } + + #endregion + } +} diff --git a/Source/LibationWinForms/ProcessQueue/ProcessQueueControl.resx b/Source/LibationWinForms/ProcessQueue/ProcessQueueControl.resx new file mode 100644 index 00000000..00da05c2 --- /dev/null +++ b/Source/LibationWinForms/ProcessQueue/ProcessQueueControl.resx @@ -0,0 +1,642 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + + + iVBORw0KGgoAAAANSUhEUgAAAm4AAAJuCAYAAAAJqI4TAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1 + MAAA6mAAADqYAAAXb5JfxUYAAAAJcEhZcwAACwwAAAsMAT9AIsgAACyySURBVHhe7d0/zL5tXd9xwQik + okkDuEhs0kGj3URxFYOmSYeq0a1xdDUdmq4MHVwZuzqadCLibCNOTVAcUTb/LCKDYIJBepziHeTg+zzH + 735+93Xen+9xvD7JK8Hv4lM5r+d850pz3T/w7W9/GwCABsojAAB5yiMAAHnKIwAAecojAAB5yiMAAHnK + IwAAecojAAB5yiMAAHnKIwAAecojAAB5yiMAAHnKIwAAecojAAB5yiMAAHnKIwAAecojAAB5yiMAAHnK + IwAAecojAAB5yiMAAHnKIwAAecojAAB5yiMAAHnKIwAAecojAAB5yiMAAHnKIwAAecojAAB5yiMAAHnK + IwAAecojAAB5yiMAAHnKIwAAecojAAB5yiMAAHnKIwAAecojAAB5yiMAAHnKIwAAecojAAB5yiMAAHnK + IwAAecojAAB5yiMAAHnKIwAAecojAAB5yiMAAHnKIwAAecojAAB5yiMAAHnKIwAAecojAAB5yiMAAHnK + IwAAecojAAB5yiMAAHnKIwAAecojAAB5yiMAAHnKIwAAecojAAB5yiMAAHnKIwAAecojAAB5yiMAAHnK + IwAAecojAAB5yiMAAHnKIwAAecojAAB5yiMAAHnKIwAAecojAAB5ymMnts3++3D9F8o7+2/D3ftfQ/XP + wnf95+Hu/buh+mfhu/7vYButaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx05smwm3NeGWSbhlEm6brWqA + E5XHTmybCbc14ZZJuGUSbputaoATlcdObJsJtzXhlkm4ZRJum61qgBOVx07Gfmn4oes/WOsJtzXhlkm4 + ZXqNcPv3wye/8x/tpVc1wInKYydj/2f40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uTFwQEAdv27qjEmKJcd + rfm+FwcHANj1vVVjTFAuO1rzXS8ODgCw689XjTFBuexozW96cXAAgF3fWDXGBOWyo8/m3y0vDw8A8Br/ + dikbY4Jy2dFn86eXl8cHAHiNP7WUjTFBuezos/nFy39aXj4AAICP+Q/LL1rKxpigXHb0Yv7A8vIhAAB8 + zO9fvjBVY0xQLjuK+VvLywcBAFD5G8sXp2qMCcplRzG/cPmny8sHAgDw0j9fvvCt0OtUjTFBueyomK9Y + Lg/i5YMBALj4Z8ulFb5kqsaYoFx29IG5VPPfXF4+IADg3C7fBv2SN2vXqRpjgnLZ0Sfm8gcR/uPy8mEB + AOdy+dOgX/wDBtVUjTFBuezoFXMp6cvf0+Yv1wWAc7n8pbiXv2ft8jPuH52qMSYolx1tzjctf2H53uUS + cD++/N/l5cMFAGa5/F5++T398nv75ff4P7984/LqqRpjgnIJAEAf5RIAgD7KJQAAfZRLAAD6KJcAAPRR + LgEA6KNcAgDQR7kEAKCPcgkAQB/lEgCAPsolAAB9lEsAAPoolwAA9FEuAQDoo1wCANBHuQQAoI9yCQBA + H+USAIA+yiUAAH2USwAA+iiXAAD0US4BAOijXAIA0Ee5BACgj3IJAEAf5RIAgD7KJQAAfZRLAAD6KJcA + APRRLgEA6KNcAgDQR7kEAKCPcgkAQB/lEgCAPsolAAB9lEsAAPoolwAA9FEuAQDoo1wCANBHuQQAoI9y + CQBAH+USAIA+yiUAAH2USwAA+iiXAAD0US4BAOijXAIA0Ee5BACgj3IJAEAf5RIAgC5+9uf9P2fMnIaN + w1EmAAAAAElFTkSuQmCC + + + + True + + + True + + + 133, 17 + + \ No newline at end of file diff --git a/Source/LibationWinForms/ProcessQueue/TrackedQueue[T].cs b/Source/LibationWinForms/ProcessQueue/TrackedQueue[T].cs new file mode 100644 index 00000000..20bbe7e8 --- /dev/null +++ b/Source/LibationWinForms/ProcessQueue/TrackedQueue[T].cs @@ -0,0 +1,230 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace LibationWinForms.ProcessQueue +{ + public enum QueuePosition + { + Fisrt, + OneUp, + OneDown, + Last + } + + /* + * This data structure is like lifting a metal chain one link at a time. + * Each time you grab and lift a new link (MoveNext call): + * + * 1) you're holding a new link in your hand (Current) + * 2) the remaining chain to be lifted shortens by 1 link (Queued) + * 3) the pile of chain at your feet grows by 1 link (Completed) + * + * The index is the link position from the first link you lifted to the + * last one in the chain. + */ + public class TrackedQueue where T : class + { + public event EventHandler CompletedCountChanged; + public event EventHandler QueuededCountChanged; + public T Current { get; private set; } + + public IReadOnlyList Queued => _queued; + public IReadOnlyList Completed => _completed; + + private readonly List _queued = new(); + private readonly List _completed = new(); + private readonly object lockObject = new(); + + public T this[int index] + { + get + { + lock (lockObject) + { + if (index < _completed.Count) + return _completed[index]; + index -= _completed.Count; + + if (index == 0 && Current != null) return Current; + + if (Current != null) index--; + + if (index < _queued.Count) return _queued.ElementAt(index); + + throw new IndexOutOfRangeException(); + } + } + } + + public int Count + { + get + { + lock (lockObject) + { + return _queued.Count + _completed.Count + (Current == null ? 0 : 1); + } + } + } + + public int IndexOf(T item) + { + lock (lockObject) + { + if (_completed.Contains(item)) + return _completed.IndexOf(item); + + if (Current == item) return _completed.Count; + + if (_queued.Contains(item)) + return _queued.IndexOf(item) + (Current is null ? 0 : 1); + return -1; + } + } + + public bool RemoveQueued(T item) + { + lock (lockObject) + { + bool removed = _queued.Remove(item); + if (removed) + QueuededCountChanged?.Invoke(this, _queued.Count); + return removed; + } + } + + public void ClearCurrent() + { + lock(lockObject) + Current = null; + } + + public bool RemoveCompleted(T item) + { + lock (lockObject) + { + bool removed = _completed.Remove(item); + if (removed) + CompletedCountChanged?.Invoke(this, _completed.Count); + return removed; + } + } + + public void ClearQueue() + { + lock (lockObject) + { + _queued.Clear(); + QueuededCountChanged?.Invoke(this, 0); + } + } + + public void ClearCompleted() + { + lock (lockObject) + { + _completed.Clear(); + CompletedCountChanged?.Invoke(this, 0); + } + } + + public bool Any(Func predicate) + { + lock (lockObject) + { + return (Current != null && predicate(Current)) || _completed.Any(predicate) || _queued.Any(predicate); + } + } + + public void MoveQueuePosition(T item, QueuePosition requestedPosition) + { + lock (lockObject) + { + if (_queued.Count == 0 || !_queued.Contains(item)) return; + + if ((requestedPosition == QueuePosition.Fisrt || requestedPosition == QueuePosition.OneUp) && _queued[0] == item) + return; + if ((requestedPosition == QueuePosition.Last || requestedPosition == QueuePosition.OneDown) && _queued[^1] == item) + return; + + int queueIndex = _queued.IndexOf(item); + + if (requestedPosition == QueuePosition.OneUp) + { + _queued.RemoveAt(queueIndex); + _queued.Insert(queueIndex - 1, item); + } + else if (requestedPosition == QueuePosition.OneDown) + { + _queued.RemoveAt(queueIndex); + _queued.Insert(queueIndex + 1, item); + } + else if (requestedPosition == QueuePosition.Fisrt) + { + _queued.RemoveAt(queueIndex); + _queued.Insert(0, item); + } + else + { + _queued.RemoveAt(queueIndex); + _queued.Insert(_queued.Count, item); + } + } + } + + public bool MoveNext() + { + lock (lockObject) + { + if (Current != null) + { + _completed.Add(Current); + CompletedCountChanged?.Invoke(this, _completed.Count); + } + if (_queued.Count == 0) + { + Current = null; + return false; + } + Current = _queued[0]; + _queued.RemoveAt(0); + + QueuededCountChanged?.Invoke(this, _queued.Count); + return true; + } + } + + public bool TryPeek(out T item) + { + lock (lockObject) + { + if (_queued.Count == 0) + { + item = null; + return false; + } + item = _queued[0]; + return true; + } + } + + public T Peek() + { + lock (lockObject) + { + if (_queued.Count == 0) throw new InvalidOperationException("Queue empty"); + return _queued.Count > 0 ? _queued[0] : default; + } + } + + public void Enqueue(T item) + { + lock (lockObject) + { + _queued.Add(item); + QueuededCountChanged?.Invoke(this, _queued.Count); + } + } + } +} diff --git a/Source/LibationWinForms/ProcessQueue/VirtualFlowControl.Designer.cs b/Source/LibationWinForms/ProcessQueue/VirtualFlowControl.Designer.cs new file mode 100644 index 00000000..77f793fc --- /dev/null +++ b/Source/LibationWinForms/ProcessQueue/VirtualFlowControl.Designer.cs @@ -0,0 +1,59 @@ +namespace LibationWinForms.ProcessQueue +{ + partial class VirtualFlowControl + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.panel1 = new System.Windows.Forms.Panel(); + this.SuspendLayout(); + // + // panel1 + // + this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.panel1.BackColor = System.Drawing.SystemColors.ControlDark; + this.panel1.Location = new System.Drawing.Point(0, 0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(377, 505); + this.panel1.TabIndex = 0; + // + // VirtualFlowControl + // + this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.Controls.Add(this.panel1); + this.Name = "VirtualFlowControl"; + this.Size = new System.Drawing.Size(377, 505); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel panel1; + } +} diff --git a/Source/LibationWinForms/ProcessQueue/VirtualFlowControl.cs b/Source/LibationWinForms/ProcessQueue/VirtualFlowControl.cs new file mode 100644 index 00000000..d031d191 --- /dev/null +++ b/Source/LibationWinForms/ProcessQueue/VirtualFlowControl.cs @@ -0,0 +1,267 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Windows.Forms; + +namespace LibationWinForms.ProcessQueue +{ + + internal delegate void RequestDataDelegate(int queueIndex, int numVisible, IReadOnlyList panelsToFill); + internal delegate void ControlButtonClickedDelegate(int queueIndex, string buttonName, ProcessBookControl panelClicked); + internal partial class VirtualFlowControl : UserControl + { + /// + /// Triggered when the needs to update the displayed s + /// + public event RequestDataDelegate RequestData; + /// + /// Triggered when one of the 's buttons has been clicked + /// + public event ControlButtonClickedDelegate ButtonClicked; + + #region Dynamic Properties + + /// + /// The number of virtual s in the + /// + public int VirtualControlCount + { + get => _virtualControlCount; + set + { + if (_virtualControlCount == 0) + vScrollBar1.Value = 0; + + _virtualControlCount = value; + AdjustScrollBar(); + DoVirtualScroll(); + } + } + + private int _virtualControlCount; + + int ScrollValue => Math.Max(vScrollBar1.Value, 0); + /// + /// Amount the control moves with a small scroll change + /// + private int SmallScrollChange => VirtualControlHeight * SMALL_SCROLL_CHANGE_MULTIPLE; + /// + /// Amount the control moves with a large scroll change. Equal to the number of whole s in the panel, less 1. + /// + private int LargeScrollChange => Math.Max(DisplayHeight / VirtualControlHeight - 1, SMALL_SCROLL_CHANGE_MULTIPLE) * VirtualControlHeight; + /// + /// Virtual height of all virtual controls within this + /// + private int VirtualHeight => (VirtualControlCount + NUM_BLANK_SPACES_AT_BOTTOM) * VirtualControlHeight - DisplayHeight + 2 * TopMargin; + /// + /// Index of the first virtual + /// + private int FirstVisibleVirtualIndex => ScrollValue / VirtualControlHeight; + /// + /// The display height of this + /// + private int DisplayHeight => DisplayRectangle.Height; + + #endregion + + #region Instance variables + + /// + /// The total height, inclusing margins, of the repeated + /// + private readonly int VirtualControlHeight; + /// + /// Margin between the top and the top of the Panel, and the bottom and the bottom of the panel + /// + private readonly int TopMargin; + + private readonly VScrollBar vScrollBar1; + private readonly List BookControls = new(); + + #endregion + + #region Global behavior settings + + /// + /// Total number of actual controls added to the panel. 23 is sufficient up to a 4k monitor height. + /// + private const int NUM_ACTUAL_CONTROLS = 23; + /// + /// Multiple of that is moved for each small scroll change + /// + private const int SMALL_SCROLL_CHANGE_MULTIPLE = 1; + /// + /// Amount of space at the bottom of the , in multiples of + /// + private const int NUM_BLANK_SPACES_AT_BOTTOM = 2; + + #endregion + + public VirtualFlowControl() + { + InitializeComponent(); + + vScrollBar1 = new VScrollBar + { + Minimum = 0, + Value = 0, + Dock = DockStyle.Right + }; + Controls.Add(vScrollBar1); + + vScrollBar1.Scroll += (_, s) => SetScrollPosition(s.NewValue); + panel1.Width -= vScrollBar1.Width + panel1.Margin.Right; + panel1.Resize += (_, _) => + { + AdjustScrollBar(); + DoVirtualScroll(); + }; + + + var control = InitControl(0); + VirtualControlHeight = control.Height + control.Margin.Top + control.Margin.Bottom; + TopMargin = control.Margin.Top; + + BookControls.Add(control); + panel1.Controls.Add(control); + + if (DesignMode) + return; + + for (int i = 1; i < NUM_ACTUAL_CONTROLS; i++) + { + control = InitControl(VirtualControlHeight * i); + BookControls.Add(control); + panel1.Controls.Add(control); + } + + vScrollBar1.SmallChange = SmallScrollChange; + panel1.Height += NUM_BLANK_SPACES_AT_BOTTOM * VirtualControlHeight; + } + + private ProcessBookControl InitControl(int locationY) + { + var control = new ProcessBookControl(); + control.Location = new Point(control.Margin.Left, locationY + control.Margin.Top); + control.Width = panel1.ClientRectangle.Width - control.Margin.Left - control.Margin.Right; + control.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top; + + control.cancelBtn.Click += ControlButton_Click; + control.moveFirstBtn.Click += ControlButton_Click; + control.moveUpBtn.Click += ControlButton_Click; + control.moveDownBtn.Click += ControlButton_Click; + control.moveLastBtn.Click += ControlButton_Click; + return control; + } + + /// + /// Handles all button clicks from all , detects which one sent the click, and fires to notify the model of the click + /// + private void ControlButton_Click(object sender, EventArgs e) + { + Control button = sender as Control; + Control form = button.Parent; + while (form is not ProcessBookControl) + form = form.Parent; + + int clickedIndex = BookControls.IndexOf((ProcessBookControl)form); + + ButtonClicked?.Invoke(FirstVisibleVirtualIndex + clickedIndex, button.Name, BookControls[clickedIndex]); + } + + /// + /// Adjusts the max width and enabled status based on the and the + /// + private void AdjustScrollBar() + { + int maxFullVisible = DisplayHeight / VirtualControlHeight; + + if (VirtualControlCount <= maxFullVisible) + { + vScrollBar1.Enabled = false; + vScrollBar1.Value = 0; + + for (int i = VirtualControlCount; i < NUM_ACTUAL_CONTROLS; i++) + BookControls[i].Visible = false; + } + else + { + vScrollBar1.Enabled = true; + vScrollBar1.LargeChange = LargeScrollChange; + + //https://stackoverflow.com/a/2882878/3335599 + int newMaximum = VirtualHeight + vScrollBar1.LargeChange - 1; + if (newMaximum < vScrollBar1.Maximum) + vScrollBar1.Value = Math.Max(vScrollBar1.Value - (vScrollBar1.Maximum - newMaximum), 0); + vScrollBar1.Maximum = newMaximum; + } + } + + /// + /// Calculated the virtual controls that are in view at the currrent scroll position and windows size, + /// positions to simulate scroll activity, then fires to notify the model to update all visible controls + /// + private void DoVirtualScroll() + { + int firstVisible = FirstVisibleVirtualIndex; + + int position = ScrollValue % VirtualControlHeight; + panel1.Location = new Point(0, -position); + + int numVisible = DisplayHeight / VirtualControlHeight; + + if (DisplayHeight % VirtualControlHeight != 0) + numVisible++; + + numVisible = Math.Min(numVisible, VirtualControlCount); + numVisible = Math.Min(numVisible, VirtualControlCount - firstVisible); + + RequestData?.Invoke(firstVisible, numVisible, BookControls); + + for (int i = 0; i < BookControls.Count; i++) + BookControls[i].Visible = i < numVisible; + } + + /// + /// Set scroll value to an integral multiple of + /// + private void SetScrollPosition(int value) + { + int newPos = (int)Math.Round((double)value / SmallScrollChange) * SmallScrollChange; + if (vScrollBar1.Value != newPos) + { + //https://stackoverflow.com/a/2882878/3335599 + vScrollBar1.Value = Math.Min(newPos, vScrollBar1.Maximum - vScrollBar1.LargeChange + 1); + DoVirtualScroll(); + } + } + + + private const int WM_MOUSEWHEEL = 522; + private const int WHEEL_DELTA = 120; + protected override void WndProc(ref Message m) + { + //Capture mouse wheel movement and interpret it as a scroll event + if (m.Msg == WM_MOUSEWHEEL) + { + //https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-mousewheel + int wheelDelta = -(short)(((ulong)m.WParam) >> 16 & ushort.MaxValue); + + int numSmallPositionMoves = Math.Abs(wheelDelta) / WHEEL_DELTA; + + int scrollDelta = Math.Sign(wheelDelta) * numSmallPositionMoves * SmallScrollChange; + + int newScrollPosition; + + if (scrollDelta > 0) + newScrollPosition = Math.Min(vScrollBar1.Value + scrollDelta, vScrollBar1.Maximum); + else + newScrollPosition = Math.Max(vScrollBar1.Value + scrollDelta, vScrollBar1.Minimum); + + SetScrollPosition(newScrollPosition); + } + + base.WndProc(ref m); + } + } +} diff --git a/Source/LibationWinForms/ProcessQueue/ProcessBookQueue.resx b/Source/LibationWinForms/ProcessQueue/VirtualFlowControl.resx similarity index 93% rename from Source/LibationWinForms/ProcessQueue/ProcessBookQueue.resx rename to Source/LibationWinForms/ProcessQueue/VirtualFlowControl.resx index 5cb320f3..f298a7be 100644 --- a/Source/LibationWinForms/ProcessQueue/ProcessBookQueue.resx +++ b/Source/LibationWinForms/ProcessQueue/VirtualFlowControl.resx @@ -57,7 +57,4 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 17, 17 - \ No newline at end of file diff --git a/Source/LibationWinForms/grid/ProductsGrid.cs b/Source/LibationWinForms/grid/ProductsGrid.cs index 93caca4d..b088262e 100644 --- a/Source/LibationWinForms/grid/ProductsGrid.cs +++ b/Source/LibationWinForms/grid/ProductsGrid.cs @@ -36,8 +36,10 @@ namespace LibationWinForms // VS has improved since then with .net6+ but I haven't checked again #endregion + public partial class ProductsGrid : UserControl { + public event EventHandler LiberateClicked; /// Number of visible rows has changed public event EventHandler VisibleCountChanged; @@ -76,7 +78,7 @@ namespace LibationWinForms return; if (e.ColumnIndex == liberateGVColumn.Index) - await Liberate_Click(getGridEntry(e.RowIndex)); + Liberate_Click(getGridEntry(e.RowIndex)); else if (e.ColumnIndex == tagAndDetailsGVColumn.Index) Details_Click(getGridEntry(e.RowIndex)); else if (e.ColumnIndex == descriptionGVColumn.Index) @@ -128,7 +130,7 @@ namespace LibationWinForms displayWindow.Show(this); } - private static async Task Liberate_Click(GridEntry liveGridEntry) + private void Liberate_Click(GridEntry liveGridEntry) { var libraryBook = liveGridEntry.LibraryBook; @@ -144,8 +146,7 @@ namespace LibationWinForms return; } - // else: liberate - await liveGridEntry.DownloadBook(); + LiberateClicked?.Invoke(this, liveGridEntry.LibraryBook); } private static void Details_Click(GridEntry liveGridEntry)