int FMGUI_FileExists(const char *path) { #ifdef _WIN32 if (GetFileAttributes(path) == INVALID_FILE_ATTRIBUTES) { if (GetLastError() == ERROR_FILE_NOT_FOUND || GetLastError() == ERROR_PATH_NOT_FOUND) { return (0); } else { ReportError2("%s: Failed to determine existence of file (%lu)", path, (Ulong)GetLastError()); return (-1); } } else { return (1); } #else struct stat sb; if (stat(path, &sb) == -1) { if (errno != ENOENT) { ReportError2("%s: Failed to determine existence of file (%s)", path, strerror(errno)); return (-1); } return (0); } else { return (1); } #endif /* _WIN32 */ }
MUS_MESSAGE SoundPipe::Open(const char *cstrFileName) { SDL_LockAudio(); m_msgPipeInStatus = MUS_STATUS_WAITING_FOR_SONG; m_msgPipeOutStatus = MUS_STATUS_WAITING_FOR_SONG; SDL_UnlockAudio(); MusMessage err = m_FFmpegDecoder.Open(cstrFileName); ReportError1("Opening %s", cstrFileName); if (err == MUS_MOD_Error) { m_msgPipeInStatus = MUS_STATUS_ERROR; m_msgPipeOutStatus = MUS_STATUS_ERROR; m_cstrCurSongPath[0] = 0; return MUS_STATUS_ERROR; } strcpy(m_cstrCurSongPath, cstrFileName); m_fSampleRate = m_FFmpegDecoder.GetSampleRate(); if (m_fSampleRate == 0) m_fSampleRate = 44100; m_cbBuf.Start(m_fSampleRate); m_dResampConvFactor = DEST_FREQ/m_fSampleRate; float fCurSpeed = m_rfResample.GetSpeed(); ReportError2("fCurSpeed=%f, resampconv=%f", fCurSpeed, m_dResampConvFactor); fCurSpeed *= m_dResampConvFactor; m_rfResample.SetFilterRate(fCurSpeed); if (fCurSpeed == 1.0) m_bUseResampFilt = 0; else m_bUseResampFilt = 1; m_lSongEndInSec = m_FFmpegDecoder.GetDuration(); if (m_lSongEndInSec == 0) m_lSongEndInSec = UINT_MAX; m_BPMDetect.Init(); memset(m_iTicks, 0, BPM_TICK_HIST); m_iCurrentTick = 0; // Create message to start song m_msgPipeInStatus = MUS_STATUS_INITIAL_BUFFERING; m_msgPipeOutStatus = MUS_STATUS_PLAYING; //ReportError("Made it through Pipe Open Routine"); return MUS_STATUS_INITIAL_BUFFERING; }
FMGUI_Dir * FMGUI_OpenDir(const char *path) { FMGUI_Dir *dir; dir = (FMGUI_Dir *) Malloc(sizeof(FMGUI_Dir)); dir->ents = NULL; dir->nents = 0; #ifdef _WIN32 { char dpath[FMGUI_PATHNAME_MAX]; HANDLE h; WIN32_FIND_DATA fdata; DWORD rv; Strlcpy(dpath, path, sizeof(dpath)); Strlcat(dpath, "\\*", sizeof(dpath)); if ((h = FindFirstFile(dpath, &fdata))==INVALID_HANDLE_VALUE) { ReportError1("Invalid file handle (%d)", (int)GetLastError()); goto fail; } while (FindNextFile(h, &fdata) != 0) { dir->ents = Realloc(dir->ents, (dir->nents+1)*sizeof(char *)); dir->ents[dir->nents++] = Strdup(fdata.cFileName); } rv = GetLastError(); FindClose(h); if (rv != ERROR_NO_MORE_FILES) { ReportError1("FindNextFileError (%lu)", rv); goto fail; } } #else /* !_WIN32 */ { DIR *dp; struct dirent *dent; if ((dp = opendir(path)) == NULL) { ReportError2("%s: Failed to open directory (%s)", path, strerror(errno)); goto fail; } while ((dent = readdir(dp)) != NULL) { dir->ents = (char **) Realloc(dir->ents, (dir->nents+1)*sizeof(char *)); dir->ents[dir->nents++] = strdup(dent->d_name); } closedir(dp); } #endif /* _WIN32 */ return (dir); fail: Free(dir); return (NULL); }
PDL_bool Open(PDL_JSParameters *parms) { const char *cstrPath = PDL_GetJSParamString(parms, 0); int32_t iTrack = PDL_GetJSParamInt(parms, 1); ReportError2("Open Message being created for %s, for track %i", cstrPath, iTrack); g_MusController.PassMessage(MUS_MESSAGE_OPEN_SONG, cstrPath, iTrack); return PDL_TRUE; }
int FMGUI_FileDelete(const char *path) { #ifdef _WIN32 if (DeleteFile(path) == 0) { ReportError2("%s: Failed to delete file (%lu)", path, (Ulong)GetLastError()); return (-1); } return (0); #else if (unlink(path) == -1) { ReportError2("%s: Failed to delete file (%s)", path, strerror(errno)); return (-1); } return (0); #endif }
int FMGUI_ChDir(const char *dir) { #ifdef _WIN32 if (SetCurrentDirectory(dir)) { return (0); } else { ReportError2("%s: Failed to change directory (%d)", dir, (int)GetLastError()); return (-1); } #else if (chdir(dir) == 0) { return (0); } else { ReportError2("%s: Failed to change directory (%s)", dir, strerror(errno)); return (-1); } #endif }
int FMGUI_RmDir(const char *dir) { #ifdef _WIN32 if (RemoveDirectory(dir)) { return (0); } else { ReportError2("%s: Failed to remove directory (%d)", dir, (int)GetLastError()); return (-1); } #else if (rmdir(dir) == 0) { return (0); } else { ReportError2("%s: Failed to remove directory (%s)", dir, strerror(errno)); return (-1); } #endif }
int FMGUI_MkDir(const char *dir) { #ifdef _WIN32 if (CreateDirectory(dir, NULL)) { return (0); } else { ReportError2("%s: Failed to create directory (%d)", dir, (int)GetLastError()); return (-1); } #else if (mkdir(dir, 0700) == 0) { return (0); } else { ReportError2("%s: Failed to create directory (%s)", dir, strerror(errno)); return (-1); } #endif }
//--------------------------------------------------------------------------- bool TcpServerCreate(void) { tcp_cons = new TList(); tcp = new MTCPServer(); if( tcp->GetError() ) { String err = String("Error tcp: ") + tcp->GetErrorMessageEng(); WriteToLogError(String("ERROR\t") + err); ReportError2(err); return false; } else return true; }
int FMGUI_GetFileInfo(const char *path, FMGUI_FileInfo *i) { struct stat sb; uid_t uid = geteuid(); gid_t gid = getegid(); if (stat(path, &sb) == -1) { ReportError2("%s: Failed to get information (%s)", path, strerror(errno)); return (-1); } i->type = FMGUI_FILE_REGULAR; i->flags = 0; i->perms = 0; if ((sb.st_mode & S_IFDIR)==S_IFDIR) { i->type = FMGUI_FILE_DIRECTORY; } else if ((sb.st_mode & S_IFLNK)==S_IFLNK) { i->type = FMGUI_FILE_SYMLINK; } else if ((sb.st_mode & S_IFIFO)==S_IFIFO) { i->type = FMGUI_FILE_FIFO; } else if ((sb.st_mode & S_IFSOCK)==S_IFSOCK) { i->type = FMGUI_FILE_SOCKET; } else if ((sb.st_mode & S_IFCHR)==S_IFCHR) { i->type = FMGUI_FILE_DEVICE; } else if ((sb.st_mode & S_IFBLK)==S_IFBLK) { i->type = FMGUI_FILE_DEVICE; } if ((sb.st_mode & S_ISUID) == S_ISUID) i->flags |= FMGUI_FILE_SUID; if ((sb.st_mode & S_ISGID) == S_ISGID) i->flags |= FMGUI_FILE_SGID; if (sb.st_uid == uid) { i->perms |= (sb.st_mode & S_IRUSR) ? FMGUI_FILE_READABLE : 0; i->perms |= (sb.st_mode & S_IWUSR) ? FMGUI_FILE_WRITEABLE : 0; i->perms |= (sb.st_mode & S_IXUSR) ? FMGUI_FILE_EXECUTABLE : 0; } else if (sb.st_gid == gid) { i->perms |= (sb.st_mode & S_IRGRP) ? FMGUI_FILE_READABLE : 0; i->perms |= (sb.st_mode & S_IWGRP) ? FMGUI_FILE_WRITEABLE : 0; i->perms |= (sb.st_mode & S_IXGRP) ? FMGUI_FILE_EXECUTABLE : 0; } else { i->perms |= (sb.st_mode & S_IROTH) ? FMGUI_FILE_READABLE : 0; i->perms |= (sb.st_mode & S_IWOTH) ? FMGUI_FILE_WRITEABLE : 0; i->perms |= (sb.st_mode & S_IXOTH) ? FMGUI_FILE_EXECUTABLE : 0; } return (0); }
void AddToIndex(const char *path, int32_t iLastMod) { const char *params[2]; params[0] = path; char cstrIndex[15]; sprintf(cstrIndex,"%i",iLastMod); params[1] = cstrIndex; #if USE_PDL PDL_Err mjErr = PDL_CallJS("AddToIndex", params, 2); if ( mjErr != PDL_NOERROR ) { ReportError1("error: %s\n", PDL_GetError()); } #endif ReportError2("Callback Val: %s : %s", params[0], params[1]); }
//--------------------------------------------------------------------------- void TcpServerStart(void) { if( ! MainCfg.TcpEnable ) { TcpPrintStatus(); return; } if( tcp->Open(MainCfg.TcpInterface.c_str(), MainCfg.TcpPort) ) { TcpPrintStatus(); } else { TcpPrintStatus(); String err = String("Error tcp: ") + tcp->GetErrorMessageEng() + " [tcp port " + IntToStr(MainCfg.TcpPort) + "]"; WriteToLogError(String("ERROR\t") + err); ReportError2(err); } }