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