2 * $Id: bmimage.h,v 1.10 2005/11/17 14:01:26 sat_turner Exp $
4 * (C) 2005 by digi_casi <digi_casi@tuxbox.org>
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.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
33 #include <lib/base/estring.h>
34 #ifdef INSTIMAGESUPPORT
35 #include <src/enigma.h>
36 #define TUXBOXDATADIR "/share/tuxbox"
37 #include <src/enigma_dyn_utils.h>
49 class bmimages
: public Object
52 std::vector
<eImage
> imageList
;
53 std::vector
<eImage
>::iterator it
;
61 void setImageName(eString imageDir
, eString imageName
)
63 if (FILE *f
= fopen(eString(imageDir
+ "/imagename").c_str(), "w"))
65 fprintf(f
, "%s", imageName
.c_str());
70 eString
getImageName(eString imageDir
)
72 unsigned int pos
= imageDir
.find_last_of("/");
73 eString imageName
= imageDir
.right(imageDir
.length() - pos
-1);
74 ifstream
nameFile(eString(imageDir
+ "/imagename").c_str());
78 getline(nameFile
, line
, '\n');
86 int load(eString mpoint
, bool clearList
)
91 eString dir
[2] = {mpoint
+ "/image/", mpoint
+ "/fwpro/"};
96 image
.name
= "Flash-Image";
98 imageList
.push_back(image
);
100 for (int i
= 0; i
< 2; i
++)
102 DIR *d
= opendir(dir
[i
].c_str());
105 while (struct dirent
*e
= readdir(d
))
107 if (strcmp(e
->d_name
, ".") && strcmp(e
->d_name
, ".."))
109 eString name
= dir
[i
] + eString(e
->d_name
);
110 stat(name
.c_str(), &s
);
111 if (S_ISDIR(s
.st_mode
))
113 image
.location
= name
;
114 image
.name
= getImageName(name
);
115 imageList
.push_back(image
);
122 return imageList
.size();
125 void discard(eString location
)
127 system(eString("rm -rf \"" + location
+ "\"").c_str());
130 void rename(eString from
, eString to
)
132 eString name
= to
.right(to
.length() - to
.find_last_of("/") - 1);
133 setImageName(to
, name
);
136 #ifdef INSTIMAGESUPPORT
137 int add(eString sourceImage
, eString imageName
, eString mountDir
)
140 eString imageDir
= mountDir
+ "/fwpro/" + imageName
;
142 eDebug("[BOOTMANAGER] unpackImage: installation device = %s, image file = %s, image dir = %s", mountDir
.c_str(), sourceImage
.c_str(), imageDir
.c_str());
144 // check if enough space is available
146 if (statfs(mountDir
.c_str(), &s
) >= 0)
147 freeSpace
= (s
.f_bavail
* (s
.f_bsize
/ 1024));
148 eDebug("[BOOTMANAGER] unpackImage: free space on device = %d", freeSpace
);
149 if (freeSpace
< 20000)
152 if (access(mountDir
.c_str(), W_OK
) != 0)
155 // check if directory is available, delete it and recreate it
156 if (access(imageDir
.c_str(), W_OK
) == 0)
157 system(eString("rm -rf " + imageDir
).c_str());
158 system(eString("mkdir " + imageDir
+ " --mode=777 --parents").c_str());
159 if (access(imageDir
.c_str(), W_OK
) != 0)
163 eString squashfsPart
= mountDir
+ "/squashfs.img";
164 remove(squashfsPart
.c_str());
165 if (system(eString("dd if=" + sourceImage
+ " of=" + squashfsPart
+ " bs=1024 skip=1152 count=4992").c_str()) >> 8)
167 eString cramfsPart
= mountDir
+ "/cramfs.img";
168 remove(cramfsPart
.c_str());
169 if (system(eString("dd if=" + sourceImage
+ " of=" + cramfsPart
+ " bs=1024 skip=0 count=1152").c_str()) >> 8)
171 remove(sourceImage
.c_str());
173 system(eString("cp " + eString(TEMPLATE_DIR
) + "instimg.tmp /tmp/instimg.sh").c_str());
174 system("chmod +x /tmp/instimg.sh");
175 system("touch /var/etc/.dont_restart_enigma");
176 system(eString("/tmp/instimg.sh " + imageDir
+ " " + cramfsPart
+ " " + squashfsPart
+ " &").c_str());
177 eZap::getInstance()->quit(2);