static nsresult GetMimeExtensions(const char *mimeType, char *extensions, int extLen)
{
    // check variables
    if (!mimeType || !extensions || extLen < 1) return NS_ERROR_FAILURE;
    extensions[0] = '\0';
    
    // make mime object
    BMimeType mime(mimeType) ;
    if (mime.InitCheck() != B_OK)
        return NS_ERROR_FAILURE;
    
    // get extensions : comma separated (if multiple extensions in a mime-type)
    // ex) "jpg,jpeg"
    BString extStr("");
    BMessage extMsg;
    mime.GetFileExtensions(&extMsg);
    uint32 type;
    int32 types_num;
    if (extMsg.GetInfo("extensions", &type, &types_num) != B_OK
        || type != B_STRING_TYPE || types_num == 0)
        return NS_ERROR_FAILURE;
    
    for (int i = 0 ; i < types_num ; i ++) {
        const char *ext;
        if (extMsg.FindString("extensions", i, &ext) != B_OK) {
            break;
        }
        if (i > 0)
            extStr.Append(",");
        extStr.Append(ext);
    }
    PL_strncpyz(extensions, extStr.String(), extLen) ;
    
    return NS_OK;
}
//----------------------------------------------------------------------------------------
// FetchAdsFileFromPath
//----------------------------------------------------------------------------------------
bool
ZMFileUtils::FetchAdsFileFromPath(
	const PMString&						parentPath,
	ZMPMStringSList &					oAdsList,
	const PMString&						inFilePrefix) const
{
	LogFunctionEnterExit;
	
	IZPLog_Str_( thisFileLA, enLT_DebugInfo, "From path : %s", parentPath.GrabCString());
	SDKFileHelper fileHelper(parentPath);
	IDFile fileId = fileHelper.GetIDFile();
	PlatformFileSystemIterator iter;
	if(!iter.IsDirectory(fileId))
		return false;

	iter.SetStartingPath(fileId);

	Utils<IZMAdFileFacade> adFileUtil;
	bool result = false;
	IDFile xmlIdFile;

	PMString filter(inFilePrefix);
	filter.Append("*.xml");
	filter.InsertW(FileUtils::GetDirectorySeperator(), 0);
	IZPLog_Str_( thisFileLA, enLT_DebugInfo, "File filter : %s", filter.GrabCString());

	bool16 hasNext = iter.FindFirstFile(xmlIdFile, filter);

	while(hasNext) {
		SDKFileHelper xmlFileHelper(xmlIdFile);
		
		PMString xmlFileName = xmlIdFile.GetFileName();
		if(ValidPath(xmlFileName))
		{
#ifdef MACINTOSH
			PMString extStr(".xml");
			extStr.SetTranslatable(kFalse);
			if (! VerifyPrefixAndSuffix(xmlFileName, inFilePrefix, extStr))
			{
				hasNext= iter.FindNextFile(xmlIdFile);
				continue;
			}
#endif
			
			PMString xmlFullPath (parentPath);
			xmlFullPath.Append(FileUtils::GetDirectorySeperator());
			xmlFullPath.Append(xmlFileName);

			if (adFileUtil->CanBeValidXMLFile(xmlFullPath))
			{
				oAdsList.push_back(new PMString(xmlIdFile.GetFileName()));
				result = true;
			}
		}

		hasNext= iter.FindNextFile(xmlIdFile);
	}

	return result;
}
Beispiel #3
0
	/*static*/
	bool Script::HasExtension(const char *script, const char *extension)
	{
		std::string scriptStr(script);
		std::string extStr(".");
		extStr += extension;
		
		return scriptStr.size() >= extStr.size() && scriptStr.substr(scriptStr.size()-extStr.size()) == extStr;
	}
