resolve merge conflicts of a9e2b99 to nyc-dev-plus-aosp
Change-Id: Ic77afb008f68ebc455d3a788119b669a52a254dc
diff --git a/adb/adb_utils.cpp b/adb/adb_utils.cpp
index 5d4755f..31ec8af 100644
--- a/adb/adb_utils.cpp
+++ b/adb/adb_utils.cpp
@@ -35,6 +35,14 @@
#include "adb_trace.h"
#include "sysdeps.h"
+#ifdef _WIN32
+# ifndef WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+# endif
+# include "windows.h"
+# include "shlobj.h"
+#endif
+
ADB_MUTEX_DEFINE(basename_lock);
ADB_MUTEX_DEFINE(dirname_lock);
@@ -254,3 +262,30 @@
return true;
}
+
+std::string adb_get_homedir_path(bool check_env_first) {
+#ifdef _WIN32
+ if (check_env_first) {
+ if (const char* const home = getenv("ANDROID_SDK_HOME")) {
+ return home;
+ }
+ }
+
+ WCHAR path[MAX_PATH];
+ const HRESULT hr = SHGetFolderPathW(NULL, CSIDL_PROFILE, NULL, 0, path);
+ if (FAILED(hr)) {
+ D("SHGetFolderPathW failed: %s", android::base::SystemErrorCodeToString(hr).c_str());
+ return {};
+ }
+ std::string home_str;
+ if (!android::base::WideToUTF8(path, &home_str)) {
+ return {};
+ }
+ return home_str;
+#else
+ if (const char* const home = getenv("HOME")) {
+ return home;
+ }
+ return {};
+#endif
+}