Skip to content

Commit

Permalink
fixed crash, added search bar to Add from Library
Browse files Browse the repository at this point in the history
fixed a crash caused by the MDL when attempting to add a manga with no chapters
  • Loading branch information
ErisLoona committed Dec 5, 2024
1 parent a96c93d commit 6af303a
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 26 deletions.
4 changes: 3 additions & 1 deletion Downloader-AddFromLibrary.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
<Grid RowDefinitions="93*, 7*">
<Border Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<ScrollViewer>
<StackPanel x:Name="MangaStackPanel" Spacing="4"/>
<StackPanel x:Name="MangaStackPanel" Spacing="4">
<AutoCompleteBox Grid.Row="1" x:Name="SearchBox" LostFocus="SearchBox_LostFocus" DropDownClosed="SearchBox_DropDownClosed" KeyDown="SearchBox_KeyDown" FilterMode="ContainsOrdinal" Background="White" Foreground="Black" Watermark="Search for a Manga..." FontSize="12" Margin="3" HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
</StackPanel>
</ScrollViewer>
</Border>
<Grid Grid.Row="1" ColumnDefinitions="50*, 50*">
Expand Down
37 changes: 33 additions & 4 deletions Downloader-AddFromLibrary.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
using static Manga_Manager.Globals;
using System.Collections.Generic;
using System.IO;
using Avalonia.Input;
using System;
using System.Linq;

namespace Manga_Manager;

public partial class Downloader_AddFromLibrary : Window
{
Dictionary<string, int> addedMangaIndexes = new Dictionary<string, int>();
private Dictionary<string, int> addedMangaIndexes = new Dictionary<string, int>();
private List<CheckBox> checkBoxes = new List<CheckBox>();

public Downloader_AddFromLibrary()
{
Expand All @@ -20,15 +24,41 @@ public Downloader_AddFromLibrary()
{
if (mangaList[i].ID != string.Empty && Downloader.addedMangas.Contains(mangaList[i].ID) == false && File.Exists(mangaList[i].Path))
{
MangaStackPanel.Children.Add(new CheckBox()
checkBoxes.Add(new CheckBox()
{
Foreground = new SolidColorBrush(Colors.White),
Margin = new Thickness(3, 0, 0, 0),
Content = mangaList[i].Title
});
MangaStackPanel.Children.Add(checkBoxes[checkBoxes.Count - 1]);
addedMangaIndexes[mangaList[i].Title] = i;
}
}

SearchBox.ItemsSource = addedMangaIndexes.Keys.ToArray();
}

private void SearchBox_LostFocus(object sender, RoutedEventArgs e)
{
if (SearchBox.Text == string.Empty)
return;
for (int i = 0; i < addedMangaIndexes.Count; i++)
if (addedMangaIndexes.ElementAt(i).Key.ToLower().Contains(SearchBox.Text.ToLower()))
{
checkBoxes[i].IsChecked = true;
break;
}
}

private void SearchBox_DropDownClosed(object sender, EventArgs e)
{
SearchBox_LostFocus(sender, null);
}

private void SearchBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
SearchBox_LostFocus(sender, null);
}

private void SelectAllButton_Clicked(object sender, RoutedEventArgs args)
Expand All @@ -43,9 +73,8 @@ private void SelectAllButton_Clicked(object sender, RoutedEventArgs args)
private void ConfirmButton_Clicked(object sender, RoutedEventArgs args)
{
List<int> selectedIndexes = new List<int>();
foreach (Control child in MangaStackPanel.Children)
foreach (CheckBox checkBox in checkBoxes)
{
CheckBox checkBox = child as CheckBox;
if (checkBox.IsChecked == true)
selectedIndexes.Add(addedMangaIndexes[checkBox.Content.ToString()]);
}
Expand Down
2 changes: 1 addition & 1 deletion Downloader.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ private async void DownloadButton_Clicked(object sender, RoutedEventArgs args)
if (selectedChapterNumbers.Count > 0)
{
string nr = padDecimal(selectedChapterNumbers.Max(), "D" + selectedChapterNumbers.Count.ToString().Length.ToString());
doc.DocumentElement.SelectSingleNode("//dc:description", nsmgr).InnerText += "<br>" + "Ch." + nr;
doc.DocumentElement.SelectSingleNode("//dc:description", nsmgr).InnerText = "Last chapter: " + "Ch." + nr;
}

doc.DocumentElement.SelectSingleNode("//dc:title", nsmgr).InnerText = currentManga.TempManga.Title;
Expand Down
17 changes: 2 additions & 15 deletions Manga Manager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,11 @@
<Copyright>Eris Loona, pseudonym</Copyright>
<PackageProjectUrl>https://github.com/ErisLoona/Manga-Library-Manager</PackageProjectUrl>
<NeutralLanguage>en</NeutralLanguage>
<FileVersion>3.0.0</FileVersion>
<FileVersion>3.0.1</FileVersion>
<ApplicationIcon>icon256.ico</ApplicationIcon>
<DebugType>embedded</DebugType>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
</PropertyGroup>
<ItemGroup>
<Compile Remove="MangaDex Library\MDLGetData.cs" />
<Compile Remove="MangaDex Library\MDLParameters.cs" />
<Compile Remove="MangaDex Library\RateLimiter.cs" />
</ItemGroup>
<ItemGroup>
<None Remove="Assets\arrowleft.png" />
<None Remove="Assets\export.png" />
Expand Down Expand Up @@ -54,14 +49,6 @@
</ItemGroup>

<ItemGroup>
<None Include="MangaDex Library\MDLGetData.cs" />
<None Include="MangaDex Library\MDLParameters.cs" />
<None Include="MangaDex Library\RateLimiter.cs" />
</ItemGroup>

<ItemGroup>
<Reference Include="MangaDex Library">
<HintPath>..\MangaDex Library\bin\Release\net8.0\publish\MangaDex Library.dll</HintPath>
</Reference>
<Folder Include="MangaDex Library\" />
</ItemGroup>
</Project>
12 changes: 11 additions & 1 deletion MangaDex Library/MDLGetData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
using System.Diagnostics;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Diagnostics;
using System.Globalization;
using System.Net.Http.Json;
using Newtonsoft.Json.Linq;
Expand Down Expand Up @@ -270,6 +275,11 @@ private static void UpdateFeed()
if (groupFound == false)
chapterGroups.Add("Anonymous (No Group)");
}
if (chapterNumbers.Count() == 0)
{
lastChapter = 0;
return;
}
bool doneGoneDidThisOne = true;
for (int j = 1; (j <= chapterNumbers.Count - 1) && (doneGoneDidThisOne == true); j++)
{
Expand Down
3 changes: 2 additions & 1 deletion MangaDex Library/MDLParameters.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.RegularExpressions;
using System.Net.Http;
using System.Text.RegularExpressions;

namespace MangaDex_Library
{
Expand Down
Binary file removed MangaDex Library/MangaDex Library.dll
Binary file not shown.
4 changes: 3 additions & 1 deletion MangaDex Library/RateLimiter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Diagnostics;
using System;
using System.Threading;
using System.Diagnostics;

namespace MangaDex_Library
{
Expand Down
2 changes: 1 addition & 1 deletion Properties/PublishProfiles/Linux Publish.pubxml.user
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<History>True|2024-12-03T07:55:53.8428381Z||;True|2024-12-02T21:20:46.8860520+01:00||;True|2024-12-02T20:39:14.6506039+01:00||;True|2024-11-29T11:47:46.0927549+01:00||;True|2024-11-29T11:37:55.4255378+01:00||;True|2024-11-29T11:37:15.3144929+01:00||;True|2024-11-29T11:35:01.2234796+01:00||;True|2024-11-29T10:43:07.8303034+01:00||;True|2024-11-27T20:49:34.0528895+01:00||;True|2024-11-27T20:48:22.3163582+01:00||;True|2024-11-27T20:30:06.3097457+01:00||;True|2024-11-27T16:59:22.2651522+01:00||;True|2024-11-27T09:39:28.4152325+01:00||;True|2024-11-27T09:01:20.5273611+01:00||;True|2024-11-27T08:56:54.6418789+01:00||;True|2024-11-27T08:51:22.1782954+01:00||;</History>
<History>True|2024-12-05T09:28:02.9478449Z||;True|2024-12-03T08:55:53.8428381+01:00||;True|2024-12-02T21:20:46.8860520+01:00||;True|2024-12-02T20:39:14.6506039+01:00||;True|2024-11-29T11:47:46.0927549+01:00||;True|2024-11-29T11:37:55.4255378+01:00||;True|2024-11-29T11:37:15.3144929+01:00||;True|2024-11-29T11:35:01.2234796+01:00||;True|2024-11-29T10:43:07.8303034+01:00||;True|2024-11-27T20:49:34.0528895+01:00||;True|2024-11-27T20:48:22.3163582+01:00||;True|2024-11-27T20:30:06.3097457+01:00||;True|2024-11-27T16:59:22.2651522+01:00||;True|2024-11-27T09:39:28.4152325+01:00||;True|2024-11-27T09:01:20.5273611+01:00||;True|2024-11-27T08:56:54.6418789+01:00||;True|2024-11-27T08:51:22.1782954+01:00||;</History>
<LastFailureDetails />
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion Properties/PublishProfiles/Windows Release.pubxml.user
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<History>True|2024-12-03T07:56:07.4697318Z||;True|2024-12-02T21:20:40.1113007+01:00||;True|2024-12-02T20:38:59.4610959+01:00||;True|2024-12-02T14:28:33.8752294+01:00||;True|2024-11-29T11:47:38.5429477+01:00||;True|2024-11-29T11:44:44.4931353+01:00||;True|2024-11-29T11:37:46.7879782+01:00||;True|2024-11-29T11:37:29.3303495+01:00||;True|2024-11-29T11:34:51.3573996+01:00||;True|2024-11-29T10:43:16.4214680+01:00||;True|2024-11-27T22:06:40.4122930+01:00||;True|2024-11-27T17:00:15.2266919+01:00||;True|2024-11-27T09:40:04.3729036+01:00||;True|2024-11-27T09:01:36.0426378+01:00||;True|2024-11-27T08:35:34.4591883+01:00||;True|2024-11-27T08:25:58.6905083+01:00||;True|2024-11-26T18:08:57.6730121+01:00||;True|2024-11-26T17:32:30.7716846+01:00||;</History>
<History>True|2024-12-05T14:48:21.6380912Z||;True|2024-12-05T15:41:01.2998753+01:00||;True|2024-12-05T10:27:53.9063325+01:00||;True|2024-12-05T10:21:12.0877537+01:00||;True|2024-12-03T08:56:07.4697318+01:00||;True|2024-12-02T21:20:40.1113007+01:00||;True|2024-12-02T20:38:59.4610959+01:00||;True|2024-12-02T14:28:33.8752294+01:00||;True|2024-11-29T11:47:38.5429477+01:00||;True|2024-11-29T11:44:44.4931353+01:00||;True|2024-11-29T11:37:46.7879782+01:00||;True|2024-11-29T11:37:29.3303495+01:00||;True|2024-11-29T11:34:51.3573996+01:00||;True|2024-11-29T10:43:16.4214680+01:00||;True|2024-11-27T22:06:40.4122930+01:00||;True|2024-11-27T17:00:15.2266919+01:00||;True|2024-11-27T09:40:04.3729036+01:00||;True|2024-11-27T09:01:36.0426378+01:00||;True|2024-11-27T08:35:34.4591883+01:00||;True|2024-11-27T08:25:58.6905083+01:00||;True|2024-11-26T18:08:57.6730121+01:00||;True|2024-11-26T17:32:30.7716846+01:00||;</History>
<LastFailureDetails />
</PropertyGroup>
</Project>
1 change: 1 addition & 0 deletions Settings.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ private void LanguageComboBox_SelectionChanged(object sender, SelectionChangedEv
{
selectedLanguage = languageDictionary[LanguageComboBox.SelectedItem.ToString()];
MDLParameters.Language = selectedLanguage;
MDLGetData.ForceReset();
}

private void UpdatesCheckBox_Checked(object sender, RoutedEventArgs e)
Expand Down

0 comments on commit 6af303a

Please sign in to comment.