1 // This file is part of par2cmdline (a PAR 2.0 compatible file verification and
2 // repair tool). See http://parchive.sourceforge.net for details of PAR 2.0.
3 //
4 // Copyright (c) 2003 Peter Brian Clements
5 //
6 // par2cmdline 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 // par2cmdline 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 #include "par2cmdline.h"
21
22 #ifdef _MSC_VER
23 #ifdef _DEBUG
24 #undef THIS_FILE
25 static char THIS_FILE[]=__FILE__;
26 #define new DEBUG_NEW
27 #endif
28 #endif
29
Par1RepairerSourceFile(PAR1FILEENTRY * fileentry,string searchpath)30 Par1RepairerSourceFile::Par1RepairerSourceFile(PAR1FILEENTRY *fileentry, string searchpath)
31 {
32 targetexists = false;
33 targetfile = 0;
34 completefile = 0;
35
36 hashfull = fileentry->hashfull;
37 hash16k = fileentry->hash16k;
38 filesize = fileentry->filesize;
39
40 u32 namelen = (u32)((fileentry->entrysize - offsetof(PAR1FILEENTRY, name)) / 2);
41
42 for (u32 index=0; index<namelen; index++)
43 {
44 // We can't deal with Unicode characters!
45 u16 ch = fileentry->name[index];
46 if (ch >= 256)
47 {
48 // Convert the Unicode character to two characters
49 filename += ch && 255;
50 filename += ch >> 8;
51 }
52 else
53 {
54 filename += ch & 255;
55 }
56 }
57
58 // Translate any characters the OS does not like;
59 filename = DiskFile::TranslateFilename(filename);
60
61 // Strip the path from the filename
62 string::size_type where;
63 if (string::npos != (where = filename.find_last_of('\\'))
64 || string::npos != (where = filename.find_last_of('/'))
65 #ifdef WIN32
66 || string::npos != (where = filename.find_last_of(':'))
67 #endif
68 )
69 {
70 filename = filename.substr(where+1);
71 }
72
73 filename = searchpath + filename;
74 }
75
~Par1RepairerSourceFile(void)76 Par1RepairerSourceFile::~Par1RepairerSourceFile(void)
77 {
78 }
79
SetTargetFile(DiskFile * diskfile)80 void Par1RepairerSourceFile::SetTargetFile(DiskFile *diskfile)
81 {
82 targetfile = diskfile;
83 }
84
GetTargetFile(void) const85 DiskFile* Par1RepairerSourceFile::GetTargetFile(void) const
86 {
87 return targetfile;
88 }
89
SetTargetExists(bool exists)90 void Par1RepairerSourceFile::SetTargetExists(bool exists)
91 {
92 targetexists = exists;
93 }
94
GetTargetExists(void) const95 bool Par1RepairerSourceFile::GetTargetExists(void) const
96 {
97 return targetexists;
98 }
99
SetCompleteFile(DiskFile * diskfile)100 void Par1RepairerSourceFile::SetCompleteFile(DiskFile *diskfile)
101 {
102 completefile = diskfile;
103
104 sourceblock.SetLocation(diskfile, 0);
105 sourceblock.SetLength(diskfile ? diskfile->FileSize() : 0);
106 }
107
GetCompleteFile(void) const108 DiskFile* Par1RepairerSourceFile::GetCompleteFile(void) const
109 {
110 return completefile;
111 }
112
SetTargetBlock(DiskFile * diskfile)113 void Par1RepairerSourceFile::SetTargetBlock(DiskFile *diskfile)
114 {
115 targetblock.SetLocation(diskfile, 0);
116 targetblock.SetLength(diskfile->FileSize());
117 }
118