blob: 3132602e03732cc5f58610255c89be159f0a50bf (
plain)
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
|
#include "talk/base/win32.h"
#include <shellapi.h>
#include <shlobj.h>
#include <tchar.h>
#include <time.h>
#include "talk/base/common.h"
#include "talk/base/diskcache.h"
#include "talk/base/pathutils.h"
#include "talk/base/stream.h"
#include "talk/base/stringencode.h"
#include "talk/base/stringutils.h"
#include "talk/base/diskcache_win32.h"
namespace talk_base {
bool DiskCacheWin32::InitializeEntries() {
// Note: We could store the cache information in a separate file, for faster
// initialization. Figuring it out empirically works, too.
std::wstring path16 = ToUtf16(folder_);
path16.append(1, '*');
WIN32_FIND_DATA find_data;
HANDLE find_handle = FindFirstFile(path16.c_str(), &find_data);
if (find_handle != INVALID_HANDLE_VALUE) {
do {
size_t index;
std::string id;
if (!FilenameToId(ToUtf8(find_data.cFileName), &id, &index))
continue;
Entry* entry = GetOrCreateEntry(id, true);
entry->size += find_data.nFileSizeLow;
total_size_ += find_data.nFileSizeLow;
entry->streams = max(entry->streams, index + 1);
FileTimeToUnixTime(find_data.ftLastWriteTime, &entry->last_modified);
} while (FindNextFile(find_handle, &find_data));
FindClose(find_handle);
}
return true;
}
bool DiskCacheWin32::PurgeFiles() {
std::wstring path16 = ToUtf16(folder_);
path16.append(1, '*');
path16.append(1, '\0');
SHFILEOPSTRUCT file_op = { 0 };
file_op.wFunc = FO_DELETE;
file_op.pFrom = path16.c_str();
file_op.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT
| FOF_NORECURSION | FOF_FILESONLY;
if (0 != SHFileOperation(&file_op)) {
LOG_F(LS_ERROR) << "Couldn't delete cache files";
return false;
}
return true;
}
bool DiskCacheWin32::FileExists(const std::string& filename) const {
DWORD result = ::GetFileAttributes(ToUtf16(filename).c_str());
return (INVALID_FILE_ATTRIBUTES != result);
}
bool DiskCacheWin32::DeleteFile(const std::string& filename) const {
return ::DeleteFile(ToUtf16(filename).c_str()) != 0;
}
}
|