source: subversion/applications/lib/libimg/ImgFat.cpp @ 34621

Last change on this file since 34621 was 2092, checked in by enxrah, 13 years ago

Nick didn't write this. I did :-)

File size: 2.6 KB
Line 
1/*
2    Copyright (C) 2007 Robert Hart, rob@bathterror.free-online.co.uk
3
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU Lesser General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
17
18 */
19#include "Img.h"
20
21ImgFat::ImgFat(){
22  filesize = 0;
23  filename = "";
24  filetype = "";
25  nblocks = 0;
26}
27
28void ImgFat::CreateHeader(){
29  data = new char[GetNumFatBlocks() * 512];
30  SetByte(0x0, 1);              //True sub-file
31  SetString(0x1, filename);   //File name
32  SetString(0x9, filetype);      //sub-type
33  SetLong(0xC, filesize);       //filesize
34  SetLong(0x10, 0);             //sequence number
35  SetByte(0x12, 0, 14);         //padding
36  SetBlockList(0x20, firstblock, firstblock+nblocks);
37}
38
39int ImgFat::GetNumFatBlocks(){
40  return (int)((nblocks/240)+1);
41}
42
43int ImgFat::GetNumBlocks(){
44  return (nblocks);
45}
46
47void ImgFat::SetNumBlocks(int n){
48  cout << "Number of blocks set to " << n <<endl;
49  nblocks = n;
50}
51
52void ImgFat::SetFileSize(int n){
53  filesize = n;
54  nblocks = n/blocksize + 1;
55}
56
57void ImgFat::SetFirstBlock(int n){
58  firstblock = n;
59}
60
61void ImgFat::SetFileName(char* fn){
62  filename.assign(fn);
63}
64
65void ImgFat::SetFileType(char* fn){
66  filetype.assign(fn);
67}
68
69void ImgFat::GetFileName(std::string &fn){
70  fn.assign(filename);
71}
72
73void ImgFat::GetFileType(std::string &fn){
74  fn.assign(filetype);
75}
76
77int ImgFat::GetFileSize(){
78  return filesize;
79}
80
81void ImgFat::WriteFile(std::ofstream &out){
82  CreateHeader();
83  out.write(data, 512*GetNumFatBlocks());
84}
85
86int ImgFat::ReadFile(std::ifstream &in)
87{
88  int subfile, part;
89  filename = "";
90  filetype = "";
91  in.read(data, blocksize);
92  subfile = DecodeByte(0x0);
93  DecodeString(0x1, 8, filename);
94  DecodeString(0x9, 3, filetype);
95  filesize = DecodeLong(0xC);
96  DecodeBlockList(0x20, firstblock, nblocks);
97  //  firstblock = DecodeShort(0x20);
98  cout << "Found fat block for " << filename << "(" << filetype << ")" << endl;
99  cout << "Filesize " << filesize << " spanning blocks " << firstblock << " to " << nblocks << endl;
100  nblocks -= firstblock;
101  return blocksize;
102}
Note: See TracBrowser for help on using the repository browser.