📄 tglobalsettings.cpp
字号:
/*
* Copyright (c) 2002-2006 Milan Cutka
*
* 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 of the License, 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "stdafx.h"
#include "Tconfig.h"
#include "TglobalSettings.h"
#include "reg.h"
#include "ffdshow_mediaguids.h"
#include "ffcodecs.h"
#include "ffdshow_constants.h"
#include "TsampleFormat.h"
#include "ffImgfmt.h"
#include "TpresetSettings.h"
#include "ffdebug.h"
#include "Tstream.h"
#include "IffdshowDec.h"
#include "TcompatibilityManager.h"
//===================================== TglobalSettingsBase ======================================
TglobalSettingsBase::TglobalSettingsBase(const Tconfig *Iconfig,int Imode,const char_t *Ireg_child,TintStrColl *Icoll):filtermode(Imode),config(Iconfig),reg_child(Ireg_child),Toptions(Icoll)
{
static const TintOptionT<TglobalSettingsBase> iopts[]=
{
IDFF_filterMode ,&TglobalSettingsBase::filtermode ,1,1,_l(""),0,
NULL,0,
IDFF_trayIcon ,&TglobalSettingsBase::trayIcon ,0,0,_l(""),0,
_l("trayIcon"),TintOption::DEF_DYN,
IDFF_trayIconType ,&TglobalSettingsBase::trayIconType ,0,2,_l(""),0,
NULL,1,
IDFF_trayIconChanged ,&TglobalSettingsBase::trayIconChanged ,0,0,_l(""),0,
NULL,0,
IDFF_trayIconExt ,&TglobalSettingsBase::trayIconExt ,0,0,_l(""),0,
_l("trayIconExt"),0,
IDFF_outputdebug ,&TglobalSettingsBase::outputdebug ,0,0,_l(""),0,
_l("outputdebug"),1,
IDFF_outputdebugfile ,&TglobalSettingsBase::outputdebugfile ,0,0,_l(""),0,
_l("outputdebugfile"),0,
IDFF_errorbox ,&TglobalSettingsBase::errorbox ,0,0,_l(""),0,
_l("errorbox1"),1,
IDFF_multipleInstances,&TglobalSettingsBase::multipleInstances,0,4,_l(""),0,
_l("multipleInstances"),TintOption::DEF_DYN,
IDFF_isBlacklist ,&TglobalSettingsBase::isBlacklist ,0,0,_l(""),0,
_l("isBlacklist"),1,
IDFF_isCompatibilityList ,&TglobalSettingsBase::isUseonlyin ,0,0,_l(""),0,
_l("isUseonlyin"),1,
IDFF_compManagerMode ,&TglobalSettingsBase::compOnLoadMode ,1,4,_l(""),0,
NULL,1,
IDFF_isCompMgr ,&TglobalSettingsBase::isCompMgr ,0,0,_l(""),0,
NULL,1,
IDFF_isCompMgrChanged ,&TglobalSettingsBase::isCompMgrChanged ,0,0,_l(""),0,
NULL,0,
IDFF_addToROT ,&TglobalSettingsBase::addToROT ,0,0,_l(""),0,
_l("addToROT"),0,
IDFF_allowedCpuFlags ,&TglobalSettingsBase::allowedCPUflags ,1,1,_l(""),0,
NULL,0,
0
};
addOptions(iopts);
static const TstrOption sopts[]=
{
IDFF_debugfile ,(TstrVal)&TglobalSettingsBase::debugfile ,MAX_PATH,_l(""),0,
_l("debugfile"),_l("\\ffdebug.log"),
IDFF_dscalerPath,(TstrVal)&TglobalSettingsBase::dscalerPth,MAX_PATH,_l(""),0,
NULL,NULL,
IDFF_blacklist ,(TstrVal)&TglobalSettingsBase::blacklist ,MAX_COMPATIBILITYLIST_LENGTH,_l(""),0,
_l("blacklist"),BLACKLIST_EXE_FILENAME,
IDFF_compatibilityList ,(TstrVal)&TglobalSettingsBase::useonlyin ,MAX_COMPATIBILITYLIST_LENGTH,_l(""),0,
_l("useonlyin"),COMPATIBLE_EXE_FILENAME,
0
};
addOptions(sopts);
static const TcreateParamList3<TmultipleInstances> listMultipleInstances(::multipleInstances,&TmultipleInstances::id,&TmultipleInstances::name);setParamList(IDFF_multipleInstances,&listMultipleInstances);
}
void TglobalSettingsBase::load(void)
{
char_t rkey[MAX_PATH];
tsprintf(rkey,FFDSHOW_REG_PARENT _l("\\%s"),reg_child);
TregOpRegRead tHKCU(HKEY_CURRENT_USER,rkey);
reg_op(tHKCU);
TregOpRegRead tHKLM(HKEY_LOCAL_MACHINE,rkey);
reg_op_codec(tHKCU,&tHKLM);
TregOpRegRead tDScaler(HKEY_LOCAL_MACHINE,FFDSHOW_REG_PARENT _l("\\") FFDSHOW);
tDScaler._REG_OP_S(IDFF_dscalerPath,_l("dscalerPth"),dscalerPth,MAX_PATH,_l(""));
TregOpRegRead tCPU(HKEY_CURRENT_USER,FFDSHOW_REG_PARENT _l("\\") FFDSHOW);
tCPU._REG_OP_N(IDFF_allowedCpuFlags,_l("allowedCPUflags"),allowedCPUflags,255);
firstBlacklist=firstUseonlyin=true;
// Load Icon type : common through video, audio and vfw.
TregOpRegRead tHKCU_global(HKEY_CURRENT_USER,FFDSHOW_REG_PARENT _l("\\ffdshow"));
tHKCU_global._REG_OP_N(IDFF_trayIconType,_l("trayIconType"),trayIconType,1);
// Load compatibility manager::dontask : shared by video and audio.
tHKCU_global._REG_OP_N(IDFF_isCompMgr,_l("isCompMgr"),isCompMgr,1);
// fix 'SinkuHadouken.exe'#1310 -> 'SinkuHadouken.exe'#13#10 (rev 976 bug)
char_t sinkuhadouken[19]={'S','i','n','k','u','H','a','d','o','u','k','e','n','.','e','x','e',0x1e,'\0'};
ffstring complist(useonlyin);
size_t pos=complist.find(sinkuhadouken);
if (pos!=complist.npos)
complist.replace(pos+17,1,_l("\r\n"));
// fix ' wmenc.exe'#13#10 -> 'wmenc.exe'#13#10 (rev 1125 bug)
char_t wmenc[13]={' ','w','m','e','n','c','.','e','x','e',13,10,'\0'};
pos=complist.find(wmenc);
if (pos!=complist.npos)
complist.erase(pos,1);
strncpy(useonlyin,complist.c_str(),countof(useonlyin));
useonlyin[countof(useonlyin)-1]=0;
}
void TglobalSettingsBase::save(void)
{
char_t rkey[MAX_PATH];tsprintf(rkey,FFDSHOW_REG_PARENT _l("\\%s"),reg_child);
TregOpRegWrite tHKCU(HKEY_CURRENT_USER,rkey);
reg_op(tHKCU);
reg_op_codec(tHKCU,NULL);
TregOpRegWrite tDScaler(HKEY_LOCAL_MACHINE,FFDSHOW_REG_PARENT _l("\\") FFDSHOW);
tDScaler._REG_OP_S(IDFF_dscalerPath,_l("dscalerPth"),dscalerPth,MAX_PATH,_l(""));
TregOpRegWrite tCPU(HKEY_CURRENT_USER,FFDSHOW_REG_PARENT _l("\\") FFDSHOW);
tCPU._REG_OP_N(IDFF_allowedCpuFlags,_l("allowedCPUflags"),allowedCPUflags,255);
// Save Icon type : common through video, audio and vfw.
if (trayIconChanged)
{
TregOpRegWrite tHKCU_global(HKEY_CURRENT_USER,FFDSHOW_REG_PARENT _l("\\ffdshow"));
tHKCU_global._REG_OP_N(IDFF_trayIconType,_l("trayIconType"),trayIconType,0);
trayIconChanged=0;
}
// Save compatibility manager::dontask : common through video and audio decoders.
if (isCompMgrChanged)
{
TregOpRegWrite tHKCU_global(HKEY_CURRENT_USER,FFDSHOW_REG_PARENT _l("\\ffdshow"));
tHKCU_global._REG_OP_N(IDFF_isCompMgr,_l("isCompMgr"),isCompMgr,0);
isCompMgrChanged=0;
}
}
bool TglobalSettingsBase::exportReg(bool all,const char_t *regflnm,bool unicode)
{
if (fileexists(regflnm) && DeleteFile(regflnm)==0)
return false;
TstreamFile f(regflnm,false,true,unicode?Tstream::ENC_LE16:Tstream::ENC_ASCII);if (!f) return false;
if (unicode)
f.printf(L"Windows Registry Editor Version 5.00\n\n");
else
f.printf("REGEDIT4\n\n");
regExport(f,HKEY_LOCAL_MACHINE,FFDSHOW_REG_PARENT _l("\\") FFDSHOW,unicode);
if (all || strcmp(reg_child,FFDSHOWDECVIDEO)==0)
regExport(f,HKEY_CURRENT_USER ,FFDSHOW_REG_PARENT _l("\\") FFDSHOWDECVIDEO,unicode);
if (all || strcmp(reg_child,FFDSHOWDECAUDIO)==0)
{
regExport(f,HKEY_CURRENT_USER ,FFDSHOW_REG_PARENT _l("\\") FFDSHOWDECAUDIO,unicode);
regExport(f,HKEY_LOCAL_MACHINE,FFDSHOW_REG_PARENT _l("\\") FFDSHOWDECAUDIO,unicode);
}
if (all || strcmp(reg_child,FFDSHOWENC)==0)
{
regExport(f,HKEY_CURRENT_USER ,FFDSHOW_REG_PARENT _l("\\") FFDSHOWENC,unicode);
regExport(f,HKEY_LOCAL_MACHINE,FFDSHOW_REG_PARENT _l("\\") FFDSHOWENC,unicode);
}
if (all || strcmp(reg_child,FFDSHOWDECVIDEOVFW)==0)
{
regExport(f,HKEY_CURRENT_USER ,FFDSHOW_REG_PARENT _l("\\") FFDSHOWDECVIDEOVFW,unicode);
regExport(f,HKEY_LOCAL_MACHINE,FFDSHOW_REG_PARENT _l("\\") FFDSHOWDECVIDEOVFW,unicode);
}
return true;
}
void TglobalSettingsBase::_reg_op_codec(short id,TregOp &tHKCU,TregOp *tHKLM,const char_t *name,int &val,int def)
{
if (!tHKCU._REG_OP_N(id,name,val,def) && tHKLM)
tHKLM->_REG_OP_N(id,name,val,def);
}
bool TglobalSettingsBase::inBlacklist(const char_t *exe)
{
if (firstBlacklist)
{
firstBlacklist=false;
strtok(blacklist,_l(";"),blacklistList);
}
for (strings::const_iterator b=blacklistList.begin();b!=blacklistList.end();b++)
if (DwStrcasecmp(*b,exe)==0)
return true;
return false;
}
bool TglobalSettingsBase::inUseonlyin(const char_t *exe,IffdshowBase *Ideci)
{
// MessageBox(NULL,exe,_l("ffdshow inUseonlyin"),MB_OK);
bool old_firstUseonlyin=firstUseonlyin;
if (firstUseonlyin)
{
firstUseonlyin=false;
strtok(useonlyin,_l("\r\n"),useonlyinList);
}
for (strings::const_iterator b=useonlyinList.begin();b!=useonlyinList.end();b++)
if (DwStrcasecmp(*b,exe)==0)
return true;
if (!isCompMgr)
return false;
if (TcompatibilityManager::s_mode==0)
{
TcompatibilityManager::s_mode=-1;
TcompatibilityManager *dlg=new TcompatibilityManager(Ideci,NULL,exe);
dlg->show();
delete dlg;
}
bool result=false;
switch (TcompatibilityManager::s_mode)
{
case -1:
case 0:
case 1:
result=false;
break;
case 2:
if (old_firstUseonlyin) addToCompatiblityList(blacklist,exe,_l(";"));
result=false;
break;
case 3:
result=true;
break;
case 4:
if (old_firstUseonlyin) addToCompatiblityList(useonlyin,exe,_l("\r\n"));
result=true;
break;
}
if (isCompMgrChanged)
save();
return result;
}
void TglobalSettingsBase::addToCompatiblityList(char_t *list, const char_t *exe, const char_t *delimit)
{
strings listList;
strtok(list,delimit,listList);
listList.push_back(exe);
ffstring result;
for (strings::const_iterator b=listList.begin();b!=listList.end();b++)
result+=*b+delimit;
strncpy(list,result.c_str(),std::min<size_t>(MAX_COMPATIBILITYLIST_LENGTH,result.size()+1));
save();
}
//===================================== TglobalSettingsDec ======================================
TglobalSettingsDec::TglobalSettingsDec(const Tconfig *Iconfig,int Imode,const char_t *Ireg_child,TintStrColl *Icoll,TOSDsettings *Iosd):TglobalSettingsBase(Iconfig,Imode,Ireg_child,Icoll),osd(Iosd)
{
static const TintOptionT<TglobalSettingsDec> iopts[]=
{
IDFF_autoPreset ,&TglobalSettingsDec::autoPreset ,0,0,_l(""),0,
_l("autoPresets"),0,
IDFF_autoPresetFileFirst,&TglobalSettingsDec::autoPresetFileFirst,0,0,_l(""),0,
_l("autoPresetFileFirst"),0,
IDFF_streamsOptionsMenu ,&TglobalSettingsDec::streamsMenu ,0,0,_l(""),0,
_l("streamsOptionsMenu"),0,
0
};
addOptions(iopts);
static const TstrOption sopts[]=
{
IDFF_defaultPreset,(TstrVal)&TglobalSettingsDec::defaultPreset,260,_l(""),0,
_l("activePreset"),FFPRESET_DEFAULT,
0
};
addOptions(sopts);
}
void TglobalSettingsDec::reg_op(TregOp &t)
{
TglobalSettingsBase::reg_op(t);
osd->reg_op(t);
}
void TglobalSettingsDec::load(void)
{
TglobalSettingsBase::load();
osd->loadPresets(reg_child);
}
void TglobalSettingsDec::save(void)
{
TglobalSettingsBase::save();
osd->savePresets(reg_child);
}
void TglobalSettingsDec::fixMissing(int &codecId,int movie1,int movie2,int movie3)
{
fixMissing(codecId,movie1,movie2);
fixMissing(codecId,movie2,movie3);
fixMissing(codecId,movie1,movie3);
}
void TglobalSettingsDec::fixMissing(int &codecId,int movie1,int movie2)
{
if (!config->isDecoder[movie1] && !config->isDecoder[movie2]) codecId=IDFF_MOVIE_NONE;
else if (codecId==movie1 && !config->isDecoder[movie1]) codecId=movie2;
else if (codecId==movie2 && !config->isDecoder[movie2]) codecId=movie1;
}
void TglobalSettingsDec::fixMissing(int &codecId,int movie)
{
if (!config->isDecoder[movie]) codecId=0;
}
int TglobalSettingsDec::getDefault(int id)
{
switch (id)
{
case IDFF_trayIcon:return 1;
default:return TglobalSettingsBase::getDefault(id);
}
}
static bool compStrPtrs(const char_t *s1,const char_t *s2)
{
return stricmp(s1,s2)<0;
}
void TglobalSettingsDec::cleanupCodecsList(std::vector<CodecID> &ids,Tstrptrs &codecs)
{
std::sort(ids.begin(),ids.end());
std::vector<CodecID>::iterator idsend=std::unique(ids.begin(),ids.end());
codecs.clear();
for (std::vector<CodecID>::const_iterator id=ids.begin();id!=idsend;id++)
codecs.push_back(getCodecName(*id));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -