Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: .NET

on:
push:
branches: [ dev ]
pull_request:
branches: [ dev ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: Restore dependencies
run: dotnet restore Platforms/Anf.sln
- name: Build
run: dotnet build Platforms/Anf.sln --no-restore
- name: Test
run: dotnet test Platforms/Anf.sln --no-build --verbosity normal
2 changes: 1 addition & 1 deletion Platforms/Anf.Avalon/Anf.Avalon.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<MSIXBuild>false</MSIXBuild>
</PropertyGroup>
<PropertyGroup Condition="'$(MSIXBuild)'!='true'">
<TargetFrameworks>net472;net6.0</TargetFrameworks>
<TargetFrameworks>net472;net5.0</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition="'$(MSIXBuild)'=='true'">
<TargetFramework>net472</TargetFramework>
Expand Down
6 changes: 3 additions & 3 deletions Platforms/Anf.Avalon/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionE
private void InitServices()
{
AppEngine.Reset();
AppEngine.AddServices(NetworkAdapterTypes.WebRequest);
AppEngine.AddServices(NetworkAdapterTypes.HttpClient);
var store = FileStoreService.FromMd5Default(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, XComicConst.CacheFolderName));
var hp = new Lazy<HomePage>(() => new HomePage());
var cv = new Lazy<ComicView>(() => new ComicView());
Expand Down Expand Up @@ -90,8 +90,8 @@ public override void OnFrameworkInitializationCompleted()
var nav = AppEngine.GetRequiredService<MainNavigationService>();
var mainWin = AppEngine.GetRequiredService<MainWindow>();
desktop.MainWindow =mainWin;
nav.Navigate(new VisitingView());
//nav.Navigate<HomePage>();
//nav.Navigate(new VisitingView());
nav.Navigate<HomePage>();
AppEngine.GetRequiredService<TitleService>().Bind(mainWin);
mainWin.KeyDown += OnMainWinKeyDown;

Expand Down
55 changes: 28 additions & 27 deletions Platforms/Anf.Avalon/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,35 @@
x:Class="Anf.Avalon.MainWindow"
Title="Anf">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border Background="{x:Null}" x:Name="TitleBar" IsVisible="{Binding TitleVisible}">
<Grid>
<ContentControl Content="{Binding TitleControl}"
HorizontalAlignment="Center"
VerticalAlignment="Center">
</ContentControl>
<ItemsControl HorizontalAlignment="Left" Items="{Binding LeftControls}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>
</Border>
<!-- Margin="{Binding #MainWindow.OffScreenMargin}"-->
<Panel Name="MainPlan" Margin="{Binding #MainWindow.OffScreenMargin}" Grid.Row="1">
</Panel>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border Background="{x:Null}" x:Name="TitleBar" IsVisible="{Binding TitleVisible}">
<Grid>
<ContentControl Content="{Binding TitleControl}"
HorizontalAlignment="Center"
VerticalAlignment="Center">
</ContentControl>
<ItemsControl HorizontalAlignment="Left" Items="{Binding LeftControls}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>
</Border>
<!-- Margin="{Binding #MainWindow.OffScreenMargin}"-->
<Panel Name="MainPlan" Margin="{Binding #MainWindow.OffScreenMargin}" Grid.Row="1">
</Panel>
</Grid>
<Border x:Name="ExcetionBorder"
IsVisible="{Binding HasException}"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Padding="16">
IsVisible="{Binding HasException}"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Padding="16">
<Border.ContextMenu>
<ContextMenu>
<MenuItem Command="{Binding CopyExceptionCommand}" Header="Copy"/>
Expand Down Expand Up @@ -65,6 +67,5 @@
</Border>
</Grid>
</Border>

</Grid>
</Window>
5 changes: 5 additions & 0 deletions Platforms/Anf.Avalon/ViewModels/AvalonVisitingViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,5 +211,10 @@ protected async override void OnCurrentChaterCursorChanged(IDataCursor<IComicCha
ExceptionService.Exception = ex;
}
}
public override void Dispose()
{
base.Dispose();
TitleService.Title = string.Empty;
}
}
}
1 change: 1 addition & 0 deletions Platforms/Anf.Avalon/Views/VisitingView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs
{
base.OnDetachedFromLogicalTree(e);
titleService.LeftControls.Remove(vc);
vm.Dispose();
}
private void InitializeComponent()
{
Expand Down
4 changes: 2 additions & 2 deletions Platforms/Anf.Engine.Easy/Anf.Easy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
<ProjectReference Include="..\Anf.Engine\Anf.Engine.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'net461'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0"/>
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="2.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net45' or '$(TargetFramework)' == 'netstandard1.4'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="1.4.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.4'">
Expand Down
2 changes: 1 addition & 1 deletion Platforms/Anf.Web/Anf.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<MiniService>false</MiniService>
Expand Down
4 changes: 4 additions & 0 deletions Platforms/Engines/Anf.KnowEngines/BilibiliComicOperator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Anf.Networks;
using HtmlAgilityPack;
using JavaScriptEngineSwitcher.Core;
using Jint.Native.Array;
#if !NETSTANDARD1_3
using Microsoft.IO;
#endif
Expand All @@ -9,6 +12,7 @@
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Anf.KnowEngines
Expand Down
4 changes: 4 additions & 0 deletions Platforms/Engines/Anf.KnowEngines/KnowEnginesExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public static void AddKnowEngines(this IServiceCollection services)
services.AddScoped<TencentComicOperator>();
services.AddScoped<BilibiliComicOperator>();
services.AddScoped<QimiaoComicOperator>();
services.AddScoped<MangabzComicOperator>();
services.AddScoped<XmanhuaComicOperator>();
}
public static void UseKnowEngines(this IServiceProvider provider)
{
Expand All @@ -29,6 +31,8 @@ public static void UseKnowEngines(this IServiceProvider provider)
eng.Add(new TencentComicSourceCondition());
eng.Add(new BilibiliComicSourceCondition());
eng.Add(new QimianComicSourceCondition());
eng.Add(new MangabzComicCondition());
eng.Add(new XmanhuaComicCondition());
var searchEng = provider.GetRequiredService<SearchEngine>();
searchEng.Add(typeof(SomanSearchProvider));
}
Expand Down
16 changes: 16 additions & 0 deletions Platforms/Engines/Anf.KnowEngines/MangabzComicCondition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace Anf.KnowEngines
{
public class MangabzComicCondition : ComicSourceConditionBase<MangabzComicOperator>
{
public override string EnginName => "Mangabz";

public override Uri Address { get; } = new Uri("http://www.mangabz.com/");

public override bool Condition(ComicSourceContext context)
{
return context.Uri.Host == Address.Host;
}
}
}
164 changes: 164 additions & 0 deletions Platforms/Engines/Anf.KnowEngines/MangabzComicOperator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
using Anf.Networks;
using HtmlAgilityPack;
using JavaScriptEngineSwitcher.Core;
using Jint.Native.Array;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Anf.KnowEngines
{
public class MangabzComicOperator : IComicSourceProvider
{
private static readonly Regex cidRegex = new Regex(@"var MANGABZ_CID=(.*)?;", RegexOptions.Compiled);
private static readonly Regex dtRegex = new Regex(@"var MANGABZ_VIEWSIGN_DT=""(.*)?"";", RegexOptions.Compiled);
private static readonly Regex midRegex = new Regex(@"var MANGABZ_MID=(.*)?;", RegexOptions.Compiled);
private static readonly Regex viewSignRegex = new Regex(@"var MANGABZ_VIEWSIGN=(.*)?;", RegexOptions.Compiled);
private static readonly Regex imageCountRegex = new Regex(@"var MANGABZ_IMAGE_COUNT=(.*)?;", RegexOptions.Compiled);

private readonly INetworkAdapter networkAdapter;
private readonly IJsEngine jsEngine;
private static readonly Dictionary<string, string> headers = new Dictionary<string, string>
{
["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4437.0 Safari/537.36 Edg/91.0.831.1",
};

public MangabzComicOperator(INetworkAdapter networkAdapter, IJsEngine jsEngine)
{
this.networkAdapter = networkAdapter;
this.jsEngine = jsEngine;
}

protected virtual Task<Stream> GetStreamAsync(string address)
{
return networkAdapter.GetStreamAsync(new RequestSettings
{
Address = address,
Host = new Uri(address).Host,
Referrer = GetBaseAddress(),
Headers = headers
});
}
protected virtual string GetBaseAddress()
{
return "http://www.mangabz.com/";
}
public async Task<ComicEntity> GetChaptersAsync(string targetUrl)
{
var str = string.Empty;
using (var sr = new StreamReader(await GetStreamAsync(targetUrl)))
{
str = sr.ReadToEnd();
}
var html = new HtmlDocument();
html.LoadHtml(str);
var img = html.DocumentNode.SelectSingleNode("//div[@class='detail-info']/img[@class='detail-info-cover']");
var title = html.DocumentNode.SelectSingleNode("//div[@class='detail-info']/p[@class='detail-info-title']");
var desc = html.DocumentNode.SelectSingleNode("//div[@class='detail-info']/div[@class='detail-info-content']");

var chpsBox = html.DocumentNode.SelectNodes("//div[@id='chapterlistload']/a");
var chps = new List<ComicChapter>();
foreach (var item in chpsBox)
{
var name = item.InnerText.Replace(" ", string.Empty);
var addr = item.Attributes["href"].Value;
var chp = new ComicChapter
{
Title = name,
TargetUrl = "http://www.mangabz.com" + addr
};
chps.Add(chp);
}
var entity = new ComicEntity
{
ComicUrl = targetUrl,
Descript = desc?.InnerText,
ImageUrl = img?.Attributes["src"].Value,
Name = title?.InnerText,
Chapters = chps.ToArray()
};
return entity;
}

public Task<Stream> GetImageStreamAsync(string targetUrl)
{
return GetStreamAsync(targetUrl);
}

public async Task<ComicPage[]> GetPagesAsync(string targetUrl)
{
var str = string.Empty;
using (var sr = new StreamReader(await GetStreamAsync(targetUrl)))
{
str = sr.ReadToEnd();
}
var cidRgx = cidRegex.Match(str).Groups[0].Value;
var dtRgx = dtRegex.Match(str).Groups[0].Value;
var midRgx = midRegex.Match(str).Groups[0].Value;
var viewSignRgx = viewSignRegex.Match(str).Groups[0].Value;
var imgCountRgx = imageCountRegex.Match(str).Groups[0].Value;

var cid = cidRgx.Substring(0, cidRgx.IndexOf(';')).Split('=').Last();
var dt = dtRgx.Substring(0, dtRgx.IndexOf(';')).Split('=').Last().Trim('\"');
var mid = midRgx.Substring(0, midRgx.IndexOf(';')).Split('=').Last();
var viewSign = viewSignRgx.Substring(0, viewSignRgx.IndexOf(';')).Split('=').Last().Trim('\"');
var imgCount = imgCountRgx.Substring(0, imgCountRgx.IndexOf(';')).Split('=').Last().Trim('\"');
var val = int.Parse(imgCount);

var refAddr = new Uri(targetUrl).Segments.Last();

var part = $"{GetBaseAddress()}/{refAddr}/chapterimage.ashx?cid={cid}&page={{0}}&key=&_cid={cid}&_mid={mid}&_dt={DateTime.Now}&_sign={viewSign}";

async Task<ComicPage[]> RunBlockAsync(int index)
{
var pgs = new List<ComicPage>();
var partBlock = string.Format(part, index + 1);

string partEncod = null;
using (var sr = new StreamReader(await GetStreamAsync(partBlock)))
{
partEncod = sr.ReadToEnd();
}
if (!string.IsNullOrEmpty(partEncod))
{
var ret = (ArrayInstance)jsEngine.Evaluate(partEncod);
var length = ret.GetLength();
for (int i = 0; i < length; i++)
{
pgs.Add(new ComicPage
{
Name = (index + 1).ToString(),
TargetUrl = ret.GetProperty(i.ToString()).Value.ToString()
});
}
}
return pgs.ToArray();
}
var datas = new List<ComicPage[]>();
for (int i = 0; i < val; i++)
{
var j = i;
datas.Add(await RunBlockAsync(j));
}
var containPages = new HashSet<string>();
var pages = new List<ComicPage>(datas.Count);
for (int i = 0; i < datas.Count; i++)
{
var res = datas[i];
for (int q = 0; q < res.Length; q++)
{
var r = res[q];
if (containPages.Add(r.TargetUrl))
{
pages.Add(r);
}
}
}
return pages.ToArray();
}
}
}
16 changes: 16 additions & 0 deletions Platforms/Engines/Anf.KnowEngines/XmanhuaComicCondition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace Anf.KnowEngines
{
public class XmanhuaComicCondition : ComicSourceConditionBase<MangabzComicOperator>
{
public override string EnginName => "Xmanhua";

public override Uri Address { get; } = new Uri("http://www.xmanhua.com/");

public override bool Condition(ComicSourceContext context)
{
return context.Uri.Host == Address.Host;
}
}
}
Loading