// extension -> file type wxFileType * wxMimeTypesManagerImpl::GetFileTypeFromExtension(const wxString& ext) { // add the leading point if necessary wxString str; if ( ext[0u] != wxT('.') ) { str = wxT('.'); } str << ext; // suppress possible error messages wxLogNull nolog; bool knownExtension = false; wxString strFileType; wxRegKey key(wxRegKey::HKCR, str); if ( key.Open(wxRegKey::Read) ) { // it's the default value of the key if ( key.QueryValue(wxEmptyString, strFileType) ) { // create the new wxFileType object return CreateFileType(strFileType, ext); } else { // this extension doesn't have a filetype, but it's known to the // system and may be has some other useful keys (open command or // content-type), so still return a file type object for it knownExtension = true; } } if ( !knownExtension ) { // unknown extension return NULL; } return CreateFileType(wxEmptyString, ext); }
wxFileType *wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo& ftInfo) { wxCHECK_MSG( !ftInfo.GetExtensions().empty(), NULL, wxT("Associate() needs extension") ); bool ok; size_t iExtCount = 0; wxString filetype; wxString extWithDot; wxString ext = ftInfo.GetExtensions()[iExtCount]; wxCHECK_MSG( !ext.empty(), NULL, wxT("Associate() needs non empty extension") ); if ( ext[0u] != wxT('.') ) extWithDot = wxT('.'); extWithDot += ext; // start by setting the HKCR\\.ext entries // default is filetype; content type is mimetype const wxString& filetypeOrig = ftInfo.GetShortDesc(); wxRegKey key(wxRegKey::HKCR, extWithDot); if ( !key.Exists() ) { // create the mapping from the extension to the filetype ok = key.Create(); if ( ok ) { if ( filetypeOrig.empty() ) { // make it up from the extension filetype << extWithDot.c_str() + 1 << wxT("_file"); } else { // just use the provided one filetype = filetypeOrig; } key.SetValue(wxEmptyString, filetype); } } else { // key already exists, maybe we want to change it ?? if (!filetypeOrig.empty()) { filetype = filetypeOrig; key.SetValue(wxEmptyString, filetype); } else { key.QueryValue(wxEmptyString, filetype); } } // now set a mimetypeif we have it, but ignore it if none const wxString& mimetype = ftInfo.GetMimeType(); if ( !mimetype.empty() ) { // set the MIME type ok = key.SetValue(wxT("Content Type"), mimetype); if ( ok ) { // create the MIME key wxString strKey = MIME_DATABASE_KEY; strKey << mimetype; wxRegKey keyMIME(wxRegKey::HKCR, strKey); ok = keyMIME.Create(); if ( ok ) { // and provide a back link to the extension keyMIME.SetValue(wxT("Extension"), extWithDot); } } } // now make other extensions have the same filetype for (iExtCount=1; iExtCount < ftInfo.GetExtensionsCount(); iExtCount++ ) { ext = ftInfo.GetExtensions()[iExtCount]; if ( ext[0u] != wxT('.') ) extWithDot = wxT('.'); extWithDot += ext; wxRegKey key(wxRegKey::HKCR, extWithDot); if ( !key.Exists() ) key.Create(); key.SetValue(wxEmptyString, filetype); // now set any mimetypes we may have, but ignore it if none const wxString& mimetype = ftInfo.GetMimeType(); if ( !mimetype.empty() ) { // set the MIME type ok = key.SetValue(wxT("Content Type"), mimetype); if ( ok ) { // create the MIME key wxString strKey = MIME_DATABASE_KEY; strKey << mimetype; wxRegKey keyMIME(wxRegKey::HKCR, strKey); ok = keyMIME.Create(); if ( ok ) { // and provide a back link to the extension keyMIME.SetValue(wxT("Extension"), extWithDot); } } } } // end of for loop; all extensions now point to HKCR\.ext\Default // create the filetype key itself (it will be empty for now, but // SetCommand(), SetDefaultIcon() &c will use it later) wxRegKey keyFT(wxRegKey::HKCR, filetype); keyFT.Create(); wxFileType *ft = CreateFileType(filetype, extWithDot); if (ft) { if (! ftInfo.GetOpenCommand ().empty() ) ft->SetCommand (ftInfo.GetOpenCommand (), wxT("open" ) ); if (! ftInfo.GetPrintCommand().empty() ) ft->SetCommand (ftInfo.GetPrintCommand(), wxT("print" ) ); // chris: I don't like the ->m_impl-> here FIX this ?? if (! ftInfo.GetDescription ().empty() ) ft->m_impl->SetDescription (ftInfo.GetDescription ()) ; if (! ftInfo.GetIconFile().empty() ) ft->SetDefaultIcon (ftInfo.GetIconFile(), ftInfo.GetIconIndex() ); } return ft; }
void PreferencesDialog::UpdatePreferences() { ElectronConfiguration *config = new ElectronConfiguration; config->Autoload = GetCheck( IDC_CHECKAUTOLOAD ); config->Autoconfigure = GetCheck( IDC_CHECKAUTOCONFIGURE ); config->Plus1 = GetCheck( IDC_CHECKPLUS1 ); config->FirstByte = GetCheck( IDC_CHECKFIRSTBYTE ); config->FastTape = GetCheck( IDC_CHECKFASTLOAD ); config->Display.DisplayMultiplexed = GetCheck( IDC_CHECKMULTIPLEX ); config->Display.StartFullScreen = GetCheck( IDC_CHECKFULLSCREEN ); config->Display.AllowOverlay = GetCheck( IDC_CHECKOVERLAY ); config->Plus3.Enabled = GetCheck( IDC_CHECKDISK ); config->Plus3.Drive1WriteProtect = GetCheck( IDC_CHECKPROTECT0 ); config->Plus3.Drive2WriteProtect = GetCheck( IDC_CHECKPROTECT1 ); config->Volume = GetSlider( IDC_SLIDERVOLUME ); config->PersistentState = GetCheck( IDC_CHECKSAVESTATE ); if ( GetCheck( IDC_CHECKSLOGGER ) ) { if ( GetCheck( IDC_RADIO4 ) ) { config->MRBMode = MRB_4Mhz; } else if ( GetCheck( IDC_RADIOTURBO ) ) { config->MRBMode = MRB_TURBO; } else { config->MRBMode = MRB_SHADOW; } } else { config->MRBMode = MRB_OFF; } config->Write( _store ); // Update the registry to set the file types if ( GetCheck( IDC_CHECKUEFFILES ) ) { CreateFileType( ".uef", "ueffile", "Universal Emulator Format File", 1 ); } else { DeleteFileType( ".uef", "ueffile" ); } if ( GetCheck( IDC_CHECKADFFILES ) ) { CreateFileType( ".adf", "adffile", "Acorn ADFS Disk Image", 2 ); } else { DeleteFileType( ".adf", "adffile" ); } if ( GetCheck( IDC_CHECKSSDFILES ) ) { CreateFileType( ".ssd", "ssdfile", "Acorn DFS Single Sided Disk Image", 3 ); } else { DeleteFileType( ".ssd", "ssdfile" ); } if ( GetCheck( IDC_CHECKBASICFILES ) ) { CreateFileType( ".bas", "basfile", "BBC BASIC source code", 3 ); } else { DeleteFileType( ".bas", "basfile" ); } /* pass to emulator */ SDL_Event evt; evt.type = SDL_USEREVENT; evt.user.code = GUIEVT_ASSIGNCONFIG; evt.user.data1 = config; /* may have to wait here if event queue is full */ while( SDL_PushEvent( &evt ) == -1) SDL_Delay(10); }