Bookmark and Reader bugs (#1632)
* Updated swiper and some packages for reported security issues * Fixed reading lists promotion not working * Refactor RenameFileForCopy to use iterative recursion, rather than functional. * Ensured that bookmarks are fetched and ordered by Created date. * Fixed a bug where bookmarks were coming back in the correct order, but due to filenames, would not sort correctly. * Default installs to Debug log level given errors users have and Debug not being too noisy * Added jumpbar to bookmarks page * Now added jumpbar to bookmarks * Refactored some code into pipes and added some debug messaging for prefetcher * Try loading next and prev chapter's first/last page to cache so it renders faster * Updated GetImage to do a bound check on max page. Fixed a critical bug in how manga reader updates image elements src to prefetch/load pages. I was not creating a new reference which broke Angular's ability to update DOM on changes. * Refactored the image setting code to use a single method which tries to use a cached image always. * Refactored code to use getPage which favors cache and simplifies image creation code
This commit is contained in:
parent
dab42041d5
commit
38a169818b
25 changed files with 317 additions and 166 deletions
|
|
@ -37,6 +37,7 @@ public interface IDirectoryService
|
|||
IEnumerable<DirectoryDto> ListDirectory(string rootPath);
|
||||
Task<byte[]> ReadFileAsync(string path);
|
||||
bool CopyFilesToDirectory(IEnumerable<string> filePaths, string directoryPath, string prepend = "");
|
||||
bool CopyFilesToDirectory(IEnumerable<string> filePaths, string directoryPath, IList<string> newFilenames);
|
||||
bool Exists(string directory);
|
||||
void CopyFileToDirectory(string fullFilePath, string targetDirectory);
|
||||
int TraverseTreeParallelForEach(string root, Action<string> action, string searchPattern, ILogger logger);
|
||||
|
|
@ -424,6 +425,46 @@ public class DirectoryService : IDirectoryService
|
|||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies files to a destination directory. If the destination directory doesn't exist, this will create it.
|
||||
/// </summary>
|
||||
/// <remarks>If a file already exists in dest, this will rename as (2). It does not support multiple iterations of this. Overwriting is not supported.</remarks>
|
||||
/// <param name="filePaths"></param>
|
||||
/// <param name="directoryPath"></param>
|
||||
/// <param name="newFilenames">A list that matches one to one with filePaths. Each filepath will be renamed to newFilenames</param>
|
||||
/// <returns></returns>
|
||||
public bool CopyFilesToDirectory(IEnumerable<string> filePaths, string directoryPath, IList<string> newFilenames)
|
||||
{
|
||||
ExistOrCreate(directoryPath);
|
||||
string currentFile = null;
|
||||
var index = 0;
|
||||
try
|
||||
{
|
||||
foreach (var file in filePaths)
|
||||
{
|
||||
currentFile = file;
|
||||
|
||||
if (!FileSystem.File.Exists(file))
|
||||
{
|
||||
_logger.LogError("Unable to copy {File} to {DirectoryPath} as it doesn't exist", file, directoryPath);
|
||||
continue;
|
||||
}
|
||||
var fileInfo = FileSystem.FileInfo.FromFileName(file);
|
||||
var targetFile = FileSystem.FileInfo.FromFileName(RenameFileForCopy(newFilenames[index] + fileInfo.Extension, directoryPath));
|
||||
|
||||
fileInfo.CopyTo(FileSystem.Path.Join(directoryPath, targetFile.Name));
|
||||
index++;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Unable to copy {File} to {DirectoryPath}", currentFile, directoryPath);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates the combined filepath given a prepend (optional), output directory path, and a full input file path.
|
||||
/// If the output file already exists, will append (1), (2), etc until it can be written out
|
||||
|
|
@ -434,30 +475,32 @@ public class DirectoryService : IDirectoryService
|
|||
/// <returns></returns>
|
||||
private string RenameFileForCopy(string fileToCopy, string directoryPath, string prepend = "")
|
||||
{
|
||||
var fileInfo = FileSystem.FileInfo.FromFileName(fileToCopy);
|
||||
var filename = prepend + fileInfo.Name;
|
||||
|
||||
var targetFile = FileSystem.FileInfo.FromFileName(FileSystem.Path.Join(directoryPath, filename));
|
||||
if (!targetFile.Exists)
|
||||
while (true)
|
||||
{
|
||||
return targetFile.FullName;
|
||||
}
|
||||
var fileInfo = FileSystem.FileInfo.FromFileName(fileToCopy);
|
||||
var filename = prepend + fileInfo.Name;
|
||||
|
||||
var noExtension = FileSystem.Path.GetFileNameWithoutExtension(fileInfo.Name);
|
||||
if (FileCopyAppend.IsMatch(noExtension))
|
||||
{
|
||||
var match = FileCopyAppend.Match(noExtension).Value;
|
||||
var matchNumber = match.Replace("(", string.Empty).Replace(")", string.Empty);
|
||||
noExtension = noExtension.Replace(match, $"({int.Parse(matchNumber) + 1})");
|
||||
}
|
||||
else
|
||||
{
|
||||
noExtension += " (1)";
|
||||
}
|
||||
var targetFile = FileSystem.FileInfo.FromFileName(FileSystem.Path.Join(directoryPath, filename));
|
||||
if (!targetFile.Exists)
|
||||
{
|
||||
return targetFile.FullName;
|
||||
}
|
||||
|
||||
var newFilename = prepend + noExtension +
|
||||
FileSystem.Path.GetExtension(fileInfo.Name);
|
||||
return RenameFileForCopy(FileSystem.Path.Join(directoryPath, newFilename), directoryPath, prepend);
|
||||
var noExtension = FileSystem.Path.GetFileNameWithoutExtension(fileInfo.Name);
|
||||
if (FileCopyAppend.IsMatch(noExtension))
|
||||
{
|
||||
var match = FileCopyAppend.Match(noExtension).Value;
|
||||
var matchNumber = match.Replace("(", string.Empty).Replace(")", string.Empty);
|
||||
noExtension = noExtension.Replace(match, $"({int.Parse(matchNumber) + 1})");
|
||||
}
|
||||
else
|
||||
{
|
||||
noExtension += " (1)";
|
||||
}
|
||||
|
||||
var newFilename = prepend + noExtension + FileSystem.Path.GetExtension(fileInfo.Name);
|
||||
fileToCopy = FileSystem.Path.Join(directoryPath, newFilename);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue