コード例 #1
0
ファイル: php_utils.cpp プロジェクト: 292388900/codelite
bool IsPHPFileByExt(const wxString& filename)
{
    wxFileName fileName = filename;
    LexerConf::Ptr_t lexer = EditorConfigST::Get()->GetLexer(wxT("php"));
    wxString fileSpec;

    if(!lexer) {
        // Incase somehow we failed in retrieving the lexer (corrupted XML file)
        // use some hardcoded file spec
        fileSpec = wxT("*.php;*.inc;*.phtml");

    } else {
        fileSpec = lexer->GetFileSpec();
    }

    wxStringTokenizer tkz(fileSpec, wxT(";"));
    while(tkz.HasMoreTokens()) {
        wxString fileExt = tkz.NextToken();
        wxString fullname = fileName.GetFullName();

        fileExt.MakeLower();
        fullname.MakeLower();
        if(wxMatchWild(fileExt, fullname)) {
            return true;
        }
    }
    return false;
}
コード例 #2
0
ファイル: reconcileproject.cpp プロジェクト: Alexpux/codelite
    virtual wxDirTraverseResult OnFile(const wxString& filename)
    {
        wxFileName fn(filename);

        // First check for a matching file-ignore
        for(size_t n = 0; n < m_ignorefiles.GetCount(); ++n) {
            if(wxMatchWild(m_ignorefiles.Item(n), fn.GetFullName())) {
                return wxDIR_CONTINUE;
            }
        }

        if(m_types.empty()) {
            m_results.Add(filename); // No types presumably means everything
        } else {
            for(size_t n = 0; n < m_types.GetCount(); ++n) {
                if(m_types.Item(n) == fn.GetExt() || m_types.Item(n) == "*" ||
                   m_types.Item(n) == "*.*") { // Other ways to say "Be greedy"
                    m_results.Add(fn.GetFullPath());
                    break;
                }
            }
        }

        return wxDIR_CONTINUE;
    }
コード例 #3
0
wxString wxZipFSHandler::DoFind()
{
    wxString namestr, dir, filename;
    wxString match = wxEmptyString;

    while (match == wxEmptyString)
    {
        wxZipEntry *entry = m_Archive->GetNextEntry();
        if (!entry)
        {
            delete m_Archive;
            m_Archive = NULL;
            break;
        }
        namestr = entry->GetName(wxPATH_UNIX);
        delete entry;

        if (m_AllowDirs)
        {
            dir = namestr.BeforeLast(wxT('/'));
            while (!dir.empty())
            {
                if( m_DirsFound->find(dir) == m_DirsFound->end() )
                {
                    (*m_DirsFound)[dir] = 1;
                    filename = dir.AfterLast(wxT('/'));
                    dir = dir.BeforeLast(wxT('/'));
                    if (!filename.empty() && m_BaseDir == dir &&
                                wxMatchWild(m_Pattern, filename, false))
                        match = m_ZipFile + wxT("#zip:") + dir + wxT("/") + filename;
                }
                else
                    break; // already tranversed
            }
        }

        filename = namestr.AfterLast(wxT('/'));
        dir = namestr.BeforeLast(wxT('/'));
        if (m_AllowFiles && !filename.empty() && m_BaseDir == dir &&
                            wxMatchWild(m_Pattern, filename, false))
            match = m_ZipFile + wxT("#zip:") + namestr;
    }

    return match;
}
コード例 #4
0
bool t4p::ExplorerFileSystemActionClass::MatchesWildcards(const wxString& fileName) {
    if (Extensions.empty()) {
        return true;
    }
    for (size_t i = 0; i < Extensions.size(); ++i) {
        if (wxMatchWild(Extensions[i], fileName)) {
            return true;
        }
    }
    return false;
}
コード例 #5
0
static bool projectinfo_match(const wxString& path, const wxArrayString& includes, const wxArrayString& excludes) {
	if (!includes.IsEmpty()) {
		bool doInclude = false;
		for (unsigned int i = 0; i < includes.GetCount(); ++i) {
			if (wxMatchWild(includes[i], path, false)) {
				doInclude = true;
				break;
			}
		}

		if (!doInclude) return false;
	}

	for (unsigned int i = 0; i < excludes.GetCount(); ++i) {
		if (wxMatchWild(excludes[i], path, false)) {
			return false;
		}
	}

	return true;
}
コード例 #6
0
ファイル: SubMainFrame.cpp プロジェクト: murdockq/OpenPaint
 virtual bool OnDropFiles(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
                          const wxArrayString& filenames)
     {
         if(filenames.GetCount() == 1)
         {
             if(wxMatchWild(wxT("*.*"), filenames.Last()))
             {
                 Globals::Instance()->GetMainFrame()->OpenFile(filenames.Last());
             }
             else
             {
                 wxLogError(wxT("Invalid File."));
             }
         }
         return true;
     }
コード例 #7
0
void OpenResourceDialog::DoPopulateWorkspaceFile()
{
	wxArrayString tmpArr;
	wxString curSel = m_textCtrlResourceName->GetValue();
	if (!curSel.Trim().Trim(false).IsEmpty()) {

		curSel = curSel.MakeLower().Trim().Trim(false);

		for (size_t i=0; i<m_files.GetCount(); i++) {
			wxString fileName(m_files.Item(i));
			wxString fileNameOnly(wxFileName(fileName).GetFullName());

			fileNameOnly.MakeLower();

			//append wildcard at the end
			if (!curSel.EndsWith(wxT("*"))) {
				curSel << wxT("*");
			}

			// FR# [2008133]
			if (m_checkBoxUsePartialMatching->IsChecked() && !curSel.StartsWith(wxT("*"))) {
				curSel.Prepend(wxT("*"));
			}

			if (wxMatchWild(curSel, fileNameOnly)) {
				// keep the fullpath
				tmpArr.Add(m_files.Item(i));
			}
		}
	}

	// Change was done, update the file list
	for (size_t i=0; i<tmpArr.GetCount(); i++) {
		wxFileName fn(tmpArr.Item(i));
		DoAppendLine(fn.GetFullName(), fn.GetFullPath(), wxT(""), false, new OpenResourceDialogItemData(tmpArr.Item(i), -1, wxT(""), OpenResourceDialog::TYPE_WORKSPACE_FILE, wxT(""), wxT("")));
		
		if( i == 150 ) {
			m_staticTextErrorMessage->SetLabel(wxT("Too many matches, please narrow down your search"));
			break;
		}
	}

	if (m_listOptions->GetItemCount() > 0) {
		DoSelectItem(0);
	}
}
コード例 #8
0
ファイル: ExwordDevice.cpp プロジェクト: brijohn/exword_tools
DirEnts Exword::List(wxString path, wxString pattern)
{
    exword_dirent_t *entries;
    uint16_t count;
    DirEnts list;
    wxString fullpath = GetStoragePath() + path;
    if (IsConnected()) {
        if (exword_setpath(m_device, (uint8_t*)fullpath.utf8_str().data(), 0) == EXWORD_SUCCESS) {
            if (exword_list(m_device, &entries, &count) == EXWORD_SUCCESS) {
                for (int i = 0; i < count; i++) {
                    DirEntry entry(&entries[i]);
                    if (wxMatchWild(pattern.Lower(), entry.GetFilename().Lower(), true))
                        list.Add(entry);
                }
                exword_free_list(entries);
            }
        }
    }
    return list;
}
コード例 #9
0
    // Will return true if the given event file and flags
    // match the filespec and event flags given to the
    // AddTree method.
    bool IsDesiredEvent(const wxFileName& eventFileName, int eventFlags)
    {
        // warning and errors are always sent to the event handler
        if ( eventFlags & wxFSW_EVENT_ERROR )
        {
            return true;
        }
        if ( eventFlags & wxFSW_EVENT_WARNING )
        {
            return true;
        }

        if ( (m_watcherEventFlags & eventFlags) == 0 )
        {
        // event handler does not want to see this event
            return false;
        }

        return m_filespec.empty() ||
            wxMatchWild(m_filespec, eventFileName.GetFullName());
    }
