]> git.saurik.com Git - wxWidgets.git/blob - src/common/filename.cpp
df431a87a5cb7566eb5f3a0d6bea3f89cbdcaf02
[wxWidgets.git] / src / common / filename.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/filename.cpp
3 // Purpose: wxFileName - encapsulates a file path
4 // Author: Robert Roebling, Vadim Zeitlin
5 // Modified by:
6 // Created: 28.12.2000
7 // RCS-ID: $Id$
8 // Copyright: (c) 2000 Robert Roebling
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 /*
13 Here are brief descriptions of the filename formats supported by this class:
14
15 wxPATH_UNIX: standard Unix format, used under Darwin as well, absolute file
16 names have the form:
17 /dir1/dir2/.../dirN/filename, "." and ".." stand for the
18 current and parent directory respectively, "~" is parsed as the
19 user HOME and "~username" as the HOME of that user
20
21 wxPATH_DOS: DOS/Windows format, absolute file names have the form:
22 drive:\dir1\dir2\...\dirN\filename.ext where drive is a single
23 letter. "." and ".." as for Unix but no "~".
24
25 There are also UNC names of the form \\share\fullpath
26
27 wxPATH_MAC: Mac OS 8/9 and Mac OS X under CodeWarrior 7 format, absolute file
28 names have the form
29 volume:dir1:...:dirN:filename
30 and the relative file names are either
31 :dir1:...:dirN:filename
32 or just
33 filename
34 (although :filename works as well).
35 Since the volume is just part of the file path, it is not
36 treated like a separate entity as it is done under DOS and
37 VMS, it is just treated as another dir.
38
39 wxPATH_VMS: VMS native format, absolute file names have the form
40 <device>:[dir1.dir2.dir3]file.txt
41 or
42 <device>:[000000.dir1.dir2.dir3]file.txt
43
44 the <device> is the physical device (i.e. disk). 000000 is the
45 root directory on the device which can be omitted.
46
47 Note that VMS uses different separators unlike Unix:
48 : always after the device. If the path does not contain : than
49 the default (the device of the current directory) is assumed.
50 [ start of directory specyfication
51 . separator between directory and subdirectory
52 ] between directory and file
53 */
54
55 // ============================================================================
56 // declarations
57 // ============================================================================
58
59 // ----------------------------------------------------------------------------
60 // headers
61 // ----------------------------------------------------------------------------
62
63 #ifdef __GNUG__
64 #pragma implementation "filename.h"
65 #endif
66
67 // For compilers that support precompilation, includes "wx.h".
68 #include "wx/wxprec.h"
69
70 #ifdef __BORLANDC__
71 #pragma hdrstop
72 #endif
73
74 #ifndef WX_PRECOMP
75 #include "wx/intl.h"
76 #include "wx/log.h"
77 #include "wx/file.h"
78 #endif
79
80 #include "wx/filename.h"
81 #include "wx/tokenzr.h"
82 #include "wx/config.h" // for wxExpandEnvVars
83 #include "wx/utils.h"
84 #include "wx/file.h"
85
86 #if wxUSE_DYNAMIC_LOADER || wxUSE_DYNLIB_CLASS
87 #include "wx/dynlib.h"
88 #endif
89
90 // For GetShort/LongPathName
91 #ifdef __WIN32__
92 #include <windows.h>
93 #include "wx/msw/winundef.h"
94 #endif
95
96 // utime() is POSIX so should normally be available on all Unices
97 #ifdef __UNIX_LIKE__
98 #include <sys/types.h>
99 #include <utime.h>
100 #include <sys/stat.h>
101 #include <unistd.h>
102 #endif
103
104 #ifdef __MWERKS__
105 #include <stat.h>
106 #include <unistd.h>
107 #include <unix.h>
108 #endif
109
110 #ifdef __WATCOMC__
111 #include <io.h>
112 #include <sys/utime.h>
113 #include <sys/stat.h>
114 #endif
115
116 #ifdef __VISAGECPP__
117 #ifndef MAX_PATH
118 #define MAX_PATH 256
119 #endif
120 #endif
121
122 // ----------------------------------------------------------------------------
123 // private classes
124 // ----------------------------------------------------------------------------
125
126 // small helper class which opens and closes the file - we use it just to get
127 // a file handle for the given file name to pass it to some Win32 API function
128 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
129
130 class wxFileHandle
131 {
132 public:
133 wxFileHandle(const wxString& filename)
134 {
135 m_hFile = ::CreateFile
136 (
137 filename, // name
138 GENERIC_READ, // access mask
139 0, // no sharing
140 NULL, // no secutity attr
141 OPEN_EXISTING, // creation disposition
142 0, // no flags
143 NULL // no template file
144 );
145
146 if ( m_hFile == INVALID_HANDLE_VALUE )
147 {
148 wxLogSysError(_("Failed to open '%s' for reading"),
149 filename.c_str());
150 }
151 }
152
153 ~wxFileHandle()
154 {
155 if ( m_hFile != INVALID_HANDLE_VALUE )
156 {
157 if ( !::CloseHandle(m_hFile) )
158 {
159 wxLogSysError(_("Failed to close file handle"));
160 }
161 }
162 }
163
164 // return TRUE only if the file could be opened successfully
165 bool IsOk() const { return m_hFile != INVALID_HANDLE_VALUE; }
166
167 // get the handle
168 operator HANDLE() const { return m_hFile; }
169
170 private:
171 HANDLE m_hFile;
172 };
173
174 #endif // __WIN32__
175
176 // ----------------------------------------------------------------------------
177 // private functions
178 // ----------------------------------------------------------------------------
179
180 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
181
182 // convert between wxDateTime and FILETIME which is a 64-bit value representing
183 // the number of 100-nanosecond intervals since January 1, 1601.
184
185 // the number of milliseconds between the Unix Epoch (January 1, 1970) and the
186 // FILETIME reference point (January 1, 1601)
187 static const wxLongLong FILETIME_EPOCH_OFFSET = wxLongLong(0xa97, 0x30b66800);
188
189 static void ConvertFileTimeToWx(wxDateTime *dt, const FILETIME &ft)
190 {
191 wxLongLong ll(ft.dwHighDateTime, ft.dwLowDateTime);
192
193 // convert 100ns to ms
194 ll /= 10000;
195
196 // move it to our Epoch
197 ll -= FILETIME_EPOCH_OFFSET;
198
199 *dt = wxDateTime(ll);
200 }
201
202 static void ConvertWxToFileTime(FILETIME *ft, const wxDateTime& dt)
203 {
204 // do the reverse of ConvertFileTimeToWx()
205 wxLongLong ll = dt.GetValue();
206 ll *= 10000;
207 ll += FILETIME_EPOCH_OFFSET;
208
209 ft->dwHighDateTime = ll.GetHi();
210 ft->dwLowDateTime = ll.GetLo();
211 }
212
213 #endif // __WIN32__
214
215 // ============================================================================
216 // implementation
217 // ============================================================================
218
219 // ----------------------------------------------------------------------------
220 // wxFileName construction
221 // ----------------------------------------------------------------------------
222
223 void wxFileName::Assign( const wxFileName &filepath )
224 {
225 m_volume = filepath.GetVolume();
226 m_dirs = filepath.GetDirs();
227 m_name = filepath.GetName();
228 m_ext = filepath.GetExt();
229 m_relative = filepath.IsRelative();
230 }
231
232 void wxFileName::Assign(const wxString& volume,
233 const wxString& path,
234 const wxString& name,
235 const wxString& ext,
236 wxPathFormat format )
237 {
238 wxPathFormat my_format = GetFormat( format );
239 wxString my_path = path;
240
241 m_dirs.Clear();
242
243 if (!my_path.empty())
244 {
245 // 1) Determine if the path is relative or absolute.
246
247 switch (my_format)
248 {
249 case wxPATH_MAC:
250 m_relative = ( my_path[0u] == wxT(':') );
251 // We then remove a leading ":". The reason is in our
252 // storage form for relative paths:
253 // ":dir:file.txt" actually means "./dir/file.txt" in
254 // DOS notation and should get stored as
255 // (relative) (dir) (file.txt)
256 // "::dir:file.txt" actually means "../dir/file.txt"
257 // stored as (relative) (..) (dir) (file.txt)
258 // This is important only for the Mac as an empty dir
259 // actually means <UP>, whereas under DOS, double
260 // slashes can be ignored: "\\\\" is the same as "\\".
261 if (m_relative)
262 my_path.Remove( 0, 1 );
263 break;
264 case wxPATH_VMS:
265 // TODO: what is the relative path format here?
266 m_relative = FALSE;
267 break;
268 case wxPATH_UNIX:
269 m_relative = ( my_path[0u] != wxT('/') );
270 break;
271 case wxPATH_DOS:
272 m_relative = ( (my_path[0u] != wxT('/')) && (my_path[0u] != wxT('\\')) );
273 break;
274 default:
275 wxFAIL_MSG( wxT("error") );
276 break;
277 }
278
279 // 2) Break up the path into its members. If the original path
280 // was just "/" or "\\", m_dirs will be empty. We know from
281 // the m_relative field, if this means "nothing" or "root dir".
282
283 wxStringTokenizer tn( my_path, GetPathSeparators(my_format) );
284
285 while ( tn.HasMoreTokens() )
286 {
287 wxString token = tn.GetNextToken();
288
289 // Remove empty token under DOS and Unix, interpret them
290 // as .. under Mac.
291 if (token.empty())
292 {
293 if (my_format == wxPATH_MAC)
294 m_dirs.Add( wxT("..") );
295 // else ignore
296 }
297 else
298 {
299 m_dirs.Add( token );
300 }
301 }
302 }
303
304 m_volume = volume;
305 m_ext = ext;
306 m_name = name;
307 }
308
309 void wxFileName::Assign(const wxString& fullpath,
310 wxPathFormat format)
311 {
312 wxString volume, path, name, ext;
313 SplitPath(fullpath, &volume, &path, &name, &ext, format);
314
315 Assign(volume, path, name, ext, format);
316 }
317
318 void wxFileName::Assign(const wxString& fullpathOrig,
319 const wxString& fullname,
320 wxPathFormat format)
321 {
322 // always recognize fullpath as directory, even if it doesn't end with a
323 // slash
324 wxString fullpath = fullpathOrig;
325 if ( !wxEndsWithPathSeparator(fullpath) )
326 {
327 fullpath += GetPathSeparators(format)[0u];
328 }
329
330 wxString volume, path, name, ext;
331
332 // do some consistency checks in debug mode: the name should be really just
333 // the filename and the path should be really just a path
334 #ifdef __WXDEBUG__
335 wxString pathDummy, nameDummy, extDummy;
336
337 SplitPath(fullname, &pathDummy, &name, &ext, format);
338
339 wxASSERT_MSG( pathDummy.empty(),
340 _T("the file name shouldn't contain the path") );
341
342 SplitPath(fullpath, &volume, &path, &nameDummy, &extDummy, format);
343
344 wxASSERT_MSG( nameDummy.empty() && extDummy.empty(),
345 _T("the path shouldn't contain file name nor extension") );
346
347 #else // !__WXDEBUG__
348 SplitPath(fullname, NULL /* no path */, &name, &ext, format);
349 SplitPath(fullpath, &volume, &path, NULL, NULL, format);
350 #endif // __WXDEBUG__/!__WXDEBUG__
351
352 Assign(volume, path, name, ext, format);
353 }
354
355 void wxFileName::AssignDir(const wxString& dir, wxPathFormat format)
356 {
357 Assign(dir, _T(""), format);
358 }
359
360 void wxFileName::Clear()
361 {
362 m_dirs.Clear();
363
364 m_volume =
365 m_name =
366 m_ext = wxEmptyString;
367 }
368
369 /* static */
370 wxFileName wxFileName::FileName(const wxString& file)
371 {
372 return wxFileName(file);
373 }
374
375 /* static */
376 wxFileName wxFileName::DirName(const wxString& dir)
377 {
378 wxFileName fn;
379 fn.AssignDir(dir);
380 return fn;
381 }
382
383 // ----------------------------------------------------------------------------
384 // existence tests
385 // ----------------------------------------------------------------------------
386
387 bool wxFileName::FileExists()
388 {
389 return wxFileName::FileExists( GetFullPath() );
390 }
391
392 bool wxFileName::FileExists( const wxString &file )
393 {
394 return ::wxFileExists( file );
395 }
396
397 bool wxFileName::DirExists()
398 {
399 return wxFileName::DirExists( GetFullPath() );
400 }
401
402 bool wxFileName::DirExists( const wxString &dir )
403 {
404 return ::wxDirExists( dir );
405 }
406
407 // ----------------------------------------------------------------------------
408 // CWD and HOME stuff
409 // ----------------------------------------------------------------------------
410
411 void wxFileName::AssignCwd(const wxString& volume)
412 {
413 AssignDir(wxFileName::GetCwd(volume));
414 }
415
416 /* static */
417 wxString wxFileName::GetCwd(const wxString& volume)
418 {
419 // if we have the volume, we must get the current directory on this drive
420 // and to do this we have to chdir to this volume - at least under Windows,
421 // I don't know how to get the current drive on another volume elsewhere
422 // (TODO)
423 wxString cwdOld;
424 if ( !volume.empty() )
425 {
426 cwdOld = wxGetCwd();
427 SetCwd(volume + GetVolumeSeparator());
428 }
429
430 wxString cwd = ::wxGetCwd();
431
432 if ( !volume.empty() )
433 {
434 SetCwd(cwdOld);
435 }
436
437 return cwd;
438 }
439
440 bool wxFileName::SetCwd()
441 {
442 return wxFileName::SetCwd( GetFullPath() );
443 }
444
445 bool wxFileName::SetCwd( const wxString &cwd )
446 {
447 return ::wxSetWorkingDirectory( cwd );
448 }
449
450 void wxFileName::AssignHomeDir()
451 {
452 AssignDir(wxFileName::GetHomeDir());
453 }
454
455 wxString wxFileName::GetHomeDir()
456 {
457 return ::wxGetHomeDir();
458 }
459
460 void wxFileName::AssignTempFileName(const wxString& prefix, wxFile *fileTemp)
461 {
462 wxString tempname = CreateTempFileName(prefix, fileTemp);
463 if ( tempname.empty() )
464 {
465 // error, failed to get temp file name
466 Clear();
467 }
468 else // ok
469 {
470 Assign(tempname);
471 }
472 }
473
474 /* static */
475 wxString
476 wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp)
477 {
478 wxString path, dir, name;
479
480 // use the directory specified by the prefix
481 SplitPath(prefix, &dir, &name, NULL /* extension */);
482
483 #if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
484
485 #ifdef __WIN32__
486 if ( dir.empty() )
487 {
488 if ( !::GetTempPath(MAX_PATH, wxStringBuffer(dir, MAX_PATH + 1)) )
489 {
490 wxLogLastError(_T("GetTempPath"));
491 }
492
493 if ( dir.empty() )
494 {
495 // GetTempFileName() fails if we pass it an empty string
496 dir = _T('.');
497 }
498 }
499
500 if ( !::GetTempFileName(dir, name, 0, wxStringBuffer(path, MAX_PATH + 1)) )
501 {
502 wxLogLastError(_T("GetTempFileName"));
503
504 path.clear();
505 }
506 #else // Win16
507 if ( !::GetTempFileName(NULL, prefix, 0, wxStringBuffer(path, 1025)) )
508 {
509 path.clear();
510 }
511 #endif // Win32/16
512
513 #elif defined(__WXPM__)
514 // for now just create a file
515 //
516 // future enhancements can be to set some extended attributes for file
517 // systems OS/2 supports that have them (HPFS, FAT32) and security
518 // (HPFS386)
519 static const wxChar *szMktempSuffix = wxT("XXX");
520 path << dir << _T('/') << name << szMktempSuffix;
521
522 // Temporarily remove - MN
523 #ifndef __WATCOMC__
524 ::DosCreateDir(wxStringBuffer(path, MAX_PATH), NULL);
525 #endif
526
527 #else // !Windows, !OS/2
528 if ( dir.empty() )
529 {
530 dir = wxGetenv(_T("TMP"));
531 if ( path.empty() )
532 {
533 dir = wxGetenv(_T("TEMP"));
534 }
535
536 if ( dir.empty() )
537 {
538 // default
539 #ifdef __DOS__
540 dir = _T(".");
541 #else
542 dir = _T("/tmp");
543 #endif
544 }
545 }
546
547 path = dir;
548
549 if ( !wxEndsWithPathSeparator(dir) &&
550 (name.empty() || !wxIsPathSeparator(name[0u])) )
551 {
552 path += wxFILE_SEP_PATH;
553 }
554
555 path += name;
556
557 #if defined(HAVE_MKSTEMP)
558 // scratch space for mkstemp()
559 path += _T("XXXXXX");
560
561 // can use the cast here because the length doesn't change and the string
562 // is not shared
563 int fdTemp = mkstemp((char *)path.mb_str());
564 if ( fdTemp == -1 )
565 {
566 // this might be not necessary as mkstemp() on most systems should have
567 // already done it but it doesn't hurt neither...
568 path.clear();
569 }
570 else // mkstemp() succeeded
571 {
572 // avoid leaking the fd
573 if ( fileTemp )
574 {
575 fileTemp->Attach(fdTemp);
576 }
577 else
578 {
579 close(fdTemp);
580 }
581 }
582 #else // !HAVE_MKSTEMP
583
584 #ifdef HAVE_MKTEMP
585 // same as above
586 path += _T("XXXXXX");
587
588 if ( !mktemp((char *)path.mb_str()) )
589 {
590 path.clear();
591 }
592 #else // !HAVE_MKTEMP (includes __DOS__)
593 // generate the unique file name ourselves
594 #ifndef __DOS__
595 path << (unsigned int)getpid();
596 #endif
597
598 wxString pathTry;
599
600 static const size_t numTries = 1000;
601 for ( size_t n = 0; n < numTries; n++ )
602 {
603 // 3 hex digits is enough for numTries == 1000 < 4096
604 pathTry = path + wxString::Format(_T("%.03x"), n);
605 if ( !wxFile::Exists(pathTry) )
606 {
607 break;
608 }
609
610 pathTry.clear();
611 }
612
613 path = pathTry;
614 #endif // HAVE_MKTEMP/!HAVE_MKTEMP
615
616 if ( !path.empty() )
617 {
618 }
619 #endif // HAVE_MKSTEMP/!HAVE_MKSTEMP
620
621 #endif // Windows/!Windows
622
623 if ( path.empty() )
624 {
625 wxLogSysError(_("Failed to create a temporary file name"));
626 }
627 else if ( fileTemp && !fileTemp->IsOpened() )
628 {
629 // open the file - of course, there is a race condition here, this is
630 // why we always prefer using mkstemp()...
631 if ( !fileTemp->Open(path, wxFile::write_excl, wxS_IRUSR | wxS_IWUSR) )
632 {
633 // FIXME: If !ok here should we loop and try again with another
634 // file name? That is the standard recourse if open(O_EXCL)
635 // fails, though of course it should be protected against
636 // possible infinite looping too.
637
638 wxLogError(_("Failed to open temporary file."));
639
640 path.clear();
641 }
642 }
643
644 return path;
645 }
646
647 // ----------------------------------------------------------------------------
648 // directory operations
649 // ----------------------------------------------------------------------------
650
651 bool wxFileName::Mkdir( int perm, bool full )
652 {
653 return wxFileName::Mkdir( GetFullPath(), perm, full );
654 }
655
656 bool wxFileName::Mkdir( const wxString &dir, int perm, bool full )
657 {
658 if (full)
659 {
660 wxFileName filename(dir);
661 wxArrayString dirs = filename.GetDirs();
662 dirs.Add(filename.GetName());
663
664 size_t count = dirs.GetCount();
665 size_t i;
666 wxString currPath;
667 int noErrors = 0;
668 for ( i = 0; i < count; i++ )
669 {
670 currPath += dirs[i];
671
672 if (currPath.Last() == wxT(':'))
673 {
674 // Can't create a root directory so continue to next dir
675 currPath += wxFILE_SEP_PATH;
676 continue;
677 }
678
679 if (!DirExists(currPath))
680 if (!wxMkdir(currPath, perm))
681 noErrors ++;
682
683 if ( (i < (count-1)) )
684 currPath += wxFILE_SEP_PATH;
685 }
686
687 return (noErrors == 0);
688
689 }
690 else
691 return ::wxMkdir( dir, perm );
692 }
693
694 bool wxFileName::Rmdir()
695 {
696 return wxFileName::Rmdir( GetFullPath() );
697 }
698
699 bool wxFileName::Rmdir( const wxString &dir )
700 {
701 return ::wxRmdir( dir );
702 }
703
704 // ----------------------------------------------------------------------------
705 // path normalization
706 // ----------------------------------------------------------------------------
707
708 bool wxFileName::Normalize(wxPathNormalize flags,
709 const wxString& cwd,
710 wxPathFormat format)
711 {
712 // the existing path components
713 wxArrayString dirs = GetDirs();
714
715 // the path to prepend in front to make the path absolute
716 wxFileName curDir;
717
718 format = GetFormat(format);
719
720 // make the path absolute
721 if ( (flags & wxPATH_NORM_ABSOLUTE) && m_relative )
722 {
723 if ( cwd.empty() )
724 {
725 curDir.AssignCwd(GetVolume());
726 }
727 else // cwd provided
728 {
729 curDir.AssignDir(cwd);
730 }
731
732 #if 0
733 // the path may be not absolute because it doesn't have the volume name
734 // but in this case we shouldn't modify the directory components of it
735 // but just set the current volume
736 if ( !HasVolume() && curDir.HasVolume() )
737 {
738 SetVolume(curDir.GetVolume());
739
740 if ( IsAbsolute() )
741 {
742 // yes, it was the case - we don't need curDir then
743 curDir.Clear();
744 }
745 }
746 #endif
747 m_relative = FALSE;
748 }
749
750 // handle ~ stuff under Unix only
751 if ( (format == wxPATH_UNIX) && (flags & wxPATH_NORM_TILDE) )
752 {
753 if ( !dirs.IsEmpty() )
754 {
755 wxString dir = dirs[0u];
756 if ( !dir.empty() && dir[0u] == _T('~') )
757 {
758 curDir.AssignDir(wxGetUserHome(dir.c_str() + 1));
759
760 dirs.RemoveAt(0u);
761 }
762 }
763 }
764
765 // transform relative path into abs one
766 if ( curDir.IsOk() )
767 {
768 wxArrayString dirsNew = curDir.GetDirs();
769 size_t count = dirs.GetCount();
770 for ( size_t n = 0; n < count; n++ )
771 {
772 dirsNew.Add(dirs[n]);
773 }
774
775 dirs = dirsNew;
776 }
777
778 // now deal with ".", ".." and the rest
779 m_dirs.Empty();
780 size_t count = dirs.GetCount();
781 for ( size_t n = 0; n < count; n++ )
782 {
783 wxString dir = dirs[n];
784
785 if ( flags & wxPATH_NORM_DOTS )
786 {
787 if ( dir == wxT(".") )
788 {
789 // just ignore
790 continue;
791 }
792
793 if ( dir == wxT("..") )
794 {
795 if ( m_dirs.IsEmpty() )
796 {
797 wxLogError(_("The path '%s' contains too many \"..\"!"),
798 GetFullPath().c_str());
799 return FALSE;
800 }
801
802 m_dirs.RemoveAt(m_dirs.GetCount() - 1);
803 continue;
804 }
805 }
806
807 if ( flags & wxPATH_NORM_ENV_VARS )
808 {
809 dir = wxExpandEnvVars(dir);
810 }
811
812 if ( (flags & wxPATH_NORM_CASE) && !IsCaseSensitive(format) )
813 {
814 dir.MakeLower();
815 }
816
817 m_dirs.Add(dir);
818 }
819
820 if ( (flags & wxPATH_NORM_CASE) && !IsCaseSensitive(format) )
821 {
822 // VZ: expand env vars here too?
823
824 m_name.MakeLower();
825 m_ext.MakeLower();
826 }
827
828 #if defined(__WIN32__)
829 if ( (flags & wxPATH_NORM_LONG) && (format == wxPATH_DOS) )
830 {
831 Assign(GetLongPath());
832 }
833 #endif // Win32
834
835 return TRUE;
836 }
837
838 bool wxFileName::MakeRelativeTo(const wxString& pathBase, wxPathFormat format)
839 {
840 wxFileName fnBase(pathBase, format);
841
842 // get cwd only once - small time saving
843 wxString cwd = wxGetCwd();
844 Normalize(wxPATH_NORM_ALL, cwd, format);
845 fnBase.Normalize(wxPATH_NORM_ALL, cwd, format);
846
847 bool withCase = IsCaseSensitive(format);
848
849 // we can't do anything if the files live on different volumes
850 if ( !GetVolume().IsSameAs(fnBase.GetVolume(), withCase) )
851 {
852 // nothing done
853 return FALSE;
854 }
855
856 // same drive, so we don't need our volume
857 m_volume.clear();
858
859 // remove common directories starting at the top
860 while ( !m_dirs.IsEmpty() && !fnBase.m_dirs.IsEmpty() &&
861 m_dirs[0u].IsSameAs(fnBase.m_dirs[0u], withCase) )
862 {
863 m_dirs.RemoveAt(0);
864 fnBase.m_dirs.RemoveAt(0);
865 }
866
867 // add as many ".." as needed
868 size_t count = fnBase.m_dirs.GetCount();
869 for ( size_t i = 0; i < count; i++ )
870 {
871 m_dirs.Insert(wxT(".."), 0u);
872 }
873
874 m_relative = TRUE;
875
876 // we were modified
877 return TRUE;
878 }
879
880 // ----------------------------------------------------------------------------
881 // filename kind tests
882 // ----------------------------------------------------------------------------
883
884 bool wxFileName::SameAs(const wxFileName &filepath, wxPathFormat format)
885 {
886 wxFileName fn1 = *this,
887 fn2 = filepath;
888
889 // get cwd only once - small time saving
890 wxString cwd = wxGetCwd();
891 fn1.Normalize(wxPATH_NORM_ALL, cwd, format);
892 fn2.Normalize(wxPATH_NORM_ALL, cwd, format);
893
894 if ( fn1.GetFullPath() == fn2.GetFullPath() )
895 return TRUE;
896
897 // TODO: compare inodes for Unix, this works even when filenames are
898 // different but files are the same (symlinks) (VZ)
899
900 return FALSE;
901 }
902
903 /* static */
904 bool wxFileName::IsCaseSensitive( wxPathFormat format )
905 {
906 // only Unix filenames are truely case-sensitive
907 return GetFormat(format) == wxPATH_UNIX;
908 }
909
910 /* static */
911 wxString wxFileName::GetVolumeSeparator(wxPathFormat format)
912 {
913 wxString sepVol;
914
915 if ( (GetFormat(format) == wxPATH_DOS) ||
916 (GetFormat(format) == wxPATH_VMS) )
917 {
918 sepVol = wxFILE_SEP_DSK;
919 }
920 //else: leave empty
921
922 return sepVol;
923 }
924
925 /* static */
926 wxString wxFileName::GetPathSeparators(wxPathFormat format)
927 {
928 wxString seps;
929 switch ( GetFormat(format) )
930 {
931 case wxPATH_DOS:
932 // accept both as native APIs do but put the native one first as
933 // this is the one we use in GetFullPath()
934 seps << wxFILE_SEP_PATH_DOS << wxFILE_SEP_PATH_UNIX;
935 break;
936
937 default:
938 wxFAIL_MSG( _T("unknown wxPATH_XXX style") );
939 // fall through
940
941 case wxPATH_UNIX:
942 seps = wxFILE_SEP_PATH_UNIX;
943 break;
944
945 case wxPATH_MAC:
946 seps = wxFILE_SEP_PATH_MAC;
947 break;
948
949 case wxPATH_VMS:
950 seps = wxFILE_SEP_PATH_VMS;
951 break;
952 }
953
954 return seps;
955 }
956
957 /* static */
958 bool wxFileName::IsPathSeparator(wxChar ch, wxPathFormat format)
959 {
960 // wxString::Find() doesn't work as expected with NUL - it will always find
961 // it, so it is almost surely a bug if this function is called with NUL arg
962 wxASSERT_MSG( ch != _T('\0'), _T("shouldn't be called with NUL") );
963
964 return GetPathSeparators(format).Find(ch) != wxNOT_FOUND;
965 }
966
967 bool wxFileName::IsWild( wxPathFormat format )
968 {
969 // FIXME: this is probably false for Mac and this is surely wrong for most
970 // of Unix shells (think about "[...]")
971 (void)format;
972 return m_name.find_first_of(_T("*?")) != wxString::npos;
973 }
974
975 // ----------------------------------------------------------------------------
976 // path components manipulation
977 // ----------------------------------------------------------------------------
978
979 void wxFileName::AppendDir( const wxString &dir )
980 {
981 m_dirs.Add( dir );
982 }
983
984 void wxFileName::PrependDir( const wxString &dir )
985 {
986 m_dirs.Insert( dir, 0 );
987 }
988
989 void wxFileName::InsertDir( int before, const wxString &dir )
990 {
991 m_dirs.Insert( dir, before );
992 }
993
994 void wxFileName::RemoveDir( int pos )
995 {
996 m_dirs.Remove( (size_t)pos );
997 }
998
999 // ----------------------------------------------------------------------------
1000 // accessors
1001 // ----------------------------------------------------------------------------
1002
1003 void wxFileName::SetFullName(const wxString& fullname)
1004 {
1005 SplitPath(fullname, NULL /* no path */, &m_name, &m_ext);
1006 }
1007
1008 wxString wxFileName::GetFullName() const
1009 {
1010 wxString fullname = m_name;
1011 if ( !m_ext.empty() )
1012 {
1013 fullname << wxFILE_SEP_EXT << m_ext;
1014 }
1015
1016 return fullname;
1017 }
1018
1019 wxString wxFileName::GetPath( bool add_separator, wxPathFormat format ) const
1020 {
1021 format = GetFormat( format );
1022
1023 wxString fullpath;
1024
1025 // the leading character
1026 if ( format == wxPATH_MAC && m_relative )
1027 {
1028 fullpath += wxFILE_SEP_PATH_MAC;
1029 }
1030 else if ( format == wxPATH_DOS )
1031 {
1032 if (!m_relative)
1033 fullpath += wxFILE_SEP_PATH_DOS;
1034 }
1035 else if ( format == wxPATH_UNIX )
1036 {
1037 if (!m_relative)
1038 fullpath += wxFILE_SEP_PATH_UNIX;
1039 }
1040
1041 // then concatenate all the path components using the path separator
1042 size_t dirCount = m_dirs.GetCount();
1043 if ( dirCount )
1044 {
1045 if ( format == wxPATH_VMS )
1046 {
1047 fullpath += wxT('[');
1048 }
1049
1050
1051 for ( size_t i = 0; i < dirCount; i++ )
1052 {
1053 // TODO: What to do with ".." under VMS
1054
1055 switch (format)
1056 {
1057 case wxPATH_MAC:
1058 {
1059 if (m_dirs[i] == wxT("."))
1060 break;
1061 if (m_dirs[i] != wxT("..")) // convert back from ".." to nothing
1062 fullpath += m_dirs[i];
1063 fullpath += wxT(':');
1064 break;
1065 }
1066 case wxPATH_DOS:
1067 {
1068 fullpath += m_dirs[i];
1069 fullpath += wxT('\\');
1070 break;
1071 }
1072 case wxPATH_UNIX:
1073 {
1074 fullpath += m_dirs[i];
1075 fullpath += wxT('/');
1076 break;
1077 }
1078 case wxPATH_VMS:
1079 {
1080 if (m_dirs[i] != wxT("..")) // convert back from ".." to nothing
1081 fullpath += m_dirs[i];
1082 if (i == dirCount-1)
1083 fullpath += wxT(']');
1084 else
1085 fullpath += wxT('.');
1086 break;
1087 }
1088 default:
1089 {
1090 wxFAIL_MSG( wxT("error") );
1091 }
1092 }
1093 }
1094 }
1095
1096
1097
1098 return fullpath;
1099 }
1100
1101 wxString wxFileName::GetFullPath( wxPathFormat format ) const
1102 {
1103 format = GetFormat(format);
1104
1105 wxString fullpath;
1106
1107 // first put the volume
1108 if ( !m_volume.empty() )
1109 {
1110 {
1111 // Special Windows UNC paths hack, part 2: undo what we did in
1112 // SplitPath() and make an UNC path if we have a drive which is not a
1113 // single letter (hopefully the network shares can't be one letter only
1114 // although I didn't find any authoritative docs on this)
1115 if ( format == wxPATH_DOS && m_volume.length() > 1 )
1116 {
1117 fullpath << wxFILE_SEP_PATH_DOS << wxFILE_SEP_PATH_DOS << m_volume;
1118 }
1119 else if ( format == wxPATH_DOS || format == wxPATH_VMS )
1120 {
1121 fullpath << m_volume << GetVolumeSeparator(format);
1122 }
1123 // else ignore
1124 }
1125 }
1126
1127 // the leading character
1128 if ( format == wxPATH_MAC && m_relative )
1129 {
1130 fullpath += wxFILE_SEP_PATH_MAC;
1131 }
1132 else if ( format == wxPATH_DOS )
1133 {
1134 if (!m_relative)
1135 fullpath += wxFILE_SEP_PATH_DOS;
1136 }
1137 else if ( format == wxPATH_UNIX )
1138 {
1139 if (!m_relative)
1140 fullpath += wxFILE_SEP_PATH_UNIX;
1141 }
1142
1143 // then concatenate all the path components using the path separator
1144 size_t dirCount = m_dirs.GetCount();
1145 if ( dirCount )
1146 {
1147 if ( format == wxPATH_VMS )
1148 {
1149 fullpath += wxT('[');
1150 }
1151
1152
1153 for ( size_t i = 0; i < dirCount; i++ )
1154 {
1155 // TODO: What to do with ".." under VMS
1156
1157 switch (format)
1158 {
1159 case wxPATH_MAC:
1160 {
1161 if (m_dirs[i] == wxT("."))
1162 break;
1163 if (m_dirs[i] != wxT("..")) // convert back from ".." to nothing
1164 fullpath += m_dirs[i];
1165 fullpath += wxT(':');
1166 break;
1167 }
1168 case wxPATH_DOS:
1169 {
1170 fullpath += m_dirs[i];
1171 fullpath += wxT('\\');
1172 break;
1173 }
1174 case wxPATH_UNIX:
1175 {
1176 fullpath += m_dirs[i];
1177 fullpath += wxT('/');
1178 break;
1179 }
1180 case wxPATH_VMS:
1181 {
1182 if (m_dirs[i] != wxT("..")) // convert back from ".." to nothing
1183 fullpath += m_dirs[i];
1184 if (i == dirCount-1)
1185 fullpath += wxT(']');
1186 else
1187 fullpath += wxT('.');
1188 break;
1189 }
1190 default:
1191 {
1192 wxFAIL_MSG( wxT("error") );
1193 }
1194 }
1195 }
1196 }
1197
1198 // finally add the file name and extension
1199 fullpath += GetFullName();
1200
1201 return fullpath;
1202 }
1203
1204 // Return the short form of the path (returns identity on non-Windows platforms)
1205 wxString wxFileName::GetShortPath() const
1206 {
1207 #if defined(__WXMSW__) && defined(__WIN32__) && !defined(__WXMICROWIN__)
1208 wxString path(GetFullPath());
1209 wxString pathOut;
1210 DWORD sz = ::GetShortPathName(path, NULL, 0);
1211 bool ok = sz != 0;
1212 if ( ok )
1213 {
1214 ok = ::GetShortPathName
1215 (
1216 path,
1217 pathOut.GetWriteBuf(sz),
1218 sz
1219 ) != 0;
1220 pathOut.UngetWriteBuf();
1221 }
1222 if (ok)
1223 return pathOut;
1224
1225 return path;
1226 #else
1227 return GetFullPath();
1228 #endif
1229 }
1230
1231 // Return the long form of the path (returns identity on non-Windows platforms)
1232 wxString wxFileName::GetLongPath() const
1233 {
1234 wxString pathOut,
1235 path = GetFullPath();
1236
1237 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
1238 bool success = FALSE;
1239
1240 // VZ: this code was disabled, why?
1241 #if 0 // wxUSE_DYNAMIC_LOADER
1242 typedef DWORD (*GET_LONG_PATH_NAME)(const wxChar *, wxChar *, DWORD);
1243
1244 static bool s_triedToLoad = FALSE;
1245
1246 if ( !s_triedToLoad )
1247 {
1248 s_triedToLoad = TRUE;
1249 wxDllType dllKernel = wxDllLoader::LoadLibrary(_T("kernel32"));
1250 if ( dllKernel )
1251 {
1252 // may succeed or fail depending on the Windows version
1253 static GET_LONG_PATH_NAME s_pfnGetLongPathName = NULL;
1254 #ifdef _UNICODE
1255 s_pfnGetLongPathName = (GET_LONG_PATH_NAME) wxDllLoader::GetSymbol(dllKernel, _T("GetLongPathNameW"));
1256 #else
1257 s_pfnGetLongPathName = (GET_LONG_PATH_NAME) wxDllLoader::GetSymbol(dllKernel, _T("GetLongPathNameA"));
1258 #endif
1259
1260 wxDllLoader::UnloadLibrary(dllKernel);
1261
1262 if ( s_pfnGetLongPathName )
1263 {
1264 DWORD dwSize = (*s_pfnGetLongPathName)(path, NULL, 0);
1265 bool ok = dwSize > 0;
1266
1267 if ( ok )
1268 {
1269 DWORD sz = (*s_pfnGetLongPathName)(path, NULL, 0);
1270 ok = sz != 0;
1271 if ( ok )
1272 {
1273 ok = (*s_pfnGetLongPathName)
1274 (
1275 path,
1276 pathOut.GetWriteBuf(sz),
1277 sz
1278 ) != 0;
1279 pathOut.UngetWriteBuf();
1280
1281 success = TRUE;
1282 }
1283 }
1284 }
1285 }
1286 }
1287 if (success)
1288 return pathOut;
1289 #endif // wxUSE_DYNAMIC_LOADER
1290
1291 if (!success)
1292 {
1293 // The OS didn't support GetLongPathName, or some other error.
1294 // We need to call FindFirstFile on each component in turn.
1295
1296 WIN32_FIND_DATA findFileData;
1297 HANDLE hFind;
1298 pathOut = wxEmptyString;
1299
1300 wxArrayString dirs = GetDirs();
1301 dirs.Add(GetFullName());
1302
1303 wxString tmpPath;
1304
1305 size_t count = dirs.GetCount();
1306 for ( size_t i = 0; i < count; i++ )
1307 {
1308 // We're using pathOut to collect the long-name path, but using a
1309 // temporary for appending the last path component which may be
1310 // short-name
1311 tmpPath = pathOut + dirs[i];
1312
1313 if ( tmpPath.empty() )
1314 continue;
1315
1316 if ( tmpPath.Last() == wxT(':') )
1317 {
1318 // Can't pass a drive and root dir to FindFirstFile,
1319 // so continue to next dir
1320 tmpPath += wxFILE_SEP_PATH;
1321 pathOut = tmpPath;
1322 continue;
1323 }
1324
1325 hFind = ::FindFirstFile(tmpPath, &findFileData);
1326 if (hFind == INVALID_HANDLE_VALUE)
1327 {
1328 // Error: return immediately with the original path
1329 return path;
1330 }
1331
1332 pathOut += findFileData.cFileName;
1333 if ( (i < (count-1)) )
1334 pathOut += wxFILE_SEP_PATH;
1335
1336 ::FindClose(hFind);
1337 }
1338 }
1339 #else // !Win32
1340 pathOut = path;
1341 #endif // Win32/!Win32
1342
1343 return pathOut;
1344 }
1345
1346 wxPathFormat wxFileName::GetFormat( wxPathFormat format )
1347 {
1348 if (format == wxPATH_NATIVE)
1349 {
1350 #if defined(__WXMSW__) || defined(__WXPM__) || defined(__DOS__)
1351 format = wxPATH_DOS;
1352 #elif defined(__WXMAC__) && !defined(__DARWIN__)
1353 format = wxPATH_MAC;
1354 #elif defined(__VMS)
1355 format = wxPATH_VMS;
1356 #else
1357 format = wxPATH_UNIX;
1358 #endif
1359 }
1360 return format;
1361 }
1362
1363 // ----------------------------------------------------------------------------
1364 // path splitting function
1365 // ----------------------------------------------------------------------------
1366
1367 /* static */
1368 void wxFileName::SplitPath(const wxString& fullpathWithVolume,
1369 wxString *pstrVolume,
1370 wxString *pstrPath,
1371 wxString *pstrName,
1372 wxString *pstrExt,
1373 wxPathFormat format)
1374 {
1375 format = GetFormat(format);
1376
1377 wxString fullpath = fullpathWithVolume;
1378
1379 // under VMS the end of the path is ']', not the path separator used to
1380 // separate the components
1381 wxString sepPath = format == wxPATH_VMS ? wxString(_T(']'))
1382 : GetPathSeparators(format);
1383
1384 // special Windows UNC paths hack: transform \\share\path into share:path
1385 if ( format == wxPATH_DOS )
1386 {
1387 if ( fullpath.length() >= 4 &&
1388 fullpath[0u] == wxFILE_SEP_PATH_DOS &&
1389 fullpath[1u] == wxFILE_SEP_PATH_DOS )
1390 {
1391 fullpath.erase(0, 2);
1392
1393 size_t posFirstSlash = fullpath.find_first_of(sepPath);
1394 if ( posFirstSlash != wxString::npos )
1395 {
1396 fullpath[posFirstSlash] = wxFILE_SEP_DSK;
1397
1398 // UNC paths are always absolute, right? (FIXME)
1399 fullpath.insert(posFirstSlash + 1, wxFILE_SEP_PATH_DOS);
1400 }
1401 }
1402 }
1403
1404 // We separate the volume here
1405 if ( format == wxPATH_DOS || format == wxPATH_VMS )
1406 {
1407 wxString sepVol = GetVolumeSeparator(format);
1408
1409 size_t posFirstColon = fullpath.find_first_of(sepVol);
1410 if ( posFirstColon != wxString::npos )
1411 {
1412 if ( pstrVolume )
1413 {
1414 *pstrVolume = fullpath.Left(posFirstColon);
1415 }
1416
1417 // remove the volume name and the separator from the full path
1418 fullpath.erase(0, posFirstColon + sepVol.length());
1419 }
1420 }
1421
1422 // find the positions of the last dot and last path separator in the path
1423 size_t posLastDot = fullpath.find_last_of(wxFILE_SEP_EXT);
1424 size_t posLastSlash = fullpath.find_last_of(sepPath);
1425
1426 if ( (posLastDot != wxString::npos) &&
1427 ((format == wxPATH_UNIX) || (format == wxPATH_VMS)) )
1428 {
1429 if ( (posLastDot == 0) ||
1430 (fullpath[posLastDot - 1] == sepPath[0u] ) )
1431 {
1432 // under Unix and VMS, dot may be (and commonly is) the first
1433 // character of the filename, don't treat the entire filename as
1434 // extension in this case
1435 posLastDot = wxString::npos;
1436 }
1437 }
1438
1439 // if we do have a dot and a slash, check that the dot is in the name part
1440 if ( (posLastDot != wxString::npos) &&
1441 (posLastSlash != wxString::npos) &&
1442 (posLastDot < posLastSlash) )
1443 {
1444 // the dot is part of the path, not the start of the extension
1445 posLastDot = wxString::npos;
1446 }
1447
1448 // now fill in the variables provided by user
1449 if ( pstrPath )
1450 {
1451 if ( posLastSlash == wxString::npos )
1452 {
1453 // no path at all
1454 pstrPath->Empty();
1455 }
1456 else
1457 {
1458 // take everything up to the path separator but take care to make
1459 // the path equal to something like '/', not empty, for the files
1460 // immediately under root directory
1461 size_t len = posLastSlash;
1462 if ( !len )
1463 len++;
1464
1465 *pstrPath = fullpath.Left(len);
1466
1467 // special VMS hack: remove the initial bracket
1468 if ( format == wxPATH_VMS )
1469 {
1470 if ( (*pstrPath)[0u] == _T('[') )
1471 pstrPath->erase(0, 1);
1472 }
1473 }
1474 }
1475
1476 if ( pstrName )
1477 {
1478 // take all characters starting from the one after the last slash and
1479 // up to, but excluding, the last dot
1480 size_t nStart = posLastSlash == wxString::npos ? 0 : posLastSlash + 1;
1481 size_t count;
1482 if ( posLastDot == wxString::npos )
1483 {
1484 // take all until the end
1485 count = wxString::npos;
1486 }
1487 else if ( posLastSlash == wxString::npos )
1488 {
1489 count = posLastDot;
1490 }
1491 else // have both dot and slash
1492 {
1493 count = posLastDot - posLastSlash - 1;
1494 }
1495
1496 *pstrName = fullpath.Mid(nStart, count);
1497 }
1498
1499 if ( pstrExt )
1500 {
1501 if ( posLastDot == wxString::npos )
1502 {
1503 // no extension
1504 pstrExt->Empty();
1505 }
1506 else
1507 {
1508 // take everything after the dot
1509 *pstrExt = fullpath.Mid(posLastDot + 1);
1510 }
1511 }
1512 }
1513
1514 /* static */
1515 void wxFileName::SplitPath(const wxString& fullpath,
1516 wxString *path,
1517 wxString *name,
1518 wxString *ext,
1519 wxPathFormat format)
1520 {
1521 wxString volume;
1522 SplitPath(fullpath, &volume, path, name, ext, format);
1523
1524 if ( path && !volume.empty() )
1525 {
1526 path->Prepend(volume + GetVolumeSeparator(format));
1527 }
1528 }
1529
1530 // ----------------------------------------------------------------------------
1531 // time functions
1532 // ----------------------------------------------------------------------------
1533
1534 bool wxFileName::SetTimes(const wxDateTime *dtCreate,
1535 const wxDateTime *dtAccess,
1536 const wxDateTime *dtMod)
1537 {
1538 #if defined(__UNIX_LIKE__) || (defined(__DOS__) && defined(__WATCOMC__))
1539 if ( !dtAccess && !dtMod )
1540 {
1541 // can't modify the creation time anyhow, don't try
1542 return TRUE;
1543 }
1544
1545 // if dtAccess or dtMod is not specified, use the other one (which must be
1546 // non NULL because of the test above) for both times
1547 utimbuf utm;
1548 utm.actime = dtAccess ? dtAccess->GetTicks() : dtMod->GetTicks();
1549 utm.modtime = dtMod ? dtMod->GetTicks() : dtAccess->GetTicks();
1550 if ( utime(GetFullPath(), &utm) == 0 )
1551 {
1552 return TRUE;
1553 }
1554 #elif defined(__WIN32__)
1555 wxFileHandle fh(GetFullPath());
1556 if ( fh.IsOk() )
1557 {
1558 FILETIME ftAccess, ftCreate, ftWrite;
1559
1560 if ( dtCreate )
1561 ConvertWxToFileTime(&ftCreate, *dtCreate);
1562 if ( dtAccess )
1563 ConvertWxToFileTime(&ftAccess, *dtAccess);
1564 if ( dtMod )
1565 ConvertWxToFileTime(&ftWrite, *dtMod);
1566
1567 if ( ::SetFileTime(fh,
1568 dtCreate ? &ftCreate : NULL,
1569 dtAccess ? &ftAccess : NULL,
1570 dtMod ? &ftWrite : NULL) )
1571 {
1572 return TRUE;
1573 }
1574 }
1575 #else // other platform
1576 #endif // platforms
1577
1578 wxLogSysError(_("Failed to modify file times for '%s'"),
1579 GetFullPath().c_str());
1580
1581 return FALSE;
1582 }
1583
1584 bool wxFileName::Touch()
1585 {
1586 #if defined(__UNIX_LIKE__)
1587 // under Unix touching file is simple: just pass NULL to utime()
1588 if ( utime(GetFullPath(), NULL) == 0 )
1589 {
1590 return TRUE;
1591 }
1592
1593 wxLogSysError(_("Failed to touch the file '%s'"), GetFullPath().c_str());
1594
1595 return FALSE;
1596 #else // other platform
1597 wxDateTime dtNow = wxDateTime::Now();
1598
1599 return SetTimes(NULL /* don't change create time */, &dtNow, &dtNow);
1600 #endif // platforms
1601 }
1602
1603 bool wxFileName::GetTimes(wxDateTime *dtAccess,
1604 wxDateTime *dtMod,
1605 wxDateTime *dtChange) const
1606 {
1607 #if defined(__UNIX_LIKE__) || defined(__WXMAC__) || (defined(__DOS__) && defined(__WATCOMC__))
1608 wxStructStat stBuf;
1609 if ( wxStat(GetFullPath(), &stBuf) == 0 )
1610 {
1611 if ( dtAccess )
1612 dtAccess->Set(stBuf.st_atime);
1613 if ( dtMod )
1614 dtMod->Set(stBuf.st_mtime);
1615 if ( dtChange )
1616 dtChange->Set(stBuf.st_ctime);
1617
1618 return TRUE;
1619 }
1620 #elif defined(__WIN32__)
1621 wxFileHandle fh(GetFullPath());
1622 if ( fh.IsOk() )
1623 {
1624 FILETIME ftAccess, ftCreate, ftWrite;
1625
1626 if ( ::GetFileTime(fh,
1627 dtMod ? &ftCreate : NULL,
1628 dtAccess ? &ftAccess : NULL,
1629 dtChange ? &ftWrite : NULL) )
1630 {
1631 if ( dtMod )
1632 ConvertFileTimeToWx(dtMod, ftCreate);
1633 if ( dtAccess )
1634 ConvertFileTimeToWx(dtAccess, ftAccess);
1635 if ( dtChange )
1636 ConvertFileTimeToWx(dtChange, ftWrite);
1637
1638 return TRUE;
1639 }
1640 }
1641 #else // other platform
1642 #endif // platforms
1643
1644 wxLogSysError(_("Failed to retrieve file times for '%s'"),
1645 GetFullPath().c_str());
1646
1647 return FALSE;
1648 }
1649