BOOL FileMisc::IsTempFile(LPCTSTR szFilename) { CString sFilename(szFilename); sFilename.MakeLower(); CString sTempFolder = GetTempFolder(); sTempFolder.MakeLower(); return (sFilename.Find(sTempFolder) == 0); }
/*! check that the given filename is legal and remove any illegal characters \param filename [in/out] the suggested file name \return false if filename is left unchanged, true otherwise */ bool UT_legalizeFileName(std::string &filename) { UT_UTF8String sFilename(filename); UT_UTF8String sTmp; bool bRet = false; UT_UTF8Stringbuf::UTF8Iterator iter = sFilename.getIterator (); if (iter.start()) { const char * pUTF = iter.current(); while (pUTF && *pUTF) { UT_UCS4Char c = UT_UTF8Stringbuf::charCode(pUTF); if(c < ' ') { bRet = true; } else { switch(c) { case ':': case '/': case '|': case '<': case '>': case '\\': case '^': case '=': case '?': case '\"': case '[': case ']': case ';': case '*': bRet = true; break; default: sTmp += c; } } pUTF = iter.advance (); // or ++iter; } } if(bRet) { sFilename = sTmp; filename = sFilename.utf8_str(); } return bRet; }
HRESULT CGifSmileyCtrl::LoadFromFileSized(BSTR bstrFileName,INT nWidth,INT nHeight) { m_strFilename = bstrFileName; if ( _gdiPlusFail ) return E_FAIL; UnloadImage(); ATL::CString sFilename(bstrFileName); ImageItem * foundImage=NULL; LISTIMAGES::iterator it=_listImages.begin(); while (it!=_listImages.end()) { if ((*it) && (*it)->IsEqual(sFilename,nHeight)) { foundImage=(*it); break; } ++it; } if (!foundImage) { foundImage=new ImageItem; _listImages.push_back(foundImage); } if (foundImage) { m_pGifImage=foundImage->LoadImageFromFile(sFilename,nWidth,nHeight); m_pDelays=foundImage->GetFrameDelays(); m_nFrameCount=foundImage->GetFrameCount(); m_nFrameSize=foundImage->GetFrameSize(); if (m_nFrameSize.Width==0 || m_nFrameSize.Height==0) { UnloadImage(); return E_FAIL; } SIZEL size; size.cx=m_nFrameSize.Width+2; size.cy=m_nFrameSize.Height; AtlPixelToHiMetric(&size,&m_sizeExtent); return S_OK; } return E_FAIL; }
void wxLIRCCSession::onDCCSendReq ( const char * nick, const char * addr, const char * filename, unsigned long size, irc_dcc_t dccid ) { wxArrayString data; wxString sNick( nick, wxConvUTF8 ); wxString sAddr( addr, wxConvUTF8 ); wxString sFilename( filename, wxConvUTF8 ); data.Add( sAddr ); data.Add( sFilename ); wxLIRCCSessionEvent sessionevent = wxLIRCCSessionEvent( wxLIRCC_EVT_THREAD_DCCSEND, wxLIRCC_ID_DCC_SEND_REQ, this ); sessionevent.SetOrigin( sNick ); // Who wants to send a file to you using DCCSEND. sessionevent.SetParams( data ); // The person's IP address in decimal-dot notation... // ...and the sent filename. sessionevent.SetExtraLong( size ); // The filename size. sessionevent.SetId( dccid ); // An ID associated with this request. Use it in calls to irc_dcc_accept() or irc_dcc_decline(). wxQueueEvent( wxLIRCCSessionManager::Get(), sessionevent.Clone() ); // The "DCC Send" event is triggered wants to send a file to you using DCC SEND. // As with chat, in respond you should call either irc_dcc_accept() to accept this request and receive the file, // or irc_dcc_decline() to decline this request. }
bool hkvPrefabAsset::GenerateThumbnail(const char* libraryPath, const char* assetPath, const char* thumbnailPath) { hkStringBuf sFilename(libraryPath); sFilename.pathAppend(assetPath); TiXmlDocument doc; if (!doc.LoadFile(sFilename.cString())) { return true; } if (doc.RootElement() == NULL) return true; // Proceed if any only if there is actually a thumbnail node TiXmlElement* pThumbnailNode = doc.RootElement()->FirstChildElement("thumbnail"); if (pThumbnailNode == NULL) return true; IVFileOutStream* pFile = VFileAccessManager::GetInstance()->Create(thumbnailPath); if (pFile == NULL) return true; int iSize = 0; pThumbnailNode->QueryIntAttribute("size", &iSize); // Convert base64 encoded data back to binary form char* imageData = new char[iSize]; hkXmlObjectReader::base64read(hkIstream(pThumbnailNode->GetText(), (int)strlen(pThumbnailNode->GetText())).getStreamReader(), imageData, iSize); // Write image to disk pFile->Write(imageData, iSize); pFile->Close(); delete[] imageData; return true; }
int CRemoteFileDialog::FindMatch(LPCTSTR szFilename) { CString sFilename(szFilename); sFilename.TrimLeft(); sFilename.TrimRight(); if (sFilename.IsEmpty()) { return -1; } int nMatch = -1; LVFINDINFO lvfi = { LVFI_STRING, szFilename, 0, { 0, 0 }, VK_DOWN }; do { nMatch = m_lcFiles.FindItem(&lvfi, nMatch); } while (nMatch != -1 && !(GetItemType(nMatch) == RFDT_FILE || FolderSelect())); return nMatch; }
void DirectoryStructure::setPattern( string sPattern ) { vsFileList.clear(); DIR *d; struct dirent *dir; d = opendir(sDirectory.c_str()); if (d) { while ((dir = readdir(d)) != NULL) { string sFilename( dir->d_name ); if( matchPattern( sPattern, sFilename) ) vsFileList.push_back( sFilename ); } closedir(d); } resetListIterator(); iFileCount = vsFileList.size(); }
void ParsePacket(Packet &Data) { // Only process if receiving PKT_USERINFO or the user is already logged in if ((Data.Header() == PKT_USERINFO) || (m_Username.length())) switch (Data.Header()) { case PKT_USERINFO: { AddLog(L"Received PKT_USERINFO from socket " + m_wsSocket + L"."); char Result = 0; std::wstring Username = Data.RemoveNTString(); std::wstring Password = Data.RemoveNTString(); for (int i = 0; i < USERS_COUNT; ++i) // Check if Username and Password matches if (MatchString(Username, Users[i].Username) && MatchString(Password, Users[i].Password, true)) { // If user already logged in then fail new login attempt if (Users[i].LoggedIn) break; Users[i].LoggedIn = true; m_Username = Users[i].Username; Result = 1; break; } Packet UserInfo(PKT_USERINFO); UserInfo.InsertByte(Result); UserInfo.SendPacket(m_Socket); AddLog(L"Sent PKT_USERINFO to " + m_wsSocket + L"."); int Index = FindIndex(m_Socket); if (Index >= 0) { SendMessage(lsClients, LB_DELETESTRING, (WPARAM)Index, 0); SendMessage(lsClients, LB_INSERTSTRING, (WPARAM)Index, (LPARAM)std::wstring(m_wsSocket + L" - " + m_Username).c_str()); } } break; case PKT_FILE: { // Read filename std::wstring wsFilename(Data.RemoveNTString()); std::string sFilename(wsFilename.begin(), wsFilename.end()); // Check if Filename is in Files list already File *CurrentFile = NULL; std::list<File *>::const_iterator FindFile = Files.begin(); while (FindFile != Files.end()) { std::string CheckFile = ((File *)*FindFile)->Filename(); if (CheckFile == sFilename) { CurrentFile = *FindFile; break; } ++FindFile; } // If file not found then create new file and add it to Files list if (!CurrentFile) { CurrentFile = new File(sFilename, (int)Data.RemoveDWORD()); Files.push_back(CurrentFile); } // Write to file CurrentFile->Write(Data.RawData()); // if completed writing then close file and delete file object if (CurrentFile->Complete()) { // Remove file from Files list and delete File object Files.erase(FindFile); delete CurrentFile; } } break; } };
//-------------------------------------------------------------------------------------- // entry function to initialize an image from a .DDS texture //-------------------------------------------------------------------------------------- INT32 ModelTexture::LoadImageMipSetFromFile(const WCHAR *pFilename, void *pluginManager) { CleanMipSet(); try { // get the ext and load image with amd compressonator image plugin char *fileExt; wstring ws(pFilename); string sFilename(ws.begin(), ws.end()); size_t dot = sFilename.find_last_of('.'); std::string temp; if (dot != std::string::npos) { temp = (sFilename.substr(dot + 1, sFilename.size() - dot)); std::transform(temp.begin(), temp.end(), temp.begin(), toupper); fileExt = (char*)temp.data(); } pMipSet = new MipSet(); if (pMipSet == NULL) { CleanMipSet(); if (m_CMIPS) { m_CMIPS->Print("Error loading file: Out of memory for MipSet data"); } return -1; } memset(pMipSet, 0, sizeof(MipSet)); if (m_CMIPS) { char fname[_MAX_FNAME]; getFileNameExt(sFilename.c_str(), fname, _MAX_FNAME); m_CMIPS->SetProgress(0); if (m_CMIPS->m_canceled) return -1; m_CMIPS->Print("Loading: %s", fname); } if (AMDLoadMIPSTextureImage(sFilename.c_str(), pMipSet, false, pluginManager) != 0) { CleanMipSet(); if (m_CMIPS) { m_CMIPS->Print("Error: reading image, data type not supported"); } return -1; } if (pMipSet) { if (pMipSet->m_format == CMP_FORMAT_Unknown) { pMipSet->m_format = GetFormat(pMipSet); } pMipSet->m_swizzle = KeepSwizzle(pMipSet->m_format); if (pMipSet->m_compressed || (pMipSet->m_ChannelFormat == CF_Compressed)) { pMipSet->m_compressed = true; Config configsetting; configsetting.swizzle = pMipSet->m_swizzle; pMipSet = DecompressMIPSet(pMipSet, GPUDecode_INVALID, &configsetting, NULL); if (pMipSet == NULL) { if (m_CMIPS) { m_CMIPS->Print("Error: reading compressed image"); } return -1; } } if (pMipSet->m_swizzle) SwizzleMipMap(pMipSet); } else { CleanMipSet(); if (m_CMIPS) { m_CMIPS->Print("Error: reading image, data type not supported"); } return -1; } } catch (std::bad_alloc) { if (m_CMIPS) { CleanMipSet(); m_CMIPS->m_canceled = true; m_CMIPS->Print("Error: Out of Memory while loading textures!"); } return -1; } return 0; }