void LLPreviewTexture::saveAs(EFileformatType format) { if( mLoadingFullImage ) return; LLFilePicker& file_picker = LLFilePicker::instance(); const LLInventoryItem* item = getItem() ; loaded_callback_func callback; LLFilePicker::ESaveFilter saveFilter; switch (format) { case LLPreviewTexture::FORMAT_PNG: callback = LLPreviewTexture::onFileLoadedForSavePNG; saveFilter = LLFilePicker::FFSAVE_PNG; break; case LLPreviewTexture::FORMAT_TGA: default: callback = LLPreviewTexture::onFileLoadedForSaveTGA; saveFilter = LLFilePicker::FFSAVE_TGA; break; } // <FS:Ansariel> FIRE-14111: File extension missing on Linux when saving a texture //if( !file_picker.getSaveFile( saveFilter, item ? LLDir::getScrubbedFileName(item->getName()) : LLStringUtil::null) ) if( !file_picker.getSaveFile( saveFilter, item ? checkFileExtension(LLDir::getScrubbedFileName(item->getName()), format) : LLStringUtil::null) ) // </FS:Ansariel> { // User canceled or we failed to acquire save file. return; } if(mPreviewToSave) { mPreviewToSave = FALSE; LLFloaterReg::showTypedInstance<LLPreviewTexture>("preview_texture", item->getUUID()); } // remember the user-approved/edited file name. // <FS:Ansariel> FIRE-14111: File extension missing on Linux when saving a texture //mSaveFileName = file_picker.getFirstFile(); mSaveFileName = checkFileExtension(file_picker.getFirstFile(), format); // </FS:Ansariel> mLoadingFullImage = TRUE; getWindow()->incBusyCount(); mImage->forceToSaveRawImage(0) ;//re-fetch the raw image if the old one is removed. mImage->setLoadedCallback( callback, 0, TRUE, FALSE, new LLUUID( mItemUUID ), &mCallbackTextureList ); }
bool checkFileExtension(const WCHAR* wfileName, const WCHAR* wextension, bool caseInsensitive) { if (!wfileName || !wextension) { return false; } StringBuffer fileName, extension; fileName.convert(wfileName); extension.convert(wextension); return checkFileExtension(fileName, extension, caseInsensitive); }
int readFilesInsideDir(const char* path, mp3* amp3, int* nfiles, cupath* sfolder, int* nfolders) { char current_path[MAX_PATH] = {0}; char file_name[MAX_NAME] = {0}; char file_path[MAX_NAME + MAX_PATH] = {0}; DIR *dir; struct dirent *current; dir = opendir(path); strcpy(current_path, path); *nfiles = 0; *nfolders = 0; if (dir != NULL) { while ((current = readdir(dir)) != NULL) { strcpy(file_name, current->d_name); if (strcmp(file_name, ".") == 0 || strcmp(file_name, "..") == 0) continue; getFilePath(path, file_name, file_path); if (checkFileIsDir(file_path) == 0) { strcpy((sfolder + *nfolders)->fpath, file_path); ++(*nfolders); } if (checkFileExtension(current->d_name) == 0) { getFileBitRate(file_path, amp3, nfiles); strcpy((amp3 + *nfiles)->path, path); // set some mp3 members here strcpy((amp3 + *nfiles)->filename, file_name); // ++(*nfiles); } } closedir (dir); } else { perror ("readFilesInsideDir"); return -1; } return 0; }
int readSingleFile(const char* path, mp3* mp3_data) { int temp = 0; if(checkFileExists(path)) { printf("file doesn't exist\n"); return -5; } if (0 != checkFileExtension(path)) { printf("mp3 validation failed\n"); return -10; } getFileBitRate(path, mp3_data, &temp); return 0; }
/* * This function is modified from Program 4.7 * in Book Advanced Programming in the UNIX Environment, * written by W. Richard Stevens * * Descend through the hierarchy, starting at "pathname". * If "pathname" is anything other than a directory, * we lstat() it, call func(), and return. * For a directory, we call ourself recursively * for each name in the directory. */ static void ftw(char * pathname, void (* func)(char *)) { struct stat statbuf; struct dirent * dirp; DIR * dp; char * ptr; if (lstat(pathname, &statbuf) < 0) /* stat error */ { printf("ERROR: stat error on %s\n", pathname); return; } if (S_ISDIR(statbuf.st_mode)) /* a directory */ { /* * It's a directory. * So process each filename in the directory. */ ptr = pathname + strlen(pathname); /* point to end of pathname */ *ptr++ = '/'; *ptr = 0; if ((dp = opendir(pathname)) == NULL) /* can NOT read directory */ { printf("ERROR: can NOT read directory \"%s\"\n", pathname); return; } /* process all files inside one by one */ while ((dirp = readdir(dp)) != NULL) { if (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0) { continue; /* ignore dot and dot dot */ } strcpy(ptr, dirp->d_name); /* append name after slash */ ftw(pathname, func); /* recursively call ftw */ } ptr[-1] = 0; /* erase everything from slash onwards */ if (closedir(dp) < 0) { printf("ERROR: can NOT close directory %s\n", pathname); return; } } else if (S_ISREG(statbuf.st_mode)) /* a regular file */ { if (checkFileExtension(pathname)) /* whether open this file */ { func(pathname); } } else if (S_ISLNK(statbuf.st_mode)) /* a symbolic link */ { //printf("\"%s\" is a symbolic link.\n", pathname); char sym_buf[1024]; int num_char; if ((num_char = readlink(pathname, sym_buf, 1023)) < 0) { write(2, "ERROR: can NOT read link!\n", 26); return; } sym_buf[num_char] = 0; //my_printf("linkname:%s\n", sym_buf); //my_printf("%s\n", canonicalize_file_name(sym_buf)); ftw((char *)canonicalize_file_name(sym_buf), func); } }
int main(){ //int indexer() { FILE *files,*fp,*conf; char temp[MAXIMUM],tempFileName[MAXIMUM],filesName[MAXIMUM],textFileName[MAXIMUM]; int i,docId = 1; int fileType; int ret; int totalErrors = 0; initializeStopWordsArray(); initializeTrie(); /* conf = fopen("CONFIG","r"); readLine(conf,filesName); fclose(conf);*/ files = fopen("INDEX/files.txt","r"); if(files == NULL){ goto createStatusFile; } while(readLine(files,tempFileName) != FAIL) { printf("%d \n",docId); printf("%s\n",tempFileName); fileType = checkFileExtension(tempFileName); strcpy(textFileName,"temp.txt"); if(fileType == PDF){ ret = convertPdfToTxt(tempFileName,textFileName); if(ret != SUCCESS){ ++totalErrors; ++docId; continue; } } else if(fileType == DOC){ ret = convertDocToTxt(tempFileName,textFileName); if(ret != SUCCESS){ ++totalErrors; ++docId; continue; } } else if(fileType == ODT){ ret = convertOdtToTxt(tempFileName,textFileName); if(ret != SUCCESS){ ++totalErrors; ++docId; continue; } }else if(fileType == TXT){ strcpy(textFileName,tempFileName); }else if(fileType == 0){ ++totalErrors; ++docId; continue; } fp = fopen(textFileName,"r"); if(fp == NULL){ ++totalErrors; ++docId; continue; } // Read each filename from the file 'files.txt' // For each filename, read each word and add to index trie. while(readWord(fp,temp) != FAIL) { convertToLowerCase(temp); removeSpecialSymbols(temp); // printf("%s ",temp); if(temp[0] == '\0' || temp[0] == '\t' || temp[0] == ' ' || temp[0] == '\n') continue; if(checkForStopWords(temp) != SUCCESS) { int i = 0; // Presently on the words containing letters are allowed while(temp[i] != '\0') { if(temp[i] < 97 || temp[i] > 122) break; ++i; } if(temp[i] == '\0') { fileLen[docId]++; // printf("%d %s\n",docId,temp); addTerm(temp,docId); } //if(temp[0] >= 97 && temp[0]<=122) { // addTerm(temp,docId); //} //printf("%s\n",temp); } } ++docId; fclose(fp); if(fileType != TXT){ system("rm temp.txt"); system("touch temp.txt"); } printf("...Done\n"); } //printf("\nTrie Traversal\n"); //traverseTerms(); numOfDocs = docId - 1; printf("Number of docs : %d\n",numOfDocs); printf("Number of Errors : %d\n",totalErrors); // traverseTerms(); createIndexFile(); createStatusFile: system("echo \"Index Status\n==================\nIndex created on :\n\" > INDEX/STATUS.txt"); system("date >> INDEX/STATUS.txt"); system("echo \"Directory indexed : \"#// >> INDEX/STATUS.txt"); sprintf(temp,"echo \"No of Documents indexed : %d\" >> INDEX/STATUS.txt",numOfDocs); system(temp); return 0; }
void PDFExportDialog::fileNameChanged() { QString fileName = checkFileExtension(fileNameLineEdit->text(),"pdf"); fileNameLineEdit->setText( QDir::toNativeSeparators(fileName) ); }