// For GetShort/LongPathName
#ifdef __WIN32__
#include "wx/msw/wrapwin.h"
+#if defined(__MINGW32__)
+#include "wx/msw/gccpriv.h"
+#endif
#endif
#ifdef __WXWINCE__
{
SYSTEMTIME st;
st.wDay = dt.GetDay();
- st.wMonth = dt.GetMonth() + 1;
- st.wYear = dt.GetYear();
+ st.wMonth = (WORD)(dt.GetMonth() + 1);
+ st.wYear = (WORD)dt.GetYear();
st.wHour = dt.GetHour();
st.wMinute = dt.GetMinute();
st.wSecond = dt.GetSecond();
m_name = filepath.GetName();
m_ext = filepath.GetExt();
m_relative = filepath.m_relative;
+ m_hasExt = filepath.m_hasExt;
}
void wxFileName::Assign(const wxString& volume,
const wxString& path,
const wxString& name,
const wxString& ext,
+ bool hasExt,
wxPathFormat format )
{
SetPath( path, format );
m_volume = volume;
m_ext = ext;
m_name = name;
+
+ m_hasExt = hasExt;
}
void wxFileName::SetPath( const wxString& pathOrig, wxPathFormat format )
wxPathFormat format)
{
wxString volume, path, name, ext;
- SplitPath(fullpath, &volume, &path, &name, &ext, format);
+ bool hasExt;
+ SplitPath(fullpath, &volume, &path, &name, &ext, &hasExt, format);
- Assign(volume, path, name, ext, format);
+ Assign(volume, path, name, ext, hasExt, format);
}
void wxFileName::Assign(const wxString& fullpathOrig,
}
wxString volume, path, name, ext;
+ bool hasExt;
// do some consistency checks in debug mode: the name should be really just
// the filename and the path should be really just a path
#ifdef __WXDEBUG__
- wxString pathDummy, nameDummy, extDummy;
+ wxString volDummy, pathDummy, nameDummy, extDummy;
- SplitPath(fullname, &pathDummy, &name, &ext, format);
+ SplitPath(fullname, &volDummy, &pathDummy, &name, &ext, &hasExt, format);
- wxASSERT_MSG( pathDummy.empty(),
+ wxASSERT_MSG( volDummy.empty() && pathDummy.empty(),
_T("the file name shouldn't contain the path") );
SplitPath(fullpath, &volume, &path, &nameDummy, &extDummy, format);
_T("the path shouldn't contain file name nor extension") );
#else // !__WXDEBUG__
- SplitPath(fullname, NULL /* no path */, &name, &ext, format);
+ SplitPath(fullname, NULL /* no volume */, NULL /* no path */,
+ &name, &ext, &hasExt, format);
SplitPath(fullpath, &volume, &path, NULL, NULL, format);
#endif // __WXDEBUG__/!__WXDEBUG__
+ Assign(volume, path, name, ext, hasExt, format);
+}
+
+void wxFileName::Assign(const wxString& pathOrig,
+ const wxString& name,
+ const wxString& ext,
+ wxPathFormat format)
+{
+ wxString volume,
+ path;
+ SplitVolume(pathOrig, &volume, &path, format);
+
Assign(volume, path, name, ext, format);
}
void wxFileName::AssignDir(const wxString& dir, wxPathFormat format)
{
- Assign(dir, _T(""), format);
+ Assign(dir, wxEmptyString, format);
}
void wxFileName::Clear()
// we don't have any absolute path for now
m_relative = true;
+
+ // nor any extension
+ m_hasExt = false;
}
/* static */
bool wxFileName::DirExists( const wxString &dir )
{
- return ::wxDirExists( dir );
+ return ::wxPathExists( dir );
}
// ----------------------------------------------------------------------------
return ::wxGetHomeDir();
}
+#if wxUSE_FILE
+
void wxFileName::AssignTempFileName(const wxString& prefix, wxFile *fileTemp)
{
wxString tempname = CreateTempFileName(prefix, fileTemp);
}
path = dir + wxT("\\") + prefix;
int i = 1;
- while (wxFileExists(path))
+ while (FileExists(path))
{
path = dir + wxT("\\") + prefix ;
path << i;
else // mkstemp() succeeded
{
path = wxConvFile.cMB2WX( (const char*) buf );
-
+
// avoid leaking the fd
if ( fileTemp )
{
}
#else // !HAVE_MKTEMP (includes __DOS__)
// generate the unique file name ourselves
- #if !defined(__DOS__) && (!defined(__MWERKS__) || defined(__DARWIN__) )
+ #if !defined(__DOS__) && !defined(__PALMOS__) && (!defined(__MWERKS__) || defined(__DARWIN__) )
path << (unsigned int)getpid();
#endif
{
// 3 hex digits is enough for numTries == 1000 < 4096
pathTry = path + wxString::Format(_T("%.03x"), (unsigned int) n);
- if ( !wxFile::Exists(pathTry) )
+ if ( !FileExists(pathTry) )
{
break;
}
return path;
}
+#endif // wxUSE_FILE
+
// ----------------------------------------------------------------------------
// directory operations
// ----------------------------------------------------------------------------
size_t count = dirs.GetCount();
for ( size_t i = 0; i < count; i++ )
{
- if ( i > 0 ||
+ if ( i > 0 ||
#if defined(__WXMAC__) && !defined(__DARWIN__)
- // relative pathnames are exactely the other way round under mac...
- !filename.IsAbsolute()
+ // relative pathnames are exactely the other way round under mac...
+ !filename.IsAbsolute()
#else
- filename.IsAbsolute()
+ filename.IsAbsolute()
#endif
)
currPath += wxFILE_SEP_PATH;
m_dirs.Add(dir);
}
-
+
#if defined(__WIN32__) && !defined(__WXWINCE__) && wxUSE_OLE
if ( (flags & wxPATH_NORM_SHORTCUT) )
{
{
wxString path, file, ext;
wxSplitPath(shortcutPath, & path, & file, & ext);
-
- HRESULT hres;
- IShellLink* psl;
- bool success = FALSE;
+
+ HRESULT hres;
+ IShellLink* psl;
+ bool success = false;
// Assume it's not a shortcut if it doesn't end with lnk
- if (ext.Lower() != wxT("lnk"))
- return FALSE;
-
- // create a ShellLink object
- hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
- IID_IShellLink, (LPVOID*) &psl);
-
- if (SUCCEEDED(hres))
- {
- IPersistFile* ppf;
- hres = psl->QueryInterface( IID_IPersistFile, (LPVOID *) &ppf);
- if (SUCCEEDED(hres))
- {
- WCHAR wsz[MAX_PATH];
-
- MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, shortcutPath.mb_str(), -1, wsz,
- MAX_PATH);
-
- hres = ppf->Load(wsz, 0);
- if (SUCCEEDED(hres))
- {
+ if (ext.CmpNoCase(wxT("lnk"))!=0)
+ return false;
+
+ // create a ShellLink object
+ hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
+ IID_IShellLink, (LPVOID*) &psl);
+
+ if (SUCCEEDED(hres))
+ {
+ IPersistFile* ppf;
+ hres = psl->QueryInterface( IID_IPersistFile, (LPVOID *) &ppf);
+ if (SUCCEEDED(hres))
+ {
+ WCHAR wsz[MAX_PATH];
+
+ MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, shortcutPath.mb_str(), -1, wsz,
+ MAX_PATH);
+
+ hres = ppf->Load(wsz, 0);
+ if (SUCCEEDED(hres))
+ {
wxChar buf[2048];
- psl->GetPath(buf, 2048, NULL, SLGP_UNCPRIORITY);
- targetFilename = wxString(buf);
+ // Wrong prototype in early versions
+#if defined(__MINGW32__) && !wxCHECK_W32API_VERSION(2, 2)
+ psl->GetPath((CHAR*) buf, 2048, NULL, SLGP_UNCPRIORITY);
+#else
+ psl->GetPath(buf, 2048, NULL, SLGP_UNCPRIORITY);
+#endif
+ targetFilename = wxString(buf);
success = (shortcutPath != targetFilename);
- psl->GetArguments(buf, 2048);
+ psl->GetArguments(buf, 2048);
wxString args(buf);
- if (!args.IsEmpty() && arguments)
+ if (!args.empty() && arguments)
{
*arguments = args;
- }
- }
- }
- }
- psl->Release();
- return success;
+ }
+ }
+ }
+ }
+ psl->Release();
+ return success;
}
#endif
bool wxFileName::IsPathSeparator(wxChar ch, wxPathFormat format)
{
// wxString::Find() doesn't work as expected with NUL - it will always find
- // it, so it is almost surely a bug if this function is called with NUL arg
- wxASSERT_MSG( ch != _T('\0'), _T("shouldn't be called with NUL") );
-
- return GetPathSeparators(format).Find(ch) != wxNOT_FOUND;
+ // it, so test for it separately
+ return ch != _T('\0') && GetPathSeparators(format).Find(ch) != wxNOT_FOUND;
}
// ----------------------------------------------------------------------------
return true;
}
-void wxFileName::AppendDir( const wxString &dir )
+void wxFileName::AppendDir( const wxString& dir )
{
if ( IsValidDirComponent(dir) )
m_dirs.Add( dir );
}
-void wxFileName::PrependDir( const wxString &dir )
+void wxFileName::PrependDir( const wxString& dir )
{
InsertDir(0, dir);
}
-void wxFileName::InsertDir( int before, const wxString &dir )
+void wxFileName::InsertDir(size_t before, const wxString& dir)
{
if ( IsValidDirComponent(dir) )
- m_dirs.Insert( dir, before );
+ m_dirs.Insert(dir, before);
}
-void wxFileName::RemoveDir( int pos )
+void wxFileName::RemoveDir(size_t pos)
{
- m_dirs.RemoveAt( (size_t)pos );
+ m_dirs.RemoveAt(pos);
}
// ----------------------------------------------------------------------------
void wxFileName::SetFullName(const wxString& fullname)
{
- SplitPath(fullname, NULL /* no path */, &m_name, &m_ext);
+ SplitPath(fullname, NULL /* no volume */, NULL /* no path */,
+ &m_name, &m_ext, &m_hasExt);
}
wxString wxFileName::GetFullName() const
{
wxString fullname = m_name;
- if ( !m_ext.empty() )
+ if ( m_hasExt )
{
fullname << wxFILE_SEP_EXT << m_ext;
}
}
// convert back from ".." to nothing
- if ( m_dirs[i] != wxT("..") )
+ if ( !m_dirs[i].IsSameAs(wxT("..")) )
fullpath += m_dirs[i];
break;
// TODO: What to do with ".." under VMS
// convert back from ".." to nothing
- if ( m_dirs[i] != wxT("..") )
+ if ( !m_dirs[i].IsSameAs(wxT("..")) )
fullpath += m_dirs[i];
break;
}
wxString *pstrPath,
wxString *pstrName,
wxString *pstrExt,
+ bool *hasExt,
wxPathFormat format)
{
format = GetFormat(format);
*pstrName = fullpath.Mid(nStart, count);
}
- if ( pstrExt )
+ // finally deal with the extension here: we have an added complication that
+ // extension may be empty (but present) as in "foo." where trailing dot
+ // indicates the empty extension at the end -- and hence we must remember
+ // that we have it independently of pstrExt
+ if ( posLastDot == wxString::npos )
{
- if ( posLastDot == wxString::npos )
- {
- // no extension
- pstrExt->Empty();
- }
- else
- {
- // take everything after the dot
+ // no extension
+ if ( pstrExt )
+ pstrExt->clear();
+ if ( hasExt )
+ *hasExt = false;
+ }
+ else
+ {
+ // take everything after the dot
+ if ( pstrExt )
*pstrExt = fullpath.Mid(posLastDot + 1);
- }
+ if ( hasExt )
+ *hasExt = true;
}
}
MacDefaultExtensionRecord()
{
m_ext[0] = 0 ;
- m_type = m_creator = NULL ;
+ m_type = m_creator = 0 ;
}
MacDefaultExtensionRecord( const MacDefaultExtensionRecord& from )
{
if ( wxMacPathToFSRef( GetFullPath() , &fsRef ) == noErr )
{
- if ( FSGetCatalogInfo (&fsRef, kFSCatInfoFinderInfo, &catInfo, NULL, NULL, NULL) == noErr )
- {
- finfo = (FileInfo*)&catInfo.finderInfo;
- finfo->fileType = type ;
- finfo->fileCreator = creator ;
- FSSetCatalogInfo( &fsRef, kFSCatInfoFinderInfo, &catInfo ) ;
+ if ( FSGetCatalogInfo (&fsRef, kFSCatInfoFinderInfo, &catInfo, NULL, NULL, NULL) == noErr )
+ {
+ finfo = (FileInfo*)&catInfo.finderInfo;
+ finfo->fileType = type ;
+ finfo->fileCreator = creator ;
+ FSSetCatalogInfo( &fsRef, kFSCatInfoFinderInfo, &catInfo ) ;
return true ;
- }
+ }
}
return false ;
}
if ( wxMacPathToFSRef( GetFullPath() , &fsRef ) == noErr )
{
- if ( FSGetCatalogInfo (&fsRef, kFSCatInfoFinderInfo, &catInfo, NULL, NULL, NULL) == noErr )
- {
- finfo = (FileInfo*)&catInfo.finderInfo;
- *type = finfo->fileType ;
- *creator = finfo->fileCreator ;
+ if ( FSGetCatalogInfo (&fsRef, kFSCatInfoFinderInfo, &catInfo, NULL, NULL, NULL) == noErr )
+ {
+ finfo = (FileInfo*)&catInfo.finderInfo;
+ *type = finfo->fileType ;
+ *creator = finfo->fileCreator ;
return true ;
- }
+ }
}
return false ;
}