Skip to content

Commit

Permalink
Allowed for settings to contain number of retries. Because this is sh…
Browse files Browse the repository at this point in the history
…ould be a rarely used option, the only way to modify it is to edit the json settings file and restart the application. No GUI elements are added or changed.
  • Loading branch information
ajsnyde committed Dec 20, 2016
1 parent bd47fa4 commit 25bb3e9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
6 changes: 1 addition & 5 deletions Sources/BandcampDownloader/Miscellaneous/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@

namespace BandcampDownloader {

internal static class Constants {
/// <summary>
/// The maximum tries that can be done when downloading a file.
/// </summary>
public static readonly int DownloadMaxTries = 10;
internal static class Constants {
/// <summary>
/// The website URL of BandcampDownloader.
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions Sources/BandcampDownloader/Miscellaneous/UserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ internal class UserSettings {
public Boolean SaveCoverArtInTags { get; set; }
public Boolean ShowVerboseLog { get; set; }
public Boolean TagTracks { get; set; }
// Annotation required to allow serialization of static field
[JsonProperty]
public static int DownloadMaxTries { get; set; }

/// <summary>
/// Creates a new UserSettings with default values.
Expand Down Expand Up @@ -52,6 +55,7 @@ internal class UserSettings {
SaveCoverArtInTags = true;
ShowVerboseLog = false;
TagTracks = true;
DownloadMaxTries = 10;
}

/// <summary>
Expand Down
32 changes: 16 additions & 16 deletions Sources/BandcampDownloader/Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ public partial class MainWindow: Window {
Log($"Downloaded track \"{track.GetFileName(album.Artist)}\" from album \"{album.Title}\"", LogType.IntermediateSuccess);
} else if (!e.Cancelled && e.Error != null) {
if (tries < Constants.DownloadMaxTries) {
Log($"Unable to download track \"{track.GetFileName(album.Artist)}\" from album \"{album.Title}\". Try {tries} of {Constants.DownloadMaxTries}", LogType.Warning);
if (tries < UserSettings.DownloadMaxTries) {
Log($"Unable to download track \"{track.GetFileName(album.Artist)}\" from album \"{album.Title}\". Try {tries} of {UserSettings.DownloadMaxTries}", LogType.Warning);
} else {
Log($"Unable to download track \"{track.GetFileName(album.Artist)}\" from album \"{album.Title}\". Hit max retries of {Constants.DownloadMaxTries}", LogType.Error);
Log($"Unable to download track \"{track.GetFileName(album.Artist)}\" from album \"{album.Title}\". Hit max retries of {UserSettings.DownloadMaxTries}", LogType.Error);
}
} // Else the download has been cancelled (by the user)
Expand All @@ -207,7 +207,7 @@ public partial class MainWindow: Window {
this.pendingDownloads.Remove(webClient);
}
}
} while (!trackDownloaded && tries < Constants.DownloadMaxTries);
} while (!trackDownloaded && tries < UserSettings.DownloadMaxTries);

return trackDownloaded;
}
Expand Down Expand Up @@ -271,10 +271,10 @@ public partial class MainWindow: Window {
Log($"Downloaded artwork for album \"{album.Title}\"", LogType.IntermediateSuccess);
} else if (!e.Cancelled && e.Error != null) {
if (tries < Constants.DownloadMaxTries) {
Log($"Unable to download artwork for album \"{album.Title}\". Try {tries} of {Constants.DownloadMaxTries}", LogType.Warning);
if (tries < UserSettings.DownloadMaxTries) {
Log($"Unable to download artwork for album \"{album.Title}\". Try {tries} of {UserSettings.DownloadMaxTries}", LogType.Warning);
} else {
Log($"Unable to download artwork for album \"{album.Title}\". Hit max retries of {Constants.DownloadMaxTries}", LogType.Error);
Log($"Unable to download artwork for album \"{album.Title}\". Hit max retries of {UserSettings.DownloadMaxTries}", LogType.Error);
}
} // Else the download has been cancelled (by the user)
Expand All @@ -298,7 +298,7 @@ public partial class MainWindow: Window {
this.pendingDownloads.Remove(webClient);
}
}
} while (!artworkDownloaded && tries < Constants.DownloadMaxTries);
} while (!artworkDownloaded && tries < UserSettings.DownloadMaxTries);

return artwork;
}
Expand Down Expand Up @@ -408,13 +408,13 @@ public partial class MainWindow: Window {
Log($"Retrieved the size of the cover art file for album \"{album.Title}\"", LogType.VerboseInfo);
} catch {
sizeRetrieved = false;
if (tries < Constants.DownloadMaxTries) {
Log($"Failed to retrieve the size of the cover art file for album \"{album.Title}\". Try {tries} of {Constants.DownloadMaxTries}", LogType.Warning);
if (tries < UserSettings.DownloadMaxTries) {
Log($"Failed to retrieve the size of the cover art file for album \"{album.Title}\". Try {tries} of {UserSettings.DownloadMaxTries}", LogType.Warning);
} else {
Log($"Failed to retrieve the size of the cover art file for album \"{album.Title}\". Hit max retries of {Constants.DownloadMaxTries}. Progress update may be wrong.", LogType.Error);
Log($"Failed to retrieve the size of the cover art file for album \"{album.Title}\". Hit max retries of {UserSettings.DownloadMaxTries}. Progress update may be wrong.", LogType.Error);
}
}
} while (!sizeRetrieved && tries < Constants.DownloadMaxTries);
} while (!sizeRetrieved && tries < UserSettings.DownloadMaxTries);

files.Add(new TrackFile(album.ArtworkUrl, 0, size));
}
Expand All @@ -441,13 +441,13 @@ public partial class MainWindow: Window {
Log($"Retrieved the size of the MP3 file for the track \"{track.Title}\"", LogType.VerboseInfo);
} catch {
sizeRetrieved = false;
if (tries < Constants.DownloadMaxTries) {
Log($"Failed to retrieve the size of the MP3 file for the track \"{track.Title}\". Try {tries} of {Constants.DownloadMaxTries}", LogType.Warning);
if (tries < UserSettings.DownloadMaxTries) {
Log($"Failed to retrieve the size of the MP3 file for the track \"{track.Title}\". Try {tries} of {UserSettings.DownloadMaxTries}", LogType.Warning);
} else {
Log($"Failed to retrieve the size of the MP3 file for the track \"{track.Title}\". Hit max retries of {Constants.DownloadMaxTries}. Progress update may be wrong.", LogType.Error);
Log($"Failed to retrieve the size of the MP3 file for the track \"{track.Title}\". Hit max retries of {UserSettings.DownloadMaxTries}. Progress update may be wrong.", LogType.Error);
}
}
} while (!sizeRetrieved && tries < Constants.DownloadMaxTries);
} while (!sizeRetrieved && tries < UserSettings.DownloadMaxTries);

files.Add(new TrackFile(track.Mp3Url, 0, size));
}
Expand Down

0 comments on commit 25bb3e9

Please sign in to comment.