This repository has been archived by the owner on Apr 15, 2023. It is now read-only.
/
AddonDatabase.cpp
713 lines (640 loc) · 20.9 KB
/
AddonDatabase.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
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
/*
* Copyright (C) 2005-2010 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#include "AddonDatabase.h"
#include "addons/AddonManager.h"
#include "utils/log.h"
#include "DateTime.h"
#include "StringUtils.h"
#include "addons/Service.h"
using namespace ADDON;
using namespace std;
CAddonDatabase::CAddonDatabase()
{
}
CAddonDatabase::~CAddonDatabase()
{
}
bool CAddonDatabase::Open()
{
return CDatabase::Open();
}
bool CAddonDatabase::CreateTables()
{
try
{
CDatabase::CreateTables();
CLog::Log(LOGINFO, "create addon table");
m_pDS->exec("CREATE TABLE addon (id integer primary key, type text,"
"name text, summary text, description text, stars integer,"
"path text, addonID text, icon text, version text, "
"changelog text, fanart text, author text, disclaimer text)\n");
CLog::Log(LOGINFO, "create addon index");
m_pDS->exec("CREATE INDEX idxAddon ON addon(addonID)");
CLog::Log(LOGINFO, "create addonextra table");
m_pDS->exec("CREATE TABLE addonextra (id integer, key text, value text)\n");
CLog::Log(LOGINFO, "create addonextra index");
m_pDS->exec("CREATE INDEX idxAddonExtra ON addonextra(id)");
CLog::Log(LOGINFO, "create repo table");
m_pDS->exec("CREATE TABLE repo (id integer primary key, addonID text,"
"checksum text, lastcheck text)\n");
CLog::Log(LOGINFO, "create addonlinkrepo table");
m_pDS->exec("CREATE TABLE addonlinkrepo (idRepo integer, idAddon integer)\n");
m_pDS->exec("CREATE UNIQUE INDEX ix_addonlinkrepo_1 ON addonlinkrepo ( idAddon, idRepo )\n");
m_pDS->exec("CREATE UNIQUE INDEX ix_addonlinkrepo_2 ON addonlinkrepo ( idRepo, idAddon )\n");
CLog::Log(LOGINFO, "create disabled table");
m_pDS->exec("CREATE TABLE disabled (id integer primary key, addonID text)\n");
m_pDS->exec("CREATE UNIQUE INDEX idxDisabled ON disabled(addonID)");
CLog::Log(LOGINFO, "create broken table");
m_pDS->exec("CREATE TABLE broken (id integer primary key, addonID text, reason text)\n");
m_pDS->exec("CREATE UNIQUE INDEX idxBroken ON broken(addonID)");
}
catch (...)
{
CLog::Log(LOGERROR, "%s unable to create tables", __FUNCTION__);
return false;
}
return true;
}
bool CAddonDatabase::UpdateOldVersion(int version)
{
BeginTransaction();
try
{
if (version < 2)
{
m_pDS->exec("alter table addon add description text");
}
if (version < 3)
{
m_pDS->exec("alter table addon add changelog text");
}
if (version < 4)
{
m_pDS->exec("alter table addon add fanart text");
}
if (version < 5)
{
m_pDS->exec("alter table addon add author text");
}
if (version < 6)
{
m_pDS->exec("alter table addon add content text");
}
if (version < 7)
{
m_pDS->exec("CREATE TABLE addonnew (id integer primary key, type text,"
"name text, summary text, description text, stars integer,"
"path text, addonID text, icon text, version text, "
"changelog text, fanart text, author text)\n");
m_pDS->exec("INSERT INTO addonnew select id,type,name,summary,description,stars,path,addonID,icon,version,changelog,fanart,author from addon");
m_pDS->exec("DROP TABLE addon");
m_pDS->exec("ALTER TABLE addonnew RENAME TO addon");
}
if (version < 8)
{
m_pDS->exec("CREATE TABLE disabled (id integer primary key, addonID text)\n");
m_pDS->exec("CREATE INDEX idxDisabled ON disabled(addonID)");
}
if (version < 9)
{
m_pDS->exec("CREATE UNIQUE INDEX ix_addonlinkrepo_1 ON addonlinkrepo ( idAddon, idRepo )\n");
m_pDS->exec("CREATE UNIQUE INDEX ix_addonlinkrepo_2 ON addonlinkrepo ( idRepo, idAddon )\n");
m_pDS->exec("DROP INDEX idxDisabled");
m_pDS->exec("CREATE UNIQUE INDEX idxDisabled ON disabled(addonID)");
}
if (version < 10)
{
m_pDS->exec("CREATE TABLE broken (id integer primary key, addonID text, reason text)\n");
m_pDS->exec("CREATE UNIQUE INDEX idxBroken ON broken(addonID)");
}
if (version < 11)
{
m_pDS->exec("CREATE TABLE addonextra (id integer, key text, value text)\n");
m_pDS->exec("CREATE INDEX idxAddonExtra ON addonextra(id)");
}
if (version < 12)
{
m_pDS->exec("alter table addon add disclaimer text");
}
}
catch (...)
{
CLog::Log(LOGERROR, "Error attempting to upgrade an old addon database!");
RollbackTransaction();
return false;
}
CommitTransaction();
return true;
}
int CAddonDatabase::AddAddon(const AddonPtr& addon,
int idRepo)
{
try
{
if (NULL == m_pDB.get()) return -1;
if (NULL == m_pDS.get()) return -1;
CStdString sql = PrepareSQL("insert into addon (id, type, name, summary,"
"description, stars, path, icon, changelog, "
"fanart, addonID, version, author, disclaimer)"
" values(NULL, '%s', '%s', '%s', '%s', %i,"
"'%s', '%s', '%s', '%s', '%s','%s','%s','%s')",
TranslateType(addon->Type(),false).c_str(),
addon->Name().c_str(), addon->Summary().c_str(),
addon->Description().c_str(),addon->Stars(),
addon->Path().c_str(), addon->Props().icon.c_str(),
addon->ChangeLog().c_str(),addon->FanArt().c_str(),
addon->ID().c_str(), addon->Version().str.c_str(),
addon->Author().c_str(),addon->Disclaimer().c_str());
m_pDS->exec(sql.c_str());
int idAddon = (int)m_pDS->lastinsertid();
sql = PrepareSQL("insert into addonlinkrepo (idRepo, idAddon) values (%i,%i)",idRepo,idAddon);
m_pDS->exec(sql.c_str());
const InfoMap &info = addon->ExtraInfo();
for (InfoMap::const_iterator i = info.begin(); i != info.end(); ++i)
{
sql = PrepareSQL("insert into addonextra(id, key, value) values (%i, '%s', '%s')", idAddon, i->first.c_str(), i->second.c_str());
m_pDS->exec(sql.c_str());
}
return idAddon;
}
catch (...)
{
CLog::Log(LOGERROR, "%s failed on addon '%s'", __FUNCTION__, addon->Name().c_str());
}
return -1;
}
bool CAddonDatabase::GetAddon(const CStdString& id, AddonPtr& addon)
{
try
{
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS2.get()) return false;
CStdString sql = PrepareSQL("select id from addon where addonID='%s' order by version desc",id.c_str());
m_pDS2->query(sql.c_str());
if (!m_pDS2->eof())
return GetAddon(m_pDS2->fv(0).get_asInt(),addon);
}
catch (...)
{
CLog::Log(LOGERROR, "%s failed on addon %s", __FUNCTION__, id.c_str());
}
addon.reset();
return false;
}
bool CAddonDatabase::GetRepoForAddon(const CStdString& addonID, CStdString& repo)
{
try
{
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS2.get()) return false;
CStdString sql = PrepareSQL("select repo.addonID from repo join addonlinkrepo on repo.id=addonlinkrepo.idRepo join addon on addonlinkrepo.idAddon=addon.id where addon.addonID like '%s'", addonID.c_str());
m_pDS2->query(sql.c_str());
if (!m_pDS2->eof())
{
repo = m_pDS2->fv(0).get_asString();
m_pDS2->close();
return true;
}
}
catch (...)
{
CLog::Log(LOGERROR, "%s failed for addon %s", __FUNCTION__, addonID.c_str());
}
return false;
}
bool CAddonDatabase::GetAddon(int id, AddonPtr& addon)
{
try
{
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS2.get()) return false;
CStdString sql = PrepareSQL("select * from addon where id=%i",id);
m_pDS2->query(sql.c_str());
if (!m_pDS2->eof())
{
AddonProps props(m_pDS2->fv("addonID" ).get_asString(),
TranslateType(m_pDS2->fv("type").get_asString()),
m_pDS2->fv("version").get_asString());
props.name = m_pDS2->fv("name").get_asString();
props.summary = m_pDS2->fv("summary").get_asString();
props.description = m_pDS2->fv("description").get_asString();
props.changelog = m_pDS2->fv("changelog").get_asString();
props.path = m_pDS2->fv("path").get_asString();
props.icon = m_pDS2->fv("icon").get_asString();
props.fanart = m_pDS2->fv("fanart").get_asString();
props.author = m_pDS2->fv("author").get_asString();
props.disclaimer = m_pDS2->fv("disclaimer").get_asString();
sql = PrepareSQL("select reason from broken where addonID='%s'",props.id.c_str());
m_pDS2->query(sql.c_str());
if (!m_pDS2->eof())
props.broken = m_pDS2->fv(0).get_asString();
sql = PrepareSQL("select key,value from addonextra where id=%i", id);
m_pDS2->query(sql.c_str());
while (!m_pDS2->eof())
{
props.extrainfo.insert(make_pair(m_pDS2->fv(0).get_asString(), m_pDS2->fv(1).get_asString()));
m_pDS2->next();
}
addon = CAddonMgr::AddonFromProps(props);
return NULL != addon.get();
}
}
catch (...)
{
CLog::Log(LOGERROR, "%s failed on addon %i", __FUNCTION__, id);
}
addon.reset();
return false;
}
bool CAddonDatabase::GetAddons(VECADDONS& addons)
{
try
{
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS2.get()) return false;
CStdString sql = PrepareSQL("select distinct addonID from addon");
m_pDS->query(sql.c_str());
while (!m_pDS->eof())
{
sql = PrepareSQL("select id from addon where addonID='%s' order by version desc",m_pDS->fv(0).get_asString().c_str());
m_pDS2->query(sql.c_str());
AddonPtr addon;
if (GetAddon(m_pDS2->fv(0).get_asInt(),addon))
addons.push_back(addon);
m_pDS->next();
}
m_pDS->close();
return true;
}
catch (...)
{
CLog::Log(LOGERROR, "%s failed", __FUNCTION__);
}
return false;
}
void CAddonDatabase::DeleteRepository(const CStdString& id)
{
try
{
if (NULL == m_pDB.get()) return;
if (NULL == m_pDS.get()) return;
CStdString sql = PrepareSQL("select id from repo where addonID='%s'",id.c_str());
m_pDS->query(sql.c_str());
if (!m_pDS->eof())
DeleteRepository(m_pDS->fv(0).get_asInt());
}
catch (...)
{
CLog::Log(LOGERROR, "%s failed on repo '%s'", __FUNCTION__, id.c_str());
}
}
void CAddonDatabase::DeleteRepository(int idRepo)
{
try
{
if (NULL == m_pDB.get()) return;
if (NULL == m_pDS.get()) return;
CStdString sql = PrepareSQL("delete from repo where id=%i",idRepo);
m_pDS->exec(sql.c_str());
sql = PrepareSQL("delete from addon where id in (select idAddon from addonlinkrepo where idRepo=%i)",idRepo);
m_pDS->exec(sql.c_str());
sql = PrepareSQL("delete from addonextra where id in (select idAddon from addonlinkrepo where idRepo=%i)",idRepo);
m_pDS->exec(sql.c_str());
sql = PrepareSQL("delete from addonlinkrepo where idRepo=%i",idRepo);
m_pDS->exec(sql.c_str());
}
catch (...)
{
CLog::Log(LOGERROR, "%s failed on repo %i", __FUNCTION__, idRepo);
}
}
int CAddonDatabase::AddRepository(const CStdString& id, const VECADDONS& addons, const CStdString& checksum)
{
try
{
if (NULL == m_pDB.get()) return -1;
if (NULL == m_pDS.get()) return -1;
CStdString sql;
int idRepo = GetRepoChecksum(id,sql);
if (idRepo > -1)
DeleteRepository(idRepo);
BeginTransaction();
CDateTime time = CDateTime::GetCurrentDateTime();
sql = PrepareSQL("insert into repo (id,addonID,checksum,lastcheck) values (NULL,'%s','%s','%s')",id.c_str(),checksum.c_str(),time.GetAsDBDateTime().c_str());
m_pDS->exec(sql.c_str());
idRepo = (int)m_pDS->lastinsertid();
for (unsigned int i=0;i<addons.size();++i)
AddAddon(addons[i],idRepo);
CommitTransaction();
return idRepo;
}
catch (...)
{
CLog::Log(LOGERROR, "%s failed on repo '%s'", __FUNCTION__, id.c_str());
RollbackTransaction();
}
return -1;
}
int CAddonDatabase::GetRepoChecksum(const CStdString& id, CStdString& checksum)
{
try
{
if (NULL == m_pDB.get()) return -1;
if (NULL == m_pDS.get()) return -1;
CStdString strSQL = PrepareSQL("select * from repo where addonID='%s'",id.c_str());
m_pDS->query(strSQL.c_str());
if (!m_pDS->eof())
{
checksum = m_pDS->fv("checksum").get_asString();
return m_pDS->fv("id").get_asInt();
}
}
catch (...)
{
CLog::Log(LOGERROR, "%s failed on repo '%s'", __FUNCTION__, id.c_str());
}
checksum.Empty();
return -1;
}
CDateTime CAddonDatabase::GetRepoTimestamp(const CStdString& id)
{
CDateTime date;
try
{
if (NULL == m_pDB.get()) return date;
if (NULL == m_pDS.get()) return date;
CStdString strSQL = PrepareSQL("select * from repo where addonID='%s'",id.c_str());
m_pDS->query(strSQL.c_str());
if (!m_pDS->eof())
{
date.SetFromDBDateTime(m_pDS->fv("lastcheck").get_asString());
return date;
}
}
catch (...)
{
CLog::Log(LOGERROR, "%s failed on repo '%s'", __FUNCTION__, id.c_str());
}
return date;
}
bool CAddonDatabase::SetRepoTimestamp(const CStdString& id, const CStdString& time)
{
try
{
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS.get()) return false;
CStdString sql = PrepareSQL("update repo set lastcheck='%s' where addonID='%s'",time.c_str(),id.c_str());
m_pDS->exec(sql.c_str());
return true;
}
catch (...)
{
CLog::Log(LOGERROR, "%s failed on repo '%s'", __FUNCTION__, id.c_str());
}
return false;
}
bool CAddonDatabase::GetRepository(int id, VECADDONS& addons)
{
try
{
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS.get()) return false;
CStdString strSQL = PrepareSQL("select * from addonlinkrepo where idRepo=%i",id);
m_pDS->query(strSQL.c_str());
while (!m_pDS->eof())
{
AddonPtr addon;
if (GetAddon(m_pDS->fv("idAddon").get_asInt(),addon))
addons.push_back(addon);
m_pDS->next();
}
return true;
}
catch (...)
{
CLog::Log(LOGERROR, "%s failed on repo %i", __FUNCTION__, id);
}
return false;
}
bool CAddonDatabase::GetRepository(const CStdString& id, VECADDONS& addons)
{
try
{
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS.get()) return false;
CStdString strSQL = PrepareSQL("select id from repo where addonID='%s'",id.c_str());
m_pDS->query(strSQL.c_str());
if (!m_pDS->eof())
return GetRepository(m_pDS->fv(0).get_asInt(),addons);
}
catch (...)
{
CLog::Log(LOGERROR, "%s failed on repo %s", __FUNCTION__, id.c_str());
}
return false;
}
bool CAddonDatabase::Search(const CStdString& search, VECADDONS& items)
{
// first grab all the addons that match
SearchTitle(search,items);
return true;
}
bool CAddonDatabase::SearchTitle(const CStdString& search, VECADDONS& addons)
{
try
{
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS.get()) return false;
CStdString strSQL;
strSQL=PrepareSQL("select idAddon from addon where name like '%s%%'", search.c_str());
if (!m_pDS->query(strSQL.c_str())) return false;
if (m_pDS->num_rows() == 0) return false;
while (!m_pDS->eof())
{
AddonPtr addon;
GetAddon(m_pDS->fv(0).get_asInt(),addon);
if (addon->Type() >= ADDON_UNKNOWN+1 && addon->Type() < ADDON_SCRAPER_LIBRARY)
addons.push_back(addon);
m_pDS->next();
}
m_pDS->close();
return true;
}
catch (...)
{
CLog::Log(LOGERROR, "%s failed", __FUNCTION__);
}
return false;
}
void CAddonDatabase::SetPropertiesFromAddon(const AddonPtr& addon,
CFileItemPtr& pItem)
{
pItem->SetProperty("Addon.ID", addon->ID());
pItem->SetProperty("Addon.Type", TranslateType(addon->Type(),true));
pItem->SetProperty("Addon.intType", TranslateType(addon->Type()));
pItem->SetProperty("Addon.Name", addon->Name());
pItem->SetProperty("Addon.Version", addon->Version().str);
pItem->SetProperty("Addon.Summary", addon->Summary());
pItem->SetProperty("Addon.Description", addon->Description());
pItem->SetProperty("Addon.Creator", addon->Author());
pItem->SetProperty("Addon.Disclaimer", addon->Disclaimer());
pItem->SetProperty("Addon.Rating", addon->Stars());
CStdString starrating;
starrating.Format("rating%d.png", addon->Stars());
pItem->SetProperty("Addon.StarRating",starrating);
pItem->SetProperty("Addon.Path", addon->Path());
pItem->SetProperty("Addon.Broken", addon->Props().broken);
}
bool CAddonDatabase::DisableAddon(const CStdString &addonID, bool disable /* = true */)
{
try
{
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS.get()) return false;
if (disable)
{
CStdString sql = PrepareSQL("select id from disabled where addonID='%s'", addonID.c_str());
m_pDS->query(sql.c_str());
if (m_pDS->eof()) // not found
{
m_pDS->close();
sql = PrepareSQL("insert into disabled(id, addonID) values(NULL, '%s')", addonID.c_str());
m_pDS->exec(sql);
AddonPtr addon;
// If the addon is a service, stop it
if (CAddonMgr::Get().GetAddon(addonID, addon, ADDON_SERVICE, false) && addon)
{
boost::shared_ptr<CService> service = boost::dynamic_pointer_cast<CService>(addon);
if (service)
service->Stop();
}
return true;
}
return false; // already disabled or failed query
}
else
{
CStdString sql = PrepareSQL("delete from disabled where addonID='%s'", addonID.c_str());
m_pDS->exec(sql);
AddonPtr addon;
// If the addon is a service, start it
if (CAddonMgr::Get().GetAddon(addonID, addon, ADDON_SERVICE, false) && addon)
{
boost::shared_ptr<CService> service = boost::dynamic_pointer_cast<CService>(addon);
if (service)
service->Start();
}
}
return true;
}
catch (...)
{
CLog::Log(LOGERROR, "%s failed on addon '%s'", __FUNCTION__, addonID.c_str());
}
return false;
}
bool CAddonDatabase::BreakAddon(const CStdString &addonID, bool broken /* = true */, const CStdString& reason)
{
try
{
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS.get()) return false;
if (broken)
{
CStdString sql = PrepareSQL("select id from broken where addonID='%s'", addonID.c_str());
m_pDS->query(sql.c_str());
if (m_pDS->eof()) // not found
{
m_pDS->close();
sql = PrepareSQL("insert into broken(id, addonID, reason) values(NULL, '%s', '%s')", addonID.c_str(),reason.c_str());
m_pDS->exec(sql);
return true;
}
return false; // already disabled or failed query
}
else
{
CStdString sql = PrepareSQL("delete from broken where addonID='%s'", addonID.c_str());
m_pDS->exec(sql);
}
return true;
}
catch (...)
{
CLog::Log(LOGERROR, "%s failed on addon '%s'", __FUNCTION__, addonID.c_str());
}
return false;
}
bool CAddonDatabase::IsAddonDisabled(const CStdString &addonID)
{
try
{
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS.get()) return false;
CStdString sql = PrepareSQL("select id from disabled where addonID='%s'", addonID.c_str());
m_pDS->query(sql.c_str());
bool ret = !m_pDS->eof(); // in the disabled table -> disabled
m_pDS->close();
return ret;
}
catch (...)
{
CLog::Log(LOGERROR, "%s failed on addon %s", __FUNCTION__, addonID.c_str());
}
return false;
}
CStdString CAddonDatabase::IsAddonBroken(const CStdString &addonID)
{
try
{
if (NULL == m_pDB.get()) return "";
if (NULL == m_pDS.get()) return "";
CStdString sql = PrepareSQL("select reason from broken where addonID='%s'", addonID.c_str());
m_pDS->query(sql.c_str());
CStdString ret;
if (!m_pDS->eof())
ret = m_pDS->fv(0).get_asString();
m_pDS->close();
return ret;
}
catch (...)
{
CLog::Log(LOGERROR, "%s failed on addon %s", __FUNCTION__, addonID.c_str());
}
return "";
}
bool CAddonDatabase::HasDisabledAddons()
{
try
{
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS.get()) return false;
m_pDS->query("select count(id) from disabled");
bool ret = !m_pDS->eof() && m_pDS->fv(0).get_asInt() > 0; // have rows -> have disabled addons
m_pDS->close();
return ret;
}
catch (...)
{
CLog::Log(LOGERROR, "%s failed", __FUNCTION__);
}
return false;
}