~ubuntu-branches/debian/experimental/nzbget/experimental

« back to all changes in this revision

Viewing changes to daemon/postprocess/ParChecker.h

  • Committer: Package Import Robot
  • Author(s): Andreas Moog
  • Date: 2014-12-25 12:58:06 UTC
  • mfrom: (1.2.1) (3.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20141225125806-vnzgajhm7mju9933
Tags: 14.1+dfsg-1
* New Upstream release (Closes: #768863)
* debian/patches:
  - Remove 0010_unnecessary_gcryptdep.patch, included upstream
  - Refresh remaining patches
* debian/control:
  - Remove no longer needed build-depends on libpar2-dev and libsigc++-dev
* debian/nzbget.conf
  - Update sample configuration file to include new options introduced by
    new upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  This file is part of nzbget
 
3
 *
 
4
 *  Copyright (C) 2007-2014 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, write to the Free Software
 
18
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
19
 *
 
20
 * $Revision: 1139 $
 
21
 * $Date: 2014-10-09 23:11:42 +0200 (Thu, 09 Oct 2014) $
 
22
 *
 
23
 */
 
24
 
 
25
 
 
26
#ifndef PARCHECKER_H
 
27
#define PARCHECKER_H
 
28
 
 
29
#ifndef DISABLE_PARCHECK
 
30
 
 
31
#include <deque>
 
32
#include <vector>
 
33
#include <string>
 
34
 
 
35
#include "Thread.h"
 
36
#include "Log.h"
 
37
 
 
38
class ParChecker : public Thread
 
39
{
 
40
public:
 
41
        enum EStatus
 
42
        {
 
43
                psFailed,
 
44
                psRepairPossible,
 
45
                psRepaired,
 
46
                psRepairNotNeeded
 
47
        };
 
48
 
 
49
        enum EStage
 
50
        {
 
51
                ptLoadingPars,
 
52
                ptVerifyingSources,
 
53
                ptRepairing,
 
54
                ptVerifyingRepaired,
 
55
        };
 
56
 
 
57
        enum EFileStatus
 
58
        {
 
59
                fsUnknown,
 
60
                fsSuccess,
 
61
                fsPartial,
 
62
                fsFailure
 
63
        };
 
64
 
 
65
        class Segment
 
66
        {
 
67
        private:
 
68
                bool                            m_bSuccess;
 
69
                long long                       m_iOffset;
 
70
                int                                     m_iSize;
 
71
                unsigned long           m_lCrc;
 
72
 
 
73
        public:
 
74
                                                        Segment(bool bSuccess, long long iOffset, int iSize, unsigned long lCrc);
 
75
                bool                            GetSuccess() { return m_bSuccess; }
 
76
                long long                       GetOffset() { return m_iOffset; }
 
77
                int                             GetSize() { return m_iSize; }
 
78
                unsigned long           GetCrc() { return m_lCrc; }
 
79
        };
 
80
 
 
81
        typedef std::deque<Segment*>    SegmentListBase;
 
82
 
 
83
        class SegmentList : public SegmentListBase
 
84
        {
 
85
        public:
 
86
                                                        ~SegmentList();
 
87
        };
 
88
 
 
89
        typedef std::deque<char*>               FileList;
 
90
        typedef std::deque<void*>               SourceList;
 
91
        typedef std::vector<bool>               ValidBlocks;
 
92
 
 
93
        friend class Repairer;
 
94
        
 
95
private:
 
96
        char*                           m_szInfoName;
 
97
        char*                           m_szDestDir;
 
98
        char*                           m_szNZBName;
 
99
        const char*                     m_szParFilename;
 
100
        EStatus                         m_eStatus;
 
101
        EStage                          m_eStage;
 
102
        // declared as void* to prevent the including of libpar2-headers into this header-file
 
103
        void*                           m_pRepairer;
 
104
        char*                           m_szErrMsg;
 
105
        FileList                        m_QueuedParFiles;
 
106
        Mutex                           m_mutexQueuedParFiles;
 
107
        bool                            m_bQueuedParFilesChanged;
 
108
        FileList                        m_ProcessedFiles;
 
109
        int                                     m_iProcessedFiles;
 
110
        int                                     m_iFilesToRepair;
 
111
        int                                     m_iExtraFiles;
 
112
        bool                            m_bVerifyingExtraFiles;
 
113
        char*                           m_szProgressLabel;
 
114
        int                                     m_iFileProgress;
 
115
        int                                     m_iStageProgress;
 
116
        bool                            m_bCancelled;
 
117
        SourceList                      m_sourceFiles;
 
118
        std::string                     m_lastFilename;
 
119
        bool                            m_bHasDamagedFiles;
 
120
        bool                            m_bParQuick;
 
121
        bool                            m_bForceRepair;
 
122
 
 
123
        void                            Cleanup();
 
124
        EStatus                         RunParCheckAll();
 
125
        EStatus                         RunParCheck(const char* szParFilename);
 
126
        int                                     PreProcessPar();
 
127
        bool                            LoadMainParBak();
 
128
        int                                     ProcessMorePars();
 
129
        bool                            LoadMorePars();
 
130
        bool                            AddSplittedFragments();
 
131
        bool                            AddMissingFiles();
 
132
        bool                            IsProcessedFile(const char* szFilename);
 
133
        void                            WriteBrokenLog(EStatus eStatus);
 
134
        void                            SaveSourceList();
 
135
        void                            DeleteLeftovers();
 
136
        void                            signal_filename(std::string str);
 
137
        void                            signal_progress(double progress);
 
138
        void                            signal_done(std::string str, int available, int total);
 
139
        // declared as void* to prevent the including of libpar2-headers into this header-file
 
140
        // DiskFile* pDiskfile, Par2RepairerSourceFile* pSourcefile
 
141
        EFileStatus                     VerifyDataFile(void* pDiskfile, void* pSourcefile, int* pAvailableBlocks);
 
142
        bool                            VerifySuccessDataFile(void* pDiskfile, void* pSourcefile, unsigned long lDownloadCrc);
 
143
        bool                            VerifyPartialDataFile(void* pDiskfile, void* pSourcefile, SegmentList* pSegments, ValidBlocks* pValidBlocks);
 
144
        bool                            SmartCalcFileRangeCrc(FILE* pFile, long long lStart, long long lEnd, SegmentList* pSegments,
 
145
                                                        unsigned long* pDownloadCrc);
 
146
        bool                            DumbCalcFileRangeCrc(FILE* pFile, long long lStart, long long lEnd, unsigned long* pDownloadCrc);
 
147
 
 
148
protected:
 
149
        /**
 
150
        * Unpause par2-files
 
151
        * returns true, if the files with required number of blocks were unpaused,
 
152
        * or false if there are no more files in queue for this collection or not enough blocks
 
153
        */
 
154
        virtual bool            RequestMorePars(int iBlockNeeded, int* pBlockFound) = 0;
 
155
        virtual void            UpdateProgress() {}
 
156
        virtual void            Completed() {}
 
157
        virtual void            PrintMessage(Message::EKind eKind, const char* szFormat, ...) {}
 
158
        virtual void            RegisterParredFile(const char* szFilename) {}
 
159
        virtual bool            IsParredFile(const char* szFilename) { return false; }
 
160
        virtual EFileStatus     FindFileCrc(const char* szFilename, unsigned long* lCrc, SegmentList* pSegments) { return fsUnknown; }
 
161
        EStage                          GetStage() { return m_eStage; }
 
162
        const char*                     GetProgressLabel() { return m_szProgressLabel; }
 
163
        int                                     GetFileProgress() { return m_iFileProgress; }
 
164
        int                                     GetStageProgress() { return m_iStageProgress; }
 
165
 
 
166
public:
 
167
                                                ParChecker();
 
168
        virtual                         ~ParChecker();
 
169
        virtual void            Run();
 
170
        void                            SetDestDir(const char* szDestDir);
 
171
        const char*                     GetParFilename() { return m_szParFilename; }
 
172
        const char*                     GetInfoName() { return m_szInfoName; }
 
173
        void                            SetInfoName(const char* szInfoName);
 
174
        void                            SetNZBName(const char* szNZBName);
 
175
        void                            SetParQuick(bool bParQuick) { m_bParQuick = bParQuick; }
 
176
        bool                            GetParQuick() { return m_bParQuick; }
 
177
        void                            SetForceRepair(bool bForceRepair) { m_bForceRepair = bForceRepair; }
 
178
        bool                            GetForceRepair() { return m_bForceRepair; }
 
179
        EStatus                         GetStatus() { return m_eStatus; }
 
180
        void                            AddParFile(const char* szParFilename);
 
181
        void                            QueueChanged();
 
182
        void                            Cancel();
 
183
        bool                            GetCancelled() { return m_bCancelled; }
 
184
};
 
185
 
 
186
#endif
 
187
 
 
188
#endif