14
14
15
15
#include " auth/src/desktop/secure/user_secure_fake_internal.h"
16
16
17
+ #if defined(_WIN32)
18
+ #include < windows.h>
19
+ #else
17
20
#include < dirent.h>
18
21
#include < sys/stat.h>
19
22
#include < sys/types.h>
23
+ #endif // defined(_WIN32)
20
24
21
25
#include < cstdio>
22
26
#include < fstream>
@@ -55,7 +59,11 @@ std::string UserSecureFakeInternal::LoadUserData(const std::string& app_name) {
55
59
void UserSecureFakeInternal::SaveUserData (const std::string& app_name,
56
60
const std::string& user_data) {
57
61
// Make the directory in case it doesn't already exist, ignoring errors.
62
+ #if defined(_WIN32)
63
+ CreateDirectory (secure_path_.c_str (), NULL );
64
+ #else
58
65
mkdir (secure_path_.c_str (), 0700 );
66
+ #endif
59
67
60
68
std::string filename = GetFilePath (app_name);
61
69
@@ -72,10 +80,27 @@ void UserSecureFakeInternal::DeleteUserData(const std::string& app_name) {
72
80
return ;
73
81
}
74
82
infile.close ();
75
- std::remove (filename.c_str ());
83
+ #if defined(_WIN32)
84
+ DeleteFile (filename.c_str ());
85
+ #else
86
+ unlink (filename.c_str ());
87
+ #endif // defined(_WIN32)
76
88
}
77
89
78
90
void UserSecureFakeInternal::DeleteAllData () {
91
+ #if defined(_WIN32)
92
+ WIN32_FIND_DATA file_data;
93
+ HANDLE handle = FindFirstFile (secure_path_.c_str (), &file_data);
94
+ if (INVALID_HANDLE_VALUE == handle) {
95
+ return ;
96
+ }
97
+ DeleteFile (file_data.cFileName );
98
+ while (FindNextFile (handle, &file_data)) {
99
+ DeleteFile (file_data.cFileName );
100
+ }
101
+ FindClose (handle);
102
+ RemoveDirectory (secure_path_.c_str ());
103
+ #else
79
104
// These are data types defined in the "dirent" header
80
105
DIR* theFolder = opendir (secure_path_.c_str ());
81
106
if (!theFolder) {
@@ -87,12 +112,13 @@ void UserSecureFakeInternal::DeleteAllData() {
87
112
// build the path for each file in the folder
88
113
std::string filepath = secure_path_ + " /" ;
89
114
filepath.append (next_file->d_name );
90
- remove (filepath.c_str ());
115
+ unlink (filepath.c_str ());
91
116
}
92
117
closedir (theFolder);
93
118
94
119
// Remove the directory if it's empty, ignoring errors.
95
120
rmdir (secure_path_.c_str ());
121
+ #endif
96
122
}
97
123
98
124
std::string UserSecureFakeInternal::GetFilePath (const std::string& app_name) {
0 commit comments