Skip to content

Commit

Permalink
Updates to Database Dump Reader: Character Sex and release image.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoltanar committed Aug 16, 2024
1 parent f6e213a commit b004c98
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 65 deletions.
2 changes: 1 addition & 1 deletion Happy Reader.sln
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Qt5Version = 5.15.0_msvc2019
SolutionGuid = {2C3F6D43-6AFB-44A6-91C8-7E90A5625DE8}
Qt5Version = 5.15.0_msvc2019
EndGlobalSection
EndGlobal
20 changes: 2 additions & 18 deletions Happy Reader/Happy Reader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,6 @@
<Prefer32Bit>true</Prefer32Bit>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Happy Reader Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Happy Reader Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Resources\logo-hr.ico</ApplicationIcon>
</PropertyGroup>
Expand All @@ -86,11 +75,6 @@
<OutputPath>bin\x64\Release\</OutputPath>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Happy Reader Debug|x64'">
<PlatformTarget>x64</PlatformTarget>
<OutputPath>bin\x64\Happy Reader Debug\</OutputPath>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="DotNetProjects.DataVisualization.Toolkit, Version=6.1.91.0, Culture=neutral, PublicKeyToken=79778c5f2eed289b, processorArchitecture=MSIL">
<HintPath>..\packages\DotNetProjects.WpfToolkit.DataVisualization.6.1.91\lib\net40\DotNetProjects.DataVisualization.Toolkit.dll</HintPath>
Expand Down Expand Up @@ -522,8 +506,8 @@
<CollectSQLiteInteropFiles>false</CollectSQLiteInteropFiles>
</PropertyGroup>
<PropertyGroup>
<PostBuildEvent>call "$(DevEnvDir)..\tools\vsdevcmd.bat"
editbin /largeaddressaware "$(TargetPath)"</PostBuildEvent>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion Happy Reader/View/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<tabs:ProducersTab DataContext="{Binding ProducersViewModel}"/>
</TabItem>
<TabItem Visibility="Collapsed" Header="Settings" Style="{StaticResource SystemTab}">
<tabs:SettingsTab DataContext="{Binding SettingsViewModel}" x:Name="SettingsTab"/>
<tabs:SettingsTab DataContext="{Binding SettingsViewModel}" x:Name="SettingsTab" ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Visible"/>
</TabItem>
<TabItem Header="Information" Style="{StaticResource SystemTab}"
Visibility="{Binding SettingsViewModel.GuiSettings.DisplayInformationTab, Converter={StaticResource BooleanToVisibilityConverter}, ConverterParameter=C}">
Expand Down
75 changes: 44 additions & 31 deletions Happy Reader/View/Tabs/SettingsTab.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
<Setter Property="Background" Value="DimGray"/>
</Style>
</UserControl.Resources>
<Grid Background="DimGray">
<Grid Background="DimGray" Name="OwnerGrid">
<Grid.Style>
<Style TargetType="Grid">
<Setter Property="Background" Value="DimGray"/>
<Style.Resources>
<Style TargetType="Control">
<Setter Property="Foreground" Value="White" />
Expand All @@ -43,37 +44,49 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TabControl TabStripPlacement="Top">
<TabItem Header="Core Settings" DataContext="{Binding CoreSettings}">
<StackPanel x:Name="CoreSettingsPanel">
<view:LabeledTextBox LabelWidth="150" Label="Secondary Title Language:" Text="{Binding SecondaryTitleLanguage}" ToolTip="Secondary language (2 letter form) to sort titles by release date in that language"/>
<view:LabeledTextBox LabelWidth="150" Label="API Token:" Text="{Binding ApiToken}"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Content="Log In" Click="LogInWithDetails"/>
<TextBlock Grid.Column="1" Margin="5,0" x:Name="LoginResponseBlock" />
</Grid>
<CheckBox Content="Clear past data dumps and DB backups when updating" IsChecked="{Binding ClearOldDumpsAndBackups}"/>
<view:LabeledTextBox Label="VNDB Image Path:" LabelWidth="120" Text="{Binding ImageFolderPath}"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Label Content="Image Sync" Width="120"/>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<CheckBox Content="Characters" Margin="5,0" VerticalContentAlignment="Center" Checked="ImageSyncChanged" Unchecked="ImageSyncChanged" x:Name="ImageSyncCharacters"/>
<CheckBox Content="Covers" Margin="5,0" VerticalContentAlignment="Center" Checked="ImageSyncChanged" Unchecked="ImageSyncChanged" x:Name="ImageSyncCovers"/>
<CheckBox Content="Screenshots" Margin="5,0" VerticalContentAlignment="Center" Checked="ImageSyncChanged" Unchecked="ImageSyncChanged" x:Name="ImageSyncScreenshots"/>
<CheckBox Content="Screenshot Thumbnails" Margin="5,0" VerticalContentAlignment="Center" Checked="ImageSyncChanged" Unchecked="ImageSyncChanged" x:Name="ImageSyncScreenshotThumbnails"/>
</StackPanel>
<TabControl TabStripPlacement="Top" x:Name="TabControl">
<TabItem x:Name="CoreSettingsTabItem" Header="Core Settings" DataContext="{Binding CoreSettings}" >
<ScrollViewer VerticalScrollBarVisibility="Auto">
<Grid x:Name="CoreSettingsPanel" Background="DimGray">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<view:LabeledTextBox Grid.Row="0" LabelWidth="150" Label="Secondary Title Language:" Text="{Binding SecondaryTitleLanguage}" ToolTip="Secondary language (2 letter form) to sort titles by release date in that language"/>
<view:LabeledTextBox Grid.Row="1" LabelWidth="150" Label="API Token:" Text="{Binding ApiToken}"/>
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Content="Log In" Click="LogInWithDetails"/>
<TextBlock Grid.Column="1" Margin="5,0" x:Name="LoginResponseBlock" />
</Grid>
<CheckBox Grid.Row="3" Content="Clear past data dumps and DB backups when updating" IsChecked="{Binding ClearOldDumpsAndBackups}"/>
<view:LabeledTextBox Grid.Row="4" Label="VNDB Image Path:" LabelWidth="120" Text="{Binding ImageFolderPath}"/>
<Grid Grid.Row="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Label Content="Image Sync" Width="120"/>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<CheckBox Content="Characters" Margin="5,0" VerticalContentAlignment="Center" Checked="ImageSyncChanged" Unchecked="ImageSyncChanged" x:Name="ImageSyncCharacters"/>
<CheckBox Content="Covers" Margin="5,0" VerticalContentAlignment="Center" Checked="ImageSyncChanged" Unchecked="ImageSyncChanged" x:Name="ImageSyncCovers"/>
<CheckBox Content="Screenshots" Margin="5,0" VerticalContentAlignment="Center" Checked="ImageSyncChanged" Unchecked="ImageSyncChanged" x:Name="ImageSyncScreenshots"/>
<CheckBox Content="Screenshot Thumbnails" Margin="5,0" VerticalContentAlignment="Center" Checked="ImageSyncChanged" Unchecked="ImageSyncChanged" x:Name="ImageSyncScreenshotThumbnails"/>
</StackPanel>
</Grid>
<Button Grid.Row="6" x:Name="UpdateVndbButton" Content="Update VNDB Data" Click="UpdateVndbData"/>
<ListBox x:Name="UpdateLoggingBox" Visibility="Collapsed" Grid.Row="7" />
</Grid>
<Button x:Name="UpdateVndbButton" Content="Update VNDB Data" Click="UpdateVndbData"/>
<ListBox x:Name="UpdateLoggingBox" Visibility="Collapsed"/>
</StackPanel>
</ScrollViewer>
</TabItem>
<TabItem Header="Interface Settings" DataContext="{Binding GuiSettings}">
<StackPanel Background="DimGray">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public override void LoadFromStringParts(string[] parts)
Aliases = GetPart(parts, "alias");
ImageId = GetPartOrNull(parts, "image");
Description = GetPart(parts, "description");
Gender = GetPart(parts, "gender");
Gender = GetPart(parts, "sex");
}

