TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
ttkrunobject.cpp
Go to the documentation of this file.
1 #include "ttkrunobject.h"
2 #include "ttkversion.h"
3 #ifdef _WIN32
4 # define WIN32_LEAN_AND_MEAN
5 # include <qt_windows.h>
6 # include <shellapi.h>
7 #else
8 # include <unistd.h>
9 #endif
10 
11 namespace TTK
12 {
13 static bool endWith(const TTKString &value, const TTKString &tail)
14 {
15  if(value.empty() || tail.empty() || value.size() < tail.size())
16  {
17  return false;
18  }
19 
20  return value.compare(value.length() - tail.size(), tail.size(), tail) == 0;
21 }
22 }
23 
24 
25 void TTKRunObject::run(int argc, char **argv) const
26 {
27  TTKString args;
28  for(int i = 0; i < argc; ++i)
29  {
30  TTKString arg(argv[i]);
32  {
33  const size_t pos = arg.find('\"');
34  if(pos != TTKString::npos)
35  {
36  arg.insert(arg.begin() + pos, '\\');
37  }
38 
39  args.append(TTK_STR_QUOTES(arg));
40  args.append(" ");
41  }
42  }
43 
44  char path[TTK_LOW_BUFFER] = {};
46 #ifdef _WIN32
47  GetModuleFileNameA(nullptr, path, TTK_LOW_BUFFER);
48 
49  TTKString filePath = path;
50  const size_t pos = filePath.find_last_of('\\');
51  if(pos != TTKString::npos)
52  {
53  filePath.erase(pos);
54  }
55 
56  ShellExecuteA(nullptr, "open", (filePath + suffix).c_str(), args.c_str(), nullptr, SW_HIDE);
57 #else
58  TTKString filePath = get_current_dir_name();
59  if(readlink("/proc/self/exe", path, sizeof(path) - 1) != 0)
60  {
61  filePath = path;
62  const size_t pos = filePath.find_last_of('/');
63  if(pos != TTKString::npos)
64  {
65  filePath.erase(pos);
66  }
67  }
68 
69  system((filePath + suffix + " " + args).c_str());
70 #endif
71 }
void run(int argc, char **argv) const
std::string TTKString
Definition: ttkglobal.h:121
TTK_MODULE_EXPORT QString suffix(const QString &name)
The namespace of the process utils.
Definition: ttkcompat.h:24
#define TTK_SEPARATOR
Definition: ttkglobal.h:195
#define TTK_LOW_BUFFER
Definition: ttkglobal.h:259
#define TTK_APP_FILE_NAME
Definition: ttkobject.h:33
#define TTK_VERSION_STR
Definition: ttkversion.h:171
#define TTK_STR_CAT(...)
Definition: ttkglobal.h:167
#define TTK_SERVICE_RUN_NAME
Definition: ttkobject.h:35
#define TTK_STR_QUOTES(s)
Definition: ttkglobal.h:178
static bool endWith(const TTKString &value, const TTKString &tail)