[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r1753: Expand filenames that use "~/", "%APPDATA%", or "%PROGRAMFIL (in trunk: . src/config src/control src/util)
Author: edmanm
Date: 2007-05-26 01:36:24 -0400 (Sat, 26 May 2007)
New Revision: 1753
Modified:
trunk/
trunk/src/config/torsettings.cpp
trunk/src/control/torcontrol.cpp
trunk/src/util/file.cpp
trunk/src/util/file.h
Log:
r1869@adrastea: edmanm | 2007-05-26 01:33:00 -0400
Expand filenames that use "~/", "%APPDATA%", or "%PROGRAMFILES%" in either the
path to Tor's executable or torrc.
Property changes on: trunk
___________________________________________________________________
svk:merge ticket from /vidalia/local/trunk [r1869] on 54b3572a-7227-0410-958f-53ecd705b71a
Modified: trunk/src/config/torsettings.cpp
===================================================================
--- trunk/src/config/torsettings.cpp 2007-05-26 05:36:12 UTC (rev 1752)
+++ trunk/src/config/torsettings.cpp 2007-05-26 05:36:24 UTC (rev 1753)
@@ -26,6 +26,7 @@
*/
#include <QDir>
+#include <util/file.h>
#include <vidalia.h>
#include "torsettings.h"
@@ -103,7 +104,8 @@
/* Add the torrc argument (if specified) */
QString torrc = getTorrc();
if (!torrc.isEmpty()) {
- args += formatArgument(TOR_ARG_TORRC, torrc) + " ";
+ args += formatArgument(TOR_ARG_TORRC,
+ expand_filename(torrc)) + " ";
}
/* Add the ControlPort value */
quint16 controlPort = getControlPort();
Modified: trunk/src/control/torcontrol.cpp
===================================================================
--- trunk/src/control/torcontrol.cpp 2007-05-26 05:36:12 UTC (rev 1752)
+++ trunk/src/control/torcontrol.cpp 2007-05-26 05:36:24 UTC (rev 1753)
@@ -116,7 +116,7 @@
this, SLOT(onLogStdout(QString, QString)));
/* Kick off the Tor process. */
- _torProcess->start(settings.getExecutable(),
+ _torProcess->start(expand_filename(settings.getExecutable()),
settings.getArguments());
#if defined(Q_OS_WIN32)
}
Modified: trunk/src/util/file.cpp
===================================================================
--- trunk/src/util/file.cpp 2007-05-26 05:36:12 UTC (rev 1752)
+++ trunk/src/util/file.cpp 2007-05-26 05:36:24 UTC (rev 1753)
@@ -36,6 +36,10 @@
bool
touch_file(QString filename, bool createdir, QString *errmsg)
{
+ /* Expand the file's path if it starts with a shortcut, like "~/" or
+ * "%APPDATA%" */
+ filename = expand_filename(filename);
+
/* If the file's path doesn't exist and we're supposed to create it, do that
* now. */
if (createdir && !create_path(QFileInfo(filename).absolutePath())) {
@@ -66,3 +70,24 @@
return true;
}
+/** Expands <b>filename</b> if it starts with "~/". On Windows, this will
+ * expand "%APPDATA%" and "%PROGRAMFILES%". If <b>filename</b> does not
+ * start with a shortcut, <b>filename</b> will be returned unmodified. */
+QString
+expand_filename(QString filename)
+{
+#if defined(Q_OS_WIN32)
+ if (filename.startsWith("%APPDATA%\\") ||
+ filename.startsWith("%APPDATA%/"))
+ return filename.replace(0, 9, win32_app_data_folder());
+
+ if (filename.startsWith("%PROGRAMFILES%\\") ||
+ filename.startsWith("%PROGRAMFILES%/"))
+ return filename.replace(0, 14, win32_program_files_folder());
+#else
+ if (filename.startsWith("~/"))
+ return filename.replace(0, 1, QDir::homePath());
+#endif
+ return filename;
+}
+
Modified: trunk/src/util/file.h
===================================================================
--- trunk/src/util/file.h 2007-05-26 05:36:12 UTC (rev 1752)
+++ trunk/src/util/file.h 2007-05-26 05:36:24 UTC (rev 1753)
@@ -40,5 +40,10 @@
/** Creates all directories in <b>path</b>, if they do not exist. */
bool create_path(QString path);
+/** Expands <b>filename</b> if it starts with "~/". On Windows, this will
+ * expand "%APPDATA%" and "%PROGRAMFILES%". If <b>filename</b> does not
+ * start with a shortcut, <b>filename</b> will be returned unmodified. */
+QString expand_filename(QString filename);
+
#endif