#include "NetCommon.hpp" #include "NetCfg.hpp" #include "NetFavorites.hpp" #include "NetClass.hpp" #include #include #include NetResourceList *CommonRootResources; BOOL SavedCommonRootResources = FALSE; // -- NetResourceList -------------------------------------------------------- #ifdef NETWORK_LOGGING FILE* NetBrowser::LogFile = NULL; int NetBrowser::LogFileRef = 0; void NetBrowser::OpenLogFile(wchar_t *lpFileName) { if (!LogFileRef) LogFile = _wfopen(lpFileName, L"a+t"); if (LogFile) _ftprintf(LogFile, L"Opening plugin\n"); LogFileRef++; } void NetBrowser::CloseLogfile() { LogFileRef--; if (!LogFileRef && LogFile)fclose(LogFile),LogFile = NULL; } void NetBrowser::LogData(wchar_t * Data) { if (LogFile) { _ftprintf(LogFile,L"%s\n", Data); wchar_t buffer[MAX_PATH]; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, buffer, ARRAYSIZE(buffer), NULL); _ftprintf(LogFile,L"GetLastError returns: %s\n", buffer); } } #endif NetResourceList::NetResourceList() : ResList(NULL), ResCount(0) { } NetResourceList::~NetResourceList() { Clear(); } NetResourceList &NetResourceList::operator= (NetResourceList &other) { Clear(); for (unsigned I=0; I 0) { DeleteNetResource(ResList [ResCount-1]); ResList=(NETRESOURCE *)realloc(ResList,(ResCount-1)*sizeof(*ResList)); ResCount--; } } BOOL NetResourceList::Enumerate(DWORD dwScope, DWORD dwType, DWORD dwUsage, LPNETRESOURCE lpNetResource) { Clear(); if (GetFavorites(lpNetResource, this)) return TRUE; HANDLE hEnum; if (WNetOpenEnum(dwScope, dwType, dwUsage, lpNetResource, &hEnum)!=NO_ERROR) return FALSE; BOOL EnumFailed = FALSE; for (;;) { NETRESOURCE nr[1024]; DWORD NetSize=sizeof(nr),NetCount=ARRAYSIZE(nr); DWORD EnumCode=WNetEnumResource(hEnum,&NetCount,nr,&NetSize); if (EnumCode!=NO_ERROR) { if (EnumCode!=ERROR_NO_MORE_ITEMS) { Clear(); EnumFailed = TRUE; } break; } if (NetCount>0) { ResList=(NETRESOURCE *)realloc(ResList,(ResCount+NetCount)*sizeof(*ResList)); ZeroMemory(&ResList [ResCount], sizeof(*ResList)*NetCount); for (unsigned I=0; IlpRemoteName) lstrcpy(NetListRemoteName, PCurResource->lpRemoteName); else NetListRemoteName [0] = L'\0'; if (!NetList.Enumerate(RESOURCE_GLOBALNET,RESOURCETYPE_ANY,0,PCurResource)) { if (PCurResource == NULL) { const wchar_t *MsgItems[]={GetMsg(MError),GetMsg(MNetCannotBrowse),GetMsg(MOk)}; Info.Message(&MainGuid, nullptr,FMSG_WARNING|FMSG_ERRORTYPE,NULL,MsgItems,ARRAYSIZE(MsgItems),1); return(FALSE); } else { // try again with connection AddConnection(PCurResource); if (!NetList.Enumerate(RESOURCE_GLOBALNET,RESOURCETYPE_ANY,0,PCurResource)) NetList.Clear(); } } if (!CheckFavoriteItem(PCurResource) && Opt.HiddenShares) { PanelInfo PInfo = {sizeof(PanelInfo)}; Info.PanelControl(this, FCTL_GETPANELINFO,0,&PInfo); if (!Opt.HiddenSharesAsHidden || (PInfo.Flags & PFLAGS_SHOWHIDDEN)) { // Check whether we need to get the hidden shares. if (NetList.Count() > 0) { if (PCurResource != NULL) { // If the parent of the current folder is not a server if (PCurResource->dwDisplayType != RESOURCEDISPLAYTYPE_SERVER) { return TRUE; } } // If there are elements, check the first element if ((NetList[NetList.Count()-1].dwDisplayType) != RESOURCEDISPLAYTYPE_SHARE) { return TRUE; } } GetHiddenShares(); } } /* if (NetCount==0 && CurResource!=NULL && AddConnection(CurResource)) if (WNetOpenEnum(RESOURCE_GLOBALNET,RESOURCETYPE_ANY,0,CurResource,&hEnum)==NO_ERROR) { GetNetList(hEnum,NetRes,NetCount); WNetCloseEnum(hEnum); } */ return TRUE; } BOOL NetBrowser::GotoFavorite(wchar_t *lpPath) { #ifdef NEWTWORK_LOGGING LogData(L"Entered NetBrowser::GotoFavorite") #endif NETRESOURCE nr = {0}; if (GetFavoriteResource(lpPath, &nr)) { #ifdef NETWORK_LOGGING LogData(L"GetFavoriteResource SUCCEEDED"); LogNetResource(nr); #endif NetResourceList::CopyNetResource(CurResource, nr); NetResourceList::DeleteNetResource(nr); PCurResource = &CurResource; Info.PanelControl(this, FCTL_UPDATEPANEL,0,0); Info.PanelControl(this, FCTL_REDRAWPANEL,0,0); return TRUE; } return FALSE; } int NetBrowser::GetFindData(PluginPanelItem **pPanelItem,size_t *pItemsNumber,OPERATION_MODES OpMode) { #ifdef NETWORK_LOGGING LogData(L"Entering NetBrowser::GetFindData"); #endif if (OpMode & OPM_FIND) return FALSE; if (ReenterGetFindData) return TRUE; ReenterGetFindData++; if (ChangeDirSuccess) { if (CmdLinePath [0]) { // prevent recursion wchar_t TmpCmdLinePath [MAX_PATH]; lstrcpy(TmpCmdLinePath, CmdLinePath); CmdLinePath [0] = 0; ReenterGetFindData--; if (!GotoFavorite(TmpCmdLinePath)) GotoComputer(TmpCmdLinePath); ReenterGetFindData++; } *pPanelItem=NULL; *pItemsNumber=0; TSaveScreen SS; // get the list of connections, so that we can show mapped drive letters if (!ConnectedList.Enumerate(RESOURCE_CONNECTED,RESOURCETYPE_DISK,0,NULL)) { const wchar_t *MsgItems[]={GetMsg(MError),GetMsg(MNetCannotBrowse),GetMsg(MOk)}; Info.Message(&MainGuid, nullptr,FMSG_WARNING|FMSG_ERRORTYPE,NULL,MsgItems,ARRAYSIZE(MsgItems),1); ReenterGetFindData--; return FALSE; } if (!EnumerateNetList()) { ReenterGetFindData--; return FALSE; } } ChangeDirSuccess = TRUE; PluginPanelItem *NewPanelItem=(PluginPanelItem *)malloc(sizeof(PluginPanelItem)*NetList.Count()); *pPanelItem=NewPanelItem; if (NewPanelItem==NULL) { ReenterGetFindData--; return(FALSE); } int CurItemPos=0; for (unsigned I=0; I(PInfo.ViewMode + 0x30), 0 }; PluginSettings settings(MainGuid, Info.SettingsControl); settings.Set(0,StrPanelMode,Mode); } if (PCurResource == NULL || IsMSNetResource(*PCurResource)) { NetResourceList::CopyNetResource(CommonCurResource, CurResource); PCommonCurResource = PCurResource ? &CommonCurResource : NULL; SavedCommonRootResources = false; } else { *CommonRootResources = RootResources; SavedCommonRootResources = true; } } return FALSE; } int NetBrowser::DeleteFiles(struct PluginPanelItem *PanelItem,int ItemsNumber, OPERATION_MODES /*OpMode*/) { if (CheckFavoriteItem(PCurResource)) { //Deleting from favorites RemoveItems(); } else { for (int I=0; IlpRemoteName) FSF.sprintf(szFullName, L"%s\\%s", PCurResource->lpRemoteName, RemoteName); else return FALSE; if (!GetDriveToDisconnect(szFullName, LocalName)) return FALSE; int UpdateProfile = 0; if (!ConfirmCancelConnection(LocalName, szFullName, UpdateProfile)) return FALSE; DWORD status = WNetCancelConnection2(LocalName,UpdateProfile,FALSE); // if we're on the drive we're disconnecting, set the directory to // a different drive and try again if (status != NO_ERROR && HandsOffDisconnectDrive(LocalName)) status = WNetCancelConnection2(LocalName,UpdateProfile,FALSE); if (status!=NO_ERROR) { int Failed=FALSE; wchar_t MsgText[200]; FSF.sprintf(MsgText,GetMsg(MNetCannotDisconnect),LocalName); int LastError=GetLastError(); if (LastError==ERROR_OPEN_FILES || LastError==ERROR_DEVICE_IN_USE) { const wchar_t *MsgItems[]={GetMsg(MError),MsgText,L"\x1",GetMsg(MOpenFiles),GetMsg(MAskDisconnect),GetMsg(MOk),GetMsg(MCancel)}; if (Info.Message(&MainGuid, nullptr,FMSG_WARNING|FMSG_ERRORTYPE,NULL,MsgItems,ARRAYSIZE(MsgItems),2)==0) // всегда рвать соединение if (WNetCancelConnection2(LocalName,UpdateProfile,TRUE)!=NO_ERROR) Failed=TRUE; } else Failed=TRUE; if (Failed) { const wchar_t *MsgItems[]={GetMsg(MError),MsgText,GetMsg(MOk)}; Info.Message(&MainGuid, nullptr,FMSG_WARNING|FMSG_ERRORTYPE,NULL,MsgItems,ARRAYSIZE(MsgItems),1); return FALSE; } } return TRUE; } BOOL NetBrowser::GetDriveToDisconnect(const wchar_t *RemoteName, wchar_t *LocalName) { wchar_t LocalNames [MAX_PATH][10]; DWORD LocalNameCount = 0; DWORD i; for (i = 0; i < ConnectedList.Count(); i++) { NETRESOURCE &connRes = ConnectedList [i]; if (connRes.lpRemoteName && connRes.lpLocalName && *connRes.lpLocalName && lstrcmpi(connRes.lpRemoteName, RemoteName) == 0) { if (connRes.dwScope == RESOURCE_CONNECTED || connRes.dwScope == RESOURCE_REMEMBERED) { lstrcpy(LocalNames [LocalNameCount++], connRes.lpLocalName); if (LocalNameCount == 10) break; } } } if (!LocalNameCount) return FALSE; // hmmm... strange if (LocalNameCount == 1) lstrcpy(LocalName, LocalNames [0]); else { wchar_t MsgText [512]; FSF.sprintf(MsgText, GetMsg(MMultipleDisconnect), RemoteName); for (i=0; iFlags |= IsPersistent ? 0 : DIF_DISABLE; Builder.AddOKCancel(MYes, MCancel); if (!NeedConfirmCancelConnection() || Builder.ShowDialog()) { UpdateProfile=Opt.DisconnectMode?0:CONNECT_UPDATE_PROFILE; if (IsPersistent) { PluginSettings settings(MainGuid, Info.SettingsControl); settings.Set(0,StrDisconnectMode,Opt.DisconnectMode); } return TRUE; } return FALSE; } BOOL NetBrowser::NeedConfirmCancelConnection() { return (Info.AdvControl(&MainGuid, ACTL_GETCONFIRMATIONS, 0, NULL) & FCS_DISCONNECTNETWORKDRIVE) != 0; } BOOL NetBrowser::HandsOffDisconnectDrive(const wchar_t *LocalName) { wchar_t DirBuf [MAX_PATH]; GetCurrentDirectory(ARRAYSIZE(DirBuf)-1, DirBuf); if (FSF.LUpper(DirBuf [0]) != FSF.LUpper(LocalName [0])) return FALSE; // change to the root of the drive where network.dll resides if (!GetModuleFileName(NULL, DirBuf, ARRAYSIZE(DirBuf)-1)) return FALSE; DirBuf [3] = L'\0'; // truncate to "X:\\" return SetCurrentDirectory(DirBuf); } void NetBrowser::GetOpenPanelInfo(struct OpenPanelInfo *Info) { #ifdef NETWORK_LOGGING__ if (PCurResource) LogData(L"Entering NetBrowser::GetOpenPluginInfo. Info->Flags will contain OPIF_ADDDOTS"); else LogData(L"Entering NetBrowser::GetOpenPluginInfo. Info->Flags will NOT contain OPIF_ADDDOTS"); #endif Info->StructSize=sizeof(*Info); Info->Flags=OPIF_ADDDOTS|OPIF_RAWSELECTION|OPIF_SHOWPRESERVECASE; Info->HostFile=NULL; if (PCurResource == NULL) { Info->CurDir=L""; if (!Opt.RootDoublePoint) Info->Flags &= ~OPIF_ADDDOTS; } else { static wchar_t CurDir[MAX_PATH]; if (PCurResource->lpRemoteName==NULL) { if (CheckFavoriteItem(PCurResource)) lstrcpy(CurDir, GetMsg(MFavorites)); else lstrcpy(CurDir, PCurResource->lpProvider); } else { lstrcpy(CurDir, PCurResource->lpRemoteName); } Info->CurDir=CurDir; } Info->Format=(wchar_t *) GetMsg(MNetwork); static wchar_t Title[MAX_PATH]; FSF.sprintf(Title,L" %s: %s ",GetMsg(MNetwork), Info->CurDir); Info->PanelTitle=Title; Info->InfoLines=NULL; Info->InfoLinesNumber=0; Info->DescrFiles=NULL; Info->DescrFilesNumber=0; static struct PanelMode PanelModesArray[10]; static const wchar_t *ColumnTitles[3]; ColumnTitles[0]=GetMsg(MColumnName); ColumnTitles[1]=GetMsg(MColumnDisk); ColumnTitles[2]=GetMsg(MColumnComment); PanelModesArray[3].ColumnTypes=L"N,C0,C1"; PanelModesArray[3].ColumnWidths=L"0,2,0"; PanelModesArray[3].ColumnTitles=ColumnTitles; PanelModesArray[4].ColumnTypes=L"N,C0"; PanelModesArray[4].ColumnWidths=L"0,2"; PanelModesArray[4].ColumnTitles=ColumnTitles; PanelModesArray[5].ColumnTypes=L"N,C0,C1"; PanelModesArray[5].ColumnWidths=L"0,2,0"; PanelModesArray[5].ColumnTitles=ColumnTitles; Info->PanelModesArray=PanelModesArray; Info->PanelModesNumber=ARRAYSIZE(PanelModesArray); Info->StartPanelMode=PanelMode[0]; if (PCurResource && PCurResource->dwDisplayType == RESOURCEDISPLAYTYPE_SERVER) { Info->Flags|=OPIF_REALNAMES; static WORD FKeys[]= { VK_F3,0,0, VK_F4,0,MF4, VK_F5,0,MF5, VK_F6,0,MF6, VK_F7,0,0, VK_F8,0,MF8, VK_F5,LEFT_CTRL_PRESSED,0, VK_F6,LEFT_CTRL_PRESSED,0, VK_F3,LEFT_ALT_PRESSED,0, VK_F4,LEFT_ALT_PRESSED,0, VK_F5,LEFT_ALT_PRESSED,0, VK_F1,SHIFT_PRESSED,0, VK_F2,SHIFT_PRESSED,0, VK_F3,SHIFT_PRESSED,0, VK_F4,SHIFT_PRESSED,0, VK_F5,SHIFT_PRESSED,MSHIFTF5, VK_F6,SHIFT_PRESSED,MSHIFTF6, VK_F7,SHIFT_PRESSED,0, VK_F8,SHIFT_PRESSED,0, }; static struct KeyBarLabel kbl[ARRAYSIZE(FKeys)/3]; static struct KeyBarTitles kbt = {ARRAYSIZE(kbl), kbl}; for (size_t j=0,i=0; i < ARRAYSIZE(FKeys); i+=3, ++j) { kbl[j].Key.VirtualKeyCode = FKeys[i]; kbl[j].Key.ControlKeyState = FKeys[i+1]; if (FKeys[i+2]) { kbl[j].Text = kbl[j].LongText = GetMsg(FKeys[i+2]); } else { kbl[j].Text = kbl[j].LongText = L""; } } Info->KeyBar=&kbt; } else { static WORD FKeys[]= { VK_F3,0,0, VK_F4,0,(WORD)-1, VK_F5,0,0, VK_F6,0,0, VK_F7,0,0, VK_F8,0,(WORD)-1, VK_F5,LEFT_CTRL_PRESSED,0, VK_F6,LEFT_CTRL_PRESSED,0, VK_F3,LEFT_ALT_PRESSED,0, VK_F4,LEFT_ALT_PRESSED,0, VK_F5,LEFT_ALT_PRESSED,0, VK_F6,LEFT_ALT_PRESSED,0, VK_F1,SHIFT_PRESSED,0, VK_F2,SHIFT_PRESSED,0, VK_F3,SHIFT_PRESSED,0, VK_F4,SHIFT_PRESSED,0, VK_F5,SHIFT_PRESSED,0, VK_F6,SHIFT_PRESSED,0, VK_F7,SHIFT_PRESSED,0, VK_F8,SHIFT_PRESSED,0, }; static struct KeyBarLabel kbl[ARRAYSIZE(FKeys)/3]; static struct KeyBarTitles kbt = {ARRAYSIZE(kbl), kbl}; for (size_t j=0,i=0; i < ARRAYSIZE(FKeys); i+=3, ++j) { kbl[j].Key.VirtualKeyCode = FKeys[i]; kbl[j].Key.ControlKeyState = FKeys[i+1]; if (FKeys[i+2] != (WORD)-1) { kbl[j].Text = kbl[j].LongText = GetMsg(FKeys[i+2]); } else if (FKeys[i+2]) { if (FKeys[i] == VK_F4) { kbl[j].Text = kbl[j].LongText = (PCurResource && PCurResource->dwDisplayType == RESOURCEDISPLAYTYPE_DOMAIN)?GetMsg(MF4):L""; } else if (FKeys[i] == VK_F8) { kbl[j].Text = kbl[j].LongText = CheckFavoriteItem(PCurResource)?GetMsg(MF8Fav):L""; } } else { kbl[j].Text = kbl[j].LongText = L""; } } Info->KeyBar=&kbt; } } int NetBrowser::SetDirectory(const wchar_t *Dir,OPERATION_MODES OpMode) { if (OpMode & OPM_FIND) return TRUE; ChangeDirSuccess = TRUE; if (OpenFromFilePanel) PCurResource = NULL; BOOL TmpOpenFromFilePanel = OpenFromFilePanel; OpenFromFilePanel = FALSE; if (!Dir || lstrcmp(Dir,L"\\")==0) { PCurResource = NULL; RootResources.Clear(); return(TRUE); } if (lstrcmp(Dir,L"..")==0) { if (PCurResource == NULL) return FALSE; if (IsMSNetResource(*PCurResource)) { NETRESOURCE nrParent; NetResourceList::InitNetResource(nrParent); if (!GetResourceParent(*PCurResource, &nrParent)) PCurResource = NULL; else { CurResource = nrParent; PCurResource = &CurResource; } } else { RootResources.Pop(); PCurResource = RootResources.Top(); } return TRUE; } else { ChangeDirSuccess = TRUE; if (ChangeToDirectory(Dir, ((OpMode & OPM_FIND) != 0), 0)) return ChangeDirSuccess; if (GetLastError()==ERROR_CANCELLED) return FALSE; wchar_t AnsiDir[MAX_PATH]; lstrcpy(AnsiDir, Dir); if (AnsiDir [0] == L'/') AnsiDir [0] = L'\\'; if (AnsiDir [1] == L'/') AnsiDir [1] = L'\\'; // if still haven't found and the name starts with \\, try to jump to a // computer in a different domain if (wcsncmp(AnsiDir, L"\\\\", 2) == 0) { if (!TmpOpenFromFilePanel && wcschr(AnsiDir+2, L'\\')) { if (!IsReadable(AnsiDir)) { #ifdef NETWORK_LOGGING wchar_t szErrBuff[MAX_PATH*2]; _sntprintf(szErrBuff, ARRAYSIZE(szErrBuff), L"GetLastError = %d at line %d, file %s", GetLastError(), __LINE__, __FILE__); LogData(szErrBuff); #endif Info.Message(&MainGuid, nullptr, FMSG_WARNING | FMSG_ERRORTYPE | FMSG_MB_OK | FMSG_ALLINONE, NULL, (const wchar_t **) GetMsg(MError), 0, 0); return FALSE; } Info.PanelControl(this, FCTL_CLOSEPANEL,0, (void *)Dir); return TRUE; } ChangeDirSuccess = GotoComputer(AnsiDir); return ChangeDirSuccess; } } return(FALSE); } BOOL NetBrowser::ChangeToDirectory(const wchar_t *Dir, int IsFind, int IsExplicit) { // if we already have the resource list for the current directory, // do not scan it again if (!PCurResource || !PCurResource->lpRemoteName || lstrcmp(PCurResource->lpRemoteName, NetListRemoteName) != 0) EnumerateNetList(); wchar_t AnsiDir[MAX_PATH]; lstrcpy(AnsiDir, Dir); if (AnsiDir [0] == L'/') AnsiDir [0] = L'\\'; if (AnsiDir [1] == L'/') AnsiDir [1] = L'\\'; for (unsigned I=0; INumberOfStorages; i++) { nSize = WideCharToMultiByte(CP_ACP, 0, lpData->Storage[i].ServerName, -1, NULL, 0, NULL, NULL); if(!nSize) break; nSize += 3; CHAR *szServ =new CHAR[nSize]; szServ[0] = L'\\'; szServ[1] = L'\\'; WideCharToMultiByte(CP_ACP, 0, lpData->Storage[i].ServerName, -1, &szServ[2], nSize - 2, NULL, NULL); NETRESOURCE inRes = {0}; inRes.dwScope = RESOURCE_CONNECTED; inRes.dwType = RESOURCETYPE_ANY; inRes.lpRemoteName = szServ; DWORD dwRes; while((dwRes = WNetGetResourceInformation(&inRes, resResult, &dwBuffSize, &pszSys)) == ERROR_MORE_DATA) { resResult = (NETRESOURCE *)realloc(resResult, dwBuffSize); } if(dwRes == ERROR_SUCCESS) { if(IsResourceReadable(*resResult)) { NetResourceList::CopyNetResource(Parent, *resResult); Res = TRUE; } } delete(szServ); if(Res) break; } free(resResult); } } delete (szRes); return Res; } */ BOOL NetBrowser::GetResourceInfo(wchar_t *SrcName,LPNETRESOURCE DstNetResource) { NETRESOURCE nr = {0}; #ifdef NETWORK_LOGGING if (LogFile) _ftprintf(LogFile, L"GetResourceInfo %s\n", SrcName); #endif NETRESOURCE nrOut [32]; // provide buffer space NETRESOURCE *lpnrOut = &nrOut [0]; DWORD cbBuffer = sizeof(nrOut); LPTSTR pszSystem = NULL; // pointer to variable-length strings nr.dwDisplayType = RESOURCEDISPLAYTYPE_GENERIC; nr.dwScope = RESOURCE_GLOBALNET; nr.dwType = RESOURCETYPE_ANY; nr.dwUsage = RESOURCEUSAGE_ALL; nr.lpRemoteName = SrcName; DWORD dwError=WNetGetResourceInformation(&nr,lpnrOut,&cbBuffer,&pszSystem); // If the call fails because the buffer is too small, // call the LocalAlloc function to allocate a larger buffer. if (dwError == ERROR_MORE_DATA) { if ((lpnrOut = (LPNETRESOURCE)LocalAlloc(LMEM_FIXED, cbBuffer)) != NULL) dwError = WNetGetResourceInformation(&nr, lpnrOut, &cbBuffer, &pszSystem); } if (dwError == NO_ERROR) { if (DstNetResource) NetResourceList::CopyNetResource(*DstNetResource, *lpnrOut); #ifdef NETWORK_LOGGING if (LogFile) _ftprintf(LogFile, L"Result:\n"); LogNetResource(*DstNetResource); #endif if (lpnrOut != &nrOut [0]) LocalFree(lpnrOut); return TRUE; } #ifdef NETWORK_LOGGING else { if (LogFile) _ftprintf(LogFile, L"error %u\n", GetLastError()); } #endif return FALSE; } BOOL NetBrowser::GetResourceParent(NETRESOURCE &SrcRes, LPNETRESOURCE DstNetResource) { if (CheckFavoriteItem(&SrcRes) || Opt.FavoritesFlags & FAVORITES_UPBROWSE_TO_FAVORITES) { if (GetFavoritesParent(SrcRes, DstNetResource)) return TRUE; } #ifdef NETWORK_LOGGING if (LogFile) _ftprintf(LogFile, L"GetResourceParent( for:\n"); LogNetResource(SrcRes); #endif TSaveScreen ss; BOOL Ret=FALSE; NETRESOURCE nrOut [32]; // provide buffer space NETRESOURCE *lpnrOut = &nrOut [0]; DWORD cbBuffer = sizeof(nrOut); LPTSTR pszSystem = NULL; // pointer to variable-length strings NETRESOURCE nrSrc = SrcRes; nrSrc.dwDisplayType = RESOURCEDISPLAYTYPE_GENERIC; nrSrc.dwScope = RESOURCE_GLOBALNET; nrSrc.dwUsage = 0; nrSrc.dwType = RESOURCETYPE_ANY; DWORD dwError=WNetGetResourceInformation(&nrSrc,lpnrOut,&cbBuffer,&pszSystem); // If the call fails because the buffer is too small, // call the LocalAlloc function to allocate a larger buffer. if (dwError == ERROR_MORE_DATA) { if ((lpnrOut = (LPNETRESOURCE)LocalAlloc(LMEM_FIXED, cbBuffer)) != NULL) dwError = WNetGetResourceInformation(&nrSrc, lpnrOut, &cbBuffer, &pszSystem); } if (dwError == NO_ERROR) { #ifdef NETWORK_LOGGING if (LogFile) _ftprintf(LogFile, L"WNetGetResourceInformation() returned:\n"); LogNetResource(*lpnrOut); #endif nrSrc.lpProvider=lpnrOut->lpProvider; if (WNetGetResourceParent(&nrSrc,lpnrOut,&cbBuffer) == NO_ERROR) { if (DstNetResource) NetResourceList::CopyNetResource(*DstNetResource, *lpnrOut); #ifdef NETWORK_LOGGING if (LogFile) _ftprintf(LogFile, L"Result:\n"); LogNetResource(*DstNetResource); #endif Ret=TRUE; } if (lpnrOut != &nrOut [0]) LocalFree(lpnrOut); } return Ret; } BOOL NetBrowser::EditFavorites() { if (!PCurResource) return TRUE; // First we should determine the type of Favorite Item under cursor string Path; struct PanelInfo PInfo = {sizeof(PanelInfo)}; Info.PanelControl(this,FCTL_GETPANELINFO,0,&PInfo); size_t Size = Info.PanelControl(this, FCTL_GETPANELDIRECTORY, 0, nullptr); FarPanelDirectory* dir = static_cast(malloc(Size)); dir->StructSize = sizeof(FarPanelDirectory); Info.PanelControl(this, FCTL_GETPANELDIRECTORY, Size, dir); Path = dir->Name; free(dir); if(Path.At(Path.Len()-1) != L'\\') { Path+=L"\\"; } Size = Info.PanelControl(this,FCTL_GETPANELITEM,PInfo.CurrentItem,0); PluginPanelItem* PPI=(PluginPanelItem*)malloc(Size); if (PPI) { FarGetPluginPanelItem gpi={Size, PPI}; Info.PanelControl(this,FCTL_GETPANELITEM,PInfo.CurrentItem,&gpi); Path += PPI->FileName; free(PPI); } NETRESOURCE nr = {0}; if (GetFavoriteResource(Path, &nr)) { Path = nr.lpRemoteName; switch (nr.dwDisplayType) { case RESOURCEDISPLAYTYPE_DOMAIN: Info.Message( &MainGuid, nullptr, FMSG_ALLINONE, L"Data", (const wchar_t * const *)L"This is a domain", 0,1); break; case RESOURCEDISPLAYTYPE_SERVER: Info.Message( &MainGuid, nullptr, FMSG_ALLINONE, L"Data", (const wchar_t * const *)L"This is a SERVER", 0,1); break; default: Info.Message( &MainGuid, nullptr, FMSG_ALLINONE, L"Data", (const wchar_t * const *)Path.CPtr(), 0,1); } NetResourceList::DeleteNetResource(nr); return TRUE; } return FALSE; } int NetBrowser::ProcessKey(const INPUT_RECORD *Rec) { if ((Rec->EventType&(~0x8000))!=KEY_EVENT || !Rec->Event.KeyEvent.bKeyDown) return FALSE; int Key=Rec->Event.KeyEvent.wVirtualKeyCode; int Shift=Rec->Event.KeyEvent.dwControlKeyState&SHIFT_PRESSED; int Ctrl=Rec->Event.KeyEvent.dwControlKeyState&(LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED); int Alt=Rec->Event.KeyEvent.dwControlKeyState&(LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED); if (!Ctrl && !Alt && (Key==VK_F5 || Key==VK_F6)) { if (PCurResource && PCurResource->dwDisplayType == RESOURCEDISPLAYTYPE_SERVER) { struct PanelInfo PInfo = {sizeof(PanelInfo)}; Info.PanelControl(this,FCTL_GETPANELINFO,0,&PInfo); for (int I=0; I<(int)PInfo.SelectedItemsNumber; I++) { const wchar_t *pRemoteName=NULL; size_t Size = Info.PanelControl(this,FCTL_GETSELECTEDPANELITEM,I,0); PluginPanelItem* PPI=(PluginPanelItem*)malloc(Size); if (PPI) { FarGetPluginPanelItem gpi={Size, PPI}; Info.PanelControl(this,FCTL_GETSELECTEDPANELITEM,I,&gpi); pRemoteName = PPI->FileName; if (!Opt.FullPathShares) { for (unsigned I=0; IFileName,RemoteName)==0) { pRemoteName = NetList[I].lpRemoteName; break; } } } } if (!PPI||!MapNetworkDrive(pRemoteName, (Key == VK_F6), (Shift==0))) { free(PPI); break; } free(PPI); } Info.PanelControl(this,FCTL_UPDATEPANEL,0,0); Info.PanelControl(this,FCTL_REDRAWPANEL,0,0); } return(TRUE); } else if (Key == L'F' && Ctrl) { FileNames2Clipboard(TRUE); return TRUE; } else if (Key == VK_INSERT && Alt && Shift) { FileNames2Clipboard(FALSE); return TRUE; } else if (Key == VK_INSERT && Alt && Ctrl) { FileNames2Clipboard(FALSE); return TRUE; } else if (Key == VK_F4 && !Alt && !Ctrl && !Shift) { struct PanelInfo PInfo = {sizeof(PanelInfo)}; Info.PanelControl(this,FCTL_GETPANELINFO,0,&PInfo); size_t Size = Info.PanelControl(this,FCTL_GETSELECTEDPANELITEM,0,0); PluginPanelItem* PPI=(PluginPanelItem*)malloc(Size); if (PPI) { FarGetPluginPanelItem gpi={Size, PPI}; Info.PanelControl(this,FCTL_GETSELECTEDPANELITEM,0,&gpi); } if (PPI&&lstrcmp(PPI->FileName,L"..")) if (ChangeToDirectory(PPI->FileName, FALSE, TRUE)) if (FSF.PointToName(PPI->FileName) - PPI->FileName <= 2) { Info.PanelControl(this,FCTL_UPDATEPANEL,1,0); PanelRedrawInfo ri = {0}; ri.CurrentItem = ri.TopPanelItem = 0; Info.PanelControl(this,FCTL_REDRAWPANEL,0,&ri); } free(PPI); return TRUE; } else if (Key == VK_F4 && Shift) { EditFavorites(); return TRUE; } else if (Key == VK_F7 && !Alt && !Ctrl && !Shift) { CreateFavSubFolder(); return TRUE; } // disable processing of F3 - avoid unnecessary slowdown else if ((Key == VK_F3 || Key == VK_CLEAR) && !Ctrl && !Shift) { return TRUE; } else if ((Key == VK_PRIOR || Key == 0xDC) && Ctrl && !PCurResource && !Opt.RootDoublePoint) { return TRUE; } return FALSE; } BOOL NetBrowser::MapNetworkDrive(const wchar_t *RemoteName, BOOL AskDrive, BOOL Permanent) { wchar_t AnsiRemoteName[MAX_PATH]; lstrcpy(AnsiRemoteName, RemoteName); DWORD DriveMask=GetLogicalDrives(); wchar_t NewLocalName[10]; *NewLocalName=0; if (!AskDrive) GetFreeLetter(DriveMask,NewLocalName); else { if (!AskMapDrive(NewLocalName, Permanent)) return FALSE; } if (*NewLocalName) { NETRESOURCE newnr; // wchar_t LocalName[10]; newnr.dwType=RESOURCETYPE_DISK; newnr.lpLocalName=NewLocalName; newnr.lpRemoteName=AnsiRemoteName; newnr.lpProvider=NULL; for (;;) { if (IsReadable(AnsiRemoteName)) { if (AddConnection(&newnr,Permanent)) break; } else if ((AddConnectionFromFavorites(&newnr, Permanent) || AddConnectionExplicit(&newnr, Permanent)) && IsReadable(newnr.lpLocalName)) break; else if (ERROR_CANCELLED == GetLastError()) break; if (GetLastError()==ERROR_DEVICE_ALREADY_REMEMBERED) { if (!AskDrive) { GetFreeLetter(DriveMask,NewLocalName); if (*NewLocalName==0) { const wchar_t *MsgItems[]={GetMsg(MError),GetMsg(MNoFreeLetters),GetMsg(MOk)}; Info.Message(&MainGuid, nullptr,FMSG_WARNING|FMSG_ERRORTYPE,NULL,MsgItems,ARRAYSIZE(MsgItems),1); return FALSE; } } else { const wchar_t *MsgItems[]={GetMsg(MError),GetMsg(MAlreadyRemembered),GetMsg(MOk)}; Info.Message(&MainGuid, nullptr,FMSG_WARNING|FMSG_ERRORTYPE,NULL,MsgItems,ARRAYSIZE(MsgItems),1); return FALSE; } } else { wchar_t MsgText[300]; FSF.sprintf(MsgText,GetMsg(MNetCannotConnect),RemoteName,NewLocalName); const wchar_t *MsgItems[]={GetMsg(MError),MsgText,GetMsg(MOk)}; Info.Message(&MainGuid, nullptr,FMSG_WARNING|FMSG_ERRORTYPE,NULL,MsgItems,ARRAYSIZE(MsgItems),1); return FALSE; } } } else { const wchar_t *MsgItems[]={GetMsg(MError),GetMsg(MNoFreeLetters),GetMsg(MOk)}; Info.Message(&MainGuid, nullptr,FMSG_WARNING|FMSG_ERRORTYPE,NULL,MsgItems,ARRAYSIZE(MsgItems),1); return FALSE; } return TRUE; } BOOL NetBrowser::AskMapDrive(wchar_t *NewLocalName, BOOL &Permanent) { int ExitCode = 0; for (;;) { struct FarMenuItem MenuItems['Z'-'A'+1]; int MenuItemsNumber=0; memset(MenuItems,0,sizeof(MenuItems)); wchar_t umname[ARRAYSIZE(MenuItems)][4]; memset(umname, 0, sizeof(umname)); for (size_t n = 0; n < ARRAYSIZE(MenuItems); n++) MenuItems[n].Text = umname[n]; DWORD DriveMask=GetLogicalDrives(); for (int I=0; I<='Z'-'A'; I++) if ((DriveMask & (1<lpRemoteName; int n = (int)(FSF.PointToName(p) - p); if (n <= 2) lstrcpyn(szServer, p + n, ARRAYSIZE(szServer)); else { while (*++p == L'\\') n--; if (n > MAX_PATH) n = MAX_PATH; lstrcpyn(szServer, p, n-1); } FSF.sprintf(Name, L"%s\\%s", szServer, szNameCopy); //Try again to log on with the transformed user name. continue; } return FALSE; } } int NetBrowser::AddConnectionFromFavorites(NETRESOURCE *nr,int Remember) { //Try to search login info in registry if (nr) { wchar_t Name[MAX_PATH]; wchar_t Pass[MAX_PATH]; Name[0] = Pass[0] = 0; FAVORITEITEM Item = { nr->lpRemoteName, lstrlen(nr->lpRemoteName), Name, ARRAYSIZE(Name), Pass, ARRAYSIZE(Pass) }; if (ReadFavoriteItem(&Item)) { return AddConnectionWithLogon(nr, Name, Pass, Remember); } } return FALSE; } void NetBrowser::DisconnectFromServer(NETRESOURCE *nr) { //First we should know a name of the server int n = (int)(FSF.PointToName(nr->lpRemoteName) - nr->lpRemoteName); if (n <= 2) n = lstrlen(nr->lpRemoteName) + 1; wchar_t *szServer = (wchar_t*)malloc((n + 1)*sizeof(wchar_t)); if (szServer) { wchar_t *szBuff = (wchar_t*)malloc((n + 1)*sizeof(wchar_t)); if (szBuff) { lstrcpyn(szServer, nr->lpRemoteName, n); NETRESOURCE *lpBuff = 0; HANDLE hEnum; if (NO_ERROR == WNetOpenEnum(RESOURCE_CONNECTED, RESOURCETYPE_ANY, 0, NULL, &hEnum)) { DWORD cCount = (DWORD)-1; DWORD nBuffSize = 0; //Let's determine buffer's size we need to store all the connections if (ERROR_MORE_DATA == WNetEnumResource(hEnum, &cCount, NULL, &nBuffSize)) { lpBuff = (NETRESOURCE*)malloc(nBuffSize); if (lpBuff) { cCount = (DWORD)-1; if (NO_ERROR != WNetEnumResource(hEnum, &cCount, lpBuff, &nBuffSize)) free(lpBuff), lpBuff = NULL; } } WNetCloseEnum(hEnum); if (lpBuff) { for (DWORD i = 0; i < cCount; i++) { lstrcpyn(szBuff, lpBuff[i].lpRemoteName, n); if (0 == lstrcmpi(szServer, szBuff)) WNetCancelConnection2(lpBuff[i].lpRemoteName, 0, TRUE); } free(lpBuff); } } free(szBuff); } //Trying harder to disconnect from the server WNetCancelConnection2(szServer, 0, TRUE); free(szServer); } //Let's check the current dir and if it's remote try to change it to %TMP% wchar_t lpszPath[MAX_PATH]; if (GetCurrentDirectory(MAX_PATH, lpszPath)) { if (lpszPath[0] == L'\\') { ExpandEnvironmentStrings(L"%TMP%", lpszPath, MAX_PATH); SetCurrentDirectory(lpszPath); } } } void NetBrowser::GetLocalName(wchar_t *RemoteName,wchar_t *LocalName) { *LocalName=0; if (RemoteName!=NULL && *RemoteName) for (int I=ConnectedList.Count()-1; I>=0; I--) if (ConnectedList [I].lpRemoteName && ConnectedList [I].lpLocalName!=NULL && *ConnectedList [I].lpLocalName && lstrcmpi(ConnectedList [I].lpRemoteName,RemoteName)==0) { if (ConnectedList [I].dwScope==RESOURCE_CONNECTED || ConnectedList [I].dwScope==RESOURCE_REMEMBERED) lstrcpy(LocalName, ConnectedList[I].lpLocalName); break; } } int NetBrowser::GetNameAndPassword(NameAndPassInfo* passInfo) { static wchar_t LastName[256],LastPassword[256]; PluginDialogBuilder Builder(Info, MainGuid, UserPassDialogGuid, passInfo->Title ? passInfo->Title : L"", StrHelpNetBrowse); Builder.AddText(MNetUserName); Builder.AddEditField(LastName, ARRAYSIZE(LastName), 60, L"NetworkUser", true); Builder.AddText(MNetUserPassword); Builder.AddPasswordField(LastPassword, ARRAYSIZE(LastPassword), 60); Builder.AddSeparator(); int disabled = 0; if (passInfo->pRemember) Builder.AddCheckbox(MRememberPass, passInfo->pRemember); else Builder.AddCheckbox(MRememberPass, &disabled)->Flags |= DIF_DISABLE; Builder.AddOKCancel(MOk, MCancel); if (Builder.ShowDialog()) { lstrcpy(passInfo->Name, LastName); lstrcpy(passInfo->Password, LastPassword); return TRUE; } return FALSE; } void NetBrowser::FileNames2Clipboard(BOOL ToCommandLine) { PanelInfo PInfo = {sizeof(PanelInfo)}; Info.PanelControl(this, FCTL_GETPANELINFO,0,&PInfo); wchar_t CurFile [MAX_PATH]; wchar_t *CopyData=nullptr; long DataSize=0; if (ToCommandLine) { if (PInfo.ItemsNumber > 0) { wchar_t CurFile [MAX_PATH]; size_t Size = Info.PanelControl(this,FCTL_GETPANELITEM,PInfo.CurrentItem,0); PluginPanelItem* PPI=(PluginPanelItem*)malloc(Size); if (PPI) { FarGetPluginPanelItem gpi={Size, PPI}; Info.PanelControl(this,FCTL_GETPANELITEM,PInfo.CurrentItem,&gpi); lstrcpy(CurFile,PPI->FileName); free(PPI); } if (!lstrcmp(CurFile, L"..")) { if (PCurResource == NULL) lstrcpy(CurFile, L".\\"); else lstrcpy(CurFile, PCurResource->lpRemoteName); } FSF.QuoteSpaceOnly(CurFile); lstrcat(CurFile, L" "); Info.PanelControl(this, FCTL_INSERTCMDLINE,0,CurFile); } return; } for (size_t I=0; I < PInfo.SelectedItemsNumber; ++I) { if (DataSize > 0) { lstrcat(CopyData+DataSize,L"\r\n"); DataSize+=2; } size_t Size = Info.PanelControl(this,FCTL_GETSELECTEDPANELITEM,I,0); PluginPanelItem* PPI=(PluginPanelItem*)malloc(Size); if (PPI) { FarGetPluginPanelItem gpi={Size, PPI}; Info.PanelControl(this,FCTL_GETSELECTEDPANELITEM,I,&gpi); lstrcpy(CurFile,PPI->FileName); if (!lstrcmp(CurFile, L"..")) { if (PCurResource == NULL) lstrcpy(CurFile, L".\\"); else lstrcpy(CurFile, PCurResource->lpRemoteName); } FSF.QuoteSpaceOnly(CurFile); int Length=lstrlen(CurFile); wchar_t *NewPtr=(wchar_t *)realloc(CopyData, (DataSize+Length+3)*sizeof(wchar_t)); if (!NewPtr) { if (CopyData) { free(CopyData); CopyData=nullptr; } } else { CopyData=NewPtr; CopyData[DataSize]=0; lstrcpy(CopyData+DataSize, CurFile); DataSize+=Length; } free(PPI); if (!CopyData) break; } } if (CopyData) { FSF.CopyToClipboard(CopyData); free(CopyData); } } void NetBrowser::ManualConnect() { PanelInfo PInfo = {sizeof(PanelInfo)}; Info.PanelControl(this, FCTL_GETPANELINFO,0,&PInfo); if (PInfo.ItemsNumber) { size_t Size = Info.PanelControl(this,FCTL_GETPANELITEM,PInfo.CurrentItem,0); PluginPanelItem* PPI=(PluginPanelItem*)malloc(Size); if (PPI) { FarGetPluginPanelItem gpi={Size, PPI}; Info.PanelControl(this,FCTL_GETPANELITEM,PInfo.CurrentItem,&gpi); ChangeToDirectory(PPI->FileName, FALSE, TRUE); free(PPI); } } } void NetBrowser::GetRemoteName(NETRESOURCE *NetRes,wchar_t *RemoteName) { if (CheckFavoriteItem(NetRes)) { if (!NetRes->lpRemoteName) { lstrcpy(RemoteName, GetMsg(MFavorites)); } else { free(NetRes->lpComment); NetRes->lpComment = NetResourceList::CopyText(GetMsg(MFavoritesFolder)); lstrcpy(RemoteName, FSF.PointToName(NetRes->lpRemoteName)); } } else if (NetRes->lpProvider!=NULL && (NetRes->lpRemoteName==NULL || NetRes->dwDisplayType==RESOURCEDISPLAYTYPE_NETWORK)) lstrcpy(RemoteName,NetRes->lpProvider); else if (NetRes->lpRemoteName==NULL) *RemoteName=0; else if (Opt.FullPathShares) lstrcpy(RemoteName,NetRes->lpRemoteName); else lstrcpy(RemoteName,FSF.PointToName(NetRes->lpRemoteName)); } BOOL NetBrowser::IsReadable(const wchar_t *Remote) { wchar_t Mask[MAX_PATH]; if (*Remote == L'\\' && *(Remote+1) == L'\\') FSF.sprintf(Mask,L"\\\\?\\UNC%s\\*",Remote+1); else FSF.sprintf(Mask,L"%s\\*",Remote); HANDLE FindHandle; WIN32_FIND_DATA FindData; FindHandle=FindFirstFile(Mask,&FindData); DWORD err = GetLastError(); FindClose(FindHandle); SetLastError(err); if (err == ERROR_FILE_NOT_FOUND) { SetLastError(0); return TRUE; } return(FindHandle!=INVALID_HANDLE_VALUE); } void NetBrowser::SetOpenFromCommandLine(wchar_t *ShareName) { //lstrcpy (CmdLinePath, ShareName); #ifdef NETWORK_LOGGING LogData(L"SetOpenFromCommandLine ShareName is"); LogData(ShareName); #endif lstrcpy(CmdLinePath, ShareName); /*if(!GotoFavorite(ShareName)) GotoComputer(ShareName);*/ } BOOL NetBrowser::SetOpenFromFilePanel(wchar_t *ShareName) { NETRESOURCE nr; NetResourceList::InitNetResource(nr); if (!GetResourceInfo(ShareName, &nr)) return FALSE; if (!IsMSNetResource(nr)) return FALSE; OpenFromFilePanel = TRUE; return TRUE; } int NetBrowser::GotoComputer(const wchar_t *Dir) { #ifdef NETWORK_LOGGING LogData(L"Entering GotoComputer"); #endif // if there are backslashes in the name, truncate them wchar_t ComputerName [MAX_PATH]; lstrcpy(ComputerName, Dir); BOOL IsShare = FALSE; wchar_t *p = wcschr(ComputerName + 2, L'\\'); // skip past leading backslashes if (p) { IsShare = TRUE; *p = L'\0'; } else { p = wcschr(ComputerName + 2, L'/'); if (p) { IsShare = TRUE; *p = L'\0'; } } CharUpper(ComputerName); NETRESOURCE res; NetResourceList::InitNetResource(res); if (!GetResourceInfo(ComputerName, &res)) return FALSE; /* if (!IsMSNetResource (res)) return FALSE; */ if (!IsResourceReadable(res)) { int err = GetLastError(); if (err == ERROR_INVALID_PASSWORD || err == ERROR_LOGON_FAILURE || err == ERROR_ACCESS_DENIED || err == ERROR_INVALID_HANDLE || err == ERROR_LOGON_TYPE_NOT_GRANTED) if (!((AddConnectionFromFavorites(&res)||AddConnectionExplicit(&res))&&IsResourceReadable(res))) { if (GetLastError() != ERROR_CANCELLED) Info.Message(&MainGuid, nullptr, FMSG_WARNING|FMSG_ERRORTYPE|FMSG_MB_OK|FMSG_ALLINONE, NULL, (const wchar_t **) GetMsg(MError), 0, 0); return FALSE; } } CurResource = res; PCurResource = &CurResource; /*int result = */Info.PanelControl(this, FCTL_UPDATEPANEL,0,0); if (IsShare) { wchar_t ShareName [MAX_PATH]; lstrcpy(ShareName, Dir); // replace forward slashes with backslashes for (p = ShareName; *p; p++) if (*p == L'/') *p = L'\\'; SetCursorToShare(ShareName); } else Info.PanelControl(this, FCTL_REDRAWPANEL,0,0); return TRUE; } void NetBrowser::GotoLocalNetwork() { TSaveScreen ss; wchar_t ComputerName [MAX_PATH]; lstrcpy(ComputerName, L"\\\\"); DWORD ComputerNameLength = MAX_PATH-3; if (!GetComputerName(ComputerName+2, &ComputerNameLength)) return; NETRESOURCE res; NetResourceList::InitNetResource(res); if (!GetResourceInfo(ComputerName, &res) || !IsMSNetResource(res)) return; NETRESOURCE parent; NetResourceList::InitNetResource(parent); if (!GetResourceParent(res, &parent)) return; NetResourceList::CopyNetResource(CurResource, parent); PCurResource = &CurResource; Info.PanelControl(this, FCTL_UPDATEPANEL,0,0); Info.PanelControl(this, FCTL_REDRAWPANEL,0,0); } void NetBrowser::SetCursorToShare(wchar_t *Share) { PanelInfo PInfo = {sizeof(PanelInfo)}; // this returns the items in sorted order, so we can position correctly Info.PanelControl(this, FCTL_GETPANELINFO,0,&PInfo); if (PInfo.ItemsNumber) { // prevent recursion for (int i=0; i<(int)PInfo.ItemsNumber; i++) { wchar_t szAnsiName[MAX_PATH]; size_t Size = Info.PanelControl(this,FCTL_GETPANELITEM,i,0); PluginPanelItem* PPI=(PluginPanelItem*)malloc(Size); if (PPI) { FarGetPluginPanelItem gpi={Size, PPI}; Info.PanelControl(this,FCTL_GETPANELITEM,i,&gpi); lstrcpy(szAnsiName,PPI->FileName); free(PPI); } if (!FSF.LStricmp(szAnsiName, Opt.FullPathShares?Share:FSF.PointToName(Share))) { PanelRedrawInfo info; info.CurrentItem = i; info.TopPanelItem = 0; Info.PanelControl(this, FCTL_REDRAWPANEL,0,&info); break; } } } } void WINAPI ExitFARW(const ExitInfo *Info) { delete CommonRootResources; NetResourceList::DeleteNetResource(CommonCurResource); } void NetBrowser::RemoveItems() { if (!CheckFavoriteItem(PCurResource)) return; // We are in Favorites folder, so we can remove items from this folder struct PanelInfo PInfo = {sizeof(PanelInfo)}; Info.PanelControl(this,FCTL_GETPANELINFO,0,&PInfo); if (PInfo.SelectedItemsNumber <= 0) // Something strange is happen { return; } wchar_t szConfirmation[MAX_PATH*2]; if (PInfo.SelectedItemsNumber == 1) { size_t Size = Info.PanelControl(this,FCTL_GETSELECTEDPANELITEM,0,0); PluginPanelItem* PPI=(PluginPanelItem*)malloc(Size); if (PPI) { FarGetPluginPanelItem gpi={Size, PPI}; Info.PanelControl(this,FCTL_GETSELECTEDPANELITEM,0,&gpi); FSF.sprintf(szConfirmation, GetMsg(MRemoveFavItem), PPI->FileName); free(PPI); } } else // PInfo.SelectedItemsNumber > 1 FSF.sprintf(szConfirmation, GetMsg(MRemoveFavItems), PInfo.SelectedItemsNumber); const wchar_t* Msg[4]; Msg[0] = GetMsg(MRemoveFavCaption); Msg[1] = szConfirmation; Msg[2] = GetMsg(MOk); Msg[3] = GetMsg(MCancel); if (0 != Info.Message(&MainGuid, nullptr, FMSG_WARNING, L"RemoveItemFav", Msg, ARRAYSIZE(Msg), 2)) { return; // User canceled deletion } wchar_t szName[MAX_PATH*2] = {0}; lstrcpy(szName, PCurResource->lpRemoteName); wchar_t* p = szName + lstrlen(szName); if ((p>szName)&&(p[-1] != L'\\')) *p++ = L'\\'; for (int i = 0; i < (int)PInfo.SelectedItemsNumber; i++) { size_t Size = Info.PanelControl(this,FCTL_GETSELECTEDPANELITEM,i,0); PluginPanelItem* PPI=(PluginPanelItem*)malloc(Size); if (PPI) { FarGetPluginPanelItem gpi={Size, PPI}; Info.PanelControl(this,FCTL_GETSELECTEDPANELITEM,i,&gpi); lstrcpy(p,PPI->FileName); free(PPI); } RemoveFromFavorites(szName, NULL, NULL); } Info.PanelControl(this, FCTL_UPDATEPANEL,0,0); Info.PanelControl(this, FCTL_REDRAWPANEL,0,0); } void NetBrowser::CreateFavSubFolder() { if (!CheckFavoriteItem(PCurResource)) return; wchar_t buff[MAX_PATH]; if (DlgCreateFolder(buff, ARRAYSIZE(buff))) { if (!CreateSubFolder(PCurResource->lpRemoteName, buff)) { ShowMessage(L"Failed to create folder"); return; } Info.PanelControl(this,FCTL_UPDATEPANEL,0,0); Info.PanelControl(this,FCTL_REDRAWPANEL,0,0); } } void NetBrowser::GetHiddenShares() { wchar_t lpwsNetPath[MAX_PATH]; PSHARE_INFO_1 BufPtr, p; NET_API_STATUS res; if (PCurResource == NULL) return; LPTSTR lpszServer = PCurResource->lpRemoteName; wchar_t szResPath [MAX_PATH]; LPTSTR pszSystem; NETRESOURCE pri; NETRESOURCE nr [256]; DWORD er=0,tr=0,resume=0,rrsiz; lstrcpyn(lpwsNetPath,lpszServer,ARRAYSIZE(lpwsNetPath)); do { res = NetShareEnum((LPWSTR)lpwsNetPath, 1, (LPBYTE *) &BufPtr, MAX_PREFERRED_LENGTH, &er, &tr, &resume); if (res == ERROR_SUCCESS || res == ERROR_MORE_DATA) { p=BufPtr; for (DWORD J=0; J < er; J++) { memset((void *)&pri,0,sizeof(pri)); pri.dwScope = RESOURCE_GLOBALNET; pri.dwType = RESOURCETYPE_DISK; pri.lpLocalName = NULL; lstrcpy(szResPath,lpszServer); lstrcat(szResPath,L"\\"); { size_t pos = lstrlen(szResPath); lstrcpyn(&szResPath[pos], p->shi1_netname, (int)(ARRAYSIZE(szResPath)-pos)); } if (szResPath[lstrlen(szResPath)-1] == L'$' && lstrcmp(&szResPath[lstrlen(szResPath)-4],L"IPC$")) { pri.lpRemoteName = szResPath; pri.dwUsage = RESOURCEUSAGE_CONTAINER; pri.lpProvider = NULL; rrsiz = sizeof(nr); // we need to provide buffer space for WNetGetResourceInformation int rc = WNetGetResourceInformation(&pri,(void *)&nr [0],&rrsiz,&pszSystem); if (rc!=NO_ERROR) { p++; continue; //break; //????? } switch(p->shi1_type) { case STYPE_DISKTREE: case STYPE_SPECIAL: nr [0].dwType=RESOURCETYPE_DISK; break; case STYPE_PRINTQ: nr [0].dwType=RESOURCETYPE_PRINT; break; } NetList.Push(nr [0]); } p++; } NetApiBufferFree(BufPtr); } if (res == ERROR_SUCCESS) break; } while (res==ERROR_MORE_DATA); }