diff options
author | Graeme Geldenhuys <graemeg@gmail.com> | 2010-08-22 13:48:20 +0200 |
---|---|---|
committer | Graeme Geldenhuys <graemeg@gmail.com> | 2010-08-22 13:48:20 +0200 |
commit | 95a19394a4a584eb6e71d4047a07b16f16416d37 (patch) | |
tree | 16c2bb42fa9b51ffcc17d03678f996b0efa94bac /src | |
parent | d9a8635bbb6271e934795ee2125f60a061c4ea62 (diff) | |
download | fpGUI-95a19394a4a584eb6e71d4047a07b16f16416d37.tar.xz |
Introduced a new cross-platform fpgFileSize() helper function.
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/fpg_utils.pas | 1 | ||||
-rw-r--r-- | src/corelib/gdi/fpg_utils_impl.inc | 21 | ||||
-rw-r--r-- | src/corelib/x11/fpg_utils_impl.inc | 10 |
3 files changed, 30 insertions, 2 deletions
diff --git a/src/corelib/fpg_utils.pas b/src/corelib/fpg_utils.pas index d4d7886c..43f73028 100644 --- a/src/corelib/fpg_utils.pas +++ b/src/corelib/fpg_utils.pas @@ -31,6 +31,7 @@ uses function fpgToOSEncoding(aString: TfpgString): string; function fpgFromOSEncoding(aString: string): TfpgString; procedure fpgOpenURL(const aURL: TfpgString); +function fpgFileSize(const AFilename: TfpgString): integer; // *** Common functions for all platforms *** diff --git a/src/corelib/gdi/fpg_utils_impl.inc b/src/corelib/gdi/fpg_utils_impl.inc index d3bb2f0c..08a3c3ad 100644 --- a/src/corelib/gdi/fpg_utils_impl.inc +++ b/src/corelib/gdi/fpg_utils_impl.inc @@ -1,7 +1,7 @@ {%mainunit fpg_utils.pas} uses - Shellapi; + Shellapi, Windows; // GDI specific implementations of encoding functions @@ -26,3 +26,22 @@ begin end; end; +function fpgFileSize(const AFilename: TfpgString): integer; +var + FindData: TWIN32FindDataW; + FindHandle: THandle; + Str: widestring; +begin + // Don't assign the widestring to TSearchRec.name because it is of type + // string, which will generate a conversion to the system encoding + Str := UTF8Decode(Filename); + FindHandle:=Windows.FindFirstFileW(PWideChar(Str), FindData); + if FindHandle=Windows.Invalid_Handle_value then + begin + Result:=-1; + exit; + end; + Result := (int64(FindData.nFileSizeHigh) shl 32)+FindData.nFileSizeLow; + Windows.FindClose(FindHandle); +end; + diff --git a/src/corelib/x11/fpg_utils_impl.inc b/src/corelib/x11/fpg_utils_impl.inc index d8625b8c..908f411a 100644 --- a/src/corelib/x11/fpg_utils_impl.inc +++ b/src/corelib/x11/fpg_utils_impl.inc @@ -1,7 +1,7 @@ {%mainunit fpg_utils.pas} uses - Unix; + Unix, BaseUnix; // X11 specific filesystem implementations of encoding functions @@ -40,3 +40,11 @@ begin fpSystem(Helper + ' ' + aURL + '&'); end; +function fpgFileSize(const AFilename: TfpgString): integer; +var + st: baseunix.stat; +begin + if not fpstat(pointer(AFilename),st) >= 0 then + exit(-1); + Result := st.st_size; +end; |