示例#1
0
char *OGRTigerDataSource::BuildFilename( const char *pszModuleName,
                                         const char *pszExtension )

{
/* -------------------------------------------------------------------- */
/*      Force the record type to lower case if the filename appears     */
/*      to be in lower case.                                            */
/* -------------------------------------------------------------------- */
    char szLCExtension[3] = {};
    if( *pszExtension >= 'A' && *pszExtension <= 'Z' && *pszModuleName == 't' )
    {
        szLCExtension[0] = (*pszExtension) + 'a' - 'A';
        szLCExtension[1] = '\0';
        pszExtension = szLCExtension;
    }

/* -------------------------------------------------------------------- */
/*      Build the filename.                                             */
/* -------------------------------------------------------------------- */
    const size_t nFilenameLen =
        strlen(GetDirPath())
        + strlen(pszModuleName)
        + strlen(pszExtension) + 10;
    char *pszFilename = (char *) CPLMalloc(nFilenameLen);

    if( strlen(GetDirPath()) == 0 )
        snprintf( pszFilename, nFilenameLen, "%s%s",
                 pszModuleName, pszExtension );
    else
        snprintf( pszFilename, nFilenameLen, "%s/%s%s",
                 GetDirPath(), pszModuleName, pszExtension );

    return pszFilename;
}
示例#2
0
bool StageRealizer::Save(const TCHAR* dir, const TCHAR* basename, const Stage& stage, const MoveSequence& seq)
{
   {
      DWORD attr;
      std::basic_string< TCHAR > stagedir;

      stagedir = GetDirPath(dir, basename);
      attr = GetFileAttributes(stagedir.c_str());
      if (attr == -1) {
         return false;
      } else if ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0) {
         return false;
      }
   }

   if (! MoveRealizer::Save(dir, basename, seq)) {
      return false;
   }

   ::pb::Stage idea;
   if (! StageRealizer::Idealize(&idea, stage)) {
      return false;
   }

   std::basic_string< TCHAR > path, tmppath, oldpath;
   path = GetFilePath(dir, basename);
   tmppath.append(path).append(_T(".tmp"));
   oldpath.append(path).append(_T(".old"));

   {
      int fd = -1;
      errno_t err = _tsopen_s(&fd, tmppath.c_str(), 
                                 _O_WRONLY|_O_BINARY|_O_CREAT|_O_TRUNC, _SH_DENYWR, _S_IREAD|_S_IWRITE);
      if (err != 0) { goto fail; }
      
      google::protobuf::io::FileOutputStream out(fd);
      bool b = google::protobuf::TextFormat::Print(idea, &out);
      out.Flush();
      out.Close();

      if (!b) { goto fail; }
   }

   if (! DeleteFile(oldpath.c_str())) {
      DWORD err = GetLastError();
      if (err != ERROR_FILE_NOT_FOUND) { goto fail; }
   }

   MoveFile(path.c_str(), oldpath.c_str());
   if (! MoveFile(tmppath.c_str(), path.c_str())) { goto fail; }
   return true;

fail:
   return false;
}
示例#3
0
bool StageRealizer::Load(Stage** ppStage, MoveSequence** ppSeq, const TCHAR* basepath, const TCHAR* subdir, const MotionGuideList& mgl)
{
   if (ppStage == NULL) { return false; }
   if (basepath == NULL || basepath[0] == _T('\0')) { return false; }
   if (subdir == NULL || subdir[0] == _T('\0')) { return false; }
   if (! IsExist(basepath, subdir)) { return false; }

   MotionGuidePair mg;
   if (! MoveRealizer::IsExist(&mg, basepath, subdir, mgl)) { return false; }

   Stage* pStage = NULL;
   MoveSequence* pSeq = NULL;

   {
      int fd;
      std::basic_string< TCHAR > path = GetFilePath(basepath, subdir);
      errno_t err = _tsopen_s(&fd, path.c_str(),
                              _O_RDONLY|_O_BINARY, _SH_DENYWR, _S_IREAD|_S_IWRITE);
      if (err != 0) {
         return false;
      }

      ::pb::Stage idea;
      google::protobuf::io::FileInputStream in(fd);
      bool parsed = google::protobuf::TextFormat::Parse(&in, &idea);
      _close(fd);
      if (!parsed) {
         return false;
      }

      
      std::basic_string< TCHAR > dirpath = GetDirPath(basepath, subdir);
      if (! StageRealizer::Realize(&pStage, idea, subdir, dirpath.c_str())) {
         return false;
      }
   }

   if (ppSeq) {
      if (! MoveRealizer::Load(&pSeq, basepath, subdir, mg)) {
         goto fail;
      }
   }

   *ppStage = pStage;
   if (ppSeq) { *ppSeq = pSeq; }
   return true;

fail:
   if (pStage) { delete pStage; }
   if (pSeq) { delete pSeq; }
   if (ppStage) { *ppStage = NULL; }
   if (ppSeq) { *ppSeq = NULL; }
   return true;
}
示例#4
0
void OGRTigerDataSource::DeleteModuleFiles( const char *pszModule )

{
    char **papszDirFiles = VSIReadDir( GetDirPath() );
    const int nCount = CSLCount(papszDirFiles);

    for( int i = 0; i < nCount; i++ )
    {
        if( EQUALN(pszModule,papszDirFiles[i],strlen(pszModule)) )
        {
            const char *pszFilename = CPLFormFilename( GetDirPath(),
                                           papszDirFiles[i],
                                           nullptr );
            if( VSIUnlink( pszFilename ) != 0 )
            {
                CPLDebug( "OGR_TIGER", "Failed to unlink %s", pszFilename );
            }
        }
    }

    CSLDestroy( papszDirFiles );
}
示例#5
0
static GmWriter * createWriter (GmZipFileReader * pSetReader
									, GmUifSourceEntry * pEntry
									, GmRestOp option
									, GmExecUnitBase * pExecUnit
									, GmTempEvent * pEvent)
{
	GmWriter * pWriter = 0;
	wxString destPath;

	//pWriter = createWriter (FST_DIR_SOURCE, pExecUnit, option);
	destPath = ToWxString (pEntry->absolutePath);
	destPath =GetDirPath (destPath);

	assert (pWriter != 0);
	pWriter->SetDestPath (destPath);

	return pWriter;	
}
示例#6
0
Genome::Genome(std::string file)
{
	filename = file;
	CfgList* d = CfgList::LoadFile(file);

	// read sequence data
	const char* seqfile = d->GetLiteral("SequenceFile");
	std::string seqPath = GetDirPath(file) + seqfile;
	sequence = ReadTextFile(seqPath);
	std::transform(sequence.begin(), sequence.end(), sequence.begin(), ::tolower);

	// load global properties

	name = d->GetLiteral("LocusName");
	topology = d->GetLiteral("LocusTopology");
	modificationDate = d->GetLiteral("LocusModificationDate");
	definition = d->GetLiteral("Definition");
	source = d->GetLiteral("Source");

	// load features
	CfgList* features = d->GetList("features");
	mvec<FeatureProtein*> proteins = LoadFeatureList<FeatureProtein>(features->GetList("CDS"));
	members_ptr(proteins, &FeatureProtein::type) |= FeatureProtein::Type_Protein;
	
	mvec<Feature*> tRNA = LoadFeatureList<Feature>(features->GetList("tRNA"));
	members_ptr(tRNA, &Feature::type) |= Feature::Type_tRNA;

	mvec<Feature*> rRNA = LoadFeatureList<Feature>(features->GetList("rRNA"));
	members_ptr(rRNA, &Feature::type) |= Feature::Type_rRNA;

	mvec<Feature*> misc_RNA = LoadFeatureList<Feature>(features->GetList("misc_RNA"));
	members_ptr(misc_RNA, &Feature::type) |= Feature::Type_MiscRNA;

	mvec<Feature*> misc_feature = LoadFeatureList<Feature>(features->GetList("misc_feature"));
	members_ptr(misc_feature, &Feature::type) |= Feature::Type_MiscFeature;

	genes = tRNA & rRNA & misc_RNA & misc_feature & proteins;

	// sort genes
	std::sort(genes.begin(), genes.end(), GeneComparer);

	delete d;
}
示例#7
0
bool StageRealizer::SaveNew(const TCHAR* dir, const TCHAR* basename0, Stage& stage, const MoveSequence& seq)
{
   std::basic_string< TCHAR > basename;
   std::basic_string< TCHAR > stagedir;
   {
      basename = basename0;
      stagedir = GetDirPath(dir, basename0);
      DWORD attr = GetFileAttributes(stagedir.c_str());
      if (attr == -1) {
         ;
      } else {
         const TCHAR* pc;
         int n = 0;
         for (pc = basename0; *pc != _T('\0'); ++pc);
         for (--pc; _T('0') <= *pc && *pc <= _T('9'); --pc) {
            n *= 10;
            n += (*pc - _T('0'));
         }
         ++pc;
         std::basic_string<TCHAR> alpha(basename0, pc-basename0);
         for (++n; ; ++n) {
            std::basic_ostringstream< TCHAR > o;
            o << alpha << n;
            basename = o.str();
            stagedir = GetDirPath(dir, basename.c_str());
            attr = GetFileAttributes(stagedir.c_str());
            if (attr == -1) { break; }
         }
      }
      if (attr != -1) {
         return false;
      }
   }

   if (! CreateDirectory(stagedir.c_str(), NULL)) {
      return false;
   }

   const TCHAR *moviefile;
   {
      moviefile = stage.tc_moviepath.c_str();
      for (const TCHAR* pc=moviefile; *pc != _T('\0'); ++pc) {
         if (*pc == _T('\\') || *pc == _T('/')) { moviefile = pc+1; }
      }
      std::basic_ostringstream< TCHAR > o;
      o << stagedir << _T("\\") << moviefile;
      std::basic_string< TCHAR > moviepath1 = o.str();
      if (! CopyFile(stage.tc_moviepath.c_str(), moviepath1.c_str(), true)) {
         RemoveDirectory(stagedir.c_str());
         return false;
      }
   }
   stage.tc_moviepath = moviefile;
   stage.tc_basename = basename;
   {
      char* tmp;
      tmp = ::bootes::lib::util::TChar::T2C(stage.tc_moviepath.c_str());
      if (tmp == NULL) { return false; }
      stage.moviepath = tmp;
      delete[] tmp;
      tmp = ::bootes::lib::util::TChar::T2C(stage.tc_basename.c_str());
      if (tmp == NULL) { return false; }
      stage.basename = tmp;
      delete[] tmp;
   }
   if (! Save(dir, basename.c_str(), stage, seq)) {
      return false;
   }
   return true;
}