StandardPaths.cpp 2.81 KB
#include "StandardPaths.h"
#include <QCoreApplication>

#include <QDir>
QString StandardPaths::_logPath = QString();
QString StandardPaths::_profilePath = QString();

#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))

#include <QStandardPaths>
#include <QDir>
#include <QDebug>

QString StandardPaths::getLogPath()
{
    if (!_logPath.isEmpty()) return _logPath;

    // make path QCoreApplication::applicationDirPath()
    //QDir appDir(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + QString("/CloudSample"));
    QDir appDir(QCoreApplication::applicationDirPath() + QString("/CloudSample"));
    appDir.mkpath("log");
    //_logPath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation).append("/CloudSample/log");
    _logPath = QCoreApplication::applicationDirPath() + QString("/CloudSample/log");
    return _logPath;
}

QString StandardPaths::getProfilePath()
{
    if (!_profilePath.isEmpty()) return _profilePath;

    // make path
    //QDir appDir(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation));
    QDir appDir(QCoreApplication::applicationDirPath() + QString("/CloudSample"));
    appDir.mkpath("profile");
    _profilePath = QCoreApplication::applicationDirPath() + QString("/CloudSample/profile");
    return _profilePath;
}

#else

#include <string.h>
#include <shlwapi.h>
#include <Shlobj.h>

//static bool GetAppPath(TCHAR *ptcBuf, size_t size)
//{
//    TCHAR atcPath[MAX_PATH];

//    if(SUCCEEDED(SHGetFolderPath(NULL,
//        CSIDL_PERSONAL|CSIDL_FLAG_CREATE,
//        NULL,
//        0,
//        atcPath)))
//    {
//        PathAppend(atcPath, TEXT("CloudSample"));

//        WIN32_FIND_DATA wfd;
//        HANDLE hFind = FindFirstFile(atcPath, &wfd);
//        if (hFind == INVALID_HANDLE_VALUE
//            || !(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
//        {
//            SECURITY_ATTRIBUTES attrib;
//            attrib.bInheritHandle = FALSE;
//            attrib.lpSecurityDescriptor = NULL;
//            attrib.nLength = sizeof(SECURITY_ATTRIBUTES);
//            ::CreateDirectory(atcPath, &attrib);
//        }

//        wcscpy_s(ptcBuf, size, atcPath);
//        return true;
//    }

//    return false;
//}

QString StandardPaths::getLogPath()
{
    if (!_logPath.isEmpty()) return _logPath;

    _logPath = "C:\\Users\\Administrator\\Documents\\CloudSample\\log\\";
    QDir dir(_logPath);
    if(!dir.exists())
    {
        dir.mkdir(_logPath);
    }

    return _logPath;
}

QString StandardPaths::getProfilePath()
{
    if (!_profilePath.isEmpty()) return _profilePath;

   // _profilePath =QCoreApplication::applicationDirPath() + "\\profile\\";
    _profilePath = "C:\\Users\\Administrator\\Documents\\CloudSample\\profile\\";

    QDir dir(_profilePath);
    if(!dir.exists())
    {
        dir.mkdir(_profilePath);
    }

    return _profilePath;
}

#endif