Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

osdep.cpp

Go to the documentation of this file.
00001 /* 00002 * wxChecksums 00003 * Copyright (C) 2003-2004 Julien Couot 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation; either version 2 00008 * of the License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 */ 00019 00020 /** 00021 * \file osdep.cpp 00022 * OS dependant utility functions. 00023 */ 00024 00025 //--------------------------------------------------------------------------- 00026 // For compilers that support precompilation, includes "wx.h". 00027 #include <wx/wxprec.h> 00028 00029 #ifdef __BORLANDC__ 00030 #pragma hdrstop 00031 #endif 00032 00033 #ifndef WX_PRECOMP 00034 // Include your minimal set of headers here, or wx.h 00035 #include <wx/wx.h> 00036 #endif 00037 00038 // Include the Windows API header at the end prevents some problems that can 00039 // occur at the linking procedure. 00040 #if defined(__WXMSW__) 00041 #include <windows.h> 00042 #include <winbase.h> 00043 #include <winnls.h> 00044 #include <winuser.h> 00045 #include <wx/msw/private.h> 00046 #endif // __WXMSW__ 00047 00048 #include <wx/utils.h> 00049 00050 #include <sys/types.h> 00051 #include <sys/stat.h> 00052 00053 #include "osdep.hpp" 00054 #include "comdefs.hpp" 00055 00056 #include "compat.hpp" 00057 //--------------------------------------------------------------------------- 00058 00059 00060 #if defined(wxC_USE_LARGE_FILES) 00061 // Definitions for the getFileLength64 method 00062 #if defined(__WXMSW__) 00063 #include <tchar.h> 00064 #if defined(__BORLANDC__) 00065 #define wxCStat64Struct stati64 00066 #define wxCStat64Fnct _tstati64 00067 #elif defined(__GNUWIN32__) 00068 #if defined(_UNICODE) 00069 #define _tstati64 _wstati64 00070 #else 00071 #define _tstati64 _stati64 00072 #endif // defined(_UNICODE) 00073 #define wxCStat64Struct struct _stati64 00074 #define wxCStat64Fnct _tstati64 00075 #else // other compilers 00076 #define wxCStat64Struct __stat64 00077 #define wxCStat64Fnct _tstat64 00078 #endif // defined(__BORLANDC__) 00079 #else // other environments 00080 #define wxCStat64Struct struct stat64 00081 #define wxCStat64Fnct stat64 00082 #endif // defined(__WXMSW__) 00083 #endif // defined(wxC_USE_LARGE_FILES) 00084 //--------------------------------------------------------------------------- 00085 00086 00087 /// The C++ standard namespace. 00088 using namespace std; 00089 00090 00091 /** 00092 * Gets the length of the specified file. 00093 * 00094 * Should not work with large files. 00095 * 00096 * @param fileName The name of the file of which we want to get the length. 00097 * @return The length of the specified file or <CODE>wxInvalidOffset</CODE> if 00098 * an error has occured. 00099 */ 00100 off_t getFileLength(const wxChar* fileName) 00101 { 00102 struct stat s; 00103 00104 if (stat(wxFNCONV(fileName), &s) == -1) 00105 return wxInvalidOffset; 00106 else 00107 return s.st_size; 00108 } 00109 //--------------------------------------------------------------------------- 00110 00111 00112 #if defined(wxC_USE_LARGE_FILES) 00113 /** 00114 * Gets the length of the specified file. 00115 * 00116 * The return value is a 64 bit signed integer. 00117 * 00118 * @param fileName The name of the file of which we want to get the length. 00119 * @return The length of the specified file or <CODE>wxInvalidOffset</CODE> if 00120 * an error has occured. 00121 */ 00122 wxLongLong_t getFileLength64(const wxChar* fileName) 00123 { 00124 wxCStat64Struct s; 00125 int res; 00126 00127 #if defined(__WXMSW__) // Windows 00128 res = wxCStat64Fnct(fileName, &s); 00129 #else // others OS 00130 res = wxCStat64Fnct(wxFNCONV(fileName), &s); 00131 #endif // defined(__WXMSW__) 00132 00133 if (res == -1) 00134 return static_cast<wxLongLong_t>(wxInvalidOffset); 00135 else 00136 return s.st_size; 00137 } 00138 //--------------------------------------------------------------------------- 00139 #endif // defined(wxC_USE_LARGE_FILES) 00140 00141 00142 00143 /** 00144 * Gets the absolute paths where the resources of the program can be placed. 00145 * 00146 * @return The absolute paths where the resources of the program can be placed. 00147 */ 00148 wxArrayString getResourcesPaths() 00149 { 00150 wxArrayString paths; 00151 00152 // OS dependant paths 00153 #ifdef __UNIX__ 00154 // Add some standard ones 00155 paths.Add(wxString(wxT("/usr/share/")) + wxT(APP_NAME)); 00156 paths.Add(wxString(wxT("/usr/lib/")) + wxT(APP_NAME)); 00157 paths.Add(wxString(wxT("/usr/local/share/")) + wxT(APP_NAME)); 00158 paths.Add(wxString(wxT("/usr/local/lib/")) + wxT(APP_NAME)); 00159 #endif // __UNIX__ 00160 00161 #ifdef __WXMSW__ 00162 // Path of the executable 00163 paths.Add(::getAppPath().GetPath(wxPATH_GET_VOLUME)); 00164 #endif //__WXMSW__ 00165 00166 // Try current directory 00167 paths.Add(::wxGetCwd()); 00168 00169 return paths; 00170 } 00171 //--------------------------------------------------------------------------- 00172 00173 00174 #if defined(__WXMSW__) 00175 /** 00176 * Get the application (or dll) path. 00177 * 00178 * @param hMod Handle to the module whose path is being requested. 00179 * @return The application (or dll) path. 00180 */ 00181 static wxFileName getAppPath(HMODULE hMod) 00182 { 00183 const int strSize = MAX_PATH; 00184 wxString str; 00185 DWORD dw = ::GetModuleFileName(hMod, wxStringBuffer(str, strSize), strSize); 00186 00187 if (!dw) 00188 // When does it happen?? 00189 { 00190 wxFAIL; 00191 return wxFileName(); 00192 } 00193 00194 return wxFileName(str); 00195 } 00196 //--------------------------------------------------------------------------- 00197 00198 00199 /** 00200 * Gets the full file name (with path) of the application executable. 00201 * 00202 * @return The full file name (with path) of the application executable. 00203 */ 00204 wxFileName getAppPath() 00205 { 00206 return getAppPath(::GetModuleHandle(NULL)); 00207 } 00208 //--------------------------------------------------------------------------- 00209 00210 00211 /** 00212 * Gets the full file name (with path) of the current process. 00213 * 00214 * @return The full file name (with path) of the current process. 00215 */ 00216 wxFileName getModulePath() 00217 { 00218 return getAppPath(::wxGetInstance()); 00219 } 00220 //--------------------------------------------------------------------------- 00221 #endif // __WXMSW__ 00222 00223 00224 00225 /** 00226 * Converts an UTF-8 string to the local encoded string. 00227 * 00228 * @param utf8 String encoded in UTF-8. 00229 * @return The string encoded in local encoding. 00230 */ 00231 wxString UTF8toLocal(const wxString utf8) 00232 { 00233 wxCSConv conv(wxLocale::GetSystemEncodingName()); 00234 return wxString(utf8.wc_str(wxConvUTF8), conv); 00235 } 00236 //---------------------------------------------------------------------------

Generated on Sun May 30 13:37:45 2004 for wxChecksums by doxygen 1.3.7