unetbootin.cpp 145 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313
  1. /*
  2. unetbootin.cpp 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. #include "unetbootin.h"
  8. static const QList<QRegExp> ignoredtypesbothRL = QList<QRegExp>()
  9. << QRegExp("isolinux.bin$", Qt::CaseInsensitive)
  10. << QRegExp("isolinux.cfg$", Qt::CaseInsensitive)
  11. << QRegExp("memtest$", Qt::CaseInsensitive)
  12. << QRegExp("memtest.bin$", Qt::CaseInsensitive)
  13. << QRegExp("memtest86$", Qt::CaseInsensitive)
  14. << QRegExp("memtest86.bin$", Qt::CaseInsensitive)
  15. << QRegExp("memtest+$", Qt::CaseInsensitive)
  16. << QRegExp("memtest+.bin$", Qt::CaseInsensitive)
  17. << QRegExp("memtest86+$", Qt::CaseInsensitive)
  18. << QRegExp("memtest86+.bin$", Qt::CaseInsensitive)
  19. << QRegExp("memtestplus$", Qt::CaseInsensitive)
  20. << QRegExp("memtestplus.bin$", Qt::CaseInsensitive)
  21. << QRegExp("memtest86plus$", Qt::CaseInsensitive)
  22. << QRegExp("memtest86plus.bin$", Qt::CaseInsensitive)
  23. << QRegExp("mt86plus$", Qt::CaseInsensitive)
  24. << QRegExp("mt86+$", Qt::CaseInsensitive)
  25. << QRegExp("mt86.bin$", Qt::CaseInsensitive)
  26. << QRegExp("mt86plus.bin$", Qt::CaseInsensitive)
  27. << QRegExp("mt86+.bin$", Qt::CaseInsensitive)
  28. << QRegExp("system.map$", Qt::CaseInsensitive)
  29. << QRegExp(".efimg$", Qt::CaseInsensitive)
  30. << QRegExp(".html$", Qt::CaseInsensitive)
  31. << QRegExp(".jpg$", Qt::CaseInsensitive)
  32. << QRegExp(".png$", Qt::CaseInsensitive)
  33. << QRegExp(".pdf$", Qt::CaseInsensitive)
  34. << QRegExp(".pcx$", Qt::CaseInsensitive)
  35. << QRegExp(".rle$", Qt::CaseInsensitive)
  36. << QRegExp(".fnt$", Qt::CaseInsensitive)
  37. << QRegExp(".psd$", Qt::CaseInsensitive)
  38. << QRegExp(".xcf$", Qt::CaseInsensitive)
  39. << QRegExp(".bmp$", Qt::CaseInsensitive)
  40. << QRegExp(".svg$", Qt::CaseInsensitive)
  41. << QRegExp(".md5$", Qt::CaseInsensitive)
  42. << QRegExp(".md5sum$", Qt::CaseInsensitive)
  43. << QRegExp(".sha1$", Qt::CaseInsensitive)
  44. << QRegExp(".sha1sum$", Qt::CaseInsensitive)
  45. << QRegExp(".c32$", Qt::CaseInsensitive)
  46. << QRegExp(".sig$", Qt::CaseInsensitive)
  47. << QRegExp(".msg$", Qt::CaseInsensitive)
  48. << QRegExp(".cat$", Qt::CaseInsensitive)
  49. << QRegExp(".txt$", Qt::CaseInsensitive)
  50. << QRegExp(".tar$", Qt::CaseInsensitive)
  51. << QRegExp(".exe$", Qt::CaseInsensitive)
  52. << QRegExp(".deb$", Qt::CaseInsensitive)
  53. << QRegExp(".udeb$", Qt::CaseInsensitive)
  54. << QRegExp("system.map", Qt::CaseInsensitive);
  55. static const QList<QRegExp> ignoredtypeskernelRL = QList<QRegExp>()
  56. << QRegExp("initrd.gz$", Qt::CaseInsensitive)
  57. << QRegExp("initrd.img$", Qt::CaseInsensitive);
  58. static const QList<QRegExp> ignoredtypesinitrdRL = QList<QRegExp>()
  59. << QRegExp("bzImage$", Qt::CaseInsensitive);
  60. static const QString SALT_DETECTED = "*SaLT*";
  61. void callexternappT::run()
  62. {
  63. #ifdef Q_OS_WIN32
  64. SHELLEXECUTEINFO ShExecInfo = {0};
  65. ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
  66. ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
  67. ShExecInfo.hwnd = NULL;
  68. if (QSysInfo::WindowsVersion == QSysInfo::WV_NT || QSysInfo::WindowsVersion == QSysInfo::WV_2000 || QSysInfo::WindowsVersion == QSysInfo::WV_XP || QSysInfo::WindowsVersion == QSysInfo::WV_2003 )
  69. {
  70. ShExecInfo.lpVerb = NULL;
  71. }
  72. else
  73. {
  74. ShExecInfo.lpVerb = L"runas";
  75. }
  76. ShExecInfo.lpFile = LPWSTR(execFile.utf16());
  77. ShExecInfo.lpParameters = LPWSTR(execParm.utf16());
  78. ShExecInfo.lpDirectory = NULL;
  79. ShExecInfo.nShow = SW_HIDE;
  80. ShExecInfo.hInstApp = NULL;
  81. ShellExecuteEx(&ShExecInfo);
  82. WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
  83. retnValu = "";
  84. #endif
  85. #ifdef Q_OS_UNIX
  86. QProcess lnexternapp;
  87. lnexternapp.start("\"" + execFile + "\" " + execParm);
  88. lnexternapp.waitForFinished(-1);
  89. retnValu = QString(lnexternapp.readAll());
  90. #endif
  91. }
  92. void callexternappWriteToStdinT::run()
  93. {
  94. QProcess lnexternapp;
  95. lnexternapp.start("\"" + execFile + "\" " + execParm);
  96. lnexternapp.write(writeToStdin.toAscii().data());
  97. lnexternapp.closeWriteChannel();
  98. lnexternapp.waitForFinished(-1);
  99. retnValu = QString(lnexternapp.readAll());
  100. }
  101. void copyfileT::run()
  102. {
  103. QFile srcF(source);
  104. srcF.open(QIODevice::ReadOnly);
  105. QFile dstF(destination);
  106. dstF.open(QIODevice::WriteOnly);
  107. qint64 maxbytes = srcF.size();
  108. qint64 dlbytes = 0;
  109. char *buf = new char[262144];
  110. while (!srcF.atEnd())
  111. {
  112. qint64 bytesread = srcF.read(buf, 262144);
  113. dstF.write(buf, bytesread);
  114. dlbytes += bytesread;
  115. emit datacopied64(dlbytes, maxbytes);
  116. #ifdef Q_OS_UNIX
  117. unetbootin::callexternapp("sync", "");
  118. #endif
  119. }
  120. delete[] buf;
  121. srcF.close();
  122. dstF.close();
  123. emit finished();
  124. }
  125. ubngetrequestheader::ubngetrequestheader(QString urhost, QString urpath)
  126. {
  127. this->setRequest("GET", urpath);
  128. this->setValue("HOST", urhost);
  129. this->setValue("User-Agent", "UNetbootin/1.1.1");
  130. // this->setValue("User-Agent", "Wget/1.10.2");
  131. this->setValue("Accept", "*/*");
  132. this->setValue("Connection", "Keep-Alive");
  133. }
  134. randtmpfile::randtmpfile(QString rfpath, QString rfextn)
  135. {
  136. QString basefn = getrandfilename(rfpath, rfextn);
  137. this->setFileName(basefn);
  138. }
  139. QString randtmpfile::getrandfilename(QString rfpath, QString rfextn)
  140. {
  141. qsrand((unsigned int)time(0));
  142. QString basefn = QString("%1un%2.%3").arg(rfpath).arg(qrand() % 999999).arg(rfextn);
  143. while (QFile::exists(basefn))
  144. {
  145. basefn = QString("%1%2.%3").arg(rfpath).arg(qrand() % 999999).arg(rfextn);
  146. }
  147. return basefn;
  148. }
  149. void nDirListStor::sAppendSelfUrlInfoList(QUrlInfo curDirUrl)
  150. {
  151. if (curDirUrl.isValid() && curDirUrl.isReadable() && curDirUrl.isFile() && curDirUrl.size() > nMinFileSizeBytes && curDirUrl.size() < nMaxFileSizeBytes)
  152. {
  153. nDirFileListSL.append(curDirUrl.name());
  154. }
  155. else if (this->searchsymlinks && curDirUrl.isReadable() && curDirUrl.isSymLink())
  156. {
  157. nDirFileListSL.append(curDirUrl.name());
  158. }
  159. }
  160. unetbootin::unetbootin(QWidget *parent)
  161. : QWidget(parent)
  162. {
  163. setupUi(this);
  164. }
  165. bool unetbootin::ubninitialize(QList<QPair<QString, QString> > oppairs)
  166. {
  167. skipExtraction = false;
  168. redundanttopleveldir = false;
  169. isarch64 = false;
  170. islivecd = false;
  171. isnetinstall = false;
  172. ishdmedia = false;
  173. overwriteall = false;
  174. searchsymlinks = false;
  175. ignoreoutofspace = false;
  176. downloadFailed = false;
  177. exitOnCompletion = false;
  178. testingDownload = false;
  179. issalt = false;
  180. persistenceSpaceMB = 0;
  181. logFile = 0;
  182. logStream = 0;
  183. #ifdef Q_OS_MAC
  184. ignoreoutofspace = true;
  185. #endif
  186. dontgeneratesyslinuxcfg = false;
  187. #ifdef Q_OS_UNIX
  188. isext2 = false;
  189. #endif
  190. secondlayer->setEnabled(false);
  191. secondlayer->hide();
  192. firstlayer->setEnabled(true);
  193. firstlayer->show();
  194. this->setWindowTitle(UNETBOOTINB);
  195. overwriteall = false;
  196. #ifndef Q_OS_MAC
  197. typeselect->addItem(tr("Hard Disk"));
  198. #endif
  199. typeselect->addItem(tr("USB Drive"));
  200. diskimagetypeselect->addItem(tr("ISO"));
  201. diskimagetypeselect->addItem(tr("Floppy"));
  202. bool hideCustom = true;
  203. #ifdef NOEXTERN
  204. optionslayer->setEnabled(false);
  205. optionslayer->hide();
  206. radioFloppy->setEnabled(false);
  207. radioFloppy->hide();
  208. radioManual->setEnabled(false);
  209. radioManual->hide();
  210. intromessage->resize(intromessage->width(), intromessage->height() + 135);
  211. #endif
  212. #ifdef NOFLOPPY
  213. if (diskimagetypeselect->findText(tr("Floppy")) != -1)
  214. diskimagetypeselect->removeItem(diskimagetypeselect->findText(tr("Floppy")));
  215. #endif
  216. #ifdef NOISO
  217. if (diskimagetypeselect->findText(tr("ISO")) != -1)
  218. diskimagetypeselect->removeItem(diskimagetypeselect->findText(tr("ISO")));
  219. #endif
  220. #include "distrovercust.cpp"
  221. #ifdef STDUNETBOOTIN
  222. optionslayer->setEnabled(true);
  223. optionslayer->show();
  224. #include "distrover.cpp"
  225. #endif
  226. #include "customdistselect.cpp"
  227. #ifdef Q_OS_MAC
  228. resourceDir = QDir(QApplication::applicationDirPath());
  229. resourceDir.cdUp();
  230. resourceDir.cd("Resources");
  231. syslinuxcommand = resourceDir.absoluteFilePath("syslinux-mac");
  232. sevzcommand = resourceDir.absoluteFilePath("7z-mac");
  233. mke2fscommand = resourceDir.absoluteFilePath("mke2fs");
  234. fdiskcommand = locatecommand("fdisk", tr("either"), "util-linux");
  235. #endif
  236. #ifdef Q_OS_LINUX
  237. if (QFile::exists("/sbin/fdisk"))
  238. fdiskcommand = "/sbin/fdisk";
  239. else
  240. fdiskcommand = locatecommand("fdisk", tr("either"), "util-linux");
  241. if (QFile::exists("/bin/df"))
  242. dfcommand = "/bin/df";
  243. else
  244. dfcommand = locatecommand("df", tr("either"), "util-linux");
  245. if (QFile::exists("/sbin/sfdisk"))
  246. sfdiskcommand = "/sbin/sfdisk";
  247. else
  248. sfdiskcommand = locatecommand("sfdisk", tr("either"), "silent");
  249. if (QFile::exists("/lib/udev/vol_id"))
  250. volidcommand = "/lib/udev/vol_id";
  251. else
  252. volidcommand = locatecommand("vol_id", tr("either"), "silent");
  253. if (volidcommand.isEmpty())
  254. {
  255. if (QFile::exists("/sbin/blkid"))
  256. blkidcommand = "/sbin/blkid";
  257. else
  258. blkidcommand = locatecommand("blkid", tr("either"), "e2fsprogs");
  259. }
  260. else
  261. blkidcommand = "/sbin/blkid";
  262. if (QFile::exists("/sbin/mke2fs"))
  263. mke2fscommand = "/sbin/mke2fs";
  264. else
  265. mke2fscommand = locatecommand("mke2fs", tr("LiveUSB persistence"), "e2fsprogs");
  266. if (QFile::exists("/sbin/e2label"))
  267. e2labelcommand = "/sbin/e2label";
  268. else
  269. e2labelcommand = locatecommand("e2label", "Arch Linux", "e2fsprogs");
  270. if (QFile::exists("/usr/bin/mlabel"))
  271. mlabelcommand = "/usr/bin/mlabel";
  272. else
  273. mlabelcommand = locatecommand("mlabel", "Arch Linux", "mtools");
  274. syslinuxcommand = "/usr/bin/ubnsylnx";
  275. extlinuxcommand = "/usr/bin/ubnexlnx";
  276. #ifdef NOSTATIC
  277. if (QFile::exists("/usr/bin/syslinux"))
  278. syslinuxcommand = "/usr/bin/syslinux";
  279. else
  280. syslinuxcommand = locatecommand("syslinux", tr("FAT32-formatted USB drive"), "syslinux");
  281. if (QFile::exists("/usr/bin/extlinux"))
  282. extlinuxcommand = "/usr/bin/extlinux";
  283. else
  284. extlinuxcommand = locatecommand("extlinux", tr("EXT2-formatted USB drive"), "extlinux");
  285. #endif
  286. sevzcommand = locatecommand("7z", tr("either"), "p7zip-full");
  287. #endif
  288. ubntmpf = QDir::toNativeSeparators(QString("%1/").arg(QDir::tempPath()));
  289. #ifdef Q_OS_LINUX
  290. if (ubntmpf.isEmpty() || ubntmpf == "/")
  291. {
  292. ubntmpf = "/tmp/";
  293. }
  294. #endif
  295. if (typeselect->findText(tr("USB Drive")) != -1)
  296. typeselect->setCurrentIndex(typeselect->findText(tr("USB Drive")));
  297. #ifdef HDDINSTALL
  298. if (typeselect->findText(tr("Hard Disk")) != -1)
  299. typeselect->setCurrentIndex(typeselect->findText(tr("Hard Disk")));
  300. #endif
  301. for (QList<QPair<QString, QString> >::const_iterator i = oppairs.constBegin(); i < oppairs.constEnd(); ++i)
  302. {
  303. QString pfirst(i->first);
  304. QString psecond(i->second);
  305. if (pfirst.contains("method", Qt::CaseInsensitive))
  306. {
  307. if (psecond.contains("distribution", Qt::CaseInsensitive))
  308. this->radioDistro->setChecked(true);
  309. else if (psecond.contains("diskimage", Qt::CaseInsensitive))
  310. this->radioFloppy->setChecked(true);
  311. else if (psecond.contains("custom", Qt::CaseInsensitive))
  312. this->radioManual->setChecked(true);
  313. }
  314. else if (pfirst.contains("distribution", Qt::CaseInsensitive))
  315. {
  316. int distidx = this->distroselect->findText(psecond, Qt::MatchFixedString);
  317. if (distidx != -1)
  318. this->distroselect->setCurrentIndex(distidx);
  319. }
  320. else if (pfirst.contains("version", Qt::CaseInsensitive))
  321. {
  322. QStringList verlist = this->distroselect->itemData(this->distroselect->currentIndex()).value<QStringList>();
  323. for (int j = 2; j < verlist.size(); ++j)
  324. {
  325. if (verlist[j].contains(psecond, Qt::CaseInsensitive))
  326. {
  327. this->dverselect->setCurrentIndex(j-2);
  328. break;
  329. }
  330. }
  331. }
  332. else if (pfirst.contains("isofile", Qt::CaseInsensitive))
  333. {
  334. this->diskimagetypeselect->setCurrentIndex(diskimagetypeselect->findText(tr("ISO")));
  335. this->FloppyPath->setText(psecond);
  336. this->radioFloppy->setChecked(true);
  337. }
  338. else if (pfirst.contains("imgfile", Qt::CaseInsensitive))
  339. {
  340. this->diskimagetypeselect->setCurrentIndex(diskimagetypeselect->findText(tr("Floppy")));
  341. this->FloppyPath->setText(psecond);
  342. this->radioFloppy->setChecked(true);
  343. }
  344. else if (pfirst.contains("kernelfile", Qt::CaseInsensitive))
  345. {
  346. this->KernelPath->setText(psecond);
  347. }
  348. else if (pfirst.contains("initrdfile", Qt::CaseInsensitive))
  349. {
  350. this->InitrdPath->setText(psecond);
  351. }
  352. else if (pfirst.contains("cfgfile", Qt::CaseInsensitive))
  353. {
  354. QString cfgoptstxt = getcfgkernargs(psecond, "", QStringList(), QStringList());
  355. if (cfgoptstxt.isEmpty())
  356. {
  357. cfgoptstxt = getgrubcfgargs(psecond);
  358. }
  359. this->OptionEnter->setText(cfgoptstxt);
  360. }
  361. else if (pfirst.contains("kernelopts", Qt::CaseInsensitive))
  362. {
  363. this->OptionEnter->setText(psecond);
  364. }
  365. else if (pfirst.contains("installtype", Qt::CaseInsensitive))
  366. {
  367. if (psecond.contains("Hard", Qt::CaseInsensitive) || psecond.contains("HDD", Qt::CaseInsensitive))
  368. this->typeselect->setCurrentIndex(this->typeselect->findText(tr("Hard Disk")));
  369. else
  370. this->typeselect->setCurrentIndex(this->typeselect->findText(tr("USB Drive")));
  371. }
  372. else if (pfirst.contains("targetdrive", Qt::CaseInsensitive))
  373. {
  374. #ifdef Q_OS_WIN32
  375. if (!psecond.endsWith('\\'))
  376. {
  377. psecond = psecond + '\\';
  378. }
  379. #endif
  380. int driveidx = this->driveselect->findText(psecond, Qt::MatchFixedString);
  381. if (driveidx != -1)
  382. {
  383. this->driveselect->setCurrentIndex(driveidx);
  384. }
  385. else
  386. {
  387. this->driveselect->addItem(psecond);
  388. this->driveselect->setCurrentIndex(this->driveselect->findText(psecond, Qt::MatchFixedString));
  389. }
  390. }
  391. else if (pfirst.contains("showcustom", Qt::CaseInsensitive))
  392. {
  393. if (psecond.contains('y', Qt::CaseInsensitive))
  394. {
  395. hideCustom = false;
  396. }
  397. }
  398. else if (pfirst.contains("nodistro", Qt::CaseInsensitive))
  399. {
  400. if (psecond.contains('y', Qt::CaseInsensitive))
  401. {
  402. radioDistro->setEnabled(false);
  403. radioDistro->hide();
  404. distroselect->setEnabled(false);
  405. distroselect->hide();
  406. dverselect->setEnabled(false);
  407. dverselect->hide();
  408. intromessage->move(intromessage->x(), intromessage->y()-20);
  409. intromessage->resize(intromessage->width(), intromessage->height() + 20);
  410. }
  411. }
  412. else if (pfirst.contains("message", Qt::CaseInsensitive))
  413. {
  414. intromessage->setText(psecond);
  415. }
  416. else if (pfirst.contains("persistentspace", Qt::CaseInsensitive))
  417. {
  418. bool isInt = false;
  419. int numMBpersistentSpace = psecond.toInt(&isInt, 10);
  420. if (isInt)
  421. this->persistencevalue->setValue(numMBpersistentSpace);
  422. }
  423. else if (pfirst.contains("testingdownload", Qt::CaseInsensitive))
  424. {
  425. if (psecond.contains('y', Qt::CaseInsensitive))
  426. {
  427. testingDownload = true;
  428. exitOnCompletion = true;
  429. }
  430. }
  431. else if (pfirst.contains("exitoncompletion", Qt::CaseInsensitive))
  432. {
  433. if (psecond.contains('y', Qt::CaseInsensitive))
  434. {
  435. exitOnCompletion = true;
  436. }
  437. }
  438. else if (pfirst.contains("skipextraction", Qt::CaseInsensitive))
  439. {
  440. if (psecond.contains('y', Qt::CaseInsensitive))
  441. {
  442. skipExtraction = true;
  443. }
  444. }
  445. else if (pfirst.contains("autoinstall", Qt::CaseInsensitive))
  446. {
  447. if (psecond.contains('y', Qt::CaseInsensitive))
  448. {
  449. exitOnCompletion = true;
  450. overwriteall = true;
  451. return true;
  452. }
  453. }
  454. else if (pfirst.contains("action", Qt::CaseInsensitive))
  455. {
  456. if (psecond.contains("listdistros", Qt::CaseInsensitive))
  457. {
  458. for (int i = 1; i < this->distroselect->count(); ++i)
  459. {
  460. printf("%s\n", this->distroselect->itemText(i).toAscii().constData());
  461. }
  462. QApplication::exit();
  463. exit(0);
  464. }
  465. else if (psecond.contains("listversions", Qt::CaseInsensitive))
  466. {
  467. for (int i = 0; i < this->dverselect->count(); ++i)
  468. {
  469. printf("%s\n", this->dverselect->itemText(i).toAscii().constData());
  470. }
  471. QApplication::exit();
  472. exit(0);
  473. }
  474. }
  475. }
  476. if (hideCustom)
  477. {
  478. radioManual->setEnabled(false);
  479. radioManual->hide();
  480. labelkernel->setEnabled(false);
  481. labelkernel->hide();
  482. labelinitrd->setEnabled(false);
  483. labelinitrd->hide();
  484. labeloption->setEnabled(false);
  485. labeloption->hide();
  486. KernelFileSelector->setEnabled(false);
  487. KernelFileSelector->hide();
  488. InitrdFileSelector->setEnabled(false);
  489. InitrdFileSelector->hide();
  490. CfgFileSelector->setEnabled(false);
  491. CfgFileSelector->hide();
  492. OptionEnter->setEnabled(false);
  493. OptionEnter->hide();
  494. KernelPath->setEnabled(false);
  495. KernelPath->hide();
  496. InitrdPath->setEnabled(false);
  497. InitrdPath->hide();
  498. KernelFileSelector->setEnabled(false);
  499. KernelFileSelector->hide();
  500. InitrdFileSelector->setEnabled(false);
  501. InitrdFileSelector->hide();
  502. radioLayout->removeItem(verticalSpacer);
  503. }
  504. return false;
  505. }
  506. void unetbootin::on_distroselect_currentIndexChanged(int distroselectIndex)
  507. {
  508. dverselect->clear();
  509. if (distroselectIndex == -1)
  510. return;
  511. QStringList dverL = distroselect->itemData(distroselectIndex).value<QStringList>();
  512. for (int i = 2; i < dverL.size(); ++i)
  513. {
  514. if (!dverL.at(i).contains("someotherversion") && !dverL.at(i).isEmpty())
  515. dverselect->addItem(dverL.at(i));
  516. }
  517. if (dverselect->findText(dverL.at(0)) != -1)
  518. dverselect->setCurrentIndex(dverselect->findText(dverL.at(0)));
  519. intromessage->setText(dverL.at(1));
  520. radioDistro->setChecked(true);
  521. }
  522. void unetbootin::refreshdriveslist()
  523. {
  524. driveselect->clear();
  525. QStringList driveslist = listcurdrives();
  526. for (int i = 0; i < driveslist.size(); ++i)
  527. {
  528. driveselect->addItem(driveslist.at(i));
  529. }
  530. }
  531. QStringList unetbootin::listcurdrives()
  532. {
  533. return listsanedrives();
  534. }
  535. QStringList unetbootin::listsanedrives()
  536. {
  537. QStringList fulldrivelist;
  538. if (typeselect->currentText() == tr("Hard Disk"))
  539. {
  540. fulldrivelist.append(QDir::toNativeSeparators(QDir::rootPath()).toUpper());
  541. }
  542. else if (typeselect->currentText() == tr("USB Drive"))
  543. {
  544. #ifdef Q_OS_WIN32
  545. QFileInfoList extdrivesList = QDir::drives();
  546. for (int i = 0; i < extdrivesList.size(); ++i)
  547. {
  548. if (QDir::toNativeSeparators(extdrivesList.at(i).path().toUpper()) != QDir::toNativeSeparators(QDir::rootPath().toUpper()) && !QDir::toNativeSeparators(extdrivesList.at(i).path().toUpper()).contains("A:") && !QDir::toNativeSeparators(extdrivesList.at(i).path().toUpper()).contains("B:"))
  549. {
  550. if (GetDriveType(LPWSTR(extdrivesList.at(i).path().toUpper().utf16())) == 2)
  551. {
  552. fulldrivelist.append(QDir::toNativeSeparators(extdrivesList.at(i).path().toUpper()));
  553. }
  554. }
  555. }
  556. #endif
  557. #ifdef Q_OS_LINUX
  558. QDir devlstdir("/dev/disk/by-id/");
  559. QFileInfoList usbfileinfoL = devlstdir.entryInfoList(QDir::NoDotAndDotDot|QDir::Files);
  560. for (int i = 0; i < usbfileinfoL.size(); ++i)
  561. {
  562. // if (usbfileinfoL.at(i).contains(QRegExp("^usb-\\S{1,}-part\\d{1,}$")))
  563. // {
  564. // fulldrivelist.append(usbfileinfoL.at(i).canonicalFilePath());
  565. // }
  566. if (usbfileinfoL.at(i).fileName().contains(QRegExp("^usb-\\S{1,}$")) ||
  567. usbfileinfoL.at(i).fileName().contains(QRegExp("^mmc-\\S{1,}$")))
  568. {
  569. if (!volidcommand.isEmpty())
  570. {
  571. if (QString(callexternapp(volidcommand, QString("-t %2").arg(usbfileinfoL.at(i).canonicalFilePath()))).contains(QRegExp("(vfat|ext2|ext3|ext4)")))
  572. fulldrivelist.append(usbfileinfoL.at(i).canonicalFilePath());
  573. }
  574. else
  575. {
  576. QString tstrblk = QString(callexternapp(blkidcommand, QString("-s TYPE %2").arg(usbfileinfoL.at(i).canonicalFilePath())));
  577. if (tstrblk.contains('='))
  578. {
  579. if (tstrblk.section('=', -1, -1).remove('"').contains(QRegExp("(vfat|ext2|ext3|ext4)")))
  580. fulldrivelist.append(usbfileinfoL.at(i).canonicalFilePath());
  581. }
  582. }
  583. }
  584. }
  585. /*
  586. QString fdisklusbdevsS = callexternapp(fdiskcommand, "-l");
  587. QStringList usbdevsL = QString(fdisklusbdevsS).split("\n").filter(QRegExp("\\.{0,}FAT|Disk\\.{0,}")).join("\n").split(" ").join("\n").split("\t").join("\n").split("\n").filter("/dev/");
  588. for (int i = 0; i < usbdevsL.size(); ++i)
  589. {
  590. if (usbdevsL.at(i).contains(":"))
  591. {
  592. if (!QString(callexternapp(volidcommand, QString("-t %2").arg(QString(usbdevsL.at(i)).remove(":")))).contains("vfat"))
  593. continue;
  594. }
  595. fulldrivelist.append(QString(usbdevsL.at(i)).remove(":"));
  596. }
  597. */
  598. #endif
  599. #ifdef Q_OS_MAC
  600. QString diskutilList = callexternapp("diskutil", "list");
  601. QStringList usbdevsL = diskutilList.split("\n").filter(QRegExp("(FAT|Microsoft)")).join(" ").split(" ").filter("disk");
  602. for (int i = 0; i < usbdevsL.size(); ++i)
  603. {
  604. fulldrivelist.append("/dev/"+usbdevsL.at(i));
  605. }
  606. #endif
  607. }
  608. return fulldrivelist;
  609. }
  610. QStringList unetbootin::listalldrives()
  611. {
  612. QStringList fulldrivelist;
  613. #ifdef Q_OS_WIN32
  614. QFileInfoList extdrivesList = QDir::drives();
  615. for (int i = 0; i < extdrivesList.size(); ++i)
  616. {
  617. fulldrivelist.append(QDir::toNativeSeparators(extdrivesList.at(i).path().toUpper()));
  618. }
  619. #endif
  620. #ifdef Q_OS_LINUX
  621. QString fdisklusbdevsS = callexternapp(fdiskcommand, "-l");
  622. QString dflusbdevsS = callexternapp(dfcommand, "");
  623. fulldrivelist = QString(dflusbdevsS).split(" ").join("\n").split("\t").join("\n").split("\n").filter("/dev/");
  624. QStringList fulldrivelist2 = QString(fdisklusbdevsS).split(" ").join("\n").split("\t").join("\n").split("\n").filter("/dev/").replaceInStrings(":", "");
  625. for (int i = 0; i < fulldrivelist2.size(); ++i)
  626. {
  627. if (!fulldrivelist.contains(fulldrivelist2.at(i)))
  628. fulldrivelist.append(fulldrivelist2.at(i));
  629. }
  630. #endif
  631. #ifdef Q_OS_MAC
  632. return listsanedrives();
  633. #endif
  634. return fulldrivelist;
  635. }
  636. void unetbootin::on_typeselect_currentIndexChanged(int typeselectIndex)
  637. {
  638. refreshdriveslist();
  639. }
  640. void unetbootin::on_dverselect_currentIndexChanged()
  641. {
  642. radioDistro->setChecked(true);
  643. }
  644. void unetbootin::on_diskimagetypeselect_currentIndexChanged()
  645. {
  646. radioFloppy->setChecked(true);
  647. }
  648. void unetbootin::on_FloppyFileSelector_clicked()
  649. {
  650. QString nameFloppy = QDir::toNativeSeparators(QFileDialog::getOpenFileName(this, tr("Open Disk Image File"), QDir::homePath(), tr("All Files") + " (*);;" + tr("ISO") + " (*.iso);;" + tr("Floppy") + " (*.img)"));
  651. if (QFileInfo(nameFloppy).completeSuffix().contains("iso", Qt::CaseInsensitive))
  652. {
  653. if (diskimagetypeselect->findText(tr("ISO")) != -1)
  654. diskimagetypeselect->setCurrentIndex(diskimagetypeselect->findText(tr("ISO")));
  655. }
  656. if (QFileInfo(nameFloppy).completeSuffix().contains("img", Qt::CaseInsensitive) || QFileInfo(nameFloppy).completeSuffix().contains("flp", Qt::CaseInsensitive))
  657. {
  658. if (diskimagetypeselect->findText(tr("Floppy")) != -1)
  659. diskimagetypeselect->setCurrentIndex(diskimagetypeselect->findText(tr("Floppy")));
  660. }
  661. FloppyPath->clear();
  662. FloppyPath->insert(nameFloppy);
  663. radioFloppy->setChecked(true);
  664. }
  665. void unetbootin::on_KernelFileSelector_clicked()
  666. {
  667. QString nameKernel = QDir::toNativeSeparators(QFileDialog::getOpenFileName(this, tr("Open Kernel File"), QDir::homePath(), tr("All Files (*)")));
  668. KernelPath->clear();
  669. KernelPath->insert(nameKernel);
  670. radioManual->setChecked(true);
  671. }
  672. void unetbootin::on_InitrdFileSelector_clicked()
  673. {
  674. QString nameInitrd = QDir::toNativeSeparators(QFileDialog::getOpenFileName(this, tr("Open Initrd File"), QDir::homePath(), tr("All Files (*)")));
  675. InitrdPath->clear();
  676. InitrdPath->insert(nameInitrd);
  677. radioManual->setChecked(true);
  678. }
  679. void unetbootin::on_CfgFileSelector_clicked()
  680. {
  681. QString nameCfg = QFileDialog::getOpenFileName(this, tr("Open Bootloader Config File"), QDir::homePath(), tr("All Files (*)"));
  682. OptionEnter->clear();
  683. QString cfgoptstxt = getcfgkernargs(nameCfg, "", QStringList(), QStringList());
  684. if (cfgoptstxt.isEmpty())
  685. {
  686. cfgoptstxt = getgrubcfgargs(nameCfg);
  687. }
  688. OptionEnter->insert(cfgoptstxt);
  689. radioManual->setChecked(true);
  690. }
  691. void unetbootin::on_cancelbutton_clicked()
  692. {
  693. close();
  694. }
  695. void unetbootin::on_okbutton_clicked()
  696. {
  697. if (typeselect->currentIndex() == typeselect->findText(tr("USB Drive")) && driveselect->currentText().isEmpty())
  698. {
  699. QMessageBox unotenoughinputmsgb;
  700. unotenoughinputmsgb.setIcon(QMessageBox::Information);
  701. unotenoughinputmsgb.setWindowTitle(tr("Insert a USB flash drive"));
  702. unotenoughinputmsgb.setText(tr("No USB flash drives were found. If you have already inserted a USB drive, try reformatting it as FAT32."));
  703. unotenoughinputmsgb.setStandardButtons(QMessageBox::Ok);
  704. switch (unotenoughinputmsgb.exec())
  705. {
  706. case QMessageBox::Ok:
  707. break;
  708. default:
  709. break;
  710. }
  711. }
  712. #ifdef Q_OS_MAC
  713. if (locatemountpoint(driveselect->currentText()) == "NOT MOUNTED")
  714. callexternapp("diskutil", "mount "+driveselect->currentText());
  715. #endif
  716. #ifdef Q_OS_LINUX
  717. else if (typeselect->currentIndex() == typeselect->findText(tr("USB Drive")) && locatemountpoint(driveselect->currentText()) == "NOT MOUNTED")
  718. {
  719. QMessageBox merrordevnotmountedmsgbx;
  720. merrordevnotmountedmsgbx.setIcon(QMessageBox::Warning);
  721. merrordevnotmountedmsgbx.setWindowTitle(QString(tr("%1 not mounted")).arg(driveselect->currentText()));
  722. merrordevnotmountedmsgbx.setText(QString(tr("You must first mount the USB drive %1 to a mountpoint. Most distributions will do this automatically after you remove and reinsert the USB drive.")).arg(driveselect->currentText()));
  723. merrordevnotmountedmsgbx.setStandardButtons(QMessageBox::Ok);
  724. switch (merrordevnotmountedmsgbx.exec())
  725. {
  726. case QMessageBox::Ok:
  727. break;
  728. default:
  729. break;
  730. }
  731. }
  732. #endif
  733. else if (radioDistro->isChecked() && distroselect->currentIndex() == distroselect->findText(unetbootin::tr("== Select Distribution ==")))
  734. {
  735. QMessageBox dnotenoughinputmsgb;
  736. dnotenoughinputmsgb.setIcon(QMessageBox::Information);
  737. dnotenoughinputmsgb.setWindowTitle(tr("Select a distro"));
  738. dnotenoughinputmsgb.setText(tr("You must select a distribution to load."));
  739. dnotenoughinputmsgb.setStandardButtons(QMessageBox::Ok);
  740. switch (dnotenoughinputmsgb.exec())
  741. {
  742. case QMessageBox::Ok:
  743. break;
  744. default:
  745. break;
  746. }
  747. }
  748. else if (radioFloppy->isChecked() && FloppyPath->text().isEmpty())
  749. {
  750. QMessageBox fnotenoughinputmsgb;
  751. fnotenoughinputmsgb.setIcon(QMessageBox::Information);
  752. fnotenoughinputmsgb.setWindowTitle(tr("Select a disk image file"));
  753. fnotenoughinputmsgb.setText(tr("You must select a disk image file to load."));
  754. fnotenoughinputmsgb.setStandardButtons(QMessageBox::Ok);
  755. switch (fnotenoughinputmsgb.exec())
  756. {
  757. case QMessageBox::Ok:
  758. break;
  759. default:
  760. break;
  761. }
  762. }
  763. else if (radioManual->isChecked() && KernelPath->text().isEmpty())
  764. {
  765. QMessageBox knotenoughinputmsgb;
  766. knotenoughinputmsgb.setIcon(QMessageBox::Information);
  767. knotenoughinputmsgb.setWindowTitle(tr("Select a kernel and/or initrd file"));
  768. knotenoughinputmsgb.setText(tr("You must select a kernel and/or initrd file to load."));
  769. knotenoughinputmsgb.setStandardButtons(QMessageBox::Ok);
  770. switch (knotenoughinputmsgb.exec())
  771. {
  772. case QMessageBox::Ok:
  773. break;
  774. default:
  775. break;
  776. }
  777. }
  778. else if (radioFloppy->isChecked() && !QFile::exists(FloppyPath->text()) && !FloppyPath->text().startsWith("http://") && !FloppyPath->text().startsWith("ftp://"))
  779. {
  780. QMessageBox ffnotexistsmsgb;
  781. ffnotexistsmsgb.setIcon(QMessageBox::Information);
  782. ffnotexistsmsgb.setWindowTitle(tr("Diskimage file not found"));
  783. ffnotexistsmsgb.setText(tr("The specified diskimage file %1 does not exist.").arg(FloppyPath->text()));
  784. ffnotexistsmsgb.setStandardButtons(QMessageBox::Ok);
  785. switch (ffnotexistsmsgb.exec())
  786. {
  787. case QMessageBox::Ok:
  788. break;
  789. default:
  790. break;
  791. }
  792. }
  793. else if (radioManual->isChecked() && !QFile::exists(KernelPath->text()) && !KernelPath->text().startsWith("http://") && !KernelPath->text().startsWith("ftp://"))
  794. {
  795. QMessageBox kfnotexistsmsgb;
  796. kfnotexistsmsgb.setIcon(QMessageBox::Information);
  797. kfnotexistsmsgb.setWindowTitle(tr("Kernel file not found"));
  798. kfnotexistsmsgb.setText(tr("The specified kernel file %1 does not exist.").arg(KernelPath->text()));
  799. kfnotexistsmsgb.setStandardButtons(QMessageBox::Ok);
  800. switch (kfnotexistsmsgb.exec())
  801. {
  802. case QMessageBox::Ok:
  803. break;
  804. default:
  805. break;
  806. }
  807. }
  808. else if (radioManual->isChecked() && InitrdPath->text().trimmed() != "" && !QFile::exists(InitrdPath->text()) && !InitrdPath->text().startsWith("http://") && !InitrdPath->text().startsWith("ftp://"))
  809. {
  810. QMessageBox ifnotexistsmsgb;
  811. ifnotexistsmsgb.setIcon(QMessageBox::Information);
  812. ifnotexistsmsgb.setWindowTitle(tr("Initrd file not found"));
  813. ifnotexistsmsgb.setText(tr("The specified initrd file %1 does not exist.").arg(InitrdPath->text()));
  814. ifnotexistsmsgb.setStandardButtons(QMessageBox::Ok);
  815. switch (ifnotexistsmsgb.exec())
  816. {
  817. case QMessageBox::Ok:
  818. break;
  819. default:
  820. break;
  821. }
  822. }
  823. else
  824. {
  825. runinst();
  826. }
  827. }
  828. void unetbootin::on_fexitbutton_clicked()
  829. {
  830. close();
  831. }
  832. void unetbootin::on_frebootbutton_clicked()
  833. {
  834. sysreboot();
  835. }
  836. QString unetbootin::displayfisize(quint64 fisize)
  837. {
  838. if (fisize < 10000)
  839. {
  840. return QString("%1 B").arg(fisize);
  841. }
  842. else if (fisize < 10240000)
  843. {
  844. return QString("%1 KB").arg(fisize / 1024);
  845. }
  846. else
  847. {
  848. return QString("%1 MB").arg(fisize / 1048576);
  849. }
  850. }
  851. QPair<QPair<QStringList, QList<quint64> >, QStringList> unetbootin::listarchiveconts(QString archivefile)
  852. {
  853. #ifdef Q_OS_WIN32
  854. if (sevzcommand.isEmpty())
  855. {
  856. installsvzip();
  857. }
  858. randtmpfile tmplsF(ubntmpf, "ufl");
  859. callexternapp(getenv("COMSPEC"), QString("/c \"\"%1\" -bd -slt l \"%2\" > \"%3\"\"").arg(sevzcommand).arg(QFileInfo(archivefile).absoluteFilePath()).arg(QFileInfo(tmplsF).absoluteFilePath()));
  860. tmplsF.open(QIODevice::ReadOnly | QIODevice::Text);
  861. QTextStream tmplsS(&tmplsF);
  862. #endif
  863. #ifdef Q_OS_UNIX
  864. QString sevzlcommandout = callexternapp(sevzcommand, QString("-bd -slt l \"%1\"").arg(QFileInfo(archivefile).absoluteFilePath()));
  865. QTextStream tmplsS(&sevzlcommandout);
  866. #endif
  867. QString tmplsL;
  868. QStringList tmplsSLF;
  869. QStringList tmplsSLD;
  870. QList<quint64> tmplsSLFS;
  871. QString tmplsN;
  872. QString tmplsFS;
  873. while (!tmplsS.atEnd())
  874. {
  875. tmplsL = tmplsS.readLine();
  876. if (tmplsL.contains("Path = "))
  877. {
  878. if (tmplsL.contains("Path = [BOOT]"))
  879. continue;
  880. if (tmplsL == QString("Path = %1").arg(QFileInfo(archivefile).absoluteFilePath()))
  881. continue;
  882. if (tmplsL == QString("Path = %1").arg(QDir::toNativeSeparators(QFileInfo(archivefile).absoluteFilePath())))
  883. continue;
  884. tmplsN = tmplsS.readLine();
  885. if (tmplsN.contains("Folder = 1") || tmplsN.contains("Folder = +"))
  886. {
  887. tmplsSLD.append(tmplsL.remove("Path = "));
  888. }
  889. else
  890. {
  891. tmplsSLF.append(tmplsL.remove("Path = "));
  892. tmplsFS = QString(tmplsS.readLine()).remove("Size = ").trimmed();
  893. tmplsSLFS.append(tmplsFS.toULongLong());
  894. }
  895. }
  896. }
  897. #ifdef Q_OS_WIN32
  898. tmplsF.close();
  899. rmFile(tmplsF);
  900. #endif
  901. return qMakePair(qMakePair(tmplsSLF, tmplsSLFS), tmplsSLD);
  902. }
  903. bool unetbootin::overwritefileprompt(QString ovwfileloc)
  904. {
  905. if (overwriteall)
  906. {
  907. rmFile(ovwfileloc);
  908. return true;
  909. }
  910. QMessageBox overwritefilemsgbx;
  911. overwritefilemsgbx.setIcon(QMessageBox::Warning);
  912. overwritefilemsgbx.setWindowTitle(QString(tr("%1 exists, overwrite?")).arg(ovwfileloc));
  913. overwritefilemsgbx.setText(QString(tr("The file %1 already exists. Press 'Yes to All' to overwrite it and not be prompted again, 'Yes' to overwrite files on an individual basis, and 'No' to retain your existing version. If in doubt, press 'Yes to All'.")).arg(ovwfileloc));
  914. overwritefilemsgbx.setStandardButtons(QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No);
  915. switch (overwritefilemsgbx.exec())
  916. {
  917. case QMessageBox::Yes:
  918. {
  919. rmFile(ovwfileloc);
  920. return true;
  921. }
  922. case QMessageBox::YesToAll:
  923. {
  924. rmFile(ovwfileloc);
  925. overwriteall = true;
  926. return true;
  927. }
  928. case QMessageBox::No:
  929. return false;
  930. default:
  931. return false;
  932. }
  933. }
  934. bool unetbootin::ignoreoutofspaceprompt(QString destindir)
  935. {
  936. QMessageBox overwritefilemsgbx;
  937. overwritefilemsgbx.setIcon(QMessageBox::Warning);
  938. overwritefilemsgbx.setWindowTitle(QString(tr("%1 is out of space, abort installation?")).arg(destindir));
  939. overwritefilemsgbx.setText(QString(tr("The directory %1 is out of space. Press 'Yes' to abort installation, 'No' to ignore this error and attempt to continue installation, and 'No to All' to ignore all out-of-space errors.")).arg(destindir));
  940. overwritefilemsgbx.setStandardButtons(QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No);
  941. switch (overwritefilemsgbx.exec())
  942. {
  943. case QMessageBox::Yes:
  944. {
  945. QApplication::quit();
  946. return false;
  947. }
  948. case QMessageBox::No:
  949. {
  950. return true;
  951. }
  952. case QMessageBox::NoToAll:
  953. {
  954. this->ignoreoutofspace = true;
  955. return true;
  956. }
  957. default:
  958. return true;
  959. }
  960. }
  961. bool unetbootin::extractfile(QString filepath, QString destinfileL, QString archivefile)
  962. {
  963. #ifdef Q_OS_UNIX
  964. if (installType != tr("USB Drive") && filepath.contains("boot/grub")) // don't nuke grub config
  965. return false;
  966. #endif
  967. QString destindir = QFileInfo(destinfileL).dir().absolutePath();
  968. QString destinfilename = QString("%1/%2").arg(destindir).arg(QFileInfo(destinfileL).fileName());
  969. QString filepathfilename = QString("%1/%2").arg(destindir).arg(QFileInfo(filepath).fileName());
  970. if (QFile::exists(filepathfilename))
  971. {
  972. if (!overwritefileprompt(filepathfilename))
  973. return false;
  974. }
  975. if (QFile::exists(destinfilename))
  976. {
  977. if (!overwritefileprompt(destinfilename))
  978. return false;
  979. }
  980. #ifdef Q_OS_WIN32
  981. if (sevzcommand.isEmpty())
  982. {
  983. installsvzip();
  984. }
  985. #endif
  986. callexternapp(sevzcommand, QString("-bd -aos -o\"%1\" e \"%2\" \"%3\"").arg(QDir::toNativeSeparators(destindir), QDir::toNativeSeparators(archivefile), QDir::toNativeSeparators(filepath)));
  987. int retv;
  988. if (QFileInfo(filepathfilename).absoluteFilePath() == QFileInfo(destinfilename).absoluteFilePath())
  989. {
  990. retv = true;
  991. }
  992. else
  993. {
  994. retv = QFile::rename(filepathfilename, destinfilename);
  995. }
  996. this->checkifoutofspace(destindir);
  997. return retv;
  998. }
  999. bool unetbootin::checkifoutofspace(QString destindir)
  1000. {
  1001. if (ignoreoutofspace == true)
  1002. return false;
  1003. bool outofspace = false;
  1004. #ifdef Q_OS_UNIX
  1005. struct statfs diskstatS;
  1006. if (!statfs(QString(destindir+"/.").toAscii(), &diskstatS))
  1007. {
  1008. if (diskstatS.f_bavail * diskstatS.f_bfree < 1024)
  1009. outofspace = true;
  1010. }
  1011. #endif
  1012. #ifdef Q_OS_WIN32
  1013. ULARGE_INTEGER FreeBytesAvailable;
  1014. ULARGE_INTEGER TotalNumberOfBytes;
  1015. ULARGE_INTEGER TotalNumberOfFreeBytes;
  1016. if (GetDiskFreeSpaceExA(destindir.toAscii(), &FreeBytesAvailable, &TotalNumberOfBytes, &TotalNumberOfFreeBytes))
  1017. {
  1018. if (FreeBytesAvailable.QuadPart < 1024)
  1019. outofspace = true;
  1020. }
  1021. #endif
  1022. if (outofspace == true)
  1023. {
  1024. return !ignoreoutofspaceprompt(destindir);
  1025. }
  1026. return false;
  1027. }
  1028. QString unetbootin::locatekernel(QString archivefile, QPair<QStringList, QList<quint64> > archivefileconts)
  1029. {
  1030. pdesc1->setText(tr("Locating kernel file in %1").arg(archivefile));
  1031. if (issalt) {
  1032. // The grub2 boot loader is return,
  1033. // it is prepended with a Linux header,
  1034. // so that syslinux can chainload to it.
  1035. // The embeded configuration file will find the correct prefix using the .live file at the root of the USB key.
  1036. return "boot/grub2-linux.img";
  1037. }
  1038. else
  1039. {
  1040. QStringList kernelnames = QStringList() << "vmlinuz" << "vmlinux" << "bzImage" << "kernel" << "sabayon" << "gentoo" << "linux26" << "linux24" << "bsd" << "unix" << "linux" << "rescue" << "xpud" << "bzI" << "kexec" << "vmlinuz.efi";
  1041. QStringList tnarchivefileconts;
  1042. QStringList narchivefileconts;
  1043. QString curarcitm;
  1044. for (int i = 0; i < archivefileconts.second.size(); ++i)
  1045. {
  1046. // curarcitm = archivefileconts.first.at(i).right(archivefileconts.first.at(i).size() - archivefileconts.first.at(i).lastIndexOf(QDir::toNativeSeparators("/")) - 1);
  1047. // if (curarcitm.contains("isolinux", Qt::CaseInsensitive) || curarcitm.contains("memtest", Qt::CaseInsensitive) || curarcitm.contains("system.map", Qt::CaseInsensitive) || curarcitm.contains(".efimg", Qt::CaseInsensitive) || curarcitm.contains(".jpg", Qt::CaseInsensitive) || curarcitm.contains(".png", Qt::CaseInsensitive) || curarcitm.contains(".pdf", Qt::CaseInsensitive) || curarcitm.contains(".txt", Qt::CaseInsensitive) || curarcitm.contains(".pcx", Qt::CaseInsensitive) || curarcitm.contains(".rle", Qt::CaseInsensitive) || curarcitm.contains(".fnt", Qt::CaseInsensitive) || curarcitm.contains(".msg", Qt::CaseInsensitive) || curarcitm.contains(".cat", Qt::CaseInsensitive) || curarcitm.contains(".tar", Qt::CaseInsensitive) || curarcitm.contains(".psd", Qt::CaseInsensitive) || curarcitm.contains(".xcf", Qt::CaseInsensitive) || curarcitm.contains(".bmp", Qt::CaseInsensitive) || curarcitm.contains(".svg", Qt::CaseInsensitive))
  1048. // {
  1049. // continue;
  1050. // }
  1051. // if (filteroutlist(curarcitm, ignoredtypesbothRL+ignoredtypeskernelRL).isEmpty())
  1052. // {
  1053. // continue;
  1054. // }
  1055. if (archivefileconts.second.at(i) > 614400 && archivefileconts.second.at(i) < 20971520) // between 600 KB and 20 MB
  1056. {
  1057. tnarchivefileconts.append(archivefileconts.first.at(i));
  1058. }
  1059. }
  1060. narchivefileconts = filteroutlistL(tnarchivefileconts, ignoredtypesbothRL+ignoredtypeskernelRL);
  1061. for (int i = 0; i < kernelnames.size(); ++i)
  1062. {
  1063. for (int j = 0; j < narchivefileconts.size(); ++j)
  1064. {
  1065. if (narchivefileconts.at(j).right(narchivefileconts.at(j).size() - narchivefileconts.at(j).lastIndexOf(QDir::toNativeSeparators("/")) - 1).contains(kernelnames.at(i), Qt::CaseInsensitive))
  1066. {
  1067. return narchivefileconts.at(j);
  1068. }
  1069. }
  1070. }
  1071. pdesc1->setText("");
  1072. return "";
  1073. }
  1074. }
  1075. bool unetbootin::extractkernel(QString archivefile, QString kernoutputfile, QPair<QStringList, QList<quint64> > archivefileconts)
  1076. {
  1077. QString kfloc = locatekernel(archivefile, archivefileconts);
  1078. if (kfloc == "")
  1079. return false;
  1080. pdesc1->setText(tr("Copying kernel file from %1").arg(kfloc));
  1081. return extractfile(kfloc, kernoutputfile, archivefile);
  1082. }
  1083. QString unetbootin::locateinitrd(QString archivefile, QPair<QStringList, QList<quint64> > archivefileconts)
  1084. {
  1085. pdesc1->setText(tr("Locating initrd file in %1").arg(archivefile));
  1086. QStringList kernelnames = QStringList() << "initrd.img.gz" << "initrd.lz" << "initrd.igz" << "initrd.gz" << "initrd.xz" << "initrd.lzma" << "initrd.img" << "initramfs.gz" << "initramfs.img" << "initrd" << "initramfs" << "minirt" << "miniroot" << "sabayon.igz" << "gentoo.igz" << "archlive.img" << "rootfs.gz" << ".igz" << ".cgz" << ".img" << "rootfs" << "fs.gz" << "root.gz" << ".gz" << "initram" << "initr" << "init" << "ram" << ".lz" << ".lzma" << ".xz";
  1087. QStringList tnarchivefileconts;
  1088. QStringList narchivefileconts;
  1089. QString curarcitm;
  1090. for (int i = 0; i < archivefileconts.second.size(); ++i)
  1091. {
  1092. curarcitm = archivefileconts.first.at(i).right(archivefileconts.first.at(i).size() - archivefileconts.first.at(i).lastIndexOf(QDir::toNativeSeparators("/")) - 1);
  1093. // if (curarcitm.contains("isolinux", Qt::CaseInsensitive) || curarcitm.contains("memtest", Qt::CaseInsensitive) || curarcitm.contains("system.map", Qt::CaseInsensitive) || curarcitm.contains(".efimg", Qt::CaseInsensitive) || curarcitm.contains(".jpg", Qt::CaseInsensitive) || curarcitm.contains(".png", Qt::CaseInsensitive) || curarcitm.contains(".pdf", Qt::CaseInsensitive) || curarcitm.contains(".txt", Qt::CaseInsensitive) || curarcitm.contains(".pcx", Qt::CaseInsensitive) || curarcitm.contains(".rle", Qt::CaseInsensitive) || curarcitm.contains(".fnt", Qt::CaseInsensitive) || curarcitm.contains(".msg", Qt::CaseInsensitive) || curarcitm.contains(".cat", Qt::CaseInsensitive) || curarcitm.contains(".tar", Qt::CaseInsensitive) || curarcitm.contains(".psd", Qt::CaseInsensitive) || curarcitm.contains(".xcf", Qt::CaseInsensitive) || curarcitm.contains(".bmp", Qt::CaseInsensitive) || curarcitm.contains(".svg", Qt::CaseInsensitive))
  1094. // {
  1095. // continue;
  1096. // }
  1097. // if (filteroutlist(curarcitm, ignoredtypesbothRL+ignoredtypesinitrdRL).isEmpty())
  1098. // {
  1099. // continue;
  1100. // }
  1101. if (archivefileconts.second.at(i) >= 128000 && archivefileconts.second.at(i) < 314572800) // between 128 KB and 300 MB
  1102. {
  1103. tnarchivefileconts.append(archivefileconts.first.at(i));
  1104. }
  1105. }
  1106. narchivefileconts = filteroutlistL(tnarchivefileconts, ignoredtypesbothRL+ignoredtypesinitrdRL);
  1107. for (int i = 0; i < kernelnames.size(); ++i)
  1108. {
  1109. for (int j = 0; j < narchivefileconts.size(); ++j)
  1110. {
  1111. if (narchivefileconts.at(j).right(narchivefileconts.at(j).size() - narchivefileconts.at(j).lastIndexOf(QDir::toNativeSeparators("/")) - 1).contains(kernelnames.at(i), Qt::CaseInsensitive))
  1112. {
  1113. return narchivefileconts.at(j);
  1114. }
  1115. }
  1116. }
  1117. pdesc1->setText("");
  1118. return "";
  1119. }
  1120. bool unetbootin::extractinitrd(QString archivefile, QString kernoutputfile, QPair<QStringList, QList<quint64> > archivefileconts)
  1121. {
  1122. QString kfloc = locateinitrd(archivefile, archivefileconts);
  1123. if (kfloc == "")
  1124. return false;
  1125. pdesc1->setText(tr("Copying initrd file from %1").arg(kfloc));
  1126. return extractfile(kfloc, kernoutputfile, archivefile);
  1127. }
  1128. QString unetbootin::extractcfg(QString archivefile, QStringList archivefileconts)
  1129. {
  1130. pdesc1->setText(tr("Extracting bootloader configuration"));
  1131. QString saltpcfg;
  1132. QString grubpcfg;
  1133. QString syslinuxpcfg;
  1134. QStringList saltdetectfiles = QStringList() << "boot/grub2-linux.img" << "boot/grub/salt.env";
  1135. QStringList grubcfgtypes = QStringList() << "menu.lst" << "grub.conf";
  1136. QStringList mlstfoundfiles;
  1137. int saltDetected = 0; // must be equals to saltdetectfiles.size() to be considered as detected
  1138. for (int i = 0; i < saltdetectfiles.size(); ++i)
  1139. {
  1140. mlstfoundfiles = archivefileconts.filter(saltdetectfiles.at(i), Qt::CaseInsensitive);
  1141. if (!mlstfoundfiles.isEmpty())
  1142. {
  1143. saltDetected++;
  1144. }
  1145. }
  1146. if (saltDetected == saltdetectfiles.size()) {
  1147. saltpcfg = SALT_DETECTED; // not a real config, but used to inform that SaLT has been detected.
  1148. }
  1149. else
  1150. {
  1151. for (int i = 0; i < grubcfgtypes.size(); ++i)
  1152. {
  1153. mlstfoundfiles = archivefileconts.filter(grubcfgtypes.at(i), Qt::CaseInsensitive);
  1154. if (!mlstfoundfiles.isEmpty())
  1155. {
  1156. for (int j = 0; j < mlstfoundfiles.size(); ++j)
  1157. {
  1158. randtmpfile mlstftf(ubntmpf, "lst");
  1159. extractfile(archivefileconts.filter(grubcfgtypes.at(i), Qt::CaseInsensitive).at(j), mlstftf.fileName(), archivefile);
  1160. grubpcfg = getgrubcfgargs(mlstftf.fileName()).trimmed();
  1161. rmFile(mlstftf);
  1162. if (!grubpcfg.isEmpty())
  1163. break;
  1164. }
  1165. }
  1166. if (!grubpcfg.isEmpty())
  1167. break;
  1168. }
  1169. QStringList syslinuxcfgtypes = QStringList() << "syslinux.cfg" << "isolinux.cfg" << "extlinux.cfg" << "pxelinux.cfg" << "grubenv" << "menu_en.cfg" << "en.cfg" << "extlinux.conf" << "grub.cfg" << ".cfg";
  1170. QStringList lcfgfoundfiles;
  1171. for (int i = 0; i < syslinuxcfgtypes.size(); ++i)
  1172. {
  1173. lcfgfoundfiles = archivefileconts.filter(syslinuxcfgtypes.at(i), Qt::CaseInsensitive);
  1174. if (!lcfgfoundfiles.isEmpty())
  1175. {
  1176. for (int j = 0; j < lcfgfoundfiles.size(); ++j)
  1177. {
  1178. randtmpfile ccfgftf(ubntmpf, "cfg");
  1179. extractfile(archivefileconts.filter(syslinuxcfgtypes.at(i), Qt::CaseInsensitive).at(j), ccfgftf.fileName(), archivefile);
  1180. if (lcfgfoundfiles.at(j).contains("grubenv"))
  1181. loadgrub2env(ccfgftf.fileName());
  1182. else if (lcfgfoundfiles.at(j).contains("grub"))
  1183. syslinuxpcfg = getgrub2cfgargs(ccfgftf.fileName(), archivefile, archivefileconts, QStringList() << lcfgfoundfiles.at(j)).trimmed();
  1184. else
  1185. syslinuxpcfg = getcfgkernargs(ccfgftf.fileName(), archivefile, archivefileconts, QStringList() << lcfgfoundfiles.at(j)).trimmed();
  1186. rmFile(ccfgftf);
  1187. if (!syslinuxpcfg.isEmpty())
  1188. break;
  1189. }
  1190. }
  1191. if (!syslinuxpcfg.isEmpty())
  1192. break;
  1193. }
  1194. }
  1195. if (!saltpcfg.isEmpty()) {
  1196. return saltpcfg;
  1197. }
  1198. else if (syslinuxpcfg.isEmpty())
  1199. {
  1200. return grubpcfg;
  1201. }
  1202. else
  1203. {
  1204. return syslinuxpcfg;
  1205. }
  1206. }
  1207. QPair<QPair<QStringList, QStringList>, QPair<QStringList, QStringList> > unetbootin::extractcfgL(QString archivefile, QStringList archivefileconts)
  1208. {
  1209. pdesc1->setText(tr("Extracting bootloader configuration"));
  1210. QPair<QPair<QStringList, QStringList>, QPair<QStringList, QStringList> > grubpcfgPL;
  1211. QPair<QPair<QStringList, QStringList>, QPair<QStringList, QStringList> > syslinuxpcfgPL;
  1212. QPair<QPair<QStringList, QStringList>, QPair<QStringList, QStringList> > combinedcfgPL;
  1213. QPair<QPair<QStringList, QStringList>, QPair<QStringList, QStringList> > filteredcfgPL;
  1214. QStringList grubcfgtypes = QStringList() << "menu.lst" << "grub.conf";
  1215. QStringList mlstfoundfiles;
  1216. for (int i = 0; i < grubcfgtypes.size(); ++i)
  1217. {
  1218. mlstfoundfiles = archivefileconts.filter(grubcfgtypes.at(i), Qt::CaseInsensitive);
  1219. if (!mlstfoundfiles.isEmpty())
  1220. {
  1221. for (int j = 0; j < mlstfoundfiles.size(); ++j)
  1222. {
  1223. randtmpfile mlstftf(ubntmpf, "lst");
  1224. extractfile(archivefileconts.filter(grubcfgtypes.at(i), Qt::CaseInsensitive).at(j), mlstftf.fileName(), archivefile);
  1225. grubpcfgPL = getgrubcfgargsL(mlstftf.fileName());
  1226. rmFile(mlstftf);
  1227. combinedcfgPL.first.first += grubpcfgPL.first.first;
  1228. combinedcfgPL.first.second += grubpcfgPL.first.second;
  1229. combinedcfgPL.second.first += grubpcfgPL.second.first;
  1230. combinedcfgPL.second.second += grubpcfgPL.second.second;
  1231. // if (!grubpcfg.isEmpty())
  1232. // break;
  1233. }
  1234. }
  1235. // if (!grubpcfg.isEmpty())
  1236. // break;
  1237. }
  1238. QStringList syslinuxcfgtypes = QStringList() << "syslinux.cfg" << "isolinux.cfg" << "extlinux.cfg" << "pxelinux.cfg" << "grubenv" << "extlinux.conf" << "grub.cfg";
  1239. QStringList lcfgfoundfiles;
  1240. for (int i = 0; i < syslinuxcfgtypes.size(); ++i)
  1241. {
  1242. lcfgfoundfiles = archivefileconts.filter(syslinuxcfgtypes.at(i), Qt::CaseInsensitive);
  1243. if (!lcfgfoundfiles.isEmpty())
  1244. {
  1245. for (int j = 0; j < lcfgfoundfiles.size(); ++j)
  1246. {
  1247. randtmpfile ccfgftf(ubntmpf, "cfg");
  1248. extractfile(archivefileconts.filter(syslinuxcfgtypes.at(i), Qt::CaseInsensitive).at(j), ccfgftf.fileName(), archivefile);
  1249. if (lcfgfoundfiles.at(j).contains("grubenv"))
  1250. loadgrub2env(ccfgftf.fileName());
  1251. else if (lcfgfoundfiles.at(j).contains("grub"))
  1252. syslinuxpcfgPL = getgrub2cfgargsL(ccfgftf.fileName(), archivefile, archivefileconts, QStringList() << lcfgfoundfiles.at(j));
  1253. else
  1254. syslinuxpcfgPL = getcfgkernargsL(ccfgftf.fileName(), archivefile, archivefileconts, QStringList() << lcfgfoundfiles.at(j));
  1255. rmFile(ccfgftf);
  1256. combinedcfgPL.first.first += syslinuxpcfgPL.first.first;
  1257. combinedcfgPL.first.second += syslinuxpcfgPL.first.second;
  1258. combinedcfgPL.second.first += syslinuxpcfgPL.second.first;
  1259. combinedcfgPL.second.second += syslinuxpcfgPL.second.second;
  1260. // if (!syslinuxpcfg.isEmpty())
  1261. // break;
  1262. }
  1263. }
  1264. // if (!syslinuxpcfg.isEmpty())
  1265. // break;
  1266. }
  1267. /*
  1268. if (syslinuxpcfg.isEmpty())
  1269. {
  1270. return grubpcfg;
  1271. }
  1272. else
  1273. {
  1274. return syslinuxpcfg;
  1275. }
  1276. */
  1277. #ifdef NOINITRD
  1278. for (int i = 0; i < combinedcfgPL.first.second.size(); ++i)
  1279. {
  1280. combinedcfgPL.first.second[i] = "";
  1281. }
  1282. for (int i = 0; i < combinedcfgPL.second.second.size(); ++i)
  1283. {
  1284. combinedcfgPL.second.second[i] = "";
  1285. }
  1286. #endif
  1287. for (int i = 0; i < combinedcfgPL.first.first.size(); ++i)
  1288. {
  1289. bool isduplicate = false;
  1290. for (int j = 0; j < filteredcfgPL.second.first.size(); ++j)
  1291. {
  1292. if (filteredcfgPL.second.first.at(j) == combinedcfgPL.second.first.at(i)) // duplicate title
  1293. {
  1294. isduplicate = true;
  1295. break;
  1296. }
  1297. }
  1298. if (isduplicate)
  1299. continue;
  1300. if (combinedcfgPL.first.first.at(i) == kernelLoc && combinedcfgPL.first.second.at(i) == initrdLoc && combinedcfgPL.second.first.at(i).contains("Untitled Entry") && combinedcfgPL.second.second.at(i).isEmpty())
  1301. continue;
  1302. // else if (filteredcfgPL.second.first.contains(combinedcfgPL.second.first.at(i)))
  1303. // continue;
  1304. else
  1305. {
  1306. if (combinedcfgPL.first.first.at(i).isEmpty())
  1307. filteredcfgPL.first.first.append(kernelLoc);
  1308. else
  1309. {
  1310. QString indvkrnloc = getfullarchivepath(combinedcfgPL.first.first.at(i), archivefileconts);
  1311. if (indvkrnloc.isEmpty())
  1312. filteredcfgPL.first.first.append(kernelLoc);
  1313. else
  1314. filteredcfgPL.first.first.append(indvkrnloc);
  1315. }
  1316. // filteredcfgPL.first.first.append(combinedcfgPL.first.first.at(i));
  1317. if (combinedcfgPL.first.second.at(i).isEmpty())
  1318. filteredcfgPL.first.second.append(kernelLoc);
  1319. else
  1320. {
  1321. QString indvitrloc = getfullarchivepath(combinedcfgPL.first.second.at(i), archivefileconts);
  1322. if (indvitrloc.isEmpty())
  1323. {
  1324. filteredcfgPL.first.second.append(initrdLoc);
  1325. }
  1326. else
  1327. filteredcfgPL.first.second.append(indvitrloc);
  1328. }
  1329. // filteredcfgPL.first.second.append(combinedcfgPL.first.second.at(i));
  1330. filteredcfgPL.second.first.append(combinedcfgPL.second.first.at(i));
  1331. filteredcfgPL.second.second.append(combinedcfgPL.second.second.at(i));
  1332. }
  1333. }
  1334. if (redundanttopleveldir && !redundantrootdirname.isEmpty())
  1335. {
  1336. for (int i = 0; i < filteredcfgPL.first.second.size(); ++i)
  1337. {
  1338. if (filteredcfgPL.first.second.at(i).startsWith(redundantrootdirname))
  1339. {
  1340. filteredcfgPL.first.second[i] = filteredcfgPL.first.second[i].mid(redundantrootdirname.length());
  1341. }
  1342. if (filteredcfgPL.first.second.at(i).startsWith("/" + redundantrootdirname))
  1343. {
  1344. filteredcfgPL.first.second[i] = filteredcfgPL.first.second[i].mid(redundantrootdirname.length() + 1);
  1345. }
  1346. }
  1347. }
  1348. return filteredcfgPL;
  1349. }
  1350. QString unetbootin::getfullarchivepath(QString relativefilepath, QStringList archivefile)
  1351. {
  1352. QStringList pfoundmatches;
  1353. relativefilepath = QDir::fromNativeSeparators(relativefilepath);
  1354. if (relativefilepath.endsWith('/'))
  1355. relativefilepath = relativefilepath.left(relativefilepath.size()-1);
  1356. if (!relativefilepath.startsWith('/'))
  1357. relativefilepath = QString("/%1").arg(relativefilepath);
  1358. // if (!relativefilepath.endsWith('/'))
  1359. // relativefilepath = QString("%1/").arg(relativefilepath);
  1360. for (int i = 0; i < archivefile.size(); ++i)
  1361. {
  1362. QString curarchiveitem = QDir::fromNativeSeparators(archivefile.at(i));
  1363. if (curarchiveitem.endsWith('/'))
  1364. curarchiveitem = curarchiveitem.left(curarchiveitem.size()-1);
  1365. if (!curarchiveitem.startsWith('/'))
  1366. curarchiveitem = QString("/%1").arg(curarchiveitem);
  1367. // if (!curarchiveitem.endsWith('/'))
  1368. // curarchiveitem = QString("%1/").arg(curarchiveitem);
  1369. if (curarchiveitem.contains(QRegExp(relativefilepath+"$", Qt::CaseInsensitive)))
  1370. pfoundmatches.append(curarchiveitem);
  1371. }
  1372. if (pfoundmatches.isEmpty())
  1373. return "";
  1374. else
  1375. {
  1376. return filteroutlist(pfoundmatches, ignoredtypesbothRL);
  1377. }
  1378. }
  1379. QString unetbootin::filteroutlist(QString listofdata, QList<QRegExp> listofmatches)
  1380. {
  1381. if (listofdata.isEmpty())
  1382. return "";
  1383. return filteroutlist(QStringList() << listofdata, listofmatches);
  1384. }
  1385. QString unetbootin::filteroutlist(QStringList listofdata, QList<QRegExp> listofmatches)
  1386. {
  1387. if (listofdata.isEmpty())
  1388. return "";
  1389. QStringList fldatalist = filteroutlistL(listofdata, listofmatches);
  1390. if (!fldatalist.isEmpty())
  1391. return fldatalist.at(0);
  1392. else
  1393. return "";
  1394. }
  1395. QStringList unetbootin::filteroutlistL(QStringList listofdata, QList<QRegExp> listofmatches)
  1396. {
  1397. if (listofdata.isEmpty())
  1398. return QStringList();
  1399. if (listofmatches.isEmpty())
  1400. return listofdata;
  1401. if (listofdata.size() == 1)
  1402. return listofdata;
  1403. QStringList newlistofdata;
  1404. for (int i = 0; i < listofdata.size(); ++i)
  1405. {
  1406. if (!listofdata.at(i).contains(listofmatches.at(0)))
  1407. newlistofdata.append(listofdata.at(i));
  1408. }
  1409. // QStringList newlistofdata = QStringList(listofdata).filter(listofmatches.at(0));
  1410. listofmatches.removeAt(0);
  1411. if (newlistofdata.isEmpty())
  1412. {
  1413. return filteroutlistL(listofdata, listofmatches);
  1414. }
  1415. else
  1416. {
  1417. return filteroutlistL(newlistofdata, listofmatches);
  1418. }
  1419. }
  1420. void unetbootin::extractiso(QString isofile)
  1421. {
  1422. if (!sdesc2->text().contains(trcurrent))
  1423. {
  1424. sdesc1->setText(QString(sdesc1->text()).remove("<b>").replace(trcurrent+"</b>", trdone));
  1425. sdesc2->setText(QString("<b>%1 %2</b>").arg(sdesc2->text()).arg(trcurrent));
  1426. }
  1427. tprogress->setValue(0);
  1428. QPair<QPair<QStringList, QList<quint64> >, QStringList> listfilesizedirpair = listarchiveconts(isofile);
  1429. if (listfilesizedirpair.first.first.size() == 1)
  1430. {
  1431. QString subarchivename = listfilesizedirpair.first.first.at(0);
  1432. randtmpfile tmpoutsubarchive(ubntmpf, subarchivename.right(3));
  1433. pdesc1->setText(tr("<b>Extracting compressed iso:</b> %1").arg(subarchivename));
  1434. extractfile(subarchivename, tmpoutsubarchive.fileName(), isofile);
  1435. return extractiso(tmpoutsubarchive.fileName());
  1436. }
  1437. if (listfilesizedirpair.first.first.contains(QDir::toNativeSeparators("rescue/KRD.VERSION"), Qt::CaseInsensitive))
  1438. {
  1439. return extractiso_krd10(isofile);
  1440. }
  1441. QFileInfo isofileFI(isofile);
  1442. qint64 isofileSize = isofileFI.size();
  1443. if (listfilesizedirpair.first.first.size() < 10 && isofileSize > 12)
  1444. {
  1445. bool foundiso = false;
  1446. quint64 isofileSizeOneFourth = isofileSize / 4;
  1447. quint64 isofileSizeThreeFourth = isofileSizeOneFourth * 3;
  1448. for (int i = 0; i < listfilesizedirpair.first.first.size() && i < listfilesizedirpair.first.second.size(); ++i)
  1449. {
  1450. if (listfilesizedirpair.first.first.at(i).contains(QRegExp(".iso$", Qt::CaseInsensitive)))
  1451. {
  1452. if (foundiso)
  1453. break;
  1454. foundiso = true;
  1455. if (listfilesizedirpair.first.second.at(i) > isofileSizeThreeFourth)
  1456. {
  1457. QString subarchivename = listfilesizedirpair.first.first.at(i);
  1458. randtmpfile tmpoutsubarchive(ubntmpf, subarchivename.right(3));
  1459. pdesc1->setText(tr("<b>Extracting compressed iso:</b> %1").arg(subarchivename));
  1460. extractfile(subarchivename, tmpoutsubarchive.fileName(), isofile);
  1461. return extractiso(tmpoutsubarchive.fileName());
  1462. }
  1463. }
  1464. }
  1465. }
  1466. QStringList filepathnames = listfilesizedirpair.first.first;
  1467. QStringList directorypathnames;
  1468. if (listfilesizedirpair.second.size() > 0)
  1469. {
  1470. redundanttopleveldir = true;
  1471. redundantrootdirname = listfilesizedirpair.second.at(0);
  1472. for (int i = 0; i < listfilesizedirpair.second.size(); ++i)
  1473. {
  1474. if (listfilesizedirpair.second.at(i).size() < redundantrootdirname.size())
  1475. redundantrootdirname = listfilesizedirpair.second.at(i);
  1476. }
  1477. if (redundantrootdirname == "boot" ||
  1478. redundantrootdirname == "syslinux" ||
  1479. redundantrootdirname == "grub" ||
  1480. redundantrootdirname == "isolinux" ||
  1481. redundantrootdirname == "extlinux" ||
  1482. redundantrootdirname == "pxelinux")
  1483. redundanttopleveldir = false;
  1484. for (int i = 0; i < listfilesizedirpair.second.size(); ++i) // redundant toplevel path in dirs
  1485. {
  1486. if (!listfilesizedirpair.second.at(i).startsWith(redundantrootdirname))
  1487. redundanttopleveldir = false;
  1488. }
  1489. if (redundanttopleveldir)
  1490. {
  1491. for (int i = 0; i < listfilesizedirpair.first.first.size(); ++i) // redundant toplevel path in files
  1492. {
  1493. if (!listfilesizedirpair.first.first.at(i).startsWith(redundantrootdirname))
  1494. redundanttopleveldir = false;
  1495. }
  1496. }
  1497. if (redundanttopleveldir)
  1498. {
  1499. int rmnumcharsrootdir = redundantrootdirname.size();
  1500. for (int i = 0; i < listfilesizedirpair.second.size(); ++i)
  1501. {
  1502. QString tmpdirectpath = listfilesizedirpair.second[i];
  1503. tmpdirectpath.remove(0, rmnumcharsrootdir);
  1504. if (tmpdirectpath.startsWith("/") || tmpdirectpath.startsWith(QDir::toNativeSeparators("/")))
  1505. {
  1506. tmpdirectpath.remove(0, 1);
  1507. }
  1508. if (!tmpdirectpath.isEmpty())
  1509. {
  1510. directorypathnames.append(tmpdirectpath);
  1511. }
  1512. }
  1513. for (int i = 0; i < listfilesizedirpair.first.first.size(); ++i)
  1514. {
  1515. filepathnames[i].remove(0, rmnumcharsrootdir);
  1516. if (filepathnames[i].startsWith("/") || filepathnames[i].startsWith(QDir::toNativeSeparators("/")))
  1517. {
  1518. filepathnames[i].remove(0, 1);
  1519. }
  1520. }
  1521. }
  1522. else
  1523. {
  1524. directorypathnames = listfilesizedirpair.second;
  1525. }
  1526. }
  1527. if (installType == tr("USB Drive"))
  1528. {
  1529. QStringList syslinuxfilepaths = QStringList() << "boot/syslinux/syslinux.cfg" << "syslinux/syslinux.cfg" << "syslinux.cfg" << "isolinux.cfg" << "extlinux.conf";
  1530. if (QString(QDir::toNativeSeparators("/")) != QString("/"))
  1531. {
  1532. syslinuxfilepaths << QString("boot%1syslinux%1syslinux.cfg").arg(QDir::toNativeSeparators("/")) << QString("syslinux%1syslinux.cfg").arg(QDir::toNativeSeparators("/"));
  1533. }
  1534. for (int j = 0; j < syslinuxfilepaths.size(); ++j)
  1535. {
  1536. rmFile(QString("%1%2").arg(targetPath).arg(syslinuxfilepaths.at(j)));
  1537. for (int i = 0; i < filepathnames.size(); ++i)
  1538. {
  1539. if (filepathnames.at(i) == syslinuxfilepaths.at(j))
  1540. {
  1541. dontgeneratesyslinuxcfg = true;
  1542. locatedsyslinuxcfgfiles.append(syslinuxfilepaths.at(j));
  1543. }
  1544. }
  1545. }
  1546. }
  1547. if (!dontgeneratesyslinuxcfg)
  1548. {
  1549. kernelOpts = extractcfg(isofile, listfilesizedirpair.first.first);
  1550. issalt = (kernelOpts == SALT_DETECTED);
  1551. if (issalt)
  1552. {
  1553. QStringList mlstfoundfiles = listfilesizedirpair.second.filter(QRegExp("/modules$", Qt::CaseInsensitive));
  1554. if (!mlstfoundfiles.isEmpty())
  1555. {
  1556. QString match = mlstfoundfiles.at(0);
  1557. saltRootDir = match.replace(QRegExp("(.*)/modules"), "\\1");
  1558. }
  1559. kernelLine = "linux";
  1560. kernelOpts = "";
  1561. initrdLoc = "";
  1562. initrdOpts = "";
  1563. initrdLine = "";
  1564. slinitrdLine = "";
  1565. }
  1566. else
  1567. {
  1568. extraoptionsPL = extractcfgL(isofile, listfilesizedirpair.first.first);
  1569. }
  1570. #ifndef NOEXTRACTKERNEL
  1571. extractkernel(isofile, QString("%1ubnkern").arg(targetPath), listfilesizedirpair.first);
  1572. #endif
  1573. #ifndef NOEXTRACTINITRD
  1574. if (!issalt)
  1575. {
  1576. extractinitrd(isofile, QString("%1ubninit").arg(targetPath), listfilesizedirpair.first);
  1577. }
  1578. #endif
  1579. }
  1580. QStringList createdpaths = makepathtree(targetDrive, directorypathnames);
  1581. QFile ubnpathlF(QDir::toNativeSeparators(QString("%1ubnpathl.txt").arg(targetPath)));
  1582. if (ubnpathlF.exists())
  1583. {
  1584. rmFile(ubnpathlF);
  1585. }
  1586. ubnpathlF.open(QIODevice::WriteOnly | QIODevice::Text);
  1587. QTextStream ubnpathlS(&ubnpathlF);
  1588. for (int i = createdpaths.size() - 1; i > -1; i--)
  1589. {
  1590. ubnpathlS << createdpaths.at(i) << endl;
  1591. }
  1592. ubnpathlF.close();
  1593. QStringList extractedfiles;
  1594. if (!skipExtraction)
  1595. extractedfiles = extractallfiles(isofile, targetDrive, listfilesizedirpair.first, filepathnames);
  1596. QFile ubnfilelF(QDir::toNativeSeparators(QString("%1ubnfilel.txt").arg(targetPath)));
  1597. if (ubnfilelF.exists())
  1598. {
  1599. rmFile(ubnfilelF);
  1600. }
  1601. ubnfilelF.open(QIODevice::WriteOnly | QIODevice::Text);
  1602. QTextStream ubnfilelS(&ubnfilelF);
  1603. for (int i = 0; i < extractedfiles.size(); ++i)
  1604. {
  1605. ubnfilelS << extractedfiles.at(i) << endl;
  1606. }
  1607. ubnfilelF.close();
  1608. #ifdef XPUD
  1609. rmFile(QString("%1boot.cat").arg(targetPath));
  1610. rmFile(QString("%1isolinux.bin").arg(targetPath));
  1611. rmFile(QString("%1syslinux.cfg").arg(targetPath));
  1612. QFile::rename(QString("%1isolinux.cfg").arg(targetPath), QString("%1syslinux.cfg").arg(targetPath));
  1613. if (installType == tr("USB Drive"))
  1614. {
  1615. rmFile(QString("%1ubnfilel.txt").arg(targetPath));
  1616. rmFile(QString("%1ubnpathl.txt").arg(targetPath));
  1617. }
  1618. #endif
  1619. }
  1620. void unetbootin::extractiso_krd10(QString isofile)
  1621. {
  1622. if (!sdesc2->text().contains(trcurrent))
  1623. {
  1624. sdesc1->setText(QString(sdesc1->text()).remove("<b>").replace(trcurrent+"</b>", trdone));
  1625. sdesc2->setText(QString("<b>%1 %2</b>").arg(sdesc2->text()).arg(trdone));
  1626. }
  1627. tprogress->setValue(0);
  1628. QPair<QPair<QStringList, QList<quint64> >, QStringList> listfilesizedirpair = listarchiveconts(isofile);
  1629. kernelLoc = QDir::fromNativeSeparators(locatekernel(isofile, listfilesizedirpair.first));
  1630. if (!kernelLoc.startsWith("/")) kernelLoc.prepend("/");
  1631. initrdLoc = QDir::fromNativeSeparators(locateinitrd(isofile, listfilesizedirpair.first));
  1632. if (!initrdLoc.startsWith("/")) initrdLoc.prepend("/");
  1633. kernelOpts = extractcfg(isofile, listfilesizedirpair.first.first);
  1634. extraoptionsPL.first.first.clear();
  1635. extraoptionsPL.first.second.clear();
  1636. extraoptionsPL.second.first.clear();
  1637. extraoptionsPL.second.second.clear();
  1638. QPair<QPair<QStringList, QStringList>, QPair<QStringList, QStringList> > tmpoptionsL = extractcfgL(isofile, listfilesizedirpair.first.first);
  1639. for (int i = 0; i < tmpoptionsL.second.second.size(); ++i)
  1640. {
  1641. if (!tmpoptionsL.second.second.at(i).isEmpty())
  1642. {
  1643. extraoptionsPL.first.first.append(tmpoptionsL.first.first.at(i));
  1644. extraoptionsPL.first.second.append(tmpoptionsL.first.second.at(i));
  1645. extraoptionsPL.second.first.append(tmpoptionsL.second.first.at(i));
  1646. extraoptionsPL.second.second.append(tmpoptionsL.second.second.at(i));
  1647. }
  1648. }
  1649. QPair<QStringList, QList<quint64> > bootfiles;
  1650. for (int i = 0; i < listfilesizedirpair.first.first.size(); ++i)
  1651. {
  1652. if (listfilesizedirpair.first.first.at(i).startsWith("boot", Qt::CaseInsensitive))
  1653. {
  1654. bootfiles.first.append(listfilesizedirpair.first.first.at(i));
  1655. bootfiles.second.append(listfilesizedirpair.first.second.at(i));
  1656. }
  1657. }
  1658. QStringList bootpaths;
  1659. for (int i = 0; i < listfilesizedirpair.second.size(); ++i)
  1660. {
  1661. if (listfilesizedirpair.second.at(i).startsWith("boot", Qt::CaseInsensitive))
  1662. {
  1663. bootpaths.append(listfilesizedirpair.second.at(i));
  1664. }
  1665. }
  1666. if (!bootpaths.contains("rescue"))
  1667. bootpaths.append("rescue");
  1668. QStringList createdpaths = makepathtree(targetDrive, bootpaths);
  1669. QFile ubnpathlF(QDir::toNativeSeparators(QString("%1ubnpathl.txt").arg(targetPath)));
  1670. if (ubnpathlF.exists())
  1671. {
  1672. rmFile(ubnpathlF);
  1673. }
  1674. ubnpathlF.open(QIODevice::WriteOnly | QIODevice::Text);
  1675. QTextStream ubnpathlS(&ubnpathlF);
  1676. for (int i = createdpaths.size() - 1; i > -1; i--)
  1677. {
  1678. ubnpathlS << createdpaths.at(i) << endl;
  1679. }
  1680. ubnpathlF.close();
  1681. QStringList extractedfiles = extractallfiles(isofile, targetDrive, bootfiles, listfilesizedirpair.first.first);
  1682. if (QFile::exists(QString("%1liveusb").arg(targetDrive)))
  1683. overwritefileprompt(QString("%1liveusb").arg(targetDrive));
  1684. else
  1685. extractedfiles.append(QString("%1liveusb").arg(targetDrive));
  1686. QFile(QString("%1liveusb").arg(targetDrive)).open(QIODevice::WriteOnly);
  1687. pdesc1->setText(QString("Copying %1 to %2").arg(isofile).arg(QString("%1rescue%2rescue.iso").arg(targetDrive).arg(QDir::toNativeSeparators("/"))));
  1688. if (QFile::exists(QString("%1rescue%2rescue.iso").arg(targetDrive).arg(QDir::toNativeSeparators("/"))))
  1689. overwritefileprompt(QString("%1rescue%2rescue.iso").arg(targetDrive).arg(QDir::toNativeSeparators("/")));
  1690. else
  1691. extractedfiles.append(QString("%1rescue%2rescue.iso").arg(targetDrive).arg(QDir::toNativeSeparators("/")));
  1692. //QFile::copy(isofile, QString("%1rescue%2rescue.iso").arg(targetDrive).arg(QDir::toNativeSeparators("/")));
  1693. copyfilegui(isofile, QString("%1rescue%2rescue.iso").arg(targetDrive).arg(QDir::toNativeSeparators("/")));
  1694. QFile ubnfilelF(QDir::toNativeSeparators(QString("%1ubnfilel.txt").arg(targetPath)));
  1695. if (ubnfilelF.exists())
  1696. {
  1697. rmFile(ubnfilelF);
  1698. }
  1699. ubnfilelF.open(QIODevice::WriteOnly | QIODevice::Text);
  1700. QTextStream ubnfilelS(&ubnfilelF);
  1701. for (int i = 0; i < extractedfiles.size(); ++i)
  1702. {
  1703. ubnfilelS << extractedfiles.at(i) << endl;
  1704. }
  1705. ubnfilelF.close();
  1706. }
  1707. void unetbootin::copyfilegui(QString src, QString dst)
  1708. {
  1709. pdesc5->setText("");
  1710. pdesc4->setText(tr("Copying file, please wait..."));
  1711. pdesc3->setText(tr("<b>Source:</b> <a href=\"%1\">%1</a>").arg(src));
  1712. pdesc2->setText(tr("<b>Destination:</b> %1").arg(dst));
  1713. pdesc1->setText(tr("<b>Copied:</b> 0 bytes"));
  1714. QEventLoop cpfw;
  1715. copyfileT cpft;
  1716. cpft.source = src;
  1717. cpft.destination = dst;
  1718. connect(&cpft, SIGNAL(datacopied64(qint64,qint64)), this, SLOT(cpprogressupdate64(qint64,qint64)));
  1719. connect(&cpft, SIGNAL(finished()), &cpfw, SLOT(quit()));
  1720. cpft.start();
  1721. cpfw.exec();
  1722. pdesc4->setText("");
  1723. pdesc3->setText("");
  1724. pdesc2->setText("");
  1725. pdesc1->setText("");
  1726. tprogress->setValue(0);
  1727. }
  1728. QStringList unetbootin::makepathtree(QString dirmkpathw, QStringList pathlist)
  1729. {
  1730. QStringList createdpaths;
  1731. QDir dir(dirmkpathw);
  1732. for (int i = 0; i < pathlist.size(); ++i)
  1733. {
  1734. if (dir.mkdir(pathlist.at(i)))
  1735. {
  1736. createdpaths.append(pathlist.at(i));
  1737. }
  1738. }
  1739. return createdpaths;
  1740. }
  1741. QStringList unetbootin::extractallfiles(QString archivefile, QString dirxfilesto, QPair<QStringList, QList<quint64> > filesizelist, QStringList outputfilelist)
  1742. {
  1743. QStringList filelist = filesizelist.first;
  1744. QStringList extractedfiles;
  1745. QProgressDialog xprogress;
  1746. tprogress->setMaximum(filelist.size());
  1747. tprogress->setMinimum(0);
  1748. tprogress->setValue(0);
  1749. pdesc5->setText(tr("Extracting files, please wait..."));
  1750. pdesc4->setText(tr("<b>Archive:</b> %1").arg(archivefile));
  1751. pdesc3->setText(tr("<b>Source:</b>"));
  1752. pdesc2->setText(tr("<b>Destination:</b>"));
  1753. pdesc1->setText(tr("<b>Extracted:</b> 0 of %1 files").arg(filelist.size()));
  1754. for (int i = 0; i < filelist.size(); ++i)
  1755. {
  1756. pdesc3->setText(tr("<b>Source:</b> %1 (%2)").arg(filelist.at(i)).arg(displayfisize(filesizelist.second.at(i))));
  1757. pdesc2->setText(tr("<b>Destination:</b> %1%2").arg(dirxfilesto).arg(outputfilelist.at(i)));
  1758. pdesc1->setText(tr("<b>Extracted:</b> %1 of %2 files").arg(i).arg(filelist.size()));
  1759. tprogress->setValue(i);
  1760. if (extractfile(filelist.at(i), QString("%1%2").arg(dirxfilesto).arg(outputfilelist.at(i)), archivefile))
  1761. {
  1762. extractedfiles.append(filelist.at(i));
  1763. }
  1764. }
  1765. pdesc5->setText("");
  1766. pdesc4->setText("");
  1767. pdesc3->setText("");
  1768. pdesc2->setText("");
  1769. pdesc1->setText("");
  1770. tprogress->setValue(0);
  1771. return extractedfiles;
  1772. }
  1773. QString unetbootin::getgrubcfgargs(QString cfgfile)
  1774. {
  1775. QFile cfgfileF(cfgfile);
  1776. cfgfileF.open(QIODevice::ReadOnly | QIODevice::Text);
  1777. QTextStream cfgfileS(&cfgfileF);
  1778. QString cfgfileCL;
  1779. while (!cfgfileS.atEnd())
  1780. {
  1781. cfgfileCL = cfgfileS.readLine().trimmed();
  1782. if (cfgfileCL.contains("#"))
  1783. {
  1784. cfgfileCL = cfgfileCL.left(cfgfileCL.indexOf("#")).trimmed();
  1785. }
  1786. if (cfgfileCL.contains(QRegExp("^kernel\\s{1,}\\S{1,}\\s{1,}\\S{1,}", Qt::CaseInsensitive)))
  1787. {
  1788. return fixkernelbootoptions(QString(cfgfileCL).remove(QRegExp("^kernel\\s{1,}\\S{1,}\\s{1,}", Qt::CaseInsensitive)));
  1789. }
  1790. }
  1791. return "";
  1792. }
  1793. QPair<QPair<QStringList, QStringList>, QPair<QStringList, QStringList> > unetbootin::getgrubcfgargsL(QString cfgfile)
  1794. {
  1795. QPair<QStringList, QStringList> kernelandinitrd;
  1796. QPair<QStringList, QStringList> titleandparams;
  1797. int curindex = 0;
  1798. bool kernelpassed = false;
  1799. QFile cfgfileF(cfgfile);
  1800. cfgfileF.open(QIODevice::ReadOnly | QIODevice::Text);
  1801. QTextStream cfgfileS(&cfgfileF);
  1802. QString cfgfileCL;
  1803. kernelandinitrd.first.append(kernelLoc);
  1804. kernelandinitrd.second.append(initrdLoc);
  1805. titleandparams.first.append(QString("Untitled Entry Grub %1").arg(curindex));
  1806. titleandparams.second.append("");
  1807. while (!cfgfileS.atEnd())
  1808. {
  1809. cfgfileCL = cfgfileS.readLine().trimmed();
  1810. if (cfgfileCL.contains("#"))
  1811. {
  1812. cfgfileCL = cfgfileCL.left(cfgfileCL.indexOf("#")).trimmed();
  1813. }
  1814. if (cfgfileCL.contains(QRegExp("^title\\s{1,}\\S{1,}", Qt::CaseInsensitive)))
  1815. {
  1816. if (kernelpassed)
  1817. {
  1818. ++curindex;
  1819. kernelandinitrd.first.append(kernelLoc);
  1820. kernelandinitrd.second.append(initrdLoc);
  1821. titleandparams.first.append(QString("Untitled Entry Grub %1").arg(curindex));
  1822. titleandparams.second.append("");
  1823. kernelpassed = false;
  1824. }
  1825. titleandparams.first[curindex] = QString(cfgfileCL).remove("title", Qt::CaseInsensitive).trimmed();
  1826. continue;
  1827. }
  1828. if (cfgfileCL.contains(QRegExp("^initrd\\s{1,}\\S{1,}", Qt::CaseInsensitive)))
  1829. {
  1830. kernelandinitrd.second[curindex] = getFirstTextBlock(QString(cfgfileCL).remove(QRegExp("^initrd", Qt::CaseInsensitive)).trimmed());
  1831. // if (kernelandinitrd.second.at(curindex).isEmpty())
  1832. // kernelandinitrd.second[curindex] = initrdLoc;
  1833. continue;
  1834. }
  1835. // if (cfgfileCL.contains(QRegExp("^module\\s{1,}\\S{1,}", Qt::CaseInsensitive)))
  1836. // {
  1837. // kernelandinitrd.second[curindex] = getFirstTextBlock(QString(cfgfileCL).remove(QRegExp("^module", Qt::CaseInsensitive)).trimmed());
  1838. // if (kernelandinitrd.second.at(curindex).isEmpty())
  1839. // kernelandinitrd.second[curindex] = initrdLoc;
  1840. // }
  1841. if (cfgfileCL.contains(QRegExp("^kernel\\s{1,}\\S{1,}", Qt::CaseInsensitive)))
  1842. {
  1843. if (kernelpassed)
  1844. {
  1845. ++curindex;
  1846. kernelandinitrd.first.append(kernelLoc);
  1847. kernelandinitrd.second.append(initrdLoc);
  1848. titleandparams.first.append(QString("Untitled Entry Grub %1").arg(curindex));
  1849. titleandparams.second.append("");
  1850. // kernelpassed = false;
  1851. }
  1852. if (cfgfileCL.contains(QRegExp("^kernel\\s{1,}\\S{1,}\\s{1,}\\S{1,}", Qt::CaseInsensitive)))
  1853. {
  1854. titleandparams.second[curindex] = fixkernelbootoptions(QString(cfgfileCL).remove(QRegExp("^kernel\\s{1,}\\S{1,}\\s{1,}", Qt::CaseInsensitive)));
  1855. }
  1856. kernelandinitrd.first[curindex] = getFirstTextBlock(QString(cfgfileCL).remove(QRegExp("^kernel", Qt::CaseInsensitive)).trimmed());
  1857. // if (kernelandinitrd.first.at(curindex).isEmpty())
  1858. // kernelandinitrd.first[curindex] = kernelLoc;
  1859. kernelpassed = true;
  1860. continue;
  1861. }
  1862. }
  1863. return qMakePair(kernelandinitrd, titleandparams);
  1864. }
  1865. QString unetbootin::getFirstTextBlock(QString fulltext)
  1866. {
  1867. QStringList textblockL = fulltext.split(QRegExp("\\s{1,}")).filter(QRegExp("\\S{1,}"));
  1868. if (textblockL.isEmpty())
  1869. return "";
  1870. else
  1871. {
  1872. return textblockL.at(0);
  1873. }
  1874. }
  1875. void unetbootin::loadgrub2env(QString cfgfile)
  1876. {
  1877. QFile cfgfileF(cfgfile);
  1878. cfgfileF.open(QIODevice::ReadOnly | QIODevice::Text);
  1879. QTextStream cfgfileS(&cfgfileF);
  1880. QString cfgfileCL;
  1881. while (!cfgfileS.atEnd())
  1882. {
  1883. cfgfileCL = cfgfileS.readLine().trimmed();
  1884. if (cfgfileCL.contains("#"))
  1885. {
  1886. cfgfileCL = cfgfileCL.left(cfgfileCL.indexOf("#")).trimmed();
  1887. }
  1888. if (cfgfileCL.contains("${"))
  1889. {
  1890. for (QMap<QString, QString>::const_iterator i = grub2vars.begin(); i != grub2vars.end(); ++i)
  1891. {
  1892. if (cfgfileCL.contains(QString("${%1}").arg(i.key())))
  1893. cfgfileCL.replace(QString("${%1}").arg(i.key()), i.value());
  1894. }
  1895. }
  1896. if (cfgfileCL.contains(QRegExp("^set\\s{1,}\\S{1,}\\s{0,}=\\s{0,}\".{1,}\"")))
  1897. {
  1898. QRegExp setrg("^set\\s{1,}(\\S{1,})\\s{0,}=\\s{0,}\"(.{1,})\"");
  1899. setrg.indexIn(cfgfileCL);
  1900. QStringList captxt = setrg.capturedTexts();
  1901. if (captxt.size() >= 2)
  1902. {
  1903. grub2vars[captxt.at(captxt.size()-2)] = captxt.at(captxt.size()-1);
  1904. continue;
  1905. }
  1906. }
  1907. if (cfgfileCL.contains(QRegExp("^set\\s{1,}\\S{1,}\\s{0,}=\\s{0,}\\S{1,}")))
  1908. {
  1909. QRegExp setrg("^set\\s{1,}(\\S{1,})\\s{0,}=\\s{0,}(\\S{1,})");
  1910. setrg.indexIn(cfgfileCL);
  1911. QStringList captxt = setrg.capturedTexts();
  1912. if (captxt.size() >= 2)
  1913. {
  1914. grub2vars[captxt.at(captxt.size()-2)] = captxt.at(captxt.size()-1);
  1915. continue;
  1916. }
  1917. }
  1918. if (cfgfileCL.count("=") == 1)
  1919. {
  1920. QStringList splp = cfgfileCL.split("=");
  1921. if (splp.size() == 2)
  1922. {
  1923. grub2vars[splp.at(0).trimmed()] = QString(splp.at(1)).remove("\"").trimmed();
  1924. }
  1925. }
  1926. }
  1927. }
  1928. QString unetbootin::getgrub2cfgargs(QString cfgfile, QString archivefile, QStringList archivefileconts, QStringList visitedincludes)
  1929. {
  1930. QFile cfgfileF(cfgfile);
  1931. cfgfileF.open(QIODevice::ReadOnly | QIODevice::Text);
  1932. QTextStream cfgfileS(&cfgfileF);
  1933. QString cfgfileCL;
  1934. QString includesfile;
  1935. QString searchincfrs;
  1936. while (!cfgfileS.atEnd())
  1937. {
  1938. cfgfileCL = cfgfileS.readLine().trimmed();
  1939. if (cfgfileCL.contains("#"))
  1940. {
  1941. cfgfileCL = cfgfileCL.left(cfgfileCL.indexOf("#")).trimmed();
  1942. }
  1943. if (cfgfileCL.contains("${"))
  1944. {
  1945. for (QMap<QString, QString>::const_iterator i = grub2vars.begin(); i != grub2vars.end(); ++i)
  1946. {
  1947. if (cfgfileCL.contains(QString("${%1}").arg(i.key())))
  1948. cfgfileCL.replace(QString("${%1}").arg(i.key()), i.value());
  1949. }
  1950. }
  1951. if (cfgfileCL.contains(QRegExp("^set\\s{1,}\\S{1,}\\s{0,}=\\s{0,}\".{1,}\"")))
  1952. {
  1953. QRegExp setrg("^set\\s{1,}(\\S{1,})\\s{0,}=\\s{0,}\"(.{1,})\"");
  1954. setrg.indexIn(cfgfileCL);
  1955. QStringList captxt = setrg.capturedTexts();
  1956. if (captxt.size() >= 2)
  1957. {
  1958. grub2vars[captxt.at(captxt.size()-2)] = captxt.at(captxt.size()-1);
  1959. continue;
  1960. }
  1961. }
  1962. if (cfgfileCL.contains(QRegExp("^set\\s{1,}\\S{1,}\\s{0,}=\\s{0,}\\S{1,}")))
  1963. {
  1964. QRegExp setrg("^set\\s{1,}(\\S{1,})\\s{0,}=\\s{0,}(\\S{1,})");
  1965. setrg.indexIn(cfgfileCL);
  1966. QStringList captxt = setrg.capturedTexts();
  1967. if (captxt.size() >= 2)
  1968. {
  1969. grub2vars[captxt.at(captxt.size()-2)] = captxt.at(captxt.size()-1);
  1970. continue;
  1971. }
  1972. }
  1973. if (!archivefileconts.isEmpty() && QRegExp("^configfile\\s{1,}\\S{1,}.cfg$", Qt::CaseInsensitive).exactMatch(cfgfileCL))
  1974. {
  1975. includesfile = QDir::toNativeSeparators(QString(cfgfileCL).remove(QRegExp("^configfile\\s{1,}", Qt::CaseInsensitive))).trimmed();
  1976. searchincfrs = searchforgrub2includesfile(includesfile, archivefile, archivefileconts, visitedincludes).trimmed();
  1977. if (!searchincfrs.isEmpty())
  1978. return searchincfrs;
  1979. }
  1980. if (!archivefileconts.isEmpty() && QRegExp("^source\\s{1,}\\S{1,}.cfg$", Qt::CaseInsensitive).exactMatch(cfgfileCL))
  1981. {
  1982. includesfile = QDir::toNativeSeparators(QString(cfgfileCL).remove(QRegExp("^source\\s{1,}", Qt::CaseInsensitive))).trimmed();
  1983. searchincfrs = searchforgrub2includesfile(includesfile, archivefile, archivefileconts, visitedincludes).trimmed();
  1984. if (!searchincfrs.isEmpty())
  1985. return searchincfrs;
  1986. }
  1987. if (cfgfileCL.contains(QRegExp("^linux\\s{1,}\\S{1,}\\s{1,}\\S{1,}", Qt::CaseInsensitive)))
  1988. {
  1989. return fixkernelbootoptions(QString(cfgfileCL).remove(QRegExp("^linux\\s{1,}\\S{1,}\\s{1,}", Qt::CaseInsensitive))).remove(QRegExp("initrd=\\S{0,}")).trimmed();
  1990. }
  1991. }
  1992. return "";
  1993. }
  1994. QPair<QPair<QStringList, QStringList>, QPair<QStringList, QStringList> > unetbootin::getgrub2cfgargsL(QString cfgfile, QString archivefile, QStringList archivefileconts, QStringList visitedincludes)
  1995. {
  1996. QPair<QStringList, QStringList> kernelandinitrd;
  1997. QPair<QStringList, QStringList> titleandparams;
  1998. int curindex = 0;
  1999. bool kernelpassed = false;
  2000. QFile cfgfileF(cfgfile);
  2001. cfgfileF.open(QIODevice::ReadOnly | QIODevice::Text);
  2002. QTextStream cfgfileS(&cfgfileF);
  2003. QString cfgfileCL;
  2004. kernelandinitrd.first.append(kernelLoc);
  2005. kernelandinitrd.second.append(initrdLoc);
  2006. titleandparams.first.append(QString("Untitled Entry Grub %1").arg(curindex));
  2007. titleandparams.second.append("");
  2008. QString includesfile;
  2009. QPair<QPair<QStringList, QStringList>, QPair<QStringList, QStringList> > searchincfrs;
  2010. while (!cfgfileS.atEnd())
  2011. {
  2012. cfgfileCL = cfgfileS.readLine().trimmed();
  2013. if (cfgfileCL.contains("#"))
  2014. {
  2015. cfgfileCL = cfgfileCL.left(cfgfileCL.indexOf("#")).trimmed();
  2016. }
  2017. if (cfgfileCL.contains("${"))
  2018. {
  2019. for (QMap<QString, QString>::const_iterator i = grub2vars.begin(); i != grub2vars.end(); ++i)
  2020. {
  2021. if (cfgfileCL.contains(QString("${%1}").arg(i.key())))
  2022. cfgfileCL.replace(QString("${%1}").arg(i.key()), i.value());
  2023. }
  2024. }
  2025. if (cfgfileCL.contains(QRegExp("^set\\s{1,}\\S{1,}\\s{0,}=\\s{0,}\".{1,}\"")))
  2026. {
  2027. QRegExp setrg("^set\\s{1,}(\\S{1,})\\s{0,}=\\s{0,}\"(.{1,})\"");
  2028. setrg.indexIn(cfgfileCL);
  2029. QStringList captxt = setrg.capturedTexts();
  2030. if (captxt.size() >= 2)
  2031. {
  2032. grub2vars[captxt.at(captxt.size()-2)] = captxt.at(captxt.size()-1);
  2033. continue;
  2034. }
  2035. }
  2036. if (cfgfileCL.contains(QRegExp("^set\\s{1,}\\S{1,}\\s{0,}=\\s{0,}\\S{1,}")))
  2037. {
  2038. QRegExp setrg("^set\\s{1,}(\\S{1,})\\s{0,}=\\s{0,}(\\S{1,})");
  2039. setrg.indexIn(cfgfileCL);
  2040. QStringList captxt = setrg.capturedTexts();
  2041. if (captxt.size() >= 2)
  2042. {
  2043. grub2vars[captxt.at(captxt.size()-2)] = captxt.at(captxt.size()-1);
  2044. continue;
  2045. }
  2046. }
  2047. if (!archivefileconts.isEmpty() && QRegExp("^configfile\\s{1,}\\S{1,}.cfg$", Qt::CaseInsensitive).exactMatch(cfgfileCL))
  2048. {
  2049. includesfile = QDir::toNativeSeparators(QString(cfgfileCL).remove(QRegExp("^configfile\\s{1,}", Qt::CaseInsensitive))).trimmed();
  2050. searchincfrs = searchforgrub2includesfileL(includesfile, archivefile, archivefileconts, visitedincludes);
  2051. if (!searchincfrs.first.first.isEmpty())
  2052. {
  2053. kernelandinitrd.first += searchincfrs.first.first;
  2054. kernelandinitrd.second += searchincfrs.first.second;
  2055. titleandparams.first += searchincfrs.second.first;
  2056. titleandparams.second += searchincfrs.second.second;
  2057. }
  2058. continue;
  2059. }
  2060. if (!archivefileconts.isEmpty() && QRegExp("^source\\s{1,}\\S{1,}.cfg$", Qt::CaseInsensitive).exactMatch(cfgfileCL))
  2061. {
  2062. includesfile = QDir::toNativeSeparators(QString(cfgfileCL).remove(QRegExp("^source\\s{1,}", Qt::CaseInsensitive))).trimmed();
  2063. searchincfrs = searchforgrub2includesfileL(includesfile, archivefile, archivefileconts, visitedincludes);
  2064. if (!searchincfrs.first.first.isEmpty())
  2065. {
  2066. kernelandinitrd.first += searchincfrs.first.first;
  2067. kernelandinitrd.second += searchincfrs.first.second;
  2068. titleandparams.first += searchincfrs.second.first;
  2069. titleandparams.second += searchincfrs.second.second;
  2070. }
  2071. continue;
  2072. }
  2073. if (cfgfileCL.contains(QRegExp("^menuentry\\s{1,}\".{1,}\"", Qt::CaseInsensitive)))
  2074. {
  2075. if (kernelpassed)
  2076. {
  2077. ++curindex;
  2078. kernelandinitrd.first.append(kernelLoc);
  2079. kernelandinitrd.second.append(initrdLoc);
  2080. titleandparams.first.append(QString("Untitled Entry Grub %1").arg(curindex));
  2081. titleandparams.second.append("");
  2082. kernelpassed = false;
  2083. }
  2084. titleandparams.first[curindex] = QString(cfgfileCL).remove("menuentry", Qt::CaseInsensitive).remove("\"").remove("{").remove("}").trimmed();
  2085. continue;
  2086. }
  2087. if (cfgfileCL.contains(QRegExp("^initrd\\s{1,}\\S{1,}", Qt::CaseInsensitive)))
  2088. {
  2089. kernelandinitrd.second[curindex] = getFirstTextBlock(QString(cfgfileCL).remove(QRegExp("^initrd", Qt::CaseInsensitive)).trimmed());
  2090. // if (kernelandinitrd.second.at(curindex).isEmpty())
  2091. // kernelandinitrd.second[curindex] = initrdLoc;
  2092. continue;
  2093. }
  2094. // if (cfgfileCL.contains(QRegExp("^module\\s{1,}\\S{1,}", Qt::CaseInsensitive)))
  2095. // {
  2096. // kernelandinitrd.second[curindex] = getFirstTextBlock(QString(cfgfileCL).remove(QRegExp("^module", Qt::CaseInsensitive)).trimmed());
  2097. // if (kernelandinitrd.second.at(curindex).isEmpty())
  2098. // kernelandinitrd.second[curindex] = initrdLoc;
  2099. // }
  2100. if (cfgfileCL.contains(QRegExp("^linux\\s{1,}\\S{1,}", Qt::CaseInsensitive)))
  2101. {
  2102. if (kernelpassed)
  2103. {
  2104. ++curindex;
  2105. kernelandinitrd.first.append(kernelLoc);
  2106. kernelandinitrd.second.append(initrdLoc);
  2107. titleandparams.first.append(QString("Untitled Entry Grub %1").arg(curindex));
  2108. titleandparams.second.append("");
  2109. // kernelpassed = false;
  2110. }
  2111. if (cfgfileCL.contains(QRegExp("^linux\\s{1,}\\S{1,}\\s{1,}\\S{1,}", Qt::CaseInsensitive)))
  2112. {
  2113. titleandparams.second[curindex] = fixkernelbootoptions(QString(cfgfileCL).remove(QRegExp("^linux\\s{1,}\\S{1,}\\s{1,}", Qt::CaseInsensitive))).remove(QRegExp("initrd=\\S{0,}")).trimmed();
  2114. }
  2115. kernelandinitrd.first[curindex] = getFirstTextBlock(QString(cfgfileCL).remove(QRegExp("^linux", Qt::CaseInsensitive)).trimmed());
  2116. // if (kernelandinitrd.first.at(curindex).isEmpty())
  2117. // kernelandinitrd.first[curindex] = kernelLoc;
  2118. kernelpassed = true;
  2119. continue;
  2120. }
  2121. }
  2122. return qMakePair(kernelandinitrd, titleandparams);
  2123. }
  2124. QString unetbootin::getcfgkernargs(QString cfgfile, QString archivefile, QStringList archivefileconts, QStringList visitedincludes)
  2125. {
  2126. QFile cfgfileF(cfgfile);
  2127. cfgfileF.open(QIODevice::ReadOnly | QIODevice::Text);
  2128. QTextStream cfgfileS(&cfgfileF);
  2129. QString cfgfileCL;
  2130. QString includesfile;
  2131. QString searchincfrs;
  2132. while (!cfgfileS.atEnd())
  2133. {
  2134. cfgfileCL = cfgfileS.readLine().trimmed();
  2135. if (cfgfileCL.contains("#"))
  2136. {
  2137. cfgfileCL = cfgfileCL.left(cfgfileCL.indexOf("#")).trimmed();
  2138. }
  2139. if (!archivefileconts.isEmpty() && QRegExp("^include\\s{1,}\\S{1,}.cfg$", Qt::CaseInsensitive).exactMatch(cfgfileCL))
  2140. {
  2141. includesfile = QDir::toNativeSeparators(QString(cfgfileCL).remove(QRegExp("^include\\s{1,}", Qt::CaseInsensitive))).trimmed();
  2142. searchincfrs = searchforincludesfile(includesfile, archivefile, archivefileconts, visitedincludes).trimmed();
  2143. if (!searchincfrs.isEmpty())
  2144. return searchincfrs;
  2145. }
  2146. if (!archivefileconts.isEmpty() && QRegExp("^append\\s{1,}\\S{1,}.cfg$", Qt::CaseInsensitive).exactMatch(cfgfileCL))
  2147. {
  2148. includesfile = QDir::toNativeSeparators(QString(cfgfileCL).remove(QRegExp("^append\\s{1,}", Qt::CaseInsensitive))).trimmed();
  2149. searchincfrs = searchforincludesfile(includesfile, archivefile, archivefileconts, visitedincludes).trimmed();
  2150. if (!searchincfrs.isEmpty())
  2151. return searchincfrs;
  2152. }
  2153. else if (cfgfileCL.contains(QRegExp("^\\s{0,}append\\s{1,}", Qt::CaseInsensitive)))
  2154. {
  2155. return fixkernelbootoptions(QString(cfgfileCL).remove(QRegExp("\\s{0,}append\\s{1,}", Qt::CaseInsensitive)).remove(QRegExp("\\s{0,1}initrd=\\S{0,}", Qt::CaseInsensitive)));
  2156. }
  2157. }
  2158. return "";
  2159. }
  2160. QPair<QPair<QStringList, QStringList>, QPair<QStringList, QStringList> > unetbootin::getcfgkernargsL(QString cfgfile, QString archivefile, QStringList archivefileconts, QStringList visitedincludes)
  2161. {
  2162. /*
  2163. QString cfgfiledir;
  2164. if (cfgfile.contains(QDir::toNativeSeparators("/")))
  2165. cfgfiledir = QDir::fromNativeSeparators(QString(cfgfile).left(cfgfile.lastIndexOf(QDir::toNativeSeparators("/")) + 1));
  2166. if (!cfgfiledir.isEmpty())
  2167. {
  2168. if (!cfgfiledir.startsWith('/'))
  2169. cfgfiledir = QString("/%1").arg(cfgfiledir);
  2170. if (!cfgfiledir.endsWith('/'))
  2171. cfgfiledir = QString("%1/").arg(cfgfiledir);
  2172. }
  2173. */
  2174. QPair<QStringList, QStringList> kernelandinitrd;
  2175. QPair<QStringList, QStringList> titleandparams;
  2176. int curindex = 0;
  2177. bool kernelpassed = false;
  2178. QFile cfgfileF(cfgfile);
  2179. cfgfileF.open(QIODevice::ReadOnly | QIODevice::Text);
  2180. QTextStream cfgfileS(&cfgfileF);
  2181. QString cfgfileCL;
  2182. kernelandinitrd.first.append(kernelLoc);
  2183. kernelandinitrd.second.append(initrdLoc);
  2184. titleandparams.first.append(QString("Untitled Entry Grub %1").arg(curindex));
  2185. titleandparams.second.append("");
  2186. QString includesfile;
  2187. QPair<QPair<QStringList, QStringList>, QPair<QStringList, QStringList> > searchincfrs;
  2188. while (!cfgfileS.atEnd())
  2189. {
  2190. cfgfileCL = cfgfileS.readLine().trimmed();
  2191. if (cfgfileCL.contains("#"))
  2192. {
  2193. cfgfileCL = cfgfileCL.left(cfgfileCL.indexOf("#")).trimmed();
  2194. }
  2195. if (!archivefileconts.isEmpty() && QRegExp("^include\\s{1,}\\S{1,}.cfg$", Qt::CaseInsensitive).exactMatch(cfgfileCL))
  2196. {
  2197. includesfile = QDir::toNativeSeparators(QString(cfgfileCL).remove(QRegExp("^include\\s{1,}", Qt::CaseInsensitive))).trimmed();
  2198. searchincfrs = searchforincludesfileL(includesfile, archivefile, archivefileconts, visitedincludes);
  2199. if (!searchincfrs.first.first.isEmpty())
  2200. {
  2201. kernelandinitrd.first += searchincfrs.first.first;
  2202. kernelandinitrd.second += searchincfrs.first.second;
  2203. titleandparams.first += searchincfrs.second.first;
  2204. titleandparams.second += searchincfrs.second.second;
  2205. }
  2206. continue;
  2207. }
  2208. if (!archivefileconts.isEmpty() && QRegExp("^append\\s{1,}\\S{1,}.cfg$", Qt::CaseInsensitive).exactMatch(cfgfileCL))
  2209. {
  2210. includesfile = QDir::toNativeSeparators(QString(cfgfileCL).remove(QRegExp("^append\\s{1,}", Qt::CaseInsensitive))).trimmed();
  2211. searchincfrs = searchforincludesfileL(includesfile, archivefile, archivefileconts, visitedincludes);
  2212. if (!searchincfrs.first.first.isEmpty())
  2213. {
  2214. kernelandinitrd.first += searchincfrs.first.first;
  2215. kernelandinitrd.second += searchincfrs.first.second;
  2216. titleandparams.first += searchincfrs.second.first;
  2217. titleandparams.second += searchincfrs.second.second;
  2218. }
  2219. continue;
  2220. }
  2221. if (cfgfileCL.contains(QRegExp("^menu label\\s{1,}\\S{1,}", Qt::CaseInsensitive)))
  2222. {
  2223. titleandparams.first[curindex] = QString(cfgfileCL).remove(QRegExp("^menu label", Qt::CaseInsensitive)).trimmed();
  2224. continue;
  2225. }
  2226. if (cfgfileCL.contains(QRegExp("^append\\s{1,}\\S{1,}", Qt::CaseInsensitive)))
  2227. {
  2228. QString appendoptsL = QString(cfgfileCL).remove(QRegExp("^append", Qt::CaseInsensitive)).trimmed();
  2229. if (appendoptsL.contains(QRegExp("initrd=\\S{0,}", Qt::CaseInsensitive)))
  2230. {
  2231. kernelandinitrd.second[curindex] = getFirstTextBlock(QString(appendoptsL).remove(QRegExp(".{0,}initrd=", Qt::CaseInsensitive)));
  2232. appendoptsL = QString(appendoptsL).remove(QRegExp("initrd=\\S{0,}", Qt::CaseInsensitive));
  2233. // if (kernelandinitrd.second.at(curindex).isEmpty())
  2234. // kernelandinitrd.second[curindex] = initrdLoc;
  2235. // else if (!kernelandinitrd.second.at(curindex).contains('/'))
  2236. // kernelandinitrd.second[curindex] = QString("%1%2").arg(cfgfiledir, kernelandinitrd.second.at(curindex));
  2237. }
  2238. titleandparams.second[curindex] = fixkernelbootoptions(appendoptsL);
  2239. continue;
  2240. }
  2241. if (cfgfileCL.contains(QRegExp("^label\\s{1,}\\S{1,}", Qt::CaseInsensitive)))
  2242. {
  2243. if (kernelpassed)
  2244. {
  2245. ++curindex;
  2246. kernelandinitrd.first.append(kernelLoc);
  2247. kernelandinitrd.second.append(initrdLoc);
  2248. titleandparams.first.append(QString("Untitled Entry Syslinux %1").arg(curindex));
  2249. titleandparams.second.append("");
  2250. kernelpassed = false;
  2251. }
  2252. titleandparams.first[curindex] = QString(cfgfileCL).remove(QRegExp("^label", Qt::CaseInsensitive)).trimmed();
  2253. continue;
  2254. }
  2255. if (cfgfileCL.contains(QRegExp("^kernel\\s{1,}\\S{1,}", Qt::CaseInsensitive)))
  2256. {
  2257. if (kernelpassed)
  2258. {
  2259. ++curindex;
  2260. kernelandinitrd.first.append(kernelLoc);
  2261. kernelandinitrd.second.append(initrdLoc);
  2262. titleandparams.first.append(QString("Untitled Entry Syslinux %1").arg(curindex));
  2263. titleandparams.second.append("");
  2264. // kernelpassed = false;
  2265. }
  2266. kernelandinitrd.first[curindex] = getFirstTextBlock(QString(cfgfileCL).remove(QRegExp("^kernel", Qt::CaseInsensitive)).trimmed());
  2267. // if (kernelandinitrd.first.at(curindex).isEmpty())
  2268. // kernelandinitrd.first[curindex] = kernelLoc;
  2269. // else if (!kernelandinitrd.first.at(curindex).contains('/'))
  2270. // kernelandinitrd.first[curindex] = QString("%1%2").arg(cfgfiledir, kernelandinitrd.first.at(curindex));
  2271. kernelpassed = true;
  2272. continue;
  2273. }
  2274. if (cfgfileCL.contains(QRegExp("^initrd\\s{1,}\\S{1,}", Qt::CaseInsensitive)))
  2275. {
  2276. if (kernelandinitrd.second[curindex] == initrdLoc) {
  2277. kernelandinitrd.second[curindex] = getFirstTextBlock(QString(cfgfileCL).remove(QRegExp("^initrd", Qt::CaseInsensitive)).trimmed());
  2278. }
  2279. continue;
  2280. }
  2281. }
  2282. return qMakePair(kernelandinitrd, titleandparams);
  2283. }
  2284. QString unetbootin::searchforincludesfile(QString includesfile, QString archivefile, QStringList archivefileconts, QStringList visitedincludes)
  2285. {
  2286. if (includesfile.startsWith(QDir::toNativeSeparators("/")))
  2287. {
  2288. includesfile = includesfile.right(includesfile.size() - 1).trimmed();
  2289. }
  2290. QStringList includesfileL;
  2291. for (int i = 0; i < archivefileconts.size(); ++i)
  2292. {
  2293. QString curentry = archivefileconts.at(i);
  2294. if (curentry.endsWith("/") || curentry.endsWith(QDir::toNativeSeparators("/")))
  2295. {
  2296. curentry = curentry.left(curentry.size() - 1).trimmed();
  2297. }
  2298. if (curentry.contains("/"))
  2299. {
  2300. curentry = curentry.right(curentry.size() - 1 - curentry.indexOf("/"));
  2301. }
  2302. else if (curentry.contains(QDir::toNativeSeparators("/")))
  2303. {
  2304. curentry = curentry.right(curentry.size() - 1 - curentry.indexOf(QDir::toNativeSeparators("/")));
  2305. }
  2306. if (includesfile.compare(curentry, Qt::CaseInsensitive) == 0)
  2307. {
  2308. includesfileL.append(archivefileconts.at(i));
  2309. }
  2310. }
  2311. if (includesfileL.isEmpty())
  2312. {
  2313. includesfileL = archivefileconts.filter(includesfile, Qt::CaseInsensitive);
  2314. }
  2315. if (!includesfileL.isEmpty())
  2316. {
  2317. for (int i = 0; i < includesfileL.size(); ++i)
  2318. {
  2319. if (visitedincludes.contains(includesfileL.at(i)))
  2320. continue;
  2321. randtmpfile tmpoutputcfgf(ubntmpf, "cfg");
  2322. extractfile(includesfileL.at(i), tmpoutputcfgf.fileName(), archivefile);
  2323. QStringList nextinclude = visitedincludes;
  2324. nextinclude.append(includesfileL.at(i));
  2325. QString extractcfgtmp = getcfgkernargs(tmpoutputcfgf.fileName(), archivefile, archivefileconts, nextinclude).trimmed();
  2326. rmFile(tmpoutputcfgf);
  2327. if (!extractcfgtmp.isEmpty())
  2328. {
  2329. return extractcfgtmp;
  2330. }
  2331. }
  2332. }
  2333. return "";
  2334. }
  2335. QPair<QPair<QStringList, QStringList>, QPair<QStringList, QStringList> > unetbootin::searchforincludesfileL(QString includesfile, QString archivefile, QStringList archivefileconts, QStringList visitedincludes)
  2336. {
  2337. if (includesfile.startsWith(QDir::toNativeSeparators("/")))
  2338. {
  2339. includesfile = includesfile.right(includesfile.size() - 1).trimmed();
  2340. }
  2341. QStringList includesfileL;
  2342. for (int i = 0; i < archivefileconts.size(); ++i)
  2343. {
  2344. QString curentry = archivefileconts.at(i);
  2345. if (curentry.endsWith("/") || curentry.endsWith(QDir::toNativeSeparators("/")))
  2346. {
  2347. curentry = curentry.left(curentry.size() - 1).trimmed();
  2348. }
  2349. if (curentry.contains("/"))
  2350. {
  2351. curentry = curentry.right(curentry.size() - 1 - curentry.indexOf("/"));
  2352. }
  2353. else if (curentry.contains(QDir::toNativeSeparators("/")))
  2354. {
  2355. curentry = curentry.right(curentry.size() - 1 - curentry.indexOf(QDir::toNativeSeparators("/")));
  2356. }
  2357. if (includesfile.compare(curentry, Qt::CaseInsensitive) == 0)
  2358. {
  2359. includesfileL.append(archivefileconts.at(i));
  2360. }
  2361. }
  2362. if (includesfileL.isEmpty())
  2363. {
  2364. includesfileL = archivefileconts.filter(includesfile, Qt::CaseInsensitive);
  2365. }
  2366. if (!includesfileL.isEmpty())
  2367. {
  2368. for (int i = 0; i < includesfileL.size(); ++i)
  2369. {
  2370. if (visitedincludes.contains(includesfileL.at(i)))
  2371. continue;
  2372. randtmpfile tmpoutputcfgf(ubntmpf, "cfg");
  2373. extractfile(includesfileL.at(i), tmpoutputcfgf.fileName(), archivefile);
  2374. QStringList nextinclude = visitedincludes;
  2375. nextinclude.append(includesfileL.at(i));
  2376. QPair<QPair<QStringList, QStringList>, QPair<QStringList, QStringList> > extractcfgtmp = getcfgkernargsL(tmpoutputcfgf.fileName(), archivefile, archivefileconts, nextinclude);
  2377. rmFile(tmpoutputcfgf);
  2378. if (!extractcfgtmp.first.first.isEmpty())
  2379. {
  2380. return extractcfgtmp;
  2381. }
  2382. }
  2383. }
  2384. return QPair<QPair<QStringList, QStringList>, QPair<QStringList, QStringList> >();
  2385. }
  2386. QString unetbootin::searchforgrub2includesfile(QString includesfile, QString archivefile, QStringList archivefileconts, QStringList visitedincludes)
  2387. {
  2388. if (includesfile.startsWith(QDir::toNativeSeparators("/")))
  2389. {
  2390. includesfile = includesfile.right(includesfile.size() - 1).trimmed();
  2391. }
  2392. QStringList includesfileL;
  2393. for (int i = 0; i < archivefileconts.size(); ++i)
  2394. {
  2395. QString curentry = archivefileconts.at(i);
  2396. if (curentry.endsWith("/") || curentry.endsWith(QDir::toNativeSeparators("/")))
  2397. {
  2398. curentry = curentry.left(curentry.size() - 1).trimmed();
  2399. }
  2400. if (curentry.contains("/"))
  2401. {
  2402. curentry = curentry.right(curentry.size() - 1 - curentry.indexOf("/"));
  2403. }
  2404. else if (curentry.contains(QDir::toNativeSeparators("/")))
  2405. {
  2406. curentry = curentry.right(curentry.size() - 1 - curentry.indexOf(QDir::toNativeSeparators("/")));
  2407. }
  2408. if (includesfile.compare(curentry, Qt::CaseInsensitive) == 0)
  2409. {
  2410. includesfileL.append(archivefileconts.at(i));
  2411. }
  2412. }
  2413. if (includesfileL.isEmpty())
  2414. {
  2415. includesfileL = archivefileconts.filter(includesfile, Qt::CaseInsensitive);
  2416. }
  2417. if (!includesfileL.isEmpty())
  2418. {
  2419. for (int i = 0; i < includesfileL.size(); ++i)
  2420. {
  2421. if (visitedincludes.contains(includesfileL.at(i)))
  2422. continue;
  2423. randtmpfile tmpoutputcfgf(ubntmpf, "cfg");
  2424. extractfile(includesfileL.at(i), tmpoutputcfgf.fileName(), archivefile);
  2425. QStringList nextinclude = visitedincludes;
  2426. nextinclude.append(includesfileL.at(i));
  2427. QString extractcfgtmp = getgrub2cfgargs(tmpoutputcfgf.fileName(), archivefile, archivefileconts, nextinclude).trimmed();
  2428. rmFile(tmpoutputcfgf);
  2429. if (!extractcfgtmp.isEmpty())
  2430. {
  2431. return extractcfgtmp;
  2432. }
  2433. }
  2434. }
  2435. return "";
  2436. }
  2437. QPair<QPair<QStringList, QStringList>, QPair<QStringList, QStringList> > unetbootin::searchforgrub2includesfileL(QString includesfile, QString archivefile, QStringList archivefileconts, QStringList visitedincludes)
  2438. {
  2439. if (includesfile.startsWith(QDir::toNativeSeparators("/")))
  2440. {
  2441. includesfile = includesfile.right(includesfile.size() - 1).trimmed();
  2442. }
  2443. QStringList includesfileL;
  2444. for (int i = 0; i < archivefileconts.size(); ++i)
  2445. {
  2446. QString curentry = archivefileconts.at(i);
  2447. if (curentry.endsWith("/") || curentry.endsWith(QDir::toNativeSeparators("/")))
  2448. {
  2449. curentry = curentry.left(curentry.size() - 1).trimmed();
  2450. }
  2451. if (curentry.contains("/"))
  2452. {
  2453. curentry = curentry.right(curentry.size() - 1 - curentry.indexOf("/"));
  2454. }
  2455. else if (curentry.contains(QDir::toNativeSeparators("/")))
  2456. {
  2457. curentry = curentry.right(curentry.size() - 1 - curentry.indexOf(QDir::toNativeSeparators("/")));
  2458. }
  2459. if (includesfile.compare(curentry, Qt::CaseInsensitive) == 0)
  2460. {
  2461. includesfileL.append(archivefileconts.at(i));
  2462. }
  2463. }
  2464. if (includesfileL.isEmpty())
  2465. {
  2466. includesfileL = archivefileconts.filter(includesfile, Qt::CaseInsensitive);
  2467. }
  2468. if (!includesfileL.isEmpty())
  2469. {
  2470. for (int i = 0; i < includesfileL.size(); ++i)
  2471. {
  2472. if (visitedincludes.contains(includesfileL.at(i)))
  2473. continue;
  2474. randtmpfile tmpoutputcfgf(ubntmpf, "cfg");
  2475. extractfile(includesfileL.at(i), tmpoutputcfgf.fileName(), archivefile);
  2476. QStringList nextinclude = visitedincludes;
  2477. nextinclude.append(includesfileL.at(i));
  2478. QPair<QPair<QStringList, QStringList>, QPair<QStringList, QStringList> > extractcfgtmp = getgrub2cfgargsL(tmpoutputcfgf.fileName(), archivefile, archivefileconts, nextinclude);
  2479. rmFile(tmpoutputcfgf);
  2480. if (!extractcfgtmp.first.first.isEmpty())
  2481. {
  2482. return extractcfgtmp;
  2483. }
  2484. }
  2485. }
  2486. return QPair<QPair<QStringList, QStringList>, QPair<QStringList, QStringList> >();
  2487. }
  2488. void unetbootin::downloadfile(QString fileurl, QString targetfile, int minsize=524288)
  2489. {
  2490. if (fileurl.isEmpty())
  2491. {
  2492. showDownloadFailedScreen(fileurl);
  2493. return;
  2494. }
  2495. if (QFile::exists(targetfile))
  2496. {
  2497. rmFile(targetfile);
  2498. }
  2499. QUrl dlurl(fileurl);
  2500. bool isftp = false;
  2501. if (dlurl.scheme() == "ftp")
  2502. {
  2503. isftp = true;
  2504. }
  2505. QHttp dlhttp;
  2506. QFtp dlftp;
  2507. QEventLoop dlewait;
  2508. pdesc5->setText("");
  2509. pdesc4->setText(tr("Downloading files, please wait..."));
  2510. pdesc3->setText(tr("<b>Source:</b> <a href=\"%1\">%1</a>").arg(fileurl));
  2511. pdesc2->setText(tr("<b>Destination:</b> %1").arg(targetfile));
  2512. pdesc1->setText(tr("<b>Downloaded:</b> 0 bytes"));
  2513. QString realupath = QString(fileurl).remove(0, fileurl.indexOf(QString("://%1").arg(dlurl.host())) + QString("://%1").arg(dlurl.host()).length());
  2514. if (isftp)
  2515. {
  2516. connect(&dlftp, SIGNAL(done(bool)), &dlewait, SLOT(quit()));
  2517. connect(&dlftp, SIGNAL(dataTransferProgress(qint64, qint64)), this, SLOT(dlprogressupdate64(qint64, qint64)));
  2518. }
  2519. else
  2520. {
  2521. connect(&dlhttp, SIGNAL(done(bool)), &dlewait, SLOT(quit()));
  2522. connect(&dlhttp, SIGNAL(dataReadProgress(int, int)), this, SLOT(dlprogressupdate(int, int)));
  2523. }
  2524. QFile dloutfile;
  2525. if (installType == tr("USB Drive"))
  2526. {
  2527. dloutfile.setFileName(randtmpfile::getrandfilename(ubntmpf, "tmp"));
  2528. }
  2529. else
  2530. {
  2531. dloutfile.setFileName(targetfile);
  2532. }
  2533. dloutfile.open(QIODevice::WriteOnly);
  2534. if (isftp)
  2535. {
  2536. dlftp.connectToHost(dlurl.host());
  2537. dlftp.login();
  2538. dlftp.get(realupath, &dloutfile);
  2539. }
  2540. else
  2541. {
  2542. dlhttp.setHost(dlurl.host());
  2543. ubngetrequestheader dlrequest(dlurl.host(), realupath);
  2544. dlhttp.request(dlrequest, 0, &dloutfile);
  2545. }
  2546. dlewait.exec();
  2547. if (!isftp)
  2548. {
  2549. QHttpResponseHeader dlresponse(dlhttp.lastResponse());
  2550. int dlrstatus = dlresponse.statusCode();
  2551. if (dlrstatus >= 300 && dlrstatus < 400 && dlresponse.hasKey("Location"))
  2552. {
  2553. dloutfile.close();
  2554. rmFile(dloutfile);
  2555. downloadfile(dlresponse.value("Location"), targetfile, minsize);
  2556. return;
  2557. }
  2558. }
  2559. if (isftp)
  2560. {
  2561. dlftp.close();
  2562. }
  2563. else
  2564. {
  2565. dlhttp.close();
  2566. }
  2567. dloutfile.close();
  2568. if (installType == tr("USB Drive"))
  2569. {
  2570. dloutfile.rename(targetfile);
  2571. }
  2572. if (QFile(targetfile).size() <= 4096)
  2573. {
  2574. QString redirectTargetURL;
  2575. QFile seeRedirect(targetfile);
  2576. seeRedirect.open(QIODevice::ReadOnly | QIODevice::Text);
  2577. QTextStream seeRedirectTextStream(&seeRedirect);
  2578. while (!seeRedirectTextStream.atEnd())
  2579. {
  2580. QString curline = seeRedirectTextStream.readLine();
  2581. if (curline.contains("content=\"0;url="))
  2582. {
  2583. int urlstartidx = curline.indexOf("content=\"0;url=") + QString("content=\"0;url=").size();
  2584. redirectTargetURL = curline.mid(urlstartidx);
  2585. if (redirectTargetURL.contains("\""))
  2586. {
  2587. redirectTargetURL = redirectTargetURL.left(redirectTargetURL.indexOf("\""));
  2588. }
  2589. break;
  2590. }
  2591. if (curline.contains("content='0;url="))
  2592. {
  2593. int urlstartidx = curline.indexOf("content='0;url=") + QString("content='0;url=").size();
  2594. redirectTargetURL = curline.mid(urlstartidx);
  2595. if (redirectTargetURL.contains("'"))
  2596. {
  2597. redirectTargetURL = redirectTargetURL.left(redirectTargetURL.indexOf("'"));
  2598. }
  2599. break;
  2600. }
  2601. }
  2602. seeRedirect.close();
  2603. if (!redirectTargetURL.isEmpty())
  2604. {
  2605. rmFile(targetfile);
  2606. downloadfile(redirectTargetURL, targetfile, minsize);
  2607. return;
  2608. }
  2609. }
  2610. if (QFile(targetfile).size() < minsize)
  2611. {
  2612. // download failed
  2613. showDownloadFailedScreen(fileurl);
  2614. return;
  2615. }
  2616. pdesc4->setText("");
  2617. pdesc3->setText("");
  2618. pdesc2->setText("");
  2619. pdesc1->setText("");
  2620. tprogress->setValue(0);
  2621. if (testingDownload)
  2622. {
  2623. // Note that this only tests that the first download succeeds
  2624. printf("exitstatus:downloadcomplete\n");
  2625. QApplication::exit();
  2626. exit(0);
  2627. }
  2628. }
  2629. void unetbootin::showDownloadFailedScreen(const QString &fileurl)
  2630. {
  2631. progresslayer->setEnabled(false);
  2632. progresslayer->hide();
  2633. rebootlayer->setEnabled(true);
  2634. rebootlayer->show();
  2635. rebootmsgtext->setText(tr("Download of %1 %2 from %3 failed. Please try downloading the ISO file from the website directly and supply it via the diskimage option.").arg(nameDistro).arg(nameVersion).arg(fileurl));
  2636. this->frebootbutton->setEnabled(false);
  2637. this->frebootbutton->hide();
  2638. this->downloadFailed = true;
  2639. if (exitOnCompletion)
  2640. {
  2641. printf("exitstatus:downloadfailed\n");
  2642. QApplication::exit();
  2643. exit(0);
  2644. }
  2645. }
  2646. void unetbootin::dlprogressupdate(int dlbytes, int maxbytes)
  2647. {
  2648. QTime time = QTime::currentTime();
  2649. static int oldsec = 0;
  2650. // refresh the progress bar every second
  2651. if(oldsec != time.second())
  2652. {
  2653. oldsec = time.second();
  2654. tprogress->setValue(dlbytes);
  2655. tprogress->setMaximum(maxbytes);
  2656. // display the downloaded size with suffix
  2657. pdesc1->setText(tr("<b>Downloaded:</b> %1 of %2").arg(displayfisize(dlbytes)).arg(displayfisize(maxbytes)));
  2658. }
  2659. }
  2660. void unetbootin::dlprogressupdate64(qint64 dlbytes, qint64 maxbytes)
  2661. {
  2662. QTime time = QTime::currentTime();
  2663. static int oldsec = 0;
  2664. // refresh the progress bar every second
  2665. if(oldsec != time.second())
  2666. {
  2667. oldsec = time.second();
  2668. tprogress->setValue(dlbytes);
  2669. tprogress->setMaximum(maxbytes);
  2670. // display the downloaded size with suffix
  2671. pdesc1->setText(tr("<b>Downloaded:</b> %1 of %2").arg(displayfisize(dlbytes)).arg(displayfisize(maxbytes)));
  2672. }
  2673. }
  2674. void unetbootin::cpprogressupdate64(qint64 dlbytes, qint64 maxbytes)
  2675. {
  2676. QTime time = QTime::currentTime();
  2677. static int oldsec = 0;
  2678. // refresh the progress bar every second
  2679. if(oldsec != time.second())
  2680. {
  2681. oldsec = time.second();
  2682. tprogress->setValue(dlbytes);
  2683. tprogress->setMaximum(maxbytes);
  2684. // display the downloaded size with suffix
  2685. pdesc1->setText(tr("<b>Copied:</b> %1 of %2").arg(displayfisize(dlbytes)).arg(displayfisize(maxbytes)));
  2686. }
  2687. }
  2688. QString unetbootin::downloadpagecontents(QString pageurl)
  2689. {
  2690. QUrl pgurl(pageurl);
  2691. QHttp pghttp;
  2692. QEventLoop pgwait;
  2693. connect(&pghttp, SIGNAL(done(bool)), &pgwait, SLOT(quit()));
  2694. pghttp.setHost(pgurl.host());
  2695. QString realpgupath = QString(pageurl).remove(0, pageurl.indexOf(QString("://%1").arg(pgurl.host())) + QString("://%1").arg(pgurl.host()).length());
  2696. ubngetrequestheader pgrequest(pgurl.host(), realpgupath);
  2697. pghttp.request(pgrequest);
  2698. pgwait.exec();
  2699. QHttpResponseHeader pgresponse(pghttp.lastResponse());
  2700. int pgrstatus = pgresponse.statusCode();
  2701. if (pgrstatus >= 300 && pgrstatus < 400 && pgresponse.hasKey("Location"))
  2702. {
  2703. return downloadpagecontents(pgresponse.value("Location"));
  2704. }
  2705. else
  2706. {
  2707. return QString(pghttp.readAll());
  2708. }
  2709. }
  2710. QStringList unetbootin::lstFtpDirFiles(QString ldfDirStringUrl, int ldfMinSize, int ldfMaxSize)
  2711. {
  2712. QUrl ldfDirUrl(ldfDirStringUrl);
  2713. QFtp ldfFtp;
  2714. QEventLoop ldfWait;
  2715. nDirListStor nDirListStorL;
  2716. nDirListStorL.nMinFileSizeBytes = ldfMinSize;
  2717. nDirListStorL.nMaxFileSizeBytes = ldfMaxSize;
  2718. nDirListStorL.searchsymlinks = this->searchsymlinks;
  2719. connect(&ldfFtp, SIGNAL(done(bool)), &ldfWait, SLOT(quit()));
  2720. connect(&ldfFtp, SIGNAL(listInfo(QUrlInfo)), &nDirListStorL, SLOT(sAppendSelfUrlInfoList(QUrlInfo)));
  2721. ldfFtp.connectToHost(ldfDirUrl.host());
  2722. ldfFtp.login();
  2723. ldfFtp.list(ldfDirUrl.path());
  2724. ldfWait.exec();
  2725. ldfFtp.close();
  2726. return nDirListStorL.nDirFileListSL;
  2727. }
  2728. QStringList unetbootin::lstHttpDirFiles(QString ldfDirStringUrl)
  2729. {
  2730. QStringList relativefilelinksL;
  2731. QStringList relativelinksLPreFilter =
  2732. downloadpagecontents(ldfDirStringUrl)
  2733. .replace(">", ">\n")
  2734. .replace("<", "\n<")
  2735. .split("\n");
  2736. QStringList relativelinksLPart1 =
  2737. relativelinksLPreFilter
  2738. .filter(QRegExp("<a href=\"(?!\\?)\\S{1,}\">", Qt::CaseInsensitive))
  2739. .replaceInStrings(QRegExp("<a href=\"", Qt::CaseInsensitive), "")
  2740. .replaceInStrings("\">", "");
  2741. QStringList relativelinksLPart2 =
  2742. relativelinksLPreFilter
  2743. .filter(QRegExp("<a href=\'(?!\\?)\\S{1,}\'>", Qt::CaseInsensitive))
  2744. .replaceInStrings(QRegExp("<a href=\'", Qt::CaseInsensitive), "")
  2745. .replaceInStrings("\'>", "");
  2746. QStringList relativelinksL = relativelinksLPart1 << relativelinksLPart2;
  2747. for (int i = 0; i < relativelinksL.size(); ++i)
  2748. {
  2749. if (!relativelinksL.at(i).endsWith('/'))
  2750. relativefilelinksL.append(relativelinksL.at(i));
  2751. }
  2752. return relativefilelinksL;
  2753. }
  2754. QStringList unetbootin::lstNetDirFiles(QString ldfDirStringUrl, int ldfMinSize, int ldfMaxSize)
  2755. {
  2756. if (!ldfDirStringUrl.endsWith('/'))
  2757. ldfDirStringUrl += '/';
  2758. if (ldfDirStringUrl.startsWith("ftp"))
  2759. {
  2760. return lstFtpDirFiles(ldfDirStringUrl, ldfMinSize, ldfMaxSize);
  2761. }
  2762. else
  2763. {
  2764. return lstHttpDirFiles(ldfDirStringUrl);
  2765. }
  2766. }
  2767. QPair<QString, int> unetbootin::weightedFilterNetDir(QString ldfDirStringUrl, int ldfMinSize, int ldfMaxSize, QList<QRegExp> ldfFileMatchExp)
  2768. {
  2769. if (!ldfDirStringUrl.endsWith('/'))
  2770. ldfDirStringUrl += '/';
  2771. pdesc1->setText(tr("Searching in <a href=\"%1\">%1</a>").arg(ldfDirStringUrl));
  2772. QPair<QString, int> relativeFileUrl = filterBestMatch(lstNetDirFiles(ldfDirStringUrl, ldfMinSize, ldfMaxSize), ldfFileMatchExp);
  2773. if (relativeFileUrl.first.startsWith('/'))
  2774. ldfDirStringUrl = ldfDirStringUrl.left(ldfDirStringUrl.indexOf('/', 8));
  2775. pdesc2->setText(tr("%1/%2 matches in <a href=\"%3\">%3</a>").arg(relativeFileUrl.second).arg(ldfFileMatchExp.size()).arg(ldfDirStringUrl));
  2776. return qMakePair(ldfDirStringUrl+relativeFileUrl.first, relativeFileUrl.second);
  2777. }
  2778. QString unetbootin::fileFilterNetDir(QStringList ldfDirStringUrlList, int ldfMinSize, int ldfMaxSize, QList<QRegExp> ldfFileMatchExp)
  2779. {
  2780. QPair<QString, int> curRemoteFileUrlSP;
  2781. int hRegxMatch = 0;
  2782. QString hRegxMatchString;
  2783. for (int i = 0; i < ldfDirStringUrlList.size(); ++i)
  2784. {
  2785. curRemoteFileUrlSP = weightedFilterNetDir(ldfDirStringUrlList.at(i), ldfMinSize, ldfMaxSize, ldfFileMatchExp);
  2786. if (curRemoteFileUrlSP.second == ldfFileMatchExp.size())
  2787. return curRemoteFileUrlSP.first;
  2788. if (curRemoteFileUrlSP.second > hRegxMatch)
  2789. {
  2790. hRegxMatch = curRemoteFileUrlSP.second;
  2791. hRegxMatchString = curRemoteFileUrlSP.first;
  2792. }
  2793. }
  2794. return hRegxMatchString;
  2795. }
  2796. QPair<QString, int> unetbootin::filterBestMatch(QStringList ufStringList, QList<QRegExp> filterExpList)
  2797. {
  2798. QString hRegxMatchString, hRegxMatchStringEnd;
  2799. int hRegxMatch = 0;
  2800. for (int i = 0; i < ufStringList.size(); ++i)
  2801. {
  2802. int regxmatches = 0;
  2803. hRegxMatchStringEnd = ufStringList.at(i).right(ufStringList.at(i).size() - ufStringList.at(i).lastIndexOf('/') - 1);
  2804. for (int j = 0; j < filterExpList.size(); ++j)
  2805. {
  2806. if (hRegxMatchStringEnd.contains(filterExpList.at(j)))
  2807. ++regxmatches;
  2808. }
  2809. if (regxmatches >= hRegxMatch)
  2810. {
  2811. hRegxMatchString = ufStringList.at(i);
  2812. hRegxMatch = regxmatches;
  2813. }
  2814. }
  2815. return qMakePair(hRegxMatchString, hRegxMatch);
  2816. }
  2817. void unetbootin::sysreboot()
  2818. {
  2819. #ifdef Q_OS_WIN32
  2820. HANDLE hToken;
  2821. TOKEN_PRIVILEGES tkp;
  2822. OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken);
  2823. LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
  2824. tkp.PrivilegeCount = 1;
  2825. tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  2826. AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
  2827. ExitWindowsEx(EWX_REBOOT, EWX_FORCE);
  2828. #endif
  2829. #ifdef Q_OS_LINUX
  2830. callexternapp("init", "6 &");
  2831. #endif
  2832. #ifdef Q_OS_MAC
  2833. callexternapp("shutdown", "-r now &");
  2834. #endif
  2835. }
  2836. QString unetbootin::callexternapp(QString xexecFile, QString xexecParm)
  2837. {
  2838. QEventLoop cxaw;
  2839. callexternappT cxat;
  2840. connect(&cxat, SIGNAL(finished()), &cxaw, SLOT(quit()));
  2841. cxat.execFile = xexecFile;
  2842. cxat.execParm = xexecParm;
  2843. cxat.start();
  2844. cxaw.exec();
  2845. return cxat.retnValu;
  2846. }
  2847. QString unetbootin::callexternappWriteToStdin(QString xexecFile, QString xexecParm, QString xwriteToStdin)
  2848. {
  2849. QEventLoop cxaw;
  2850. callexternappWriteToStdinT cxat;
  2851. connect(&cxat, SIGNAL(finished()), &cxaw, SLOT(quit()));
  2852. cxat.execFile = xexecFile;
  2853. cxat.execParm = xexecParm;
  2854. cxat.writeToStdin = xwriteToStdin;
  2855. cxat.start();
  2856. cxaw.exec();
  2857. return cxat.retnValu;
  2858. }
  2859. QString unetbootin::getdevluid(QString voldrive)
  2860. {
  2861. #ifdef Q_OS_MAC
  2862. QString diskutilinfo = callexternapp("diskutil", "info " + voldrive);
  2863. QString uuidS = getuuid(voldrive, diskutilinfo);
  2864. if (uuidS == "None")
  2865. {
  2866. return QString("LABEL=%1").arg(getlabel(voldrive, diskutilinfo));
  2867. }
  2868. else
  2869. {
  2870. return QString("UUID=%1").arg(uuidS);
  2871. }
  2872. #endif
  2873. #ifndef Q_OS_MAC
  2874. QString uuidS = getuuid(voldrive);
  2875. if (uuidS == "None")
  2876. {
  2877. return QString("LABEL=%1").arg(getlabel(voldrive));
  2878. }
  2879. else
  2880. {
  2881. return QString("UUID=%1").arg(uuidS);
  2882. }
  2883. #endif
  2884. }
  2885. #ifdef Q_OS_MAC
  2886. QString unetbootin::getlabel(QString voldrive, QString diskutilinfo)
  2887. {
  2888. QStringList diskutiloutput = diskutilinfo.split("\n");
  2889. QStringList labelLines = diskutiloutput.filter("Volume Name");
  2890. if (labelLines.size() == 0)
  2891. return "None";
  2892. QStringList labelAtEnd = labelLines.at(0).split(":");
  2893. if (labelAtEnd.size() < 2)
  2894. return "None";
  2895. return labelAtEnd.at(labelAtEnd.size()-1).trimmed();
  2896. }
  2897. #endif
  2898. QString unetbootin::getlabel(QString voldrive)
  2899. {
  2900. #ifdef Q_OS_MAC
  2901. return getlabel(voldrive, callexternapp("diskutil", "info " + voldrive));
  2902. #endif
  2903. #ifdef Q_OS_WIN32
  2904. voldrive.append("\\");
  2905. wchar_t vollabel[50];
  2906. GetVolumeInformation(LPWSTR(voldrive.utf16()), vollabel, 50, NULL, NULL, NULL, NULL, NULL);
  2907. QString vollabelS = QString::fromWCharArray(vollabel);
  2908. if (vollabelS.isEmpty())
  2909. {
  2910. return "None";
  2911. }
  2912. else
  2913. {
  2914. return vollabelS;
  2915. }
  2916. #endif
  2917. #ifdef Q_OS_LINUX
  2918. QString volidpS = "";
  2919. if (!volidcommand.isEmpty())
  2920. volidpS = QString(callexternapp(volidcommand, QString("-l %1").arg(voldrive))).remove("\r").remove("\n").trimmed();
  2921. else
  2922. {
  2923. QString tstrblk = QString(callexternapp(blkidcommand, QString("-s LABEL %1").arg(voldrive)));
  2924. if (tstrblk.contains('='))
  2925. volidpS = tstrblk.section('=', -1, -1).remove('"').remove("\r").remove("\n").trimmed();
  2926. }
  2927. if (volidpS.isEmpty())
  2928. {
  2929. return "None";
  2930. }
  2931. else
  2932. {
  2933. return volidpS;
  2934. }
  2935. #endif
  2936. }
  2937. #ifdef Q_OS_MAC
  2938. QString unetbootin::getuuid(QString voldrive, QString diskutilinfo)
  2939. {
  2940. QStringList diskutiloutput = diskutilinfo.split("\n");
  2941. QStringList uuidList = diskutiloutput.filter("UUID"); // TODO untested
  2942. if (uuidList.size() > 0)
  2943. {
  2944. uuidList = uuidList.at(0).split(" ");
  2945. return uuidList.at(uuidList.size()-1).trimmed();
  2946. }
  2947. // otherwise FAT32 or FAT16; return serial number
  2948. bool isFat32 = diskutiloutput.filter("FAT32").size() > 0;
  2949. if (!isFat32)
  2950. {
  2951. if (diskutiloutput.filter("FAT16").size() == 0 && diskutiloutput.filter("FAT12").size() == 0)
  2952. return "None";
  2953. }
  2954. callexternapp("diskutil", "umount "+targetDev);
  2955. QFile rawDevice(voldrive);
  2956. rawDevice.open(QIODevice::ReadOnly);
  2957. if (isFat32)
  2958. {
  2959. rawDevice.seek(67);
  2960. }
  2961. else // FAT16 or FAT12
  2962. {
  2963. rawDevice.seek(39);
  2964. }
  2965. unsigned char pserial[4];
  2966. rawDevice.read((char*)pserial, 4);
  2967. QString serialNumber = QString::number(pserial[3], 16).rightJustified(2, '0')+QString::number(pserial[2], 16).rightJustified(2, '0')+"-"+QString::number(pserial[1], 16).rightJustified(2, '0')+QString::number(pserial[0], 16).rightJustified(2, '0');
  2968. rawDevice.close();
  2969. callexternapp("diskutil", "mount "+targetDev);
  2970. return serialNumber.toUpper();
  2971. }
  2972. #endif
  2973. QString unetbootin::getuuid(QString voldrive)
  2974. {
  2975. #ifdef Q_OS_MAC
  2976. return getuuid(voldrive, callexternapp("diskutil", "info " + voldrive));
  2977. #endif
  2978. #ifdef Q_OS_WIN32
  2979. voldrive.append("\\");
  2980. DWORD volserialnum = 0;
  2981. GetVolumeInformation(LPWSTR(voldrive.utf16()), NULL, NULL, &volserialnum, NULL, NULL, NULL, NULL);
  2982. if (!(volserialnum >= 1))
  2983. {
  2984. return "None";
  2985. }
  2986. QString tvolsernum = QString::number(volserialnum, 16).toUpper();
  2987. if (tvolsernum.size() == 8)
  2988. {
  2989. return QString("%1-%2").arg(tvolsernum.left(4), tvolsernum.right(4));
  2990. }
  2991. else
  2992. {
  2993. return tvolsernum;
  2994. }
  2995. #endif
  2996. #ifdef Q_OS_LINUX
  2997. QString volidpS = "";
  2998. if (!volidcommand.isEmpty())
  2999. volidpS = QString(callexternapp(volidcommand, QString("-u %1").arg(voldrive))).remove("\r").remove("\n").trimmed();
  3000. else
  3001. {
  3002. QString tstrblk = QString(callexternapp(blkidcommand, QString("-s UUID %1").arg(voldrive)));
  3003. if (tstrblk.contains('='))
  3004. volidpS = tstrblk.section('=', -1, -1).remove('"').remove("\r").remove("\n").trimmed();
  3005. }
  3006. if (volidpS.isEmpty())
  3007. {
  3008. return "None";
  3009. }
  3010. else
  3011. {
  3012. return volidpS;
  3013. }
  3014. #endif
  3015. }
  3016. #ifdef Q_OS_UNIX
  3017. QString unetbootin::locatecommand(QString commandtolocate, QString reqforinstallmode, QString packagename)
  3018. {
  3019. QString commandbinpath = callexternapp("which", commandtolocate).trimmed();
  3020. if (!commandbinpath.isEmpty() && QFile::exists(commandbinpath))
  3021. return commandbinpath;
  3022. if (packagename == "silent")
  3023. return "";
  3024. // QString commandbinpath = callexternapp("whereis", commandtolocate);
  3025. // QStringList commandbinpathL = commandbinpath.split(" ").join("\n").split("\t").join("\n").split("\n");
  3026. // for (int i = 0; i < commandbinpathL.size(); ++i)
  3027. // {
  3028. // if (commandbinpathL.at(i).contains("bin/"))
  3029. // {
  3030. // return commandbinpathL.at(i);
  3031. // }
  3032. // }
  3033. QMessageBox errorcmdnotfoundmsgbx;
  3034. errorcmdnotfoundmsgbx.setIcon(QMessageBox::Warning);
  3035. errorcmdnotfoundmsgbx.setWindowTitle(QString(tr("%1 not found")).arg(commandtolocate));
  3036. errorcmdnotfoundmsgbx.setText(QString(tr("%1 not found. This is required for %2 install mode.\nInstall the \"%3\" package or your distribution's equivalent.")).arg(commandtolocate, reqforinstallmode, packagename));
  3037. errorcmdnotfoundmsgbx.setStandardButtons(QMessageBox::Ok);
  3038. switch (errorcmdnotfoundmsgbx.exec())
  3039. {
  3040. case QMessageBox::Ok:
  3041. break;
  3042. default:
  3043. break;
  3044. }
  3045. return commandtolocate;
  3046. }
  3047. QString unetbootin::locatedevicenode(QString mountpoint)
  3048. {
  3049. QStringList rawdeviceL = QString(callexternapp("mount", "")).replace("\t", " ").split("\n").filter("/dev/").filter(QString(" %1 ").arg(mountpoint));
  3050. if (rawdeviceL.isEmpty())
  3051. {
  3052. return "NOT FOUND";
  3053. }
  3054. else
  3055. {
  3056. return QFileInfo(rawdeviceL.at(0).split(" ").at(0)).canonicalFilePath();
  3057. }
  3058. }
  3059. QString unetbootin::locatemountpoint(QString devicenode)
  3060. {
  3061. QStringList procmountsL = callexternapp("mount", "").split("\n");
  3062. for (int i = 0; i < procmountsL.size(); ++i)
  3063. {
  3064. QString mountinfo = procmountsL.at(i).split("\t").join(" ");
  3065. QStringList deviceAndRest = mountinfo.split(" on ");
  3066. if (deviceAndRest.size() < 2)
  3067. continue;
  3068. if (deviceAndRest.at(0).trimmed() != devicenode)
  3069. continue;
  3070. QStringList mountpointAndOptions = deviceAndRest.at(1).split(" (").join(" type ").split(" type ");
  3071. if (mountpointAndOptions.size() < 1)
  3072. continue;
  3073. QString mountpoint = mountpointAndOptions.at(0).trimmed();
  3074. if (QDir(mountpoint).exists())
  3075. return mountpoint;
  3076. }
  3077. return "NOT MOUNTED";
  3078. }
  3079. QString unetbootin::getGrubNotation(QString devicenode)
  3080. {
  3081. return QString("(hd%1,%2)").arg(getDiskNumber(devicenode)).arg(getPartitionNumber(devicenode));
  3082. }
  3083. QString unetbootin::getGrub2Notation(QString devicenode)
  3084. {
  3085. return QString("(hd%1,%2)").arg(getDiskNumber(devicenode)).arg(getPartitionNumber(devicenode)+1);
  3086. }
  3087. int unetbootin::letterToNumber(QChar lettertoconvert)
  3088. {
  3089. if (lettertoconvert.isLower())
  3090. {
  3091. return static_cast<int>(lettertoconvert.toAscii() - 'a');
  3092. }
  3093. if (lettertoconvert.isUpper())
  3094. {
  3095. return static_cast<int>(lettertoconvert.toAscii() - 'A');
  3096. }
  3097. else
  3098. {
  3099. return 999;
  3100. }
  3101. }
  3102. int unetbootin::getDiskNumber(QString devicenode)
  3103. {
  3104. QChar disknumchar(devicenode.at(devicenode.size() - 2));
  3105. if (disknumchar.isLetter())
  3106. {
  3107. return letterToNumber(disknumchar);
  3108. }
  3109. else
  3110. {
  3111. return disknumchar.digitValue() - 1;
  3112. }
  3113. }
  3114. int unetbootin::getPartitionNumber(QString devicenode)
  3115. {
  3116. QChar partitionchar(devicenode.at(devicenode.size() - 1));
  3117. if (partitionchar.isLetter())
  3118. {
  3119. return letterToNumber(partitionchar);
  3120. }
  3121. else
  3122. {
  3123. return partitionchar.digitValue() - 1;
  3124. }
  3125. }
  3126. #endif
  3127. #ifdef Q_OS_WIN32
  3128. void unetbootin::installsvzip()
  3129. {
  3130. if (QFile::exists(QString("%1\\7z.dll").arg(ubntmpf)))
  3131. {
  3132. rmFile(QString("%1\\7z.dll").arg(ubntmpf));
  3133. }
  3134. instIndvfl("sevnz.dll", QString("%1\\7z.dll").arg(ubntmpf));
  3135. if (QFile::exists(QString("%1sevnz.exe").arg(ubntmpf)))
  3136. {
  3137. rmFile(QString("%1sevnz.exe").arg(ubntmpf));
  3138. }
  3139. instIndvfl("sevnz.exe", QString("%1sevnz.exe").arg(ubntmpf));
  3140. sevzcommand = QString("%1sevnz.exe").arg(ubntmpf);
  3141. }
  3142. void unetbootin::configsysEdit()
  3143. {
  3144. SetFileAttributesA(QDir::toNativeSeparators(QString("%1config.sys").arg(targetDrive)).toAscii(), FILE_ATTRIBUTE_NORMAL);
  3145. QFile::copy(QDir::toNativeSeparators(QString("%1config.sys").arg(targetDrive)), QString("%1config.sys").arg(targetPath));
  3146. QFile::copy(QDir::toNativeSeparators(QString("%1config.sys").arg(targetDrive)), QString("%1confignw.txt").arg(targetPath));
  3147. QFile confignwFile(QString("%1confignw.txt").arg(targetPath));
  3148. QFile configsysFile(QDir::toNativeSeparators(QString("%1config.sys").arg(targetDrive)));
  3149. confignwFile.open(QIODevice::ReadWrite | QIODevice::Text);
  3150. configsysFile.open(QIODevice::ReadOnly | QIODevice::Text);
  3151. QTextStream confignwOut(&confignwFile);
  3152. QTextStream configsysOut(&configsysFile);
  3153. QString configsysText = QString("[menu]\n"
  3154. "menucolor=15,0\n"
  3155. "menuitem=windows,Windows\n"
  3156. "menuitem=grub,"UNETBOOTINB"\n"
  3157. "menudefault=windows,30\n"
  3158. "[grub]\n"
  3159. "device=ubnldr.exe\n"
  3160. "[windows]\n%1").arg(configsysOut.readAll());
  3161. confignwOut << configsysText << endl;
  3162. if (!QFile::copy(QString("%1confignw.txt").arg(targetPath), QDir::toNativeSeparators(QString("%1config.sys").arg(targetDrive))))
  3163. {
  3164. rmFile(configsysFile);
  3165. QFile::copy(QString("%1confignw.txt").arg(targetPath), QDir::toNativeSeparators(QString("%1config.sys").arg(targetDrive)));
  3166. }
  3167. }
  3168. void unetbootin::bootiniEdit()
  3169. {
  3170. SetFileAttributesW(LPWSTR(QDir::toNativeSeparators(QString("%1boot.ini").arg(targetDrive)).utf16()), FILE_ATTRIBUTE_NORMAL);
  3171. QFile::copy(QDir::toNativeSeparators(QString("%1boot.ini").arg(targetDrive)), QString("%1boot.ini").arg(targetPath));
  3172. QFile::copy(QDir::toNativeSeparators(QString("%1bootnw.ini").arg(targetDrive)), QString("%1bootnw.txt").arg(targetPath));
  3173. QFile bootnwFile(QString("%1bootnw.txt").arg(targetPath));
  3174. QFile bootiniFile(QDir::toNativeSeparators(QString("%1boot.ini").arg(targetDrive)));
  3175. bootnwFile.open(QIODevice::ReadWrite | QIODevice::Text);
  3176. bootiniFile.open(QIODevice::ReadOnly | QIODevice::Text);
  3177. QTextStream bootnwOut(&bootnwFile);
  3178. QTextStream bootiniOut(&bootiniFile);
  3179. QStringList bootiniCurTextL;
  3180. bool btimustreplacetimeout = true;
  3181. QRegExp btichkistimeout("\\s{0,}timeout.{0,}", Qt::CaseInsensitive);
  3182. QString bootiniCurLine;
  3183. while (!bootiniOut.atEnd())
  3184. {
  3185. bootiniCurLine = bootiniOut.readLine();
  3186. if (btimustreplacetimeout && btichkistimeout.exactMatch(bootiniCurLine))
  3187. {
  3188. bootiniCurTextL.append("timeout=15");
  3189. btimustreplacetimeout = false;
  3190. }
  3191. else
  3192. {
  3193. bootiniCurTextL.append(bootiniCurLine);
  3194. }
  3195. }
  3196. QString bootiniCurText = bootiniCurTextL.join("\n");
  3197. QString bootiniText = QString("%1\n%2=\""UNETBOOTINB"\"").arg(bootiniCurText).arg(QDir::toNativeSeparators(QString("%1ubnldr.mbr").arg(targetDrive)));
  3198. bootnwOut << bootiniText << endl;
  3199. if (!QFile::copy(QString("%1bootnw.txt").arg(targetPath), QDir::toNativeSeparators(QString("%1boot.ini").arg(targetDrive))))
  3200. {
  3201. rmFile(bootiniFile);
  3202. QFile::copy(QString("%1bootnw.txt").arg(targetPath), QDir::toNativeSeparators(QString("%1boot.ini").arg(targetDrive)));
  3203. }
  3204. }
  3205. void unetbootin::vistabcdEdit()
  3206. {
  3207. bool warch64 = false;
  3208. if (!QProcess::systemEnvironment().filter("ProgramW6432").isEmpty())
  3209. warch64 = true;
  3210. instIndvfl("emtxfile.exe", QString("%1emtxfile.exe").arg(targetPath));
  3211. QFile vbcdEditF1(QString("%1vbcdedit.bat").arg(targetPath));
  3212. vbcdEditF1.open(QIODevice::ReadWrite | QIODevice::Text);
  3213. QTextStream vbcdEditS1(&vbcdEditF1);
  3214. vbcdEditS1 << QString("bcdedit /create /d \""UNETBOOTINB"\" /application bootsector > %1tmpbcdid").arg(targetPath) << endl;
  3215. vbcdEditF1.close();
  3216. if (!warch64)
  3217. callexternapp(QString("%1vbcdedit.bat").arg(targetPath), "");
  3218. QFile vbcdTmpInF(QString("%1tmpbcdid").arg(targetPath));
  3219. vbcdTmpInF.open(QIODevice::ReadOnly | QIODevice::Text);
  3220. QTextStream vbcdTmpInS(&vbcdTmpInF);
  3221. QString qstmpvbcdin = vbcdTmpInS.readAll();
  3222. vbcdTmpInF.close();
  3223. QString vbcdIdTL;
  3224. QStringList vbcdIdTLSL;
  3225. if (!warch64)
  3226. {
  3227. vbcdIdTLSL = qstmpvbcdin.replace("{", "\n").replace("}", "\n").split("\n").filter("-");
  3228. if (!vbcdIdTLSL.isEmpty())
  3229. vbcdIdTL = vbcdIdTLSL.at(0);
  3230. }
  3231. else
  3232. {
  3233. callexternapp(QString("%1emtxfile.exe").arg(targetPath), QString("%1vbcdedit.bat runas").arg(targetPath));
  3234. vbcdTmpInF.open(QIODevice::ReadOnly | QIODevice::Text);
  3235. QTextStream vbcdTmpInS2(&vbcdTmpInF);
  3236. vbcdIdTLSL = vbcdTmpInS2.readAll().replace("{", "\n").replace("}", "\n").split("\n").filter("-");
  3237. if (!vbcdIdTLSL.isEmpty())
  3238. vbcdIdTL = vbcdIdTLSL.at(0);
  3239. vbcdTmpInF.close();
  3240. }
  3241. QSettings vdtistor("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\UNetbootin", QSettings::NativeFormat);
  3242. vdtistor.setValue("WArch64", warch64);
  3243. QFile vbcdEditF2(QString("%1vbcdedt2.bat").arg(targetPath));
  3244. vbcdEditF2.open(QIODevice::ReadWrite | QIODevice::Text);
  3245. QTextStream vbcdEditS2(&vbcdEditF2);
  3246. vbcdEditS2 << QString("bcdedit /set {%1} device boot\n"
  3247. "bcdedit /set {%1} path \\ubnldr.mbr\n"
  3248. "bcdedit /set {%1} device partition=%2\n"
  3249. "bcdedit /displayorder {%1} /addlast\n"
  3250. "bcdedit /timeout 30").arg(vbcdIdTL).arg(targetDev) << endl;
  3251. vbcdEditF2.close();
  3252. if (warch64)
  3253. {
  3254. callexternapp(QString("%1emtxfile.exe").arg(targetPath), QString("%1vbcdedt2.bat runas").arg(targetPath));
  3255. }
  3256. else
  3257. {
  3258. callexternapp(QString("%1vbcdedt2.bat").arg(targetPath), "");
  3259. }
  3260. QFile vbcdundoF(QString("%1vbcdundo.bat").arg(targetPath));
  3261. vbcdundoF.open(QIODevice::ReadWrite | QIODevice::Text);
  3262. QTextStream vbcdundoS(&vbcdundoF);
  3263. vbcdundoS << QString("bcdedit /delete {%1}").arg(vbcdIdTL) << endl;
  3264. vbcdundoF.close();
  3265. }
  3266. #endif
  3267. void unetbootin::instIndvfl(QString srcfName, QString dstfName)
  3268. {
  3269. QFile srcF(QString(":/%1").arg(srcfName));
  3270. #ifdef NOSTATIC
  3271. if (srcfName == "memdisk")
  3272. srcF.setFileName(QFile::exists("/usr/share/syslinux/memdisk") ? "/usr/share/syslinux/memdisk" : "/usr/lib/syslinux/memdisk");
  3273. else if (srcfName == "menu.c32")
  3274. srcF.setFileName(QFile::exists("/usr/share/syslinux/menu.c32") ? "/usr/share/syslinux/menu.c32" : "/usr/lib/syslinux/menu.c32");
  3275. else if (srcfName == "libutil.c32")
  3276. srcF.setFileName(QFile::exists("/usr/share/syslinux/libutil.c32") ? "/usr/share/syslinux/libutil.c32" : "/usr/lib/syslinux/libutil.c32");
  3277. else if (srcfName == "libcom32.c32")
  3278. srcF.setFileName(QFile::exists("/usr/share/syslinux/libcom32.c32") ? "/usr/share/syslinux/libcom32.c32" : "/usr/lib/syslinux/libcom32.c32");
  3279. else if (srcfName == "mbr.bin")
  3280. srcF.setFileName(QFile::exists("/usr/share/syslinux/mbr.bin") ? "/usr/share/syslinux/mbr.bin" : "/usr/lib/syslinux/mbr.bin");
  3281. else if (srcfName == "ubnsylnx")
  3282. srcF.setFileName("/usr/bin/syslinux");
  3283. // else
  3284. // srcF.setFileName(QString("/usr/lib/unetbootin/%1").arg(srcfName));
  3285. #endif
  3286. if (!srcF.exists())
  3287. {
  3288. return;
  3289. }
  3290. if (QFile::exists(dstfName))
  3291. {
  3292. if (!overwritefileprompt(dstfName))
  3293. return;
  3294. }
  3295. QFile dstF(dstfName);
  3296. dstF.open(QIODevice::WriteOnly);
  3297. srcF.open(QIODevice::ReadOnly);
  3298. dstF.write(srcF.readAll());
  3299. dstF.close();
  3300. srcF.close();
  3301. }
  3302. QString unetbootin::instTempfl(QString srcfName, QString dstfType)
  3303. {
  3304. QString dstfName = randtmpfile::getrandfilename(ubntmpf, dstfType);
  3305. instIndvfl(srcfName, dstfName);
  3306. return dstfName;
  3307. }
  3308. void unetbootin::runinst()
  3309. {
  3310. this->trcurrent = tr("(Current)");
  3311. this->trdone = tr("(Done)");
  3312. firstlayer->setEnabled(false);
  3313. firstlayer->hide();
  3314. secondlayer->setEnabled(true);
  3315. secondlayer->show();
  3316. rebootlayer->setEnabled(false);
  3317. rebootlayer->hide();
  3318. progresslayer->setEnabled(true);
  3319. progresslayer->show();
  3320. sdesc1->setText(QString("<b>%1 %2</b>").arg(sdesc1->text()).arg(trcurrent));
  3321. tprogress->setValue(0);
  3322. installType = typeselect->currentText();
  3323. targetDrive = driveselect->currentText();
  3324. persistenceSpaceMB = this->persistencevalue->value();
  3325. QString ginstallDir;
  3326. QString installDir;
  3327. QString isotmpf = randtmpfile::getrandfilename(ubntmpf, "iso");
  3328. #ifdef Q_OS_WIN32
  3329. if (installType == tr("Hard Disk"))
  3330. {
  3331. ginstallDir = "unetbtin/";
  3332. }
  3333. if (installType == tr("USB Drive"))
  3334. {
  3335. ginstallDir = "";
  3336. }
  3337. installDir = ginstallDir;
  3338. targetDev = QString("%1").arg(targetDrive).remove("\\");
  3339. rawtargetDev = targetDev;
  3340. #endif
  3341. #ifdef Q_OS_UNIX
  3342. if (installType == tr("Hard Disk"))
  3343. {
  3344. QString devnboot = locatedevicenode("/boot");
  3345. if (devnboot == "NOT FOUND")
  3346. {
  3347. ginstallDir = "boot/";
  3348. installDir = ginstallDir;
  3349. targetDev = locatedevicenode("/");
  3350. }
  3351. else
  3352. {
  3353. ginstallDir = "";
  3354. installDir = "boot/";
  3355. targetDev = devnboot;
  3356. }
  3357. devluid = getdevluid(targetDev);
  3358. }
  3359. if (installType == tr("USB Drive"))
  3360. {
  3361. targetDev = driveselect->currentText();
  3362. devluid = getdevluid(targetDev);
  3363. ginstallDir = "";
  3364. installDir = ginstallDir;
  3365. targetDrive = QString("%1/").arg(locatemountpoint(targetDev));
  3366. }
  3367. #ifdef Q_OS_LINUX
  3368. if (targetDev.contains(QRegExp("p\\d$")))
  3369. rawtargetDev = QString(targetDev).remove(QRegExp("p\\d$"));
  3370. else
  3371. rawtargetDev = QString(targetDev).remove(QRegExp("\\d$"));
  3372. #endif
  3373. #ifdef Q_OS_MAC
  3374. rawtargetDev = QString(targetDev).remove(QRegExp("s\\d$"));
  3375. #endif
  3376. #endif
  3377. #ifndef Q_OS_UNIX
  3378. devluid = getdevluid(targetDev);
  3379. #endif
  3380. kernelLine = "kernel";
  3381. kernelLoc = QString("/%1ubnkern").arg(ginstallDir);
  3382. initrdLine = "initrd";
  3383. slinitrdLine = "initrd=";
  3384. initrdLoc = QString("/%1ubninit").arg(ginstallDir);
  3385. #ifdef NOINITRD
  3386. initrdLoc = "";
  3387. initrdOpts = "";
  3388. initrdLine = "";
  3389. slinitrdLine = "";
  3390. #endif
  3391. #ifdef NODEFAULTKERNEL
  3392. kernelLoc = "";
  3393. #endif
  3394. targetPath = QDir::toNativeSeparators(QString("%1%2").arg(targetDrive).arg(installDir));
  3395. QDir dir;
  3396. if (!dir.exists(targetPath))
  3397. {
  3398. dir.mkpath(targetPath);
  3399. }
  3400. if (QFile::exists(QString("%1ubnkern").arg(targetPath)))
  3401. {
  3402. overwritefileprompt(QString("%1ubnkern").arg(targetPath));
  3403. }
  3404. if (QFile::exists(QString("%1ubninit").arg(targetPath)))
  3405. {
  3406. overwritefileprompt(QString("%1ubninit").arg(targetPath));
  3407. }
  3408. if (radioFloppy->isChecked())
  3409. {
  3410. if (diskimagetypeselect->currentIndex() == diskimagetypeselect->findText(tr("Floppy")))
  3411. {
  3412. instIndvfl("memdisk", QString("%1ubnkern").arg(targetPath));
  3413. if (!FloppyPath->text().startsWith("http://") && !FloppyPath->text().startsWith("ftp://"))
  3414. QFile::copy(FloppyPath->text(), QString("%1ubninit").arg(targetPath));
  3415. else
  3416. downloadfile(FloppyPath->text(), QString("%1ubninit").arg(targetPath));
  3417. }
  3418. if (diskimagetypeselect->currentIndex() == diskimagetypeselect->findText(tr("ISO")))
  3419. {
  3420. if (!FloppyPath->text().startsWith("http://") && !FloppyPath->text().startsWith("ftp://"))
  3421. extractiso(FloppyPath->text());
  3422. else
  3423. {
  3424. downloadfile(FloppyPath->text(), isotmpf);
  3425. extractiso(isotmpf);
  3426. }
  3427. if (QFile::exists(QString("%1sevnz.exe").arg(ubntmpf)))
  3428. {
  3429. rmFile(QString("%1sevnz.exe").arg(ubntmpf));
  3430. }
  3431. if (QFile::exists(QString("%1\\7z.dll").arg(ubntmpf)))
  3432. {
  3433. rmFile(QString("%1\\7z.dll").arg(ubntmpf));
  3434. }
  3435. }
  3436. }
  3437. else if (radioManual->isChecked())
  3438. {
  3439. if (!KernelPath->text().startsWith("http://") && !KernelPath->text().startsWith("ftp://"))
  3440. QFile::copy(KernelPath->text(), QString("%1ubnkern").arg(targetPath));
  3441. else
  3442. downloadfile(KernelPath->text(), QString("%1ubnkern").arg(targetPath));
  3443. if (!InitrdPath->text().startsWith("http://") && !InitrdPath->text().startsWith("ftp://"))
  3444. QFile::copy(InitrdPath->text(), QString("%1ubninit").arg(targetPath));
  3445. else
  3446. downloadfile(InitrdPath->text(), QString("%1ubninit").arg(targetPath));
  3447. kernelOpts = OptionEnter->text();
  3448. }
  3449. else if (radioDistro->isChecked())
  3450. {
  3451. nameDistro = distroselect->currentText();
  3452. nameVersion = dverselect->currentText();
  3453. if (nameVersion.contains("_Live"))
  3454. {
  3455. nameVersion.remove("_Live");
  3456. islivecd = true;
  3457. }
  3458. else
  3459. {
  3460. islivecd = false;
  3461. }
  3462. if (nameVersion.contains("_NetInstall"))
  3463. {
  3464. nameVersion.remove("_NetInstall");
  3465. isnetinstall = true;
  3466. }
  3467. if (nameVersion.contains("_HdMedia"))
  3468. {
  3469. nameVersion.remove("_HdMedia");
  3470. ishdmedia = true;
  3471. }
  3472. if (nameVersion.contains("_x64"))
  3473. {
  3474. nameVersion.remove("_x64");
  3475. isarch64 = true;
  3476. }
  3477. else
  3478. {
  3479. isarch64 = false;
  3480. }
  3481. QString cpuarch;
  3482. QString relname = nameVersion.toLower();
  3483. #include "customdistrolst.cpp"
  3484. if (QFile::exists(QString("%1sevnz.exe").arg(ubntmpf)))
  3485. {
  3486. rmFile(QString("%1sevnz.exe").arg(ubntmpf));
  3487. }
  3488. if (QFile::exists(QString("%1\\7z.dll").arg(ubntmpf)))
  3489. {
  3490. rmFile(QString("%1\\7z.dll").arg(ubntmpf));
  3491. }
  3492. if (downloadFailed)
  3493. {
  3494. return;
  3495. }
  3496. }
  3497. if (!sdesc1->text().contains(trdone))
  3498. {
  3499. sdesc1->setText(QString(sdesc1->text()).remove("<b>").replace(trcurrent+"</b>", trdone));
  3500. }
  3501. if (sdesc2->text().contains(trcurrent))
  3502. {
  3503. sdesc2->setText(QString(sdesc2->text()).remove("<b>").replace(trcurrent+"</b>", trdone));
  3504. }
  3505. else
  3506. {
  3507. sdesc2->setText(QString("%1 %2").arg(sdesc2->text()).arg(trdone));
  3508. }
  3509. sdesc3->setText(QString("<b>%1 %2</b>").arg(sdesc3->text()).arg(trcurrent));
  3510. tprogress->setValue(0);
  3511. if (this->persistenceSpaceMB > 0 && !issalt)
  3512. {
  3513. this->kernelOpts += " persistent";
  3514. for (int i = 0; i < this->extraoptionsPL.second.second.size(); ++i)
  3515. {
  3516. this->extraoptionsPL.second.second[i] += " persistent";
  3517. }
  3518. }
  3519. instDetType();
  3520. }
  3521. void unetbootin::instDetType()
  3522. {
  3523. if (installType == tr("Hard Disk"))
  3524. {
  3525. runinsthdd();
  3526. }
  3527. if (installType == tr("USB Drive"))
  3528. {
  3529. runinstusb();
  3530. }
  3531. }
  3532. #ifdef Q_OS_UNIX
  3533. void unetbootin::writegrub2cfg()
  3534. {
  3535. QFile menulst;
  3536. menulst.setFileName("/boot/grub/grub.cfg");
  3537. if (QFile::exists(QString("%1.bak").arg(menulst.fileName())))
  3538. rmFile(QString("%1.bak").arg(menulst.fileName()));
  3539. QFile::copy(menulst.fileName(), QString("%1.bak").arg(menulst.fileName()));
  3540. QFile bkmenulst(QString("%1.bak").arg(menulst.fileName()));
  3541. bkmenulst.open(QIODevice::ReadOnly | QIODevice::Text);
  3542. QTextStream bkmenulstout(&bkmenulst);
  3543. menulst.open(QIODevice::WriteOnly | QIODevice::Text);
  3544. QTextStream menulstout(&menulst);
  3545. QRegExp mlstchkistimeout("\\s{0,}set\\s{1,}timeout=\\d{1,}.{0,}", Qt::CaseInsensitive);
  3546. QStringList ecurmenulstTextL;
  3547. bool mlstmustreplacetimeout = true;
  3548. QString menulstCurLine;
  3549. while (!bkmenulstout.atEnd())
  3550. {
  3551. menulstCurLine = bkmenulstout.readLine();
  3552. if (mlstmustreplacetimeout && mlstchkistimeout.exactMatch(menulstCurLine))
  3553. {
  3554. ecurmenulstTextL.append("set timeout=15");
  3555. mlstmustreplacetimeout = false;
  3556. }
  3557. else
  3558. {
  3559. ecurmenulstTextL.append(menulstCurLine);
  3560. }
  3561. }
  3562. QString ecurmenulstText = ecurmenulstTextL.join("\n");
  3563. QString menulstxt = QString(
  3564. "%9\n\n"
  3565. #ifndef NODEFAULTBOOT
  3566. "\nmenuentry \""UNETBOOTINB"\" {\n"
  3567. "\tset root=%8\n"
  3568. "\t%1 %2 %3 %4\n"
  3569. "\t%5 %6 %7\n"
  3570. "}\n"
  3571. #endif
  3572. ).arg(kernelLine.replace("kernel", "linux")).arg(kernelParam).arg(kernelLoc).arg(kernelOpts).arg(initrdLine).arg(initrdLoc).arg(initrdOpts)
  3573. .arg(getGrub2Notation(targetDev)).arg(ecurmenulstText)
  3574. ;
  3575. if (!extraoptionsPL.first.first.isEmpty())
  3576. {
  3577. for (int i = 0; i < extraoptionsPL.first.first.size(); ++i)
  3578. {
  3579. menulstxt.append(QString("\nmenuentry \"%1\" {\n"
  3580. "\tset root=%5\n"
  3581. "\tlinux %2 %4\n"
  3582. "\tinitrd %3\n"
  3583. "}\n").arg(QString(extraoptionsPL.second.first.at(i)).remove("^")).arg(extraoptionsPL.first.first.at(i)).arg(extraoptionsPL.first.second.at(i)).arg(extraoptionsPL.second.second.at(i))
  3584. .arg(getGrubNotation(targetDev))
  3585. );
  3586. }
  3587. }
  3588. menulstout << menulstxt << endl;
  3589. menulst.close();
  3590. }
  3591. #endif
  3592. void unetbootin::runinsthdd()
  3593. {
  3594. this->tprogress->setValue(this->tprogress->maximum()/3);
  3595. #ifdef Q_OS_UNIX
  3596. if (QFile::exists("/boot/grub/grub.cfg")) // has grub2
  3597. {
  3598. pdesc1->setText(tr("Configuring grub2 on %1").arg(targetDev));
  3599. writegrub2cfg();
  3600. if (!QFile::exists("/boot/grub/menu.lst")) // grub2-only
  3601. {
  3602. QSettings install(QSettings::SystemScope, "UNetbootin");
  3603. install.setValue("Location", "/");
  3604. fininstall();
  3605. return;
  3606. }
  3607. }
  3608. #endif
  3609. #ifdef Q_OS_WIN32
  3610. pdesc1->setText(tr("Configuring grldr on %1").arg(targetDev));
  3611. if (QFile::exists(QDir::toNativeSeparators(QString("%1unetbtin.exe").arg(targetDrive))))
  3612. {
  3613. rmFile(QDir::toNativeSeparators(QString("%1unetbtin.exe").arg(targetDrive)));
  3614. }
  3615. QFile::copy(appLoc, QDir::toNativeSeparators(QString("%1unetbtin.exe").arg(targetDrive)));
  3616. QFile::setPermissions(QDir::toNativeSeparators(QString("%1unetbtin.exe").arg(targetDrive)), QFile::ReadOther|QFile::WriteOther|QFile::ExeOther);
  3617. if (QFile::exists(QDir::toNativeSeparators(QString("%1ubnldr").arg(targetDrive))))
  3618. {
  3619. overwritefileprompt(QDir::toNativeSeparators(QString("%1ubnldr").arg(targetDrive)));
  3620. }
  3621. instIndvfl("ubnldr", QString("%1ubnldr").arg(targetDrive));
  3622. if (QFile::exists(QDir::toNativeSeparators(QString("%1ubnldr.mbr").arg(targetDrive))))
  3623. {
  3624. overwritefileprompt(QDir::toNativeSeparators(QString("%1ubnldr.mbr").arg(targetDrive)));
  3625. }
  3626. instIndvfl("ubnldr.mbr", QString("%1ubnldr.mbr").arg(targetDrive));
  3627. if (QFile::exists(QDir::toNativeSeparators(QString("%1ubnldr.exe").arg(targetDrive))))
  3628. {
  3629. overwritefileprompt(QDir::toNativeSeparators(QString("%1ubnldr.exe").arg(targetDrive)));
  3630. }
  3631. instIndvfl("ubnldr.exe", QString("%1ubnldr.exe").arg(targetDrive));
  3632. #endif
  3633. QFile menulst;
  3634. #ifdef Q_OS_WIN32
  3635. menulst.setFileName(QString("%1menu.lst").arg(targetPath));
  3636. #endif
  3637. #ifdef Q_OS_UNIX
  3638. pdesc1->setText(tr("Configuring grub on %1").arg(targetDev));
  3639. menulst.setFileName("/boot/grub/menu.lst");
  3640. if (QFile::exists(QString("%1.bak").arg(menulst.fileName())))
  3641. rmFile(QString("%1.bak").arg(menulst.fileName()));
  3642. QFile::copy(menulst.fileName(), QString("%1.bak").arg(menulst.fileName()));
  3643. QFile bkmenulst(QString("%1.bak").arg(menulst.fileName()));
  3644. bkmenulst.open(QIODevice::ReadOnly | QIODevice::Text);
  3645. QTextStream bkmenulstout(&bkmenulst);
  3646. #endif
  3647. menulst.open(QIODevice::WriteOnly | QIODevice::Text);
  3648. QTextStream menulstout(&menulst);
  3649. #ifdef Q_OS_UNIX
  3650. QRegExp mlstchkistimeout("\\s{0,}timeout\\s{1,}\\d{1,}.{0,}", Qt::CaseInsensitive);
  3651. QRegExp mlstchkishiddenmenu("\\s{0,}hiddenmenu.{0,}", Qt::CaseInsensitive);
  3652. QStringList ecurmenulstTextL;
  3653. bool mlstmustreplacetimeout = true;
  3654. bool mlstmustreplacehiddenmenu = true;
  3655. QString menulstCurLine;
  3656. while (!bkmenulstout.atEnd())
  3657. {
  3658. menulstCurLine = bkmenulstout.readLine();
  3659. if (mlstmustreplacehiddenmenu && mlstchkishiddenmenu.exactMatch(menulstCurLine))
  3660. {
  3661. ecurmenulstTextL.append("#hiddenmenu");
  3662. mlstmustreplacehiddenmenu = false;
  3663. }
  3664. else if (mlstmustreplacetimeout && mlstchkistimeout.exactMatch(menulstCurLine))
  3665. {
  3666. ecurmenulstTextL.append("timeout\t\t15");
  3667. mlstmustreplacetimeout = false;
  3668. }
  3669. else
  3670. {
  3671. ecurmenulstTextL.append(menulstCurLine);
  3672. }
  3673. }
  3674. QString ecurmenulstText = ecurmenulstTextL.join("\n");
  3675. #endif
  3676. QString menulstxt = QString(
  3677. #ifdef Q_OS_UNIX
  3678. "%9\n\n"
  3679. #endif
  3680. #ifdef Q_OS_WIN32
  3681. "default 0\n"
  3682. "timeout 10\n"
  3683. #endif
  3684. #ifndef NODEFAULTBOOT
  3685. "\ntitle "UNETBOOTINB"\n"
  3686. #ifdef Q_OS_WIN32
  3687. "find --set-root %3\n"
  3688. #endif
  3689. #ifdef Q_OS_UNIX
  3690. "root %8\n"
  3691. #endif
  3692. "%1 %2 %3 %4\n"
  3693. "%5 %6 %7\n"
  3694. "boot\n"
  3695. #endif
  3696. ).arg(kernelLine).arg(kernelParam).arg(kernelLoc).arg(kernelOpts).arg(initrdLine).arg(initrdLoc).arg(initrdOpts)
  3697. #ifdef Q_OS_UNIX
  3698. .arg(getGrubNotation(targetDev)).arg(ecurmenulstText)
  3699. #endif
  3700. ;
  3701. if (!extraoptionsPL.first.first.isEmpty())
  3702. {
  3703. for (int i = 0; i < extraoptionsPL.first.first.size(); ++i)
  3704. {
  3705. menulstxt.append(QString("\ntitle %1\n"
  3706. #ifdef Q_OS_WIN32
  3707. "find --set-root %2\n"
  3708. #endif
  3709. #ifdef Q_OS_UNIX
  3710. "root %5\n"
  3711. #endif
  3712. "kernel %2 %4\n"
  3713. "initrd %3\n"
  3714. "boot\n").arg(QString(extraoptionsPL.second.first.at(i)).remove("^")).arg(extraoptionsPL.first.first.at(i)).arg(extraoptionsPL.first.second.at(i)).arg(extraoptionsPL.second.second.at(i))
  3715. #ifdef Q_OS_UNIX
  3716. .arg(getGrubNotation(targetDev))
  3717. #endif
  3718. );
  3719. }
  3720. }
  3721. menulstout << menulstxt << endl;
  3722. menulst.close();
  3723. #ifdef Q_OS_WIN32
  3724. QSettings install("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\UNetbootin", QSettings::NativeFormat);
  3725. install.setValue("Location", targetDrive);
  3726. install.setValue("DisplayName", "UNetbootin");
  3727. install.setValue("UninstallString", QDir::toNativeSeparators(QString("%1unetbtin.exe").arg(targetDrive)));
  3728. //QSettings runonce("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce", QSettings::NativeFormat);
  3729. //runonce.setValue("UNetbootin Uninstaller", QDir::toNativeSeparators(QString("%1unetbtin.exe").arg(targetDrive)));
  3730. if (QSysInfo::WindowsVersion == QSysInfo::WV_32s || QSysInfo::WindowsVersion == QSysInfo::WV_95 || QSysInfo::WindowsVersion == QSysInfo::WV_98 || QSysInfo::WindowsVersion == QSysInfo::WV_Me)
  3731. {
  3732. configsysEdit();
  3733. }
  3734. else if (QSysInfo::WindowsVersion == QSysInfo::WV_NT || QSysInfo::WindowsVersion == QSysInfo::WV_2000 || QSysInfo::WindowsVersion == QSysInfo::WV_XP || QSysInfo::WindowsVersion == QSysInfo::WV_2003 )
  3735. {
  3736. bootiniEdit();
  3737. }
  3738. else if (QSysInfo::WindowsVersion == QSysInfo::WV_VISTA) //|| QSysInfo::WindowsVersion == QSysInfo::WV_WINDOWS7) // TODO when upgrading to latest Qt
  3739. {
  3740. vistabcdEdit();
  3741. }
  3742. else
  3743. {
  3744. configsysEdit();
  3745. bootiniEdit();
  3746. vistabcdEdit();
  3747. }
  3748. #endif
  3749. #ifdef Q_OS_UNIX
  3750. QSettings install(QSettings::SystemScope, "UNetbootin");
  3751. install.setValue("Location", "/");
  3752. #endif
  3753. fininstall();
  3754. }
  3755. void unetbootin::rmFile(QFile &fn)
  3756. {
  3757. if (!fn.exists()) return;
  3758. fn.setPermissions(QFile::WriteUser);
  3759. fn.remove();
  3760. #ifdef Q_OS_UNIX
  3761. callexternapp("sync", "");
  3762. #endif
  3763. }
  3764. void unetbootin::rmFile(const QString &fn)
  3765. {
  3766. if (!QFile::exists(fn)) return;
  3767. QFile::setPermissions(fn, QFile::WriteUser);
  3768. QFile::remove(fn);
  3769. #ifdef Q_OS_UNIX
  3770. callexternapp("sync", "");
  3771. #endif
  3772. }
  3773. void unetbootin::mvFile(QFile &fn, QFile &outfn)
  3774. {
  3775. rmFile(outfn);
  3776. fn.rename(outfn.fileName());
  3777. #ifdef Q_OS_UNIX
  3778. callexternapp("sync", "");
  3779. #endif
  3780. }
  3781. void unetbootin::mvFile(const QString &fn, const QString &outfn)
  3782. {
  3783. rmFile(outfn);
  3784. QFile::rename(fn, outfn);
  3785. #ifdef Q_OS_UNIX
  3786. callexternapp("sync", "");
  3787. #endif
  3788. }
  3789. void unetbootin::replaceTextInFile(QString repfilepath, QRegExp replaceme, QString replacewith)
  3790. {
  3791. QFile repfileF(repfilepath);
  3792. randtmpfile nrepfileF(QFileInfo(repfilepath).canonicalPath(), "cfg");
  3793. QString nrepfilepath = QFileInfo(nrepfileF).canonicalFilePath();
  3794. repfileF.open(QIODevice::ReadOnly | QIODevice::Text);
  3795. nrepfileF.open(QIODevice::WriteOnly | QIODevice::Text);
  3796. QTextStream repfileTS(&repfileF);
  3797. QTextStream nrepfileTS(&nrepfileF);
  3798. while (!repfileTS.atEnd())
  3799. {
  3800. nrepfileTS << repfileTS.readLine().replace(replaceme, replacewith) << "\n";
  3801. }
  3802. repfileF.close();
  3803. rmFile(repfilepath);
  3804. nrepfileF.rename(repfilepath);
  3805. nrepfileF.close();
  3806. //mvFile(nrepfilepath, repfilepath);
  3807. }
  3808. void unetbootin::setLabel(QString devname, QString newlabel)
  3809. {
  3810. #ifdef Q_OS_LINUX
  3811. if (isext2)
  3812. {
  3813. callexternapp(e2labelcommand, devname+" "+newlabel);
  3814. }
  3815. else
  3816. {
  3817. callexternapp(mlabelcommand, "-i "+devname+" ::"+newlabel);
  3818. }
  3819. #endif
  3820. #ifdef Q_OS_MAC
  3821. callexternapp("diskutil", "rename "+devname+" "+newlabel);
  3822. #endif
  3823. #ifdef Q_OS_WIN32
  3824. callexternapp("label", devname+" "+newlabel);
  3825. #endif
  3826. this->devlabel = QString(newlabel);
  3827. if (this->devluid.startsWith("LABEL="))
  3828. this->devluid = "LABEL="+newlabel;
  3829. #ifdef Q_OS_MAC
  3830. this->targetPath = this->locatemountpoint(devname) + "/";
  3831. this->targetDrive = this->targetPath;
  3832. #endif
  3833. }
  3834. QString unetbootin::fixkernelbootoptions(const QString &cfgfileCL)
  3835. {
  3836. if (cfgfileCL.contains("archisolabel=") && (this->devlabel == "" || this->devlabel == "None"))
  3837. {
  3838. this->devlabel = this->getlabel(this->targetDev);
  3839. if (this->installType == tr("USB Drive") && (this->devlabel == "" || this->devlabel == "None"))
  3840. {
  3841. QString isolabelopt = QString(cfgfileCL).trimmed();
  3842. int startIdx = isolabelopt.indexOf("archisolabel=");
  3843. if (startIdx >= 0)
  3844. {
  3845. isolabelopt = isolabelopt.right(isolabelopt.size() - startIdx - QString("archisolabel=").size()).trimmed();
  3846. int endIdx = isolabelopt.indexOf(" ");
  3847. if (endIdx > 0)
  3848. {
  3849. isolabelopt = isolabelopt.left(endIdx);
  3850. setLabel(this->targetDev, isolabelopt);
  3851. }
  3852. }
  3853. }
  3854. }
  3855. if ((this->devlabel == "" || this->devlabel == "None") && devluid.contains("LABEL") && (cfgfileCL.contains(QRegExp("root=\\S{0,}LABEL=\\S{0,}")) || cfgfileCL.contains(QRegExp("root=\\S{0,}CDLABEL=\\S{0,}"))))
  3856. {
  3857. setLabel(this->targetDev, "LIVE");
  3858. }
  3859. QString ncfgfileCL = cfgfileCL;
  3860. if (ncfgfileCL.contains("root=live:CDLABEL"))
  3861. {
  3862. ncfgfileCL = QString(ncfgfileCL)
  3863. .replace(QRegExp("root=\\S{0,}LABEL=\\S{0,}"), QString("root=live:%1").arg(devluid))
  3864. .replace(QRegExp("root=\\S{0,}CDLABEL=\\S{0,}"), QString("root=live:%1").arg(devluid));
  3865. }
  3866. else
  3867. {
  3868. ncfgfileCL = QString(ncfgfileCL)
  3869. .replace(QRegExp("root=\\S{0,}LABEL=\\S{0,}"), QString("root=%1").arg(devluid))
  3870. .replace(QRegExp("root=\\S{0,}CDLABEL=\\S{0,}"), QString("root=%1").arg(devluid));
  3871. }
  3872. return QString(ncfgfileCL)
  3873. .replace("rootfstype=iso9660", "rootfstype=auto")
  3874. .replace("theme:sabayon", "theme:sabayon cdroot_type=vfat")
  3875. .replace("pmedia=cd", "pmedia=usbflash")
  3876. .replace(QRegExp("archisolabel=\\S{0,}"), QString("archisolabel=%1").arg(devlabel))
  3877. .trimmed();
  3878. }
  3879. /*void unetbootin::logText(const QString &text)
  3880. {
  3881. return;
  3882. if (targetPath.isNull() || targetPath.isEmpty())
  3883. {
  3884. loggedLinesNotYetWritten.append(text);
  3885. return;
  3886. }
  3887. if (logStream == 0)
  3888. {
  3889. logFile = new QFile(QString("%1unetbootin-log.txt").arg(targetPath));
  3890. logFile->open(QIODevice::WriteOnly | QIODevice::Text);
  3891. logStream = new QTextStream(logFile);
  3892. for (int i = 0; i < loggedLinesNotYetWritten.size(); ++i)
  3893. {
  3894. *logStream << loggedLinesNotYetWritten.at(i) << endl;
  3895. }
  3896. loggedLinesNotYetWritten.clear();
  3897. }
  3898. *logStream << text << endl;
  3899. }
  3900. */
  3901. void unetbootin::finishLogging()
  3902. {
  3903. if (logFile != 0)
  3904. {
  3905. logFile->close();
  3906. }
  3907. }
  3908. void unetbootin::writeTextToFile(const QString &text, const QString &filePath)
  3909. {
  3910. QFile syslinuxcfg(filePath);
  3911. if (syslinuxcfg.exists())
  3912. {
  3913. rmFile(syslinuxcfg);
  3914. }
  3915. syslinuxcfg.open(QIODevice::WriteOnly | QIODevice::Text);
  3916. QTextStream syslinuxcfgout(&syslinuxcfg);
  3917. syslinuxcfgout << text << endl;
  3918. syslinuxcfg.close();
  3919. }
  3920. void unetbootin::runinstusb()
  3921. {
  3922. this->tprogress->setValue(this->tprogress->maximum()/3);
  3923. pdesc1->setText(tr("Installing syslinux to %1").arg(targetDev));
  3924. #ifdef Q_OS_WIN32
  3925. QString sysltfloc = instTempfl("syslinux.exe", "exe");
  3926. callexternapp(sysltfloc, QString("-ma %1").arg(targetDev));
  3927. rmFile(sysltfloc);
  3928. #endif
  3929. #ifdef STATICLINUX
  3930. if (QFile::exists(syslinuxcommand))
  3931. rmFile(syslinuxcommand);
  3932. instIndvfl("ubnsylnx", syslinuxcommand);
  3933. QFile::setPermissions(syslinuxcommand, QFile::ReadOwner|QFile::ExeOwner|QFile::ReadGroup|QFile::ExeGroup|QFile::ReadOther|QFile::ExeOther|QFile::WriteOwner);
  3934. // chmod(syslinuxcommand, S_IRUSR|S_IRGRP|S_IROTH|S_IRWXU);
  3935. if (QFile::exists(extlinuxcommand))
  3936. rmFile(extlinuxcommand);
  3937. instIndvfl("ubnexlnx", extlinuxcommand);
  3938. QFile::setPermissions(extlinuxcommand, QFile::ReadOwner|QFile::ExeOwner|QFile::ReadGroup|QFile::ExeGroup|QFile::ReadOther|QFile::ExeOther|QFile::WriteOwner);
  3939. #endif
  3940. #ifdef Q_OS_LINUX
  3941. isext2 = false;
  3942. if (!volidcommand.isEmpty())
  3943. {
  3944. if (callexternapp(volidcommand, QString("-t %2").arg(targetDev)).contains(QRegExp("(ext2|ext3|ext4)")))
  3945. isext2 = true;
  3946. }
  3947. else
  3948. {
  3949. QString tstrblk = callexternapp(blkidcommand, QString("-s TYPE %2").arg(targetDev));
  3950. if (tstrblk.contains('='))
  3951. {
  3952. if (tstrblk.contains(QRegExp("(ext2|ext3|ext4)")))
  3953. isext2 = true;
  3954. }
  3955. }
  3956. if (isext2)
  3957. {
  3958. pdesc1->setText(tr("Installing extlinux to %1").arg(targetDev));
  3959. callexternapp(extlinuxcommand, QString("-i \"%1\"").arg(targetPath));
  3960. }
  3961. else
  3962. callexternapp(syslinuxcommand, targetDev);
  3963. if (rawtargetDev != targetDev)
  3964. {
  3965. // make active
  3966. if (sfdiskcommand != "") {
  3967. // use sfdisk if available
  3968. callexternapp(sfdiskcommand, QString("%1 -A%2").arg(rawtargetDev, QString(targetDev).remove(rawtargetDev).remove("p")));
  3969. } else {
  3970. // use fdisk if sfdisk is unavailable
  3971. bool isOk = false;
  3972. int partitionNumber = QString(targetDev).remove(rawtargetDev).remove("p").toInt(&isOk, 10);
  3973. if (isOk)
  3974. {
  3975. QString output = callexternapp("fdisk", "-l");
  3976. QStringList outputL = output.split('\n');
  3977. outputL = outputL.filter(targetDev);
  3978. if (outputL.size() > 0)
  3979. {
  3980. outputL = outputL.filter("*");
  3981. bool isActive = outputL.size() > 0;
  3982. if (!isActive)
  3983. {
  3984. QString fdiskWriteToStdin = "a\n";
  3985. fdiskWriteToStdin += (QString::number(partitionNumber) + "\n");
  3986. fdiskWriteToStdin += "w\n";
  3987. callexternappWriteToStdin("fdisk", rawtargetDev, fdiskWriteToStdin);
  3988. }
  3989. }
  3990. }
  3991. }
  3992. QFile usbmbrF(rawtargetDev);
  3993. QFile mbrbinF(":/mbr.bin");
  3994. #ifdef NOSTATIC
  3995. mbrbinF.setFileName(QFile::exists("/usr/share/syslinux/mbr.bin") ? "/usr/share/syslinux/mbr.bin" : "/usr/lib/syslinux/mbr.bin");
  3996. #endif
  3997. usbmbrF.open(QIODevice::WriteOnly);
  3998. mbrbinF.open(QIODevice::ReadOnly);
  3999. usbmbrF.write(mbrbinF.readAll());
  4000. mbrbinF.close();
  4001. usbmbrF.close();
  4002. }
  4003. #endif
  4004. #ifdef Q_OS_MAC
  4005. callexternapp("sync", "");
  4006. callexternapp("diskutil", "umount "+targetDev);
  4007. callexternapp("sync", "");
  4008. callexternapp("hdiutil", "unmount "+targetDev);
  4009. callexternapp("sync", "");
  4010. callexternapp(resourceDir.absoluteFilePath("mkbootable"), targetDev);
  4011. /*
  4012. callexternapp("sync", "");
  4013. callexternapp("diskutil", "umount "+targetDev);
  4014. callexternapp("sync", "");
  4015. callexternapp("hdiutil", "unmount "+targetDev);
  4016. callexternapp("sync", "");
  4017. QFile usbmbrF(rawtargetDev);
  4018. QFile mbrbinF(resourceDir.absoluteFilePath("mbr.bin"));
  4019. usbmbrF.open(QIODevice::WriteOnly);
  4020. mbrbinF.open(QIODevice::ReadOnly);
  4021. usbmbrF.write(mbrbinF.readAll());
  4022. mbrbinF.close();
  4023. usbmbrF.close();
  4024. */
  4025. callexternapp("sync", "");
  4026. callexternapp("diskutil", "mount "+targetDev);
  4027. callexternapp("sync", "");
  4028. #endif
  4029. #ifndef XPUD
  4030. if (!dontgeneratesyslinuxcfg)
  4031. {
  4032. QString syslinuxcfgtxt = QString("default menu.c32\n"
  4033. "prompt 0\n"
  4034. "menu title UNetbootin\n"
  4035. "timeout 100\n\n"
  4036. #ifndef NODEFAULTBOOT
  4037. "label unetbootindefault\n"
  4038. "menu label Default\n"
  4039. "kernel %1\n"
  4040. "append %4%2 %3\n"
  4041. #endif
  4042. ).arg(kernelLoc, initrdLoc, kernelOpts, slinitrdLine);
  4043. if (!extraoptionsPL.first.first.isEmpty())
  4044. {
  4045. for (int i = 0; i < extraoptionsPL.first.first.size(); ++i)
  4046. {
  4047. syslinuxcfgtxt.append(QString("\nlabel %5\n"
  4048. "menu label %1\n"
  4049. "kernel %2\n"
  4050. "append %6%3 %4\n").arg(extraoptionsPL.second.first.at(i)).arg(extraoptionsPL.first.first.at(i)).arg(extraoptionsPL.first.second.at(i)).arg(extraoptionsPL.second.second.at(i)).arg(QString("ubnentry%1").arg(i)).arg(slinitrdLine));
  4051. }
  4052. }
  4053. writeTextToFile(syslinuxcfgtxt, QString("%1syslinux.cfg").arg(targetPath));
  4054. }
  4055. else
  4056. {
  4057. for (int j = 0; j < locatedsyslinuxcfgfiles.size(); ++j)
  4058. {
  4059. QString syslpathloc = QFileInfo(locatedsyslinuxcfgfiles.at(j)).path();
  4060. if (syslpathloc == ".") syslpathloc = "";
  4061. if (syslpathloc.contains(QDir::toNativeSeparators("/")))
  4062. {
  4063. if (!syslpathloc.endsWith(QDir::toNativeSeparators("/")))
  4064. syslpathloc.append(QDir::toNativeSeparators("/"));
  4065. }
  4066. else
  4067. {
  4068. if (!syslpathloc.endsWith("/"))
  4069. syslpathloc.append("/");
  4070. }
  4071. QString abssyslpathloc = QDir::fromNativeSeparators(QString(syslpathloc));
  4072. if (!abssyslpathloc.startsWith("/"))
  4073. abssyslpathloc.prepend("/");
  4074. instIndvfl("menu.c32", QString("%1%2menu.c32").arg(targetPath).arg(syslpathloc));
  4075. instIndvfl("libutil.c32", QString("%1%2libutil.c32").arg(targetPath).arg(syslpathloc));
  4076. instIndvfl("libcom32.c32", QString("%1%2libcom32.c32").arg(targetPath).arg(syslpathloc));
  4077. QString syslrealcfgloc = QString(locatedsyslinuxcfgfiles.at(j)).replace("isolinux.cfg", "syslinux.cfg").replace("extlinux.conf", "syslinux.cfg");
  4078. if (syslrealcfgloc != locatedsyslinuxcfgfiles.at(j))
  4079. {
  4080. QFile::copy(QString("%1%2").arg(targetPath).arg(locatedsyslinuxcfgfiles.at(j)), QString("%1%2").arg(targetPath).arg(syslrealcfgloc));
  4081. }
  4082. replaceTextInFile(QString("%1%2").arg(targetPath).arg(syslrealcfgloc), QRegExp("\\S{0,}vesamenu.c32"), QString("%1menu.c32").arg(abssyslpathloc));
  4083. #ifdef Q_OS_UNIX
  4084. if (isext2)
  4085. {
  4086. QFile::copy(QString("%1%2").arg(targetPath).arg(locatedsyslinuxcfgfiles.at(j)), QString("%1%2extlinux.conf").arg(targetPath).arg(syslpathloc));
  4087. QString extlpathloc = QString(syslpathloc).replace("syslinux", "extlinux");
  4088. if (syslpathloc != extlpathloc)
  4089. callexternapp("ln", QString("-s %1 %2").arg(syslpathloc).arg(extlpathloc));
  4090. }
  4091. #endif
  4092. }
  4093. }
  4094. #endif
  4095. #ifdef Q_OS_UNIX
  4096. if (!dontgeneratesyslinuxcfg && isext2)
  4097. QFile::copy(QString("%1syslinux.cfg").arg(targetPath), QString("%1extlinux.conf").arg(targetPath));
  4098. #endif
  4099. if (!dontgeneratesyslinuxcfg)
  4100. {
  4101. instIndvfl("menu.c32", QString("%1menu.c32").arg(targetPath));
  4102. instIndvfl("libutil.c32", QString("%1libutil.c32").arg(targetPath));
  4103. instIndvfl("libcom32.c32", QString("%1libcom32.c32").arg(targetPath));
  4104. }
  4105. fininstall();
  4106. }
  4107. void unetbootin::killApplication()
  4108. {
  4109. exit(0);
  4110. }
  4111. void unetbootin::fininstall()
  4112. {
  4113. #ifdef Q_OS_UNIX
  4114. this->tprogress->setValue(this->tprogress->maximum()*2/3);
  4115. pdesc1->setText(tr("Syncing filesystems"));
  4116. callexternapp("sync", "");
  4117. #endif
  4118. if (this->persistenceSpaceMB > 0)
  4119. {
  4120. pdesc1->setText(tr("Setting up persistence"));
  4121. this->tprogress->setMaximum(persistenceSpaceMB);
  4122. this->tprogress->setValue(0);
  4123. QString persfile = "casper-rw";
  4124. if (issalt && !saltRootDir.isEmpty()) {
  4125. QStringList persistencedir;
  4126. persistencedir.append("persistence");
  4127. makepathtree(QString("%1%2").arg(targetPath).arg(saltRootDir), persistencedir);
  4128. persfile = QString("%1/persistence/%1.save").arg(saltRootDir);
  4129. }
  4130. #ifdef Q_OS_WIN32
  4131. QString mke2fscommand = instTempfl("mke2fs.exe", "exe");
  4132. #endif
  4133. if (QFile::exists(QString("%1%2").arg(targetPath).arg(persfile)))
  4134. {
  4135. rmFile(QString("%1%2").arg(targetPath).arg(persfile));
  4136. }
  4137. QFile persistenceFile(QString("%1%2").arg(targetPath).arg(persfile));
  4138. persistenceFile.open(QFile::WriteOnly);
  4139. int bytesWritten = 1048576;
  4140. char writeEmpty[1048576];
  4141. memset(writeEmpty, 0, 1048576);
  4142. for (int i = 0; i < persistenceSpaceMB && bytesWritten == 1048576; ++i)
  4143. {
  4144. this->tprogress->setValue(i);
  4145. bytesWritten = persistenceFile.write(writeEmpty, 1048576);
  4146. }
  4147. this->tprogress->setValue(this->tprogress->maximum());
  4148. #ifdef Q_OS_UNIX
  4149. callexternapp(mke2fscommand, QString("-F \"%1%2\"").arg(targetPath).arg(persfile));
  4150. #endif
  4151. #ifdef Q_OS_WIN32
  4152. callexternappWriteToStdin(mke2fscommand, QString("\"%1%2\"").arg(targetPath).arg(persfile), "\n");
  4153. rmFile(mke2fscommand);
  4154. #endif
  4155. }
  4156. pdesc1->setText("");
  4157. progresslayer->setEnabled(false);
  4158. progresslayer->hide();
  4159. rebootlayer->setEnabled(true);
  4160. rebootlayer->show();
  4161. sdesc3->setText(QString(sdesc3->text()).remove("<b>").replace(trcurrent+"</b>", trdone));
  4162. sdesc4->setText(QString("<b>%1 %2</b>").arg(sdesc4->text()).arg(trcurrent));
  4163. if (installType == tr("Hard Disk"))
  4164. {
  4165. rebootmsgtext->setText(tr("After rebooting, select the "UNETBOOTINB" menu entry to boot.%1\nReboot now?").arg(postinstmsg));
  4166. }
  4167. if (installType == tr("USB Drive"))
  4168. {
  4169. #ifndef Q_OS_MAC
  4170. rebootmsgtext->setText(tr("After rebooting, select the USB boot option in the BIOS boot menu.%1\nReboot now?").arg(postinstmsg));
  4171. #endif
  4172. #ifdef Q_OS_MAC
  4173. rebootmsgtext->setText(tr("The created USB device will not boot off a Mac. Insert it into a PC, and select the USB boot option in the BIOS boot menu.%1").arg(postinstmsg));
  4174. this->frebootbutton->setEnabled(false);
  4175. this->frebootbutton->hide();
  4176. #endif
  4177. }
  4178. finishLogging();
  4179. if (exitOnCompletion)
  4180. {
  4181. printf("exitstatus:success\n");
  4182. QApplication::exit();
  4183. exit(0);
  4184. }
  4185. }