Blame view

LiveChat/FeiTalk/StandardPaths.cpp 2.81 KB
9f17d59e   陈明泉   no message
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
  #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