[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r1217: Factor creating our data directory and touching an empty tor (in trunk/src: . gui/config util util/geoip)
Author: edmanm
Date: 2006-09-21 01:34:08 -0400 (Thu, 21 Sep 2006)
New Revision: 1217
Added:
trunk/src/util/file.cpp
trunk/src/util/file.h
Modified:
trunk/src/gui/config/advancedpage.cpp
trunk/src/util/geoip/geoipcache.cpp
trunk/src/util/util.pri
trunk/src/vidalia.cpp
trunk/src/vidalia.h
Log:
Factor creating our data directory and touching an empty torrc into
create_path() and touch_file().
Modified: trunk/src/gui/config/advancedpage.cpp
===================================================================
--- trunk/src/gui/config/advancedpage.cpp 2006-09-21 04:11:40 UTC (rev 1216)
+++ trunk/src/gui/config/advancedpage.cpp 2006-09-21 05:34:08 UTC (rev 1217)
@@ -27,6 +27,7 @@
#include <QFile>
#include <QFileInfo>
#include <gui/common/vmessagebox.h>
+#include <util/file.h>
#include <vidalia.h>
#include "advancedpage.h"
@@ -124,11 +125,12 @@
return;
}
/* Attempt to create the specified file */
- if (!torrcFile.open(QIODevice::WriteOnly)) {
+ QString errmsg;
+ if (!touch_file(filename, false, &errmsg)) {
VMessageBox::warning(this,
tr("Failed to Create File"),
tr("Unable to create %1 [%2]").arg(filename)
- .arg(torrcFile.errorString()),
+ .arg(errmsg),
VMessageBox::Ok);
return;
}
Added: trunk/src/util/file.cpp
===================================================================
--- trunk/src/util/file.cpp (rev 0)
+++ trunk/src/util/file.cpp 2006-09-21 05:34:08 UTC (rev 1217)
@@ -0,0 +1,67 @@
+/****************************************************************
+ * Vidalia is distributed under the following license:
+ *
+ * Copyright (C) 2006, Matt Edman, Justin Hipple
+ *
+ * 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.
+ *
+ * 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ ****************************************************************/
+
+/**
+ * \file file.cpp
+ * \version $Id$
+ */
+
+#include <QDir>
+#include <QFile>
+#include "file.h"
+
+
+/** Create an empty file named <b>filename</b>. if <b>createdir</b> is true,
+ * then the full path to <b>filename</b> will be created. Returns true on
+ * success, or false on error and <b>errmsg</b> will be set. */
+bool
+touch_file(QString filename, bool createdir, QString *errmsg)
+{
+ /* 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())) {
+ return false;
+ }
+
+ /* Touch the file */
+ QFile file(filename);
+ if (!QFileInfo(filename).exists()) {
+ if (!file.open(QIODevice::WriteOnly)) {
+ return err(errmsg, file.errorString());
+ }
+ }
+ return true;
+}
+
+/** Creates all directories in <b>path</b>, if they do not exist. */
+bool
+create_path(QString path)
+{
+ QDir dir(path);
+ if (!dir.exists()) {
+ path = dir.absolutePath();
+ if (!dir.mkpath(path)) {
+ return false;
+ }
+ }
+ return true;
+}
+
Property changes on: trunk/src/util/file.cpp
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/src/util/file.h
===================================================================
--- trunk/src/util/file.h (rev 0)
+++ trunk/src/util/file.h 2006-09-21 05:34:08 UTC (rev 1217)
@@ -0,0 +1,43 @@
+/****************************************************************
+ * Vidalia is distributed under the following license:
+ *
+ * Copyright (C) 2006, Matt Edman, Justin Hipple
+ *
+ * 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.
+ *
+ * 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ ****************************************************************/
+
+/**
+ * \file file.h
+ * \version $Id$
+ */
+
+#ifndef _FILE_H
+#define _FILE_H
+
+#include <QString>
+#include "string.h"
+
+
+/** Create an empty file named <b>filename</b>. if <b>createdir</b> is true,
+ * then the full path to <b>filename</b> will be created. Returns true on
+ * success, or false on error and <b>errmsg</b> will be set. */
+bool touch_file(QString filename, bool createdir = false, QString *errmsg = 0);
+
+/** Creates all directories in <b>path</b>, if they do not exist. */
+bool create_path(QString path);
+
+#endif
+
Property changes on: trunk/src/util/file.h
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: trunk/src/util/geoip/geoipcache.cpp
===================================================================
--- trunk/src/util/geoip/geoipcache.cpp 2006-09-21 04:11:40 UTC (rev 1216)
+++ trunk/src/util/geoip/geoipcache.cpp 2006-09-21 05:34:08 UTC (rev 1217)
@@ -28,6 +28,7 @@
#include <QDir>
#include <QTextStream>
#include <util/string.h>
+#include <util/file.h>
#include <vidalia.h>
#include "geoipcache.h"
@@ -55,7 +56,7 @@
GeoIpCache::saveToDisk(QString *errmsg)
{
/* Make sure we have a data directory. */
- if (!Vidalia::createDataDirectory(errmsg)) {
+ if (!create_path(Vidalia::dataDirectory())) {
return false;
}
Modified: trunk/src/util/util.pri
===================================================================
--- trunk/src/util/util.pri 2006-09-21 04:11:40 UTC (rev 1216)
+++ trunk/src/util/util.pri 2006-09-21 05:34:08 UTC (rev 1217)
@@ -26,14 +26,16 @@
$$PWD/string.h \
$$PWD/torsocket.h \
$$PWD/html.h \
- $$PWD/process.h
+ $$PWD/process.h \
+ $$PWD/file.h
SOURCES += $$PWD/net.cpp \
$$PWD/http.cpp \
$$PWD/string.cpp \
$$PWD/torsocket.cpp \
$$PWD/html.cpp \
- $$PWD/process.cpp
+ $$PWD/process.cpp \
+ $$PWD/file.cpp
win32 {
HEADERS += $$PWD/win32.h
Modified: trunk/src/vidalia.cpp
===================================================================
--- trunk/src/vidalia.cpp 2006-09-21 04:11:40 UTC (rev 1216)
+++ trunk/src/vidalia.cpp 2006-09-21 05:34:08 UTC (rev 1217)
@@ -252,21 +252,6 @@
#endif
}
-/** Creates Vidalia's data directory, if it doesn't already exist. */
-bool
-Vidalia::createDataDirectory(QString *errmsg)
-{
- QDir datadir(dataDirectory());
- if (!datadir.exists()) {
- QString path = datadir.absolutePath();
- if (!datadir.mkpath(path)) {
- return err(errmsg,
- QString("Could not create data directory: %1").arg(path));
- }
- }
- return true;
-}
-
/** Returns the location of Vidalia's pid file. */
QString
Vidalia::pidFile()
Modified: trunk/src/vidalia.h
===================================================================
--- trunk/src/vidalia.h 2006-09-21 04:11:40 UTC (rev 1216)
+++ trunk/src/vidalia.h 2006-09-21 05:34:08 UTC (rev 1217)
@@ -82,8 +82,6 @@
static QString dataDirectory();
/** Returns the default location of Vidalia's data directory. */
static QString defaultDataDirectory();
- /** Creates Vidalia's data directory, if it doesn't already exist. */
- static bool createDataDirectory(QString *errmsg);
/** Returns the location of Vidalia's pid file. */
static QString pidFile();