Fixed the file implementations, they weren't using a mode, and the base path was always set to /tmp/.

We now get the systems idea of where the users download folder is and use that as the base path when receiving a file.

PiperOrigin-RevId: 406406731
This commit is contained in:
jfcarroll
2021-10-29 11:46:22 -07:00
committed by Copybara-Service
parent acf516189b
commit 44fad7d8fb
7 changed files with 57 additions and 17 deletions
+23 -2
View File
@@ -14,6 +14,8 @@
#include "platform/impl/windows/test_utils.h"
#include <shlobj.h>
#include "absl/strings/str_cat.h"
namespace test_utils {
@@ -29,8 +31,27 @@ std::wstring StringToWideString(const std::string& s) {
}
std::string GetPayloadPath(location::nearby::PayloadId payload_id) {
auto returnString = absl::StrCat("/tmp/", payload_id);
PWSTR basePath;
return returnString;
// Retrieves the full path of a known folder identified by the folder's
// KNOWNFOLDERID.
// https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetknownfolderpath
SHGetKnownFolderPath(
FOLDERID_Downloads, // rfid: A reference to the KNOWNFOLDERID that
// identifies the folder.
0, // dwFlags: Flags that specify special retrieval options.
NULL, // hToken: An access token that represents a particular user.
&basePath); // ppszPath: When this method returns, contains the address
// of a pointer to a null-terminated Unicode string that
// specifies the path of the known folder. The calling
// process is responsible for freeing this resource once it
// is no longer needed by calling CoTaskMemFree, whether
// SHGetKnownFolderPath succeeds or not.
char* fullpathUTF8 = new char((wcslen(basePath) + 1) * sizeof(char));
wcstombs(fullpathUTF8, basePath, (wcslen(basePath) + 1) * sizeof(char));
std::string fullPath = std::string(fullpathUTF8);
auto retval = absl::StrCat(fullPath += "/", payload_id);
return retval;
}
} // namespace test_utils