Skip to content

Commit

Permalink
xslt update
Browse files Browse the repository at this point in the history
  • Loading branch information
libgenapps committed May 23, 2018
1 parent 528748a commit 37ba310
Show file tree
Hide file tree
Showing 17 changed files with 342 additions and 74 deletions.
3 changes: 2 additions & 1 deletion LibgenDesktop.Setup/AppFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ static AppFiles()
AddFile(@"Mirrors\bookfi_net.xslt");
AddFile(@"Mirrors\b_ok_xyz_step1.xslt");
AddFile(@"Mirrors\b_ok_xyz_step2.xslt");
AddFile(@"Mirrors\booksc_org.xslt");
AddFile(@"Mirrors\booksc_org_step1.xslt");
AddFile(@"Mirrors\booksc_org_step2.xslt");
}

public static string GetBinariesDirectoryPath(bool is64Bit)
Expand Down
4 changes: 2 additions & 2 deletions LibgenDesktop.Setup/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{
internal static class Constants
{
public const string CURRENT_VERSION = "1.1.3";
public const string TITLE_VERSION = "1.1.3";
public const string CURRENT_VERSION = "1.1.4";
public const string TITLE_VERSION = "1.1.4";
public const string PRODUCT_TITLE_FORMAT = "Libgen Desktop " + TITLE_VERSION + " ({0}-bit)";
public const string SHORTCUT_TITLE_FORMAT = "Libgen Desktop ({0}-bit)";
public const string PRODUCT_COMPANY = "Libgen Apps";
Expand Down
6 changes: 3 additions & 3 deletions LibgenDesktop/Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ namespace LibgenDesktop.Common
{
internal static class Constants
{
public const string CURRENT_VERSION = "1.1.3";
public const string CURRENT_GITHUB_RELEASE_NAME = "1.1.3";
public static readonly DateTime CURRENT_GITHUB_RELEASE_DATE = new DateTime(2018, 5, 22);
public const string CURRENT_VERSION = "1.1.4";
public const string CURRENT_GITHUB_RELEASE_NAME = "1.1.4";
public static readonly DateTime CURRENT_GITHUB_RELEASE_DATE = new DateTime(2018, 5, 23);
public const string CURRENT_DATABASE_VERSION = "1.0";

public const string APP_SETTINGS_FILE_NAME = "libgen.config";
Expand Down
9 changes: 7 additions & 2 deletions LibgenDesktop/LibgenDesktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@
<Compile Include="ViewModels\DetailsItems\FictionDetailsItemViewModel.cs" />
<Compile Include="ViewModels\DetailsItems\NonFictionDetailsItemViewModel.cs" />
<Compile Include="ViewModels\DetailsItems\SciMagDetailsItemViewModel.cs" />
<Compile Include="ViewModels\Library\ScanResultItemViewModel.cs" />
<Compile Include="ViewModels\SearchResultItems\SciMagSearchResultItemViewModel.cs" />
<Compile Include="ViewModels\SearchResultItems\FictionSearchResultItemViewModel.cs" />
<Compile Include="ViewModels\SearchResultItems\NonFictionSearchResultItemViewModel.cs" />
Expand Down Expand Up @@ -701,9 +702,13 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>Mirrors\b_ok_xyz_step2.xslt</TargetPath>
</ContentWithTargetPath>
<ContentWithTargetPath Include="Resources\Mirrors\booksc_org.xslt">
<ContentWithTargetPath Include="Resources\Mirrors\booksc_org_step1.xslt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>Mirrors\booksc_org.xslt</TargetPath>
<TargetPath>Mirrors\booksc_org_step1.xslt</TargetPath>
</ContentWithTargetPath>
<ContentWithTargetPath Include="Resources\Mirrors\booksc_org_step2.xslt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>Mirrors\booksc_org_step2.xslt</TargetPath>
</ContentWithTargetPath>
<ContentWithTargetPath Include="Resources\Languages\Russian.lng">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,38 @@ public LibraryWindowLocalizator(List<Translation> prioritizedTranslationList, La
Scan = Format(translation => translation?.Scan);
BrowseDirectoryDialogTitle = Format(translation => translation?.BrowseDirectoryDialogTitle);
CreatingIndexes = Format(translation => translation?.CreatingIndexes);
NotFound = Format(translation => translation?.NotFound);
ScanLog = Format(translation => translation?.ScanLog);
Error = Format(translation => translation?.Error);
ColumnsFile = Format(translation => translation?.File);
ColumnsAuthors = Format(translation => translation?.Authors);
ColumnsTitle = Format(translation => translation?.Title);
}

public string WindowTitle { get; }
public string Scan { get; }
public string BrowseDirectoryDialogTitle { get; }
public string CreatingIndexes { get; }
public string NotFound { get; }
public string ScanLog { get; }
public string Error { get; }
public string ColumnsFile { get; }
public string ColumnsAuthors { get; }
public string ColumnsTitle { get; }

public string GetScanStartedString(string directory) => Format(translation => translation?.ScanStarted, new { directory });
public string GetScanCompleteString(int found, int notFound) => Format(translation => translation?.ScanComplete,
new { found = Formatter.ToFormattedString(found), notFound = Formatter.ToFormattedString(notFound) });
public string GetFoundString(int count) => Format(translation => translation?.Found, new { count });
public string GetNotFoundString(int count) => Format(translation => translation?.NotFound, new { count });
public string GetScanCompleteString(int found, int notFound, int errors) => Format(translation => translation?.ScanComplete,
new { found = Formatter.ToFormattedString(found), notFound = Formatter.ToFormattedString(notFound),
errors = Formatter.ToFormattedString(errors) });

private string Format(Func<Translation.LibraryTranslation, string> field, object templateArguments = null)
{
return Format(translation => field(translation?.Library), templateArguments);
}

private string Format(Func<Translation.LibraryColumnsTranslation, string> field, object templateArguments = null)
{
return Format(translation => field(translation?.Library?.Columns), templateArguments);
}
}
}
11 changes: 11 additions & 0 deletions LibgenDesktop/Models/Localization/Translation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -544,15 +544,26 @@ internal class SynchronizationTranslation
public SynchronizationLogMessagesTranslation LogMessages { get; set; }
}

internal class LibraryColumnsTranslation
{
public string File { get; set; }
public string Authors { get; set; }
public string Title { get; set; }
}

internal class LibraryTranslation
{
public string WindowTitle { get; set; }
public string Scan { get; set; }
public string BrowseDirectoryDialogTitle { get; set; }
public string ScanStarted { get; set; }
public string CreatingIndexes { get; set; }
public string Found { get; set; }
public string NotFound { get; set; }
public string ScanLog { get; set; }
public string Error { get; set; }
public string ScanComplete { get; set; }
public LibraryColumnsTranslation Columns { get; set; }
}

internal class DatabaseTranslation
Expand Down
90 changes: 57 additions & 33 deletions LibgenDesktop/Models/MainModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ public Task ScanAsync(string scanDirectory, IProgress<object> progressHandler)
{
int found = 0;
int notFound = 0;
int errors = 0;
if (NonFictionBookCount > 0)
{
Logger.Debug("Retrieving the list of non-fiction table indexes.");
Expand All @@ -499,9 +500,9 @@ public Task ScanAsync(string scanDirectory, IProgress<object> progressHandler)
progressHandler.Report(new GenericProgress(GenericProgress.Event.SCAN_CREATING_INDEXES));
localDatabase.CreateNonFictionMd5HashIndex();
}
ScanDirectory(scanDirectory.ToLower(), scanDirectory, progressHandler, ref found, ref notFound);
ScanDirectory(scanDirectory.ToLower(), scanDirectory, progressHandler, ref found, ref notFound, ref errors);
}
progressHandler.Report(new ScanCompleteProgress(found, notFound));
progressHandler.Report(new ScanCompleteProgress(found, notFound, errors));
});
}

