21 #if defined(WIN32) || defined (CF_MXE_CROSS_COMPILE)
46 filespec = malloc(strlen(dir)+2+1);
47 strcpy(filespec, dir);
48 index = strlen(filespec)-1;
50 filespec[
index] =
'\0';
51 strcat(filespec,
"/*");
53 dp = (DIR *)malloc(
sizeof(DIR));
56 dp->dir = strdup(dir);
58 if ((
handle = _findfirst(filespec, &(dp->fileinfo))) < 0) {
78 struct dirent *
readdir(DIR *dp) {
79 if (!dp || dp->finished)
82 if (dp->offset != 0) {
83 if (_findnext(dp->handle, &(dp->fileinfo)) < 0) {
93 strncpy(dp->dent.d_name, dp->fileinfo.name, _MAX_FNAME);
94 dp->dent.d_name[_MAX_FNAME] =
'\0';
97 dp->dent.d_reclen = strlen(dp->dent.d_name)+
sizeof(char)+
sizeof(dp->dent.d_ino)+
sizeof(dp->dent.d_reclen)+
sizeof(dp->dent.d_off);
98 dp->dent.d_off = dp->offset;
114 _findclose(dp->handle);
133 dir_Info->handle = 0;
134 dir_Info->offset = 0;
135 dir_Info->finished = 0;
137 filespec = malloc(strlen(dir_Info->dir)+2+1);
138 strcpy(filespec, dir_Info->dir);
139 index = strlen(filespec)-1;
141 filespec[
index] =
'\0';
142 strcat(filespec,
"/*");
144 if ((
handle = _findfirst(filespec, &(dir_Info->fileinfo))) < 0) {
145 if (errno == ENOENT) {
146 dir_Info->finished = 1;
149 dir_Info->handle =
handle;
163 SERVICE_STATUS m_ServiceStatus;
165 SERVICE_STATUS_HANDLE m_ServiceStatusHandle;
167 #define SERVICE_NAME L"Crossfire"
169 #define SERVICE_DISPLAY L"Crossfire server"
171 #define SERVICE_DESCRIPTION L"Crossfire is a multiplayer online RPG game."
180 TCHAR strDir[MAX_PATH];
181 SC_HANDLE schSCManager;
182 SC_HANDLE schService;
183 wchar_t *strDescription = SERVICE_DESCRIPTION;
185 GetModuleFileName(NULL, strDir, MAX_PATH);
186 wcscat(strDir, L
" -srv");
188 schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
190 if (schSCManager == NULL) {
191 printf(
"openscmanager failed");
195 schService = CreateService(schSCManager,
199 SERVICE_WIN32_OWN_PROCESS,
200 SERVICE_DEMAND_START,
201 SERVICE_ERROR_NORMAL,
209 if (schService == NULL) {
210 printf(
"createservice failed");
214 ChangeServiceConfig2(schService, SERVICE_CONFIG_DESCRIPTION, &strDescription);
216 CloseServiceHandle(schService);
217 CloseServiceHandle(schSCManager);
226 SC_HANDLE schSCManager;
229 schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
231 if (schSCManager == NULL) {
232 printf(
"open failed");
236 hService = OpenService(schSCManager, SERVICE_NAME, SERVICE_ALL_ACCESS);
238 if (hService == NULL) {
239 printf(
"openservice failed");
243 if (DeleteService(hService) == 0) {
244 printf(
"Delete failed");
248 if (CloseServiceHandle(hService) == 0) {
249 printf(
"close failed");
253 if (!CloseServiceHandle(schSCManager)) {
254 printf(
"close schSCManager failed");
267 void WINAPI ServiceCtrlHandler(DWORD Opcode) {
269 case SERVICE_CONTROL_PAUSE:
270 m_ServiceStatus.dwCurrentState = SERVICE_PAUSED;
273 case SERVICE_CONTROL_CONTINUE:
274 m_ServiceStatus.dwCurrentState = SERVICE_RUNNING;
277 case SERVICE_CONTROL_STOP:
278 m_ServiceStatus.dwWin32ExitCode = 0;
279 m_ServiceStatus.dwCurrentState = SERVICE_STOPPED;
280 m_ServiceStatus.dwCheckPoint = 0;
281 m_ServiceStatus.dwWaitHint = 0;
283 SetServiceStatus(m_ServiceStatusHandle, &m_ServiceStatus);
291 case SERVICE_CONTROL_INTERROGATE:
297 extern int main(
int argc,
char **argv);
306 void WINAPI ServiceMain(DWORD argc, LPTSTR *argv) {
310 GetModuleFileName(NULL, strDir, 1024);
311 strSlash = wcschr(strDir,
'\\');
316 m_ServiceStatus.dwServiceType = SERVICE_WIN32;
317 m_ServiceStatus.dwCurrentState = SERVICE_START_PENDING;
318 m_ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
319 m_ServiceStatus.dwWin32ExitCode = 0;
320 m_ServiceStatus.dwServiceSpecificExitCode = 0;
321 m_ServiceStatus.dwCheckPoint = 0;
322 m_ServiceStatus.dwWaitHint = 0;
324 m_ServiceStatusHandle = RegisterServiceCtrlHandler(SERVICE_NAME, ServiceCtrlHandler);
325 if (m_ServiceStatusHandle == (SERVICE_STATUS_HANDLE)0) {
329 m_ServiceStatus.dwCurrentState = SERVICE_RUNNING;
330 m_ServiceStatus.dwCheckPoint = 0;
331 m_ServiceStatus.dwWaitHint = 0;
332 SetServiceStatus(m_ServiceStatusHandle, &m_ServiceStatus);
344 SERVICE_TABLE_ENTRY DispatchTable[] = {
345 { SERVICE_NAME, ServiceMain },
348 StartServiceCtrlDispatcher(DispatchTable);