Beispiel #1
0
//---------------------------------------------------------------------------------
void FTP::SaveUsedDirNFile(void)
{
	PROC(("SaveUsedDirNFile","was:(%s,%s)",Host.Home,SelectFile.c_str()))
	PanelInfo pi;

	//Save current file to restore
	if(!ShowHosts && hConnect)
	{
		String s;
		FtpGetCurrentDirectory(hConnect,s);
		StrCpy(Host.Home, s.c_str(), ARRAYSIZE(Host.Home));
	}

	//Save current file to restore
	if(FP_Info->Control(this,FCTL_GETPANELINFO,&pi))
	{
		if(pi.ItemsNumber > 0 && pi.CurrentItem < pi.ItemsNumber)
		{
			SelectFile = FTP_FILENAME(&pi.PanelItems[pi.CurrentItem]);
			Log(("SetLastHost: [%s]", SelectFile.c_str()));
		}

		Log(("Saved (%s,%s)",Host.Home,SelectFile.c_str()));
	}
}
Beispiel #2
0
void FTP::FTP_FixPaths(LPCSTR base, PluginPanelItem *p, int cn, BOOL FromPlugin)
{
	String str;

	if(!base || !base[0])
		return;

	for(; cn--; p++)
	{
		char *CurName = FTP_FILENAME(p);

		if(StrCmp(CurName,"..") == 0 ||
		        StrCmp(CurName,".") == 0)
			continue;

		str.printf("%s%c%s", base, FromPlugin ? '/' : '\\', CurName);
		StrCpy(p->FindData.cFileName, str.c_str(), ARRAYSIZE(p->FindData.cFileName));

		if(str.Length() >= (int)ARRAYSIZE(p->FindData.cFileName))
			FPIL_ADDSET(p, str.Length()+1, strdup(str.c_str()));
		else
			FPIL_ADDSET(p, 0, NULL);
	}
}
Beispiel #3
0
BOOL ParseDirLine(Connection *Connect,BOOL AllFiles,FTPFileInfo* p)
{
	PROC(("ParseDirLine", "%p,%d", Connect, AllFiles))
	String        Line, Line1;
	FTPDirList    dl;
	FTPServerInfo si;

	while(true)
	{
		Connect->GetOutput(Line);

		if(!Line.Length())
			break;

		if(strstr(Line.c_str(),": Permission denied"))
		{
			WINPORT(SetLastError)(ERROR_ACCESS_DENIED);
			return FALSE;
		}

		if(Line.Length() < 20)
			continue;

		//Check contains skipped text
		static LPCSTR FTPMsg[] =
		{
			"data connection",
			"transfer complete",
			"bytes received",
			"DEVICE:[",
			"Total of "
		};
		BOOL Found = FALSE;

		for(size_t n = 0; n < ARRAYSIZE(FTPMsg); n++)
			if(strstr(Line.c_str(),FTPMsg[n]))
			{
				Found = TRUE;
				break;
			}

		if(Found) continue;

		//Check special skip strings
		if(StrCmp(Line.c_str(), "Directory ", 10) == 0 &&
		        strchr(Line.c_str()+10,'[') != NULL)
			continue;

		//Set start detect info
		memset(p, 0, sizeof(*p));
		si.ServerType = Connect->Host.ServerType;
		StrCpy(si.ServerInfo, Connect->SystemInfo, ARRAYSIZE(si.ServerInfo));
		//Use temp buffer
		Line1 = Line;
		//Detect
		WORD     idx;
		FTPType* tp = dl.GetType(Connect->Host.ServerType);

		if(Connect->Host.ServerType == FTP_TYPE_DETECT ||
		        Connect->Host.ServerType == FTP_TYPE_INVALID ||
		        tp == NULL)
		{
			idx = dl.DetectStringType(&si, Line.c_str(), Line.Length());

			if(idx == FTP_TYPE_INVALID || (tp=dl.GetType(idx)) == NULL)
			{
				LogCmd(Message("ParserDETECT: %s->%s [%s]", Parser2Str(Connect->Host.ServerType,&dl), Parser2Str(idx,&dl), Line1.c_str()), ldInt);

				if(Connect->Host.ServerType != FTP_TYPE_DETECT &&
				        Connect->Host.ServerType != FTP_TYPE_INVALID)
				{
					LogCmd(Message("ParserIGNORE: [%s]", Line1.c_str()), ldInt);
					Connect->AddCmdLine(Message("ParserIGNORE: [%s]", Line1.c_str()));
					continue;
				}

				BadFormat(Connect,Line1.c_str(),FALSE);
				break;
			}
			else
			{
				Log(("ParserDETECTED: %s->%s [%s]",Parser2Str(Connect->Host.ServerType,&dl),Parser2Str(idx,&dl),Line1.c_str()));
				Connect->Host.ServerType = idx;
			}
		}
		else
			idx = Connect->Host.ServerType;

		//Use temp buffer
		Line = Line1;
		Log(("toParse: %d,[%s], %d",Line.Length(),Line.c_str()));

		//Parse
		if(!tp->Parser(&si,p,Line.c_str(),Line.Length()))
		{
			LogCmd(Message("ParserFAIL: %s->%s [%s]",
			               Parser2Str(Connect->Host.ServerType,&dl),
			               Parser2Str(idx,&dl),
			               Line1.c_str()),
			       ldInt);
			Connect->AddCmdLine(Message("ParserFAIL: (%s) [%s]", Parser2Str(idx,&dl), Line1.c_str()));
			continue;
		}

		//Skip entryes
		char *CurName = FTP_FILENAME(p);

		if(p->FileType == NET_SKIP ||
		        !CurName[0] ||
		        StrCmp(CurName,".") == 0 ||
		        (!AllFiles && StrCmp(CurName,"..") == 0))
			continue;

		//Correct attrs
		if(p->FileType == NET_DIRECTORY ||
		        p->FileType == NET_SYM_LINK_TO_DIR)
			SET_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY);

		if(p->FileType == NET_SYM_LINK_TO_DIR ||
		        p->FileType == NET_SYM_LINK)
			SET_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_REPARSE_POINT);

		//Convert name text
