File: PlatformSpecific.h

package info (click to toggle)
amule 1%3A2.3.2-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 27,584 kB
  • sloc: cpp: 115,104; ansic: 8,572; sh: 5,729; makefile: 1,706; php: 1,680; perl: 955; yacc: 822; ruby: 729; objc: 692; lex: 633; java: 413; xml: 27; python: 26; awk: 21; sed: 16
file content (152 lines) | stat: -rw-r--r-- 4,166 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//
// This file is part of the aMule Project.
//
// Copyright (c) 2008-2011 aMule Team ( admin@amule.org / http://www.amule.org )
//
// Any parts of this program derived from the xMule, lMule or eMule project,
// or contributed by third-party developers are copyrighted by their
// respective authors.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
//

#ifndef PLATFORMSPECIFIC_H
#define PLATFORMSPECIFIC_H

#include <common/Path.h>
#include "Types.h"


namespace PlatformSpecific {


/**
 * Create sparse file.
 *
 * This function will create the named file sparse if possible.
 *
 * @param name The file to be created (sparse if possible).
 * @param size The desired size of the file.
 * @return true, if creating the file succeeded, false otherwise.
 */
bool CreateSparseFile(const CPath& name, uint64_t size);


/**
 * Returns the max number of connections the current OS can handle.
 *
 * Currently anything but windows will return the default value (-1);
 */
#ifdef __WINDOWS__
int GetMaxConnections();
#else
inline int GetMaxConnections() { return -1; }
#endif


/**
 * File system types returned by GetFilesystemType
 */
enum EFSType {
	fsFAT,		//! File Allocation Table
	fsNTFS,		//! New Technology File System
	fsHFS,		//! Hierarchical File System
	fsHPFS,		//! High Performace File System
	fsMINIX,	//! Minix file system
	fsOther		//! Unknown, other
};

/**
 * Find out the filesystem type of the given path.
 *
 * @param path The path for which the filesystem type should be checked.
 * @return The filesystem type of the given path.
 *
 * This function returns fsOther on unknown or network file systems (because the
 * real filesystem type cannot be determined).
 */
EFSType GetFilesystemType(const CPath& path);


/**
 * Checks if the filesystem can handle special chars.
 *
 * @param path The path for which the file system should be checked.
 * @return true if the underlying filesystem can handle special chars.
 *
 * This function checks if the file system of the given path can handle
 * special chars e.g. ':' in file names. This function will always return
 * false on MSW, since Windows cannot handle those characters on any file system.
 *
 * Based on http://en.wikipedia.org/wiki/Comparison_of_file_systems
 */
#ifdef __WINDOWS__
inline bool CanFSHandleSpecialChars(const CPath& WXUNUSED(path)) { return false; }
#else
// Other filesystem types may be added
inline bool CanFSHandleSpecialChars(const CPath& path)
{
	switch (GetFilesystemType(path)) {
		case fsFAT:
		case fsNTFS:
		case fsHFS:
			return false;
		default:
			return true;
	}
}
#endif


/**
 * Check if the filesystem can handle large files.
 *
 * @param path The path for which the filesystem should be checked.
 * @return true if the underlying filesystem can handle large files.
 *
 * This function checks if the file system of the given path can handle
 * large files (>4GB).
 *
 * Based on http://en.wikipedia.org/wiki/Comparison_of_file_systems
 */
inline bool CanFSHandleLargeFiles(const CPath& path)
{
	switch (GetFilesystemType(path)) {
		case fsFAT:
		case fsHFS:
		case fsHPFS:
		case fsMINIX:
			return false;
		default:
			return true;
	}
}

/**
 * Disable / enable computer's energy saving "standby" mode.
 *
 */
#if defined __WINDOWS__ || defined __WXMAC__
	#define PLATFORMSPECIFIC_CAN_PREVENT_SLEEP_MODE 1
#else
	#define PLATFORMSPECIFIC_CAN_PREVENT_SLEEP_MODE 0
#endif

void PreventSleepMode();
void AllowSleepMode();

}; /* namespace PlatformSpecific */

#endif /* PLATFORMSPECIFIC_H */