static int parse_document( fs::path const& filein_ , fs::path const& fileout_ , fs::path const& deps_out_ , fs::path const& locations_out_ , fs::path const& xinclude_base_ , int indent , int linewidth , bool pretty_print) { string_stream buffer; id_manager ids; int result = 0; try { quickbook::state state(filein_, xinclude_base_, buffer, ids); set_macros(state); if (state.error_count == 0) { state.add_dependency(filein_); state.current_file = load(filein_); // Throws load_error parse_file(state); if(state.error_count) { detail::outerr() << "Error count: " << state.error_count << ".\n"; } } result = state.error_count ? 1 : 0; if (!deps_out_.empty()) { fs::ofstream out(deps_out_); BOOST_FOREACH(quickbook::state::dependency_list::value_type const& d, state.dependencies) { if (d.second) { out << detail::path_to_generic(d.first) << std::endl; } } } if (!locations_out_.empty()) { fs::ofstream out(locations_out_); BOOST_FOREACH(quickbook::state::dependency_list::value_type const& d, state.dependencies) { out << (d.second ? "+ " : "- ") << detail::path_to_generic(d.first) << std::endl; } }
fs::path StarsApp::getPrevFile( const fs::path ¤t ) { if( !current.empty() ) { fs::path previous; fs::directory_iterator end_itr; for( fs::directory_iterator i( current.parent_path() ); i != end_itr; ++i ) { // skip if not a file if( !fs::is_regular_file( i->status() ) ) continue; if( *i == current ) { // do we know what file came before this one? if( !previous.empty() ) return previous; else break; } else { // skip if extension does not match if( std::find( mMusicExtensions.begin(), mMusicExtensions.end(), i->path().extension() ) == mMusicExtensions.end() ) continue; // keep track of this file previous = *i; } } } // failed, return empty path return fs::path(); }
void TextureSequenceOptimizer::saveMax( fs::path path ) { if ( path == fs::path() ) { path = app::App::get()->getFolderPath(); app::console() << "SAVE MAX: " << path << std::endl; } if( ! path.empty() ){ fs::path jsonPath = path; jsonPath.append("sequence.json"); JsonTree doc = JsonTree::makeObject(); JsonTree size = JsonTree::makeObject("size"); size.pushBack(JsonTree("width", mOriOutline.getWidth() )); size.pushBack(JsonTree("height", mOriOutline.getHeight() )); doc.pushBack(size); JsonTree sequence = JsonTree::makeArray("sequence"); //go thru each surface for (int i = 0; i < mSurfaceRefs.size(); i++) { fs::path tempPath = path; //only clone the non-transparent area based on the offsets Surface tempSurf; JsonTree curImage = JsonTree::makeObject(); if( mTrimMaxAreas[i].calcArea() == 0 ){ app::console() << " Image is completely transparent: " << mFileNames[i] << std::endl; tempPath.append("transparent.png"); // check if transparent pixel exists if( !fs::exists(tempPath) ){ // create transparent png if it doesn't exist tempSurf = mSurfaceRefs[i]->clone( Area(0,0,10,10) ); writeImage( tempPath, tempSurf ); } // point to transparent image curImage.pushBack(JsonTree("x", mTrimMaxAreas[i].x1)); curImage.pushBack(JsonTree("y", mTrimMaxAreas[i].y1)); curImage.pushBack(JsonTree("fileName", "transparent.png" )); }else{ tempSurf = mSurfaceRefs[i]->clone(mTrimMaxAreas[i]); tempPath.append(toString(mFileNames[i])); writeImage( tempPath, tempSurf ); curImage.pushBack(JsonTree("x", mTrimMaxAreas[i].x1)); curImage.pushBack(JsonTree("y", mTrimMaxAreas[i].y1)); curImage.pushBack(JsonTree("fileName", mFileNames[i] )); } sequence.pushBack(curImage); //app::console() << "saving: " << tempPath << " "<< mTrimMaxAreas[i] << std::endl; tempPath.clear(); } doc.pushBack(sequence); doc.write( jsonPath, JsonTree::WriteOptions()); //saveJson(path); } }
void AudioVisualizerApp::listAudio(const fs::path& directory, vector<fs::path>& list) { // clear the list list.clear(); if(directory.empty() || !fs::is_directory(directory)) return; // make a list of all audio files in the directory fs::directory_iterator end_itr; for( fs::directory_iterator i( directory ); i != end_itr; ++i ) { // skip if not a file if( !fs::is_regular_file( i->status() ) ) continue; // skip if extension does not match string extension = i->path().extension().string(); extension.erase(0, 1); if( std::find( mAudioExtensions.begin(), mAudioExtensions.end(), extension ) == mAudioExtensions.end() ) continue; // file matches list.push_back(i->path()); } }
fs::path AudioVisualizerApp::nextAudio( const fs::path& file ) { if( file.empty() || !fs::is_regular_file( file ) ) return fs::path(); fs::path& directory = file.parent_path(); // make a list of all audio files in the directory vector<fs::path> files; listAudio( directory, files ); // return if there are no audio files in the directory if( files.empty() ) return fs::path(); // find current audio file auto itr = std::find( files.begin(), files.end(), file ); // if not found, or if it is the last audio file, simply return first audio file if( itr == files.end() || *itr == files.back() ) return files.front(); // return next file return *( ++itr ); }
fs::path StarsApp::getNextFile( const fs::path ¤t ) { if( !current.empty() ) { bool useNext = false; fs::directory_iterator end_itr; for( fs::directory_iterator i( current.parent_path() ); i != end_itr; ++i ) { // skip if not a file if( !fs::is_regular_file( i->status() ) ) continue; if(useNext) { // skip if extension does not match if( std::find( mMusicExtensions.begin(), mMusicExtensions.end(), i->path().extension() ) == mMusicExtensions.end() ) continue; // file matches, return it return i->path(); } else if( *i == current ) { useNext = true; } } } // failed, return empty path return fs::path(); }
void AudioVisualizerApp::playAudio( const fs::path& file ) { FMOD_RESULT err; // ignore if this is not a file if( file.empty() || !fs::is_regular_file( file ) ) return; // if audio is already playing, stop it first stopAudio(); // stream the audio err = mFMODSystem->createStream( file.string().c_str(), FMOD_SOFTWARE, NULL, &mFMODSound ); err = mFMODSystem->playSound( FMOD_CHANNEL_FREE, mFMODSound, false, &mFMODChannel ); // we want to be notified of channel events err = mFMODChannel->setCallback( channelCallback ); // keep track of the audio file mAudioPath = file; mIsAudioPlaying = true; // console() << "Now playing:" << mAudioPath.filename() << std::endl; }
bool handle_action(sf::Event event) { short i; location the_point; bool to_return = false; the_point = {event.mouseButton.x, event.mouseButton.y}; if(file_in_mem.empty()) return false; for(i = 0; i < 6; i++) if((the_point.in(pc_area_buttons[i][0])) && (univ.party[i].main_status != eMainStatus::ABSENT)) { do_button_action(0,i); current_active_pc = i; redraw_screen(); } for(i = 0; i < 5; i++) if((the_point.in(edit_rect[i])) && (univ.party[current_active_pc].main_status != eMainStatus::ABSENT)) { do_button_action(0,i + 10); switch(i) { case 0: display_pc(current_active_pc,10,nullptr); break; case 1: display_pc(current_active_pc,11,nullptr); break; case 2: pick_race_abil(&univ.party[current_active_pc],0); break; case 3: spend_xp(current_active_pc,2,nullptr); break; case 4: edit_xp(&univ.party[current_active_pc]); break; } } for(i = 0; i < 24; i++) if((the_point.in(item_string_rects[i][1])) && // drop item univ.party[current_active_pc].items[i].variety != eItemType::NO_ITEM) { flash_rect(item_string_rects[i][1]); univ.party[current_active_pc].take_item(i); } for(i = 0; i < 24; i++) if((the_point.in(item_string_rects[i][2])) && // identify item univ.party[current_active_pc].items[i].variety != eItemType::NO_ITEM) { flash_rect(item_string_rects[i][2]); univ.party[current_active_pc].items[i].ident = true; } return to_return; }
void ASM_Gaze_Tracker::initASM_Gaze_Tracker(const fs::path & trackermodel, const fs::path & cameraProfile) { tracker = load_ft<face_tracker>(trackermodel.string()); tracker.detector.baseDir = trackermodel.parent_path().string() + fs::path("/").make_preferred().native(); if (cameraProfile.empty() == false) { findBestFrontalFaceShapeIn3D(); readCameraProfile(cameraProfile, cameraMatrix, distCoeffs); } }
fs::path Path::MakeAbsolute(fs::path path, std::string const& token) const { if (path.empty()) return path; int idx = find_token(token.c_str(), token.size()); if (idx == -1) throw agi::InternalError("Bad token: " + token); path.make_preferred(); const auto str = path.string(); if (boost::starts_with(str, "?dummy") || boost::starts_with(str, "dummy-audio:")) return path; return (paths[idx].empty() || path.is_absolute()) ? path : paths[idx]/path; }
void ThresholdTestApp::loadFile( const fs::path &path ) { if( ! path.empty() ) { mSurface = Surface8u::create( loadImage( path ) ); mGraySurface = Channel( mSurface->getWidth(), mSurface->getHeight() ); mThresholded = Channel( mSurface->getWidth(), mSurface->getHeight() ); ip::grayscale( *mSurface, &mGraySurface ); mThresholdClass = ip::AdaptiveThreshold( &mGraySurface ); } }
shared_ptr<ISound> StarsApp::createSound( const fs::path &path ) { shared_ptr<ISound> sound; if(mSoundEngine && !path.empty()) { // create sound in a very safe way sound = shared_ptr<ISound>( mSoundEngine->play3D( path.string().c_str(), vec3df(0,0,0), false, true ), std::mem_fun(&ISound::drop) ); } return sound; }
fs::path GetExecutionPath() { if(g_ExecPath.empty()) { wchar_t exec_path[MAX_PATH]; DWORD length = GetModuleFileName( NULL, exec_path, MAX_PATH ); PathRemoveFileSpec(exec_path); g_ExecPath = fs::path(exec_path); } return g_ExecPath; }
fs::path Path::MakeRelative(fs::path const& path, fs::path const& base) const { if (path.empty() || base.empty()) return path; const auto str = path.string(); if (boost::starts_with(str, "?dummy") || boost::starts_with(str, "dummy-audio:")) return path; // Paths on different volumes can't be made relative to each other if (path.has_root_name() && path.root_name() != base.root_name()) return path.string(); auto path_it = path.begin(); auto ref_it = base.begin(); for (; path_it != path.end() && ref_it != base.end() && *path_it == *ref_it; ++path_it, ++ref_it) ; agi::fs::path result; for (; ref_it != base.end(); ++ref_it) result /= ".."; for (; path_it != path.end(); ++path_it) result /= *path_it; return result; }
void StarsApp::playMusic( const fs::path &path, bool loop ) { if(mSoundEngine && !path.empty()) { // stop current music if(mMusic) mMusic->stop(); // play music in a very safe way mMusic = shared_ptr<ISound>( mSoundEngine->play2D( path.string().c_str(), loop, true ), std::mem_fun(&ISound::drop) ); if(mMusic) mMusic->setIsPaused(false); mMusicPath = path; mPlayMusic = true; } }
void UserManager::openKinect( const fs::path &path ) { try { mndl::ni::OpenNI kinect; if ( path.empty() ) kinect = OpenNI( OpenNI::Device() ); else kinect = OpenNI( path ); { std::lock_guard< std::mutex > lock( mMutex ); mNI = kinect; } } catch ( ... ) { if ( path.empty() ) mKinectProgress = "No device detected"; else mKinectProgress = "Recording not found"; return; } if ( path.empty() ) mKinectProgress = "Connected"; else mKinectProgress = "Recording loaded"; { std::lock_guard< std::mutex > lock( mMutex ); mNI.setDepthAligned(); mNI.start(); mNIUserTracker = mNI.getUserTracker(); mNIUserTracker.addListener( this ); } }
void Path::SetToken(const char *token_name, fs::path const& token_value) { int idx = find_token(token_name, strlen(token_name)); if (idx == -1) throw agi::InternalError("Bad token: " + std::string(token_name)); if (token_value.empty()) paths[idx] = token_value; else if (!token_value.is_absolute()) paths[idx].clear(); else { paths[idx] = token_value; paths[idx].make_preferred(); if (fs::FileExists(paths[idx])) paths[idx] = paths[idx].parent_path(); } }
void LoggingConfig::configureLogging(const fs::path& logging_config) { if (logging_config.empty()) { LOG(WARNING) << "Unable to find a global logging configuration file!"; return; } LoggingConfig config; ValidationMap validation = config.parse(logging_config.string()); if (!validation.isEmpty()) { if (validation.isCritical()) LOG(FATAL) << "Unable to parse global logging configuration file:"; else LOG(WARNING) << "There is a problem parsing the global logging configuration file:"; validation.log(); } if (validation.isCritical()) return; auto log_sections = config.getLogSections(); for (auto it = log_sections.begin(); it != log_sections.end(); ++it) it->configureLogging(); }
void KinectUser::setup( const fs::path &path ) { if ( path.empty() ) mNI = ni::OpenNI( ni::OpenNI::Device() ); else mNI = ni::OpenNI( path ); mNIUserTracker = mNI.getUserTracker(); mNI.setMirrored(); mNI.start(); mParams = params::PInterfaceGl( "Kinect", Vec2i( 300, 500 ) ); mParams.addPersistentSizeAndPosition(); mParams.addText( "User outlines" ); mParams.addPersistentParam( " Enable", &mOutlineEnable, true ); mParams.addPersistentParam( " Blur", &mOutlineBlurAmt, 15.0, "min=1 max=15 step=.5" ); mParams.addPersistentParam( " Erode", &mOutlineErodeAmt, 4.0, "min=1 max=15 step=.5" ); mParams.addPersistentParam( " Dilate", &mOutlineDilateAmt, 4.0, "min=1 max=15 step=.5" ); mParams.addPersistentParam( " Threshold", &mOutlineThres, 128, "min=1 max=255" ); mParams.addPersistentParam( " Thickness", &mOutlineWidth, 3, "min=.5 max=15 step=.2" ); mParams.addPersistentParam( " Miter limit", &mMiterLimit, .75, "min=-1 max=1 step=.05" ); mParams.addPersistentParam( " Color", &mOutlineColor, ColorA::hexA( 0x50ffffff ) ); mParams.addText( "Hand" ); mParams.addPersistentParam( " Hand size", &mHandSize, 5., "min=0 max=50 step=.5" ); mParams.addPersistentParam( " Hand Color", &mHandColor, ColorA::hexA( 0x50ffffff ) ); mParams.addPersistentParam( " Hand smoothing", &mHandSmoothing, .7, "min=0 max=1 step=.05" ); setBounds( app::getWindowBounds() ); #ifdef OUTLINE_SHADER mShader = gl::GlslProg( app::loadResource( RES_LINE_VERT ), app::loadResource( RES_LINE_FRAG ), app::loadResource( RES_LINE_GEOM ), GL_LINES_ADJACENCY_EXT, GL_TRIANGLE_STRIP, 7 ); #endif }
fs::path AppImplMsw::getSaveFilePath( const fs::path &initialPath, vector<string> extensions ) { OPENFILENAMEA ofn; // common dialog box structure char szFile[260]; // buffer for file name // Initialize OPENFILENAME ZeroMemory( &ofn, sizeof(ofn) ); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = App::get()->getRenderer()->getHwnd(); ofn.lpstrFile = szFile; // Set lpstrFile[0] to '\0' so that GetOpenFileName does not // use the contents of szFile to initialize itself. // // Set lpstrFile[0] to '\0' so that GetOpenFileName does not // use the contents of szFile to initialize itself. // ofn.lpstrFile[0] = '\0'; ofn.nMaxFile = sizeof( szFile ); if( extensions.empty() ) { ofn.lpstrFilter = "All\0*.*\0"; } else { char extensionStr[10000]; size_t offset = 0; strcpy( extensionStr, "Supported Types" ); offset += strlen( extensionStr ) + 1; for( vector<string>::const_iterator strIt = extensions.begin(); strIt != extensions.end(); ++strIt ) { strcpy( extensionStr + offset, "*." ); offset += 2; strcpy( extensionStr + offset, strIt->c_str() ); offset += strIt->length(); // append a semicolon to all but the last extensions if( strIt + 1 != extensions.end() ) { extensionStr[offset] = ';'; offset += 1; } else { extensionStr[offset] = 0; offset += 1; } } extensionStr[offset] = 0; ofn.lpstrFilter = extensionStr; } ofn.nFilterIndex = 1; ofn.lpstrFileTitle = NULL; ofn.nMaxFileTitle = 0; if( initialPath.empty() ) ofn.lpstrInitialDir = NULL; else { char initialPathStr[MAX_PATH]; strcpy( initialPathStr, initialPath.string().c_str() ); ofn.lpstrInitialDir = initialPathStr; } ofn.Flags = OFN_SHOWHELP | OFN_OVERWRITEPROMPT; // Display the Open dialog box. string result; if( ::GetSaveFileNameA( &ofn ) == TRUE ) { result = string( ofn.lpstrFile ); } return result; }
void process_directory(const fs::path &directory, const long depth, ProcessParams ¶ms) { // Exclude entire directories bool exclude = false; std::vector<std::string>::const_iterator x_iter = params.excludes.begin(); std::vector<std::string>::const_iterator x_end = params.excludes.end(); for( ; x_iter != x_end; ++x_iter ) { if(boost::contains(directory.file_string(), *x_iter)) { exclude = true; break; } } if(exclude) { info(std::string("excluding directory: ") + directory.file_string() + " matched: " + *x_iter); ++params.dir_ex_count; return; } try { fs::directory_iterator p_iter(directory), p_end; for( ; p_iter != p_end; ++p_iter) { if( is_directory(*p_iter) ) { // recurse if we haven't hit the limit if(depth < params.limit_depth) process_directory(p_iter->path(), depth + 1, params); else { info(std::string("depth reached, skipping: ") + p_iter->path().file_string()); } } else if( is_regular_file(*p_iter) ) { // Check again for excluding file names exclude = false; x_iter = params.excludes.begin(); for( ; x_iter != x_end; ++x_iter ) { if(boost::contains(p_iter->path().file_string(), *x_iter)) { exclude = true; break; } } if(exclude) { info(std::string("excluding file: ") + p_iter->path().file_string() + " matched: " + *x_iter); ++params.file_ex_count; continue; } try { const fs::path dest_subdir = build_dest(*p_iter); fs::path dest_file; if(!dest_subdir.empty()) dest_file = params.dest_dir / dest_subdir; else if(params.ignore_unsorted) { info(std::string("ignoring unsorted: ") + p_iter->path().file_string()); ++params.unsorted_ignored_count; continue; } else { info(std::string("unsorted file (missing metadata): ") + p_iter->path().file_string()); dest_file = params.unsorted_dir; ++params.unsorted_count; } dest_file /= p_iter->filename(); if(fs::exists(dest_file)) { if(params.ignore_dups) { info(std::string("ignoring: ") + p_iter->path().file_string() + " duplicates: " + dest_file.file_string()); ++params.dups_ignored_count; continue; } else { if(params.force) { info(std::string("force removing: ") + dest_file.file_string() + " for: " + p_iter->path().file_string()); if(!params.dry_run) fs::remove(dest_file); } else if(params.rename) { info(std::string("renaming: ") + p_iter->path().file_string() + " duplicates: " + dest_file.file_string()); dest_file = uniquify(dest_file); } else { info(std::string("duplicate file: ") + p_iter->path().file_string() + " of: " + dest_file.file_string()); dest_file = params.dups_dir / dest_subdir / p_iter->filename(); // Ugh, more dup possibilities if(fs::exists(dest_file)) { info(std::string("renaming: ") + p_iter->path().file_string() + " duplicates: " + dest_file.file_string()); dest_file = uniquify(dest_file); } } ++params.dups_count; } } if(!params.dry_run) fs::create_directories(dest_file.parent_path()); if(params.symlink) { info(std::string("linking from: ") + p_iter->path().file_string() + " to: " + dest_file.file_string()); if(!params.dry_run) { // The target of a symlink must be either absolute (aka complete) or // relative to the location of the link. Easiest solution is to make // a complete path. fs::path target; if(p_iter->path().is_complete()) target = p_iter->path(); else target = fs::initial_path() / p_iter->path(); fs::create_symlink(target, dest_file); } } else { info(std::string("copying from: ") + p_iter->path().file_string() + " to: " + dest_file.file_string()); if(!params.dry_run) { // Copy the file and restore its write time (needed for posix) std::time_t time = fs::last_write_time(*p_iter); fs::copy_file(*p_iter, dest_file); fs::last_write_time(dest_file, time); if(params.verify) { md5digest src_digest, dst_digest; bool ok = md5sum(p_iter->path(), src_digest); if(ok) ok = md5sum(dest_file, dst_digest); if(ok) ok = (memcmp(src_digest,dst_digest, sizeof(md5digest))==0); if(!ok) { // Should probably find a more appropriate exception for this throw std::runtime_error(std::string("File verification failed: '") + p_iter->path().file_string() + "' differs from '" + dest_file.file_string() + "'"); } else { info(std::string("verification passed")); } } } } if(params.move) { info(std::string("removing: ") + p_iter->path().file_string()); if(!params.dry_run) fs::remove(*p_iter); } if(!g_verbose && (params.ok_count % DOT_EVERY)==0) { std::cout << "." << std::flush; g_neednewline = true; } ++params.ok_count; } catch(fs::filesystem_error& e) { error(e, std::string("skipping file: " + p_iter->path().file_string())); ++params.file_err_count; } } } } catch(fs::filesystem_error& e) { error(e, std::string("skipping directory: " + directory.file_string())); ++params.dir_err_count; } }