//		Connect->ToOEM(CurName);
		//OK
		return TRUE;
	}

	WINPORT(SetLastError)(ERROR_NO_MORE_FILES);
	return FALSE;
}
Beispiel #4
0
int FTP::GetFindData(PluginPanelItem **pPanelItem, int *pItemsNumber, int OpMode)
{
	PROC(("FTP::GetFindData",NULL))
	DWORD        b,e;
	char            *Data[3];
	*pPanelItem   = NULL;
	*pItemsNumber = 0;

//Hosts
	if(ShowHosts)
	{
		EnumHost        Enum(HostsPath);
		FP_SizeItemList il(FALSE);
		PluginPanelItem tmp;
		FTPHost         h;

		if(!IS_SILENT(OpMode))
		{
			memset(&tmp, 0, sizeof(tmp));
			strcpy(tmp.FindData.cFileName,"..");
			tmp.FindData.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;

			if(!IS_SILENT(OpMode))
			{
				tmp.Description               = (char *)"..";
				tmp.CustomColumnNumber        = 3;
				tmp.CustomColumnData          = Data;
				tmp.CustomColumnData[0]       = (char *)"..";
				tmp.CustomColumnData[1]       = (char *)"..";
				tmp.CustomColumnData[2]       = (char *)"..";
			}

			if(!il.Add(&tmp))
				return FALSE;
		}

		while(true)
		{
			if(!Enum.GetNextHost(&h))
				break;

			if(!h.Read(NULL))
				continue;

			memset(&tmp, 0, sizeof(tmp));
			/* Panel item MUST have name the save as file saved to disk
			   in case you want to copy between panels work.
			*/
			h.MkINIFile(tmp.FindData.cFileName,NULL,"");
			tmp.FindData.ftLastWriteTime  = h.LastWrite;
			tmp.FindData.dwFileAttributes = h.Folder ? FILE_ATTRIBUTE_DIRECTORY : 0;
			tmp.Flags                     = PPIF_USERDATA;
			tmp.PackSizeHigh              = FTP_HOSTID;
			tmp.UserData                  = (DWORD_PTR)&h;

			if(!IS_SILENT(OpMode))
			{
				tmp.Description               = h.HostDescr;
				tmp.CustomColumnNumber        = 3;
				tmp.CustomColumnData          = Data;
				tmp.CustomColumnData[0]       = h.Host;  //C0
				tmp.CustomColumnData[1]       = h.Home;  //C1
				tmp.CustomColumnData[2]       = h.User;  //C2
			}

			if(!il.Add(&tmp))
				return FALSE;

			Log(("Item[%d]=[%s] attr=%08X",
			     il.Count()-1, FTP_FILENAME(il.Item(il.Count()-1)),
			     il.Item(il.Count()-1)->FindData.dwFileAttributes));
		}

		*pPanelItem   = il.Items();
		*pItemsNumber = il.Count();
		return TRUE;
	}

//FTP
	FP_Screen _scr;
	FTPFileInfo FileInfo;

	if(!hConnect)
	{
		goto AskConnect;
	}

Restart:

	if(!FtpFindFirstFile(hConnect, "*", &FileInfo, &ResetCache))
	{
		if(GetLastError() == ERROR_NO_MORE_FILES)
		{
			*pItemsNumber = 0;
			return TRUE;
		}

		if(SwitchingToFTP && GetLastError() == ERROR_CANCELLED)
		{
			;
		}
		else
		{
			if(CurrentState == fcsExpandList)
			{
				FreeFindData(*pPanelItem,*pItemsNumber);
				*pPanelItem   = NULL;
				*pItemsNumber = 0;
				return FALSE;
			}

//Query reconnect
			do
			{
				if(!hConnect)
					break;

				if(GetLastError() == ERROR_CANCELLED)
					break;

				if(!hConnect->ConnectMessageTimeout(MConnectionLost,Host.HostName,-MRestore))
				{
					Log(("WaitMessage cancelled"));
					break;
				}

				if(FtpCmdLineAlive(hConnect) &&
				        FtpKeepAlive(hConnect))
					goto Restart;

				if(SelectFile.Length() && CurrentState != fcsExpandList)
					SaveUsedDirNFile();

AskConnect:

				if(Connect())
					goto Restart;
				else
					break;
			}
			while(true);
		}

		if(!ShowHosts)
			BackToHosts();

		FreeFindData(*pPanelItem, *pItemsNumber);
		return GetFindData(pPanelItem,pItemsNumber,OpMode);
	}

	GET_TIME(b);

	do
	{
		if(Opt.ShowIdle)
		{
			char str[ 200 ];
			GET_TIME(e);

			if(CMP_TIME(e,b) > 0.5)
			{
				_snprintf(str,ARRAYSIZE(str),"%s%d", FP_GetMsg(MReaded), *pItemsNumber);
				SetLastError(ERROR_SUCCESS);
				IdleMessage(str,Opt.ProcessColor);
				b = e;

				if(CheckForEsc(FALSE))
				{
					SetLastError(ERROR_CANCELLED);
					return FALSE;
				}
			}
		}

		PluginPanelItem *NewPanelItem=*pPanelItem;

		if((*pItemsNumber % 1024) == 0)
		{
			if(!NewPanelItem)
				NewPanelItem = (PluginPanelItem *)malloc((1024+1)*sizeof(PluginPanelItem));
			else
				NewPanelItem = (PluginPanelItem *)realloc(NewPanelItem,(*pItemsNumber+1024+1)*sizeof(PluginPanelItem));

			if(NewPanelItem == NULL)
			{
				/*-*/Log(("GetFindData(file)::!reallocate plugin panels items %d -> %d",*pItemsNumber,*pItemsNumber+1024+1));
				return FALSE;
			}

			*pPanelItem=NewPanelItem;
		}

		PluginPanelItem *CurItem = &NewPanelItem[*pItemsNumber];
		memset(CurItem, 0, sizeof(PluginPanelItem));
		CurItem->FindData = FileInfo.FindData;

		if(!IS_SILENT(OpMode))
		{
			CurItem->CustomColumnNumber             = FTP_COL_MAX;
			CurItem->Owner                          = FileInfo.FTPOwner[0] ? strdup(FileInfo.FTPOwner) : NULL;
			CurItem->CustomColumnData               = (LPSTR*)malloc(sizeof(LPSTR*)*FTP_COL_MAX);
			CurItem->CustomColumnData[FTP_COL_MODE] = strdup(FileInfo.UnixMode);
			CurItem->CustomColumnData[FTP_COL_LINK] = strdup(FileInfo.Link);
			hConnect->ToOEM(CurItem->CustomColumnData[FTP_COL_LINK]);
		}

		(*pItemsNumber)++;
	}
	while(FtpFindNextFile(hConnect,&FileInfo));

	return TRUE;
}
Beispiel #5
0
int FTP::ProcessEvent(int Event,void *Param)
{
#if defined(__FILELOG__)
	static LPCSTR states[] = { "fcsNormal", "fcsExpandList", "fcsClose", "fcsConnecting","fcsFTP" };
	PROC(("ProcessEvent","%d (%s),%08X",Event,states[CurrentState],Param))
#endif
	PanelInfo pi;
	int       n;
	FTPHost*  p;
	pi.PanelItems = NULL;

	if(Event == FE_BREAK ||
	        CurrentState == fcsClose ||
	        CurrentState == fcsConnecting)
	{
		Log(("Skip event"));
		return FALSE;
	}

//Close notify
	if(Event == FE_CLOSE)
	{
		Log(("Close notify"));
		CurrentState = fcsClose;

		if(ShowHosts)
		{
			if(!pi.PanelItems)
				FP_Info->Control(this, FCTL_GETPANELINFO, &pi);

			FP_SetRegKey("LastHostsMode",pi.ViewMode);
			Log(("Write HostsMode: %d",pi.ViewMode));
		}

		return FALSE;
	}

//Position cursor to added|corrected item on panel
	if(Event == FE_REDRAW)
	{
		if(SelectFile.Length())
		{
			Log(("PositionItem: [%s]",SelectFile.c_str()));

			if(!pi.PanelItems)
				FP_Info->Control(this, FCTL_GETPANELINFO, &pi);

			for(n = 0; n < pi.ItemsNumber; n++)
			{
				if(ShowHosts)
				{
					if((p=FTPHost::Convert(&pi.PanelItems[n])) == NULL ||
					        !SelectFile.Cmp(PointToName(p->RegKey)))
						continue;
				}
				else
				{
					if(!SelectFile.Cmp(FTP_FILENAME(&pi.PanelItems[n])))
						continue;
				}

				Log(("PosItem[%d] [%s]", n, FTP_FILENAME(&pi.PanelItems[n])));
				PanelRedrawInfo pri;
				pri.CurrentItem  = n;
				pri.TopPanelItem = pi.TopPanelItem;
				SelectFile       = "";
				FP_Info->Control(this,FCTL_REDRAWPANEL,&pri);
				break;
			}

			SelectFile = "";
		}
	}/*REDRAW*/

//Correct saved hosts mode on change
	if(ShowHosts && Event == FE_CHANGEVIEWMODE)
	{
		if(!pi.PanelItems)
			FP_Info->Control(this, FCTL_GETPANELINFO, &pi);

		Log(("New ColumnMode %d",pi.ViewMode));
		FP_SetRegKey("LastHostsMode",pi.ViewMode);
	}

//Set start hosts panel mode
	if(Event == FE_REDRAW)
	{
		if(ShowHosts && !PluginColumnModeSet)
		{
			if(Opt.PluginColumnMode != -1)
				FP_Info->Control(this,FCTL_SETVIEWMODE,&Opt.PluginColumnMode);
			else
			{
				int num = FP_GetRegKey("LastHostsMode",2);
				FP_Info->Control(this,FCTL_SETVIEWMODE,&num);
			}

			PluginColumnModeSet = TRUE;
		}
		else if(isBackup() && NeedToSetActiveMode)
		{
			FP_Info->Control(this,FCTL_SETVIEWMODE,&ActiveColumnMode);
			NeedToSetActiveMode = FALSE;
		}
	}

//Keep alive
	if(Event == FE_IDLE          &&
	        !ShowHosts                &&
	        FtpCmdLineAlive(hConnect) &&
	        KeepAlivePeriod           &&
	        FP_PeriodEnd(KeepAlivePeriod))
	{
		Log(("Keep alive"));
		FTPCmdBlock blocked(this,TRUE);

		if(Opt.ShowIdle)
		{
			SetLastError(ERROR_SUCCESS);
			IdleMessage(FP_GetMsg(MKeepAliveExec),Opt.ProcessColor);
		}

		FtpKeepAlive(hConnect);
		Log(("end Keep alive"));
	}

//CMD line
	if(Event == FE_COMMAND)
	{
		Log(("CMD line"));
		return ExecCmdLine((LPCSTR)Param,FALSE);
	}

	return FALSE;
}
Beispiel #6
0
void FTP::SaveList(FP_SizeItemList* il)
{
	LPCSTR m;

	if((m=GetOtherPath(Opt.sli.path)) != NULL)
	{
		SayOutError(m);
		return;
	}

	strcat(Opt.sli.path,"ftplist.lst");

	if(!AskSaveList(&Opt.sli))
		return;

	FILE *f = fopen(Opt.sli.path, Opt.sli.Append ? "a" : "w");

	if(!f)
	{
		SayOutError(FMSG(MFLErrCReate),FMSG_ERRORTYPE);
		return;
	}

	PluginPanelItem* p;
	int              n;
	int              level;
	char             str[1024+2],
	   BasePath[1024+2],
	   CurrentUrlPath[1024+2];
	CurrentUrlPath[0] = 0;
	_snprintf(BasePath, ARRAYSIZE(BasePath),
	          "%s%s%s%s",
	          Opt.sli.AddPrefix ? "ftp://" : "",
	          Opt.sli.AddPasswordAndUser ? Message("%s:%s@",hConnect->UserName,hConnect->UserPassword) : "",
	          hConnect->hostname,
	          hConnect->CurDir.c_str());
	AddEndSlash(BasePath,'/',ARRAYSIZE(BasePath));

	if(Opt.sli.ListType == sltTree)
		fprintf(f,"BASE: \"%s\"\n",BasePath);

	for(n = 0; n < il->Count(); n++)
	{
		p = il->Item(n);

		if(p->FindData.dwReserved1 == MAX_DWORD)
			continue;

		//URLS --------------------------------------
		if(Opt.sli.ListType == sltUrlList)
		{
			if(IS_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY))
				continue;

			FixFTPSlash(FTP_FILENAME(p));
			_snprintf(str,ARRAYSIZE(str),"%s%s",BasePath,FTP_FILENAME(p));

			if(Opt.sli.Quote) QuoteStr(str);

			fprintf(f,"%s\n",str);
		}
		else

			//TREE --------------------------------------
			if(Opt.sli.ListType == sltTree)
			{
				StrCpy(str, FTP_FILENAME(p), ARRAYSIZE(str));
				FixFTPSlash(str);

				for(m = str,level = 0;
				        (m=strchr(m,'/')) != NULL;
				        m++,level++);

				fprintf(f,"%*c", level*2+2, ' ');
				m = strrchr(str,'/');

				if(m) m++;
				else m = str;

				fprintf(f,"%c%s",
				        IS_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY) ? '/' : ' ', m);

				if(Opt.sli.Size)
				{
					level = Max(1, Opt.sli.RightBound - 10 - level*2 - 2 - 1 - (int)strlen(m));
					fprintf(f,"%*c",level,' ');

					if(IS_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY))
						fprintf(f,"<DIR>");
					else
						fprintf(f,"%10I64u", ((__int64)p->FindData.nFileSizeHigh) << 32 | p->FindData.nFileSizeLow);
				}

				fprintf(f,"\n");
			}
			else

				//GROUPS ------------------------------------
				if(Opt.sli.ListType == sltGroup)
				{
					if(IS_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY))
						continue;

					FixFTPSlash(FTP_FILENAME(p));
					_snprintf(str, ARRAYSIZE(str), "%s%s", BasePath, FTP_FILENAME(p));

					if(!IS_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY))
						*strrchr(str,'/') = 0;

					if(StrCmp(CurrentUrlPath,str,-1,FALSE) != 0)
					{
						StrCpy(CurrentUrlPath, str, ARRAYSIZE(CurrentUrlPath));
						fprintf(f,"\n[%s]\n", CurrentUrlPath);
					}

					StrCpy(str, FTP_FILENAME(p), ARRAYSIZE(str));
					FixFTPSlash(str);
					m = strrchr(str,'/');

					if(m) m++;
					else m = str;

					fprintf(f," %s", m);

					if(Opt.sli.Size)
					{
						level = Max(1, Opt.sli.RightBound - 10 - (int)strlen(m) - 1);
						fprintf(f,"%*c%10I64u",
						        level,' ',
						        ((__int64)p->FindData.nFileSizeHigh) << 32 | p->FindData.nFileSizeLow);
					}

					fprintf(f,"\n");
				}
	}

	fclose(f);
	LPCSTR itms[] = { FMSG(MFLDoneTitle), FMSG(MFLFile), Opt.sli.path, FMSG(MFLDone), FMSG(MOk) };
	FMessage(FMSG_LEFTALIGN,NULL,itms,5,1);
}
Beispiel #7
0
BOOL FTP::ShowFilesList(FP_SizeItemList* il)
{
	int              cn,n,i,w,
	  num;
	int              Breaks[] = { VK_INSERT, VK_F2, 0 },
	                            BNumber;
	char             str[ 500 ];
	PluginPanelItem *p;
	FarMenuItem     *mi = NULL;
	char            *m,*nm;

	if(!il || !il->Count())
		return FALSE;

	//Create|Recreate
	mi = (FarMenuItem *)realloc(mi,il->Count()*sizeof(FarMenuItem));
	memset(mi, 0, il->Count()*sizeof(FarMenuItem));
	//Scan number of items
	w = cn = 0;

	for(i = n = 0; n < il->Count(); n++)
	{
		p = il->Item(n);
		p->NumberOfLinks        = StrSlashCount(FTP_FILENAME(p));
		p->FindData.dwReserved1 = 0;
		w = Max(w,static_cast<int>(strlen(PointToName(FTP_FILENAME(p)))) + (int)p->NumberOfLinks + 1);
		cn++;
		MNUM(mi[i++]) = n;
	}

	w = Min(Max(60,Min(w,MSZ)),FP_ConWidth()-8);

	if(!cn) return FALSE;

	//Calc length of size and count digits
	int szSize = 0,
	    szCount = 0;

	for(n = 0; n < cn; n++)
	{
		p = il->Item(MNUM(mi[n]));
		FDigit(str, ((__int64)p->FindData.nFileSizeHigh) << 32 | p->FindData.nFileSizeLow, -1);
		szSize = Max(static_cast<int>(strlen(str)),szSize);

		if(IS_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY))
		{
			FDigit(str,p->FindData.dwReserved0,-1);
			szCount = Max(static_cast<int>(strlen(str)),szCount);
		}
	}

	//Filename width
	w -= szSize + szCount + 6;

	//Set menu item text
	for(n = 0; n < cn; n++)
	{
		p = il->Item(MNUM(mi[n]));
		m = mi[n].Text;

		for(i = 0; i < (int)p->NumberOfLinks; i++)
		{
			*(m++) = ' ';
			*(m++) = ' ';
		}

		nm = PointToName(FTP_FILENAME(p));

		for(i = (int)(m - mi[n].Text); i < w; i++)
			if(*nm)
				*(m++) = *(nm++);
			else
				*(m++) = ' ';

		*(m++) = (*nm) ? FAR_SBMENU_CHAR : ' ';

		if(szSize)
		{
			*(m++) = ' ';
			*(m++) = FAR_VERT_CHAR;
			*(m++) = ' ';
			FDigit(str, ((__int64)p->FindData.nFileSizeHigh) << 32 | p->FindData.nFileSizeLow, -1);
			m += sprintf(m,"%*s",szSize,str);
		}

		if(szCount)
		{
			*(m++) = ' ';
			*(m++) = FAR_VERT_CHAR;
			*(m++) = ' ';

			if(IS_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY))
				FDigit(str,p->FindData.dwReserved0,-1);
			else
				str[0] = 0;

			m += sprintf(m,"%*s",szCount,str);
		}

		*m = 0;
	}

	num = -1;

	do
	{
		//Set selected
		for(n = 0; n < cn; n++)
			mi[n].Checked = il->Items()[ MNUM(mi[n])].FindData.dwReserved1 != MAX_DWORD;

		//Title
		__int64 tsz = 0,tcn = 0;

		for(n = 0; n < cn; n++)
		{
			p = il->Item(MNUM(mi[n]));

			if(p->FindData.dwReserved1 != MAX_DWORD &&
			        !IS_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY))
			{
				tsz += ((__int64)p->FindData.nFileSizeHigh) << 32 | p->FindData.nFileSizeLow;
				tcn++;
			}
		}

		StrCpy(str,FP_GetMsg(FMSG(MListTitle)),ARRAYSIZE(str));
		StrCat(str," (",ARRAYSIZE(str));
		StrCat(str,FDigit(NULL,tsz,-1),ARRAYSIZE(str));

		if(il->TotalFullSize != tsz)
		{
			StrCat(str,"{",ARRAYSIZE(str));
			StrCat(str,FDigit(NULL,il->TotalFullSize,-1),ARRAYSIZE(str));
			StrCat(str,"}",ARRAYSIZE(str));
		}

		StrCat(str,"/",ARRAYSIZE(str));
		StrCat(str,FDigit(NULL,tcn,-1),ARRAYSIZE(str));

		if(tcn != il->TotalFiles)
		{
			StrCat(str,"{",ARRAYSIZE(str));
			StrCat(str,FDigit(NULL,il->TotalFiles,-1),ARRAYSIZE(str));
			StrCat(str,"}",ARRAYSIZE(str));
		}

		StrCat(str,")",ARRAYSIZE(str));
		//Menu
		n = FP_Info->Menu(FP_Info->ModuleNumber,-1,-1,0,FMENU_SHOWAMPERSAND,
		                  str,
		                  FP_GetMsg(FMSG(MListFooter)),
		                  "FTPFilesList", Breaks, &BNumber, mi,cn);

		//key ESC
		if(n == -1)
		{
			num = FALSE;
			break;
		}

		//key Enter
		if(BNumber == -1)
		{
			num = TRUE;
			break;
		}

		//Set selected
		if(num != -1) mi[num].Selected = FALSE;

		num = n;
		mi[num].Selected = TRUE;
		//Process keys
		bool set;

		switch(BNumber)
		{
				/*INS*/
			case 0: //Current
				p = il->Item(MNUM(mi[num]));
				//Next item
				n = num+1;
				//Switch selected
				set = p->FindData.dwReserved1 != MAX_DWORD;
				p->FindData.dwReserved1 = set ? MAX_DWORD : 0;

				//Switch all nested
				if(IS_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY))
				{
					i = StrSlashCount(FTP_FILENAME(p));

					for(; n < cn; n++)
					{
						p = il->Item(MNUM(mi[n]));

						if(StrSlashCount(FTP_FILENAME(p)) <= i)
							break;

						p->FindData.dwReserved1 = set ? MAX_DWORD : 0;
					}
				}

				//INS-moves-down
				if(n < cn)
				{
					mi[num].Selected = FALSE;
					mi[n].Selected   = TRUE;
					num = n;
				}

				break;
				/*F2*/
			case 1:
				SaveList(il);
				break;
		}
	}
	while(true);

	free(mi);

	if(!num)
		return FALSE;

	return TRUE;
}
Beispiel #8
0
BOOL idDeleteCB(PluginPanelItem* p,LPVOID dt)
{
	PROC(("idDeleteCB", "%p,%p [%s]", p, dt, FTP_FILENAME(p)));
	int      rres;
	FTPHost* h       = FTPHost::Convert(p);
	char    *CurName = FTP_FILENAME(p);
	char    *m;

	if(((DeleteData*)dt)->ShowHosts && !h)
		return TRUE;

//Ask
	if(IS_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY))
	{
		if(!((DeleteData*)dt)->DeleteAllFolders &&
		        IS_SILENT(((DeleteData*)dt)->OpMode))
		{
			LPCSTR MsgItems[]=
			{
				((DeleteData*)dt)->ShowHosts ? FP_GetMsg(MDeleteHostsTitle):FP_GetMsg(MDeleteTitle),
				((DeleteData*)dt)->ShowHosts ? FP_GetMsg(MDeleteHostFolder):FP_GetMsg(MDeleteFolder),
				CurName,
				FP_GetMsg(MDeleteGroupDelete), FP_GetMsg(MDeleteGroupAll), FP_GetMsg(MDeleteGroupCancel)
			};
			rres = FMessage(FMSG_WARNING|FMSG_DOWN, NULL,
			                MsgItems, ARRAYSIZE(MsgItems),
			                3);

			switch(rres)
			{
					/*ESC*/
				case -1:
					return FALSE;
					/*Del*/
				case  0:
					break;
					/*DelAll*/
				case  1:
					((DeleteData*)dt)->DeleteAllFolders = TRUE;
					break;
					/*Cancel*/
				case  2:
					return FALSE;
			}
		}
	}

