本文整理汇总了C++中std::filesystem::path类的典型用法代码示例。如果您正苦于以下问题:C++ path类的具体用法?C++ path怎么用?C++ path使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了path类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Open
bool AudioSourceOJM::Open(std::filesystem::path f)
{
char sig[4];
ifile = std::make_shared<std::ifstream>(f.string(), std::ios::binary);
if (!ifile->is_open())
{
Log::Printf("AudioSourceOJM: unable to load %s.\n", f.c_str());
return false;
}
ifile->read(sig, 4);
switch (GetContainerKind(sig))
{
case M30:
parseM30();
break;
case OMC:
parseOMC();
break;
default:
return false;
}
ifile->close();
return true;
}
示例2: InvalidOperationException
fs::path
HOSTFXR_UTILITY::GetAbsolutePathToHostFxr(
const fs::path & dotnetPath
)
{
std::vector<std::wstring> versionFolders;
const auto hostFxrBase = dotnetPath.parent_path() / "host" / "fxr";
LOG_INFOF(L"Resolving absolute path to hostfxr.dll from '%ls'", dotnetPath.c_str());
if (!is_directory(hostFxrBase))
{
throw InvalidOperationException(format(L"Unable to find hostfxr directory at %s", hostFxrBase.c_str()));
}
FindDotNetFolders(hostFxrBase, versionFolders);
if (versionFolders.empty())
{
throw InvalidOperationException(format(L"Hostfxr directory '%s' doesn't contain any version subdirectories", hostFxrBase.c_str()));
}
const auto highestVersion = FindHighestDotNetVersion(versionFolders);
const auto hostFxrPath = hostFxrBase / highestVersion / "hostfxr.dll";
if (!is_regular_file(hostFxrPath))
{
throw InvalidOperationException(format(L"hostfxr.dll not found at '%s'", hostFxrPath.c_str()));
}
LOG_INFOF(L"hostfxr.dll located at '%ls'", hostFxrPath.c_str());
return hostFxrPath;
}
示例3: run_process
std::system_error run_process(const std::filesystem::path &filename, const std::vector<std::string> &argv,
const std::vector<std::string> &envp)
{
cpid = fork();
if (cpid == -1)
{
return std::system_error(std::make_error_code(std::errc(std::errno)));
}
if (cpid == 0)
{
std::vector<char *> arg;
arg.push_back(filename.c_str());
for (const auto &v : argv)
{
arg.push_back(v.c_str());
}
arg.push_back(nullptr);
std::vector<char *> env;
for (auto &e : envp)
{
env.push_back(e.c_str());
}
env.push_back(nullptr);
auto exec_error = execve(filename.c_str(), arg.data(), env.data());
perror("execve");
exit(EXIT_FAILURE);
}
else
{
attached = true;
}
return std::system_error(std::make_error_code(std::errc(0)));
}
示例4: decrypt_file
void decrypt_file(
fs::path const & sourcefile,
fs::path const & destfile,
std::string_view password)
{
CryptoPP::FileSource source(
sourcefile.c_str(),
true,
new CryptoPP::DefaultDecryptorWithMAC(
(CryptoPP::byte*)password.data(), password.size(),
new CryptoPP::FileSink(
destfile.c_str())
)
);
}
示例5: open
bool open(const std::filesystem::path& jpeg_file) override
{
auto fp = ::fopen(to_osmbstr(to_utf8(jpeg_file.native())).c_str(), "rb");
if(nullptr == fp) return false;
bool is_opened = false;
struct ::jpeg_decompress_struct jdstru;
error_mgr jerr;
jdstru.err = ::jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = _m_error_handler;
if (!setjmp(jerr.setjmp_buf))
{
::jpeg_create_decompress(&jdstru);
::jpeg_stdio_src(&jdstru, fp);
_m_read_jpg(jdstru);
jpeg_finish_decompress(&jdstru);
is_opened = true;
}
::jpeg_destroy_decompress(&jdstru);
::fclose(fp);
return is_opened;
}
示例6: float
//------------------------------------------------------------
bool ofOpenALSoundPlayer::mpg123ReadFile(const std::filesystem::path& path,vector<short> & buffer,vector<float> & fftAuxBuffer){
int err = MPG123_OK;
mpg123_handle * f = mpg123_new(nullptr,&err);
if(mpg123_open(f,path.c_str())!=MPG123_OK){
ofLogError("ofOpenALSoundPlayer") << "mpg123ReadFile(): couldn't read \"" << path << "\"";
return false;
}
mpg123_enc_enum encoding;
long int rate;
mpg123_getformat(f,&rate,&channels,(int*)&encoding);
if(encoding!=MPG123_ENC_SIGNED_16){
ofLogError("ofOpenALSoundPlayer") << "mpg123ReadFile(): " << getMpg123EncodingString(encoding)
<< " encoding for \"" << path << "\"" << " unsupported, expecting MPG123_ENC_SIGNED_16";
return false;
}
samplerate = rate;
size_t done=0;
size_t buffer_size = mpg123_outblock( f );
buffer.resize(buffer_size/2);
while(mpg123_read(f,(unsigned char*)&buffer[buffer.size()-buffer_size/2],buffer_size,&done)!=MPG123_DONE){
buffer.resize(buffer.size()+buffer_size/2);
};
buffer.resize(buffer.size()-(buffer_size/2-done/2));
mpg123_close(f);
mpg123_delete(f);
fftAuxBuffer.resize(buffer.size());
for(int i=0;i<(int)buffer.size();i++){
fftAuxBuffer[i] = float(buffer[i])/32565.f;
}
duration = float(buffer.size()/channels) / float(samplerate);
return true;
}
示例7: sfStream
//------------------------------------------------------------
bool ofOpenALSoundPlayer::sfStream(const std::filesystem::path& path,vector<short> & buffer,vector<float> & fftAuxBuffer){
if(!streamf){
SF_INFO sfInfo;
streamf = sf_open(path.c_str(),SFM_READ,&sfInfo);
if(!streamf){
ofLogError("ofOpenALSoundPlayer") << "sfStream(): couldn't read \"" << path << "\"";
return false;
}
stream_subformat = sfInfo.format & SF_FORMAT_SUBMASK ;
if (stream_subformat == SF_FORMAT_FLOAT || stream_subformat == SF_FORMAT_DOUBLE){
sf_command (streamf, SFC_CALC_SIGNAL_MAX, &stream_scale, sizeof (stream_scale)) ;
if (stream_scale < 1e-10)
stream_scale = 1.0 ;
else
stream_scale = 32700.0 / stream_scale ;
}
channels = sfInfo.channels;
duration = float(sfInfo.frames) / float(sfInfo.samplerate);
samplerate = sfInfo.samplerate;
stream_samples_read = 0;
}
int curr_buffer_size = BUFFER_STREAM_SIZE*channels;
if(speed>1) curr_buffer_size *= (int)round(speed);
buffer.resize(curr_buffer_size);
fftAuxBuffer.resize(buffer.size());
if (stream_subformat == SF_FORMAT_FLOAT || stream_subformat == SF_FORMAT_DOUBLE){
sf_count_t samples_read = sf_read_float (streamf, &fftAuxBuffer[0], fftAuxBuffer.size());
stream_samples_read += samples_read;
if(samples_read<(int)fftAuxBuffer.size()){
fftAuxBuffer.resize(samples_read);
buffer.resize(samples_read);
setPosition(0);
if(!bLoop) stopThread();
stream_samples_read = 0;
stream_end = true;
}
for (int i = 0 ; i < int(fftAuxBuffer.size()) ; i++){
fftAuxBuffer[i] *= stream_scale ;
buffer[i] = 32565.0 * fftAuxBuffer[i];
}
}else{
sf_count_t frames_read = sf_readf_short(streamf,&buffer[0],curr_buffer_size/channels);
stream_samples_read += frames_read*channels;
if(frames_read<curr_buffer_size/channels){
fftAuxBuffer.resize(frames_read*channels);
buffer.resize(frames_read*channels);
setPosition(0);
if(!bLoop) stopThread();
stream_samples_read = 0;
stream_end = true;
}
for(int i=0;i<(int)buffer.size();i++){
fftAuxBuffer[i]=float(buffer[i])/32565.0f;
}
}
return true;
}
示例8: LoadSong7KFromFilename
std::shared_ptr<VSRG::Song> LoadSong7KFromFilename(std::filesystem::path Filename, std::filesystem::path Prefix, VSRG::Song *Sng)
{
auto prefix = Prefix.string();
bool AllocSong = false;
if (!Sng)
{
AllocSong = true;
Sng = new VSRG::Song();
}
std::wstring Ext = Utility::Widen(Filename.extension().string());
// no extension
if (!Filename.has_extension() || !VSRGValidExtension(Ext))
{
if (AllocSong) delete Sng;
return nullptr;
}
Sng->SongDirectory = Prefix.string();
auto fn = Prefix / Filename;
auto fnu8 = Utility::Narrow(fn.wstring());
for (int i = 0; i < sizeof(LoadersVSRG) / sizeof(loaderVSRGEntry_t); i++)
{
if (Ext == LoadersVSRG[i].Ext)
{
Log::LogPrintf("Load %s from disk...", fnu8.c_str());
try
{
LoadersVSRG[i].LoadFunc(fn, Sng);
Log::LogPrintf(" ok\n");
}
catch (std::exception &e)
{
Log::LogPrintf("Failure loading: %s\n", e.what());
}
break;
}
}
if (AllocSong)
return std::shared_ptr<VSRG::Song>(Sng);
return nullptr;
}
示例9: FileWatch
FileWatchWin::FileWatchWin(const std::filesystem::path& path, const FileMonitor::t_callbackFunc& callback, DWORD dwNotifyFilter, HANDLE hDirectory) :
FileWatch(path),
m_callback(callback),
m_dwNotifyFilter(dwNotifyFilter),
m_hDirectory(hDirectory)
{
std::string filename = path.filename().string();
m_filename.assign(filename.begin(), filename.end());
memset(m_pOverlapped.get(), 0, sizeof(*m_pOverlapped));
m_pOverlapped->hEvent = CreateEvent(nullptr, true, false, nullptr);
}
示例10: find_last_file_matching_pattern
static std::filesystem::path find_last_file_matching_pattern(const std::filesystem::path& pattern) {
std::filesystem::path last_match;
for(const auto& entry : std::filesystem::directory_iterator(u"", pattern.c_str())) {
if( std::filesystem::is_regular_file(entry.status()) ) {
const auto match = entry.path();
if( match > last_match ) {
last_match = match;
}
}
}
return last_match;
}
示例11: sfReadFile
// ----------------------------------------------------------------------------
bool ofOpenALSoundPlayer::sfReadFile(const std::filesystem::path& path, vector<short> & buffer, vector<float> & fftAuxBuffer){
SF_INFO sfInfo;
SNDFILE* f = sf_open(path.c_str(),SFM_READ,&sfInfo);
if(!f){
ofLogError("ofOpenALSoundPlayer") << "sfReadFile(): couldn't read \"" << path << "\"";
return false;
}
buffer.resize(sfInfo.frames*sfInfo.channels);
fftAuxBuffer.resize(sfInfo.frames*sfInfo.channels);
int subformat = sfInfo.format & SF_FORMAT_SUBMASK ;
if (subformat == SF_FORMAT_FLOAT || subformat == SF_FORMAT_DOUBLE){
double scale ;
sf_command (f, SFC_CALC_SIGNAL_MAX, &scale, sizeof (scale)) ;
if (scale < 1e-10)
scale = 1.0 ;
else
scale = 32700.0 / scale ;
sf_count_t samples_read = sf_read_float (f, &fftAuxBuffer[0], fftAuxBuffer.size());
if(samples_read<(int)fftAuxBuffer.size()){
ofLogWarning("ofOpenALSoundPlayer") << "sfReadFile(): read " << samples_read << " float samples, expected "
<< fftAuxBuffer.size() << " for \"" << path << "\"";
}
for (int i = 0 ; i < int(fftAuxBuffer.size()) ; i++){
fftAuxBuffer[i] *= scale ;
buffer[i] = 32565.0 * fftAuxBuffer[i];
}
}else{
sf_count_t frames_read = sf_readf_short(f,&buffer[0],sfInfo.frames);
if(frames_read<sfInfo.frames){
ofLogError("ofOpenALSoundPlayer") << "sfReadFile(): read " << frames_read << " frames from buffer, expected "
<< sfInfo.frames << " for \"" << path << "\"";
return false;
}
sf_seek(f,0,SEEK_SET);
frames_read = sf_readf_float(f,&fftAuxBuffer[0],sfInfo.frames);
if(frames_read<sfInfo.frames){
ofLogError("ofOpenALSoundPlayer") << "sfReadFile(): read " << frames_read << " frames from fft buffer, expected "
<< sfInfo.frames << " for \"" << path << "\"";
return false;
}
}
sf_close(f);
channels = sfInfo.channels;
duration = float(sfInfo.frames) / float(sfInfo.samplerate);
samplerate = sfInfo.samplerate;
return true;
}
示例12: loadFontFace
//-----------------------------------------------------------
static bool loadFontFace(const std::filesystem::path& _fontname, FT_Face & face, std::filesystem::path & filename){
std::filesystem::path fontname = _fontname;
filename = ofToDataPath(_fontname,true);
ofFile fontFile(filename,ofFile::Reference);
int fontID = 0;
if(!fontFile.exists()){
#ifdef TARGET_LINUX
filename = linuxFontPathByName(fontname.string());
#elif defined(TARGET_OSX)
if(fontname==OF_TTF_SANS){
fontname = "Helvetica Neue";
#if MAC_OS_X_VERSION_10_13 && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_13
fontID = 0;
#else
fontID = 4;
#endif
}else if(fontname==OF_TTF_SERIF){
fontname = "Times New Roman";
}else if(fontname==OF_TTF_MONO){
fontname = "Menlo Regular";
}
filename = osxFontPathByName(fontname.string());
#elif defined(TARGET_WIN32)
if(fontname==OF_TTF_SANS){
fontname = "Arial";
}else if(fontname==OF_TTF_SERIF){
fontname = "Times New Roman";
}else if(fontname==OF_TTF_MONO){
fontname = "Courier New";
}
filename = winFontPathByName(fontname.string());
#endif
if(filename == "" ){
ofLogError("ofTrueTypeFont") << "loadFontFace(): couldn't find font \"" << fontname << "\"";
return false;
}
ofLogVerbose("ofTrueTypeFont") << "loadFontFace(): \"" << fontname << "\" not a file in data loading system font from \"" << filename << "\"";
}
FT_Error err;
err = FT_New_Face( library, filename.string().c_str(), fontID, &face );
if (err) {
// simple error table in lieu of full table (see fterrors.h)
string errorString = "unknown freetype";
if(err == 1) errorString = "INVALID FILENAME";
ofLogError("ofTrueTypeFont") << "loadFontFace(): couldn't create new face for \"" << fontname << "\": FT_Error " << err << " " << errorString;
return false;
}
return true;
}
示例13: print_pdf
void print_pdf(
fs::path const & pdfpath,
fs::path const & dirpath)
{
const int height = 842;
const int width = 595;
const int margin = 20;
auto image_paths = get_images(dirpath);
PDFWriter pdf;
pdf.StartPDF(pdfpath.string(), ePDFVersion13);
PDFPage* page = nullptr;
PageContentContext* context = nullptr;
auto top = height - margin;
for (size_t i = 0; i < image_paths.size(); ++i)
{
auto dims = pdf.GetImageDimensions(image_paths[i]);
if (i == 0 || top - dims.second < margin)
{
if (page != nullptr)
{
pdf.EndPageContentContext(context);
pdf.WritePageAndRelease(page);
}
page = new PDFPage();
page->SetMediaBox(PDFRectangle(0, 0, width, height));
context = pdf.StartPageContentContext(page);
top = height - margin;
}
context->DrawImage(margin, top - dims.second, image_paths[i]);
top -= dims.second + margin;
}
if (page != nullptr)
{
pdf.EndPageContentContext(context);
pdf.WritePageAndRelease(page);
}
pdf.EndPDF();
}
示例14:
Optional<File::Error> File::open_fatfs(const std::filesystem::path& filename, BYTE mode) {
auto result = f_open(&f, reinterpret_cast<const TCHAR*>(filename.c_str()), mode);
if( result == FR_OK ) {
if( mode & FA_OPEN_ALWAYS ) {
const auto result = f_lseek(&f, f_size(&f));
if( result != FR_OK ) {
f_close(&f);
}
}
}
if( result == FR_OK ) {
return { };
} else {
return { result };
}
}
示例15: ConvertToSMTiming
void ConvertToSMTiming(VSRG::Song *Sng, std::filesystem::path PathOut)
{
TimingData BPS, VSpeeds, Warps;
VSRG::Difficulty* Diff = Sng->Difficulties[0].get();
Diff->GetPlayableData(nullptr, BPS, VSpeeds, Warps);
std::ofstream out(PathOut.string());
// Technically, stepmania's #OFFSET is actually #GAP, not #OFFSET.
out << "#OFFSET:" << -Diff->Offset << ";\n";
out << "#BPMS:";
for (auto i = Diff->Timing.begin();
i != Diff->Timing.end();
++i)
{
double Time = 0;
double Value = 0;
switch (Diff->BPMType)
{
case VSRG::Difficulty::BT_BEAT:
Time = i->Time;
Value = i->Value;
break;
case VSRG::Difficulty::BT_BEATSPACE:
Time = i->Time;
Value = 60000 / i->Value;
break;
case VSRG::Difficulty::BT_MS:
Time = i->Time / 1000.0;
Value = i->Value;
break;
}
double Beat = QuantizeBeat(IntegrateToTime(BPS, Time + Diff->Offset, 0));
out << Beat << "=" << Value;
if ((i + 1) != Diff->Timing.end()) // Only output comma if there's still stuff to output.
out << "\n,";
}
out << ";";
}