-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFoster.cpp
More file actions
1870 lines (1607 loc) · 53.8 KB
/
Copy pathFoster.cpp
File metadata and controls
1870 lines (1607 loc) · 53.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//Foster.cpp
//Implements definitions of Foster functionality.
//"Bad becomes good" - Tory Foster
//josh@mindaptiv.com
//includes
#include "pch.h"
#include "Foster.h"
//Namespaces
using namespace std;
using namespace Platform;
using namespace Windows::Foundation::Collections;
using namespace Windows::Foundation;
using namespace Windows::System;
using namespace concurrency;
using namespace Windows::Gaming::Input;
//Variables
enum gamepadUpdatingState
{
STARTED,
REMOVED,
ALL_REMOVED
};
bool controllersPurged;
uint32_t presentGamepadsAdded;
gamepadUpdatingState gamepadState;
//END Variables
//Method definitions:
//build a message to be logged to debug
void debug(wstring str)
{
//Credit to Community & anon @ StackOverflow for the og macro code
std::wostringstream os_;
os_ << str << "\n";
OutputDebugStringW(os_.str().c_str());
}//END debug print
//encoding:
//via tfinniga @ stackoverflow
std::string utf8_encode(const std::wstring &wstr)
{
if (wstr.empty())
{
return std::string();
}
int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
std::string strTo(size_needed, 0);
WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL);
return strTo;
}//end utf8 encoding
std::wstring utf8_decode(const std::string &str)
{
if (str.empty())
{
return std::wstring();
}
int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0);
std::wstring wstrTo(size_needed, 0);
MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstrTo[0], size_needed);
return wstrTo;
}//end utf8 decoding
//Producers:
//Fills cylonStruct with timezone name, UTC offset bias, and dst flag
void produceTimeZone(struct cylonStruct& tory)
{
//Variable Declaration
DWORD tzResult;
TIME_ZONE_INFORMATION tzinfo;
std::wstring timezoneName;
//grab and convert bias
tzResult = GetTimeZoneInformation(&tzinfo);
//set bias
tory.timeZone = tzinfo.Bias;
//Check DWORD value
if (tzResult == TIME_ZONE_ID_STANDARD)
{
//standard time
tory.dst = STANDARD_TIME;
}
else if (tzResult == TIME_ZONE_ID_DAYLIGHT)
{
//daylight time
tory.dst = DAYLIGHT_TIME;
}
else
{
//otherwise or invalid ==> shenanigans
//"Oh hell! I have to run home and grab my broom!"
tory.dst = STANDARD_TIME;
}
//end if
//grab time zone name
std::wstring standardName;
//grab name from TimeZoneInformation
standardName = tzinfo.StandardName;
//convert to utf8
tory.timeZoneName = utf8_encode(standardName);
}
//end produceBias
//Grabs time information and stores it in cylonStruct
void produceDateTime(struct cylonStruct& tory)
{
//Variable declaration
SYSTEMTIME st;
//init st
GetLocalTime(&st);
//grab values from SYSTEMTIME
tory.milliseconds = st.wMilliseconds;
tory.seconds = st.wSecond;
tory.minutes = st.wMinute;
tory.hours = st.wHour;
if (SUNDAY <= st.wDayOfWeek && st.wDayOfWeek <= SATURDAY)
{
//0 = Sun, ..., 6 = Sat
tory.day = st.wDayOfWeek;
}
else
{
//error case
tory.day = SUNDAY;
}//end if
if (1 <= st.wDay && st.wDay <= 31)
{
tory.date = st.wDay;
}
else
{
//error
tory.date = 0;
}//end if
if (1 <= st.wMonth && st.wMonth <= 12)
{
tory.month = st.wMonth;
}
else
{
//error
tory.month = 0;
}//end if
if (st.wYear < 0)
{
//error
tory.year = 0;
}
else
{
tory.year = st.wYear;
}
}
//end produceDateTime
//populates tory's device name
void produceDeviceName(struct cylonStruct& tory)
{
//Variable declaration
int result;
char hostBuffer[MAX_PATH];
std::string deviceName;
std::wstring wDeviceName;
WSAData wsa_data;
//start WSA
WSAStartup(MAKEWORD(1, 1), &wsa_data);
//grab result
result = gethostname(hostBuffer, MAX_PATH);
deviceName = hostBuffer;
//check socket errors
int error;
error = WSAGetLastError();
//cleanup WSA
WSACleanup();
//convert string to wstring (this is done for debugging with the separate debugging test app that wants wstrings)
wDeviceName = utf8_decode(deviceName);
//Check for empty name
if (wDeviceName.length() <= 0)
{
wDeviceName = L"0";
}//end if
//set device name for tory
tory.deviceName = utf8_encode(wDeviceName);
}
//end produceDeviceName
//for getting processor info
void produceProcessorInfo(struct cylonStruct& tf)
{
//Variable Declaration
SYSTEM_INFO sysinfo;
std::string architecture_s;
float32 minHertzz = 1000000000;
//Grab system info
GetNativeSystemInfo(&sysinfo);
//Convert results into local values
//Convert architecture
if (sysinfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
{
//x64 (AMD or Intel)
tf.architecture = "x64";
}
else if (sysinfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_ARM)
{
//ARM
tf.architecture = "ARM";
}
else if (sysinfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)
{
//Intel Itanium-based
tf.architecture = "Itanium";
}
else if (sysinfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
{
//x86
tf.architecture = "x86";
}
else
{
//unknown error
tf.architecture = "0";
}
//end if
//set tory page size
tf.pageSize = (uint32_t)sysinfo.dwPageSize;
//set the min and max pointers for apps
tf.minAppAddress = (uintptr_t)sysinfo.lpMinimumApplicationAddress;
tf.maxAppAddress = (uintptr_t)sysinfo.lpMaximumApplicationAddress;
//set the number of processors
tf.processorCount = (UINT64)sysinfo.dwNumberOfProcessors;
//set allocation granularity
tf.allocationGranularity = (uint32_t)sysinfo.dwAllocationGranularity;
//grab default minimum CPU hertz
tf.hertz = minHertzz;
}
//end produce processor info
//via Ted's Blog
HMODULE GetKernelModule()
{
//NOTE: may not be permissable in Windows Store - hack to get into kernel32
MEMORY_BASIC_INFORMATION mbi = { 0 };
VirtualQuery(VirtualQuery, &mbi, sizeof(mbi));
return reinterpret_cast<HMODULE>(mbi.AllocationBase);
}//end GetKernelModule
//for getting memory info
void produceMemoryInfo(struct cylonStruct& tf)
{
//variable declaration
BOOL bIsWow64 = FALSE;
LPFN_ISWOW64PROCESS fnIsWow64Process;
HMODULE kernelModule = GetKernelModule();
//set unavailable fields
tf.lowMemory = 0;
tf.threshold = 0;
tf.bytesAvails = 0;
//determine OS architecture
//use get process address to get a pointer to function if it exists
//use virtual query of virtual query in place of GetModuleHandle()
fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(kernelModule, "IsWow64Process");
//if isWoW64Process is found
if (NULL != fnIsWow64Process)
{
//current process is not found to be Wow64
if (!fnIsWow64Process(GetCurrentProcess(), &bIsWow64))
{
//error case, assume 32-bit
tf.memoryBytes = 1000000000;
tf.osArchitecture = 32;
}
//current process is found to be Wow64
else
{
//Process is running under WOW64, assume 64-bit
tf.memoryBytes = 2000000000;
tf.osArchitecture = 64;
}
}
//if isWow64 is not found
else
{
//not 64-bit, so assume 32-bit
tf.memoryBytes = 1000000000;
tf.osArchitecture = 32;
}
//New for Win10/Sinew Memory Manager get AppMemoryReport
AppMemoryReport^ report = MemoryManager::GetAppMemoryReport();
//Grab memory info for cylonStruct
tf.memoryBytes = (uint64_t) report->TotalCommitLimit;
float lowMemory = (float)0.99;
tf.threshold = (uint64_t) (lowMemory * tf.memoryBytes);
tf.bytesAvails = (uint64_t)(report->TotalCommitLimit - report->TotalCommitUsage);
//Calculate low memory
if (tf.bytesAvails / tf.memoryBytes >= lowMemory)
{
tf.lowMemory = 1;
}
else
{
tf.lowMemory = 0;
}//END if lowMemory
}
//end produceMemoryInfo
//for getting account picture info
void produceAccountPicture(struct cylonStruct& tf)
{
//Set type
tf.pictureType = ".png";
}
//end produceAccountPicture
void produceDeviceTypeInformation(struct cylonStruct& tf, std::string type)
{
//Variable Declaration
Windows::Foundation::IAsyncOperation<Windows::Devices::Enumeration::DeviceInformationCollection^>^ operation;
Windows::Devices::Enumeration::DeviceInformationCollection^ devices;
Windows::Devices::Enumeration::DeviceClass deviceType;
unsigned int deviceStructType; //type variable in deviceStruct(s) to be built
//set deviceType operation filter based on type string
if (type == "all" || type == "All")
{
deviceType = Windows::Devices::Enumeration::DeviceClass::All;
deviceStructType = GENERIC_TYPE;
}
else if (type == "AudioCapture" || type == "audioCapture")
{
deviceType = Windows::Devices::Enumeration::DeviceClass::AudioCapture;
deviceStructType = AUDIO_CAPTURE_TYPE;
}
else if (type == "AudioRender" || type == "audioRender")
{
deviceType = Windows::Devices::Enumeration::DeviceClass::AudioRender;
deviceStructType = AUDIO_RENDER_TYPE;
}
else if (type == "PortableStorageDevice" || type == "portableStorageDevice")
{
deviceType = Windows::Devices::Enumeration::DeviceClass::PortableStorageDevice;
deviceStructType = STORAGE_TYPE;
}
else if (type == "VideoCapture" || type == "videoCapture")
{
deviceType = Windows::Devices::Enumeration::DeviceClass::VideoCapture;
deviceStructType = VIDEO_CAPTURE_TYPE;
}
else if (type == "ImageScanner" || type == "imageScanner")
{
deviceType = Windows::Devices::Enumeration::DeviceClass::ImageScanner;
deviceStructType = IMAGE_SCANNER_TYPE;
}
else if (type == "Location" || type == "location")
{
deviceType = Windows::Devices::Enumeration::DeviceClass::Location;
deviceStructType = LOCATION_AWARE_TYPE;
}
else
{
//"Hey... You ever wonder why we're here?" - Simmons
//ERROR case, default to all
deviceType = Windows::Devices::Enumeration::DeviceClass::All;
deviceStructType = GENERIC_TYPE;
}
//Grab devices collection for audio rendering
operation = Windows::Devices::Enumeration::DeviceInformation::FindAllAsync(deviceType);
while (operation->Status == Windows::Foundation::AsyncStatus::Started)
{
//WAIT, YO
}
//get the results and close the operation
devices = operation->GetResults();
operation->Close();
//store results in tory based on type string
//have to repeat if logic here due to necessary waiting on operation, either repeat if-logic or repeat the operation code above
if (type == "all" || type == "All")
{
tf.installedDeviceCount = devices->Size;
}
else if (type == "AudioCapture" || type == "audioCapture")
{
//Store Size
tf.micCount = devices->Size;
}//END IF
else if (type == "AudioRender" || type == "audioRender")
{
tf.speakerCount = devices->Size;
}
else if (type == "PortableStorageDevice" || type == "portableStorageDevice")
{
tf.portableStorageCount = devices->Size;
}
else if (type == "VideoCapture" || type == "videoCapture")
{
tf.videoCount = devices->Size;
}
else if (type == "ImageScanner" || type == "imageScanner")
{
tf.scannerCount = devices->Size;
}
else if (type == "Location" || type == "location")
{
tf.locationCount = devices->Size;
}
else
{
//"Hey... You ever wonder why we're here?" - Simmons
//ERROR case, default to all
tf.installedDeviceCount = devices->Size;
}
//toss all detected devices into the list
for (unsigned int i = 0; i < devices->Size; i++)
{
//Variable Declaration
struct deviceStruct device;
//Create a device
device = buildDevice(devices->GetAt(i), deviceStructType);
//if necessary, build a storage device
if (deviceStructType == STORAGE_TYPE)
{
//build storage device
struct storageStruct storage = buildStorage(devices->GetAt(i), device);
//insert into storages
tf.storages.push_back(storage);
//set storage index of super
device.storageIndex = tf.storages.size() - 1;
}
//put device in detectedDevices
tf.detectedDevices.push_back(device);
if (deviceStructType == STORAGE_TYPE)
{
//synchronize the list nodes
tf.storages.back().superDevice = tf.detectedDevices.back();
tf.storages.back().deviceIndex = tf.detectedDevices.size() - 1;
}
}//END FOR
}//END produce device information
//produces device information for all types except the "all" filter
void produceDeviceTypesInformation(struct cylonStruct& tf)
{
//Grab collections and counts
produceDeviceTypeInformation(tf, "AudioCapture");
produceDeviceTypeInformation(tf, "AudioRender");
produceDeviceTypeInformation(tf, "Location");
produceDeviceTypeInformation(tf, "ImageScanner");
produceDeviceTypeInformation(tf, "VideoCapture");
produceDeviceTypeInformation(tf, "PortableStorageDevice");
//Grab primary display device
produceDisplayInformation(tf);
//Grab Keyboard, Mouse, Controllers
produceKeyboardInformation(tf);
produceMouseInformation(tf);
produceGamepadInformation(tf);
//Grab total count
tf.detectedDeviceCount = tf.detectedDevices.size();
}//END produce device types information
//produces the device and display structs for the primary monitor
void produceDisplayInformation(struct cylonStruct& tf)
{
//Variable Declaration
Windows::Graphics::Display::DisplayInformation^ displayInformation;
Windows::Devices::Enumeration::DeviceInformation^ deviceInfo;
struct displayStruct displayDevice;
struct deviceStruct superDevice;
//Build super
superDevice = buildDevice(deviceInfo, DISPLAY_TYPE);
//Grab display info
displayInformation = Windows::Graphics::Display::DisplayInformation::GetForCurrentView();
//Build display device
displayDevice = buildDisplay(superDevice, displayInformation);
//Insert super/parent into devices lists
tf.displayDevices.push_back(displayDevice);
displayDevice.superDevice.displayIndex = tf.displayDevices.size() - 1;
tf.detectedDevices.push_back(displayDevice.superDevice);
tf.displayDevices.back().superDevice = tf.detectedDevices.back();
tf.displayDevices.back().deviceIndex = tf.detectedDevices.size() - 1;
}//END produceDisplayInformation
//produces information about pointer devices
void produceMouseInformation(struct cylonStruct& tf)
{
//Variable Declaration
Windows::Devices::Input::MouseCapabilities mouseStats;
Windows::Devices::Enumeration::DeviceInformation^ deviceInfo;
struct deviceStruct mouse;
struct mouseStruct mice;
//check if mouse exists
if (mouseStats.MousePresent == 1)
{
//build device
mouse = buildDevice(deviceInfo, MOUSE_TYPE);
//insert mouse device into detectedDevices
tf.detectedDevices.push_back(mouse);
tf.mice.deviceIndex = tf.detectedDevices.size() - 1;
//Populate mice variables
if (mouseStats.HorizontalWheelPresent == 1)
{
tf.mice.anyHorizontalWheelPresent = true;
}
else
{
//error/invalid/unknown/not present
tf.mice.anyHorizontalWheelPresent = false;
}
if (mouseStats.VerticalWheelPresent == 1)
{
tf.mice.anyVerticalWheelPresent = true;
}
else
{
tf.mice.anyHorizontalWheelPresent = false;
}
if (mouseStats.SwapButtons == 1)
{
tf.mice.anyLeftRightSwapped = true;
}
else
{
tf.mice.anyLeftRightSwapped = false;
}
tf.mice.maxNumberOfButons = mouseStats.NumberOfButtons;
}
}
//create deviceStruct for keyboard
void produceKeyboardInformation(struct cylonStruct& tf)
{
//Variable Declaration
struct deviceStruct keyboard;
Windows::Devices::Enumeration::DeviceInformation^ deviceInfo;
Windows::Devices::Input::KeyboardCapabilities keyboardInfo;
//check if keyboard exists
//If keyboard exists
if (keyboardInfo.KeyboardPresent == 1)
{
//build device
keyboard = buildDevice(deviceInfo, KEYBOARD_TYPE);
//insert keyboard device into detectedDevices
tf.detectedDevices.push_back(keyboard);
}//END if
}
//end produce Keyboard information
//grabs information for (up to) 4 XInput controllers
//NOTE: can throw app-crashing exceptions when multiple gamepads are in use and disconnect in certain orders, use at your own risk!
void produceControllerInformation(struct cylonStruct& tf)
{
//Variable Declaration
DWORD result;
XINPUT_STATE state;
//for plays 0-maxPlayerCount
for (DWORD userIndex = 0; userIndex < XUSER_MAX_COUNT; userIndex++)
{
//zero memory
ZeroMemory(&state, sizeof(XINPUT_STATE));
//Get state of controller
result = XInputGetState(userIndex, &state);
if (result == ERROR_SUCCESS)
{
//build device struct
struct deviceStruct device = buildDevice(userIndex);
//build controller struct
struct controllerStruct controller = buildController(device, state, userIndex);
//insert into controllers
tf.controllers.push_back(controller);
//set controller index
controller.superDevice.controllerIndex = tf.controllers.size() - 1;
//insert into devices
tf.detectedDevices.push_back(controller.superDevice);
//sync lists
tf.controllers.back().superDevice = tf.detectedDevices.back();
tf.controllers.back().deviceIndex = tf.detectedDevices.size() - 1;
}//END If controller connected
}//END FOR
}//END produceControllerInfo
void produceGamepadInformation(struct cylonStruct& tf)
{
//Set State Trackers
gamepadState = STARTED;
presentGamepadsAdded = 0;
controllersPurged = false;
//Event handlers
Gamepad::GamepadAdded += ref new EventHandler<Gamepad^>(OnGamepadAdded);
Gamepad::GamepadRemoved += ref new EventHandler<Gamepad^>(OnGamepadRemoved);
for (uint32_t i = 0; i < Gamepad::Gamepads->Size; i++)
{
//GamepadReading
GamepadReading reading = Gamepad::Gamepads->GetAt(i)->GetCurrentReading();
//Build Device and Controller Structs
struct deviceStruct device = buildDevice(i);
struct controllerStruct controller = buildController(device, i, reading);
//insert into lists an dsync
tf.controllers.push_back(controller);
controller.superDevice.controllerIndex = tf.controllers.size() - 1;
tf.detectedDevices.push_back(controller.superDevice);
tf.controllers.back().superDevice = tf.detectedDevices.back();
tf.controllers.back().deviceIndex = tf.detectedDevices.size() - 1;
}//END for all gamepads
}//END produceGamepadInfo
//for logging
void produceLog(struct cylonStruct& tf)
{
std::wostringstream os_;
os_ << "Cylon @: " << &tf << endl
<< "Username: " << utf8_decode(tf.username) << endl
<< "Device Name: " << utf8_decode(tf.deviceName) << endl
<< "Timestamp: " << tf.day << ", " << tf.month << "/" << tf.day << "/" << tf.year << " " << tf.hours << ":" << tf.minutes << ":" << tf.seconds << ":" << tf.milliseconds << endl
<< "Profile Picture Location: " << hex<< tf.pictureLocation <<dec<< " Type: " << utf8_decode(tf.pictureType) << " Path: " << utf8_decode(tf.picturePath) << endl
<< "Processor Architecture: " << utf8_decode(tf.architecture) << endl
<< "Processor Count: " << tf.processorCount << endl
<< "Processor Level: " << tf.processorLevel << endl
<< "Processor Clock Speed: "<< tf.hertz<< "Hz" << endl
<< "OS Architecture: " << tf.osArchitecture << endl
<< "Total Memory: " << tf.memoryBytes << endl
<< "Available Memory: " << tf.bytesAvails << endl
<< "Low Memory Threshold: " << tf.threshold << endl
<< "Low Memory? " << tf.lowMemory << endl
<< "Page Size: " << tf.pageSize << endl
<< "Allocation Granularity: " << tf.allocationGranularity << endl
<< "Min/Max App Address: "<< tf.minAppAddress << "/" << tf.maxAppAddress << endl
<< "Detected Device Count: "<< tf.detectedDeviceCount << endl
<< "Error: " << tf.error <<endl<<endl
<< "Devices: "<<endl
;
for (list<deviceStruct>::const_iterator iterator = tf.detectedDevices.begin(), end = tf.detectedDevices.end(); iterator != end; ++iterator)
{
os_
<< "\t" << "Name: " << utf8_decode(iterator->name) << endl
<< "\t" << "Type: " << iterator->deviceType << endl
<< "\t" << "Vendor ID: " << endl
<< "\t" << "ID: " << utf8_decode(iterator->id_string) << endl
<< "\t" << "Orientation: " << iterator->orientation << endl
<< "\t" << "USB Bus: " << endl
<< "\t" << "UDev Device #: " << endl
<< "\t" << "Panel Location: " << iterator->panelLocation << endl
<< "\t" << "In Lid: " << iterator->inLid << endl
<< "\t" << "In Dock: " << iterator->inDock << endl
<< "\t" << "Is Default: " << iterator->isDefault <<endl
<< "\t" << "Is Enabled: " <<iterator->isEnabled <<endl
<< "\t" << "Controller Index: " << iterator->controllerIndex << endl
<< "\t" << "Storage Index: " << iterator->storageIndex << endl
<< "\t" << "Display Index: "<<iterator->displayIndex << endl
<<endl
;
}
os_ << endl << "Controllers: " << endl;
for (list<controllerStruct>::const_iterator iterator = tf.controllers.begin(), end = tf.controllers.end(); iterator != end; ++iterator)
{
os_
<< "\t" << "User Index: " << iterator->userIndex << endl
<< "\t" << "Packet Number: " << iterator->packetNumber<<endl
<< "\t" << "Left Trigger: " <<iterator->leftTrigger <<endl
<< "\t" << "Right Trigger: " << iterator->rightTrigger <<endl
<< "\t" << "Left Thumb X: " << iterator->thumbLeftX <<endl
<< "\t" << "Left Thumb Y: " << iterator->thumbLeftY <<endl
<< "\t" << "Right Thumb X: " << iterator->thumbRightX <<endl
<< "\t" << "Right Thumb Y: " << iterator->thumbRightY << endl
<< "\t" << "Buttons: " << hex<< iterator->buttons << dec<<endl
<< endl
;
}
os_ << endl << "Displays: " << endl;
for (list<displayStruct>::const_iterator iterator = tf.displayDevices.begin(), end = tf.displayDevices.end(); iterator != end; ++iterator)
{
os_
<< "\t" << "Rotation Preference: " << iterator->rotationPreference << endl
<< "\t" << "Current Rotation: " << iterator->currentRotation << endl
<< "\t" << "Native Rotation: " << iterator->nativeRotation << endl
<< "\t" << "Stereoscopic Enabled? " << iterator->isStereoscopicEnabled << endl
<< "\t" << "Resolution Scale: " << iterator->resolutionScale << endl
<< "\t" << "Logical DPI: " << iterator->logicalDPI << endl
<< "\t" << "Raw DPI X: " << iterator->rawDPIX << endl
<< "\t" << "Raw DPI Y: " << iterator->rawDPIY << endl
<< "\t" << "Color Profile Buffer Size: " << iterator->colorLength << endl
<< endl
;
}
os_ << "Mouse Stats: " << endl
<< "\t" << "Left/Right Swapped: " << tf.mice.anyLeftRightSwapped << endl
<< "\t" << "Vertical Wheel: " << tf.mice.anyVerticalWheelPresent << endl
<< "\t" << "Horizontal Wheel: " << tf.mice.anyHorizontalWheelPresent << endl
<< "\t" << "Button Count: " << tf.mice.maxNumberOfButons << endl;
OutputDebugStringW(os_.str().c_str());
}//END produceLog
//produce Tory
void produceTory(struct cylonStruct& tory)
{
//Clear pre-existing lists
tory.detectedDevices.clear();
tory.displayDevices.clear();
tory.controllers.clear();
//device name
produceDeviceName(tory);
//time zone
produceTimeZone(tory);
//date and timef
produceDateTime(tory);
//processor
produceProcessorInfo(tory);
//picture
produceAccountPicture(tory);
//devices
produceDeviceTypesInformation(tory);
//memory
produceMemoryInfo(tory);
//log - for debugging only
//produceLog(tory);
}
//end produce tory
//END producers
//Builders
//build Tory
struct cylonStruct buildTory()
{
//Variable Declartion
struct cylonStruct tory;
//device name
produceDeviceName(tory);
//time zone
produceTimeZone(tory);
//date and time
produceDateTime(tory);
//processor
produceProcessorInfo(tory);
//picture
produceAccountPicture(tory);
//devices
produceDeviceTypesInformation(tory);
//memory
produceMemoryInfo(tory);
//log - for debugging only
//produceLog(tory);
//return
return tory;
}
//end build tory
//build a storageStruct with given data
struct storageStruct buildStorage(Windows::Devices::Enumeration::DeviceInformation^ deviceInfo, struct deviceStruct superDevice)
{
//Variable declaration
struct storageStruct storage;
std::wstring error = L"0";
//Set parent paired deviceStruct
storage.superDevice = superDevice;
//TODO: remove this when restore proper path retrieval
storage.path = "0";
//get path
//TODO: try Ellen code as solution
//TOOD: Restore this somehow? Clearly have file in c:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\winrt\windows.devices.portable.h but compiler cannot resolve namespace
//NOTE: if not already noted in documentation, your package manifest requires access to Removable Storage for these next two lines to function!
//Windows::Storage::StorageFolder^ folder = Windows::Devices::Portable::StorageDevice::FromId(deviceInfo->Id);
//storage.path = utf8_encode(folder->Path->Data());
//set unavailable fields
storage.bytesAvails = 0;
storage.totalBytes = 0;
storage.isEmulated = 0;
//return struct
return storage;
}
//build a device struct with given data
struct deviceStruct buildDevice(Windows::Devices::Enumeration::DeviceInformation^ deviceInfo, unsigned int deviceType)
{
struct deviceStruct device;
std::wstring error = L"0";
//set device type
device.deviceType = deviceType;
//set unused fields
device.vendorID = 0;
//set to zero for now, modify later if necessary
device.displayIndex = 0;
device.controllerIndex = 0;
device.sensorsIndex = 0;
device.storageIndex = 0;
device.orientation = 0;
device.usb_bus = 0;
device.udev_deviceNumber = 0;
device.midiIndex = 0;
//get out for display/keyboard/mouse/controller devices, as they have different metadata than the regular kind we retrieve
if (device.deviceType == DISPLAY_TYPE || device.deviceType == KEYBOARD_TYPE || device.deviceType == MOUSE_TYPE || device.deviceType == CONTROLLER_TYPE)
{
//set errors/unknown values
device.name = utf8_encode(error);
device.id_string = utf8_encode(error);
device.id_int = 0;
device.inDock = false;
device.inLid = false;
device.panelLocation = 0;
//default these to true
device.isDefault = true;
device.isEnabled = true;
//return
return device;
}
//END if device is a special type
//Set device variables from DeviceInformation data
if (deviceInfo->Name->IsEmpty())
{
device.name = utf8_encode(error);
}
else
{
device.name = utf8_encode(deviceInfo->Name->Data());
}//END if Name Empty
if (deviceInfo->Id->IsEmpty())
{
device.id_string = utf8_encode(error);
device.id_int = 0;
}
else
{
device.id_string = utf8_encode(deviceInfo->Id->Data());
device.id_int = 0; //TODO: could make this a hash of the Data field used for id_string above?
}//END if ID Empty
if (deviceInfo->EnclosureLocation != nullptr)
{
if (deviceInfo->EnclosureLocation->InDock == true)
{
//if device is in docking station of computer
device.inDock = true;
}
else
{
//false or error
device.inDock = false;
}//END if inDock
if (deviceInfo->EnclosureLocation->InLid == true)
{
//if device is in the lid of the computer
device.inLid = true;
}
else
{
//false or error
device.inLid = false;
}//END if inLid
//set the panel location of the device (if available)
if (deviceInfo->EnclosureLocation->Panel.Equals(Windows::Devices::Enumeration::Panel::Top))
{
device.panelLocation = TOP_PANEL;
}
else if (deviceInfo->EnclosureLocation->Panel.Equals(Windows::Devices::Enumeration::Panel::Bottom))
{
device.panelLocation = BOTTOM_PANEL;
}
else if (deviceInfo->EnclosureLocation->Panel.Equals(Windows::Devices::Enumeration::Panel::Front))
{
device.panelLocation = FRONT_PANEL;
}
else if (deviceInfo->EnclosureLocation->Panel.Equals(Windows::Devices::Enumeration::Panel::Back))
{
device.panelLocation = BACK_PANEL;
}
else if (deviceInfo->EnclosureLocation->Panel.Equals(Windows::Devices::Enumeration::Panel::Left))
{
device.panelLocation = LEFT_PANEL;
}
else if (deviceInfo->EnclosureLocation->Panel.Equals(Windows::Devices::Enumeration::Panel::Right))
{
device.panelLocation = RIGHT_PANEL;
}
else
{
//unknown or error
device.panelLocation = UNKNOWN_PANEL_LOCATION;
}//END if panelLocation
}//end if enclosurelocation is null
else
{
//if enclosure is null
//errors for all because unknown/invalid/missing/empty