@@ -17,6 +17,7 @@ namespace Benny_Scraper.BusinessLogic
17
17
{
18
18
public class NovelProcessor : INovelProcessor
19
19
{
20
+ private const string PdfFileExtension = ".pdf" ;
20
21
private static readonly ILogger Logger = LogManager . GetCurrentClassLogger ( ) ;
21
22
private readonly INovelService _novelService ;
22
23
private readonly IChapterService _chapterService ;
@@ -160,7 +161,7 @@ private async Task UpdateExistingNovelAsync(Novel novel, Uri novelTableOfContent
160
161
if ( newChapters . Any ( chapter => chapter ? . Pages != null ) )
161
162
{
162
163
if ( string . IsNullOrEmpty ( novel . SaveLocation ) )
163
- novel . SaveLocation = Path . Combine ( documentsFolder , SanitizeFileName ( novel . Title ) + ".pdf" ) ;
164
+ novel . SaveLocation = Path . Combine ( documentsFolder , SanitizeFileName ( novel . Title ) + PdfFileExtension ) ;
164
165
UpdatePdf ( novel , chapterDataBuffers ) ;
165
166
foreach ( var chapterDataBuffer in chapterDataBuffers )
166
167
{
@@ -278,7 +279,7 @@ private void CreatePdfByChapter(Novel novel, IEnumerable<ChapterDataBuffer> chap
278
279
//https://stackoverflow.com/questions/50858209/system-notsupportedexception-no-data-is-available-for-encoding-1252
279
280
280
281
var sanitizedTitle = SanitizeFileName ( $ "{ novel . Title } - { chapter . Title } ") ;
281
- var pdfFilePath = Path . Combine ( pdfDirectoryPath , $ " { sanitizedTitle } .pdf" ) ;
282
+ var pdfFilePath = Path . Combine ( pdfDirectoryPath , sanitizedTitle + PdfFileExtension ) ;
282
283
document . Save ( pdfFilePath ) ;
283
284
}
284
285
}
@@ -324,7 +325,7 @@ private void CreateSinglePdf(Novel novel, IEnumerable<ChapterDataBuffer> chapter
324
325
325
326
var sanitizedTitle = SanitizeFileName ( $ "{ novel . Title } ") ;
326
327
Logger . Info ( $ "Saving PDF to { pdfDirectoryPath } ") ;
327
- var pdfFilePath = Path . Combine ( pdfDirectoryPath , $ " { sanitizedTitle } .pdf" ) ;
328
+ var pdfFilePath = Path . Combine ( pdfDirectoryPath , sanitizedTitle + PdfFileExtension ) ;
328
329
document . Save ( pdfFilePath ) ;
329
330
Logger . Info ( $ "PDF saved to { pdfFilePath } ") ;
330
331
Console . WriteLine ( $ "PDF saved to { pdfFilePath } ") ;
@@ -333,12 +334,12 @@ private void CreateSinglePdf(Novel novel, IEnumerable<ChapterDataBuffer> chapter
333
334
private void UpdatePdf ( Novel novel , IEnumerable < ChapterDataBuffer > chapterDataBuffer )
334
335
{
335
336
var pdfFilePath = novel . SaveLocation ;
336
- if ( Path . GetExtension ( pdfFilePath ) != ".pdf" )
337
+ if ( Path . GetExtension ( pdfFilePath ) != PdfFileExtension )
337
338
throw new ArgumentException ( "The path to the pdf file is not a pdf file. " + pdfFilePath ) ;
338
339
if ( ! File . Exists ( pdfFilePath ) )
339
340
throw new ArgumentException ( "The path to the pdf file does not exist. " + pdfFilePath ) ;
340
341
341
- var tempPdfFilePath = Path . Combine ( Path . GetTempPath ( ) , Path . GetRandomFileName ( ) + ".pdf" ) ;
342
+ var tempPdfFilePath = Path . Combine ( Path . GetTempPath ( ) , Path . GetRandomFileName ( ) + PdfFileExtension ) ;
342
343
343
344
Logger . Info ( "Updating PDF file: " + pdfFilePath ) ;
344
345
using ( FileStream pdfFile = File . OpenRead ( pdfFilePath ) ) // dispose the filestream after use to avoid the error "The process cannot access the file because it is being used by another process"
0 commit comments