string PfileHeaderReader::ReadExtension(rmscrypto::api::SharedStream stream,
                                        uint32_t                     offset,
                                        uint32_t                     length)
{
  ByteArray ext;

  if (offset >= stream->Size()) {
    throw exceptions::RMSPFileException("Bad extension",
                                        exceptions::RMSPFileException::BadArguments);
  }

  ReadAtOffset(ext, stream, offset, length);
  string extStr(ext.begin(), ext.end());

  Logger::Hidden("PfileHeaderReader: Extension: %s", extStr.c_str());

  return extStr;
}
Beispiel #5
0
CFtpDialog::CFtpDialog(BRect frame, const char *name, window_type type, int flags,
	BWindow *owner)
	: HDialog(frame, name, type, flags, owner, NULL)
{

	fReply = new char[1024];
	fPath = new char[PATH_MAX];
	fSave = false;
	fSocket = -1;

	Create();
	Layout();

#if 0
	// Build Extension->Mimetype list // Takes looong
	typedef pair<string,string> entry;
	BMessage mimDat;
	BMessage extDat;
	BMimeType mimTyp;
	int32 mimIdx = -1;
	int32 extIdx = 0;
	const char* mimCStr;
	const char* extCStr;
	if (BMimeType::GetInstalledTypes(&mimDat) == B_OK) {
		while (mimDat.FindString("types", ++mimIdx, &mimCStr) == B_OK) {
			if ((mimTyp.SetTo(mimCStr) == B_OK) && (mimTyp.GetFileExtensions(&extDat) == B_OK)) {
				extIdx = -1;
				while (extDat.FindString("extensions", ++extIdx, &extCStr) == B_OK) {
					BString extStr(extCStr);
					extStr.ToLower();
					if (extStr.ByteAt(0) == '.')  extStr.Remove(0, 1);
					fExtMime[extCStr] = mimCStr;
				}
			}
		}
	}
#else
	// perhaps it's better to go with some predefiend types:
	fExtMime["aiff"] = "audio/x-aiff";
	fExtMime["bz2"] = "application/x-bzip2";
	fExtMime["cc"] = "text/x-source-code";
	fExtMime["cpp"] = "text/x-source-code";
	fExtMime["css"] = "text/css";
	fExtMime["gif"] = "image/gif";
	fExtMime["gz"] = "application/x-gzip";
	fExtMime["h"] = "text/x-source-code";
	fExtMime["htm"] = "text/html";
	fExtMime["html"] = "text/html";
	fExtMime["jpeg"] = "image/jpeg";
	fExtMime["jpg"] = "image/jpeg";
	fExtMime["mod"] = "audio/x-mod";
	fExtMime["mov"] = "video/quicktime";
	fExtMime["mp3"] = "audio/x-mpeg";
	fExtMime["ogg"] = "audio/ogg.vorbis";
	fExtMime["pdf"] = "application/pdf";
	fExtMime["php"] = "text/x-php";
	fExtMime["pl"] = "text/x-perl";
	fExtMime["pkg"] = "application/x-scode-UPkg";
	fExtMime["png"] = "image/png";
	fExtMime["py"] = "text/x-source-code";
	fExtMime["rar"] = "application/x-rar";
	fExtMime["swf"] = "application/x-shockwave-flash";
	fExtMime["tar"] = "application/x-tar";
	fExtMime["tga"] = "image/x-targa";
	fExtMime["tgz"] = "application/x-gzip";
	fExtMime["txt"] = "text/plain";
	fExtMime["xml"] = "text/xml";
	fExtMime["zip"] = "application/zip";
#endif

} // CFtpDialog::CFtpDialog
Beispiel #6
0
void
VisItDataServerPrivate::ReadData(const std::string &var)
{
    // Set some defaults.
    MaterialAttributes       mAtts;
    ExpressionList           combinedExprList(exprList);
    MeshManagementAttributes meshAtts;
    bool                     treatAllDbsAsTimeVarying = false;
    bool                     ignoreExtents = true;
    std::string              selectionName;
    int                      windowID = 0;

    //
    // Tickle the engine to create a vis window. Works around a bug in engine!
    //
    if(!createdVisWin)
    {
        createdVisWin = true;

        // Set some defaults.
        WindowAttributes     windowAtts;
        windowAtts.SetColorTables(*avtColorTables::Instance()->GetColorTables());
        AnnotationAttributes annotationAtts;
        AnnotationObjectList annotationObjectList;
        std::string          extStr("?");
        VisualCueList        visCues;
        int                  frameAndState[] = {0,0,0,0,0,0,0};
        double               viewExtents[] = {0., 1., 0., 1., 0., 1.};
        std::string          ctName("hot");

        engine.GetEngineMethods()->SetWinAnnotAtts(&windowAtts,
                               &annotationAtts,
                               &annotationObjectList,
                               extStr,
                               &visCues,
                               frameAndState,
                               viewExtents,
                               ctName,
                               windowID);
    }

    //
    // Determine the name of the mesh for this variable.
    //
    const avtDatabaseMetaData *md = GetMetaData(openFile);
    if(md == NULL)
    {
        EXCEPTION1(VisItException, "Can't get the metadata.");
    }
    std::string mesh = md->MeshForVar(var);
    // Add the metadata expressions to the known expressions.
    for(int i = 0; i < md->GetNumberOfExpressions(); ++i)
        combinedExprList.AddExpressions(*md->GetExpression(i));

    //
    // Get the SIL so we can make a SIL restriction.
    //
    const SILAttributes *silAtts = mdserver.GetMDServerMethods()->GetSIL(openFile, openTimeState,
                                                   treatAllDbsAsTimeVarying);
    if(silAtts == NULL)
    {
        EXCEPTION1(VisItException, "Can't get the SIL.");
    }
    avtSIL sil(*silAtts);
    avtSILRestriction_p silr = new avtSILRestriction(&sil);
    silr->SetTopSet(mesh.c_str());

    //
    // Start a new network
    //
    engine.GetEngineMethods()->ReadDataObject(openFileFormat,
                          openFile,
                          var,
                          openTimeState,
                          silr,
                          mAtts,  // lots of junk!
                          combinedExprList,
                          meshAtts,
                          treatAllDbsAsTimeVarying,
                          ignoreExtents,
                          selectionName,
                          windowID);
}