当前位置: 首页>>代码示例>>C++>>正文


C++ FileIO::open方法代码示例

本文整理汇总了C++中FileIO::open方法的典型用法代码示例。如果您正苦于以下问题:C++ FileIO::open方法的具体用法?C++ FileIO::open怎么用?C++ FileIO::open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileIO的用法示例。


在下文中一共展示了FileIO::open方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ImageOpenBinary

void CDAccess_Image::ImageOpenBinary(const char *path, bool isIso)
{
	NumTracks = FirstTrack = LastTrack = 1;
	total_sectors = 0;
	disc_type = DISC_TYPE_CDDA_OR_M1;
	auto &track = Tracks[1];
	track = {};
	FileIO fp;
	if(fp.open(path) != OK)
	{
		ErrnoHolder ene(errno);
		throw(MDFN_Error(ene.Errno(), _("Could not open file \"%s\": %s"), path, ene.StrError()));
	}
	track.fp = std::make_shared<FileIO>(std::move(fp));
	track.FirstFileInstance = 1;
	track.DIFormat = DI_FORMAT_MODE1_RAW;
	if(isIso)
	{
		track.DIFormat = DI_FORMAT_MODE1;
		track.postgap = 150;
		total_sectors += track.postgap;
	}

	track.sectors = GetSectorCount(&track);
	total_sectors += track.sectors;
}
开发者ID:kiorter,项目名称:emu-ex-plus-alpha,代码行数:26,代码来源:CDAccess_Image.cpp

示例2: ImageOpen