//Display
	SaveConsoleTitle::Text(CurName);
	FtpConnectMessage(((DeleteData*)dt)->hConnect, MDeleteTitle, PointToName(CurName));

//===============================
//Hosts
	if(((DeleteData*)dt)->ShowHosts)
		return FP_DeleteRegKeyAll(h->RegKey);

//===============================
//FTP
	m = strrchr(CurName,'/');

	if(m) CurName = m+1;

	if(IS_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY))
	{
//FTP directory
		//Succ delete
		if(FtpRemoveDirectory(((DeleteData*)dt)->hConnect, CurName))
		{
			if(Opt.UpdateDescriptions) p->Flags |= PPIF_PROCESSDESCR;

			return TRUE;
		}
	}
	else
	{
//FTP file
		//Succ delete
		if(FtpDeleteFile(((DeleteData*)dt)->hConnect,CurName))
		{
			if(Opt.UpdateDescriptions) p->Flags |= PPIF_PROCESSDESCR;

			return TRUE;
		}
	}

//Error
	Log(("Del error: %s", ((DeleteData*)dt)->SkipAll ? "SkipAll" : "Ask"));

	if(((DeleteData*)dt)->SkipAll == FALSE)
	{
		rres = FtpConnectMessage(((DeleteData*)dt)->hConnect, MCannotDelete, CurName, -MCopySkip, MCopySkipAll);

		switch(rres)
		{
			/*skip*/     case 0:
				Log(("Skip"));
				return TRUE;
				/*skip all*/
			case 1:
				((DeleteData*)dt)->SkipAll = TRUE;
				Log(("SkipAll"));
				return TRUE;
			default:
				Log(("Other"));
				SetLastError(ERROR_CANCELLED);
				return FALSE;
		}
	}
	else
		return TRUE;
}