StelFileMgr.cpp   StelFileMgr.cpp 
#include <config.h> /*
* Stellarium
* Copyright (C) 2010 Fabien Chereau
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U
SA.
*/
#include <cstdlib> #include <cstdlib>
#include <QCoreApplication> #include <QCoreApplication>
#include <QFileInfo> #include <QFileInfo>
#include <QDir> #include <QDir>
#include <QString> #include <QString>
#include <QDebug> #include <QDebug>
#include <QDesktopServices> #include <QDesktopServices>
#include "StelUtils.hpp" #include "StelUtils.hpp"
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
# include <windows.h> # include <windows.h>
# ifndef _SHOBJ_H # ifndef _SHOBJ_H
# include <shlobj.h> # include <shlobj.h>
# include <QLibrary> # include <QLibrary>
# endif # endif
#endif #endif
#ifdef Q_OS_MAC
#include "StelMacosxDirs.hpp"
#endif
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
// Initialize static members. // Initialize static members.
QStringList StelFileMgr::fileLocations; QStringList StelFileMgr::fileLocations;
QString StelFileMgr::userDir; QString StelFileMgr::userDir;
QString StelFileMgr::screenshotDir; QString StelFileMgr::screenshotDir;
void StelFileMgr::init() void StelFileMgr::init()
{ {
// Set the userDir member. // Set the userDir member.
skipping to change at line 79 skipping to change at line 93
qWarning() << "WARNING: could not locate installation direct ory"; qWarning() << "WARNING: could not locate installation direct ory";
} }
#if defined(Q_OS_WIN) || defined(Q_OS_MAC) #if defined(Q_OS_WIN) || defined(Q_OS_MAC)
screenshotDir = getDesktopDir(); screenshotDir = getDesktopDir();
#else #else
screenshotDir = QDir::homePath(); screenshotDir = QDir::homePath();
#endif #endif
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
StelMacosxDirs::addApplicationPluginDirectory(); QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPat h());
#endif #endif
} }
QString StelFileMgr::findFile(const QString& path, const Flags& flags) QString StelFileMgr::findFile(const QString& path, const Flags& flags)
{ {
if (path.isEmpty()) if (path.isEmpty())
throw std::runtime_error("Empty file path"); throw std::runtime_error("Empty file path");
// explicitly specified relative paths // explicitly specified relative paths
if (path[0] == '.') if (path[0] == '.')
{ {
if (fileFlagsCheck(path, flags)) if (fileFlagsCheck(path, flags))
return path; return path;
skipping to change at line 383 skipping to change at line 397
else if (!userDirFI.isWritable()) else if (!userDirFI.isWritable())
{ {
qWarning() << "WARNING StelFileMgr::setScreenshotDir dir is not writable: " << userDirFI.filePath(); qWarning() << "WARNING StelFileMgr::setScreenshotDir dir is not writable: " << userDirFI.filePath();
throw std::runtime_error("NOT_VALID"); throw std::runtime_error("NOT_VALID");
} }
screenshotDir = userDirFI.filePath(); screenshotDir = userDirFI.filePath();
} }
QString StelFileMgr::getLocaleDir() QString StelFileMgr::getLocaleDir()
{ {
#ifdef ENABLE_NLS
QFileInfo localePath; QFileInfo localePath;
#if defined(Q_OS_WIN) || defined(Q_OS_MAC) #if defined(Q_OS_WIN) || defined(Q_OS_MAC)
// Windows and MacOS X have the locale dir in the installation folde r // Windows and MacOS X have the locale dir in the installation folde r
localePath = QFileInfo(getInstallationDir() + "/locale"); localePath = QFileInfo(getInstallationDir() + "/locale");
// or MacosxDirs::getApplicationResourcesDirectory().append( "/local e" ); // or MacosxDirs::getApplicationResourcesDirectory().append( "/local e" );
#else #else
// Linux, BSD etc, the locale dir is set in the config.h // Linux, BSD etc, the locale dir is set in the config.h
// but first, if we are in the development tree, don't rely on an // but first, if we are in the development tree, don't rely on an
// install having been done. // install having been done.
if (getInstallationDir() == ".") if (getInstallationDir() == ".")
skipping to change at line 407 skipping to change at line 422
} }
else else
localePath = QFileInfo(QFile::decodeName(INSTALL_LOCALEDIR)) ; localePath = QFileInfo(QFile::decodeName(INSTALL_LOCALEDIR)) ;
#endif #endif
if (localePath.exists()) if (localePath.exists())
{ {
return localePath.filePath(); return localePath.filePath();
} }
else else
{ {
qWarning() << "WARNING in StelFileMgr::getLocaleDir() - coul d not determine locale directory, returning \"\""; qWarning() << "WARNING StelFileMgr::getLocaleDir() - could n ot determine locale directory, returning \"\"";
return ""; return "";
} }
#else
return QString();
#endif
} }
// Returns the path to the cache directory. Note that subdirectories may ne ed to be created for specific caches. // Returns the path to the cache directory. Note that subdirectories may ne ed to be created for specific caches.
QString StelFileMgr::getCacheDir() QString StelFileMgr::getCacheDir()
{ {
const QString& cachePath = QDesktopServices::storageLocation(QDeskto pServices::CacheLocation); const QString& cachePath = QDesktopServices::storageLocation(QDeskto pServices::CacheLocation);
if (cachePath.isEmpty()) if (cachePath.isEmpty())
{ {
return getUserDir()+"/cache"; return getUserDir()+"/cache";
} }
return cachePath; return cachePath;
} }
void StelFileMgr::makeSureDirExistsAndIsWritable(const QString& dirFullPath ) void StelFileMgr::makeSureDirExistsAndIsWritable(const QString& dirFullPath )
{ {
// Check that the dirFullPath directory exists // Check that the dirFullPath directory exists
QFileInfo uDir(dirFullPath); QFileInfo uDir(dirFullPath);
if (!uDir.exists()) if (!uDir.exists())
{ {
// The modules directory doesn't exist, lets create it. // The modules directory doesn't exist, lets create it.
qDebug() << "Creates directory " << uDir.filePath(); qDebug() << "Creating directory " << uDir.filePath();
if (!QDir("/").mkpath(uDir.filePath())) if (!QDir("/").mkpath(uDir.filePath()))
{ {
throw std::runtime_error(QString("Could not create d irectory: " +uDir.filePath()).toStdString()); throw std::runtime_error(QString("Could not create d irectory: " +uDir.filePath()).toStdString());
} }
QFileInfo uDir2(dirFullPath);
if (!uDir2.isWritable())
{
throw std::runtime_error(QString("Directory is not w
ritable: " +uDir2.filePath()).toStdString());
}
} }
if (!uDir.isWritable()) else if (!uDir.isWritable())
{ {
throw std::runtime_error(QString("Directory is not writable: " +uDir.filePath()).toStdString()); throw std::runtime_error(QString("Directory is not writable: " +uDir.filePath()).toStdString());
} }
} }
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
QString StelFileMgr::getWin32SpecialDirPath(int csidlId) QString StelFileMgr::getWin32SpecialDirPath(int csidlId)
{ {
// This function is implemented using code from QSettings implementa tion in QT // This function is implemented using code from QSettings implementa tion in QT
// (GPL edition, version 4.3). // (GPL edition, version 4.3).
 End of changes. 10 change blocks. 
10 lines changed or deleted 35 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/