source: subversion/applications/lib/libimg/Img.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.1 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 "Parser.h"
20#include "Node.h"
21#include "Img.h"
22#include <iostream>
23#include <fstream>
24#include <sstream>
25#include <string>
26#include "time.h"
27
28ImgLblFile::ImgLblFile(){
29  Fat.SetFileType("LBL");
30  Fat.SetFileName("LBL00001");
31}
32ImgRgnFile::ImgRgnFile(){
33  Fat.SetFileType("RGN");
34  Fat.SetFileName("RGN00001");
35}
36
37Img::Img(){
38
39}
40
41void Img::WriteFile(std::ofstream &out){
42  m_header.SetNumFatBlocks( m_TreFile.Fat.GetNumFatBlocks() + 
43                            m_RgnFile.Fat.GetNumFatBlocks() +
44                            m_LblFile.Fat.GetNumFatBlocks());
45  m_header.WriteFile(out);
46  m_TreFile.Fat.WriteFile(out);
47  m_RgnFile.Fat.WriteFile(out);
48  m_LblFile.Fat.WriteFile(out);
49  m_TreFile.WriteFile(out);
50  m_RgnFile.WriteFile(out);
51  m_LblFile.WriteFile(out);
52}
53
54void Img::ReadFile(std::ifstream &in)
55{
56  ImgFat* fat;
57  m_header.ReadFile(in);
58  fat = new ImgFat[m_header.GetNumFatBlocks()];
59  for(int i=0;i<m_header.GetNumFatBlocks();i++)
60    fat[i].ReadFile(in);
61  for(int i=0;i<m_header.GetNumFatBlocks();i++)
62    {
63      if(fat[i].GetFileSize()){
64        std::string ft;
65        fat[i].GetFileType(ft);
66        if(ft=="RGN"){
67          m_RgnFile.Fat.SetFileSize(fat[i].GetFileSize());
68          m_RgnFile.ReadFile(in);
69        }
70        if(ft=="TRE"){
71          m_TreFile.Fat.SetFileSize(fat[i].GetFileSize());
72          m_TreFile.ReadFile(in);
73        }
74        if(ft=="LBL"){
75          m_LblFile.Fat.SetFileSize(fat[i].GetFileSize());
76          m_LblFile.ReadFile(in);
77        }
78      }
79    }
80}
Note: See TracBrowser for help on using the repository browser.