void FileList::DeletePluginItemList(PluginPanelItem *(&ItemList),int &ItemNumber) { PluginPanelItem *PItemList=ItemList; if (PItemList) { for (int I=0; I<ItemNumber; I++,PItemList++) { FreePluginPanelItem(PItemList); } delete[] ItemList; } }
void PrintFiles(FileList* SrcPanel) { _ALGO(CleverSysLog clv(L"Alt-F5 (PrintFiles)")); string strPrinterName; DWORD Needed = 0, Returned; DWORD FileAttr; string strSelName; size_t DirsCount=0; size_t SelCount=SrcPanel->GetSelCount(); if (!SelCount) { _ALGO(SysLog(L"Error: !SelCount")); return; } // проверка каталогов _ALGO(SysLog(L"Check for FILE_ATTRIBUTE_DIRECTORY")); SrcPanel->GetSelName(nullptr,FileAttr); while (SrcPanel->GetSelName(&strSelName,FileAttr)) { if (TestParentFolderName(strSelName) || (FileAttr & FILE_ATTRIBUTE_DIRECTORY)) DirsCount++; } if (DirsCount==SelCount) return; EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, nullptr, PRINTER_INFO_LEVEL, nullptr, 0, &Needed, &Returned); if (!Needed) return; block_ptr<PRINTER_INFO> pi(Needed); if (!EnumPrinters(PRINTER_ENUM_LOCAL|PRINTER_ENUM_CONNECTIONS,nullptr,PRINTER_INFO_LEVEL,(LPBYTE)pi.get(),Needed,&Needed,&Returned)) { Global->CatchError(); Message(MSG_WARNING|MSG_ERRORTYPE,1,MSG(MPrintTitle),MSG(MCannotEnumeratePrinters),MSG(MOk)); return; } { _ALGO(CleverSysLog clv2(L"Show Menu")); LangString strTitle; string strName; if (SelCount==1) { SrcPanel->GetSelName(nullptr,FileAttr); SrcPanel->GetSelName(&strName,FileAttr); strSelName = TruncStr(strName,50); strTitle = MPrintTo; strTitle << InsertQuote(strSelName); } else { _ALGO(SysLog(L"Correct: SelCount-=DirsCount")); SelCount-=DirsCount; strTitle = MPrintFilesTo; strTitle << SelCount; } VMenu2 PrinterList(strTitle,nullptr,0,ScrY-4); PrinterList.SetFlags(VMENU_WRAPMODE|VMENU_SHOWAMPERSAND); PrinterList.SetPosition(-1,-1,0,0); AddToPrintersMenu(&PrinterList,pi.get(),Returned); if (PrinterList.Run()<0) { _ALGO(SysLog(L"ESC")); return; } strPrinterName = NullToEmpty(static_cast<const wchar_t*>(PrinterList.GetUserData(nullptr, 0))); } HANDLE hPrinter; if (!OpenPrinter(UNSAFE_CSTR(strPrinterName), &hPrinter,nullptr)) { Global->CatchError(); Message(MSG_WARNING|MSG_ERRORTYPE,1,MSG(MPrintTitle),MSG(MCannotOpenPrinter), strPrinterName.data(),MSG(MOk)); _ALGO(SysLog(L"Error: Cannot Open Printer")); return; } { _ALGO(CleverSysLog clv3(L"Print selected Files")); SCOPED_ACTION(SaveScreen); auto PR_PrintMsg = [](){ Message(0, 0, MSG(MPrintTitle), MSG(MPreparingForPrinting)); }; SCOPED_ACTION(TPreRedrawFuncGuard)(std::make_unique<PreRedrawItem>(PR_PrintMsg)); SetCursorType(false, 0); PR_PrintMsg(); auto hPlugin=SrcPanel->GetPluginHandle(); int PluginMode=SrcPanel->GetMode()==PLUGIN_PANEL && !Global->CtrlObject->Plugins->UseFarCommand(hPlugin,PLUGIN_FARGETFILE); SrcPanel->GetSelName(nullptr,FileAttr); while (SrcPanel->GetSelName(&strSelName,FileAttr)) { if (TestParentFolderName(strSelName) || (FileAttr & FILE_ATTRIBUTE_DIRECTORY)) continue; int Success=FALSE; string FileName; string strTempDir, strTempName; if (PluginMode) { if (FarMkTempEx(strTempDir)) { api::CreateDirectory(strTempDir,nullptr); auto ListItem = SrcPanel->GetLastSelectedItem(); if (ListItem) { PluginPanelItem PanelItem; FileList::FileListToPluginItem(*ListItem, &PanelItem); if (Global->CtrlObject->Plugins->GetFile(hPlugin,&PanelItem,strTempDir,strTempName,OPM_SILENT)) FileName = strTempName; else api::RemoveDirectory(strTempDir); FreePluginPanelItem(PanelItem); } } } else FileName = strSelName; api::File SrcFile; if(SrcFile.Open(FileName, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, nullptr, OPEN_EXISTING)) { DOC_INFO_1 di1 = {UNSAFE_CSTR(FileName)}; if (StartDocPrinter(hPrinter,1,(LPBYTE)&di1)) { char Buffer[8192]; DWORD Read,Written; Success=TRUE; while (SrcFile.Read(Buffer, sizeof(Buffer), Read) && Read > 0) if (!WritePrinter(hPrinter,Buffer,Read,&Written)) { Global->CatchError(); Success=FALSE; break; } EndDocPrinter(hPrinter); } SrcFile.Close(); } if (!strTempName.empty()) { DeleteFileWithFolder(strTempName); } if (Success) SrcPanel->ClearLastGetSelection(); else { if (Message(MSG_WARNING|MSG_ERRORTYPE,2,MSG(MPrintTitle),MSG(MCannotPrint), strSelName.data(),MSG(MSkip),MSG(MCancel))) break; } } ClosePrinter(hPrinter); } SrcPanel->Redraw(); }