<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>Vidalia: UpdateProcess.cpp Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.6.3 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="dirs.html"><span>Directories</span></a></li> </ul> </div> <div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <div class="navpath"><a class="el" href="dir_b47abd1aad201a152869566145babb61.html">src</a> » <a class="el" href="dir_695ba8f8357372e02d38c40b3c6dbe81.html">vidalia</a> </div> </div> <div class="contents"> <h1>UpdateProcess.cpp</h1><a href="_update_process_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> <a name="l00002"></a>00002 <span class="comment">** This file is part of Vidalia, and is subject to the license terms in the</span> <a name="l00003"></a>00003 <span class="comment">** LICENSE file, found in the top level directory of this distribution. If you</span> <a name="l00004"></a>00004 <span class="comment">** did not receive the LICENSE file with this file, you may obtain it from the</span> <a name="l00005"></a>00005 <span class="comment">** Vidalia source package distributed by the Vidalia Project at</span> <a name="l00006"></a>00006 <span class="comment">** http://www.vidalia-project.net/. No part of Vidalia, including this file,</span> <a name="l00007"></a>00007 <span class="comment">** may be copied, modified, propagated, or distributed except according to the</span> <a name="l00008"></a>00008 <span class="comment">** terms described in the LICENSE file.</span> <a name="l00009"></a>00009 <span class="comment">*/</span> <a name="l00010"></a>00010 <a name="l00011"></a>00011 <span class="preprocessor">#include "<a class="code" href="_update_process_8h.html">UpdateProcess.h</a>"</span> <a name="l00012"></a>00012 <span class="preprocessor">#include "<a class="code" href="_vidalia_8h.html">Vidalia.h</a>"</span> <a name="l00013"></a>00013 <a name="l00014"></a>00014 <span class="preprocessor">#include "<a class="code" href="stringutil_8h.html">stringutil.h</a>"</span> <a name="l00015"></a>00015 <a name="l00016"></a>00016 <span class="preprocessor">#include <QDir></span> <a name="l00017"></a>00017 <span class="preprocessor">#include <QDomDocument></span> <a name="l00018"></a>00018 <span class="preprocessor">#include <QDomElement></span> <a name="l00019"></a>00019 <span class="preprocessor">#include <QDomNodeList></span> <a name="l00020"></a>00020 <a name="l00021"></a>00021 <a name="l00022"></a><a class="code" href="class_update_process.html#a1fc9d03ee0a4e7d8824b41d3ccf5a50a">00022</a> <a class="code" href="class_update_process.html#a1fc9d03ee0a4e7d8824b41d3ccf5a50a">UpdateProcess::UpdateProcess</a>(QObject *parent) <a name="l00023"></a>00023 : QProcess(parent) <a name="l00024"></a>00024 { <a name="l00025"></a>00025 <a class="code" href="class_update_process.html#a5af899e34cb30d7968559c360b872812">_currentCommand</a> = <a class="code" href="class_update_process.html#ac5239113ac6cd658d43e7f85ae941892a8ba38d0257ecabf0e9c21728b27ed9cd">NoCommand</a>; <a name="l00026"></a>00026 <a class="code" href="class_update_process.html#a4b3773b05113c02ecfb1de2f3d116421">_socksPort</a> = 0; <a name="l00027"></a>00027 <a name="l00028"></a>00028 connect(<span class="keyword">this</span>, SIGNAL(readyReadStandardError()), <a name="l00029"></a>00029 <span class="keyword">this</span>, SLOT(<a class="code" href="class_update_process.html#a9ef904f0434b701cf8d1c8ac68473194">readStandardError</a>())); <a name="l00030"></a>00030 connect(<span class="keyword">this</span>, SIGNAL(readyReadStandardOutput()), <a name="l00031"></a>00031 <span class="keyword">this</span>, SLOT(<a class="code" href="class_update_process.html#abb9ea44d23dc24a2d4b74d229aec3405">readStandardOutput</a>())); <a name="l00032"></a>00032 connect(<span class="keyword">this</span>, SIGNAL(finished(<span class="keywordtype">int</span>, QProcess::ExitStatus)), <a name="l00033"></a>00033 <span class="keyword">this</span>, SLOT(<a class="code" href="class_update_process.html#a6ade5ac73e733c8feb2a621f8e2fba0e">onFinished</a>(<span class="keywordtype">int</span>, QProcess::ExitStatus))); <a name="l00034"></a>00034 <a name="l00035"></a>00035 setEnvironment(systemEnvironment()); <a name="l00036"></a>00036 } <a name="l00037"></a>00037 <a name="l00038"></a>00038 <span class="keywordtype">void</span> <a name="l00039"></a><a class="code" href="class_update_process.html#a54e487ec966b73a18d503a01beb39b5b">00039</a> <a class="code" href="class_update_process.html#a54e487ec966b73a18d503a01beb39b5b">UpdateProcess::checkForUpdates</a>(<a class="code" href="class_update_process.html#a7f96e69b1f212525d935655e9c00505a">BundleInfo</a> bi) <a name="l00040"></a>00040 { <a name="l00041"></a>00041 QStringList args; <a name="l00042"></a>00042 <a name="l00043"></a>00043 args << <span class="stringliteral">"update"</span> << <span class="stringliteral">"--force-check"</span> <a name="l00044"></a>00044 << <span class="stringliteral">" --controller-log-format"</span> <a name="l00045"></a>00045 << <span class="stringliteral">"--repo="</span> + <a class="code" href="class_update_process.html#abedc59438d71f84d07f8ae1558a2145f">updateRepositoryDir</a>() <a name="l00046"></a>00046 << <span class="stringliteral">"--debug"</span>; <a name="l00047"></a>00047 <span class="keywordflow">if</span> (<a class="code" href="class_update_process.html#a4b3773b05113c02ecfb1de2f3d116421">_socksPort</a>) <a name="l00048"></a>00048 args << <span class="stringliteral">"--socks-port="</span> + QString::number(<a class="code" href="class_update_process.html#a4b3773b05113c02ecfb1de2f3d116421">_socksPort</a>); <a name="l00049"></a>00049 <a name="l00050"></a>00050 args << <a class="code" href="class_update_process.html#aa4faf0b0513bca7ae5b0a10d4c077df1">bundleInfoToString</a>(bi); <a name="l00051"></a>00051 <a name="l00052"></a>00052 <a class="code" href="_vidalia_8h.html#a61e4319b31bbbc7eb1a5724b487be75f">vNotice</a>(<span class="stringliteral">"updater: launching auto-update executable: %1 %2"</span>) <a name="l00053"></a>00053 .arg(<a class="code" href="class_update_process.html#a5d6ecf49da3e0d37e99ac5794d78c145">updateExecutable</a>()) <a name="l00054"></a>00054 .arg(args.join(<span class="stringliteral">" "</span>)); <a name="l00055"></a>00055 <a class="code" href="class_update_process.html#a02082dfdfd6d195d3b60d58a9851414b">_currentBundle</a> = bi; <a name="l00056"></a>00056 <a class="code" href="class_update_process.html#a5af899e34cb30d7968559c360b872812">_currentCommand</a> = <a class="code" href="class_update_process.html#ac5239113ac6cd658d43e7f85ae941892aa14277377dbaab311cdd2bf895c07307">CheckForUpdates</a>; <a name="l00057"></a>00057 start(<a class="code" href="class_update_process.html#a5d6ecf49da3e0d37e99ac5794d78c145">updateExecutable</a>(), args); <a name="l00058"></a>00058 } <a name="l00059"></a>00059 <a name="l00060"></a>00060 <span class="keywordtype">void</span> <a name="l00061"></a><a class="code" href="class_update_process.html#a7f5215ea87f91e23d08d99e5af43b25f">00061</a> <a class="code" href="class_update_process.html#a7f5215ea87f91e23d08d99e5af43b25f">UpdateProcess::installUpdates</a>(<a class="code" href="class_update_process.html#a7f96e69b1f212525d935655e9c00505a">BundleInfo</a> bi) <a name="l00062"></a>00062 { <a name="l00063"></a>00063 QStringList args; <a name="l00064"></a>00064 <a name="l00065"></a>00065 args << <span class="stringliteral">"update"</span> << <span class="stringliteral">"--controller-log-format"</span> <a name="l00066"></a>00066 << <span class="stringliteral">"--repo="</span> + <a class="code" href="class_update_process.html#abedc59438d71f84d07f8ae1558a2145f">updateRepositoryDir</a>() <a name="l00067"></a>00067 << <span class="stringliteral">"--install"</span>; <a name="l00068"></a>00068 <span class="keywordflow">if</span> (<a class="code" href="class_update_process.html#a4b3773b05113c02ecfb1de2f3d116421">_socksPort</a>) <a name="l00069"></a>00069 args << <span class="stringliteral">"--socks-port="</span> + QString::number(<a class="code" href="class_update_process.html#a4b3773b05113c02ecfb1de2f3d116421">_socksPort</a>); <a name="l00070"></a>00070 <a name="l00071"></a>00071 args << <a class="code" href="class_update_process.html#aa4faf0b0513bca7ae5b0a10d4c077df1">bundleInfoToString</a>(bi); <a name="l00072"></a>00072 <a name="l00073"></a>00073 <a class="code" href="_vidalia_8h.html#a61e4319b31bbbc7eb1a5724b487be75f">vNotice</a>(<span class="stringliteral">"updater: launching auto-update executable: %1 %2"</span>) <a name="l00074"></a>00074 .arg(<a class="code" href="class_update_process.html#a5d6ecf49da3e0d37e99ac5794d78c145">updateExecutable</a>()) <a name="l00075"></a>00075 .arg(args.join(<span class="stringliteral">" "</span>)); <a name="l00076"></a>00076 <a class="code" href="class_update_process.html#a02082dfdfd6d195d3b60d58a9851414b">_currentBundle</a> = bi; <a name="l00077"></a>00077 <a class="code" href="class_update_process.html#a5af899e34cb30d7968559c360b872812">_currentCommand</a> = <a class="code" href="class_update_process.html#ac5239113ac6cd658d43e7f85ae941892a359c42bed4c86ef4763c9a08ebfc95f6">InstallUpdates</a>; <a name="l00078"></a>00078 start(<a class="code" href="class_update_process.html#a5d6ecf49da3e0d37e99ac5794d78c145">updateExecutable</a>(), args); <a name="l00079"></a>00079 } <a name="l00080"></a>00080 <a name="l00081"></a>00081 <span class="keywordtype">void</span> <a name="l00082"></a><a class="code" href="class_update_process.html#a5cafa5631df3a12997dde3b67c89b620">00082</a> <a class="code" href="class_update_process.html#a5cafa5631df3a12997dde3b67c89b620">UpdateProcess::setSocksPort</a>(quint16 port) <a name="l00083"></a>00083 { <a name="l00084"></a>00084 <a class="code" href="class_update_process.html#a4b3773b05113c02ecfb1de2f3d116421">_socksPort</a> = port; <a name="l00085"></a>00085 } <a name="l00086"></a>00086 <a name="l00087"></a>00087 <span class="keywordtype">bool</span> <a name="l00088"></a><a class="code" href="class_update_process.html#aa4653e307cc553334fdba8bb98e8e46a">00088</a> <a class="code" href="class_update_process.html#aa4653e307cc553334fdba8bb98e8e46a">UpdateProcess::isRunning</a>()<span class="keyword"> const</span> <a name="l00089"></a>00089 <span class="keyword"></span>{ <a name="l00090"></a>00090 <span class="keywordflow">return</span> (state() != QProcess::NotRunning); <a name="l00091"></a>00091 } <a name="l00092"></a>00092 <a name="l00093"></a>00093 <span class="keywordtype">void</span> <a name="l00094"></a><a class="code" href="class_update_process.html#ab95cffe3f9fcb73e648f17304fa6b15c">00094</a> <a class="code" href="class_update_process.html#ab95cffe3f9fcb73e648f17304fa6b15c">UpdateProcess::cancel</a>() <a name="l00095"></a>00095 { <a name="l00096"></a>00096 <span class="keywordflow">if</span> (<a class="code" href="class_update_process.html#a5af899e34cb30d7968559c360b872812">_currentCommand</a> == <a class="code" href="class_update_process.html#ac5239113ac6cd658d43e7f85ae941892aa14277377dbaab311cdd2bf895c07307">CheckForUpdates</a>) { <a name="l00097"></a>00097 <span class="preprocessor">#if defined(Q_OS_WIN32)</span> <a name="l00098"></a>00098 <span class="preprocessor"></span> kill(); <a name="l00099"></a>00099 <span class="preprocessor">#else</span> <a name="l00100"></a>00100 <span class="preprocessor"></span> terminate(); <a name="l00101"></a>00101 <span class="preprocessor">#endif</span> <a name="l00102"></a>00102 <span class="preprocessor"></span> } <a name="l00103"></a>00103 } <a name="l00104"></a>00104 <a name="l00105"></a>00105 <span class="keywordtype">void</span> <a name="l00106"></a><a class="code" href="class_update_process.html#a9ef904f0434b701cf8d1c8ac68473194">00106</a> <a class="code" href="class_update_process.html#a9ef904f0434b701cf8d1c8ac68473194">UpdateProcess::readStandardError</a>() <a name="l00107"></a>00107 { <a name="l00108"></a>00108 <span class="keywordtype">int</span> idx; <a name="l00109"></a>00109 <span class="keywordtype">bool</span> ok; <a name="l00110"></a>00110 QString line, type; <a name="l00111"></a>00111 QHash<QString,QString> args; <a name="l00112"></a>00112 <a name="l00113"></a>00113 setReadChannel(QProcess::StandardError); <a name="l00114"></a>00114 <span class="keywordflow">while</span> (canReadLine()) { <a name="l00115"></a>00115 line = readLine().trimmed(); <a name="l00116"></a>00116 <a class="code" href="_vidalia_8h.html#a7743cb328f470aa8f382716fbcf61daa">vInfo</a>(<span class="stringliteral">"updater (stderr): %1"</span>).arg(line); <a name="l00117"></a>00117 <a name="l00118"></a>00118 idx = line.indexOf(<span class="stringliteral">" "</span>); <a name="l00119"></a>00119 <span class="keywordflow">if</span> (idx < 0 || idx == line.length()-1) <a name="l00120"></a>00120 <span class="keywordflow">continue</span>; <a name="l00121"></a>00121 type = line.mid(0, idx); <a name="l00122"></a>00122 line = line.mid(idx + 1); <a name="l00123"></a>00123 <a name="l00124"></a>00124 args = <a class="code" href="stringutil_8cpp.html#a2be53af228dd65232621f02a47bd8488">string_parse_keyvals</a>(line, &ok); <a name="l00125"></a>00125 <span class="keywordflow">if</span> (! ok) <a name="l00126"></a>00126 <span class="keywordflow">continue</span>; <a name="l00127"></a>00127 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (line.startsWith(<span class="stringliteral">"thandy.InstallFailed: "</span>, Qt::CaseInsensitive)) {<span class="comment"></span> <a name="l00128"></a>00128 <span class="comment"> /** XXX: This is a fucking kludge. If installation fails, Thandy just</span> <a name="l00129"></a>00129 <span class="comment"> * dumps a Python traceback that (for obvious reasons) doesn't</span> <a name="l00130"></a>00130 <span class="comment"> * follow the expected format. There isn't a defined control</span> <a name="l00131"></a>00131 <span class="comment"> * message type for this yet we'd really like the error, so treat</span> <a name="l00132"></a>00132 <span class="comment"> * this one specially.</span> <a name="l00133"></a>00133 <span class="comment"> */</span> <a name="l00134"></a>00134 emit <a class="code" href="class_update_process.html#a5c44f3f6eb1ec1253d11dad1e94f2b23">installUpdatesFailed</a>(line); <a name="l00135"></a>00135 <span class="keywordflow">continue</span>; <a name="l00136"></a>00136 } <a name="l00137"></a>00137 <a name="l00138"></a>00138 <span class="keywordflow">if</span> (! type.compare(<span class="stringliteral">"CAN_INSTALL"</span>, Qt::CaseInsensitive)) { <a name="l00139"></a>00139 QString <span class="keyword">package </span>= args.value("PKG"); <a name="l00140"></a>00140 <span class="keywordflow">if</span> (! package.isEmpty()) { <a name="l00141"></a>00141 <a class="code" href="class_package_info.html">PackageInfo</a> pkgInfo = <a class="code" href="class_update_process.html#a8304b8d0832f18048a138ff4ee9676f1">packageInfo</a>(package); <a name="l00142"></a>00142 <span class="keywordflow">if</span> (pkgInfo.<a class="code" href="class_package_info.html#ac2d03db9c4e5d75ec9290187fd3b6a14">isValid</a>()) <a name="l00143"></a>00143 <a class="code" href="class_update_process.html#aeb464d61d31ea758449d6aa81f915031">_packageList</a> << pkgInfo; <a name="l00144"></a>00144 } <a name="l00145"></a>00145 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="class_update_process.html#a5af899e34cb30d7968559c360b872812">_currentCommand</a> == <a class="code" href="class_update_process.html#ac5239113ac6cd658d43e7f85ae941892aa14277377dbaab311cdd2bf895c07307">CheckForUpdates</a> <a name="l00146"></a>00146 && ! type.compare(<span class="stringliteral">"DEBUG"</span>) <a name="l00147"></a>00147 && args.value(<span class="stringliteral">"msg"</span>).startsWith(<span class="stringliteral">"Got "</span>)) { <a name="l00148"></a>00148 <span class="comment">/* XXX: This is an even worse fucking kludge. Thandy only reports</span> <a name="l00149"></a>00149 <span class="comment"> * download progress in a not-so-parser-friendly log message,</span> <a name="l00150"></a>00150 <span class="comment"> * though, so we must kludge again.</span> <a name="l00151"></a>00151 <span class="comment"> *</span> <a name="l00152"></a>00152 <span class="comment"> * Here's an example of what we're parsing:</span> <a name="l00153"></a>00153 <span class="comment"> * "Got 1666048/1666560 bytes from http://updates.torproject.org/thandy/data/win32/tor-0.2.1.9-alpha.msi"</span> <a name="l00154"></a>00154 <span class="comment"> *</span> <a name="l00155"></a>00155 <span class="comment"> * (Note that the kludge above would even match on "Got milk?".)</span> <a name="l00156"></a>00156 <span class="comment"> */</span> <a name="l00157"></a>00157 QStringList parts = args.value(<span class="stringliteral">"msg"</span>).split(<span class="stringliteral">" "</span>); <a name="l00158"></a>00158 <span class="keywordflow">if</span> (parts.size() == 5) { <a name="l00159"></a>00159 QStringList progress = parts.at(1).split(<span class="stringliteral">"/"</span>); <a name="l00160"></a>00160 <span class="keywordflow">if</span> (progress.size() == 2) { <a name="l00161"></a>00161 <span class="keywordtype">int</span> bytesReceived = progress.at(0).toUInt(); <a name="l00162"></a>00162 <span class="keywordtype">int</span> bytesTotal = progress.at(1).toUInt(); <a name="l00163"></a>00163 <a class="code" href="_vidalia_8h.html#a7743cb328f470aa8f382716fbcf61daa">vInfo</a>(<span class="stringliteral">"updater: Downloaded %1 of %2 bytes of file %3"</span>).arg(bytesReceived) <a name="l00164"></a>00164 .arg(bytesTotal) <a name="l00165"></a>00165 .arg(parts.at(4)); <a name="l00166"></a>00166 emit <a class="code" href="class_update_process.html#ae3893a1e2f6eaf338e5d35c1967a4e43">downloadProgress</a>(parts.at(4), bytesReceived, bytesTotal); <a name="l00167"></a>00167 } <a name="l00168"></a>00168 } <a name="l00169"></a>00169 } <a name="l00170"></a>00170 } <a name="l00171"></a>00171 } <a name="l00172"></a>00172 <a name="l00173"></a>00173 <span class="keywordtype">void</span> <a name="l00174"></a><a class="code" href="class_update_process.html#abb9ea44d23dc24a2d4b74d229aec3405">00174</a> <a class="code" href="class_update_process.html#abb9ea44d23dc24a2d4b74d229aec3405">UpdateProcess::readStandardOutput</a>() <a name="l00175"></a>00175 { <a name="l00176"></a>00176 QString line; <a name="l00177"></a>00177 <a name="l00178"></a>00178 setReadChannel(QProcess::StandardOutput); <a name="l00179"></a>00179 <span class="keywordflow">while</span> (canReadLine()) { <a name="l00180"></a>00180 line = readLine().trimmed(); <a name="l00181"></a>00181 <a class="code" href="_vidalia_8h.html#a7743cb328f470aa8f382716fbcf61daa">vInfo</a>(<span class="stringliteral">"updater (stdout): %1"</span>).arg(line); <a name="l00182"></a>00182 } <a name="l00183"></a>00183 } <a name="l00184"></a>00184 <a name="l00185"></a>00185 <span class="keywordtype">void</span> <a name="l00186"></a><a class="code" href="class_update_process.html#a6ade5ac73e733c8feb2a621f8e2fba0e">00186</a> <a class="code" href="class_update_process.html#a6ade5ac73e733c8feb2a621f8e2fba0e">UpdateProcess::onFinished</a>(<span class="keywordtype">int</span> exitCode, QProcess::ExitStatus exitStatus) <a name="l00187"></a>00187 { <a name="l00188"></a>00188 <a class="code" href="_vidalia_8h.html#a7743cb328f470aa8f382716fbcf61daa">vInfo</a>(<span class="stringliteral">"updater: update process finished with exit code %1"</span>).arg(exitCode); <a name="l00189"></a>00189 <a name="l00190"></a>00190 <span class="keywordflow">if</span> (<a class="code" href="class_update_process.html#a5af899e34cb30d7968559c360b872812">_currentCommand</a> == <a class="code" href="class_update_process.html#ac5239113ac6cd658d43e7f85ae941892aa14277377dbaab311cdd2bf895c07307">CheckForUpdates</a>) { <a name="l00191"></a>00191 <span class="keywordflow">if</span> (exitStatus == QProcess::NormalExit) { <a name="l00192"></a>00192 emit <a class="code" href="class_update_process.html#a0ba81f11f9fc4300291830d5ca095951">updatesAvailable</a>(<a class="code" href="class_update_process.html#a02082dfdfd6d195d3b60d58a9851414b">_currentBundle</a>, <a class="code" href="class_update_process.html#aeb464d61d31ea758449d6aa81f915031">_packageList</a>); <a name="l00193"></a>00193 } <span class="keywordflow">else</span> { <a name="l00194"></a>00194 emit <a class="code" href="class_update_process.html#add9bbf76630b289df3681e18b487fd5f">checkForUpdatesFailed</a>(tr(<span class="stringliteral">"Vidalia was unable to check for available "</span> <a name="l00195"></a>00195 <span class="stringliteral">"software updates because Tor's update process "</span> <a name="l00196"></a>00196 <span class="stringliteral">"exited unexpectedly."</span>)); <a name="l00197"></a>00197 } <a name="l00198"></a>00198 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="class_update_process.html#a5af899e34cb30d7968559c360b872812">_currentCommand</a> == <a class="code" href="class_update_process.html#ac5239113ac6cd658d43e7f85ae941892a359c42bed4c86ef4763c9a08ebfc95f6">InstallUpdates</a>) { <a name="l00199"></a>00199 <span class="keywordflow">if</span> (exitStatus == QProcess::NormalExit && exitCode == 0) <a name="l00200"></a>00200 emit <a class="code" href="class_update_process.html#ac082af6a8e6d7ea066561c721f4fd9ae">updatesInstalled</a>(<a class="code" href="class_update_process.html#aeb464d61d31ea758449d6aa81f915031">_packageList</a>.size()); <a name="l00201"></a>00201 } <a name="l00202"></a>00202 <a class="code" href="class_update_process.html#aeb464d61d31ea758449d6aa81f915031">_packageList</a>.clear(); <a name="l00203"></a>00203 } <a name="l00204"></a>00204 <a name="l00205"></a>00205 <span class="keywordtype">void</span> <a name="l00206"></a><a class="code" href="class_update_process.html#a8779681b5b2cdd58fe38909e4af3d13c">00206</a> <a class="code" href="class_update_process.html#a8779681b5b2cdd58fe38909e4af3d13c">UpdateProcess::onError</a>(QProcess::ProcessError <a class="code" href="namespacetc.html#aa7353218fd7baef0876bbb422ce818af">error</a>) <a name="l00207"></a>00207 { <a name="l00208"></a>00208 <span class="keywordflow">if</span> (error == QProcess::FailedToStart) { <a name="l00209"></a>00209 <a class="code" href="_vidalia_8h.html#a6d8c1ad992d06eece6f19b8246219779">vWarn</a>(<span class="stringliteral">"updater: failed to start"</span>); <a name="l00210"></a>00210 emit <a class="code" href="class_update_process.html#add9bbf76630b289df3681e18b487fd5f">checkForUpdatesFailed</a>(tr(<span class="stringliteral">"Vidalia was unable to check for available "</span> <a name="l00211"></a>00211 <span class="stringliteral">"software updates because it could not find "</span> <a name="l00212"></a>00212 <span class="stringliteral">"'%1'."</span>).arg(<a class="code" href="class_update_process.html#a5d6ecf49da3e0d37e99ac5794d78c145">updateExecutable</a>())); <a name="l00213"></a>00213 } <a name="l00214"></a>00214 } <a name="l00215"></a>00215 <a name="l00216"></a>00216 <span class="keywordtype">int</span> <a name="l00217"></a><a class="code" href="class_update_process.html#a54d4d22cb36b1690d3c476f908681878">00217</a> <a class="code" href="class_update_process.html#a54d4d22cb36b1690d3c476f908681878">UpdateProcess::checkForUpdatesInterval</a>() <a name="l00218"></a>00218 { <a name="l00219"></a>00219 <span class="comment">/* XXX: Check twice a day. Why? Because arma said so. */</span> <a name="l00220"></a>00220 <span class="keywordflow">return</span> 12*60*60; <a name="l00221"></a>00221 } <a name="l00222"></a>00222 <a name="l00223"></a>00223 QDateTime <a name="l00224"></a><a class="code" href="class_update_process.html#acc5db0f95435463db6229a12c6b33b47">00224</a> <a class="code" href="class_update_process.html#acc5db0f95435463db6229a12c6b33b47">UpdateProcess::nextCheckForUpdates</a>(<span class="keyword">const</span> QDateTime &lastCheckedAt) <a name="l00225"></a>00225 { <a name="l00226"></a>00226 <span class="keywordflow">return</span> lastCheckedAt.addSecs(<a class="code" href="class_update_process.html#a54d4d22cb36b1690d3c476f908681878">checkForUpdatesInterval</a>()).toUTC(); <a name="l00227"></a>00227 } <a name="l00228"></a>00228 <a name="l00229"></a>00229 <span class="keywordtype">bool</span> <a name="l00230"></a><a class="code" href="class_update_process.html#afe8256e9bfeac91f946b73036fbec004">00230</a> <a class="code" href="class_update_process.html#afe8256e9bfeac91f946b73036fbec004">UpdateProcess::shouldCheckForUpdates</a>(<span class="keyword">const</span> QDateTime &lastCheckedAt) <a name="l00231"></a>00231 { <a name="l00232"></a>00232 QDateTime nextCheckAt = <a class="code" href="class_update_process.html#acc5db0f95435463db6229a12c6b33b47">nextCheckForUpdates</a>(lastCheckedAt); <a name="l00233"></a>00233 <span class="keywordflow">return</span> (QDateTime::currentDateTime().toUTC() >= nextCheckAt); <a name="l00234"></a>00234 } <a name="l00235"></a>00235 <a name="l00236"></a>00236 QString <a name="l00237"></a><a class="code" href="class_update_process.html#a5d6ecf49da3e0d37e99ac5794d78c145">00237</a> <a class="code" href="class_update_process.html#a5d6ecf49da3e0d37e99ac5794d78c145">UpdateProcess::updateExecutable</a>() <a name="l00238"></a>00238 { <a name="l00239"></a>00239 <span class="keywordflow">return</span> <span class="stringliteral">"thandy.exe"</span>; <a name="l00240"></a>00240 } <a name="l00241"></a>00241 <a name="l00242"></a>00242 QString <a name="l00243"></a><a class="code" href="class_update_process.html#abedc59438d71f84d07f8ae1558a2145f">00243</a> <a class="code" href="class_update_process.html#abedc59438d71f84d07f8ae1558a2145f">UpdateProcess::updateRepositoryDir</a>() <a name="l00244"></a>00244 { <a name="l00245"></a>00245 <span class="keywordflow">return</span> QDir::convertSeparators(<a class="code" href="class_vidalia.html#a5c923ad28bb9f02299f5c4d3c6c2bde0">Vidalia::dataDirectory</a>() + <span class="stringliteral">"/updates"</span>); <a name="l00246"></a>00246 } <a name="l00247"></a>00247 <a name="l00248"></a>00248 QString <a name="l00249"></a><a class="code" href="class_update_process.html#aa4faf0b0513bca7ae5b0a10d4c077df1">00249</a> <a class="code" href="class_update_process.html#aa4faf0b0513bca7ae5b0a10d4c077df1">UpdateProcess::bundleInfoToString</a>(<a class="code" href="class_update_process.html#a7f96e69b1f212525d935655e9c00505a">BundleInfo</a> bi) <a name="l00250"></a>00250 { <a name="l00251"></a>00251 <span class="keywordflow">switch</span> (bi) { <a name="l00252"></a>00252 <span class="keywordflow">case</span> <a class="code" href="class_update_process.html#a7f96e69b1f212525d935655e9c00505aaeedc102a1d827bd521456d530472ffa4">TorBundleInfo</a>: <a name="l00253"></a>00253 <span class="keywordflow">return</span> <span class="stringliteral">"/bundleinfo/tor/win32/"</span>; <a name="l00254"></a>00254 <span class="keywordflow">default</span>: <a name="l00255"></a>00255 <span class="keywordflow">return</span> QString(); <a name="l00256"></a>00256 }; <a name="l00257"></a>00257 } <a name="l00258"></a>00258 <a name="l00259"></a>00259 <a class="code" href="class_package_info.html">PackageInfo</a> <a name="l00260"></a><a class="code" href="class_update_process.html#a8304b8d0832f18048a138ff4ee9676f1">00260</a> <a class="code" href="class_update_process.html#a8304b8d0832f18048a138ff4ee9676f1">UpdateProcess::packageInfo</a>(<span class="keyword">const</span> QString &package) <a name="l00261"></a>00261 { <a name="l00262"></a>00262 QProcess proc; <a name="l00263"></a>00263 QStringList args; <a name="l00264"></a>00264 <a name="l00265"></a>00265 args << <span class="stringliteral">"json2xml"</span> <a name="l00266"></a>00266 << QDir::convertSeparators(<a class="code" href="class_update_process.html#abedc59438d71f84d07f8ae1558a2145f">updateRepositoryDir</a>() + <span class="stringliteral">"/"</span> + package); <a name="l00267"></a>00267 <a name="l00268"></a>00268 <a class="code" href="_vidalia_8h.html#a61e4319b31bbbc7eb1a5724b487be75f">vNotice</a>(<span class="stringliteral">"updater: launching auto-update executable: %1 %2"</span>) <a name="l00269"></a>00269 .arg(<a class="code" href="class_update_process.html#a5d6ecf49da3e0d37e99ac5794d78c145">updateExecutable</a>()) <a name="l00270"></a>00270 .arg(args.join(<span class="stringliteral">" "</span>)); <a name="l00271"></a>00271 <a name="l00272"></a>00272 proc.setEnvironment(proc.systemEnvironment()); <a name="l00273"></a>00273 proc.start(<a class="code" href="class_update_process.html#a5d6ecf49da3e0d37e99ac5794d78c145">updateExecutable</a>(), args); <a name="l00274"></a>00274 <span class="keywordflow">if</span> (! proc.waitForStarted()) <a name="l00275"></a>00275 <span class="keywordflow">return</span> <a class="code" href="class_package_info.html">PackageInfo</a>(); <a name="l00276"></a>00276 <span class="keywordflow">if</span> (! proc.waitForFinished()) <a name="l00277"></a>00277 <span class="keywordflow">return</span> <a class="code" href="class_package_info.html">PackageInfo</a>(); <a name="l00278"></a>00278 <span class="keywordflow">return</span> <a class="code" href="class_update_process.html#a1da3e9862f8f95ca894b7c03959a8647">packageInfoFromXml</a>(proc.readAll()); <a name="l00279"></a>00279 } <a name="l00280"></a>00280 <a name="l00281"></a>00281 <a class="code" href="class_package_info.html">PackageInfo</a> <a name="l00282"></a><a class="code" href="class_update_process.html#a1da3e9862f8f95ca894b7c03959a8647">00282</a> <a class="code" href="class_update_process.html#a1da3e9862f8f95ca894b7c03959a8647">UpdateProcess::packageInfoFromXml</a>(<span class="keyword">const</span> QByteArray &xml) <a name="l00283"></a>00283 { <a name="l00284"></a>00284 QDomDocument doc; <a name="l00285"></a>00285 QDomElement dict, elem; <a name="l00286"></a>00286 QDomNodeList nodeList; <a name="l00287"></a>00287 QString errmsg; <a name="l00288"></a>00288 QStringList versionParts; <a name="l00289"></a>00289 <a class="code" href="class_package_info.html">PackageInfo</a> pkgInfo; <a name="l00290"></a>00290 <a name="l00291"></a>00291 <span class="keywordflow">if</span> (! doc.setContent(xml, <span class="keyword">false</span>, &errmsg, 0, 0)) <a name="l00292"></a>00292 <span class="keywordflow">goto</span> <a class="code" href="stringutil_8cpp.html#a6e3f242b28c9165146182aec25e351a3">err</a>; <a name="l00293"></a>00293 <a name="l00294"></a>00294 <span class="comment">/* XXX: Qt 4.4 introduced XPath support, which would make the following</span> <a name="l00295"></a>00295 <span class="comment"> * parsing much easier. Whenever we drop support for Qt < 4.4, this should</span> <a name="l00296"></a>00296 <span class="comment"> * be updated.</span> <a name="l00297"></a>00297 <span class="comment"> */</span> <a name="l00298"></a>00298 elem = doc.documentElement().firstChildElement(<span class="stringliteral">"signed"</span>); <a name="l00299"></a>00299 <span class="keywordflow">if</span> (elem.isNull()) { <a name="l00300"></a>00300 errmsg = <span class="stringliteral">"Signed element not found"</span>; <a name="l00301"></a>00301 <span class="keywordflow">goto</span> <a class="code" href="stringutil_8cpp.html#a6e3f242b28c9165146182aec25e351a3">err</a>; <a name="l00302"></a>00302 } <a name="l00303"></a>00303 <a name="l00304"></a>00304 dict = elem.firstChildElement(<span class="stringliteral">"dict"</span>); <a name="l00305"></a>00305 <span class="keywordflow">if</span> (dict.isNull()) { <a name="l00306"></a>00306 errmsg = <span class="stringliteral">"no Dict element as a child of Signed"</span>; <a name="l00307"></a>00307 <span class="keywordflow">goto</span> <a class="code" href="stringutil_8cpp.html#a6e3f242b28c9165146182aec25e351a3">err</a>; <a name="l00308"></a>00308 } <a name="l00309"></a>00309 <a name="l00310"></a>00310 elem = dict.firstChildElement(<span class="stringliteral">"name"</span>); <a name="l00311"></a>00311 <span class="keywordflow">if</span> (elem.isNull()) { <a name="l00312"></a>00312 errmsg = <span class="stringliteral">"Name element not found"</span>; <a name="l00313"></a>00313 <span class="keywordflow">goto</span> <a class="code" href="stringutil_8cpp.html#a6e3f242b28c9165146182aec25e351a3">err</a>; <a name="l00314"></a>00314 } <a name="l00315"></a>00315 pkgInfo.<a class="code" href="class_package_info.html#a25be2f32505176783901ece0c7cf1cc3">setName</a>(elem.text()); <a name="l00316"></a>00316 <a name="l00317"></a>00317 elem = dict.firstChildElement(<span class="stringliteral">"version"</span>).firstChildElement(<span class="stringliteral">"list"</span>); <a name="l00318"></a>00318 <span class="keywordflow">if</span> (elem.isNull()) { <a name="l00319"></a>00319 errmsg = <span class="stringliteral">"no valid Version element found"</span>; <a name="l00320"></a>00320 <span class="keywordflow">goto</span> <a class="code" href="stringutil_8cpp.html#a6e3f242b28c9165146182aec25e351a3">err</a>; <a name="l00321"></a>00321 } <a name="l00322"></a>00322 elem = elem.firstChildElement(<span class="stringliteral">"item"</span>); <a name="l00323"></a>00323 <span class="keywordflow">for</span> ( ; ! elem.isNull(); elem = elem.nextSiblingElement(<span class="stringliteral">"item"</span>)) { <a name="l00324"></a>00324 versionParts << elem.text(); <a name="l00325"></a>00325 } <a name="l00326"></a>00326 pkgInfo.<a class="code" href="class_package_info.html#a7260ec05dcff8f538bcfd73fb6e015df">setVersion</a>(versionParts.join(<span class="stringliteral">"."</span>)); <a name="l00327"></a>00327 <a name="l00328"></a>00328 elem = dict.firstChildElement(<span class="stringliteral">"shortdesc"</span>).firstChildElement(<span class="stringliteral">"dict"</span>); <a name="l00329"></a>00329 <span class="keywordflow">if</span> (elem.isNull()) { <a name="l00330"></a>00330 errmsg = <span class="stringliteral">"no valid Shortdesc element found"</span>; <a name="l00331"></a>00331 <span class="keywordflow">goto</span> <a class="code" href="stringutil_8cpp.html#a6e3f242b28c9165146182aec25e351a3">err</a>; <a name="l00332"></a>00332 } <a name="l00333"></a>00333 elem = elem.firstChildElement(); <a name="l00334"></a>00334 <span class="keywordflow">for</span> ( ; ! elem.isNull(); elem = elem.nextSiblingElement()) { <a name="l00335"></a>00335 pkgInfo.<a class="code" href="class_package_info.html#a0070f09007f1c05c0d604394c79dd2c3">setShortDescription</a>(elem.tagName(), elem.text()); <a name="l00336"></a>00336 } <a name="l00337"></a>00337 <a name="l00338"></a>00338 elem = dict.firstChildElement(<span class="stringliteral">"longdesc"</span>).firstChildElement(<span class="stringliteral">"dict"</span>); <a name="l00339"></a>00339 <span class="keywordflow">if</span> (elem.isNull()) { <a name="l00340"></a>00340 errmsg = <span class="stringliteral">"no valid Longdesc element found"</span>; <a name="l00341"></a>00341 <span class="keywordflow">goto</span> <a class="code" href="stringutil_8cpp.html#a6e3f242b28c9165146182aec25e351a3">err</a>; <a name="l00342"></a>00342 } <a name="l00343"></a>00343 elem = elem.firstChildElement(); <a name="l00344"></a>00344 <span class="keywordflow">for</span> ( ; ! elem.isNull(); elem = elem.nextSiblingElement()) { <a name="l00345"></a>00345 pkgInfo.<a class="code" href="class_package_info.html#a2fd26fc2d10e95ed541e1bb4af2e7c68">setLongDescription</a>(elem.tagName(), elem.text()); <a name="l00346"></a>00346 } <a name="l00347"></a>00347 <a name="l00348"></a>00348 <span class="keywordflow">return</span> pkgInfo; <a name="l00349"></a>00349 <a name="l00350"></a>00350 <a class="code" href="stringutil_8cpp.html#a6e3f242b28c9165146182aec25e351a3">err</a>: <a name="l00351"></a>00351 <a class="code" href="_vidalia_8h.html#a6d8c1ad992d06eece6f19b8246219779">vWarn</a>(<span class="stringliteral">"updater: invalid package info XML document: %1"</span>).arg(errmsg); <a name="l00352"></a>00352 <span class="keywordflow">return</span> <a class="code" href="class_package_info.html">PackageInfo</a>(); <a name="l00353"></a>00353 } <a name="l00354"></a>00354 </pre></div></div> <hr class="footer"/><address style="text-align: right;"><small>Generated on Mon Aug 30 22:58:55 2010 for Vidalia by <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address> </body> </html>