This repository has been archived by the owner on Jun 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ObsInfoPlugin.cpp
109 lines (82 loc) · 2.61 KB
/
ObsInfoPlugin.cpp
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
// ObsInfoPlugin.cpp : Defines the exported functions for the DLL application.
//
#include "ObsInfoPlugin.h"
#include "SettingsManager.h"
#include <string>
#include "OBSApi.h"
#include "Encoding.h"
void DumpStringToFile(std::wstring things) {
std::wstring fullpath = Settings()->AppDataPath + L"\\" + Settings()->FileName;
// check if file exists and append
FILE *fp = _wfopen(fullpath.c_str(), L"ab");
if (fp == NULL) {
// if it doesn't exist yet, create it through write
fp = _wfopen(fullpath.c_str(), L"wb");
}
if (fp != NULL)
{
// convert things to default windows codepage
std::string def = CEncoding::Wide2Default(things);
fprintf(fp, "%s\r\n", def.c_str());
fclose(fp);
}
else
{
// I don't even...
}
}
// convert milliseconds to hours:minutes:seconds, 0 leading on minutes and seconds, hours can be a lot
std::wstring MilliToHMSString(UINT time)
{
wchar_t s[1024];
uint32_t totalseconds = (uint32_t)trunc(time / 1000.0);
uint32_t hr = (uint32_t)trunc(totalseconds / 60.0 / 60.0);
uint32_t min = (uint32_t)trunc(totalseconds / 60.0) - (hr * 60);
uint32_t sec = totalseconds % 60;
wsprintf(s, Settings()->Format.c_str(), hr, min, sec);
return s;
}
void __stdcall HotKeyProc(DWORD a, UPARAM b, bool bDown) {
if (bDown)
{
// get total stream time till now and dump that into a file
UINT time = OBSGetTotalStreamTime();
DumpStringToFile(MilliToHMSString(time));
}
}
bool LoadPlugin() {
// intialization stuff when plugin "really" gets loaded - register hotkey in OBS and get the appdata path
Settings()->AppDataPath = OBSGetAppDataPath();
Settings()->IniFile = OBSGetPluginDataPath() + L"\\" + L"ObsInfo.ini";
// load from ini file if available
Settings()->Load();
Settings()->RegisteredHotKey = OBSCreateHotkey(Settings()->HotVKey, &HotKeyProc, 0);
return true;
}
void UnloadPlugin() {
UINT k = Settings()->RegisteredHotKey;
Settings()->RegisteredHotKey = 0;
OBSDeleteHotkey(k);
}
void OnStartStream() {
// might be useful to mark start and stops of older streams
DumpStringToFile(L"StartStream");
}
void OnStopStream() {
DumpStringToFile(L"StopStream");
}
CTSTR GetPluginName() {
return L"ObsInfoPlugin";
}
CTSTR GetPluginDescription() {
return L"ObsInfoPlugin does stuff when you press F12";
}
void ConfigPlugin(HWND hHandle) {
CSettingsForm frmSettings(hHandle, Settings()->Parent);
if (frmSettings.AskAndSetSettings())
{
Settings()->Save();
UnloadPlugin();
LoadPlugin();
}
}