Symbolic names for block types
[rarfs.git] / src / rarblock.cc
blobb2375db7d355dd5adb4433125c749a9cad4e0be3
1 /***************************************************************************
2 * Copyright (C) 2006 Kent Gustavsson <nedo80@gmail.com>
3 ****************************************************************************/
4 /*
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Library General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 // Class: RARBlock
24 // Created by: Kent Gustavsson <nedo80@gmail.com>
25 // Created on: Tue Feb 28 16:05:38 2006
28 #include "rarblock.h"
31 RARBlock::RARBlock(std::istream &in)
33 checksum = in.get() * 256;
34 checksum += in.get();
36 blocktype = in.get();
38 flags = in.get();
39 flags += in.get()* 256;
41 headsize = in.get();
42 headsize += in.get() * 256;
44 if ( ( flags & 0x8000 ) != 0 )
46 size = in.get();
47 size += in.get() * 256;
48 size += in.get() * 256 * 256;
49 size += in.get() * 256 * 256 * 256;
50 in.seekg(headsize - 7 - 4 + size, std::ios::cur);
52 else
54 size = 0;
55 in.seekg(headsize - 7, std::ios::cur);
59 RARBlock::~RARBlock()
64 bool
65 RARBlock::isBlock()
67 return (blocktype);
70 void
71 RARBlock::print()
74 std::cout << "Checksum: 0x" << (std::hex) << checksum << std::endl;
75 std::cout << "BlockType: 0x" << (std::hex) << (int)blocktype;
77 switch ( blocktype )
79 case MARKER:
80 std::cout << " Marker Block" << std::endl;
81 break;
82 case ARCHIVE:
83 std::cout << " Archive Header" << std::endl;
84 break;
85 case FILE:
86 std::cout << " File Header" << std::endl;
87 break;
88 case COMMENT_1_50:
89 std::cout << " Comment Header" << std::endl;
90 break;
91 case AV_1_50:
92 std::cout << " Extra Information" << std::endl;
93 break;
94 case SUB_2_00:
95 std::cout << " Sub Block" << std::endl;
96 break;
97 case RECOVERY_2_00:
98 std::cout << " Recovery Record" << std::endl;
99 break;
100 default:
101 std::cout << " Unknown Block" << std::endl;
102 break;
105 std::cout << "Flags: 0x" << (std::hex) << flags << std::endl;
106 if( blocktype == FILE )
108 std::cout << "\tData in previous file " << (int)(flags & 0x01) << std::endl;
109 std::cout << "\tData in continues file " << (int)(flags & 0x02) << std::endl;
110 std::cout << "\tPassword " << (int)(flags & 0x04) << std::endl;
111 std::cout << "\tFile Comment " << (int)(flags & 0x08) << std::endl;
112 std::cout << "\tSolid flag " << (int)(flags &0x10) << std::endl;
113 std::cout << "\tDictionary: ";
115 switch ((int)(flags &0xe0) >> 5)
117 case 0:
118 std::cout << "64 Kb" << std::endl;
119 break;
120 case 1:
121 std::cout << "128 Kb" << std::endl;
122 break;
123 case 2:
124 std::cout << "256 Kb" << std::endl;
125 break;
126 case 3:
127 std::cout << "512 Kb" << std::endl;
128 break;
129 case 4:
130 std::cout << "1024 Kb" << std::endl;
131 break;
132 case 5:
133 std::cout << "reserved_1" << std::endl;
134 break;
135 case 6:
136 std::cout << "reserved_2" << std::endl;
137 break;
138 case 7:
139 std::cout << "directory" << std::endl;
140 break;
144 std::cout << "Size: 0x" << headsize << std::endl;
145 std::cout << "DataSize: 0x" << size << std::endl;