unetbootin.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. /*
  2. unetbootin.h from UNetbootin <http://unetbootin.sourceforge.net>
  3. Copyright (C) 2007-2008 Geza Kovacs <geza0kovacs@gmail.com>
  4. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.
  5. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License at <http://www.gnu.org/licenses/> for more details.
  6. */
  7. #ifndef UNETBOOTIN_H
  8. #define UNETBOOTIN_H
  9. #include <QtCore>
  10. #include <QtGui>
  11. #include <QtNetwork>
  12. #include <time.h>
  13. //#include <QtDebug>
  14. #include "ui_unetbootin.h"
  15. #ifdef Q_OS_WIN32
  16. #define WIN32_LEAN_AND_MEAN
  17. #define _WIN32_WINNT 0x0500
  18. #include <windows.h>
  19. #include <shellapi.h>
  20. #endif
  21. #ifdef Q_OS_MACX
  22. #include <sys/param.h>
  23. #include <sys/mount.h>
  24. #include <sys/statvfs.h>
  25. #endif
  26. #ifdef Q_OS_LINUX
  27. #include <sys/vfs.h>
  28. #endif
  29. #ifdef AUTOSUPERGRUBDISK
  30. #define UNETBOOTINB "Auto Super Grub Disk"
  31. #define NOEXTERN
  32. //#define NOISO
  33. #define HDDINSTALL
  34. #endif
  35. #ifdef EEEPCLOS
  36. #define UNETBOOTINB "UNetbootin-EeePCLinuxOS"
  37. #define NOMANUAL
  38. #define NOFLOPPY
  39. //#define USBINSTALL
  40. #endif
  41. #ifdef EEEUBUNTU
  42. #define UNETBOOTINB "UNetbootin-Ubuntu Eee"
  43. #define NOMANUAL
  44. #define NOFLOPPY
  45. //#define USBINSTALL
  46. #endif
  47. #ifdef ELIVE
  48. #define UNETBOOTINB "Elive USB Installer"
  49. #define NOMANUAL
  50. #define NOFLOPPY
  51. //#define USBINSTALL
  52. #endif
  53. #ifdef GNEWSENSE
  54. #define UNETBOOTINB "FUSBi"
  55. #define NOMANUAL
  56. #define NOFLOPPY
  57. //#define USBINSTALL
  58. #endif
  59. #ifdef KIWILINUX
  60. #define UNETBOOTINB "Kiwi pe USB"
  61. #define NOMANUAL
  62. #define NOFLOPPY
  63. //#define USBINSTALL
  64. #endif
  65. #ifdef NIMBLEX
  66. #define UNETBOOTINB "NimbleX Installer"
  67. #define NOMANUAL
  68. #define NOFLOPPY
  69. //#define USBINSTALL
  70. #endif
  71. #ifdef SLITAZ
  72. #define UNETBOOTINB "SliTaz Installer"
  73. #define NOMANUAL
  74. #define NOFLOPPY
  75. //#define USBINSTALL
  76. #endif
  77. #ifdef XPUD
  78. #define UNETBOOTINB "xPUD USB Installer"
  79. #define NOMANUAL
  80. #define NOFLOPPY
  81. //#define USBINSTALL
  82. #define NOEXTRACTKERNEL
  83. #define NOEXTRACTINITRD
  84. #define NODEFAULTBOOT
  85. #define NODEFAULTKERNEL
  86. #define NOINITRD
  87. #endif
  88. #ifndef UNETBOOTINB
  89. #define UNETBOOTINB "FreeNetBootin"
  90. #define STDUNETBOOTIN
  91. //#define USBINSTALL
  92. #endif
  93. class customver : public QObject
  94. {
  95. Q_OBJECT
  96. };
  97. class uninstaller : public QObject
  98. {
  99. Q_OBJECT
  100. };
  101. class callexternappT : public QThread
  102. {
  103. public:
  104. QString execFile;
  105. QString execParm;
  106. QString retnValu;
  107. void run();
  108. };
  109. class callexternappWriteToStdinT : public QThread
  110. {
  111. public:
  112. QString execFile;
  113. QString execParm;
  114. QString writeToStdin;
  115. QString retnValu;
  116. void run();
  117. };
  118. class copyfileT : public QThread
  119. {
  120. Q_OBJECT
  121. public:
  122. QString source;
  123. QString destination;
  124. void run();
  125. signals:
  126. void datacopied64(qint64 dlbytes, qint64 maxbytes);
  127. void finished();
  128. };
  129. class ubngetrequestheader : public QHttpRequestHeader
  130. {
  131. public:
  132. ubngetrequestheader(QString urhost, QString urpath);
  133. };
  134. class randtmpfile : public QFile
  135. {
  136. public:
  137. randtmpfile(QString rfpath, QString rfextn);
  138. static QString getrandfilename(QString rfpath, QString rfextn);
  139. };
  140. class nDirListStor : public QObject
  141. {
  142. Q_OBJECT
  143. public:
  144. QStringList nDirFileListSL;
  145. int nMinFileSizeBytes;
  146. int nMaxFileSizeBytes;
  147. bool searchsymlinks;
  148. public slots:
  149. void sAppendSelfUrlInfoList(QUrlInfo curDirUrl);
  150. };
  151. class unetbootin : public QWidget, private Ui::unetbootinui
  152. {
  153. Q_OBJECT
  154. public:
  155. unetbootin(QWidget *parent = 0);
  156. QString trcurrent;
  157. QString trdone;
  158. QString appNlang;
  159. QString appDir;
  160. QString appLoc;
  161. QString ubntmpf;
  162. QString nameDistro;
  163. QString nameVersion;
  164. bool skipExtraction;
  165. bool isarch64;
  166. bool islivecd;
  167. bool isnetinstall;
  168. bool ishdmedia;
  169. bool overwriteall;
  170. bool searchsymlinks;
  171. bool ignoreoutofspace;
  172. bool dontgeneratesyslinuxcfg;
  173. bool downloadFailed;
  174. bool exitOnCompletion;
  175. bool testingDownload;
  176. bool issalt;
  177. bool redundanttopleveldir;
  178. QString redundantrootdirname;
  179. QString saltRootDir;
  180. int persistenceSpaceMB;
  181. QString extraBootOptions;
  182. QStringList locatedsyslinuxcfgfiles;
  183. QString targetDrive;
  184. QString targetPath;
  185. QString installType;
  186. QString targetDev;
  187. QString rawtargetDev;
  188. QString devluid;
  189. QString devlabel;
  190. QString devuuid;
  191. QString postinstmsg;
  192. QString kernelLine, kernelParam, kernelLoc, kernelOpts, initrdLine, initrdLoc, initrdOpts;
  193. QString slinitrdLine;
  194. QString sevzcommand;
  195. QPair<QPair<QStringList, QStringList>, QPair<QStringList, QStringList> > extraoptionsPL;
  196. QMap<QString, QString> grub2vars;
  197. QFile *logFile;
  198. QTextStream *logStream;
  199. QStringList loggedLinesNotYetWritten;
  200. #ifdef Q_OS_UNIX
  201. QString fdiskcommand;
  202. QString sfdiskcommand;
  203. QString dfcommand;
  204. QString blkidcommand;
  205. QString volidcommand;
  206. QString syslinuxcommand;
  207. QString extlinuxcommand;
  208. QString mke2fscommand;
  209. QString mlabelcommand;
  210. QString e2labelcommand;
  211. bool isext2;
  212. #endif
  213. #ifdef Q_OS_MAC
  214. QDir resourceDir;
  215. #endif
  216. bool ubninitialize(QList<QPair<QString, QString> > oppairs);
  217. QString displayfisize(quint64 fisize);
  218. QPair<QPair<QStringList, QList<quint64> >, QStringList> listarchiveconts(QString archivefile);
  219. bool overwritefileprompt(QString ovwfileloc);
  220. bool ignoreoutofspaceprompt(QString destindir);
  221. bool extractfile(QString filepath, QString destinfileL, QString archivefile);
  222. bool checkifoutofspace(QString destindir);
  223. QString locatekernel(QString archivefile, QPair<QStringList, QList<quint64> > archivefileconts);
  224. bool extractkernel(QString archivefile, QString kernoutputfile, QPair<QStringList, QList<quint64> > archivefileconts);
  225. QString locateinitrd(QString archivefile, QPair<QStringList, QList<quint64> > archivefileconts);
  226. bool extractinitrd(QString archivefile, QString initoutputfile, QPair<QStringList, QList<quint64> > archivefileconts);
  227. QString extractcfg(QString archivefile, QStringList archivefileconts);
  228. QPair<QPair<QStringList, QStringList>, QPair<QStringList, QStringList> > extractcfgL(QString archivefile, QStringList archivefileconts);
  229. QString getfullarchivepath(QString relativefilepath, QStringList archivefile);
  230. QString filteroutlist(QString listofdata, QList<QRegExp> listofmatches);
  231. QString filteroutlist(QStringList listofdata, QList<QRegExp> listofmatches);
  232. QStringList filteroutlistL(QStringList listofdata, QList<QRegExp> listofmatches);
  233. void extractiso(QString isofile);
  234. void extractiso_krd10(QString isofile);
  235. void copyfilegui(QString src, QString dst);
  236. QStringList makepathtree(QString dirmkpathw, QStringList pathlist);
  237. QStringList extractallfiles(QString archivefile, QString dirxfilesto, QPair<QStringList, QList<quint64> > filesizelist, QStringList outputfilelist);
  238. QString getgrubcfgargs(QString cfgfile);
  239. QPair<QPair<QStringList, QStringList>, QPair<QStringList, QStringList> > getgrubcfgargsL(QString cfgfile);
  240. QString getFirstTextBlock(QString fulltext);
  241. void loadgrub2env(QString cfgfile);
  242. QString getgrub2cfgargs(QString cfgfile, QString archivefile, QStringList archivefileconts, QStringList visitedincludes);
  243. QPair<QPair<QStringList, QStringList>, QPair<QStringList, QStringList> > getgrub2cfgargsL(QString cfgfile, QString archivefile, QStringList archivefileconts, QStringList visitedincludes);
  244. QString getcfgkernargs(QString cfgfile, QString archivefile, QStringList archivefileconts, QStringList visitedincludes);
  245. QPair<QPair<QStringList, QStringList>, QPair<QStringList, QStringList> > getcfgkernargsL(QString cfgfile, QString archivefile, QStringList archivefileconts, QStringList visitedincludes);
  246. QString searchforincludesfile(QString includesfile, QString archivefile, QStringList archivefileconts, QStringList visitedincludes);
  247. QPair<QPair<QStringList, QStringList>, QPair<QStringList, QStringList> > searchforincludesfileL(QString includesfile, QString archivefile, QStringList archivefileconts, QStringList visitedincludes);
  248. QString searchforgrub2includesfile(QString includesfile, QString archivefile, QStringList archivefileconts, QStringList visitedincludes);
  249. QPair<QPair<QStringList, QStringList>, QPair<QStringList, QStringList> > searchforgrub2includesfileL(QString includesfile, QString archivefile, QStringList archivefileconts, QStringList visitedincludes);
  250. void downloadfile(QString fileurl, QString targetfile, int minsize);
  251. QString downloadpagecontents(QString pageurl);
  252. QStringList lstFtpDirFiles(QString ldfDirStringUrl, int ldfMinSize, int ldfMaxSize);
  253. QStringList lstHttpDirFiles(QString ldfDirStringUrl);
  254. QStringList lstNetDirFiles(QString ldfDirStringUrl, int ldfMinSize, int ldfMaxSize);
  255. QPair<QString, int> weightedFilterNetDir(QString ldfDirStringUrl, int ldfMinSize, int ldfMaxSize, QList<QRegExp> ldfFileMatchExp);
  256. QString fileFilterNetDir(QStringList ldfDirStringUrlList, int ldfMinSize, int ldfMaxSize, QList<QRegExp> ldfFileMatchExp);
  257. QPair<QString, int> filterBestMatch(QStringList ufStringList, QList<QRegExp> filterExpList);
  258. void sysreboot();
  259. static QString callexternapp(QString xexecFile, QString xexecParm);
  260. static QString callexternappWriteToStdin(QString xexecFile, QString xexecParm, QString xwriteToStdin);
  261. QString getdevluid(QString voldrive);
  262. QString getlabel(QString voldrive);
  263. QString getuuid(QString voldrive);
  264. #ifdef Q_OS_MAC
  265. QString getlabel(QString voldrive, QString diskutilinfo);
  266. QString getuuid(QString voldrive, QString diskutilinfo);
  267. #endif
  268. void refreshdriveslist();
  269. QStringList listcurdrives();
  270. QStringList listsanedrives();
  271. QStringList listalldrives();
  272. void replaceTextInFile(QString repfilepath, QRegExp replaceme, QString replacewith);
  273. QString fixkernelbootoptions(const QString &cfgfileCL);
  274. void setLabel(QString devname, QString newlabel);
  275. #ifdef Q_OS_UNIX
  276. QString locatecommand(QString commandtolocate, QString reqforinstallmode, QString packagename);
  277. QString locatedevicenode(QString mountpoint);
  278. QString locatemountpoint(QString devicenode);
  279. QString getGrubNotation(QString devicenode);
  280. QString getGrub2Notation(QString devicenode);
  281. int letterToNumber(QChar lettertoconvert);
  282. int getDiskNumber(QString devicenode);
  283. int getPartitionNumber(QString devicenode);
  284. #endif
  285. #ifdef Q_OS_WIN32
  286. void installsvzip();
  287. void configsysEdit();
  288. void bootiniEdit();
  289. void vistabcdEdit();
  290. #endif
  291. void instIndvfl(QString srcfName, QString dstfName);
  292. QString instTempfl(QString srcfName, QString dstfType);
  293. void runinst();
  294. void instDetType();
  295. #ifdef Q_OS_UNIX
  296. void writegrub2cfg();
  297. #endif
  298. void runinsthdd();
  299. void runinstusb();
  300. void logText(const QString &text);
  301. void finishLogging();
  302. void writeTextToFile(const QString &text, const QString &filePath);
  303. void fininstall();
  304. void rmFile(const QString &fn);
  305. void rmFile(QFile &fn);
  306. void mvFile(const QString &fn, const QString &outfn);
  307. void mvFile(QFile &fn, QFile &outfn);
  308. void showDownloadFailedScreen(const QString &fileurl);
  309. private slots:
  310. void on_distroselect_currentIndexChanged(int distroselectIndex);
  311. void on_typeselect_currentIndexChanged(int typeselectIndex);
  312. void on_dverselect_currentIndexChanged();
  313. void on_diskimagetypeselect_currentIndexChanged();
  314. void on_FloppyFileSelector_clicked();
  315. void on_KernelFileSelector_clicked();
  316. void on_InitrdFileSelector_clicked();
  317. void on_CfgFileSelector_clicked();
  318. void on_cancelbutton_clicked();
  319. void on_frebootbutton_clicked();
  320. void on_fexitbutton_clicked();
  321. public slots:
  322. void dlprogressupdate(int dlbytes, int maxbytes);
  323. void dlprogressupdate64(qint64 dlbytes, qint64 maxbytes);
  324. void cpprogressupdate64(qint64 dlbytes, qint64 maxbytes);
  325. void on_okbutton_clicked();
  326. void killApplication();
  327. };
  328. #endif