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
+29 -8
View File
@@ -14,6 +14,9 @@
#include "platform/api/platform.h"
#include <shlobj.h>
#include "platform/impl/shared/count_down_latch.h"
#include "platform/impl/shared/file.h"
#include "platform/impl/windows/atomic_boolean.h"
#include "platform/impl/windows/atomic_reference.h"
@@ -22,7 +25,6 @@
#include "platform/impl/windows/bluetooth_classic_medium.h"
#include "platform/impl/windows/cancelable.h"
#include "platform/impl/windows/condition_variable.h"
#include "platform/impl/shared/count_down_latch.h"
#include "platform/impl/windows/executor.h"
#include "platform/impl/windows/future.h"
#include "platform/impl/windows/listenable_future.h"
@@ -41,7 +43,28 @@ namespace api {
namespace {
std::string GetPayloadPath(PayloadId payload_id) {
return absl::StrCat("/tmp/", payload_id);
PWSTR basePath;
// 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
@@ -71,14 +94,13 @@ ImplementationPlatform::CreateConditionVariable(Mutex* mutex) {
std::unique_ptr<InputFile> ImplementationPlatform::CreateInputFile(
PayloadId payload_id, std::int64_t total_size) {
return absl::make_unique<shared::InputFile>(
GetPayloadPath(payload_id), total_size);
return absl::make_unique<shared::InputFile>(GetPayloadPath(payload_id),
total_size);
}
std::unique_ptr<OutputFile> ImplementationPlatform::CreateOutputFile(
PayloadId payload_id) {
return absl::make_unique<shared::OutputFile>(
GetPayloadPath(payload_id));
return absl::make_unique<shared::OutputFile>(GetPayloadPath(payload_id));
}
// TODO(b/184975123): replace with real implementation.
@@ -111,8 +133,7 @@ ImplementationPlatform::CreateBluetoothAdapter() {
std::unique_ptr<BluetoothClassicMedium>
ImplementationPlatform::CreateBluetoothClassicMedium(
nearby::api::BluetoothAdapter& adapter) {
return absl::make_unique<windows::BluetoothClassicMedium>(
adapter);
return absl::make_unique<windows::BluetoothClassicMedium>(adapter);
}
// TODO(b/184975123): replace with real implementation.