public CharacterItem Clone() => (CharacterItem)((ICloneable)this).Clone();
Expand Down
63 changes: 50 additions & 13 deletions HappySearchObjectClasses/DumpReader/DumpReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ public class DumpReader
public string OutputFilePath { get; }
public VisualNovelDatabase Database { get; }
public SuggestionScorer SuggestionScorer { get; }
public Dictionary<int, Release> Releases { get; } = new();
/// <summary>
/// Key is release id.
/// </summary>
public Dictionary<int, List<LangRelease>> LangReleases { get; } = new();
public Dictionary<int, List<int>> ProducerReleases { get; } = new();
public Dictionary<int, List<Release>> VnReleases { get; } = new();
public Dictionary<int, DumpAnime> Animes { get; } = new();
public Dictionary<int, List<DumpVnAnime>> VnAnimes { get; } = new();
Expand Down Expand Up @@ -173,33 +171,44 @@ private void LoadCharacters(int[] previousCharacterIds)

private void LoadReleases()
{
Dictionary<int, List<int>> producerReleases = new();
Dictionary<int, Release> releases = new();
Load<ProducerRelease>((i, _) =>
{
if (!i.Developer) return;
if (!ProducerReleases.ContainsKey(i.ReleaseId)) ProducerReleases[i.ReleaseId] = new List<int>();
ProducerReleases[i.ReleaseId].Add(i.ProducerId);
}, "db\\releases_producers");
{
if (!i.Developer) return;
if (!producerReleases.ContainsKey(i.ReleaseId)) producerReleases[i.ReleaseId] = new List<int>();
producerReleases[i.ReleaseId].Add(i.ProducerId);
}, "db\\releases_producers");
Load<LangRelease>((i, _) =>
{
if (!LangReleases.ContainsKey(i.ReleaseId)) LangReleases[i.ReleaseId] = new List<LangRelease>();
LangReleases[i.ReleaseId].Add(i);
}, "db\\releases_titles");
Load<Release>((i, _) => Releases[i.ReleaseId] = i, "db\\releases");
Load<Release>((i, _) => releases[i.ReleaseId] = i, "db\\releases");
Load<VnRelease>((i, _) =>
{
if (!VnReleases.ContainsKey(i.VnId)) VnReleases[i.VnId] = new List<Release>();
if (!Releases.TryGetValue(i.ReleaseId, out var release)) return;
if (!releases.TryGetValue(i.ReleaseId, out var release)) return;
if (i.ReleaseType == "trial")
{
Releases.Remove(i.ReleaseId);
releases.Remove(i.ReleaseId);
return;
}
release.Languages = LangReleases[i.ReleaseId];
foreach (var langRelease in release.Languages) langRelease.Partial = i.ReleaseType == "partial";
ProducerReleases.TryGetValue(i.ReleaseId, out var producerRelease);
producerReleases.TryGetValue(i.ReleaseId, out var producerRelease);
release.Producers = producerRelease ?? new List<int>();
VnReleases[i.VnId].Add(release);
}, "db\\releases_vn");
Load<ReleaseImage>((i, _) =>
{
if (!releases.TryGetValue(i.ReleaseId, out var release)) return;
release.Images.Add(i);
}, "db\\releases_images");
//clear collections to save memory
producerReleases.Clear();
releases.Clear();
GC.Collect();
}

