1 /* 2 * This file is part of nzbget. See <http://nzbget.net>. 3 * 4 * Copyright (C) 2017 Andrey Prygunkov <hugbug@users.sourceforge.net> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 21 #ifndef DIRECTRENAMER_H 22 #define DIRECTRENAMER_H 23 24 #include "ArticleDownloader.h" 25 26 class DirectRenamer 27 { 28 public: 29 class FileHash 30 { 31 public: FileHash(const char * filename,const char * hash)32 FileHash(const char* filename, const char* hash) : 33 m_filename(filename), m_hash(hash) {} GetFilename()34 const char* GetFilename() { return m_filename; } GetHash()35 const char* GetHash() { return m_hash; } 36 37 private: 38 CString m_filename; 39 CString m_hash; 40 }; 41 42 typedef std::deque<FileHash> FileHashList; 43 44 class ParFile 45 { 46 public: ParFile(int id,const char * filename,const char * setId,bool completed)47 ParFile(int id, const char* filename, const char* setId, bool completed) : 48 m_id(id), m_filename(filename), m_setId(setId), m_completed(completed) {} GetId()49 int GetId() { return m_id; } GetFilename()50 const char* GetFilename() { return m_filename; } GetSetId()51 const char* GetSetId() { return m_setId; } GetCompleted()52 bool GetCompleted() { return m_completed; } 53 54 private: 55 int m_id; 56 CString m_filename; 57 CString m_setId; 58 bool m_completed = false; 59 }; 60 61 typedef std::deque<ParFile> ParFileList; 62 63 std::unique_ptr<ArticleContentAnalyzer> MakeArticleContentAnalyzer(); 64 void ArticleDownloaded(DownloadQueue* downloadQueue, FileInfo* fileInfo, 65 ArticleInfo* articleInfo, ArticleContentAnalyzer* articleContentAnalyzer); 66 void FileDownloaded(DownloadQueue* downloadQueue, FileInfo* fileInfo); 67 68 protected: 69 virtual void RenameCompleted(DownloadQueue* downloadQueue, NzbInfo* nzbInfo) = 0; 70 71 private: 72 void CheckState(DownloadQueue* downloadQueue, NzbInfo* nzbInfo); 73 void UnpausePars(NzbInfo* nzbInfo); 74 void RenameFiles(DownloadQueue* downloadQueue, NzbInfo* nzbInfo, FileHashList* parHashes); 75 bool RenameCompletedFile(NzbInfo* nzbInfo, const char* oldName, const char* newName); 76 bool NeedRenamePars(NzbInfo* nzbInfo); 77 void CollectPars(NzbInfo* nzbInfo, ParFileList* parFiles); 78 CString BuildNewRegularName(const char* oldName, FileHashList* parHashes, const char* hash16k); 79 CString BuildNewParName(const char* oldName, const char* destDir, const char* setId, int& vol); 80 81 friend class DirectParLoader; 82 }; 83 84 #endif 85