Expand Down Expand Up @@ -909,50 +910,73 @@ private TableType DetectImportTableType(SqlDumpReader.ParsedTableDefinition pars
return TableType.UNKNOWN;
}

private void ScanDirectory(string rootScanDirectory, string scanDirectory, IProgress<object> progressHandler, ref int found, ref int notFound)
private void ScanDirectory(string rootScanDirectory, string scanDirectory, IProgress<object> progressHandler, ref int found, ref int notFound,
ref int errors)
{
foreach (string filePath in Directory.EnumerateFiles(scanDirectory))
try
{
string md5Hash;
try
foreach (string filePath in Directory.EnumerateFiles(scanDirectory))
{
using (MD5 md5 = MD5.Create())
using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
string relativeFilePath = filePath;
if (relativeFilePath.ToLower().StartsWith(rootScanDirectory))
{
byte[] md5HashArray = md5.ComputeHash(fileStream);
md5Hash = BitConverter.ToString(md5HashArray).Replace("-", String.Empty).ToLowerInvariant();
relativeFilePath = relativeFilePath.Substring(rootScanDirectory.Length + 1);
}
string md5Hash;
try
{
using (MD5 md5 = MD5.Create())
using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
byte[] md5HashArray = md5.ComputeHash(fileStream);
md5Hash = BitConverter.ToString(md5HashArray).Replace("-", String.Empty).ToLowerInvariant();
}
}
catch (Exception exception)
{
Logger.Debug($"Couldn't calculate MD5 hash for the file: {filePath}");
Logger.Exception(exception);
progressHandler.Report(new ScanProgress(relativeFilePath, error: true));
errors++;
continue;
}
try
{
NonFictionBook book = localDatabase.GetNonFictionBookByMd5Hash(md5Hash);
if (book != null)
{
progressHandler.Report(new ScanProgress(relativeFilePath, book.Authors, book.Title));
found++;
}
else
{
progressHandler.Report(new ScanProgress(relativeFilePath));
notFound++;
}
}
catch (Exception exception)
{
Logger.Debug($"Couldn't lookup the MD5 hash: {md5Hash} in the database for the file: {filePath}");
Logger.Exception(exception);
progressHandler.Report(new ScanProgress(relativeFilePath, error: true));
errors++;
continue;
}
}
catch (Exception exception)
{
Logger.Debug($"Couldn't calculate MD5 hash for the file: {filePath}");
Logger.Exception(exception);
continue;
}
string relativeFilePath = filePath;
if (relativeFilePath.ToLower().StartsWith(rootScanDirectory))
{
relativeFilePath = relativeFilePath.Substring(rootScanDirectory.Length + 1);
}
NonFictionBook book = localDatabase.GetNonFictionBookByMd5Hash(md5Hash);
if (book != null)
{
progressHandler.Report(new ScanProgress(relativeFilePath, book.Authors, book.Title));
found++;
}
else
foreach (string directoryPath in Directory.EnumerateDirectories(scanDirectory))
{
progressHandler.Report(new ScanProgress(relativeFilePath));
notFound++;
ScanDirectory(rootScanDirectory, directoryPath, progressHandler, ref found, ref notFound, ref errors);
}
}
foreach (string directoryPath in Directory.EnumerateDirectories(scanDirectory))
catch (Exception exception)
{
ScanDirectory(rootScanDirectory, directoryPath, progressHandler, ref found, ref notFound);
Logger.Exception(exception);
progressHandler.Report(new ScanProgress(scanDirectory, error: true));
errors++;
}
}

