- 1.PNG (3.46 KiB) Viewed 4590 times
Вернул
- 2.PNG (15.08 KiB) Viewed 4590 times
Code: Select all
bool ProcessLocalFileTypes(const string& Name, const string& ShortName, FILETYPE_MODE Mode, bool AlwaysWaitFinish)
{
string strCommand, strDescription, strMask;
{
int ActualCmdCount=0; // отображаемых ассоциаций в меню
filemasks FMask; // для работы с масками файлов
int CommandCount=0;
DWORD Index=0;
unsigned __int64 id;
string FileName = PointToName(Name);
size_t w = 0;
std::vector<string> descs, cmds, ocmds;
while (ConfigProvider().AssocConfig()->EnumMasksForType(Mode,Index++,&id,strMask))
{
strCommand.clear();
if (FMask.Set(strMask,FMF_SILENT))
{
if (FMask.Compare(FileName))
{
ConfigProvider().AssocConfig()->GetCommand(id,Mode,strCommand);
if (!strCommand.empty())
{
ConfigProvider().AssocConfig()->GetDescription(id,strDescription);
CommandCount++;
}
}
if (strCommand.empty())
continue;
}
string strCommandText = strCommand;
SubstFileName(nullptr,strCommandText,Name, ShortName,nullptr,nullptr,nullptr,nullptr,TRUE);
// все "подставлено", теперь проверим условия "if exist"
if (!ExtractIfExistCommand(strCommandText))
continue;
ActualCmdCount++;
if (!strDescription.empty())
SubstFileName(nullptr,strDescription, Name, ShortName, nullptr, nullptr, nullptr, nullptr, TRUE);
descs.push_back( strDescription );
ocmds.push_back( strCommand );
cmds.push_back( strCommandText );
w = std::max( w, strDescription.length() );
}
if (!CommandCount)
return false;
if (!ActualCmdCount)
return true;
int ExitCode=0;
if (ActualCmdCount>1)
{
const auto TypesMenu = VMenu2::create(MSG(MSelectAssocTitle), nullptr, 0, ScrY - 4);
TypesMenu->SetHelp(L"FileAssoc");
TypesMenu->SetMenuFlags(VMENU_WRAPMODE);
TypesMenu->SetId(SelectAssocMenuId);
for( Index = 0; Index < descs.size(); Index++ ) {
MenuItemEx TypesMenuItem( (!w) ? cmds[Index] : str_printf( L"%-*s\x00A6%s", w, descs[Index].c_str(), cmds[Index].c_str() ) );
TypesMenuItem.SetSelect(Index==0);
TypesMenuItem.UserData = cmds[Index];
TypesMenu->AddItem(TypesMenuItem);
}
ExitCode=TypesMenu->Run();
if (ExitCode<0)
return true;
}
strCommand = ocmds[ExitCode];
}
string strListName, strAnotherListName, strShortListName, strAnotherShortListName;
const string* ListNames[] =
{
&strListName,
&strAnotherListName,
&strShortListName,
&strAnotherShortListName
};
int PreserveLFN=SubstFileName(nullptr,strCommand, Name, ShortName, &strListName, &strAnotherListName, &strShortListName, &strAnotherShortListName);
const auto ListFileUsed = !std::all_of(ALL_CONST_RANGE(ListNames), std::mem_fn(&string::empty));
// Снова все "подставлено", теперь проверим условия "if exist"
if (ExtractIfExistCommand(strCommand))
{
SCOPED_ACTION(PreserveLongName)(ShortName, PreserveLFN);
RemoveExternalSpaces(strCommand);
if (!strCommand.empty())
{
Global->CtrlObject->CmdLine()->ExecString(strCommand,AlwaysWaitFinish, false, false, ListFileUsed, false,
Mode == FILETYPE_VIEW || Mode == FILETYPE_ALTVIEW || Mode == FILETYPE_EDIT || Mode == FILETYPE_ALTEDIT);
if (!(Global->Opt->ExcludeCmdHistory&EXCLUDECMDHISTORY_NOTFARASS) && !AlwaysWaitFinish) //AN
{
const auto curDir = Global->CtrlObject->CmdLine()->GetCurDir();
Global->CtrlObject->CmdHistory->AddToHistory(strCommand, HR_DEFAULT, nullptr, nullptr, curDir.data());
}
}
}
std::for_each(CONST_RANGE(ListNames, i)
{
if (!i->empty())
os::DeleteFile(*i);
});
return true;
}
Если удаление такого вида было каким-то политическим решением то сорри.