-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToyDef.cpp
54 lines (45 loc) · 1.31 KB
/
ToyDef.cpp
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
#include "ToyDef.h"
QDir DirectoryOf(const QString &subdir) {
static map<QString,QDir> ma;
static QDir dir(QApplication::applicationDirPath());
if (ma.count(subdir)){
return ma[subdir];
}
#if defined(Q_OS_WIN)
if (dir.dirName().toLower() == "debug"
|| dir.dirName().toLower() == "release"
|| dir.dirName().toLower() == "bin")
dir.cdUp();
#elif defined(Q_OS_MAC)
if (dir.dirName() == "MacOS"){
dir.cdUp();
dir.cdUp();
dir.cdUp();
}
#endif
dir.cd(subdir);
ma[subdir] = dir;
return dir;
}
QString GetFileDir(QString file){
#if !defined(WIN32)
file = file.replace("\\","//");
#endif
return DirectoryOf("").absoluteFilePath(file);
}
string GetStdFileDir(string file){
return GetFileDir(QString::fromStdString(file)).toStdString();
}
SicilyToy::SicilyToy(){
timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(Play()));
timer -> start(1000);
}
void SicilyToy::Send(const string &mes,int life){
static QUdpSocket *sender = new QUdpSocket();
int len = mes.length();
char *cstr = new char[len + 1];
strncpy(cstr,mes.c_str(),len);
cstr[len] = char(life);
sender->writeDatagram(cstr,len + 1,UDPaddr,UDPport);
}