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
|
#include "main.h"
#include "./enumIniFile.h"
#include "./service.h"
#include "./ifc_omservicehost.h"
#include "./ifc_omstorage.h"
#include "./ifc_omstoragehandlerenum.h"
#include "./ifc_omstorageext.h"
#include "./ifc_omfilestorage.h"
#include <shlwapi.h>
#include <strsafe.h>
#define OMS_GROUP "OnlineService"
#define OMS_ID "id"
#define OMS_NAME "name"
#define OMS_URL "url"
#define OMS_ICON "icon"
#define OMS_FLAGS "flags"
#define OMS_RATING "rating"
#define OMS_VERSION "version"
#define OMS_DESCRIPTION "description"
#define OMS_AUTHORFIRST "authorFirst"
#define OMS_AUTHORLAST "authorLast"
#define OMS_PUBLISHED "publishedDate"
#define OMS_UPDATED "updatedDate"
#define OMS_THUMBNAIL "thumbnail"
#define OMS_SCREENSHOT "screenshot"
#define OMS_GENERATION "generation"
EnumIniFile::EnumIniFile(LPCWSTR pszAddress, ifc_omservicehost *serviceHost)
: ref(1), address(NULL), host(serviceHost), hFind(NULL)
{
address = Plugin_CopyString(pszAddress);
if (NULL != host)
{
host->AddRef();
ifc_omstorageext *storageExt = NULL;
if (SUCCEEDED(host->QueryInterface(IFC_OmStorageExt, (void**)&storageExt)) && storageExt != NULL)
{
ifc_omstoragehandlerenum *handlerEnum = NULL;
if (SUCCEEDED(storageExt->Enumerate(&SUID_OmStorageIni, &handlerEnum)) && handlerEnum != NULL)
{
reader.RegisterHandlers(handlerEnum);
handlerEnum->Release();
}
storageExt->Release();
}
}
}
EnumIniFile::~EnumIniFile()
{
Plugin_FreeString(address);
if (NULL != host)
host->Release();
if (NULL != hFind)
FindClose(hFind);
}
HRESULT EnumIniFile::CreateInstance(LPCWSTR pszAddress, ifc_omservicehost *host, EnumIniFile **instance)
{
if (NULL == instance)
return E_POINTER;
WCHAR szBuffer[MAX_PATH * 2] = {0};
HRESULT hr = Plugin_ResolveRelativePath(pszAddress, host, szBuffer, ARRAYSIZE(szBuffer));
if (FAILED(hr)) return hr;
// test if we can load this one
if (FALSE == PathIsDirectory(szBuffer) && PathFileExists(szBuffer))
{
UINT id = GetPrivateProfileInt(TEXT(OMS_GROUP), WTEXT(OMS_ID), 0, pszAddress);
if (0 == id) return OMSTORAGE_E_UNKNOWN_FORMAT;
}
*instance = new EnumIniFile(szBuffer, host);
if (NULL == *instance) return E_OUTOFMEMORY;
return S_OK;
}
size_t EnumIniFile::AddRef()
{
return InterlockedIncrement((LONG*)&ref);
}
size_t EnumIniFile::Release()
{
if (0 == ref)
return ref;
LONG r = InterlockedDecrement((LONG*)&ref);
if (0 == r)
delete(this);
return r;
}
int EnumIniFile::QueryInterface(GUID interface_guid, void **object)
{
if (NULL == object) return E_POINTER;
if (IsEqualIID(interface_guid, IFC_OmServiceEnum))
*object = static_cast<ifc_omserviceenum*>(this);
else
{
*object = NULL;
return E_NOINTERFACE;
}
if (NULL == *object)
return E_UNEXPECTED;
AddRef();
return S_OK;
}
HRESULT EnumIniFile::Next(ULONG listSize, ifc_omservice **elementList, ULONG *elementCount)
{
if(NULL != elementCount)
*elementCount = 0;
if (0 == listSize || NULL == elementList)
return E_INVALIDARG;
ULONG counter = 0;
BOOL bFoundNext = FALSE;
HRESULT hr = S_OK;
if (NULL == hFind)
{
hFind = FindFirstFile(address, &fData);
if (INVALID_HANDLE_VALUE == hFind)
{
DWORD error = GetLastError();
return HRESULT_FROM_WIN32(error);
}
bFoundNext = TRUE;
}
else
{
bFoundNext = FindNextFile(hFind, &fData);
}
if (bFoundNext)
{
do
{
LPCWSTR p = address;
while(p && L'.' == *p && L'\0' != *p) p++;
if (p && L'\0' != *p)
{
WCHAR base[MAX_PATH] = {0};
StringCchCopy(base, MAX_PATH, address);
PathRemoveFileSpec(base);
int baseLen = lstrlen(base);
base[baseLen] = L'\0';
if (!PathAppend(base, fData.cFileName))
{
base[baseLen] = L'\0';
PathAppend(base, fData.cAlternateFileName);
}
hr = reader.Load(base, host, &elementList[counter]);
if (S_OK == hr)
{
listSize--;
counter++;
if (0 == listSize) break;
}
}
bFoundNext = FindNextFile(hFind, &fData);
} while(bFoundNext);
}
if(NULL != elementCount)
*elementCount = counter;
return (counter > 0) ? S_OK : S_FALSE;
}
HRESULT EnumIniFile::Reset(void)
{
if (NULL != hFind)
{
FindClose(hFind);
hFind = NULL;
}
return S_OK;
}
HRESULT EnumIniFile::Skip(ULONG elementCount)
{
return E_NOTIMPL;
}
#define CBCLASS EnumIniFile
START_DISPATCH;
CB(ADDREF, AddRef)
CB(RELEASE, Release)
CB(QUERYINTERFACE, QueryInterface)
CB(API_NEXT, Next)
CB(API_RESET, Reset)
CB(API_SKIP, Skip)
END_DISPATCH;
#undef CBCLASS
|