void CDAccess_Image::ImageOpen(const char *path, bool image_memcache)
{
 //MemoryStream fp(new FileStream(path, FileStream::MODE_READ));
 FileIO fp;
 fp.open(path);
 if(!fp)
 {
	throw MDFN_Error(0, "Error opening file \"%s\"", path);
 }
 static const unsigned max_args = 4;
 std::string linebuf;
 std::string cmdbuf, args[max_args];
 bool IsTOC = FALSE;
 int32 active_track = -1;
 int32 AutoTrackInc = 1; // For TOC
 CDRFILE_TRACK_INFO TmpTrack;
 std::string file_base, file_ext;
 std::map<std::string, std::shared_ptr<FileIO>> toc_streamcache;

 disc_type = DISC_TYPE_CDDA_OR_M1;
 TmpTrack = {};

 MDFN_GetFilePathComponents(path, &base_dir, &file_base, &file_ext);

 if(!strcasecmp(file_ext.c_str(), ".toc"))
 {
  MDFN_printf(_("TOC file detected.\n"));
  IsTOC = true;
 }

 // Check for annoying UTF-8 BOM.
 if(!IsTOC)
 {
  uint8 bom_tmp[3];

  if(fp.read(bom_tmp, 3) == 3 && bom_tmp[0] == 0xEF && bom_tmp[1] == 0xBB && bom_tmp[2] == 0xBF)
  {
   // Print an annoying error message, but don't actually error out.
   MDFN_PrintError(_("UTF-8 BOM detected at start of CUE sheet."));
  }
  else
   fp.seekS(0);
 }


 // Assign opposite maximum values so our tests will work!
 FirstTrack = 99;
 LastTrack = 0;

 linebuf.reserve(1024);
 while(get_line(fp, linebuf) >= 0)
 {
   unsigned argcount = 0;

   if(IsTOC)
   {
    // Handle TOC format comments
    size_t ss_loc = linebuf.find("//");

    if(ss_loc != std::string::npos)
     linebuf.resize(ss_loc);
   }

   // Call trim AFTER we handle TOC-style comments, so we'll be sure to remove trailing whitespace in lines like: MONKEY  // BABIES
   MDFN_trim(linebuf);

   if(linebuf.length() == 0)	// Skip blank lines.
    continue;

   // Grab command and arguments.
   {
    size_t offs = 0;

    offs = UnQuotify(linebuf, offs, cmdbuf, false);
    for(argcount = 0; argcount < max_args && offs < linebuf.length(); argcount++)
     offs = UnQuotify(linebuf, offs, args[argcount]);

    // Make sure unused arguments are cleared out so we don't have inter-line leaks!
    for(unsigned x = argcount; x < max_args; x++)
     args[x].clear();

    MDFN_strtoupper(cmdbuf);
   }

   //printf("%s\n", cmdbuf.c_str()); //: %s %s %s %s\n", cmdbuf.c_str(), args[0].c_str(), args[1].c_str(), args[2].c_str(), args[3].c_str());

   if(IsTOC)
   {
    if(cmdbuf == "TRACK")
    {
     if(active_track >= 0)
     {
    	Tracks[active_track] = TmpTrack;
    	TmpTrack = {};
      active_track = -1;
     }

     if(AutoTrackInc > 99)
     {
      throw(MDFN_Error(0, _("Invalid track number: %d"), AutoTrackInc));
//.........这里部分代码省略.........
开发者ID:kiorter,项目名称:emu-ex-plus-alpha,代码行数:101,代码来源:CDAccess_Image.cpp

示例3: ParseTOCFileLineInfo

void CDAccess_Image::ParseTOCFileLineInfo(CDRFILE_TRACK_INFO *track, const int tracknum, const std::string &filename, const char *binoffset, const char *msfoffset, const char *length, bool image_memcache, std::map<std::string, std::shared_ptr<FileIO>> &toc_streamcache)
{
 long offset = 0; // In bytes!
 long tmp_long;
 int m, s, f;
 uint32 sector_mult;
 long sectors;

 auto ribbit = toc_streamcache.find(filename);

 if(ribbit != toc_streamcache.end())
 {
  track->FirstFileInstance = 0;

  track->fp = ribbit->second;
 }
 else
 {
  std::string efn;

  track->FirstFileInstance = 1;

  efn = MDFN_EvalFIP(base_dir, filename);

  FileIO fp;
  fp.open(efn.c_str());
  if(!fp)
  {
  	throw MDFN_Error(0, "Error opening file \"%s\"", efn.c_str());
  }

  track->fp = std::make_shared<FileIO>(std::move(fp));
  toc_streamcache[filename] = track->fp;
 }

 if(filename.length() >= 4 && !strcasecmp(filename.c_str() + filename.length() - 4, ".wav"))
 {
  track->AReader = AR_Open(*track->fp);

  if(!track->AReader)
   throw MDFN_Error(0, "TODO ERROR");
 }

 sector_mult = DI_Size_Table[track->DIFormat];

 if(track->SubchannelMode)
  sector_mult += 96;

 if(binoffset && trio_sscanf(binoffset, "%ld", &tmp_long) == 1)
 {
  offset += tmp_long;
 }

 if(msfoffset && trio_sscanf(msfoffset, "%d:%d:%d", &m, &s, &f) == 3)
 {
  offset += ((m * 60 + s) * 75 + f) * sector_mult;
 }

 track->FileOffset = offset; // Make sure this is set before calling GetSectorCount()!
 sectors = GetSectorCount(track);
 //printf("Track: %d, offset: %ld, %ld\n", tracknum, offset, sectors);

 if(length)
 {
  tmp_long = sectors;

  if(trio_sscanf(length, "%d:%d:%d", &m, &s, &f) == 3)
   tmp_long = (m * 60 + s) * 75 + f;
  else if(track->DIFormat == DI_FORMAT_AUDIO)
  {
   char *endptr = NULL;

   tmp_long = strtol(length, &endptr, 10);

   // Error?
   if(endptr == length)
   {
    tmp_long = sectors;
   }
   else
    tmp_long /= 588;

  }

  if(tmp_long > sectors)
  {
   throw MDFN_Error(0, _("Length specified in TOC file for track %d is too large by %ld sectors!\n"), tracknum, (long)(tmp_long - sectors));
  }
  sectors = tmp_long;
 }

 track->sectors = sectors;
}
开发者ID:kiorter,项目名称:emu-ex-plus-alpha,代码行数:93,代码来源:CDAccess_Image.cpp


注:本文中的FileIO::open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。