private void ResolveUserVnForVn(ListedVN vn, SQLiteTransaction transaction)
Expand All @@ -217,9 +226,9 @@ private void ResolveUserVnForVn(ListedVN vn, SQLiteTransaction transaction)
Started = dumpUserVn.Started,
Finished = dumpUserVn.Finished
};
if (Votes.ContainsKey(vn.VNID))
if (Votes.TryGetValue(vn.VNID, out var dumpvVote))
{
var vote = Votes[vn.VNID].FirstOrDefault(v => v.UserId == UserId);
var vote = dumpvVote.FirstOrDefault(v => v.UserId == UserId);
if (vote != null)
{
userVn.Vote = vote.Vote;
Expand Down Expand Up @@ -378,6 +387,7 @@ void ResolveRelease()
vn.Languages = JsonConvert.SerializeObject(languages);
vn.ProducerID = releases.SelectMany(r => r.Producers).FirstOrDefault(p => Database.Producers[p] != null);
vn.ReleaseLink = firstRelease.Website;
ResolveVnImage(vn, releases);
}
void ResolveTitle()
{
Expand All @@ -392,6 +402,33 @@ void ResolveTitle()
}
}

private void ResolveVnImage(ListedVN vn, List<Release> releases)
{
if(vn.ImageId != null ) return;
var image = releases.SelectMany(r => r.Images).OrderBy(image =>
{
return image.Type switch
{
"pkgfront" => 0,
"dig" => 1,
"pkgcontent" => 2,
"pkgmed" => 3,
"pkgback" => 4,
"pkgside" => 4,
_ => -1,
};
}).ThenBy(image =>
{
foreach (var language in image.Languages ?? Array.Empty<string>())
{
if (language == "en") return 0;
if (language == StaticHelpers.CSettings.SecondaryTitleLanguage) return 1;
}
return 2;
}).FirstOrDefault();
if (image != null) vn.ImageId = $"cv{image.Image}";
}

private void ResolveLength(ListedVN vn, List<LengthVote> lengthVotes)
{
var completeReleaseLengths = new List<int>();
Expand Down
21 changes: 21 additions & 0 deletions HappySearchObjectClasses/DumpReader/ProducerRelease.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Collections.Generic;
using System.Linq;
using Happy_Apps_Core.Database;

//Unused fields commented out to save memory
namespace Happy_Apps_Core.DumpReader;

/// <summary>
Expand All @@ -13,6 +15,7 @@ public class Release : DumpItem
public string Website { get; set; }
public List<LangRelease> Languages { get; set; }
public List<int> Producers { get; set; }
public List<ReleaseImage> Images { get; } = new List<ReleaseImage>();

public override void LoadFromStringParts(string[] parts)
{
Expand Down Expand Up @@ -50,4 +53,22 @@ public override void LoadFromStringParts(string[] parts)
public int VnId { get; set; }
public int ReleaseId { get; set; }
public string ReleaseType { get; set; }
}

public class ReleaseImage : DumpItem
{
public int ReleaseId { get; set; }
public int Image { get; set; }
public string Type { get; set; }
//public int Vid { get; set; }
public string[] Languages { get; set; }

public override void LoadFromStringParts(string[] parts)
{
ReleaseId = GetInteger(parts, "id", 1);
Image = GetInteger(parts, "img", 2);
Type = GetPart(parts, "itype");
var languagesString = GetPartOrNull(parts, "lang");
if(languagesString != null) Languages = languagesString.Trim('{','}').Split(',').ToArray();
}
}

0 comments on commit b004c98

Please sign in to comment.