/** * This method inserts values into the specified value table * @param fileName the fileName of the csv file * @param valueTable the value table to insert into * @param keyIndex the column index to use as the match criteria */ void FileController::insertValues(const string& fileName, ValueTable* valueTable, int keyIndex) { if (validateFileName(fileName)) { ifstream input(fileName.c_str()); if (input.good()) { string line; getline(input, line); valueTable->setHeaders(getHeaders(line)); while (getline(input, line)) { stringstream lineStream(line); string cell; vector<string> values; while (getline(lineStream, cell, ',')) { values.push_back(stripAll(cell)); } valueTable->addValue(values[keyIndex], values); } } else { cout << "File Does Not Exist." << endl; } } else { cout << "Incorrect File Format." << endl; } }
/** * This method is used to write data to a specified output csv file * @param fileName the csv filename * @param value the value to write */ void FileController::writeValue(const string& fileName, const string& value) { if (validateFileName(fileName)) { ofstream aFile; aFile.open(fileName.c_str(), ios::app); aFile << value << endl; } }
void SkeletonData::SaveSkeleton(std::string directory, std::string fileName, SceneRoot * _sceneRoot) { try{ //Validate directory validateDirectory(directory); //Validate filename validateFileName(fileName); //Create dir if( PathFileExistsA(directory.c_str()) == TRUE) { app::console() << "dir created/exists" << std::endl; std::ofstream jointFile; try { jointFile.open(directory.append(fileName)); if(jointFile.fail() == false){ jointFile << "{" << "\"joints\": " << "[" << std::endl; //write the joints to file (loop through roots and recurse through children) for(unsigned long int i = 0; i < _sceneRoot->children.size(); ++i){ Joint * j = dynamic_cast<Joint * >(_sceneRoot->children.at(i)); jointFile << writeJoint(j); if (j != _sceneRoot->children.back()) { jointFile << ","; } jointFile << std::endl; } jointFile << "]}" << std::endl; jointFile.close(); }else{ throw std::exception("Failed to write in directory. Permission may be denied."); } }catch (std::exception ex){ if (jointFile.is_open()){ jointFile.close(); } throw ex; } }else{ app::console() << "Does Not exist!\n" << std::endl; throw std::exception("Directory does not exist!"); } }catch(std::exception ex){ throw ex; } }
/* * Implements create interface. Validates file name, creates a new file block * if file does not exist. * Parameters: * o const char *name - file name to be created * sets my_errno to END_OF_FILE read at end of file. */ void mfs_create(const char *name) { if(validateFileName(name)) { struct mfs_file* file = Head; while(file) { if(strcompare(file->fname,name)) { return; } file = file->next; } struct mfs_file* newfile = mfs_construct(name); newfile->next = Head; Head = newfile; } else { my_errno = INVALID_FILE_NAME; } }
status_t AaptDir::validate() const { const size_t NF = mFiles.size(); const size_t ND = mDirs.size(); size_t i; for (i = 0; i < NF; i++) { if (!validateFileName(mFiles.valueAt(i)->getLeaf().string())) { SourcePos(mFiles.valueAt(i)->getPrintableSource(), -1).error( "Invalid filename. Unable to add."); return UNKNOWN_ERROR; } size_t j; for (j = i+1; j < NF; j++) { if (strcasecmp(mFiles.valueAt(i)->getLeaf().string(), mFiles.valueAt(j)->getLeaf().string()) == 0) { SourcePos(mFiles.valueAt(i)->getPrintableSource(), -1).error( "File is case-insensitive equivalent to: %s", mFiles.valueAt(j)->getPrintableSource().string()); return UNKNOWN_ERROR; } // TODO: if ".gz", check for non-.gz; if non-, check for ".gz" // (this is mostly caught by the "marked" stuff, below) } for (j = 0; j < ND; j++) { if (strcasecmp(mFiles.valueAt(i)->getLeaf().string(), mDirs.valueAt(j)->getLeaf().string()) == 0) { SourcePos(mFiles.valueAt(i)->getPrintableSource(), -1).error( "File conflicts with dir from: %s", mDirs.valueAt(j)->getPrintableSource().string()); return UNKNOWN_ERROR; } } } for (i = 0; i < ND; i++) { if (!validateFileName(mDirs.valueAt(i)->getLeaf().string())) { SourcePos(mDirs.valueAt(i)->getPrintableSource(), -1).error( "Invalid directory name, unable to add."); return UNKNOWN_ERROR; } size_t j; for (j = i+1; j < ND; j++) { if (strcasecmp(mDirs.valueAt(i)->getLeaf().string(), mDirs.valueAt(j)->getLeaf().string()) == 0) { SourcePos(mDirs.valueAt(i)->getPrintableSource(), -1).error( "Directory is case-insensitive equivalent to: %s", mDirs.valueAt(j)->getPrintableSource().string()); return UNKNOWN_ERROR; } } status_t err = mDirs.valueAt(i)->validate(); if (err != NO_ERROR) { return err; } } return NO_ERROR; }