4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "UtilsSystem.hpp"
25 #include "CommandLine.hpp"
26 #include "LocalPath.hpp"
27 #include "LogFile.hpp"
28 #include "OS/FileUtil.hpp"
29 #include "OS/MemInfo.hpp"
30 #include "Screen/Point.hpp"
33 #include "Android/NativeView.hpp"
34 #include "Android/Main.hpp"
41 #include <sys/statvfs.h>
55 // This is necessary to be called periodically to get rid of
56 // memory defragmentation, since on pocket pc platforms there is no
57 // automatic defragmentation.
58 void MyCompactHeaps() {
59 #if defined(GNAV) && !defined(__GNUC__)
60 HeapCompact(GetProcessHeap(), 0);
62 typedef DWORD (_stdcall
*CompactAllHeapsFn
) (void);
63 static CompactAllHeapsFn CompactAllHeaps
= NULL
;
64 static bool init
= false;
66 // get the pointer to the function
67 CompactAllHeaps
= (CompactAllHeapsFn
)GetProcAddress(
68 LoadLibrary(_T("coredll.dll")), _T("CompactAllHeaps"));
75 #endif /* _WIN32_WCE */
78 * Calculates the free disk space for the given path
79 * @param path The path defining the "drive" to look on
80 * @return Number of KiB free on the destination drive
82 unsigned long FindFreeSpace(const TCHAR
*path
) {
85 return 64 * 1024 * 1024;
88 if (statvfs(path
, &s
) < 0)
90 return s
.f_bsize
* s
.f_bavail
/ 1024;
92 #else /* !HAVE_POSIX */
93 ULARGE_INTEGER FreeBytesAvailableToCaller
;
94 ULARGE_INTEGER TotalNumberOfBytes
;
95 ULARGE_INTEGER TotalNumberOfFreeBytes
;
96 if (GetDiskFreeSpaceEx(path
,
97 &FreeBytesAvailableToCaller
,
99 &TotalNumberOfFreeBytes
)) {
100 return FreeBytesAvailableToCaller
.LowPart
/ 1024;
103 #endif /* !HAVE_POSIX */
107 StartupLogFreeRamAndStorage()
110 unsigned long freeram
= SystemFreeRAM() / 1024;
111 LogFormat("Free ram %lu KB", freeram
);
113 unsigned long freestorage
= FindFreeSpace(GetPrimaryDataPath());
114 LogFormat("Free storage %lu KB", freestorage
);
118 * Returns the screen dimension rect to be used
119 * @return The screen dimension rect to be used
124 #if defined(WIN32) && !defined(_WIN32_WCE)
125 unsigned width
= CommandLine::width
+ 2 * GetSystemMetrics(SM_CXFIXEDFRAME
);
126 unsigned height
= CommandLine::height
+ 2 * GetSystemMetrics(SM_CYFIXEDFRAME
)
127 + GetSystemMetrics(SM_CYCAPTION
);
129 return { width
, height
};
132 return { GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
) };
133 #elif defined(ANDROID)
134 return native_view
->GetSize();
135 #elif defined(USE_VIDEOCORE)
136 uint32_t width
, height
;
137 return graphics_get_display_size(0, &width
, &height
) >= 0
138 ? PixelSize(width
, height
)
139 : PixelSize(640, 480);
141 /// @todo implement this properly for SDL/UNIX
142 return { CommandLine::width
, CommandLine::height
};