コード例 #10
0
ContextBasePtr ContextManager::NewContextByFileName (LEditor *parent, const wxFileName &fileName)
{
	EditorConfig::ConstIterator iter = EditorConfigST::Get()->LexerBegin();
	for ( ; iter != EditorConfigST::Get()->LexerEnd(); iter++ ) {
		LexerConfPtr lexer = iter->second;
		wxString lexExt = lexer->GetFileSpec();
		wxStringTokenizer tkz ( lexExt, wxT ( ";") );
		while ( tkz.HasMoreTokens() ) {
			wxString ext      = tkz.NextToken();
			wxString fullname = fileName.GetFullName();

			ext.MakeLower(); fullname.MakeLower();
			if ( wxMatchWild ( ext, fullname ) ) {
				return ContextManager::Get()->NewContext ( parent, lexer->GetName() );
			}
		}
	}

	// return the default context
	return ContextManager::Get()->NewContext ( parent, wxT ( "Text") );
}
コード例 #11
0
ファイル: ProjectClass.cpp プロジェクト: 62BRAINS/triumph4php
bool t4p::ProjectClass::IsASourceFile(const wxString& fullPath, const t4p::FileTypeClass& fileType) const {
    bool matches = false;

    // first do a directory check  only. since AllSources() clones the
    // Sources list; it can be expensive due to regex re-compilation of the
    // wildcards. for performance, we make sure that the file in question
    // is definitely in the sources before we copy the sources list
    std::vector<t4p::SourceClass>::const_iterator source;
    for (source = Sources.begin(); source < Sources.end() && !matches; ++source) {
        matches = source->IsInRootDirectory(fullPath);
    }
    if (matches) {
        matches = false;

        // a file is considered a file if its in a source directory and it matches
        // any of the recognized file extensions
        std::vector<wxString> allExtensions = fileType.GetAllSourceFileExtensions();
        std::vector<wxString>::const_iterator s;
        for (s = allExtensions.begin(); !matches && s != allExtensions.end(); ++s) {
            matches = wxMatchWild(*s, fullPath);
        }
    }
    return matches;
}
コード例 #12
0
void mbCmdForEachDir::Execute(mbCommands& stack)
{
	mbDirTraverser traverser;
	wxString idref;

	MB_CMD_GUARD_OPT;
	bool hidden = ParseBool(wxT("Hidden"), true, wxT("yes"));
	bool recurse = ParseBool(wxT("Recurse"), true);
	bool reverse = ParseBool(wxT("Reverse"), true);
	wxString id = ParseProp(wxT("Id"), true, wxT("ForEach"));
	wxString path = ParseProp(wxT("Path"), false);

	wxString flagstr;
	int flags = 0;
	if( hidden )
	{
		flags |= wxDIR_HIDDEN;
		flagstr += wxT("Hidden ");
	}
	if( recurse )
	{
		flags |= wxDIR_DIRS;
		flagstr += wxT("Recurse ");
	}
	if( reverse )
	{
		flagstr += wxT("Reverse ");
	}

	wxFileName fname = wxFileName(path);
	wxString filespec = fname.GetFullName();


	PrintExecute(stack, wxT("%s %s %s"), fname.GetPathWithSep().c_str(), filespec.c_str(), flagstr.c_str() );

	traverser = mbDirTraverser::Init( fname.GetPathWithSep(), filespec, flags, reverse );
	idref = id;

	// Optional parameter does not affect ForEachFile child elements so stop here
	MB_CMD_UNGUARD_OPT;

	for( mbDirTraverser ft=traverser; ft; ++ft )
	{
		GmbVariables().PushLocal(GetDebugId(&stack), idref, ft.GetPath() );

		for( mbCommands::iterator it=m_commands.begin(); it!=m_commands.end(); ++it )
		{
			// Special Ignore elements
			if( wxString(wxT("Ignore")).IsSameAs((*it)->GetName()) )
			{
				// Parse ignore mask, if matches current file then skip to next file
				if( wxMatchWild((*it)->ParseProp(wxT("Id"), false), ft.GetPath(), false) )
					break;
			}
			else
			{
				// Execute other children elements normally
				mbCmd::StaticExecute(stack, *it);
			}
		}

		GmbVariables().PopLocal(GetDebugId(&stack));
	}
}
コード例 #13
0
ファイル: Import.cpp プロジェクト: Kirushanr/audacity
// returns number of tracks imported
int Importer::Import(wxString fName,
                     TrackFactory *trackFactory,
                     Track *** tracks,
                     Tags *tags,
                     wxString &errorMessage)
{
   ImportFileHandle *inFile = NULL;
   int numTracks = 0;

   wxString extension = fName.AfterLast(wxT('.'));

   // This list is used to call plugins in correct order
   ImportPluginList importPlugins;
   ImportPluginList::compatibility_iterator importPluginNode;

   // This list is used to remember plugins that should have been compatible with the file.
   ImportPluginList compatiblePlugins;
   
   // If user explicitly selected a filter,
   // then we should try importing via corresponding plugin first
   wxString type = gPrefs->Read(wxT("/LastOpenType"),wxT(""));
   
   // Not implemented (yet?)
   wxString mime_type = wxT("*");

   // First, add user-selected filter
   bool usersSelectionOverrides;
   // False if override filter is not found
   bool foundOverride = false;
   gPrefs->Read(wxT("/ExtendedImport/OverrideExtendedImportByOpenFileDialogChoice"), &usersSelectionOverrides, false);
   wxLogDebug(wxT("LastOpenType is %s"),type.c_str());
   wxLogDebug(wxT("OverrideExtendedImportByOpenFileDialogChoice is %i"),usersSelectionOverrides);
   if (usersSelectionOverrides)
   {
      
      importPluginNode = mImportPluginList->GetFirst();
      while(importPluginNode)
      {
         ImportPlugin *plugin = importPluginNode->GetData();
         if (plugin->GetPluginFormatDescription().CompareTo(type) == 0)
         {
            // This plugin corresponds to user-selected filter, try it first.
            wxLogDebug(wxT("Inserting %s"),plugin->GetPluginStringID().c_str());
            importPlugins.Insert(plugin);
            foundOverride = true;
         }
         importPluginNode = importPluginNode->GetNext();
      }
   }
   bool foundItem = false;
   wxLogMessage(wxT("File name is %s"),fName.Lower().c_str());
   wxLogMessage(wxT("Mime type is %s"),mime_type.Lower().c_str());
   for (size_t i = 0; i < mExtImportItems->Count(); i++)
   {
      ExtImportItem *item = &(*mExtImportItems)[i];
      bool matches_ext = false, matches_mime = false;
      wxLogDebug(wxT("Testing extensions"));
      for (size_t j = 0; j < item->extensions.Count(); j++)
      {
         wxLogDebug(wxT("%s"),item->extensions[j].Lower().c_str());
         if (wxMatchWild (item->extensions[j].Lower(),fName.Lower(), false))
         {
            wxLogDebug(wxT("Match!"));
            matches_ext = true;
            break;
         }
      }
      if (item->extensions.Count() == 0)
      {
         wxLogDebug(wxT("Match! (empty list)"));
         matches_ext = true;
      }
      if (matches_ext)
         wxLogDebug(wxT("Testing mime types"));
      else
         wxLogDebug(wxT("Not testing mime types"));
      for (size_t j = 0; matches_ext && j < item->mime_types.Count(); j++)
      {
         if (wxMatchWild (item->mime_types[j].Lower(),mime_type.Lower(), false))
         {
            wxLogDebug(wxT("Match!"));
            matches_mime = true;
            break;
         }
      }
      if (item->mime_types.Count() == 0)
      {
         wxLogDebug(wxT("Match! (empty list)"));
         matches_mime = true;
      }
      if (matches_ext && matches_mime)
      {
         wxLogDebug(wxT("Complete match!"));
         for (size_t j = 0; j < item->filter_objects.Count() && (item->divider < 0 || (int) j < item->divider); j++)
         {
            wxLogDebug(wxT("Inserting %s"),item->filter_objects[j]->GetPluginStringID().c_str());
            importPlugins.Append(item->filter_objects[j]);
         }
         foundItem = true;
      }
   }

   if (!foundItem || (usersSelectionOverrides && !foundOverride))
   {
      bool prioritizeMp3 = false;
      if (usersSelectionOverrides && !foundOverride)
         importPlugins.Clear();
      wxLogDebug(wxT("Applying default rule"));
      // Special treatment for mp3 files
      if (wxMatchWild (wxT("*.mp3"),fName.Lower(), false))
         prioritizeMp3 = true;
      // By default just add all plugins (except for MP3)
      importPluginNode = mImportPluginList->GetFirst();
      while(importPluginNode)
      {
         ImportPlugin *plugin = importPluginNode->GetData();
         if (importPlugins.Find(plugin) == NULL)
         {
            // Skip MP3 import plugin. Opens some non-mp3 audio files (ac3 for example) as garbage.
            if (plugin->GetPluginFormatDescription().CompareTo( _("MP3 files") ) != 0)
            {
               wxLogDebug(wxT("Inserting %s"),plugin->GetPluginStringID().c_str());
               importPlugins.Append(plugin);
            }
            else if (prioritizeMp3)
            {
               if (usersSelectionOverrides)
               {
                  wxLogDebug(wxT("Inserting %s at 1"),plugin->GetPluginStringID().c_str());
                  importPlugins.Insert((size_t) 1, plugin);
               }
               else
               {
                  wxLogDebug(wxT("Inserting %s at 0"),plugin->GetPluginStringID().c_str());
                  importPlugins.Insert((size_t) 0, plugin);
               }
            }
         }
         importPluginNode = importPluginNode->GetNext();
      }
   }

   importPluginNode = importPlugins.GetFirst();
   while(importPluginNode)
   {
      ImportPlugin *plugin = importPluginNode->GetData();
      // Try to open the file with this plugin (probe it)
      wxLogMessage(wxT("Opening with %s"),plugin->GetPluginStringID().c_str());
      inFile = plugin->Open(fName);
      if ( (inFile != NULL) && (inFile->GetStreamCount() > 0) )
      {
         wxLogMessage(wxT("Open(%s) succeeded"), fName.Lower().c_str());
         // File has more than one stream - display stream selector
         if (inFile->GetStreamCount() > 1)                                                  
         {
            ImportStreamDialog ImportDlg(inFile, NULL, -1, _("Select stream(s) to import"));

            if (ImportDlg.ShowModal() == wxID_CANCEL)
            {
               delete inFile;
               return 0;
            }
         }
         // One stream - import it by default
         else
            inFile->SetStreamUsage(0,TRUE);

         int res;
         
         res = inFile->Import(trackFactory, tracks, &numTracks, tags);

         delete inFile;

         if (res == eProgressSuccess || res == eProgressStopped)
         {
            // LOF ("list-of-files") has different semantics
            if (extension.IsSameAs(wxT("lof"), false))
               return 1;

            if (numTracks > 0) {
               // success!
               return numTracks;
            }
         }

         if (res == eProgressCancelled || res == eProgressFailed)
         {
            return 0;
         }

         // We could exit here since we had a match on the file extension,
         // but there may be another plug-in that can import the file and
         // that may recognize the extension, so we allow the loop to
         // continue.
      }
      importPluginNode = importPluginNode->GetNext();
   }
   wxLogError(wxT("Importer::Import: Opening failed."));
   // None of our plugins can handle this file.  It might be that
   // Audacity supports this format, but support was not compiled in.
   // If so, notify the user of this fact
   UnusableImportPluginList::compatibility_iterator unusableImporterNode
      = mUnusableImportPluginList->GetFirst();
   while(unusableImporterNode)
   {
      UnusableImportPlugin *unusableImportPlugin = unusableImporterNode->GetData();
      if( unusableImportPlugin->SupportsExtension(extension) )
      {
         errorMessage.Printf(_("This version of Audacity was not compiled with %s support."),
                             unusableImportPlugin->
                             GetPluginFormatDescription().c_str());
         return 0;
      }
      unusableImporterNode = unusableImporterNode->GetNext();
   }

   /* warnings for unsupported data types */

#ifdef USE_MIDI
   // MIDI files must be imported, not opened
   if ((extension.IsSameAs(wxT("midi"), false))||(extension.IsSameAs(wxT("mid"), false))) {
      errorMessage.Printf(_("\"%s\" \nis a MIDI file, not an audio file. \nAudacity cannot open this type of file for playing, but you can\nedit it by clicking File > Import > MIDI."), fName.c_str());
      return 0;
   }
#endif

   if (compatiblePlugins.GetCount() <= 0)
   {
      // if someone has sent us a .cda file, send them away
      if (extension.IsSameAs(wxT("cda"), false)) {
         /* i18n-hint: %s will be the filename */
         errorMessage.Printf(_("\"%s\" is an audio CD track. \nAudacity cannot open audio CDs directly. \nExtract (rip) the CD tracks to an audio format that \nAudacity can import, such as WAV or AIFF."), fName.c_str());
         return 0;
      }
   
      // playlist type files
      if ((extension.IsSameAs(wxT("m3u"), false))||(extension.IsSameAs(wxT("ram"), false))||(extension.IsSameAs(wxT("pls"), false))) {
         errorMessage.Printf(_("\"%s\" is a playlist file. \nAudacity cannot open this file because it only contains links to other files. \nYou may be able to open it in a text editor and download the actual audio files."), fName.c_str());
         return 0;
      }
      //WMA files of various forms
      if ((extension.IsSameAs(wxT("wma"), false))||(extension.IsSameAs(wxT("asf"), false))) {
         errorMessage.Printf(_("\"%s\" is a Windows Media Audio file. \nAudacity cannot open this type of file due to patent restrictions. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName.c_str());
         return 0;
      }
      //AAC files of various forms (probably not encrypted)
      if ((extension.IsSameAs(wxT("aac"), false))||(extension.IsSameAs(wxT("m4a"), false))||(extension.IsSameAs(wxT("m4r"), false))||(extension.IsSameAs(wxT("mp4"), false))) {
         errorMessage.Printf(_("\"%s\" is an Advanced Audio Coding file. \nAudacity cannot open this type of file. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName.c_str());
         return 0;
      }
      // encrypted itunes files
      if ((extension.IsSameAs(wxT("m4p"), false))) {
         errorMessage.Printf(_("\"%s\" is an encrypted audio file. \nThese typically are from an online music store. \nAudacity cannot open this type of file due to the encryption. \nTry recording the file into Audacity, or burn it to audio CD then \nextract the CD track to a supported audio format such as WAV or AIFF."), fName.c_str());
         return 0;
      }
      // Real Inc. files of various sorts
      if ((extension.IsSameAs(wxT("ra"), false))||(extension.IsSameAs(wxT("rm"), false))||(extension.IsSameAs(wxT("rpm"), false))) {
         errorMessage.Printf(_("\"%s\" is a RealPlayer media file. \nAudacity cannot open this proprietary format. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName.c_str());
         return 0;
      }
   
      // Other notes-based formats
      if ((extension.IsSameAs(wxT("kar"), false))||(extension.IsSameAs(wxT("mod"), false))||(extension.IsSameAs(wxT("rmi"), false))) {
         errorMessage.Printf(_("\"%s\" is a notes-based file, not an audio file. \nAudacity cannot open this type of file. \nTry converting it to an audio file such as WAV or AIFF and \nthen import it, or record it into Audacity."), fName.c_str());
         return 0;
      }
   
      // MusePack files
      if ((extension.IsSameAs(wxT("mp+"), false))||(extension.IsSameAs(wxT("mpc"), false))||(extension.IsSameAs(wxT("mpp"), false))) {
         errorMessage.Printf(_("\"%s\" is a Musepack audio file. \nAudacity cannot open this type of file. \nIf you think it might be an mp3 file, rename it to end with \".mp3\" \nand try importing it again. Otherwise you need to convert it to a supported audio \nformat, such as WAV or AIFF."), fName.c_str());
         return 0;
      }
   
      // WavPack files
      if ((extension.IsSameAs(wxT("wv"), false))||(extension.IsSameAs(wxT("wvc"), false))) {
         errorMessage.Printf(_("\"%s\" is a Wavpack audio file. \nAudacity cannot open this type of file. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName.c_str());
         return 0;
      }
   
      // AC3 files
      if ((extension.IsSameAs(wxT("ac3"), false))) {
         errorMessage.Printf(_("\"%s\" is a Dolby Digital audio file. \nAudacity cannot currently open this type of file. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName.c_str());
         return 0;
      }
   
      // Speex files
      if ((extension.IsSameAs(wxT("spx"), false))) {
         errorMessage.Printf(_("\"%s\" is an Ogg Speex audio file. \nAudacity cannot currently open this type of file. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName.c_str());
         return 0;
      }
   
      // Video files of various forms
      if ((extension.IsSameAs(wxT("mpg"), false))||(extension.IsSameAs(wxT("mpeg"), false))||(extension.IsSameAs(wxT("avi"), false))||(extension.IsSameAs(wxT("wmv"), false))||(extension.IsSameAs(wxT("rv"), false))) {
         errorMessage.Printf(_("\"%s\" is a video file. \nAudacity cannot currently open this type of file. \nYou need to extract the audio to a supported format, such as WAV or AIFF."), fName.c_str());
         return 0;
      }

      // we were not able to recognize the file type
      errorMessage.Printf(_("Audacity did not recognize the type of the file '%s'.\nIf it is uncompressed, try importing it using \"Import Raw\"."),fName.c_str());
   }
   else
   {
      // We DO have a plugin for this file, but import failed.
      wxString pluglist = wxEmptyString;

      importPluginNode = compatiblePlugins.GetFirst();
      while(importPluginNode)
      {
         ImportPlugin *plugin = importPluginNode->GetData();
         if (pluglist == wxEmptyString)
           pluglist = plugin->GetPluginFormatDescription();
         else
           pluglist = pluglist + wxT(", ") + plugin->GetPluginFormatDescription();
         importPluginNode = importPluginNode->GetNext();
      }

      errorMessage.Printf(_("Audacity recognized the type of the file '%s'.\nImporters supposedly supporting such files are:\n%s,\nbut none of them understood this file format."),fName.c_str(), pluglist.c_str());
   }

   return 0;
}
コード例 #14
0
ファイル: dir.cpp プロジェクト: CyberIntelMafia/clamav-devel
bool wxDirData::Read(wxString *filename)
{
    //dirent *de = NULL;    // just to silence compiler warnings
    int ret;
    char tmpbuf[300];
    bool matches = false;
    size_t flags_search;

    // speed up string concatenation in the loop a bit
    wxString path = m_dirname;
    path += wxT('/');
    path.reserve(path.length() + 255);

    wxString de_d_name;
    de_d_name.reserve(500);
    flags_search = 0;
    if (wxDIR_DIRS & m_flags) {
        flags_search |= SDIR_DIRS;
    }
    if (wxDIR_FILES & m_flags) {
        flags_search |= SDIR_FILES;
    }
    if (NULL == m_dir) {
#ifdef _PACC_VER
// walk around the PalmOS pacc compiler bug
        ret = svfs_dir_findfirst (m_dirname.fn_str().data(), &m_dir, tmpbuf, sizeof (tmpbuf), flags_search);
#else
         ret = svfs_dir_findfirst (m_dirname.fn_str(), &m_dir, tmpbuf, sizeof (tmpbuf), flags_search);
#endif
    } else {
        ret = svfs_dir_findnext (m_dir, tmpbuf, sizeof (tmpbuf));
    }
    for (; ret > 0; ) {

#if wxUSE_UNICODE
        de_d_name = wxString(tmpbuf, *wxConvFileName);
#else
        de_d_name = tmpbuf;
#endif

        // don't return "." and ".." unless asked for
        if ( tmpbuf[0] == '.' &&
             ((tmpbuf[1] == '.' && tmpbuf[2] == '\0') ||
              (tmpbuf[1] == '\0')) )
        {
            if ( !(m_flags & wxDIR_DOTDOT) )
                continue;

            // we found a valid match
            break;
        }

        // check the name
        if ( m_filespec.empty() )
        {
            matches = m_flags & wxDIR_HIDDEN ? true : tmpbuf[0] != '.';
        }
        else
        {
            // test against the pattern
            matches = wxMatchWild(m_filespec, de_d_name,
                                  !(m_flags & wxDIR_HIDDEN));
        }
        if (matches)
            break;
        ret = svfs_dir_findnext (m_dir, tmpbuf, sizeof (tmpbuf));
    }

    *filename = de_d_name;

    return true;
}
コード例 #15
0
void FileDialog::FilterFiles(HWND hDlg, bool refresh)
{
   HWND parent = ::GetParent(hDlg);
   IShellFolder *ishell = NULL;
   IShellBrowser *ishellbrowser = NULL;  // Does not have to be released
   IShellView *ishellview = NULL;
   IFolderView *ifolderview = NULL;
   LPMALLOC imalloc = NULL;
   HRESULT hr;
   
   // Get pointer to the ListView control
   HWND lv = ::GetDlgItem(::GetDlgItem(parent, lst2), 1);
   if (lv == NULL)
   {
      wxASSERT(lv != NULL);
      return;
   }
   
   // Get shell's memory allocation interface (must be Release()'d)
   hr = SHGetMalloc(&imalloc);
   if ((hr != NOERROR) || (imalloc == NULL))
   {
      wxASSERT((hr == NOERROR) && (imalloc != NULL));
      return;
   }

   // Get IShellBrowser interface for current dialog
   ishellbrowser = (IShellBrowser*)::SendMessage(parent, WM_GETISHELLBROWSER, 0, 0);
   if (ishellbrowser)
   {
      // Get IShellBrowser interface for returned browser
      if (ishellbrowser->QueryActiveShellView(&ishellview) == S_OK)
      {
         // Get the IFolderView interface...available on XP or greater
         ishellview->QueryInterface(IID_IFolderView, (void **)&ifolderview);
      }
   }

   // Init
   LVITEM lvi;
   wxZeroMemory(lvi);

   // Process all items
   int fltcnt = (int) m_Filters.GetCount();
   int itmcnt = ::SendMessage(lv, LVM_GETITEMCOUNT, 0, 0);
   for (int itm = 0; itm < itmcnt; itm++)
   {
      // Retrieve the file IDL
      lvi.iItem = itm;
      lvi.mask = LVIF_PARAM;
      if (ListView_GetItem(lv, &lvi) != TRUE)
      {
         wxASSERT(FALSE);
         break;
      }

      LPCITEMIDLIST fidl = (LPCITEMIDLIST) lvi.lParam;

      // On Vista, lParam no longer contains the pidl so retrieve it via the
      // IFolderView interface.  This interface is only available on XP or higher
      // so if that limitation isn't workable, use IShellView::GetItemObject() to
      // retrieve items.
      if (fidl == NULL && ifolderview != NULL)
      {
         ifolderview->Item(itm, (LPITEMIDLIST *) &fidl);
      }

      if (fidl == NULL)
      {
         wxASSERT(fidl != NULL);
         break;
      }

      // Retrieve the IShellFolder interface of the parent (must be Release()'d)
      if (ishell == NULL)
      {
         hr = SHBindToParentLocal(fidl, IID_IShellFolder, (void **)&ishell, NULL);
         if (!SUCCEEDED(hr))
         {
            wxASSERT(SUCCEEDED(hr));
            break;
         }
      }
      
      // Get the attributes of the object
      DWORD attr = SFGAO_FOLDER | SFGAO_BROWSABLE;
      hr = ishell->GetAttributesOf(1, &fidl, &attr);
      if (!SUCCEEDED(hr))
      {
         wxASSERT(SUCCEEDED(hr));
         break;
      }
      
      // Allow all folders (things like zip files get filtered below)
      if ((attr & (SFGAO_FOLDER)) && !(attr & SFGAO_BROWSABLE))
      {
         continue;
      }
      
      // Retrieve the parsable name of the object (includes extension)
      STRRET str;
      hr = ishell->GetDisplayNameOf(fidl, SHGDN_INFOLDER | SHGDN_FORPARSING, &str);
      if (hr != NOERROR)
      {
         // For some objects, we get back an error of 80070057.  I'm assuming this
         // means there is no way to represent the name (like some sort of virtual name)
         // or I've not used the correct PIDL.  But, in either case, it "probably"
         // represents some sort of folder (at least in all cases I've seen), so we
         // simply allow it to display.
         continue;
      }
      
      // Convert result to wxString
      wxString filename;
      switch (str.uType)
      {
         case STRRET_WSTR:
            filename = str.pOleStr;
            imalloc->Free(str.pOleStr);
            break;
            
         case STRRET_OFFSET:
            filename = wxString(((char *)fidl) + str.uOffset, wxConvISO8859_1);
            break;
            
         case STRRET_CSTR:
            filename = wxString(str.cStr, wxConvISO8859_1);
            break;
      }
      
      // Convert the filename to lowercase (and remember to write filters in lowercase!)
      filename = filename.Lower();

      // Attempt to match it to all of our filters
      bool match = false;
      for (int flt = 0; flt < fltcnt; flt++)
      {
         if (wxMatchWild(m_Filters[flt], filename, false))
         {
            match = true;
            break;
         }
      }
      
      // Remove it from the display if it didn't match any of the filters.
      if (!match)
      {
         ListView_DeleteItem(lv, itm);
         itm--;
         itmcnt--;
      }
   }

   // On Vista and maybe XP, we seem to need to refresh the view after
   // changing the filters.  But, only refresh for type changes and not
   // selection changes since it causes additional selection change
   // events to occur.
   if (ishellview && refresh)
   {
      ishellview->Refresh();
   }

   // Release the interface
   if (ifolderview)
   {
      ifolderview->Release();
   }

   // Release the interface
   if (ishellview)
   {
      ishellview->Release();
   }

   // Release the interface
   if (ishell)
   {
      ishell->Release();
   }
   
   // Release the interface
   if (imalloc)
   {
      imalloc->Release();
   }
}
コード例 #16
0
void OpenResourceDialog::DoPopulateTags()
{
	if (m_tags.empty())
		return;

	bool gotExactMatch(false);

	wxArrayString tmpArr;
	wxString curSel = m_textCtrlResourceName->GetValue();
	wxString curSelNoStar;
	if (!curSel.Trim().Trim(false).IsEmpty()) {

		curSel = curSel.MakeLower().Trim().Trim(false);
		curSelNoStar = curSel.c_str();

		for (size_t i=0; i<m_tags.size(); i++) {
			TagEntryPtr tag = m_tags.at(i);
			wxString    name(tag->GetName());

			name.MakeLower();

			//append wildcard at the end
			if (!curSel.EndsWith(wxT("*"))) {
				curSel << wxT("*");
			}

			// FR# [2008133]
			if (m_checkBoxUsePartialMatching->IsChecked() && !curSel.StartsWith(wxT("*"))) {
				curSel.Prepend(wxT("*"));
			}

			if (wxMatchWild(curSel, name)) {
				
				// keep the fullpath
				int index(0);
				if(tag->GetKind() == wxT("function") || tag->GetKind() == wxT("prototype"))
					index = DoAppendLine(tag->GetName(), 
										 tag->GetSignature(), 
										 tag->GetScope(), 
										 tag->GetKind() == wxT("function"),
										 new OpenResourceDialogItemData(tag->GetFile(), tag->GetLine(), tag->GetPattern(), m_type, tag->GetName(), tag->GetScope()));
				else 
					index = DoAppendLine(tag->GetName(), 
										 tag->GetScope(), 
										 wxT(""), 
										 false,
										 new OpenResourceDialogItemData(tag->GetFile(), tag->GetLine(), tag->GetPattern(), m_type, tag->GetName(), tag->GetScope()));
										 
				if (curSelNoStar == name && !gotExactMatch) {
					gotExactMatch = true;
					DoSelectItem(index);
				}
			}
		}
	}

	if (m_listOptions->GetItemCount() == 150) {
		m_staticTextErrorMessage->SetLabel(wxT("Too many matches, please narrow down your search"));
	}

	if (!gotExactMatch && m_listOptions->GetItemCount()) {
		DoSelectItem(0);
	}
}
コード例 #17
0
ファイル: dirmac.cpp プロジェクト: beanhome/dev
bool wxDirData::Read(wxString *filename)
{
    wxString result;
    OSStatus err = noErr ;
    if ( NULL == m_iterator )
    {
        FSRef dirRef;
        err = wxMacPathToFSRef( m_dirname , &dirRef ) ;
        if ( err == noErr )
        {
            err = FSOpenIterator(&dirRef, kFSIterateFlat, &m_iterator);
        }
        if ( err )
        {
            Close() ;
            return false ;
        }
    }

    wxString name ;
    wxString lowerfilespec = m_filespec.Lower();

    while( noErr == err )
    {
        HFSUniStr255 uniname ;
        FSRef fileRef;
        FSCatalogInfo catalogInfo;
        ItemCount fetched = 0;

        err = FSGetCatalogInfoBulk( m_iterator, 1, &fetched, NULL, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo , &catalogInfo , &fileRef, NULL, &uniname );

        // expected error codes

        if ( errFSNoMoreItems == err )
            return false ;
        if ( afpAccessDenied == err )
            return false ;

        if ( noErr != err )
            break ;

        name = wxMacHFSUniStrToString( &uniname ) ;
        wxString lowername = name.Lower();

        if ( ( name == wxT(".") || name == wxT("..") ) && !(m_flags & wxDIR_DOTDOT) )
            continue;

        if ( ( name[0U] == '.' ) && !(m_flags & wxDIR_HIDDEN ) )
            continue ;

        if ( (((FileInfo*)&catalogInfo.finderInfo)->finderFlags & kIsInvisible ) && !(m_flags & wxDIR_HIDDEN ) )
            continue ;

        // its a dir and we don't want it
        if ( (catalogInfo.nodeFlags & kFSNodeIsDirectoryMask)  && !(m_flags & wxDIR_DIRS) )
            continue ;

        // its a file but we don't want it
        if ( (catalogInfo.nodeFlags & kFSNodeIsDirectoryMask) == 0  && !(m_flags & wxDIR_FILES ) )
            continue ;

        if ( m_filespec.empty() || m_filespec == wxT("*.*") || m_filespec == wxT("*") )
        {
        }
        else if ( !wxMatchWild(lowerfilespec, lowername , false) )
        {
            continue ;
        }

        break ;
    }
    if ( err != noErr )
    {
        return false ;
    }

    *filename = name ;
    return true;
}
コード例 #18
0
 bool IsToProcess(const wxString& headername) const
 {
     if (m_strToMatch.IsEmpty())
         return true;
     return wxMatchWild(m_strToMatch, headername, false);
 }
コード例 #19
0
// returns number of tracks imported
int Importer::Import(wxString fName,
                     TrackFactory *trackFactory,
                     Track *** tracks,
                     Tags *tags,
                     wxString &errorMessage)
{
   AudacityProject *pProj = GetActiveProject();
   pProj->mbBusyImporting = true;

   ImportFileHandle *inFile = NULL;
   int numTracks = 0;

   wxString extension = fName.AfterLast(wxT('.'));

   // This list is used to call plugins in correct order
   ImportPluginList importPlugins;
   ImportPluginList::compatibility_iterator importPluginNode;

   // This list is used to remember plugins that should have been compatible with the file.
   ImportPluginList compatiblePlugins;
   
   // If user explicitly selected a filter,
   // then we should try importing via corresponding plugin first
   wxString type = gPrefs->Read(wxT("/LastOpenType"),wxT(""));
   
   // Not implemented (yet?)
   wxString mime_type = wxT("*");

   // First, add user-selected filter
   bool usersSelectionOverrides;
   gPrefs->Read(wxT("/ExtendedImport/OverrideExtendedImportByOpenFileDialogChoice"), &usersSelectionOverrides, false);

   wxLogDebug(wxT("LastOpenType is %s"),type.c_str());
   wxLogDebug(wxT("OverrideExtendedImportByOpenFileDialogChoice is %i"),usersSelectionOverrides);

   if (usersSelectionOverrides)
   {
      importPluginNode = mImportPluginList->GetFirst();
      while (importPluginNode)
      {
         ImportPlugin *plugin = importPluginNode->GetData();
         if (plugin->GetPluginFormatDescription().CompareTo(type) == 0)
         {
            // This plugin corresponds to user-selected filter, try it first.
            wxLogDebug(wxT("Inserting %s"),plugin->GetPluginStringID().c_str());
            importPlugins.Insert(plugin);
         }
         importPluginNode = importPluginNode->GetNext();
      }
   }

   wxLogMessage(wxT("File name is %s"),(const char *) fName.c_str());
   wxLogMessage(wxT("Mime type is %s"),(const char *) mime_type.Lower().c_str());

   for (size_t i = 0; i < mExtImportItems->Count(); i++)
   {
      ExtImportItem *item = &(*mExtImportItems)[i];
      bool matches_ext = false, matches_mime = false;
      wxLogDebug(wxT("Testing extensions"));
      for (size_t j = 0; j < item->extensions.Count(); j++)
      {
         wxLogDebug(wxT("%s"), (const char *) item->extensions[j].Lower().c_str());
         if (wxMatchWild (item->extensions[j].Lower(),fName.Lower(), false))
         {
            wxLogDebug(wxT("Match!"));
            matches_ext = true;
            break;
         }
      }
      if (item->extensions.Count() == 0)
      {
         wxLogDebug(wxT("Match! (empty list)"));
         matches_ext = true;
      }
      if (matches_ext)
         wxLogDebug(wxT("Testing mime types"));
      else
         wxLogDebug(wxT("Not testing mime types"));
      for (size_t j = 0; matches_ext && j < item->mime_types.Count(); j++)
      {
         if (wxMatchWild (item->mime_types[j].Lower(),mime_type.Lower(), false))
         {
            wxLogDebug(wxT("Match!"));
            matches_mime = true;
            break;
         }
      }
      if (item->mime_types.Count() == 0)
      {
         wxLogDebug(wxT("Match! (empty list)"));
         matches_mime = true;
      }
      if (matches_ext && matches_mime)
      {
         wxLogDebug(wxT("Complete match!"));
         for (size_t j = 0; j < item->filter_objects.Count() && (item->divider < 0 || (int) j < item->divider); j++)
         {
            // the filter_object can be NULL if a suitable importer was not found
            // this happens when we recompile with --without-ffmpeg and there
            // is still ffmpeg in prefs from previous --with-ffmpeg builds
            if (!(item->filter_objects[j]))
               continue;
            wxLogDebug(wxT("Inserting %s"),item->filter_objects[j]->GetPluginStringID().c_str());
            importPlugins.Append(item->filter_objects[j]);
         }
      }
   }

   // Add all plugins that support the extension
   importPluginNode = mImportPluginList->GetFirst();

   // Here we rely on the fact that the first plugin in mImportPluginList is libsndfile.
   // We want to save this for later insertion ahead of libmad, if libmad supports the extension.
   // The order of plugins in mImportPluginList is determined by the Importer constructor alone and
   // is not changed by user selection overrides or any other mechanism, but we include an assert
   // in case subsequent code revisions to the constructor should break this assumption that 
   // libsndfile is first. 
   ImportPlugin *libsndfilePlugin = importPluginNode->GetData();
   wxASSERT(libsndfilePlugin->GetPluginStringID().IsSameAs(wxT("libsndfile")));

   while (importPluginNode)
   {
      ImportPlugin *plugin = importPluginNode->GetData();
      // Make sure its not already in the list
      if (importPlugins.Find(plugin) == NULL)
      {
         if (plugin->SupportsExtension(extension))
         {
            // If libmad is accidentally fed a wav file which has been incorrectly
            // given an .mp3 extension then it can choke on the contents and crash.
            // To avoid this, put libsndfile ahead of libmad in the lists created for 
            // mp3 files, or for any of the extensions supported by libmad. 
            // A genuine .mp3 file will first fail an attempted import with libsndfile
            // but then get processed as desired by libmad.
            // But a wav file which bears an incorrect .mp3 extension will be successfully 
            // processed by libsndfile and thus avoid being submitted to libmad.
            if (plugin->GetPluginStringID().IsSameAs(wxT("libmad")))
            {
               // Make sure libsndfile is not already in the list
               if (importPlugins.Find(libsndfilePlugin) == NULL)
               {
                  wxLogDebug(wxT("Appending %s"),libsndfilePlugin->GetPluginStringID().c_str());
                  importPlugins.Append(libsndfilePlugin);
               }
            }
            wxLogDebug(wxT("Appending %s"),plugin->GetPluginStringID().c_str());
            importPlugins.Append(plugin);
         }
      }

      importPluginNode = importPluginNode->GetNext();
   }

   // Add remaining plugins, except for libmad, which should not be used as a fallback for anything.
   // Otherwise, if FFmpeg (libav) has not been installed, libmad will still be there near the 
   // end of the preference list importPlugins, where it will claim success importing FFmpeg file
   // formats unsuitable for it, and produce distorted results.
   importPluginNode = mImportPluginList->GetFirst();
   while (importPluginNode)
   {
      ImportPlugin *plugin = importPluginNode->GetData();
      if (!(plugin->GetPluginStringID().IsSameAs(wxT("libmad"))))
      {
         // Make sure its not already in the list
         if (importPlugins.Find(plugin) == NULL)
         {
            wxLogDebug(wxT("Appending %s"),plugin->GetPluginStringID().c_str());
            importPlugins.Append(plugin);
         }
      }

      importPluginNode = importPluginNode->GetNext();
   }

   importPluginNode = importPlugins.GetFirst();
   while(importPluginNode)
   {
      ImportPlugin *plugin = importPluginNode->GetData();
      // Try to open the file with this plugin (probe it)
      wxLogMessage(wxT("Opening with %s"),plugin->GetPluginStringID().c_str());
      inFile = plugin->Open(fName);
      if ( (inFile != NULL) && (inFile->GetStreamCount() > 0) )
      {
         wxLogMessage(wxT("Open(%s) succeeded"),(const char *) fName.c_str());
         // File has more than one stream - display stream selector
         if (inFile->GetStreamCount() > 1)                                                  
         {
            ImportStreamDialog ImportDlg(inFile, NULL, -1, _("Select stream(s) to import"));

            if (ImportDlg.ShowModal() == wxID_CANCEL)
            {
               delete inFile;
               pProj->mbBusyImporting = false;
               return 0;
            }
         }
         // One stream - import it by default
         else
            inFile->SetStreamUsage(0,TRUE);

         int res;
         
         res = inFile->Import(trackFactory, tracks, &numTracks, tags);

         delete inFile;

         if (res == eProgressSuccess || res == eProgressStopped)
         {
            // LOF ("list-of-files") has different semantics
            if (extension.IsSameAs(wxT("lof"), false))
            {
               pProj->mbBusyImporting = false;
               return 1;
            }

            if (numTracks > 0) 
            {
               // success!
               pProj->mbBusyImporting = false;
               return numTracks;
            }
         }

         if (res == eProgressCancelled || res == eProgressFailed)
         {
            pProj->mbBusyImporting = false;
            return 0;
         }

         // We could exit here since we had a match on the file extension,
         // but there may be another plug-in that can import the file and
         // that may recognize the extension, so we allow the loop to
         // continue.
      }
      importPluginNode = importPluginNode->GetNext();
   }
   wxLogError(wxT("Importer::Import: Opening failed."));

   // None of our plugins can handle this file.  It might be that
   // Audacity supports this format, but support was not compiled in.
   // If so, notify the user of this fact
   UnusableImportPluginList::compatibility_iterator unusableImporterNode
      = mUnusableImportPluginList->GetFirst();
   while(unusableImporterNode)
   {
      UnusableImportPlugin *unusableImportPlugin = unusableImporterNode->GetData();
      if( unusableImportPlugin->SupportsExtension(extension) )
      {
         errorMessage.Printf(_("This version of Audacity was not compiled with %s support."),
                             unusableImportPlugin->
                             GetPluginFormatDescription().c_str());
         pProj->mbBusyImporting = false;
         return 0;
      }
      unusableImporterNode = unusableImporterNode->GetNext();
   }

   /* warnings for unsupported data types */

#ifdef USE_MIDI
   // MIDI files must be imported, not opened
   if ((extension.IsSameAs(wxT("midi"), false))||(extension.IsSameAs(wxT("mid"), false))) {
      errorMessage.Printf(_("\"%s\" \nis a MIDI file, not an audio file. \nAudacity cannot open this type of file for playing, but you can\nedit it by clicking File > Import > MIDI."), fName.c_str());
      pProj->mbBusyImporting = false;
      return 0;
   }
#endif

   if (compatiblePlugins.GetCount() <= 0)
   {
      // if someone has sent us a .cda file, send them away
      if (extension.IsSameAs(wxT("cda"), false)) {
         /* i18n-hint: %s will be the filename */
         errorMessage.Printf(_("\"%s\" is an audio CD track. \nAudacity cannot open audio CDs directly. \nExtract (rip) the CD tracks to an audio format that \nAudacity can import, such as WAV or AIFF."), fName.c_str());
         pProj->mbBusyImporting = false;
         return 0;
      }
   
      // playlist type files
      if ((extension.IsSameAs(wxT("m3u"), false))||(extension.IsSameAs(wxT("ram"), false))||(extension.IsSameAs(wxT("pls"), false))) {
         errorMessage.Printf(_("\"%s\" is a playlist file. \nAudacity cannot open this file because it only contains links to other files. \nYou may be able to open it in a text editor and download the actual audio files."), fName.c_str());
         pProj->mbBusyImporting = false;
         return 0;
      }
      //WMA files of various forms
      if ((extension.IsSameAs(wxT("wma"), false))||(extension.IsSameAs(wxT("asf"), false))) {
         errorMessage.Printf(_("\"%s\" is a Windows Media Audio file. \nAudacity cannot open this type of file due to patent restrictions. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName.c_str());
         pProj->mbBusyImporting = false;
         return 0;
      }
      //AAC files of various forms (probably not encrypted)
      if ((extension.IsSameAs(wxT("aac"), false))||(extension.IsSameAs(wxT("m4a"), false))||(extension.IsSameAs(wxT("m4r"), false))||(extension.IsSameAs(wxT("mp4"), false))) {
         errorMessage.Printf(_("\"%s\" is an Advanced Audio Coding file. \nAudacity cannot open this type of file. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName.c_str());
         pProj->mbBusyImporting = false;
         return 0;
      }
      // encrypted itunes files
      if ((extension.IsSameAs(wxT("m4p"), false))) {
         errorMessage.Printf(_("\"%s\" is an encrypted audio file. \nThese typically are from an online music store. \nAudacity cannot open this type of file due to the encryption. \nTry recording the file into Audacity, or burn it to audio CD then \nextract the CD track to a supported audio format such as WAV or AIFF."), fName.c_str());
         pProj->mbBusyImporting = false;
         return 0;
      }
      // Real Inc. files of various sorts
      if ((extension.IsSameAs(wxT("ra"), false))||(extension.IsSameAs(wxT("rm"), false))||(extension.IsSameAs(wxT("rpm"), false))) {
         errorMessage.Printf(_("\"%s\" is a RealPlayer media file. \nAudacity cannot open this proprietary format. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName.c_str());
         pProj->mbBusyImporting = false;
         return 0;
      }
   
      // Other notes-based formats
      if ((extension.IsSameAs(wxT("kar"), false))||(extension.IsSameAs(wxT("mod"), false))||(extension.IsSameAs(wxT("rmi"), false))) {
         errorMessage.Printf(_("\"%s\" is a notes-based file, not an audio file. \nAudacity cannot open this type of file. \nTry converting it to an audio file such as WAV or AIFF and \nthen import it, or record it into Audacity."), fName.c_str());
         pProj->mbBusyImporting = false;
         return 0;
      }
   
      // MusePack files
      if ((extension.IsSameAs(wxT("mp+"), false))||(extension.IsSameAs(wxT("mpc"), false))||(extension.IsSameAs(wxT("mpp"), false))) {
         errorMessage.Printf(_("\"%s\" is a Musepack audio file. \nAudacity cannot open this type of file. \nIf you think it might be an mp3 file, rename it to end with \".mp3\" \nand try importing it again. Otherwise you need to convert it to a supported audio \nformat, such as WAV or AIFF."), fName.c_str());
         pProj->mbBusyImporting = false;
         return 0;
      }
   
      // WavPack files
      if ((extension.IsSameAs(wxT("wv"), false))||(extension.IsSameAs(wxT("wvc"), false))) {
         errorMessage.Printf(_("\"%s\" is a Wavpack audio file. \nAudacity cannot open this type of file. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName.c_str());
         pProj->mbBusyImporting = false;
         return 0;
      }
   
      // AC3 files
      if ((extension.IsSameAs(wxT("ac3"), false))) {
         errorMessage.Printf(_("\"%s\" is a Dolby Digital audio file. \nAudacity cannot currently open this type of file. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName.c_str());
         pProj->mbBusyImporting = false;
         return 0;
      }
   
      // Speex files
      if ((extension.IsSameAs(wxT("spx"), false))) {
         errorMessage.Printf(_("\"%s\" is an Ogg Speex audio file. \nAudacity cannot currently open this type of file. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName.c_str());
         pProj->mbBusyImporting = false;
         return 0;
      }
   
      // Video files of various forms
      if ((extension.IsSameAs(wxT("mpg"), false))||(extension.IsSameAs(wxT("mpeg"), false))||(extension.IsSameAs(wxT("avi"), false))||(extension.IsSameAs(wxT("wmv"), false))||(extension.IsSameAs(wxT("rv"), false))) {
         errorMessage.Printf(_("\"%s\" is a video file. \nAudacity cannot currently open this type of file. \nYou need to extract the audio to a supported format, such as WAV or AIFF."), fName.c_str());
         pProj->mbBusyImporting = false;
         return 0;
      }

      // we were not able to recognize the file type
      errorMessage.Printf(_("Audacity did not recognize the type of the file '%s'.\nIf it is uncompressed, try importing it using \"Import Raw\"."),fName.c_str());
   }
   else
   {
      // We DO have a plugin for this file, but import failed.
      wxString pluglist = wxEmptyString;

      importPluginNode = compatiblePlugins.GetFirst();
      while(importPluginNode)
      {
         ImportPlugin *plugin = importPluginNode->GetData();
         if (pluglist == wxEmptyString)
           pluglist = plugin->GetPluginFormatDescription();
         else
           pluglist = pluglist + wxT(", ") + plugin->GetPluginFormatDescription();
         importPluginNode = importPluginNode->GetNext();
      }

      errorMessage.Printf(_("Audacity recognized the type of the file '%s'.\nImporters supposedly supporting such files are:\n%s,\nbut none of them understood this file format."),fName.c_str(), pluglist.c_str());
   }

   pProj->mbBusyImporting = false;
   return 0;
}
コード例 #20
0
void FileDialog::FilterFiles(HWND hDlg)
{
   HWND parent = ::GetParent(hDlg);
   IShellFolder *ishell = NULL;
   LPMALLOC imalloc = NULL;
   HRESULT hr;
   
   // Get pointer to the ListView control
   HWND lv = ::GetDlgItem(::GetDlgItem(parent, lst2), 1);
   if (lv == NULL)
   {
      wxASSERT(lv != NULL);
      return;
   }
   
   // Get shell's memory allocation interface (must be Release()'d)
   hr = SHGetMalloc(&imalloc);
   if ((hr != NOERROR) || (imalloc == NULL))
   {
      wxASSERT((hr == NOERROR) && (imalloc != NULL));
      return;
   }
   
   // Init
   LVITEM lvi;
   wxZeroMemory(lvi);
   
   // Process all items
   int fltcnt = m_Filters.GetCount();
   int itmcnt = ::SendMessage(lv, LVM_GETITEMCOUNT, 0, 0);
   for (int itm = 0; itm < itmcnt; itm++)
   {
      // Retrieve the file IDL
      lvi.iItem = itm;
      lvi.mask = LVIF_PARAM;
      if (ListView_GetItem(lv, &lvi) != TRUE)
      {
         wxASSERT(FALSE);
         break;
      }
      LPCITEMIDLIST fidl = (LPCITEMIDLIST) lvi.lParam;
      
      // Retrieve the IShellFolder interface of the parent (must be Release()'d)
      if (ishell == NULL)
      {
         hr = SHBindToParent(fidl, IID_IShellFolder, (void **)&ishell, NULL);
         if (!SUCCEEDED(hr))
         {
            wxASSERT(SUCCEEDED(hr));
            break;
         }
      }
      
      // Get the attributes of the object
      DWORD attr = SFGAO_FOLDER | SFGAO_STREAM;
      hr = ishell->GetAttributesOf(1, &fidl, &attr);
      if (!SUCCEEDED(hr))
      {
         wxASSERT(SUCCEEDED(hr));
         break;
      }
      
      // Allow all folders (things like zip files get filtered below)
      if (attr == SFGAO_FOLDER)
      {
         continue;
      }
      
      // Retrieve the parsable name of the object (includes extension)
      STRRET str;
      hr = ishell->GetDisplayNameOf(fidl, SHGDN_INFOLDER | SHGDN_FORPARSING, &str);
      if (hr != NOERROR)
      {
         // For some objects, we get back an error of 80070057.  I'm assuming this
         // means there is no way to represent the name (like some sort of virtual name)
         // or I've not used the correct PIDL.  But, in either case, it "probably"
         // represents some sort of folder (at least in all cases I've seen), so we
         // simply allow it to display.
         continue;
      }
      
      // Convert result to wxString
      wxString filename;
      switch (str.uType)
      {
         case STRRET_WSTR:
            filename = str.pOleStr;
            imalloc->Free(str.pOleStr);
            break;
            
         case STRRET_OFFSET:
            filename = wxString(((char *)fidl) + str.uOffset, wxConvISO8859_1);
            break;
            
         case STRRET_CSTR:
            filename = wxString(str.cStr, wxConvISO8859_1);
            break;
      }
      
      // Attempt to match it to all of our filters
      bool match = false;
      for (int flt = 0; flt < fltcnt; flt++)
      {
         if (wxMatchWild(m_Filters[flt], filename, false))
         {
            match = true;
            break;
         }
      }
      
      // Remove it from the display if it didn't match any of the filters.
      if (!match)
      {
         ListView_DeleteItem(lv, itm);
         itm--;
         itmcnt--;
      }
   }
   
done:
   
   // Release the interface
   if (ishell)
   {
      ishell->Release();
   }
   
   // Release the interface
   if (imalloc)
   {
      imalloc->Release();
   }
}
コード例 #21
0
ファイル: dir.cpp プロジェクト: czxxjtu/wxPython-1
bool wxDirData::Read(wxString *filename)
{
    dirent *de = NULL;    // just to silence compiler warnings
    bool matches = false;

    // speed up string concatenation in the loop a bit
    wxString path = m_dirname;
    path += _T('/');
    path.reserve(path.length() + 255);

    wxString de_d_name;

    while ( !matches )
    {
        de = readdir(m_dir);
        if ( !de )
            return false;

#if wxUSE_UNICODE
        de_d_name = wxString(de->d_name, *wxConvFileName);
#else
        de_d_name = de->d_name;
#endif

        // don't return "." and ".." unless asked for
        if ( de->d_name[0] == '.' &&
             ((de->d_name[1] == '.' && de->d_name[2] == '\0') ||
              (de->d_name[1] == '\0')) )
        {
            if ( !(m_flags & wxDIR_DOTDOT) )
                continue;

            // we found a valid match
            break;
        }

        // check the type now
        if ( !(m_flags & wxDIR_FILES) && !wxDir::Exists(path + de_d_name) )
        {
            // it's a file, but we don't want them
            continue;
        }
        else if ( !(m_flags & wxDIR_DIRS) && wxDir::Exists(path + de_d_name) )
        {
            // it's a dir, and we don't want it
            continue;
        }

        // finally, check the name
        if ( m_filespec.empty() )
        {
            matches = m_flags & wxDIR_HIDDEN ? true : de->d_name[0] != '.';
        }
        else
        {
            // test against the pattern
            matches = wxMatchWild(m_filespec, de_d_name,
                                  !(m_flags & wxDIR_HIDDEN));
        }
    }

    *filename = de_d_name;

    return true;
}