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
|
#include "precomp__gen_ff.h"
#include "embedwndguid.h"
#include "wa2wndembed.h"
#include "wa2frontend.h"
#include "wa2cfgitems.h"
#include <bfc/string/stringW.h>
extern void initFFApi();
EmbedWndGuidMgr embedWndGuidMgr;
EmbedWndGuid::EmbedWndGuid(embedWindowState *_ws)
{
hwnd = NULL;
guid = INVALID_GUID;
if (_ws == NULL) return ;
ws = _ws;
hwnd = ws->me;
embedWndGuidMgr.getGuid(this);
}
EmbedWndGuid::EmbedWndGuid(EmbedWndGuid *wg)
{
hwnd = NULL;
guid = INVALID_GUID;
if (wg == NULL) return ;
ws = wg->getEmbedWindowState();
hwnd = ws->me;
guid = wg->getGuid();
}
GUID EmbedWndGuidMgr::getGuid(embedWindowState *ws)
{
foreach(table)
EmbedWndGuid *ewg = table.getfor();
if (ewg->getEmbedWindowState() == ws)
{
return ewg->getGuid();
}
endfor;
return INVALID_GUID;
}
GUID EmbedWndGuidMgr::getGuid(EmbedWndGuid *wg)
{
if (wg == NULL) return INVALID_GUID;
// if we aren't loaded yet, init wasabi, otherwise ignore
initFFApi();
int gotit = 0;
int nowrite = 0;
wchar_t windowTitle[256] = L"";
HWND child;
GUID newGuid = INVALID_GUID;
if (wg->getEmbedWindowState()->flags & EMBED_FLAGS_GUID)
{
newGuid = GET_EMBED_GUID(wg->getEmbedWindowState());
nowrite=1;
goto bypass;
}
if (wa2.isVis(wg->getEmbedWindowState()->me))
{
newGuid = avs_guid;
nowrite = 1;
extern int disable_send_visrandom;
extern _bool visrandom;
wa2.pollVisRandom();
goto bypass;
}
child = GetWindow(wg->getEmbedWindowState()->me, GW_CHILD);
if (child == wa2.getMediaLibrary())
{ newGuid = library_guid; nowrite = 1; goto bypass; }
if (!gotit)
{
foreach(table)
EmbedWndGuid *ewg = table.getfor();
if (ewg->getEmbedWindowState() == wg->getEmbedWindowState())
{
wg->setGuid(ewg->getGuid());
gotit = 1;
break;
}
endfor;
}
if (!gotit)
{
// not found, look for window title in saved table
GetWindowTextW(wg->getEmbedWindowState()->me, windowTitle, 256);
if (*windowTitle)
{
wchar_t str[256] = L"";
StringW configString = windowTitle;
configString += L"_guid";
WASABI_API_CONFIG->getStringPrivate(configString, str, 256, L"");
if (*str)
{
wg->setGuid(nsGUID::fromCharW(str));
table.addItem(new EmbedWndGuid(wg));
gotit = 1;
}
}
}
if (!gotit)
{
// not found in saved table, or no title for the window, assign a new guid
if (!_wcsicmp(windowTitle, L"AVS"))
{ newGuid = avs_guid; nowrite = 1; }
else
CoCreateGuid(&newGuid);
bypass:
wg->setGuid(newGuid);
// save a copy of the element
table.addItem(new EmbedWndGuid(wg));
// write the guid in the saved table
if (*windowTitle && !nowrite)
{
wchar_t str[256] = {0};
nsGUID::toCharW(newGuid, str);
StringW configString = windowTitle;
configString += L"_guid";
WASABI_API_CONFIG->setStringPrivate(configString, str);
}
}
return wg->getGuid();
}
embedWindowState *EmbedWndGuidMgr::getEmbedWindowState(GUID g)
{
foreach(table)
EmbedWndGuid *ewg = table.getfor();
if (ewg->getGuid() == g)
{
embedWindowState *ews = ewg->getEmbedWindowState();
if (wa2.isValidEmbedWndState(ews))
return ews;
}
endfor;
return NULL;
}
void EmbedWndGuidMgr::retireEmbedWindowState(embedWindowState *ws)
{
foreach(table)
EmbedWndGuid *ewg = table.getfor();
if (ewg->getEmbedWindowState() == ws)
{
delete table.getfor();
table.removeByPos(foreach_index);
break;
}
endfor;
}
int EmbedWndGuidMgr::testGuid(GUID g)
{
// if (g == library_guid) return 1;
// if (g == avs_guid) return 1;
foreach(table)
EmbedWndGuid *ewg = table.getfor();
if (ewg->getGuid() == g)
{
if (!wa2.isValidEmbedWndState(ewg->getEmbedWindowState())) retireEmbedWindowState(ewg->getEmbedWindowState());
else return 1;
}
endfor;
return 0;
}
int EmbedWndGuidMgr::getNumWindowStates()
{
return table.getNumItems();
}
GUID EmbedWndGuidMgr::enumWindowState(int n, embedWindowState **ws)
{
EmbedWndGuid *ewg = table.enumItem(n);
if (ewg)
{
embedWindowState *ews = ewg->getEmbedWindowState();
if (wa2.isValidEmbedWndState(ews))
{
if (ws) *ws = ews;
return ewg->getGuid();
}
}
return INVALID_GUID;
}
|