private void CheckAndCreateNonFictionIndexes(IProgress<object> progressHandler, CancellationToken cancellationToken)
private void CheckAndCreateNonFictionIndexes(IProgress<object> progressHandler, CancellationToken cancellationToken)
{
Logger.Debug("Retrieving the list of non-fiction table indexes.");
List<string> nonFictionIndexes = localDatabase.GetNonFictionIndexList();
Expand Down
4 changes: 3 additions & 1 deletion LibgenDesktop/Models/ProgressArgs/ScanCompleteProgress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
{
internal class ScanCompleteProgress
{
public ScanCompleteProgress(int found, int notFound)
public ScanCompleteProgress(int found, int notFound, int errors)
{
Found = found;
NotFound = notFound;
Errors = errors;
}

public int Found { get; }
public int NotFound { get; }
public int Errors { get; }
}
}
5 changes: 4 additions & 1 deletion LibgenDesktop/Models/ProgressArgs/ScanProgress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
{
internal class ScanProgress
{
public ScanProgress(string relativeFilePath)
public ScanProgress(string relativeFilePath, bool error = false)
{
RelativeFilePath = relativeFilePath;
Found = false;
Error = error;
Authors = null;
Title = null;
}
Expand All @@ -14,12 +15,14 @@ public ScanProgress(string relativeFilePath, string authors, string title)
{
RelativeFilePath = relativeFilePath;
Found = true;
Error = false;
Authors = authors;
Title = title;
}

public string RelativeFilePath { get; }
public bool Found { get; }
public bool Error { get; }
public string Authors { get; }
public string Title { get; }
}
Expand Down
13 changes: 11 additions & 2 deletions LibgenDesktop/Resources/Languages/English.lng
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,17 @@
"BrowseDirectoryDialogTitle": "Scan for non-fiction books in...",
"ScanStarted": "Scan started in {directory}",
"CreatingIndexes": "Please wait. Creating missing database indexes...",
"NotFound": "not found",
"ScanComplete": "Scan complete: found {found}, not found {notFound}."
"Found": "Found ({count})",
"NotFound": "Not found ({count})",
"ScanLog": "Scan log",
"Error": "error",
"ScanComplete": "Scan complete. Found: {found}, not found: {notFound}, errors: {errors}.",
"Columns":
{
"File": "File",
"Authors": "Authors",
"Title": "Title"
}
},
"Database":
{
Expand Down
13 changes: 11 additions & 2 deletions LibgenDesktop/Resources/Languages/Russian.lng
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,17 @@
"BrowseDirectoryDialogTitle": "Искать известные книги в...",
"ScanStarted": "Начато сканирование в {directory}",
"CreatingIndexes": "Идет создание отсутствующих индексов. Пожалуйста, подождите...",
"NotFound": "не найдено",
"ScanComplete": "Сканирование завершено: найдено {found}, не найдено {notFound}."
"Found": "Найдено ({count})",
"NotFound": "Не найдено ({count})",
"ScanLog": "Журнал сканирования",
"Error": "ошибка",
"ScanComplete": "Сканирование завершено. Найдено: {found}, не найдено: {notFound}, ошибок: {errors}.",
"Columns":
{
"File": "Файл",
"Authors": "Авторы",
"Title": "Наименование"
}
},
"Database":
{
Expand Down
9 changes: 9 additions & 0 deletions LibgenDesktop/Resources/Mirrors/booksc_org_step1.xslt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="(//a[starts-with(@href, '/book/')])[1]">
<xsl:text>http://booksc.org</xsl:text>
<xsl:value-of select="@href" />
</xsl:for-each>
</xsl:template>
</xsl:transform>
9 changes: 9 additions & 0 deletions LibgenDesktop/Resources/Mirrors/booksc_org_step2.xslt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="(//a[starts-with(@href, '/dl/')])[1]">
<xsl:text>http://booksc.org</xsl:text>
<xsl:value-of select="@href" />
</xsl:for-each>
</xsl:template>
</xsl:transform>
4 changes: 2 additions & 2 deletions LibgenDesktop/Resources/Mirrors/mirrors.config
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
},
"booksc.org":
{
"SciMagDownloadUrl": "http://booksc.org/s/?q={doi}&t=0",
"SciMagDownloadTransformations": "booksc_org"
"SciMagDownloadUrl": "http://booksc.org/s/?q={md5}&t=0",
"SciMagDownloadTransformations": "booksc_org_step1,booksc_org_step2"
},
"GenoType (TOR)":
{
Expand Down
25 changes: 25 additions & 0 deletions LibgenDesktop/ViewModels/Library/ScanResultItemViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using LibgenDesktop.Models.Entities;

namespace LibgenDesktop.ViewModels.Library
{
internal class ScanResultItemViewModel : ViewModel
{
public ScanResultItemViewModel(LibgenObjectType libgenObjectType, int libgenObjectId, string fullFilePath, string relativeFilePath, string authors,
string title)
{
LibgenObjectType = libgenObjectType;
LibgenObjectId = libgenObjectId;
FullFilePath = fullFilePath;
RelativeFilePath = relativeFilePath;
Authors = authors;
Title = title;
}

public LibgenObjectType LibgenObjectType { get; }
public int LibgenObjectId { get; }
public string FullFilePath { get; }
public string RelativeFilePath { get; }
public string Authors { get; }
public string Title { get; }
}
}
Loading

0 comments on commit 37ba310

Please sign in to comment.