AJA NTV2 SDK  17.5.0.1242
NTV2 SDK 17.5.0.1242
system.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
8 #include "system.h"
9 
10 #include <cstdlib>
11 #include <sstream>
12 
13 #if defined(AJA_WINDOWS)
14 
15 namespace aja
16 {
17  bool
18  write_registry_string(HKEY hkey, std::string key_path, std::string key, std::string value)
19  {
20  bool outValue = false;
21 
22  DWORD dwType = REG_EXPAND_SZ;
23  DWORD dwInSize = (DWORD)value.size();
24 
25  DWORD disposition;
26 
27  HKEY openedPathHkey;
28  long lResult = RegCreateKeyExA(hkey, key_path.c_str(), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_WOW64_64KEY, NULL, &openedPathHkey, &disposition);
29  if(ERROR_SUCCESS == lResult)
30  {
31  lResult = RegSetValueExA(openedPathHkey, key.c_str(), NULL, dwType, (BYTE*)value.c_str(), dwInSize);
32  if (lResult == ERROR_SUCCESS)
33  {
34  outValue = true;
35  }
36  RegCloseKey(openedPathHkey);
37  }
38 
39  return outValue;
40  }
41 
42  bool
43  write_registry_dword(HKEY hkey, std::string key_path, std::string key, DWORD value)
44  {
45  bool outValue = false;
46 
47  DWORD dwType = REG_DWORD;
48  DWORD dwInSize = sizeof(value);
49 
50  DWORD disposition;
51 
52  HKEY openedPathHkey;
53  long lResult = RegCreateKeyExA(hkey, key_path.c_str(), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_WOW64_64KEY, NULL, &openedPathHkey, &disposition);
54  if(ERROR_SUCCESS == lResult)
55  {
56  lResult = RegSetValueExA(openedPathHkey, key.c_str(), NULL, dwType, (BYTE*)&value, dwInSize);
57  if (lResult == ERROR_SUCCESS)
58  {
59  outValue = true;
60  }
61  RegCloseKey(openedPathHkey);
62  }
63 
64  return outValue;
65  }
66 
67  std::string
68  read_registry_string(HKEY hkey, std::string key_path, std::string key)
69  {
70  std::string outValue;
71 
72  const DWORD buffSize = 128;
73  char szBuff[buffSize];
74  memset(szBuff, 0, buffSize);
75 
76  DWORD dwType = 0;
77  DWORD dwInOutSize = buffSize;
78 
79  HKEY openedPathHkey;
80  long lResult = RegOpenKeyExA(hkey, key_path.c_str(), 0, KEY_QUERY_VALUE|KEY_WOW64_64KEY, &openedPathHkey);
81  if(ERROR_SUCCESS == lResult)
82  {
83  lResult = RegQueryValueExA(openedPathHkey, key.c_str(), NULL, &dwType, (BYTE*)szBuff, &dwInOutSize);
84  if (lResult == ERROR_SUCCESS)
85  {
86  outValue = szBuff;
87  }
88 
89  RegCloseKey(openedPathHkey);
90  }
91 
92  return outValue;
93  }
94 
95  DWORD
96  read_registry_dword(HKEY hkey, std::string key_path, std::string key)
97  {
98  DWORD outValue=0;
99 
100  DWORD dwType = 0;
101  DWORD dwInOutSize = sizeof(outValue);
102 
103  HKEY openedPathHkey;
104  long lResult = RegOpenKeyExA(hkey, key_path.c_str(), 0, KEY_QUERY_VALUE|KEY_WOW64_64KEY, &openedPathHkey);
105  if(ERROR_SUCCESS == lResult)
106  {
107  lResult = RegQueryValueExA(openedPathHkey, key.c_str(), NULL, &dwType, (BYTE*)&outValue, &dwInOutSize);
108  RegCloseKey(openedPathHkey);
109  }
110 
111  return outValue;
112  }
113 
114  int reveal_file_in_file_manager(const std::string& filePath)
115  {
116  std::ostringstream oss;
117  oss << "explorer /select," << "\"" << filePath << "\"";
118  return ::system(oss.str().c_str());
119  }
120 
121 } //end aja namespace
122 
123 #endif //end AJA_WINDOWS
124 
125 #if defined(AJA_MAC)
126 namespace aja
127 {
128  int reveal_file_in_file_manager(const std::string& filePath)
129  {
130  std::ostringstream oss;
131  oss << "/usr/bin/osascript" << " -e \"" << "tell application \\\"Finder\\\"" << "\""
132  << " -e \"" << "activate" << "\""
133  << " -e \"" << "reveal \\\"" + filePath + "\\\" as POSIX file" << "\""
134  << " -e \"" << "end tell" << "\"";
135  return ::system(oss.str().c_str());
136  }
137 } //end aja namespace
138 #endif //end AJA_MAC
139 
140 #if defined(AJA_LINUX)
141 #include <libgen.h> // for dirname()
142 namespace aja
143 {
144  int reveal_file_in_file_manager(const std::string& filePath)
145  {
146  // need to pass the directory of the file to open in file manager, otherwise
147  // will open in the default application for file type
148  std::ostringstream oss;
149  oss << "xdg-open " << "\"" << dirname((char*)filePath.c_str()) << "\"";
150  return ::system(oss.str().c_str());
151  }
152 } //end aja namespace
153 #endif //end AJA_LINUX
nlohmann::json_abiNLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON_v3_11_NLOHMANN_JSON_VERSION_PATCH::detail::parse_event_t::value
@ value
the parser finished reading a JSON value
NULL
#define NULL
Definition: ntv2caption608types.h:19
aja::reveal_file_in_file_manager
AJA_EXPORT int reveal_file_in_file_manager(const std::string &filePath)
nlohmann::json_abiNLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON_v3_11_NLOHMANN_JSON_VERSION_PATCH::detail::parse_event_t::key
@ key
the parser read a key of a value in an object
system.h
System specific functions.
aja
Definition: common.cpp:57