1// 2// This file is part of the aMule Project. 3// 4// Copyright (c) 2008-2011 aMule Team ( admin@amule.org / http://www.amule.org ) 5// 6// Any parts of this program derived from the xMule, lMule or eMule project, 7// or contributed by third-party developers are copyrighted by their 8// respective authors. 9// 10// This program is free software; you can redistribute it and/or modify 11// it under the terms of the GNU General Public License as published by 12// the Free Software Foundation; either version 2 of the License, or 13// (at your option) any later version. 14// 15// This program is distributed in the hope that it will be useful, 16// but WITHOUT ANY WARRANTY; without even the implied warranty of 17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18// GNU General Public License for more details. 19// 20// You should have received a copy of the GNU General Public License 21// along with this program; if not, write to the Free Software 22// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 23// 24 25#ifndef PLATFORMSPECIFIC_H 26#define PLATFORMSPECIFIC_H 27 28#include <common/Path.h> 29#include "Types.h" 30 31 32namespace PlatformSpecific { 33 34 35/** 36 * Create sparse file. 37 * 38 * This function will create the named file sparse if possible. 39 * 40 * @param name The file to be created (sparse if possible). 41 * @param size The desired size of the file. 42 * @return true, if creating the file succeeded, false otherwise. 43 */ 44bool CreateSparseFile(const CPath& name, uint64_t size); 45 46 47/** 48 * Returns the max number of connections the current OS can handle. 49 * 50 * Currently anything but windows will return the default value (-1); 51 */ 52#ifdef __WXMSW__ 53int GetMaxConnections(); 54#else 55inline int GetMaxConnections() { return -1; } 56#endif 57 58 59/** 60 * File system types returned by GetFilesystemType 61 */ 62enum EFSType { 63 fsFAT, //! File Allocation Table 64 fsNTFS, //! New Technology File System 65 fsHFS, //! Hierarchical File System 66 fsHPFS, //! High Performace File System 67 fsMINIX, //! Minix file system 68 fsOther //! Unknown, other 69}; 70 71/** 72 * Find out the filesystem type of the given path. 73 * 74 * @param path The path for which the filesystem type should be checked. 75 * @return The filesystem type of the given path. 76 * 77 * This function returns fsOther on unknown or network file systems (because the 78 * real filesystem type cannot be determined). 79 */ 80EFSType GetFilesystemType(const CPath& path); 81 82 83/** 84 * Checks if the filesystem can handle special chars. 85 * 86 * @param path The path for which the file system should be checked. 87 * @return true if the underlying filesystem can handle special chars. 88 * 89 * This function checks if the file system of the given path can handle 90 * special chars e.g. ':' in file names. This function will always return 91 * false on MSW, since Windows cannot handle those characters on any file system. 92 * 93 * Based on http://en.wikipedia.org/wiki/Comparison_of_file_systems 94 */ 95#ifdef __WXMSW__ 96inline bool CanFSHandleSpecialChars(const CPath& WXUNUSED(path)) { return false; } 97#else 98// Other filesystem types may be added 99inline bool CanFSHandleSpecialChars(const CPath& path) 100{ 101 switch (GetFilesystemType(path)) { 102 case fsFAT: 103 case fsHFS: 104 return false; 105 default: 106 return true; 107 } 108} 109#endif 110 111 112/** 113 * Check if the filesystem can handle large files. 114 * 115 * @param path The path for which the filesystem should be checked. 116 * @return true if the underlying filesystem can handle large files. 117 * 118 * This function checks if the file system of the given path can handle 119 * large files (>4GB). 120 * 121 * Based on http://en.wikipedia.org/wiki/Comparison_of_file_systems 122 */ 123inline bool CanFSHandleLargeFiles(const CPath& path) 124{ 125 switch (GetFilesystemType(path)) { 126 case fsFAT: 127 case fsHFS: 128 case fsHPFS: 129 case fsMINIX: 130 return false; 131 default: 132 return true; 133 } 134} 135 136/** 137 * Disable / enable computer's energy saving "standby" mode. 138 * 139 */ 140#if defined __WXMSW__ || defined __WXMAC__ 141 #define PLATFORMSPECIFIC_CAN_PREVENT_SLEEP_MODE 1 142#else 143 #define PLATFORMSPECIFIC_CAN_PREVENT_SLEEP_MODE 0 144#endif 145 146void PreventSleepMode(); 147void AllowSleepMode(); 148 149}; /* namespace PlatformSpecific */ 150 151#endif /* PLATFORMSPECIFIC_H */ 152