OLD | NEW |
| (Empty) |
1 // Copyright 2004-2009 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // ======================================================================== | |
15 // | |
16 // Disk functions | |
17 | |
18 #ifndef OMAHA_COMMON_DISK_H__ | |
19 #define OMAHA_COMMON_DISK_H__ | |
20 | |
21 #include <atlstr.h> | |
22 #include "base/basictypes.h" | |
23 | |
24 namespace omaha { | |
25 | |
26 // A constant we use to determine a large drive. | |
27 // Although today this isn't really really large, | |
28 // it is enough to distinguish small, removable | |
29 // drives that are not continually connected to | |
30 // a computer, from the drives that are. | |
31 // In addition to using this constant, we | |
32 // also check if the drive is hot-pluggable. | |
33 const uint64 kLargeDriveSize = 0x00000000ffffffff; | |
34 | |
35 // returns true if the device is an external disk | |
36 // drive typically is something like: \\?\C: | |
37 bool IsDiskExternal(const TCHAR *drive); | |
38 | |
39 // | |
40 // Determines if a drive can be unplugged without manually disabling | |
41 // the drive first. By default, USB drives are initialized with | |
42 // "surprise removal" enabled, which means they are hot-pluggable. | |
43 // | |
44 // @param drive The root of the drive, as returned from GetLogicalDriveStrings | |
45 // e.g. "E:\\". | |
46 // | |
47 // @returns true if the drive is optimized for quick/surprise removal. | |
48 // If the function returns false, then caching (lazy write) is enabled for | |
49 // the drive, otherwise it is not. | |
50 // If an error occurs during this call, the return value will be 'true' since | |
51 // we always want to treat a drive as hot-pluggable if we're not sure. | |
52 // | |
53 bool IsHotPluggable(const TCHAR* drive); | |
54 | |
55 // | |
56 // @returns true if the specified drive is larger than kLargeDriveSize. | |
57 // | |
58 // @param drive The root of the drive, as returned from GetLogicalDriveStrings | |
59 // e.g. "E:\\". | |
60 // | |
61 bool IsLargeDrive(const TCHAR* drive); | |
62 | |
63 // find the first fixed local disk with at least the space requested | |
64 // returns the drive in the drive parameter | |
65 // returns E_FAIL if no drive with enough space could be found | |
66 HRESULT FindFirstLocalDriveWithEnoughSpace(const uint64 space_required, | |
67 CString *drive); | |
68 | |
69 // Get free disk space of a drive containing the specified folder | |
70 HRESULT GetFreeDiskSpace(uint32 csidl, uint64* free_disk_space); | |
71 | |
72 // Get free disk space of a drive containing the specified folder | |
73 HRESULT GetFreeDiskSpace(const TCHAR* folder, uint64* free_disk_space); | |
74 | |
75 // Has enough free disk space on a drive containing the specified folder | |
76 HRESULT HasEnoughFreeDiskSpace(uint32 csidl, uint64 disk_space_needed); | |
77 | |
78 // Has enough free disk space on a drive containing the specified folder | |
79 HRESULT HasEnoughFreeDiskSpace(const TCHAR* folder, uint64 disk_space_needed); | |
80 | |
81 // Convert from "\Device\Harddisk0\Partition1\WINNT\System32\ntdll.dll" to | |
82 // "C:\WINNT\System32\ntdll.dll" | |
83 HRESULT DevicePathToDosPath(const TCHAR* device_path, CString* dos_path); | |
84 | |
85 // | |
86 // Disables critical error dialogs on the current thread. | |
87 // The system does not display the critical-error-handler message box. | |
88 // Instead, the system returns the error to the calling process. | |
89 // | |
90 class DisableThreadErrorUI { | |
91 public: | |
92 DisableThreadErrorUI() { | |
93 // Set the error mode | |
94 prev_mode_ = SetErrorMode(SEM_FAILCRITICALERRORS); | |
95 } | |
96 | |
97 ~DisableThreadErrorUI() { | |
98 // Restore the error mode | |
99 SetErrorMode(prev_mode_); | |
100 } | |
101 | |
102 protected: | |
103 UINT prev_mode_; | |
104 }; | |
105 | |
106 } // namespace omaha | |
107 | |
108 #endif // OMAHA_COMMON_DISK_H__ | |
109 | |
OLD | NEW |