56 #define PROFILE_VERSION 2.0
57 #define MAX_PROFILE_MAJOR_VERSION 2
58 #define MAX_DEVICE_PROFILE_MAJOR_VERSION 1
68 #if defined(OVR_OS_WIN32)
70 TCHAR data_path[MAX_PATH];
71 SHGetFolderPath(0, CSIDL_LOCAL_APPDATA,
NULL, 0, data_path);
81 DWORD attrib = GetFileAttributes(wpath);
82 bool exists = attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_DIRECTORY);
85 CreateDirectory(wpath,
NULL);
89 #elif defined(OVR_OS_MAC)
91 const char* home = getenv(
"HOME");
93 path +=
"/Library/Preferences/Oculus";
97 DIR* dir = opendir(path);
100 mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO);
110 passwd* pwd = getpwuid(getuid());
111 const char* home = pwd->pw_dir;
113 path +=
"/.config/Oculus";
117 DIR* dir = opendir(path);
120 mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO);
136 path +=
"/ProfileDB.json";
153 sensor->GetDeviceInfo(&sinfo);
160 const char* product_name =
NULL;
170 const char* oculus =
strstr(product_name,
"Oculus ");
172 product_name = oculus +
OVR_strlen(
"Oculus ");
174 for (
const char* s=product_name; *s != 0; s++)
198 for (
int k=0; k<num_qtags; k++)
204 if (tagval && tagval->
Name == tag_names[k])
206 if (tagval->
Value == qtags[k])
215 if (num_matches == num_qtags)
244 if (tagval && tagval->
Name == tag_name)
246 if (tagval->
Value == qtag)
340 root->AddNumberItem(
"Oculus Profile Version", 2.0);
350 JSON* version_item = root->GetFirstItem();
351 if (version_item->
Name ==
"Oculus Profile Version")
368 JSON* version_item = root->GetFirstItem();
369 if (version_item->
Name ==
"Oculus Profile Version")
392 root->AddNumberItem(
"Oculus Profile Version", 2.0);
397 const char* default_dk1_user = item1->
Value;
400 int profileCount = (int)item2->
dValue;
401 JSON* profileItem = item2;
403 for (
int p=0; p<profileCount; p++)
405 profileItem = root->GetNextItem(profileItem);
406 if (profileItem ==
NULL)
409 if (profileItem->Name ==
"Profile")
412 const char* profileName;
415 if (item && (item->
Name ==
"Name"))
417 profileName = item->
Value;
427 const char* tag_names[2] = {
"User",
"Product"};
429 tags[0] = profileName;
434 float neckeye[2] = { 0, 0 };
445 if (item->
Name ==
"NeckEyeHori")
446 neckeye[0] = (float)item->
dValue;
447 else if (item->
Name ==
"NeckEyeVert")
448 neckeye[1] = (float)item->
dValue;
450 user_profile->SetValue(item);
455 const char* device_name = item->
Name.
ToCStr();
461 device_profile->SetValue(device_item);
465 tags[1] = device_name;
475 if (player_height > 0)
480 const float EYE_TO_HEADTOP_RATIO = 0.44538f;
481 const float MALE_AVG_HEAD_HEIGHT = 0.232f;
482 const float FEMALE_AVG_HEAD_HEIGHT = 0.218f;
487 head_height = FEMALE_AVG_HEAD_HEIGHT;
489 head_height = MALE_AVG_HEAD_HEIGHT;
491 float skull = EYE_TO_HEADTOP_RATIO * head_height;
492 float eye_height = player_height - skull;
498 if (neckeye[0] > 0 && neckeye[1] > 0)
508 const char* tag_names[1] = {
"Product" };
509 const char* tags[1] = {
"RiftDK1" };
511 product_profile->SetValue(
"DefaultUser", default_dk1_user);
565 name_item->
Value = name;
570 else if (compare < 0)
585 if (user_item ==
NULL)
610 if (users && index < users->GetItemCount())
664 for (
unsigned int i=0; i<user_items.
GetSize(); i++)
666 user_items[i]->RemoveNode();
667 user_items[i]->Release();
683 const char* tag_names[2] = {
"Product",
"Serial"};
694 if (product_str && serial_str)
696 tags[0] = product_str;
697 tags[1] = serial_str;
707 const char* user = p->GetValue(
"DefaultUser");
708 if (user !=
NULL && user[0] != 0)
722 const char* tag_names[2] = {
"Product",
"Serial"};
733 if (product_str && serial_str)
735 tags[0] = product_str;
736 tags[1] = serial_str;
739 p->SetValue(
"DefaultUser", user);
760 if (tagged_data ==
NULL)
800 if (tagged_data ==
NULL)
809 for (
int i=0; i<num_tags; i++)
818 tagged_item->
AddItem(
"tags", taglist);
819 tagged_item->
AddItem(
"vals", vals);
824 for (
unsigned int i=0; i<profile->
Values.GetSize(); i++)
845 while (item_element && value_element)
849 if (item_element->
Value != value_element->
Value)
966 for (
unsigned int i=0; i<
Values.GetSize(); i++)
986 item_name = item->
Name;
988 item_name = prefix +
"." + item->
Name;
1012 path +=
"/Devices.json";
1020 JSON* version = root->GetFirstItem();
1021 if (version && version->
Name ==
"Oculus Device Profile Version")
1033 JSON* device = root->GetNextItem(version);
1036 if (device->
Name ==
"Device")
1040 if (product_item && serial_item
1041 && (product_item->
dValue == device_id) && (serial_item->
Value == serial))
1049 device = root->GetNextItem(device);
1058 int digit1 = (byte >> 4) & 0x000f;
1059 int digit2 = byte & 0x000f;
1060 int decimal = digit1 * 10 + digit2;
1067 bool success =
false;
1076 sensor = ((
HMDDevice*)device)->GetSensor();
1115 const char* model_name,
1116 const char* device_serial)
1125 bool user_found =
false;
1129 const char* tag_names[3];
1130 const char* tags[3];
1131 tag_names[0] =
"User";
1137 tag_names[num_tags] =
"Product";
1138 tags[num_tags] = model_name;
1144 tag_names[num_tags] =
"Serial";
1145 tags[num_tags] = device_serial;
1150 for (
int combos=1; combos<=num_tags; combos++)
1152 for (
int i=0; i<(num_tags - combos + 1); i++)
1186 const char* device_model,
1187 const char* device_serial)
1189 if (!
LoadUser(root, user, device_model, device_serial))
1200 if (
ValMap.Get(key, &value))
1218 if (
ValMap.Get(key, &value))
1233 if (
ValMap.Get(key, &value))
1249 return (value->
dValue != 0);
1259 return (
int)(value->
dValue);
1269 return (
float)(value->
dValue);
1283 while (item && count < val_count)
1286 values[count] = (float)item->
dValue;
1321 while (item && count < val_count)
1324 values[count] = item->
dValue;
1368 if (
ValMap.Get(key, &value))
1389 if (
ValMap.Get(key, &value))
1420 if (
ValMap.Get(key, &value))
1426 for (
int i=num_vals; i<num_existing_vals; i++)
1430 while (item && val_count < num_vals)
1433 item->
dValue = vals[val_count];
1453 for (; val_count < num_vals; val_count++)
1461 if (
ValMap.Get(key, &value))
1480 if (
ValMap.Get(key, &value))
1486 for (
int i=num_vals; i<num_existing_vals; i++)
1490 while (item && val_count < num_vals)
1493 item->
dValue = vals[val_count];
1513 for (; val_count < num_vals; val_count++)
virtual bool GetDeviceInfo(DeviceInfo *info) const
void SetDoubleValues(const char *key, const double *vals, int num_vals)
void LoadCache(bool create)
void AddArrayNumber(double n)
bool CreateUser(const char *user, const char *name)
void PushBack(const ValueType &val)
virtual Profile * CreateProfile()
const char * GetValue(const char *key)
float GetFloatValue(const char *key, float default_val) const
bool LoadUser(JSON *root, const char *user, const char *device_name, const char *device_serial)
int GetNumValues(const char *key) const
unsigned GetItemCount() const
int GetIntValue(const char *key, int default_val) const
OVR::Hash< String, JSON *, String::HashFunctor > ValMap
void InsertArrayElement(int index, JSON *item)
static ProfileManager * Create()
#define OVR_KEY_NECK_TO_EYE_DISTANCE
String GetProfilePath(bool create_dir)
UPInt OVR_STDCALL DecodeString(wchar_t *pbuff, const char *putf8str, SPInt bytesLen)
virtual DeviceType GetType() const
void SetBoolValue(const char *key, bool val)
OVR::Array< JSON * > Values
String GetBaseOVRPath(bool create_dir)
void AddBoolItem(const char *name, bool b)
char *OVR_CDECL OVR_strcpy(char *dest, UPInt destsize, const char *src)
#define OVR_DEFAULT_NECK_TO_EYE_VERTICAL
const char * GetDefaultUser(const DeviceBase *device)
Profile * GetProfile(const DeviceBase *device, const char *user)
const char * ToCStr() const
bool LoadDeviceFile(unsigned int device_id, const char *serial)
const char * GetUser(unsigned int index)
static JSON * FindTaggedData(JSON *data, const char **tag_names, const char **qtags, int num_qtags)
static JSON * Load(const char *path, const char **perror=0)
static void FilterTaggedData(JSON *data, const char *tag_name, const char *qtag, Array< JSON * > &items)
#define OVR_DEFAULT_NECK_TO_EYE_HORIZONTAL
static JSON * CreateObject()
static int BCDByte(unsigned int byte)
void AddArrayElement(JSON *item)
void AddItem(const char *string, JSON *item)
static JSON * CreateArray()
void SetValue(const char *key, const char *val)
static JSON * CreateNumber(double num)
void SetIntValue(const char *key, int val)
int GetFloatValues(const char *key, float *values, int num_vals) const
bool GetBoolValue(const char *key, bool default_val) const
void SetDoubleValue(const char *key, double val)
Profile * GetDefaultProfile(const DeviceBase *device)
void LoadV1Profiles(JSON *v1)
JSON * GetItemByIndex(unsigned i)
int OVR_CDECL OVR_strcmp(const char *dest, const char *src)
JSON * GetNextItem(JSON *item)
void SetFloatValues(const char *key, const float *vals, int num_vals)
#define OVR_DEFAULT_PLAYER_HEIGHT
bool SetTaggedProfile(const char **key_names, const char **keys, int num_keys, Profile *profile)
void CopyItems(JSON *root, String prefix)
void AddNumberItem(const char *name, double n)
void AddStringItem(const char *name, const char *s)
bool LoadDeviceProfile(const DeviceBase *device)
#define OVR_DEFAULT_GENDER
static JSON * CreateString(const char *s)
OVR_FORCE_INLINE const T Min(const T a, const T b)
int GetDoubleValues(const char *key, double *values, int num_vals) const
const int MAX_DEVICE_PROFILE_MAJOR_VERSION
virtual SensorDevice * GetSensor()=0
int char * index(const char *__s, int __c) __THROW __attribute_pure__ __nonnull((1))
void AppendChar(UInt32 ch)
#define OVR_KEY_PLAYER_HEIGHT
static bool LoadProfile(const DeviceBase *device, const char *user, Profile **profile)
bool RemoveUser(const char *user)
void SetFloatValue(const char *key, float val)
Profile * GetTaggedProfile(const char **key_names, const char **keys, int num_keys)
#define OVR_KEY_EYE_HEIGHT
static JSON * CreateBool(bool b)
UPInt OVR_CDECL OVR_strlen(const char *str)
__END_NAMESPACE_STD __BEGIN_NAMESPACE_STD size_t size_t char char * strstr(const char *__haystack, const char *__needle) __THROW __attribute_pure__ __nonnull((1
bool SetDefaultUser(const DeviceBase *device, const char *user)
JSON * GetItemByName(const char *name)
bool GetDeviceTags(const DeviceBase *device, String &product, String &serial)
double GetDoubleValue(const char *key, double default_val) const