Skip to content

Commit

Permalink
Refactor visual diff action
Browse files Browse the repository at this point in the history
- Pass `Config` to `SendGuiMessage()`
- Return `absl::Status`
- Use `absl::FunctionRef<>`
- Clean up how the path to "Program Files" is obtained

PiperOrigin-RevId: 637559132
Change-Id: Icee7464935d75ce8706edb70b69c237ca3afd853
  • Loading branch information
cblichmann authored and copybara-github committed May 27, 2024
1 parent f8a8420 commit e5199d7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
17 changes: 17 additions & 0 deletions util/process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#include <cstdlib>
#include <cstring>
#include <locale> // IWYU pragma: keep
#include <string>
#include <vector>

#include "third_party/absl/base/attributes.h" // IWYU pragma: keep
#include "third_party/absl/status/status.h"
Expand Down Expand Up @@ -285,4 +287,19 @@ absl::StatusOr<std::string> GetCommonAppDataDirectory(
return path;
}

absl::StatusOr<std::string> GetProgramFilesDirectory() {
#if defined(_WIN32)
char buffer[MAX_PATH] = {0};
if (SHGetFolderPath(/*hwndOwner=*/0, CSIDL_PROGRAM_FILES, /*hToken=*/0,
/*dwFlags=*/0, buffer) != S_OK) {
return absl::UnknownError(GetLastOsError());
}
return std::string(buffer);
#elif defined(__APPLE__)
return "/Applications";
#else
return "/opt";
#endif
}

} // namespace security::binexport
12 changes: 11 additions & 1 deletion util/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ absl::StatusOr<std::string> GetModuleFilename();
// Windows C:\Users\<User>\AppData\Roaming\BinDiff
// %AppData%\BinDiff
// Linux /home/<User>/.bindiff
// macOS /Users/<User>/Library/Application Supprt/BinDiff
// macOS /Users/<User>/Library/Application Support/BinDiff
absl::StatusOr<std::string> GetOrCreateAppDataDirectory(
absl::string_view product_name);

Expand All @@ -70,6 +70,16 @@ absl::StatusOr<std::string> GetOrCreateAppDataDirectory(
absl::StatusOr<std::string> GetCommonAppDataDirectory(
absl::string_view product_name);

// Returns the platform-specific per-machine directory for application packages.
// Returns one of these paths:
// OS Typical value
// ------------------------------------------------------
// Windows C:\Program Files
// %ProgramFiles%
// Linux /opt
// macOS /Applications
absl::StatusOr<std::string> GetProgramFilesDirectory();

} // namespace security::binexport

#endif // UTIL_PROCESS_H_

0 comments on commit e5199d7

Please sign in to comment.