📄 sc.c
字号:
/* * Softcam plugin to VDR (C++) * * This code 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 * of the License, or (at your option) any later version. * * This code 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Or, point your browser to http://www.gnu.org/copyleft/gpl.html */#include <malloc.h>#include <stdlib.h>#include <getopt.h>#include <typeinfo>#ifndef STATICBUILD#include <dlfcn.h>#include <dirent.h>#include <fnmatch.h>#endif#include <vdr/plugin.h>#include <vdr/menuitems.h>#include <vdr/status.h>#include <vdr/dvbdevice.h>#include <vdr/channels.h>#include <vdr/ci.h>#include <vdr/interface.h>#include <vdr/menu.h>#include <vdr/tools.h>#include <vdr/config.h>#include "sc.h"#include "scsetup.h"#include "filter.h"#include "system.h"#include "cam.h"#include "smartcard.h"#include "data.h"#include "network.h"#include "misc.h"#include "opts.h"#include "i18n.h"#include "log-core.h"#include "version.h"#define MIN_VERS 1 // required VDR version#define MIN_MAJOR 4#define MIN_MINOR 6#define MINAPIVERSNUM 10405// some sanity checks#ifdef HAVE_SOFTCSA#error softcsa/ffdecsa patch MUST NOT be applied. Next time read the README first.#endif#if APIVERSNUM >= 10500#ifdef VDR_IS_SC_PATCHED#error You MUST NOT patch the VDR core. Next time read the README first.#endif#else //APIVERSNUM >= 10500#if !defined(VDR_IS_SC_PATCHED)#error You MUST patch the VDR core with the supplied patch. Next time read the README first.#endif#if VDR_IS_SC_PATCHED<402#error Your VDR core is patched with an outdated patch version. Please upgrade to the supplied version.#endif#endif //APIVERSNUM >= 10500#if APIVERSNUM<MINAPIVERSNUM#error Your VDR API version is too old. See README.#endif// SC API version number for loading shared libraries#define SCAPIVERS 8const char *ScVersion = SCVERSION;static cPlugin *ScPlugin;static cOpts *ScOpts, *LogOpts;static const struct LogModule lm_core = { (LMOD_ENABLE|L_CORE_ALL)&LOPT_MASK, (LMOD_ENABLE|L_CORE_LOAD|L_CORE_ECM|L_CORE_PIDS|L_CORE_AU|L_CORE_AUSTATS|L_CORE_CAIDS|L_CORE_NET|L_CORE_CI|L_CORE_SC|L_CORE_HOOK)&LOPT_MASK, "core", { "load","action","ecm","ecmProc","pids","au","auStats","auExtra","auExtern", "caids","keys","dynamic","csa","ci","av7110","net","netData","msgcache", "serial","smartcard","hook","ciFull" } };ADD_MODULE(L_CORE,lm_core)// --- cMenuEditCapItem --------------------------------------------------------class cMenuEditCapItem : public cMenuEditIntItem {protected: virtual void Set(void);public: cMenuEditCapItem(const char *Name, int *Value); eOSState ProcessKey(eKeys Key); };cMenuEditCapItem::cMenuEditCapItem(const char *Name, int *Value):cMenuEditIntItem(Name, Value, 0){ Set();}void cMenuEditCapItem::Set(void){ if(!*value) SetValue(tr("off")); else cMenuEditIntItem::Set();}eOSState cMenuEditCapItem::ProcessKey(eKeys Key){ eOSState state = cMenuEditItem::ProcessKey(Key); if(state==osUnknown) state=cMenuEditIntItem::ProcessKey(Key); return state;}// --- cMenuEditHexItem ------------------------------------------------------class cMenuEditHexItem : public cMenuEditItem {private: bool abc, isOn; // void SetButtons(bool on);protected: int *value; int min, max; // virtual void Set(void);public: cMenuEditHexItem(const char *Name, int *Value, int Min=0, int Max=INT_MAX); virtual eOSState ProcessKey(eKeys Key); };cMenuEditHexItem::cMenuEditHexItem(const char *Name, int *Value, int Min, int Max):cMenuEditItem(Name){ value=Value; min=Min; max=Max; if(*value<min) *value=min; else if(*value>max) *value=max; Set(); abc=true; isOn=false;}void cMenuEditHexItem::SetButtons(bool on){ if(on) { if(abc) cSkinDisplay::Current()->SetButtons("A","B","C","D-F"); else cSkinDisplay::Current()->SetButtons("D","E","F","A-C"); isOn=true; } else { cSkinDisplay::Current()->SetButtons(0); isOn=false; }}void cMenuEditHexItem::Set(void){ char buf[16]; snprintf(buf,sizeof(buf),"%X",*value); SetValue(buf);}eOSState cMenuEditHexItem::ProcessKey(eKeys Key){ switch(NORMALKEY(Key)) { case kUp: case kDown: if(isOn) SetButtons(false); break; default: if(!isOn) SetButtons(true); break; } eOSState state=cMenuEditItem::ProcessKey(Key); if(state!=osUnknown) return state; int newValue=*value; bool IsRepeat=Key & k_Repeat; Key=NORMALKEY(Key); switch(Key) { case kBlue: abc=!abc; SetButtons(true); break; case kRed: case kGreen: case kYellow: case k0 ... k9: { if(fresh) { newValue=0; fresh=false; } int add; if(Key>=kRed && Key<=kYellow) add=(abc ? 10:13)+(Key-kRed); else add=(Key-k0); newValue=newValue*16+add; break; } case kLeft: newValue=*value-1; fresh=true; if(!IsRepeat && newValue<min) newValue=max; break; case kRight: newValue=*value+1; fresh=true; if(!IsRepeat && newValue>max) newValue=min; break; default: if(*value<min) { *value=min; Set(); } if(*value>max) { *value=max; Set(); } return osUnknown; } if(newValue!=*value && (!fresh || min<=newValue) && newValue<=max) { *value=newValue; Set(); } return osContinue;}// --- cScInfoItem -------------------------------------------------------------class cScInfoItem : public cOsdItem {private: void SetValue(const char *Name, const char *Value);public: cScInfoItem(const char *Name, int Value, eOSState State=osUnknown); cScInfoItem(const char *Name, const char *Value=0, eOSState State=osUnknown); };cScInfoItem::cScInfoItem(const char *Name, int Value, eOSState State):cOsdItem(State){ char buf[16]; snprintf(buf,sizeof(buf),"%d",Value); SetValue(Name,buf); if(State==osUnknown) SetSelectable(false);}cScInfoItem::cScInfoItem(const char *Name, const char *Value, eOSState State):cOsdItem(State){ SetValue(Name,Value); if(State==osUnknown) SetSelectable(false);}void cScInfoItem::SetValue(const char *Name, const char *Value){ char *buff; asprintf(&buff,Value ? "%s:\t%s":"%s",Name,Value); SetText(buff,false); cStatus::MsgOsdCurrentItem(buff);}// --- cOpt --------------------------------------------------------------------cOpt::cOpt(const char *Name, const char *Title){ name=Name; title=Title; fullname=0; persistant=true;}cOpt::~cOpt(){ free(fullname);}const char *cOpt::FullName(const char *PreStr){ if(PreStr) { free(fullname); asprintf(&fullname,"%s.%s",PreStr,name); return fullname; } else return name;}// --- cOptInt -----------------------------------------------------------------cOptInt::cOptInt(const char *Name, const char *Title, int *Storage, int Min, int Max):cOpt(Name,Title){ storage=Storage; min=Min; max=Max;}void cOptInt::Parse(const char *Value){ *storage=atoi(Value);}void cOptInt::Backup(void){ value=*storage;}bool cOptInt::Set(void){ if(value!=*storage) { *storage=value; return true; } return false;}void cOptInt::Store(const char *PreStr){ ScPlugin->SetupStore(FullName(PreStr),*storage);}void cOptInt::Create(cOsdMenu *menu){ menu->Add(new cMenuEditIntItem(tr(title),&value,min,max));}// --- cOptSel -----------------------------------------------------------------cOptSel::cOptSel(const char *Name, const char *Title, int *Storage, int NumStr, const char * const *Strings):cOptInt(Name,Title,Storage,0,NumStr){ strings=Strings; trStrings=0;}cOptSel::~cOptSel(){ free(trStrings);}void cOptSel::Create(cOsdMenu *menu){ free(trStrings); if((trStrings=MALLOC(const char *,max))) { for(int i=0; i<max ; i++) trStrings[i]=tr(strings[i]); menu->Add(new cMenuEditStraItem(tr(title),&value,max,trStrings)); }}// --- cOptBool -----------------------------------------------------------------cOptBool::cOptBool(const char *Name, const char *Title, int *Storage):cOptInt(Name,Title,Storage,0,1){}void cOptBool::Create(cOsdMenu *menu){ menu->Add(new cMenuEditBoolItem(tr(title),&value));}// --- cOptStr -----------------------------------------------------------------cOptStr::cOptStr(const char *Name, const char *Title, char *Storage, int Size, const char *Allowed):cOpt(Name,Title){ storage=Storage; size=Size; allowed=Allowed; value=MALLOC(char,size);}cOptStr::~cOptStr(){ free(value);}void cOptStr::Parse(const char *Value){ strn0cpy(storage,Value,size);}void cOptStr::Backup(void){ strn0cpy(value,storage,size);}bool cOptStr::Set(void){ if(strcmp(value,storage)) { strn0cpy(storage,value,size); return true; } return false;}void cOptStr::Store(const char *PreStr){ ScPlugin->SetupStore(FullName(PreStr),storage);}void cOptStr::Create(cOsdMenu *menu){ menu->Add(new cMenuEditStrItem(tr(title),value,size,allowed));}// --- cOptMInt ----------------------------------------------------------------class cOptMInt : public cOpt {protected: int *storage, *value; int size, mode, len;public: cOptMInt(const char *Name, const char *Title, int *Storage, int Size, int Mode); virtual ~cOptMInt(); virtual void Parse(const char *Value); virtual void Backup(void); virtual bool Set(void); virtual void Store(const char *PreStr); virtual void Create(cOsdMenu *menu); };// mode: 0-Cap 1-Int 2-HexcOptMInt::cOptMInt(const char *Name, const char *Title, int *Storage, int Size, int Mode):cOpt(Name,Title){ storage=Storage; size=Size; mode=Mode; len=sizeof(int)*size; value=MALLOC(int,size);}cOptMInt::~cOptMInt(){ free(value);}void cOptMInt::Parse(const char *Value){ memset(storage,0,len); int i=0; while(1) { char *p; const int c=strtol(Value,&p,mode>1 ? 16:10); if(p==Value || i>=size) return; if(c>0) storage[i++]=c; Value=p; }}void cOptMInt::Backup(void){ memcpy(value,storage,len);}bool cOptMInt::Set(void){ if(memcmp(value,storage,len)) { memset(storage,0,len); for(int i=0, k=0; i<size; i++) if(value[i]>0) storage[k++]=value[i]; return true; } return false;}void cOptMInt::Store(const char *PreStr){ char b[256]; int p=0; for(int i=0; i<size; i++) if(storage[i]) p+=snprintf(b+p,sizeof(b)-p,mode>1 ? "%x ":"%d ",storage[i]); ScPlugin->SetupStore(FullName(PreStr),p>0?b:0);}void cOptMInt::Create(cOsdMenu *menu){ for(int i=0; i<size; i++) { const char *buff=tr(title); switch(mode) { case 0: menu->Add(new cMenuEditCapItem(buff,&value[i])); break; case 1: menu->Add(new cMenuEditIntItem(buff,&value[i],0,65535)); break; case 2: menu->Add(new cMenuEditHexItem(buff,&value[i],0,65535)); break; } if(value[i]==0) break; }}// --- cOpts -------------------------------------------------------------------cOpts::cOpts(const char *PreStr, int NumOpts){ preStr=PreStr; numOpts=NumOpts; numAdd=0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -