]> git.saurik.com Git - wxWidgets.git/blob - src/palmos/mimetype.cpp
Only filter out duplicate -libraries. Let other constructs
[wxWidgets.git] / src / palmos / mimetype.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: palmos/mimetype.cpp
3 // Purpose: classes and functions to manage MIME types
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 23.09.98
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence (part of wxExtra library)
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "mimetype.h"
14 #endif
15
16 // for compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 // This really doesn't apply to Palm OS
24 #ifdef __WXPALMOS__
25
26 #if wxUSE_MIMETYPE
27
28 #ifndef WX_PRECOMP
29 #include "wx/string.h"
30 #if wxUSE_GUI
31 #include "wx/icon.h"
32 #include "wx/msgdlg.h"
33 #endif
34 #endif //WX_PRECOMP
35
36 #include "wx/log.h"
37 #include "wx/file.h"
38 #include "wx/iconloc.h"
39 #include "wx/intl.h"
40 #include "wx/dynarray.h"
41 #include "wx/confbase.h"
42
43 #include "wx/palmos/mimetype.h"
44
45 // other standard headers
46 #include <ctype.h>
47
48 // in case we're compiling in non-GUI mode
49 class WXDLLEXPORT wxIcon;
50
51 // These classes use Windows registry to retrieve the required information.
52 //
53 // Keys used (not all of them are documented, so it might actually stop working
54 // in future versions of Windows...):
55 // 1. "HKCR\MIME\Database\Content Type" contains subkeys for all known MIME
56 // types, each key has a string value "Extension" which gives (dot preceded)
57 // extension for the files of this MIME type.
58 //
59 // 2. "HKCR\.ext" contains
60 // a) unnamed value containing the "filetype"
61 // b) value "Content Type" containing the MIME type
62 //
63 // 3. "HKCR\filetype" contains
64 // a) unnamed value containing the description
65 // b) subkey "DefaultIcon" with single unnamed value giving the icon index in
66 // an icon file
67 // c) shell\open\command and shell\open\print subkeys containing the commands
68 // to open/print the file (the positional parameters are introduced by %1,
69 // %2, ... in these strings, we change them to %s ourselves)
70
71 // although I don't know of any official documentation which mentions this
72 // location, uses it, so it isn't likely to change
73 static const wxChar *MIME_DATABASE_KEY = wxT("MIME\\Database\\Content Type\\");
74
75 // this function replaces Microsoft %1 with Unix-like %s
76 static bool CanonicalizeParams(wxString& command)
77 {
78 // transform it from '%1' to '%s' style format string (now also test for %L
79 // as apparently MS started using it as well for the same purpose)
80
81 // NB: we don't make any attempt to verify that the string is valid, i.e.
82 // doesn't contain %2, or second %1 or .... But we do make sure that we
83 // return a string with _exactly_ one '%s'!
84 bool foundFilename = false;
85 size_t len = command.length();
86 for ( size_t n = 0; (n < len) && !foundFilename; n++ )
87 {
88 if ( command[n] == wxT('%') &&
89 (n + 1 < len) &&
90 (command[n + 1] == wxT('1') || command[n + 1] == wxT('L')) )
91 {
92 // replace it with '%s'
93 command[n + 1] = wxT('s');
94
95 foundFilename = true;
96 }
97 }
98
99 return foundFilename;
100 }
101
102 void wxFileTypeImpl::Init(const wxString& strFileType, const wxString& ext)
103 {
104 // VZ: does it? (FIXME)
105 wxCHECK_RET( !ext.empty(), _T("needs an extension") );
106
107 if ( ext[0u] != wxT('.') ) {
108 m_ext = wxT('.');
109 }
110 m_ext << ext;
111
112 m_strFileType = strFileType;
113 if ( !strFileType ) {
114 m_strFileType = m_ext.AfterFirst('.') + _T("_auto_file");
115 }
116 }
117
118 wxString wxFileTypeImpl::GetVerbPath(const wxString& verb) const
119 {
120 wxString path;
121 path << m_strFileType << _T("\\shell\\") << verb << _T("\\command");
122 return path;
123 }
124
125 size_t wxFileTypeImpl::GetAllCommands(wxArrayString *verbs,
126 wxArrayString *commands,
127 const wxFileType::MessageParameters& params) const
128 {
129 wxCHECK_MSG( !m_ext.empty(), 0, _T("GetAllCommands() needs an extension") );
130
131 if ( m_strFileType.empty() )
132 {
133 // get it from the registry
134 wxFileTypeImpl *self = wxConstCast(this, wxFileTypeImpl);
135 wxRegKey rkey(wxRegKey::HKCR, m_ext);
136 if ( !rkey.Exists() || !rkey.QueryValue(wxEmptyString, self->m_strFileType) )
137 {
138 wxLogDebug(_T("Can't get the filetype for extension '%s'."),
139 m_ext.c_str());
140
141 return 0;
142 }
143 }
144
145 // enum all subkeys of HKCR\filetype\shell
146 size_t count = 0;
147 wxRegKey rkey(wxRegKey::HKCR, m_strFileType + _T("\\shell"));
148 long dummy;
149 wxString verb;
150 bool ok = rkey.GetFirstKey(verb, dummy);
151 while ( ok )
152 {
153 wxString command = wxFileType::ExpandCommand(GetCommand(verb), params);
154
155 // we want the open bverb to eb always the first
156
157 if ( verb.CmpNoCase(_T("open")) == 0 )
158 {
159 if ( verbs )
160 verbs->Insert(verb, 0);
161 if ( commands )
162 commands->Insert(command, 0);
163 }
164 else // anything else than "open"
165 {
166 if ( verbs )
167 verbs->Add(verb);
168 if ( commands )
169 commands->Add(command);
170 }
171
172 count++;
173
174 ok = rkey.GetNextKey(verb, dummy);
175 }
176
177 return count;
178 }
179
180 // ----------------------------------------------------------------------------
181 // modify the registry database
182 // ----------------------------------------------------------------------------
183
184 bool wxFileTypeImpl::EnsureExtKeyExists()
185 {
186 wxRegKey rkey(wxRegKey::HKCR, m_ext);
187 if ( !rkey.Exists() )
188 {
189 if ( !rkey.Create() || !rkey.SetValue(wxEmptyString, m_strFileType) )
190 {
191 wxLogError(_("Failed to create registry entry for '%s' files."),
192 m_ext.c_str());
193 return false;
194 }
195 }
196
197 return true;
198 }
199
200 // ----------------------------------------------------------------------------
201 // get the command to use
202 // ----------------------------------------------------------------------------
203
204 wxString wxFileTypeImpl::GetCommand(const wxChar *verb) const
205 {
206 // suppress possible error messages
207 wxLogNull nolog;
208 wxString strKey;
209
210 if ( wxRegKey(wxRegKey::HKCR, m_ext + _T("\\shell")).Exists() )
211 strKey = m_ext;
212 if ( wxRegKey(wxRegKey::HKCR, m_strFileType + _T("\\shell")).Exists() )
213 strKey = m_strFileType;
214
215 if ( !strKey )
216 {
217 // no info
218 return wxEmptyString;
219 }
220
221 strKey << wxT("\\shell\\") << verb;
222 wxRegKey key(wxRegKey::HKCR, strKey + _T("\\command"));
223 wxString command;
224 if ( key.Open(wxRegKey::Read) ) {
225 // it's the default value of the key
226 if ( key.QueryValue(wxEmptyString, command) ) {
227 bool foundFilename = CanonicalizeParams(command);
228
229 #if wxUSE_IPC
230 // look whether we must issue some DDE requests to the application
231 // (and not just launch it)
232 strKey += _T("\\DDEExec");
233 wxRegKey keyDDE(wxRegKey::HKCR, strKey);
234 if ( keyDDE.Open(wxRegKey::Read) ) {
235 wxString ddeCommand, ddeServer, ddeTopic;
236 keyDDE.QueryValue(wxEmptyString, ddeCommand);
237 ddeCommand.Replace(_T("%1"), _T("%s"));
238
239 wxRegKey(wxRegKey::HKCR, strKey + _T("\\Application")).
240 QueryValue(wxEmptyString, ddeServer);
241 wxRegKey(wxRegKey::HKCR, strKey + _T("\\Topic")).
242 QueryValue(wxEmptyString, ddeTopic);
243
244 if (ddeTopic.IsEmpty())
245 ddeTopic = wxT("System");
246
247 // HACK: we use a special feature of wxExecute which exists
248 // just because we need it here: it will establish DDE
249 // conversation with the program it just launched
250 command.Prepend(_T("WX_DDE#"));
251 command << _T('#') << ddeServer
252 << _T('#') << ddeTopic
253 << _T('#') << ddeCommand;
254 }
255 else
256 #endif // wxUSE_IPC
257 if ( !foundFilename )
258 {
259 // we didn't find any '%1' - the application doesn't know which
260 // file to open (note that we only do it if there is no DDEExec
261 // subkey)
262 //
263 // HACK: append the filename at the end, hope that it will do
264 command << wxT(" %s");
265 }
266 }
267 }
268 //else: no such file type or no value, will return empty string
269
270 return command;
271 }
272
273 bool
274 wxFileTypeImpl::GetOpenCommand(wxString *openCmd,
275 const wxFileType::MessageParameters& params)
276 const
277 {
278 wxString cmd = GetCommand(wxT("open"));
279
280 *openCmd = wxFileType::ExpandCommand(cmd, params);
281
282 return !openCmd->empty();
283 }
284
285 bool
286 wxFileTypeImpl::GetPrintCommand(wxString *printCmd,
287 const wxFileType::MessageParameters& params)
288 const
289 {
290 wxString cmd = GetCommand(wxT("print"));
291
292 *printCmd = wxFileType::ExpandCommand(cmd, params);
293
294 return !printCmd->empty();
295 }
296
297 // ----------------------------------------------------------------------------
298 // getting other stuff
299 // ----------------------------------------------------------------------------
300
301 // TODO this function is half implemented
302 bool wxFileTypeImpl::GetExtensions(wxArrayString& extensions)
303 {
304 if ( m_ext.empty() ) {
305 // the only way to get the list of extensions from the file type is to
306 // scan through all extensions in the registry - too slow...
307 return false;
308 }
309 else {
310 extensions.Empty();
311 extensions.Add(m_ext);
312
313 // it's a lie too, we don't return _all_ extensions...
314 return true;
315 }
316 }
317
318 bool wxFileTypeImpl::GetMimeType(wxString *mimeType) const
319 {
320 // suppress possible error messages
321 wxLogNull nolog;
322 wxRegKey key(wxRegKey::HKCR, m_ext);
323
324 return key.Open(wxRegKey::Read) &&
325 key.QueryValue(wxT("Content Type"), *mimeType);
326 }
327
328 bool wxFileTypeImpl::GetMimeTypes(wxArrayString& mimeTypes) const
329 {
330 wxString s;
331
332 if ( !GetMimeType(&s) )
333 {
334 return false;
335 }
336
337 mimeTypes.Clear();
338 mimeTypes.Add(s);
339 return true;
340 }
341
342
343 bool wxFileTypeImpl::GetIcon(wxIconLocation *iconLoc) const
344 {
345 wxString strIconKey;
346 strIconKey << m_strFileType << wxT("\\DefaultIcon");
347
348 // suppress possible error messages
349 wxLogNull nolog;
350 wxRegKey key(wxRegKey::HKCR, strIconKey);
351
352 if ( key.Open(wxRegKey::Read) ) {
353 wxString strIcon;
354 // it's the default value of the key
355 if ( key.QueryValue(wxEmptyString, strIcon) ) {
356 // the format is the following: <full path to file>, <icon index>
357 // NB: icon index may be negative as well as positive and the full
358 // path may contain the environment variables inside '%'
359 wxString strFullPath = strIcon.BeforeLast(wxT(',')),
360 strIndex = strIcon.AfterLast(wxT(','));
361
362 // index may be omitted, in which case BeforeLast(',') is empty and
363 // AfterLast(',') is the whole string
364 if ( strFullPath.empty() ) {
365 strFullPath = strIndex;
366 strIndex = wxT("0");
367 }
368
369 if ( iconLoc )
370 {
371 iconLoc->SetFileName(wxExpandEnvVars(strFullPath));
372
373 iconLoc->SetIndex(wxAtoi(strIndex));
374 }
375
376 return true;
377 }
378 }
379
380 // no such file type or no value or incorrect icon entry
381 return false;
382 }
383
384 bool wxFileTypeImpl::GetDescription(wxString *desc) const
385 {
386 // suppress possible error messages
387 wxLogNull nolog;
388 wxRegKey key(wxRegKey::HKCR, m_strFileType);
389
390 if ( key.Open(wxRegKey::Read) ) {
391 // it's the default value of the key
392 if ( key.QueryValue(wxEmptyString, *desc) ) {
393 return true;
394 }
395 }
396
397 return false;
398 }
399
400 // helper function
401 wxFileType *
402 wxMimeTypesManagerImpl::CreateFileType(const wxString& filetype, const wxString& ext)
403 {
404 wxFileType *fileType = new wxFileType;
405 fileType->m_impl->Init(filetype, ext);
406 return fileType;
407 }
408
409 // extension -> file type
410 wxFileType *
411 wxMimeTypesManagerImpl::GetFileTypeFromExtension(const wxString& ext)
412 {
413 // add the leading point if necessary
414 wxString str;
415 if ( ext[0u] != wxT('.') ) {
416 str = wxT('.');
417 }
418 str << ext;
419
420 // suppress possible error messages
421 wxLogNull nolog;
422
423 bool knownExtension = false;
424
425 wxString strFileType;
426 wxRegKey key(wxRegKey::HKCR, str);
427 if ( key.Open(wxRegKey::Read) ) {
428 // it's the default value of the key
429 if ( key.QueryValue(wxEmptyString, strFileType) ) {
430 // create the new wxFileType object
431 return CreateFileType(strFileType, ext);
432 }
433 else {
434 // this extension doesn't have a filetype, but it's known to the
435 // system and may be has some other useful keys (open command or
436 // content-type), so still return a file type object for it
437 knownExtension = true;
438 }
439 }
440
441 if ( !knownExtension )
442 {
443 // unknown extension
444 return NULL;
445 }
446
447 return CreateFileType(wxEmptyString, ext);
448 }
449
450 /*
451 wxFileType *
452 wxMimeTypesManagerImpl::GetOrAllocateFileTypeFromExtension(const wxString& ext)
453 {
454 wxFileType *fileType = GetFileTypeFromExtension(ext);
455 if ( !fileType )
456 {
457 fileType = CreateFileType(wxEmptyString, ext);
458 }
459
460 return fileType;
461 }
462 */
463
464 // MIME type -> extension -> file type
465 wxFileType *
466 wxMimeTypesManagerImpl::GetFileTypeFromMimeType(const wxString& mimeType)
467 {
468 wxString strKey = MIME_DATABASE_KEY;
469 strKey << mimeType;
470
471 // suppress possible error messages
472 wxLogNull nolog;
473
474 wxString ext;
475 wxRegKey key(wxRegKey::HKCR, strKey);
476 if ( key.Open(wxRegKey::Read) ) {
477 if ( key.QueryValue(wxT("Extension"), ext) ) {
478 return GetFileTypeFromExtension(ext);
479 }
480 }
481
482 // unknown MIME type
483 return NULL;
484 }
485
486 size_t wxMimeTypesManagerImpl::EnumAllFileTypes(wxArrayString& mimetypes)
487 {
488 // enumerate all keys under MIME_DATABASE_KEY
489 wxRegKey key(wxRegKey::HKCR, MIME_DATABASE_KEY);
490
491 wxString type;
492 long cookie;
493 bool cont = key.GetFirstKey(type, cookie);
494 while ( cont )
495 {
496 mimetypes.Add(type);
497
498 cont = key.GetNextKey(type, cookie);
499 }
500
501 return mimetypes.GetCount();
502 }
503
504 // ----------------------------------------------------------------------------
505 // create a new association
506 // ----------------------------------------------------------------------------
507
508 wxFileType *wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo& ftInfo)
509 {
510 wxCHECK_MSG( !ftInfo.GetExtensions().IsEmpty(), NULL,
511 _T("Associate() needs extension") );
512
513 bool ok;
514 int iExtCount = 0 ;
515 wxString filetype;
516 wxString extWithDot;
517
518 wxString ext = ftInfo.GetExtensions()[iExtCount];
519
520 wxCHECK_MSG( !ext.empty(), NULL,
521 _T("Associate() needs non empty extension") );
522
523 if ( ext[0u] != _T('.') )
524 extWithDot = _T('.');
525 extWithDot += ext;
526
527 // start by setting the HKCR\\.ext entries
528 // default is filetype; content type is mimetype
529 const wxString& filetypeOrig = ftInfo.GetShortDesc();
530
531 wxRegKey key(wxRegKey::HKCR, extWithDot);
532 if ( !key.Exists() )
533 {
534 // create the mapping from the extension to the filetype
535 ok = key.Create();
536 if ( ok )
537 {
538
539 if ( filetypeOrig.empty() )
540 {
541 // make it up from the extension
542 filetype << extWithDot.c_str() + 1 << _T("_file");
543 }
544 else
545 {
546 // just use the provided one
547 filetype = filetypeOrig;
548 }
549
550 key.SetValue(wxEmptyString, filetype);
551 }
552 }
553 else
554 {
555 // key already exists, maybe we want to change it ??
556 if (!filetypeOrig.empty())
557 {
558 filetype = filetypeOrig;
559 key.SetValue(wxEmptyString, filetype);
560 }
561 else
562 {
563 key.QueryValue(wxEmptyString, filetype);
564 }
565 }
566 // now set a mimetypeif we have it, but ignore it if none
567 const wxString& mimetype = ftInfo.GetMimeType();
568 if ( !mimetype.empty() )
569 {
570 // set the MIME type
571 ok = key.SetValue(_T("Content Type"), mimetype);
572
573 if ( ok )
574 {
575 // create the MIME key
576 wxString strKey = MIME_DATABASE_KEY;
577 strKey << mimetype;
578 wxRegKey keyMIME(wxRegKey::HKCR, strKey);
579 ok = keyMIME.Create();
580
581 if ( ok )
582 {
583 // and provide a back link to the extension
584 keyMIME.SetValue(_T("Extension"), extWithDot);
585 }
586 }
587 }
588
589
590 // now make other extensions have the same filetype
591
592 for (iExtCount=1; iExtCount < ftInfo.GetExtensionsCount(); iExtCount++ )
593 {
594 ext = ftInfo.GetExtensions()[iExtCount];
595 if ( ext[0u] != _T('.') )
596 extWithDot = _T('.');
597 extWithDot += ext;
598
599 wxRegKey key(wxRegKey::HKCR, extWithDot);
600 if ( !key.Exists() ) key.Create();
601 key.SetValue(wxEmptyString, filetype);
602
603 // now set any mimetypes we may have, but ignore it if none
604 const wxString& mimetype = ftInfo.GetMimeType();
605 if ( !mimetype.empty() )
606 {
607 // set the MIME type
608 ok = key.SetValue(_T("Content Type"), mimetype);
609
610 if ( ok )
611 {
612 // create the MIME key
613 wxString strKey = MIME_DATABASE_KEY;
614 strKey << mimetype;
615 wxRegKey keyMIME(wxRegKey::HKCR, strKey);
616 ok = keyMIME.Create();
617
618 if ( ok )
619 {
620 // and provide a back link to the extension
621 keyMIME.SetValue(_T("Extension"), extWithDot);
622 }
623 }
624 }
625
626
627 } // end of for loop; all extensions now point to HKCR\.ext\Default
628
629 // create the filetype key itself (it will be empty for now, but
630 // SetCommand(), SetDefaultIcon() &c will use it later)
631 wxRegKey keyFT(wxRegKey::HKCR, filetype);
632 keyFT.Create();
633
634 wxFileType *ft = CreateFileType(filetype, extWithDot);
635
636 if (ft)
637 {
638 if (! ftInfo.GetOpenCommand ().IsEmpty() ) ft->SetCommand (ftInfo.GetOpenCommand (), wxT("open" ) );
639 if (! ftInfo.GetPrintCommand().IsEmpty() ) ft->SetCommand (ftInfo.GetPrintCommand(), wxT("print" ) );
640 // chris: I don't like the ->m_impl-> here FIX this ??
641 if (! ftInfo.GetDescription ().IsEmpty() ) ft->m_impl->SetDescription (ftInfo.GetDescription ()) ;
642 if (! ftInfo.GetIconFile().IsEmpty() ) ft->SetDefaultIcon (ftInfo.GetIconFile(), ftInfo.GetIconIndex() );
643
644 }
645 return ft;
646 }
647
648 bool wxFileTypeImpl::SetCommand(const wxString& cmd,
649 const wxString& verb,
650 bool WXUNUSED(overwriteprompt))
651 {
652 wxCHECK_MSG( !m_ext.empty() && !verb.empty(), false,
653 _T("SetCommand() needs an extension and a verb") );
654
655 if ( !EnsureExtKeyExists() )
656 return false;
657
658 wxRegKey rkey(wxRegKey::HKCR, GetVerbPath(verb));
659 #if 0
660 if ( rkey.Exists() && overwriteprompt )
661 {
662 #if wxUSE_GUI
663 wxString old;
664 rkey.QueryValue(wxEmptyString, old);
665 if ( wxMessageBox
666 (
667 wxString::Format(
668 _("Do you want to overwrite the command used to %s "
669 "files with extension \"%s\" ?\nCurrent value is \n%s, "
670 "\nNew value is \n%s %1"), // bug here FIX need %1 ??
671 verb.c_str(),
672 m_ext.c_str(),
673 old.c_str(),
674 cmd.c_str()),
675 _("Confirm registry update"),
676 wxYES_NO | wxICON_QUESTION
677 ) != wxYES )
678 #endif // wxUSE_GUI
679 {
680 // cancelled by user
681 return false;
682 }
683 }
684 #endif
685 // TODO:
686 // 1. translate '%s' to '%1' instead of always adding it
687 // 2. create DDEExec value if needed (undo GetCommand)
688 return rkey.Create() && rkey.SetValue(wxEmptyString, cmd + _T(" \"%1\"") );
689 }
690
691 /* // no longer used
692 bool wxFileTypeImpl::SetMimeType(const wxString& mimeTypeOrig)
693 {
694 wxCHECK_MSG( !m_ext.empty(), false, _T("SetMimeType() needs extension") );
695
696 if ( !EnsureExtKeyExists() )
697 return false;
698
699 // VZ: is this really useful? (FIXME)
700 wxString mimeType;
701 if ( !mimeTypeOrig )
702 {
703 // make up a default value for it
704 wxString cmd;
705 wxSplitPath(GetCommand(_T("open")), NULL, &cmd, NULL);
706 mimeType << _T("application/x-") << cmd;
707 }
708 else
709 {
710 mimeType = mimeTypeOrig;
711 }
712
713 wxRegKey rkey(wxRegKey::HKCR, m_ext);
714 return rkey.Create() && rkey.SetValue(_T("Content Type"), mimeType);
715 }
716 */
717
718 bool wxFileTypeImpl::SetDefaultIcon(const wxString& cmd, int index)
719 {
720 wxCHECK_MSG( !m_ext.empty(), false, _T("SetDefaultIcon() needs extension") );
721 wxCHECK_MSG( !m_strFileType.empty(), false, _T("File key not found") );
722 // the next line fails on a SMBshare, I think because it is case mangled
723 // wxCHECK_MSG( !wxFileExists(cmd), false, _T("Icon file not found.") );
724
725 if ( !EnsureExtKeyExists() )
726 return false;
727
728 wxRegKey rkey(wxRegKey::HKCR, m_strFileType + _T("\\DefaultIcon"));
729
730 return rkey.Create() &&
731 rkey.SetValue(wxEmptyString,
732 wxString::Format(_T("%s,%d"), cmd.c_str(), index));
733 }
734
735 bool wxFileTypeImpl::SetDescription (const wxString& desc)
736 {
737 wxCHECK_MSG( !m_strFileType.empty(), false, _T("File key not found") );
738 wxCHECK_MSG( !desc.empty(), false, _T("No file description supplied") );
739
740 if ( !EnsureExtKeyExists() )
741 return false;
742
743 wxRegKey rkey(wxRegKey::HKCR, m_strFileType );
744
745 return rkey.Create() &&
746 rkey.SetValue(wxEmptyString, desc);
747 }
748
749 // ----------------------------------------------------------------------------
750 // remove file association
751 // ----------------------------------------------------------------------------
752
753 bool wxFileTypeImpl::Unassociate()
754 {
755 bool result = true;
756 if ( !RemoveOpenCommand() )
757 result = false;
758 if ( !RemoveDefaultIcon() )
759 result = false;
760 if ( !RemoveMimeType() )
761 result = false;
762 if ( !RemoveDescription() )
763 result = false;
764
765 /*
766 //this might hold other keys, eg some have CSLID keys
767 if ( result )
768 {
769 // delete the root key
770 wxRegKey key(wxRegKey::HKCR, m_ext);
771 if ( key.Exists() )
772 result = key.DeleteSelf();
773 }
774 */
775 return result;
776 }
777
778 bool wxFileTypeImpl::RemoveOpenCommand()
779 {
780 return RemoveCommand(_T("open"));
781 }
782
783 bool wxFileTypeImpl::RemoveCommand(const wxString& verb)
784 {
785 wxCHECK_MSG( !m_ext.empty() && !verb.empty(), false,
786 _T("RemoveCommand() needs an extension and a verb") );
787
788 wxString sKey = m_strFileType;
789 wxRegKey rkey(wxRegKey::HKCR, GetVerbPath(verb));
790
791 // if the key already doesn't exist, it's a success
792 return !rkey.Exists() || rkey.DeleteSelf();
793 }
794
795 bool wxFileTypeImpl::RemoveMimeType()
796 {
797 wxCHECK_MSG( !m_ext.empty(), false, _T("RemoveMimeType() needs extension") );
798
799 wxRegKey rkey(wxRegKey::HKCR, m_ext);
800 return !rkey.Exists() || rkey.DeleteSelf();
801 }
802
803 bool wxFileTypeImpl::RemoveDefaultIcon()
804 {
805 wxCHECK_MSG( !m_ext.empty(), false,
806 _T("RemoveDefaultIcon() needs extension") );
807
808 wxRegKey rkey (wxRegKey::HKCR, m_strFileType + _T("\\DefaultIcon"));
809 return !rkey.Exists() || rkey.DeleteSelf();
810 }
811
812 bool wxFileTypeImpl::RemoveDescription()
813 {
814 wxCHECK_MSG( !m_ext.empty(), false,
815 _T("RemoveDescription() needs extension") );
816
817 wxRegKey rkey (wxRegKey::HKCR, m_strFileType );
818 return !rkey.Exists() || rkey.DeleteSelf();
819 }
820
821 #endif // wxUSE_MIMETYPE
822 #endif // __WXPALMOS__