void CreateOrientationFolders(int parent_index) { int jj; int nGames = GetNumGames(); LPTREEFOLDER lpFolder = treeFolders[parent_index]; // create our two subfolders LPTREEFOLDER lpVert, lpHorz; lpVert = NewFolder("Vertical", next_folder_id++, parent_index, IDI_FOLDER, GetFolderFlags(numFolders)); AddFolder(lpVert); lpHorz = NewFolder("Horizontal", next_folder_id++, parent_index, IDI_FOLDER, GetFolderFlags(numFolders)); AddFolder(lpHorz); // no games in top level folder SetAllBits(lpFolder->m_lpGameBits,FALSE); for (jj = 0; jj < nGames; jj++) { if (drivers[jj]->flags & ORIENTATION_SWAP_XY) { AddGame(lpVert,jj); } else { AddGame(lpHorz,jj); } } }
void CreateSoundFolders(int parent_index) { int i,jj; int nGames = GetNumGames(); int nFolder = numFolders; LPTREEFOLDER lpFolder = treeFolders[parent_index]; LPTREEFOLDER map[SOUND_COUNT]; // no games in top level folder SetAllBits(lpFolder->m_lpGameBits,FALSE); for (i=1;i<SOUND_COUNT;i++) { // Defined in sndintrf.c struct snd_interface { unsigned sound_num; /* ID */ const char *name; /* description */ int (*chips_num)(const struct MachineSound *msound); /* returns number of chips if applicable */ int (*chips_clock)(const struct MachineSound *msound); /* returns chips clock if applicable */ int (*start)(const struct MachineSound *msound); /* starts sound emulation */ void (*stop)(void); /* stops sound emulation */ void (*update)(void); /* updates emulation once per frame if necessary */ void (*reset)(void); /* resets sound emulation */ }; extern struct snd_interface sndintf[]; LPTREEFOLDER lpTemp; for (jj = 1; jj < i; jj++) if (!strcmp(soundtype_name(i), soundtype_name(jj))) break; if (i != jj) { map[i] = map[jj]; continue; } lpTemp = NewFolder(sndintf[i].name, next_folder_id++, parent_index, IDI_CPU, GetFolderFlags(numFolders)); AddFolder(lpTemp); map[i] = treeFolders[nFolder++]; } for (jj = 0; jj < nGames; jj++) { int n; struct InternalMachineDriver drv; expand_machine_driver(drivers[jj]->drv,&drv); for (n = 0; n < MAX_SOUND; n++) if (drv.sound[n].sound_type != SOUND_DUMMY) { // sound type #'s are one-based AddGame(map[drv.sound[n].sound_type],jj); } } }
void CreateManufacturerFolders(int parent_index) { int i,jj; int nGames = GetNumGames(); int start_folder = numFolders; LPTREEFOLDER lpFolder = treeFolders[parent_index]; // not sure why this is added separately // should find out at some point. LPTREEFOLDER lpTemp; lpTemp = NewFolder("Romstar", next_folder_id++, parent_index, IDI_MANUFACTURER, GetFolderFlags(numFolders)); AddFolder(lpTemp); // no games in top level folder SetAllBits(lpFolder->m_lpGameBits,FALSE); for (jj = 0; jj < nGames; jj++) { const char *s = FixString(drivers[jj]->manufacturer); const char *s2 = LicenseManufacturer(drivers[jj]->manufacturer); if (s == NULL || s[0] == '\0') continue; // look for an extant manufacturer treefolder for this game for (i=numFolders-1;i>=start_folder;i--) { if (strncmp(treeFolders[i]->m_lpTitle,s,20) == 0 || (s2 != NULL && strncmp(treeFolders[i]->m_lpTitle,s2,20) == 0)) { AddGame(treeFolders[i],jj); break; } } if (i == start_folder-1) { // nope, it's a manufacturer we haven't seen before, make it. lpTemp = NewFolder(s, next_folder_id++, parent_index, IDI_MANUFACTURER, GetFolderFlags(numFolders)); AddFolder(lpTemp); AddGame(lpTemp,jj); } } }
void CreateYearFolders(int parent_index) { int i,jj; int nGames = GetNumGames(); int start_folder = numFolders; LPTREEFOLDER lpFolder = treeFolders[parent_index]; // no games in top level folder SetAllBits(lpFolder->m_lpGameBits,FALSE); for (jj = 0; jj < nGames; jj++) { char s[100]; strcpy(s,drivers[jj]->year); if (s[0] == '\0') continue; if (s[4] == '?') s[4] = '\0'; // look for an extant year treefolder for this game // (likely to be the previous one, so start at the end) for (i=numFolders-1;i>=start_folder;i--) { if (strncmp(treeFolders[i]->m_lpTitle,s,4) == 0) { AddGame(treeFolders[i],jj); break; } } if (i == start_folder-1) { // nope, it's a year we haven't seen before, make it. LPTREEFOLDER lpTemp; lpTemp = NewFolder(s, next_folder_id++, parent_index, IDI_YEAR, GetFolderFlags(numFolders)); AddFolder(lpTemp); AddGame(lpTemp,jj); } } }
void GameListModel::UpdateGame(const std::shared_ptr<const UICommon::GameFile>& game) { int index = FindGame(game->GetFilePath()); if (index < 0) { AddGame(game); } else { m_games[index] = game; emit dataChanged(createIndex(index, 0), createIndex(index + 1, columnCount(QModelIndex()))); } }
void CreateSourceFolders(int parent_index) { int i,jj; int nGames = GetNumGames(); int start_folder = numFolders; LPTREEFOLDER lpFolder = treeFolders[parent_index]; // no games in top level folder SetAllBits(lpFolder->m_lpGameBits,FALSE); for (jj = 0; jj < nGames; jj++) { const char *s = GetDriverFilename(jj); if (s == NULL || s[0] == '\0') continue; // look for an extant source treefolder for this game // (likely to be the previous one, so start at the end) for (i=numFolders-1;i>=start_folder;i--) { if (strcmp(treeFolders[i]->m_lpTitle,s) == 0) { AddGame(treeFolders[i],jj); break; } } if (i == start_folder-1) { // nope, it's a source file we haven't seen before, make it. LPTREEFOLDER lpTemp; lpTemp = NewFolder(s, next_folder_id++, parent_index, IDI_SOURCE, GetFolderFlags(numFolders)); AddFolder(lpTemp); AddGame(lpTemp,jj); } } }
void RemoveFromCustomFolder(LPTREEFOLDER lpFolder,int driver_index) { if ((lpFolder->m_dwFlags & F_CUSTOM) == 0) { MessageBox(GetMainWindow(),"Unable to remove game from non-custom folder", MAME32NAME,MB_OK | MB_ICONERROR); return; } if (TestBit(lpFolder->m_lpGameBits,driver_index) != 0) { RemoveGame(lpFolder,driver_index); if (TrySaveExtraFolder(lpFolder) == FALSE) AddGame(lpFolder,driver_index); // undo on error } }
void CreateCPUFolders(int parent_index) { int i,jj; int nGames = GetNumGames(); int nFolder = numFolders; LPTREEFOLDER lpFolder = treeFolders[parent_index]; LPTREEFOLDER map[CPU_COUNT]; // no games in top level folder SetAllBits(lpFolder->m_lpGameBits,FALSE); for (i=1;i<CPU_COUNT;i++) { LPTREEFOLDER lpTemp; for (jj = 1; jj < i; jj++) if (!strcmp(cputype_name(i), cputype_name(jj))) break; if (i != jj) { map[i] = map[jj]; continue; } lpTemp = NewFolder(cputype_name(i), next_folder_id++, parent_index, IDI_CPU, GetFolderFlags(numFolders)); AddFolder(lpTemp); map[i] = treeFolders[nFolder++]; } for (jj = 0; jj < nGames; jj++) { int n; struct InternalMachineDriver drv; expand_machine_driver(drivers[jj]->drv,&drv); for (n = 0; n < MAX_CPU; n++) if (drv.cpu[n].cpu_type != CPU_DUMMY) { // cpu type #'s are one-based AddGame(map[drv.cpu[n].cpu_type],jj); } } }
// Called to re-associate games with folders void ResetWhichGamesInFolders(void) { UINT i, jj, k; BOOL b; int nGames = GetNumGames(); for (i = 0; i < numFolders; i++) { LPTREEFOLDER lpFolder = treeFolders[i]; // setup the games in our built-in folders for (k = 0; g_lpFolderData[k].m_lpTitle; k++) { if (lpFolder->m_nFolderId == g_lpFolderData[k].m_nFolderId) { if (g_lpFolderData[k].m_pfnQuery || g_lpFolderData[k].m_bExpectedResult) { SetAllBits(lpFolder->m_lpGameBits, FALSE); for (jj = 0; jj < nGames; jj++) { // invoke the query function b = g_lpFolderData[k].m_pfnQuery ? g_lpFolderData[k].m_pfnQuery(jj) : TRUE; // if we expect FALSE, flip the result if (!g_lpFolderData[k].m_bExpectedResult) b = !b; // if we like what we hear, add the game if (b) AddGame(lpFolder, jj); } } break; } } } }
// Called to add child folders of the top level extra folders already created BOOL TryAddExtraFolderAndChildren(int parent_index) { FILE* fp = NULL; char fname[MAX_PATH]; char readbuf[256]; char* p; char* name; int id, current_id; LPTREEFOLDER lpTemp = NULL; LPTREEFOLDER lpFolder = treeFolders[parent_index]; current_id = lpFolder->m_nFolderId; id = lpFolder->m_nFolderId - MAX_FOLDERS; /* "folder\title.ini" */ sprintf( fname, "%s\\%s.ini", GetFolderDir(), ExtraFolderData[id]->m_szTitle); fp = fopen(fname, "r"); if (fp == NULL) return FALSE; while ( fgets(readbuf, 256, fp) ) { /* do we have [...] ? */ if (readbuf[0] == '[') { p = strchr(readbuf, ']'); if (p == NULL) { continue; } *p = '\0'; name = &readbuf[1]; /* is it [FOLDER_SETTINGS]? */ if (strcmp(name, "FOLDER_SETTINGS") == 0) { current_id = -1; continue; } else { /* it it [ROOT_FOLDER]? */ if (!strcmp(name, "ROOT_FOLDER")) { current_id = lpFolder->m_nFolderId; lpTemp = lpFolder; } else { /* must be [folder name] */ current_id = next_folder_id++; /* create a new folder with this name, and the flags for this folder as read from the registry */ lpTemp = NewFolder(name,current_id,parent_index, ExtraFolderData[id]->m_nSubIconId, GetFolderFlags(numFolders) | F_CUSTOM); AddFolder(lpTemp); } } } else if (current_id != -1) { /* string on a line by itself -- game name */ name = strtok(readbuf, " \t\r\n"); if (name == NULL) { current_id = -1; continue; } /* IMPORTANT: This assumes that all driver names are lowercase! */ _strlwr( name ); if (lpTemp == NULL) { ErrorMsg("Error parsing %s: missing [folder name] or [ROOT_FOLDER]", fname); current_id = lpFolder->m_nFolderId; lpTemp = lpFolder; } AddGame(lpTemp,GetGameNameIndex(name)); } } if ( fp ) { fclose( fp ); } return TRUE; }
void AbstractGameList::AddGames(QList<GameFile*> items) { for (GameFile* o : items) AddGame(o); }
int main( int pArgc, const char** pArgs ) { const char* lQueryPtr; int lLock; int lMemId; char lQuery[4096]; char lOp[12]; BOOL lPrintTitle; #ifndef _NO_IPC_ union semun lNULL; #endif #ifdef _NO_IPC_ gGlobalState.Clear(); if( InitLogFile() ) { fprintf( gLogFile, "IMR Init version 0.13.13b %s\n", GetTime( time(NULL)) ); } #endif #ifdef _FAST_CGI_ while( FCGI_Accept() >= 0 ) { #endif lPrintTitle = TRUE; /* Send the header required by the server */ printf("Content-type: text/plain%c%c", 10, 10); lQueryPtr = getenv( "QUERY_STRING" ); if( lQueryPtr == NULL ) { printf( "No parameters\n" ); } else { StrMaxCopy( lQuery, lQueryPtr, 4096 ); UnpadQuery( lQuery ); if( sscanf( lQuery, "=%11s", lOp ) == 1 ) { #ifndef _FAST_CGI_ /* Change the local directory */ char* lPathEnd = strrchr( pArgs[0], '/' ); if( lPathEnd != NULL ) { *lPathEnd = 0; chdir( pArgs[0] ); } #endif if( !strcmp( lOp, "RESET" ) ) { printf( "RESET OK\n\n" ); #ifdef _NO_IPC_ /* // gGlobalState.Clear(); // sleep( 2 ); // return 0; // break; */ #else lLock = semget( IR_SEM_KEY, 1, 0777 ); lMemId = shmget( IR_SHMEM_KEY, sizeof( IRState ), 0666 ); if( lLock != -1 ) { semctl( lLock, 0, IPC_RMID, lNULL ); } if( lMemId != -1 ) { shmctl( lMemId, IPC_RMID, NULL ); } #endif if( InitLogFile() ) { fprintf( gLogFile, "IMR Reset %s\n", GetTime( time(NULL)) ); } #ifdef _FAST_CGI_ break; #endif } else if( !strcmp( lOp, "SET_MESSAGE" ) ) { } /* else if( !strcmp( lOp, "STICK" ) ) { // Fork and leave a child running for 1 hour int lCode = fork(); if( lCode == 0 ) { if( InitLogFile() ) { fprintf( gLogFile, "STICK Start %s\n", GetTime( time(NULL)) ); CloseLogFile(); } close( 0 ); close( 1 ); close( 2 ); sleep( 3600 ); if( InitLogFile() ) { fprintf( gLogFile, "STICK End %s\n", GetTime( time(NULL)) ); CloseLogFile(); } } else if( lCode == -1 ) { printf( "ERROR\n" ); } else { printf( "SUCCESS\n" ); } } */ else { IRState* lState = NULL; #ifdef _NO_IPC_ lState = &gGlobalState; #else int lLock; /* Semaphore */ int lMemId; /* Shared memory */ struct sembuf lSemOp; lSemOp.sem_flg = 0; /*Avoid corruption but must not core-dump SEM_UNDO; // Risky but prevents dead-lock */ lSemOp.sem_num = 0; /* First try to create the structure for the first time */ /* Lock the data struct */ lLock = semget( IR_SEM_KEY, 1, 0777|IPC_CREAT|IPC_EXCL ); if( lLock != -1 ) { union semun lArg; /* Initialize the newly created semaphore */ lArg.val = 1; semctl( lLock, 0, SETVAL, lArg ); } else { lLock = semget( IR_SEM_KEY, 1, 0777 ); } if( lLock == -1 ) { printf( "Unable to get semaphore\n" ); } else { lSemOp.sem_op = -1; if( semop( lLock, &lSemOp, 1 ) == -1 ) { printf( "Unable to decrement semaphore\n" ); lLock = -1; } else { /* From here we can work safely */ lMemId = shmget( IR_SHMEM_KEY, sizeof( IRState ), 0666|IPC_CREAT|IPC_EXCL ); if( lMemId != -1 ) { lState = (IRState*)shmat( lMemId, NULL, 0 ); if( (int)lState == -1 ) { lState = NULL; } if( lState == NULL ) { printf( "Unable to attach shmem\n" ); } else { Clear( lState ); if( InitLogFile() ) { fprintf( gLogFile, "IMR Init %s\n", GetTime( time(NULL)) ); } } } else { lMemId = shmget( IR_SHMEM_KEY, sizeof( IRState ), 0666 ); if( lMemId == -1 ) { printf( "Unable to get shmem\n" ); } else { lState = (IRState*)shmat( lMemId, NULL, 0 ); if( (int)lState == -1 ) { lState = NULL; } if( lState == NULL ) { printf( "Unable to attach shmem\n" ); } } } } } #endif if( lState != NULL ) { lPrintTitle = FALSE; VerifyExpirations( lState ); if( !strcmp( lOp, "REFRESH" ) ) { int lUserIndex; int lUserId; int lTimeStamp; if( sscanf( lQuery, "%*s %d-%u %d", &lUserIndex, &lUserId, &lTimeStamp )==3 ) { PrintStateChange( lState, lUserIndex, lUserId, lTimeStamp ); } } else if( !strcmp( lOp, "ADD_CHAT" ) ) { int lUserIndex; int lUserId; char lChatMessage[200]; if( sscanf( lQuery, "%*s %d-%u %200s", &lUserIndex, &lUserId, lChatMessage )==3 ) { Unpad( lChatMessage ); AddChatMessage( lState, lUserIndex, lUserId, lChatMessage ); } } /* URL?=ADD_USER MAJOR-MINORID VERSION KEY2 KEY3 ALIAS */ else if( !strcmp( lOp, "ADD_USER" ) ) { int lMajorID; int lMinorID; int lVersion; unsigned int lKey2; unsigned int lKey3; char lUserName[40]; #ifdef _EXPIRED_ AddUser( lState, "User", 1,-1, -1, 0, 0 ); #else if( sscanf( lQuery, "%*s %d-%d %d %d %d %40s", &lMajorID, &lMinorID, &lVersion, &lKey2, &lKey3, lUserName )==6 ) { Unpad( lUserName ); AddUser( lState, lUserName, lVersion,lMajorID, lMinorID, lKey2, lKey3 ); } #endif } /* URL?=ADD_GAME USER_ID GAME_NAME TRACK_NAME NBLAP WEAPON PORT */ else if( !strcmp( lOp, "ADD_GAME" ) ) { int lUserIndex; int lUserId; int lNbLap; char lGameName[40]; char lTrackName[40]; int lWeapon; unsigned lPort; if( sscanf( lQuery, "%*s %d-%u %40s %40s %d %d %u", &lUserIndex, &lUserId, lGameName, lTrackName, &lNbLap, &lWeapon, &lPort )==7 ) { const char* lRemoteAddr = getenv( "REMOTE_ADDR" ); if( (lRemoteAddr != NULL)&&(strlen(lRemoteAddr) != 0) ) { Unpad( lTrackName ); Unpad( lGameName ); AddGame( lState, lGameName, lTrackName, lNbLap, lUserIndex, lUserId, lRemoteAddr, lPort, lWeapon ); } } } else if( !strcmp( lOp, "JOIN_GAME" ) ) { int lUserIndex; int lUserId; int lGameIndex; int lGameId; if( sscanf( lQuery, "%*s %d-%u %d-%u", &lGameIndex, &lGameId, &lUserIndex, &lUserId )==4 ) { JoinGame( lState, lGameIndex, lGameId, lUserIndex, lUserId ); } } else if( !strcmp( lOp, "DEL_GAME" ) ) { int lUserIndex; int lUserId; int lGameIndex; int lGameId; if( sscanf( lQuery, "%*s %d-%u %d-%u", &lGameIndex, &lGameId, &lUserIndex, &lUserId )==4 ) { DeleteGame( lState, lGameIndex, lGameId, lUserIndex, lUserId ); } } else if( !strcmp( lOp, "LEAVE_GAME" ) ) { int lUserIndex; int lUserId; int lGameIndex; int lGameId; if( sscanf( lQuery, "%*s %d-%u %d-%u", &lGameIndex, &lGameId, &lUserIndex, &lUserId )==4 ) { LeaveGame( lState, lGameIndex, lGameId, lUserIndex, lUserId ); } } else if( !strcmp( lOp, "DEL_USER" ) ) { int lUserIndex; int lUserId; if( sscanf( lQuery, "%*s %d-%u", &lUserIndex, &lUserId )==2 ) { DeleteUser( lState, lUserIndex, lUserId ); } } else if( !strcmp( lOp, "START_GAME" ) ) { int lUserIndex; int lUserId; int lGameIndex; int lGameId; if( sscanf( lQuery, "%*s %d-%u %d-%u", &lGameIndex, &lGameId, &lUserIndex, &lUserId )==4 ) { StartGame( lState, lGameIndex, lGameId, lUserIndex, lUserId ); } } else { lPrintTitle = TRUE; } } #ifdef _NO_IPC_ lState = NULL; #else /* Release lock */ if( lLock != -1 ) { lSemOp.sem_op = 1; semop( lLock, &lSemOp, 1 ); /* Release memory */ if( lState != NULL ) { shmdt( (char*)lState ); } } #endif } } } CloseLogFile(); if( lPrintTitle ) { printf( "Internet Meeting Room (c)1996,97 GrokkSoft inc.\n" ); } #ifdef _FAST_CGI_ } #endif return 0; }