-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXC11Sys.cpp
More file actions
139 lines (120 loc) · 2.46 KB
/
XC11Sys.cpp
File metadata and controls
139 lines (120 loc) · 2.46 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**************************************************************************
/* FileName: XWinSys.cpp
/* FileDesc:
/* FileAuthor: YangCao
/* CreateTime: 2014/10/14 20:30:22
/* CopyRight: yc
/*************************************************************************/
#include "XSys.h"
#include<thread>
#include <mutex>
#include<stdio.h>
#ifdef _WIN32
#include<io.h>
#else
#include<unistd.h>
#endif
using namespace std;
#ifndef _UNITY_OWLGAME_
#include "cocos2d.h"
using namespace cocos2d;
//using namespace cocos2d::extension;
#endif
class XC11Mutex : public XMutex
{
public:
XC11Mutex():mtx(){}
virtual void Lock(){mtx.lock();}
virtual bool TryLook(){return mtx.try_lock();}
virtual void Unlock(){mtx.unlock();}
protected:
std::mutex mtx;
};
namespace XSys
{
XThreadPool* XCreateThreadPool(int thread_count){return NULL;}
void XReleaseThreadPool(XThreadPool*){}
bool XDeleteFile(const char* path){return true;}
bool XDeleteDirectory(const char* path, bool bIsSubDelAll)
{
#ifndef _UNITY_OWLGAME_
return FileUtils::getInstance()->removeDirectory(path);
#else
return false;
#endif
}
void XLogOutput(const char* log)
{
#ifndef _UNITY_OWLGAME_
CCLog(log);
#else
#endif
}
XMutex* XCreateMutex()
{
return (new XC11Mutex());
}
bool XCreateFile(const char* file_path)
{
FILE* fp = fopen(file_path, "wb");
if(fp)
{
fclose(fp);
return true;
}
return false;
}
bool XCreateDirectory(const char* path)
{
#ifndef _UNITY_OWLGAME_
//return (TRUE == CreateDirectoryA(path, NULL));
return FileUtils::getInstance()->createDirectory(path);
#else
return false;//ÏȽûÓÃ
#endif
}
bool XIsFileExist(const char* file_path)
{
#ifndef _UNITY_OWLGAME_
return FileUtils::getInstance()->isFileExist(file_path);//( (_access( file_path , 0 )) != -1 );
#else
return ( (_access( file_path , 0 )) != -1 );
#endif
}
bool XIsDirectory(const char* path)
{
return false;
}
bool XSetFileSize(FILE* fp, long size)
{
#ifdef _WIN32
bool bRet = (0 == _chsize(XFileNo(fp), size));
#else
bool bRet = (0 == ftruncate(XFileNo(fp), size));
#endif // _WIN32
return bRet;
}
bool XSetFileSize(const char* path, long size)
{
if (!XIsFileExist(path))
{
return false;
}
FILE* fp = fopen(path, "wb");
if (!fp)
{
return false;
}
bool bRet = XSetFileSize(fp, size);
fclose(fp);
return bRet;
}
int XFileNo(FILE* fp)
{
#ifdef _WIN32
return _fileno(fp);
#else
return fileno(fp);
#endif
}
}