-
Notifications
You must be signed in to change notification settings - Fork 0
Methods
Producer functions make calls to WinRT and supported Win32 API's to get relevant system, user and hardware information. After retrieving this information, these functions format and store the data in a given cylonStruct.
-
void produceUsername(struct cylonStruct& tf)
-
This function calls the Windows UserInformation GetDisplayNameAsync() method to retrieve the username of the current logged in user. To allow rapid refreshes of a cylonStruct, a blocking loop prevents the function from proceeding until the asynchronous response has replied with a result. Finally, the function converts the result into a wstring and stores it in the provided cylonStruct.
-
void produceTimeZone(struct cyclonStruct& tory)
-
This function calls the Windows method GetTimeZoneInformation, and stores the received bias and time zone names in the given cylonStruct. Additionally, a conversion is done on the DWORD result of the GetTimeZoneInformation call, and the result is stored as the dst member variable of the cylonStruct.
-
void produceDateTime(struct cylonStruct& tory)
-
This function calls the Windows method GetLocalTime, and stores the resulting responses for hours, minutes, seconds, milliseconds, day, date, month, and year in the provided cylonStruct.
-
void produceDeviceName(struct cylonStruct& tory)
-
This function calls a Windows socket WSAStartup, and makes a request for the host's name via gethostname. After receiving the host name, WSACleanup() is called. The method then converts the host name to a wstring and stores it in the provided cylonStruct.
-
void produceProcessorInfo(struct cylonStruct& tf)
-
This function calls the Windows GetNativeSystemInfo method and fills a local SYSTEM_INFO struct. The cylonStruct's processor architecture variable is set via an if-else interpretation of that object's wProcessorArchitecture enum. Additionally, the cylonStruct's pageSize, minAppAddress, maxAppAddress, processorCount, and allocationGranularity are all gleaned from the SYSTEM_INFO object.
-
void produceMemoryInfo(struct cylonStruct& tf)
-
Due to constraints on UWP, this function checks for the presence of the IsWow64Process() function in the Kernel32.lib (traditionally unaccessible by WinRT apps). If the Kernel function is not located, the given cylonStruct's architecture is set to 32-bit and a minimum RAM of 1GB. If the function is located, a call is made using the current process. If the value returned is true, the architecture is set to 64-bit, otherwise it defaults to 32-bit. WARNING: the above calls use a workaround utilizing the GetKernelModule() method detailed further down in this page, use of this code may result in a rejected submission from the Windows Store for your app, use at your own discretion.
-
The remaining code in this method IS safe to use though.
-
New additions for UWP/Windows 10 have the method grab an AppMemoryReport via GetAppMemoryReport() in the MemoryManager namespace. While other flavors of Centurion (Saul, Ellen, etc.) use the memoryBytes field for how much RAM is installed, Foster has to compromise with the OS rules for UWP apps, and instead sets the memoryBytes field equal to the TotalCommitLimit (measured in bytes) from the report. A lowMemory constant is hard coded (for example, 0.99, though you can change this line to fit your own needs), and then used with the memoryBytes field to calculate the threshold field of the provided cylonStruct. The bytesAvails field of the cylonStruct is calculated using the difference between the TotalCommitLimit and the report's TotalCommitUsage fields. Finally, the cylonStruct's lowMemory field is calculated using the bytesAvails and memoryBytes fields.
-
void produceAccountPicture(struct cylonStruct& tf)
-
In UWP, retrieving account profile image data is an asynchronous process, to avoid busy waiting, the majority of the code has been relocated into a helper class. For now, the only field of the provided cylonStruct that is changed by this method is setting the pictureType field to ".png"
-
void produceDeviceTypeInformation(struct cylonStruct& tf, std::string type)
-
This function retrieves a DeviceInformationCollection^ object like the previous method, but can filter results based on type (video capture, audio capture, audio render, image scanner, location aware, portable storage device, or all, where all recreates the results of the previous method). It then creates a deviceStruct object for each device in the collection and stores it in the master device list of the given cylonStruct.
-
void produceDeviceTypesInformation(struct cylonStruct& tf)
-
This function calls produceDeviceTypeInformation for video capture, audio capture, audio render, location aware, portable storage, and image scanning devices. Following this it calls the additional producers for display, mouse, keyboard, and controller devices before finally updating the cylonStruct's detectedDevices count to be the size of the master device's list.
-
void produceDisplayInformation(struct cylonStruct& tf)
-
This function creates a new instance of a displayStruct (for storing the metadata of the primary display device) using the Windows DisplayInformation class, and creates an additional "parent" deviceStruct to represent the displayStruct within the master list of devices. The deviceStruct's displayIndex value is set to the current size of the display devices list of the provided cylonStruct, and then both of the created structures are stored within the appropriately typed lists of the cylonStruct.
-
void produceMouseInformation(struct cylonStruct& tf)
-
This function creates a new instance of a mouseStruct (for storing the metadata of all the available mice for the current machine) using the Windows MouseCapabilities class, and creates an additional "parent" deviceStruct to represent the mouseStruct in the master list of devices. The deviceStruct is then inserted into the devices list for the provided cylonStruct.
-
void produceKeyboardInformation(struct cylonStruct& tf)
-
This function creates a new deviceStruct and stores it in the master devices list, but only if a keyboard is found via the Windows KeyboardCapabilities class.
-
void produceControllerInformation(struct cylonStruct& tf)
-
This function iterates over all possible values of userIndex for XInput, ranging from 0 to XUSER_MAX_COUNT. For each index, XInputGetState() is called. If the result is successful for that index, a controllerStruct is created and filled with the appropriate metadata from the provided XINPUT_STATE object, as well as a "parent" deviceStruct to represent the controller in the master devices list for the given cylonStruct. The deviceStruct's controllerIndex is set to the size of the controllers list for the cylonStruct, and then both objects are inserted into the appropriate lists. Warning: this XInput style has thrown exceptions in testing when controllers are disconnected in ascending order (i.e., player 1 disconnects before player 2). For a safer approach, please use the produceGamepadInformation() method instead.
-
void produceGamepadInformation(struct cylonStruct& tf)
-
This method begins by setting the gamepad tracking enum "gamepadState", declared in Foster.cpp, to STARTED, defaulting the presentGamepadsAdded int to 0, and lowering the controllersPurged flag. New event handlers are added for when a Gamepad object is removed or added to the computer at runtime (see OnGamepadAdded/Removed for more info). The method then iterates over the size of the Gaming::Gamepads field, and retrieves a reading for every value over the range of that value. deviceStruct and controllerStruct objects are then built, and placed into their respective lists in the given cylonStruct. Finally, the lists are synchronized with each other and the method returns.
-
void produceLog(struct cylonStruct& tf)
-
This method prints out a detailed report of all of the metadata for a given cylonStruct, and its associated device lists.
-
void produceTory(struct cylonStruct& tf)
-
This function calls all other producer functions on a given cylonStruct, excluding produceLog() (commented out but can be re-enabled for debugging purproses) and produceControllerInformation() (replaced by produceGamepadInformation() in produceDeviceTypes()).
Builder functions are similar to constructors. They call various producers to create an object, and then return the fully formed structure for consumption by another method.
-
struct cylonStruct buildTory()
-
This function acts similar to a constructor for a cylonStruct. The struct is initialized and then filled many of the above producer methods, finally returning the new cylonStruct.
-
struct deviceStruct buildDevice(Windows::Devices::Enumeration::DeviceInformation^ deviceInfo, unsigned int deviceType)
-
This function acts similar to a constructor for a deviceStruct. If the provided type is for a display, mouse, keyboard, or controller, a short if clause creates a "default" definition for these device types, and then returns immediately. Otherwise, the provided deviceInfo object is probed and any metadata retrieved is stored before returning the new struct. Fields that are not used in the Windows 8.1 context of the Final Five project (like vendorID) are set to a default.
-
struct controllerStruct buildController(struct deviceStruct superDevice, XINPUT_STATE state, DWORD userIndex)
-
This function acts similar to a constructor for a controllerStruct. It initializes a new controllerStruct, and then populates that struct with acquired values for the provided userIndex, superDevice, and state objects before finally returning the new struct.
-
struct buildDisplay(struct deviceStruct superDevice, Windows::Graphics::Display::DisplayInformation^ displayInformation)
-
This function acts similar to a constructor for a displayStruct. It initializes a new displayStruct, and then populates that struct with acquired values for the provided superDevice and displayInformation objects before finally returning the new struct.
-
struct buildStorage(Windows::Devices::Enumeration::DeviceInformation^ deviceInfo, struct deviceStruct superDevice)
-
This function acts similar to a constructor for a storageStruct. It initializes a new storageStruct, and then populates that struct with acquired values from the provided superDevice and deviceInfo objects before finally returning the new struct. Fields that are unavailable in a UWP context are set to a default value.
-
std::string utf8_encode(const std::wstring &wstr)
-
This function converts a given wstring to a utf8 encoded std::string. Via tfinniga at stackoverflow.
-
std::wstring utf8_decode(const std::string &str)
-
This function converts a given string to a wstring. Via tfinniga at stackoverflow.
- HMODULE GetKernelModule()
- This function allows produceMemoryInformation() to access Kernel32.lib from the WinRT context. For more information, please see the Ted's Blog article on how this method works. This method MAY not pass Windows Store submissions, so use at your own discretion.
- void debug(wstring str)
- This function takes a wstring and prints it to the console utilizing a wostringstream and the MS OutputDebugStringW method.