const char *Pathname::GetExtensionFromPath(const char *path) { const char *fname = GetNameFromPath(path); char *c = strrchr(fname,'.'); if (c == NULL) c = strrchr(path,0); return c; }
CPlaylist::CPlaylist(LPCTSTR pszPath) : m_pszPath(NULL), m_pszName(NULL), m_pList(NULL), m_iCurrentTrack(-1), m_uCount(0), m_bCEPlaylist(false), m_bHidden(false), m_bTransient(false) { LPCTSTR pszName = NULL, pszExt = NULL; if (pszPath) { size_t BufLen = _tcslen(pszPath) + 1; m_pszPath = new TCHAR [BufLen]; if (m_pszPath) { StringCchCopy(m_pszPath, BufLen, pszPath); GetNameFromPath(m_pszPath, BufLen, &m_pszName); } } }
std::string FConfigVariableManager::GetConfigurationFileName() const { char FileNameBuffer[256]; GetModuleFileName(nullptr, FileNameBuffer, sizeof(FileNameBuffer)); std::string ConfigurationFileName = RemoveExtension(GetNameFromPath(FileNameBuffer)); return ConfigurationFileName + ".ini"; }
bool LoadTexture(const char* file_name, char* out_name) { CGLImageData ImageData; if (ImageData.LoadTexture(file_name)) { Texture* texture = new Texture; if(!out_name) { // take texture name from path // e.g. from 'textures/sky.bmp' will be 'sky' char* part = GetNameFromPath(file_name); if(!part) { sLog(DEFAULT_LOG_NAME, LOG_WARNING_EV, "Failed to get name from texture path"); return false; } texture->name = part; } else { texture->name = new char[strlen(out_name) + 1]; memset(texture->name, '\0', strlen(out_name) + 1); strcpy(texture->name, out_name); } texture->width = ImageData.width; texture->height = ImageData.height; texture->tex = ImageData.GetTexID(); texture_count++; textures = (Texture*)realloc(textures, texture_count * sizeof(Texture)); memcpy(&textures[texture_count - 1], texture, sizeof(Texture)); delete texture; return true; } return false; }
DWORD GetNameHash( WCHAR *Path ) { if ( !Path ) { return 0; } WCHAR *Name = GetNameFromPath( Path ); if ( !Name ) { return 0; } m_wcslwr( Name ); DWORD dwHash = CalcHashW( Name ); return dwHash; }
bool copyEntities() { file_copy(root+"routines/animation.inc", mokoi::path + "/scripts/routines/animation.inc"); file_copy(root+"routines/counter.inc", mokoi::path + "/scripts/routines/counter.inc"); file_copy(root+"routines/enhanced.inc", mokoi::path + "/scripts/routines/enhanced.inc"); file_copy(root+"routines/entity.inc", mokoi::path + "/scripts/routines/entity.inc"); file_copy(root+"routines/general.inc", mokoi::path + "/scripts/routines/general.inc"); file_copy(root+"routines/game_default.inc", mokoi::path + "/scripts/routines/game_default.inc"); if ( oz::hasEntities() ) { std::string name; while ( oz::nextEntities(name) ) { std::string file_path = GetNameFromPath(name); elix::string::Replace( file_path, ".zes", ".mps" ); std::cout << "mokoi::save: Coping " << name << std::endl; file_copy( name, mokoi::path + "/scripts/" + file_path ); } } }
int OpenImage (int nFlags, LONG lParam) { FARPROC lpfnOpenDlg; int hInFile = 0; int nError = EC_ERROR; int nFileType; OFSTRUCT Of; ATOM Atom; WORD wBytes; int hTempFile; int nErr = FALSE; /* First get szOpenFileName filled in */ switch (nFlags) { case SCAN_OPEN: CleanFiles (); Atom = (ATOM) LOWORD (lParam); wBytes = GlobalGetAtomName (Atom, szOpenFileName, 128); GlobalDeleteAtom (Atom); GetNameFromPath ((LPSTR) szImageName, (LPSTR) szOpenFileName); bIsCurrTemp = FALSE; bImageModified = FALSE; break; case USER_OPEN: // CleanFiles (); BUG HERE???? lpfnOpenDlg = MakeProcInstance ((FARPROC)OpenDlgProc, hInstIP); hInFile = DialogBox (hInstIP, "FILEDLG", hWndIP, lpfnOpenDlg); FreeProcInstance (lpfnOpenDlg); if (hInFile) { CleanFiles (); // Put here instead of before call to dialog _lclose (hInFile); // Kludge.. /* Always get image name from path. Optionally also update the szOpenDir */ GetNameFromPath ((LPSTR) szImageName, (LPSTR) szOpenFileName); if (szOpenFileName [1] == ':') // Look for A: or B:, if neither, remember open drive/directory { if (! (szOpenFileName [0] == 'A' || szOpenFileName[0] == 'B' || szOpenFileName[0] == 'a' || szOpenFileName[0] == 'b')) { SeparateFile ((LPSTR) szOpenDir, (LPSTR) szImageName, (LPSTR)szOpenFileName); _fstrcpy ((LPSTR) szSaveDir, (LPSTR) szOpenDir); } } bIsCurrTemp = FALSE; } else nErr = USER_ABANDON; bImageModified = FALSE; break; case COMMAND_LINE_OPEN: CleanFiles (); _fstrcpy ((LPSTR)szOpenFileName, (LPSTR) lParam); GetNameFromPath ((LPSTR) szImageName, (LPSTR) szOpenFileName); bIsCurrTemp = FALSE; bImageModified = FALSE; break; case TOOLS_OPEN: _fstrcpy ((LPSTR)szOpenFileName, (LPSTR) lParam); bIsCurrTemp = TRUE; break; case OIC_OPEN: case AUTO_CONVERT_OPEN: _fstrcpy ((LPSTR)szOpenFileName, (LPSTR) lParam); bIsCurrTemp = TRUE; bImageModified = FALSE; break; case CLIPBOARD_OPEN: CleanFiles (); Atom = (ATOM) LOWORD (lParam); wBytes = GlobalGetAtomName (Atom, szOpenFileName, 128); GlobalDeleteAtom (Atom); _fstrcpy ((LPSTR) szImageName, (LPSTR) "Untitled"); bIsCurrTemp = TRUE; bImageModified = FALSE; break; case GENERIC_OPEN: case UNDO_OPEN: _fstrcpy ((LPSTR)szOpenFileName, (LPSTR) lParam); break; } if (nErr != 0) return (nErr); hInFile = OpenFile ((LPSTR)szOpenFileName, (LPOFSTRUCT)&Of, OF_READWRITE); if (hInFile <= 0) { if (hInFile == 0) hInFile = IDCANCEL; nError = hInFile; return (nError); } /* Identify and Import File */ if (image_active) { _fstrcpy ((LPSTR) szTempPath, (LPSTR) szOpenFileName); // Store it somewhere SendMessage (hWndDisplay, WM_CLOSE, 0, 0); // Close that baby down! if (nFlags == USER_OPEN) // So we don't re-display dialog nFlags = COMMAND_LINE_OPEN; else if (nFlags == CLIPBOARD_OPEN) nFlags = GENERIC_OPEN; _lclose (hInFile); PostMessage (hWndIP, WM_SHOWIMAGE, nFlags, (LONG) (LPSTR) szTempPath); // Re-prime the pump return (0); } _fstrcpy ((LPSTR) szCurrFileName, (LPSTR) szOpenFileName); // For having UNDO cap. 5/91 _llseek (hInFile, 0L, 0); nFileType = IdentFormat (hInFile, (LPSTR) szOpenFileName); if (nFileType < 0) { /* File type unknown */ _lclose (hInFile); hImportFile = 0; return (nFileType); } switch (nFileType) { case IDFMT_CCPI: { char Buffer [128]; GetTempFileName (0, (LPSTR) "OIC", 0, (LPSTR) Buffer); #ifndef DECIPHER /* If file type is compressed cpi, decompress first, then re-open */ hTempFile = DecompressCPI (hInFile ,(LPSTR) Buffer); if (hTempFile > 0) { _lclose (hInFile); return (OpenImage (OIC_OPEN, (LONG) (LPSTR) Buffer)); } else return (hTempFile); } #else return (EC_UFILETYPE); #endif break; case IDFMT_WMF: { char Buffer [128]; WORD Retval; wUserImportType = (WORD) nFileType; GetTempFileName (0, (LPSTR) "WMF", 0, (LPSTR) Buffer); Retval = wmfImportMetaFile (hWndIP, hInFile, (LPSTR) Buffer); if (Retval == 0) { _lclose (hInFile); return (OpenImage (OIC_OPEN, (LONG) (LPSTR) Buffer)); } else return (USER_ABANDON); } break; case IDFMT_CPI: break; default: if (bDoDisplay) // If we are going to actually display the thing, we may need to do some stuff first.. if (bAutoConvert) { /* Now if opened image is not CPI, save as CPI and re-open as CPI */ if (wImportType != IDFMT_CPI) if (bAutoConvert) { wUserImportType = (WORD) nFileType; hImportFile = hInFile; SetState (IMPORT_TYPE, nFileType); nError = ImportFile(); if (nError != 0) return (nError); else return (DoSave (SAVE_TO_CPI)); } } break; } hImportFile = hInFile; SetState (IMPORT_TYPE, nFileType); if (! wUserImportType) wUserImportType = wImportType; nError = ImportFile(); if (nError >= 0) if (! bDoDisplay) PostMessage (hWndIP, WM_COMMAND, IDM_SAVE, 0L); return (nError); }
int main( int argc, char **argv ) { //版本查询 if(1 < argc && !strcasecmp(argv[1], "-v" )) { printf("%s Epoll Server Ver: 3.0.9 build in %s %s\n\n",SVR_NAME, __DATE__, __TIME__); printf("--------------[log]-----------------\n"); printf("[2014-02-08] v3.0.9 [f] aux thread close socket when it does not monitor the socket\n"); printf("[2013-04-03] v3.0.8 [a]patxiao frequency log\n"); printf("[2013-03-15] v3.0.7 [a]patxiao support close port link\n"); printf("[2012-11-06] add level log\n"); printf("[2012-11-06] add error msg for exeption close link\n"); printf("[2012-04-10] support uniqueID for mq file: key={proj_id+FF+uniqueID}\n"); printf("[2011-09-01] support ip table access/deny\n"); printf("[2011-07-20] support admin so\n"); printf("[2011-05-11] if setrlimit failed, exit!\n"); printf("[2011-03-16] add mutil thread, mutil cq ,mutil port.\n"); printf("[2010-11-30] delete tcp nagle to solve 'the last pkg slow' problem.\n"); exit(0); } if(argc < 2) { printf("%s [config]\n", argv[0]); printf("%s [config] -d\n", argv[0]); printf("%s -v\n", argv[0]); exit(0); } //进程互斥锁 int lock_fd = open(argv[1], O_RDWR|O_CREAT, 0640); if(lock_fd < 0 ) { printf("Open Lock File Failed,Server Init Failed!\n"); return -1; } int ret = flock(lock_fd, LOCK_EX | LOCK_NB); if(ret < 0 ) { printf("Lock File Failed,Server is already Running!\n"); return -1; } //后台 if((argc>=3) && (0 == strcasecmp(argv[2], "-d"))) { ; } else { InitDaemon(); } //自定义信号 signal(SIGUSR1, sigusr1_handle); signal(SIGUSR2, sigusr2_handle); char szProcName[128]; GetNameFromPath(argv[0],szProcName); char szTmp[128]; sprintf(szTmp,"../log/%s",szProcName); TLib_Log_LogInit(szTmp, 0x10000000, 5); TLib_Log_LogMsg("===== %s begin Start... =====\n",SVR_NAME); g_pMainCtrl = new CMainCtrl(); ret = g_pMainCtrl->Initialize(szProcName,argv[1]); if( 0 != ret ) { exit(0); } TLib_Log_LogMsg("===== %s Started. =====\n",SVR_NAME); g_pMainCtrl->Run(); return 0; }