예제 #1
0
파일: FtpAPI.cpp 프로젝트: elfmz/far2l
WORD FTP::SelectServerType(WORD Type)
{
	FarMenuItem MenuItems[50];
	FTPDirList  dl;
	WORD        n,cn;
	memset(MenuItems, 0, sizeof(MenuItems));
	StrCpy(MenuItems[0].Text, FP_GetMsg(MTableAuto), ARRAYSIZE(MenuItems[0].Text));
	MenuItems[1].Separator = TRUE;
	cn = dl.GetNumberOfSupportedTypes();

	for(n = 0; n < ARRAYSIZE(MenuItems) && n < cn; n++)
	{
		FTPType* tp = dl.GetType(n);
		snprintf(MenuItems[n+2].Text, ARRAYSIZE(MenuItems[0].Text),
		          "%s %c %s",
		          tp->TypeName, FAR_VERT_CHAR, tp->TypeDescription);
	}

	if(Type >= n)
		MenuItems[0].Selected      = TRUE;
	else
		MenuItems[Type+2].Selected = TRUE;

	int rc = FP_Info->Menu(FP_Info->ModuleNumber,-1,-1,0,FMENU_AUTOHIGHLIGHT,
	                       FP_GetMsg(MTableTitle), NULL,NULL,NULL,NULL,MenuItems,n+2);

	if(rc == -1)
		return Type;
	else
		return ((WORD)rc) == 0 ? FTP_TYPE_DETECT : ((WORD)rc-2);
}
예제 #2
0
void SetTitles(char *cols[], LPCSTR fmt,int cn)
{
	int n = 0;

	if(!fmt || *fmt == 0 || !cn)
		return;

	do
	{
		if(*fmt == 'C' || *fmt == 'c')
		{
			fmt++;

			switch(*fmt)
			{
				case '0':
					cols[n] = (char*)FP_GetMsg(MFileMode);
					break;
				case '1':
					cols[n] = (char*)FP_GetMsg(MLink);
					break;
				default:
					cols[n] = (char*)"<unk>";
			}
		}
		else
			cols[n] = NULL;

		n++;

		if(n >= cn)
			return;

		while(true)
		{
			if(*fmt == 0)
				return;

			if(*fmt == ',')
			{
				fmt++;
				break;
			}

			fmt++;
		}
	}
	while(true);
}
예제 #3
0
파일: Ftp.cpp 프로젝트: FarGroup/FarManager
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;
}
예제 #4
0
파일: Event.cpp 프로젝트: CyberShadow/FAR
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;
}
예제 #5
0
void FTP::GetOpenPluginInfo(struct OpenPluginInfo *pi)
{
	PROC(("GetOpenPluginInfo","%s cc: %d pi: %p hC:%p",ShowHosts?"HOSTS":"FTP",CallLevel,pi,hConnect));
	PanelInfo thisPInfo = { 0 };
	static int inside = 0;
	inside++;
	memset(pi, 0, sizeof(*pi));
	pi->StructSize = sizeof(*pi);

//---------------- FLAGS
	if(!hConnect || ShowHosts)
		pi->Flags = OPIF_SHOWPRESERVECASE | OPIF_USEHIGHLIGHTING;
	else
		pi->Flags = OPIF_ADDDOTS | OPIF_USEFILTER | OPIF_USESORTGROUPS | OPIF_USEHIGHLIGHTING |
		            OPIF_SHOWPRESERVECASE;

	Log(("SetFlags %08X", pi->Flags));
//---------------- HOST, CURDIR
	static String curDir;
	GetCurPath(curDir);
	pi->HostFile = NULL;
	pi->CurDir   = curDir.c_str();
//---------------- TITLE
	pi->PanelTitle = PanelTitle;

	if(ShowHosts)
		_snprintf(PanelTitle, ARRAYSIZE(PanelTitle),
		          " FTP: %s ", pi->CurDir);
	else
		_snprintf(PanelTitle, ARRAYSIZE(PanelTitle),
		          (hConnect&&hConnect->Host.ServerType==FTP_TYPE_MVS)? " FTP: %s@%s/%s ": " FTP: %s@%s%s ",
		          Host.User, Host.Host, pi->CurDir);

	if(inside > 1)
	{
		inside--;
		return;
	}

//---------------- FORMAT
	static String Format;

	if(ShowHosts)
		Format = "//Hosts/";
	else
		Format.printf("//%s/",Host.Host);

	Format.cat(pi->CurDir + (*pi->CurDir == '/' || *pi->CurDir == '\\'));
	pi->Format = Format.c_str();
//---------------- INFO LINES
	static struct InfoPanelLine InfoLines[7];
	char *m;
	memset(InfoLines, 0, sizeof(InfoLines));
//Client
	StrCpy(InfoLines[0].Text,FP_GetMsg(MFtpInfoFTPClient),ARRAYSIZE(InfoLines[0].Text));
	InfoLines[0].Separator = TRUE;
	StrCpy(InfoLines[1].Text,FP_GetMsg(MFtpInfoHostName),ARRAYSIZE(InfoLines[0].Text));
	StrCpy(InfoLines[1].Data,Host.HostName,ARRAYSIZE(InfoLines[0].Data));
	StrCpy(InfoLines[2].Text,FP_GetMsg(MFtpInfoHostDescr),ARRAYSIZE(InfoLines[0].Text));
	StrCpy(InfoLines[2].Data,Host.HostDescr,ARRAYSIZE(InfoLines[0].Data));
	StrCpy(InfoLines[3].Text,FP_GetMsg(MFtpInfoHostType),ARRAYSIZE(InfoLines[0].Text));

	if(hConnect)
		FtpSystemInfo(hConnect,InfoLines[3].Data,ARRAYSIZE(InfoLines[0].Data));
	else
		InfoLines[3].Data[0] = 0;

//Titles
	StrCpy(InfoLines[4].Text,FP_GetMsg(MFtpInfoFtpTitle),ARRAYSIZE(InfoLines[0].Text));
	InfoLines[4].Separator=TRUE;
	InfoLines[5].Text[0] = 0;

	if(hConnect)
		StrCpy(InfoLines[5].Data, hConnect->GetStartReply(), ARRAYSIZE(InfoLines[5].Data));
	else
		InfoLines[5].Data[0] = 0;

	m = strpbrk(InfoLines[5].Data,"\n\r");

	if(m) *m = 0;

	StrCpy(InfoLines[6].Text, FP_GetMsg(MResmResume), ARRAYSIZE(InfoLines[0].Text));

	if(hConnect)
		StrCpy(InfoLines[6].Data, FP_GetMsg(FtpIsResume(hConnect)?MResmSupport:MResmNotSupport), ARRAYSIZE(InfoLines[0].Data));
	else
		StrCpy(InfoLines[6].Data, FP_GetMsg(MResmNotConnected), ARRAYSIZE(InfoLines[0].Data));

	pi->InfoLines       = InfoLines;
	pi->InfoLinesNumber = 7;
//---------------- DESCR
	static char *DescrFiles[32],
	       DescrFilesString[256];
	StrCpy(DescrFilesString, Opt.DescriptionNames, ARRAYSIZE(DescrFilesString));
	int   DescrFilesNumber = 0;
	char *NamePtr          = DescrFilesString;

	while(DescrFilesNumber < (int)ARRAYSIZE(DescrFiles))
	{
		while(isspace(*NamePtr)) NamePtr++;

		if(*NamePtr == 0) break;

		DescrFiles[DescrFilesNumber++] = NamePtr;

		if((NamePtr=strchr(NamePtr,',')) == NULL) break;

		*(NamePtr++)=0;
	}

	pi->DescrFiles=DescrFiles;

	if(!Opt.ReadDescriptions)
		pi->DescrFilesNumber=0;
	else
		pi->DescrFilesNumber=DescrFilesNumber;

//---------------- SHORTCUT
	static String ShortcutData;

	if(ShowHosts)
	{
		/*
		HOSTSTS
		  Hostspath
		*/
		ShortcutData.printf("HOST:%s", HostsPath);
	}
	else
	{
		/*
		FTP
		  Host
		  1
		  AskLogin    + 3
		  AsciiMode   + 3
		  PassiveMode + 3
		  UseFirewall + 3
		  HostTable
		  1
		  User
		  1
		  Password
		  1
		  ExtCmdView + 3
		  IOBuffSize (atoi)
		  1
		  FFDup + '0'
		  DecodeCmdLine + '0'
		  1
		*/
		ShortcutData.printf("FTP:%s\x1%c%c%c%c%d\x1%s\x1%s\x1%s\x1%c%d\x1%c\x1%c\x1",
		                    Host.Host,
		                    Host.AskLogin+3, Host.AsciiMode+3, Host.PassiveMode+3, Host.UseFirewall+3, Host.ServerType,
		                    Host.HostTable,
		                    Host.User,
		                    Host.Password,
		                    Host.ExtCmdView+3, Host.IOBuffSize,
		                    '0'+Host.FFDup, '0'+Host.DecodeCmdLine);
	}

	pi->ShortcutData = ShortcutData.c_str();

//---------------- PANEL MODES
//HOSTST
	if(ShowHosts)
	{
		static struct PanelMode PanelModesArray[10];
		static char *ColumnTitles[4] = { NULL };
		static char *ColumnTitles2[4] = { NULL };
		static char  Mode[ 20 ], ModeSz[20], ModeSz2[20];
		int      dizLen = 0,
		         nmLen  = 0,
		         hLen   = 0,
		         hstLen = 0;
		int      n,num;
		FTPHost* p;
		memset(&PanelModesArray,0,sizeof(PanelModesArray));

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

		for(n = 0; n < thisPInfo.ItemsNumber; n++)
		{
			p = FTPHost::Convert(&thisPInfo.PanelItems[n]);

			if(!p) continue;

			dizLen = Max(dizLen,(int)strlen(p->HostDescr));
			nmLen  = Max(nmLen, (int)strlen(p->User));
			hLen   = Max(hLen, (int)strlen(p->Home));
			hstLen = Max(hstLen,(int)strlen(p->Host));
		}

		ColumnTitles[0] = (char*)FP_GetMsg(MHostColumn);
		//==1
		PanelModesArray[1].ColumnTypes   = (char *)"C0";
		PanelModesArray[1].ColumnWidths  = (char *)"0";
		//==2
		num = 1;
		n   = (thisPInfo.PanelRect.right-thisPInfo.PanelRect.left)/2;
		//HOST
		strcpy(Mode,"C0");
		sprintf(ModeSz,hLen || nmLen || dizLen ? "%d" : "0",hstLen);

		//HOME
		if(hLen)
		{
			strcat(Mode,",C1");

			if(hLen < n && (nmLen || dizLen))
			{
				strcat(ModeSz,Message(",%d",hLen));
				n -= hLen;
			}
			else
				strcat(ModeSz,",0");

			ColumnTitles[num++] = (char*)FP_GetMsg(MHomeColumn);
		}

		//UNAME
		if(nmLen)
		{
			strcat(Mode,",C2");

			if(nmLen < n && dizLen)
			{
				strcat(ModeSz,Message(",%d",nmLen));
			}
			else
				strcat(ModeSz,",0");

			ColumnTitles[num++] = (char*)FP_GetMsg(MUserColumn);
		}

		//DIZ
		if(dizLen)
		{
			strcat(Mode,",Z");
			strcat(ModeSz,",0");
			ColumnTitles[num] = (char*)FP_GetMsg(MDescColumn);
		}

		PanelModesArray[2].ColumnTypes   = Mode;
		PanelModesArray[2].ColumnWidths  = ModeSz;
		PanelModesArray[2].ColumnTitles  = ColumnTitles;
		ColumnTitles2[0] = (char*)FP_GetMsg(MHostColumn);
		ColumnTitles2[1] = (char*)FP_GetMsg(MDescColumn);

		if(!dizLen)
		{
			PanelModesArray[3].ColumnTypes   = (char *)"C0";
			PanelModesArray[3].ColumnWidths  = (char *)"0";
		}
		else
		{
			PanelModesArray[3].ColumnTypes   = (char *)"C0,Z";
			PanelModesArray[3].ColumnWidths  = ModeSz2;
			sprintf(ModeSz2,"%d,0",Min((int)(thisPInfo.PanelRect.right-thisPInfo.PanelRect.left)/2,hstLen));
		}

		PanelModesArray[3].ColumnTitles  = ColumnTitles2;
		pi->PanelModesArray  = PanelModesArray;
		pi->PanelModesNumber = ARRAYSIZE(PanelModesArray);
		pi->StartPanelMode   = 0;

		for(n = 1; n <= 3; n++)
		{
			PanelModesArray[n].StatusColumnTypes   = PanelModesArray[n].ColumnTypes;
			PanelModesArray[n].StatusColumnWidths  = PanelModesArray[n].ColumnWidths;
		}
	}
	else
	{
//FTP
		static struct PanelMode PanelModesArray[10];
		memset(PanelModesArray, 0, sizeof(PanelModesArray));
		static char *ColumnTitles[10];
		SetTitles(ColumnTitles, FP_GetMsg(MColumn9), ARRAYSIZE(ColumnTitles));
		PanelModesArray[9].ColumnTypes  = (char*)FP_GetMsg(MColumn9);
		PanelModesArray[9].ColumnWidths = (char*)FP_GetMsg(MSizes9);
		PanelModesArray[9].ColumnTitles = ColumnTitles;
		PanelModesArray[9].FullScreen   = atoi(FP_GetMsg(MFullScreen9));
		static char *ColumnTitles1[10];
		SetTitles(ColumnTitles1, FP_GetMsg(MColumn0), ARRAYSIZE(ColumnTitles));
		PanelModesArray[0].ColumnTypes  = (char*)FP_GetMsg(MColumn0);
		PanelModesArray[0].ColumnWidths = (char*)FP_GetMsg(MSizes0);
		PanelModesArray[0].ColumnTitles = ColumnTitles1;
		PanelModesArray[0].FullScreen   = atoi(FP_GetMsg(MFullScreen0));
		pi->PanelModesArray  = PanelModesArray;
		pi->PanelModesNumber = ARRAYSIZE(PanelModesArray);
	}

//---------------- KEYBAR
	static struct KeyBarTitles KeyBar;
	memset(&KeyBar,0,sizeof(KeyBar));
	KeyBar.ShiftTitles[1-1] = (char *)"";
	KeyBar.ShiftTitles[2-1] = (char *)"";
	KeyBar.ShiftTitles[3-1] = (char *)"";
	KeyBar.AltTitles[6-1]   = (char*)FP_GetMsg(MAltF6);

	if(ShowHosts)
	{
		KeyBar.ShiftTitles[1-1] = (char*)FP_GetMsg(MShiftF1);
		KeyBar.ShiftTitles[4-1] = ShowHosts ? (char*)FP_GetMsg(MShiftF4):NULL;
	}
	else
	{
		KeyBar.ShiftTitles[1-1] = (char*)FP_GetMsg(MShiftF1);
		KeyBar.ShiftTitles[7-1] = (char*)FP_GetMsg(MShiftF7);
	}

	pi->KeyBar=&KeyBar;

//---------------- RESTORE SCREEN
	if(!SkipRestoreScreen && CurrentState != fcsExpandList && CurrentState != fcsOperation && !IS_SILENT(FP_LastOpMode))
		FP_Screen::FullRestore();

//Back
	inside--;
}
예제 #6
0
void Connection::recvrequestINT(char *cmd, char *local, char *remote, const char *mode)
{
	int              oldtype = 0,
	                 is_retr;
	FHandle          fout;
	SOCKET           din = INVALID_SOCKET;
	int              ocode, oecode;
	BOOL             oldBrk = FtpSetBreakable(this, -1);
	FTPCurrentStates oState = CurrentState;
	FTNNotify        ni;

	if(type == TYPE_A)
		restart_point = 0;

	ni.Upload       = FALSE;
	ni.Starting     = TRUE;
	ni.Success      = TRUE;
	ni.RestartPoint = restart_point;
	ni.Port         = ntohs(portnum);
	ni.Password[0] = 0; //StrCpy( ni.Password,   UserPassword, ARRAYSIZE(ni.Password));
	StrCpy(ni.User,       UserName, ARRAYSIZE(ni.User));
	StrCpy(ni.HostName,   hostname, ARRAYSIZE(ni.HostName));
	StrCpy(ni.LocalFile,  local, ARRAYSIZE(ni.LocalFile));
	StrCpy(ni.RemoteFile, remote, ARRAYSIZE(ni.RemoteFile));

	if(local[0] == '-' && local[1] == 0)
	{
		;
	}
	else
	{
		fout.Handle = Fopen(local, mode, Opt.SetHiddenOnAbort ? FILE_ATTRIBUTE_HIDDEN : FILE_ATTRIBUTE_NORMAL);

		if(!fout.Handle)
		{
			ErrorCode = GetLastError();
			SysError = TRUE;
			Log(("!Fopen [%s] %s",mode,__WINError()));

			if(!ConnectMessage(MErrorOpenFile,local,-MRetry))
				ErrorCode = ERROR_CANCELLED;

			//goto abort;
			return;
		}

		Log(("recv file [%d] \"%s\"=%p",Host.IOBuffSize,local,fout.Handle));

		if(restart_point != -1)
		{
			if(!Fmove(fout.Handle,restart_point))
			{
				ErrorCode = GetLastError();
				SysError = TRUE;

				if(!ConnectMessage(MErrorPosition,local,-MRetry))
					ErrorCode = ERROR_CANCELLED;

				return;
			}
		}

		TrafficInfo->Resume(restart_point == -1 ? 0 : restart_point);
	}

	is_retr = StrCmp(cmd,Opt.cmdRetr) == 0;

	if(proxy && is_retr)
	{
		proxtrans(cmd, local, remote);
		return;
	}

	if(!initconn())
	{
		Log(("!initconn"));
		return;
	}

	if(!is_retr)
	{
		if(type != TYPE_A)
		{
			oldtype = type;
			setascii();
		}
	}
	else if(restart_point)
	{
		if(!ResumeSupport)
		{
			AddCmdLine(FMSG(MResumeRestart));
			restart_point = 0;
		}
		else if(restart_point != -1)
		{
			if(command("%s %I64u",Opt.cmdRest,restart_point) != RPL_CONTINUE)
			{
				Log(("!restart SIZE"));
				return;
			}
		}
	}

	if(Host.PassiveMode)
	{
		din = dataconn();

		if(din == INVALID_SOCKET)
		{
			Log(("!dataconn: PASV ent"));
			goto abort;
		}
	}

	if(remote)
	{
		if(command("%s %s", cmd, remote) != RPL_PRELIM)
		{
			if(oldtype)
				SetType(oldtype);

			Log(("!command [%s]",cmd));
			fout.Close();

			if(Fsize(local))
				DeleteFile(local);

			return;
		}
	}
	else if(command("%s", cmd) != RPL_PRELIM)
	{
		if(oldtype)
			SetType(oldtype);

		return;
	}

	if(!Host.PassiveMode)
	{
		din = dataconn();

		if(din == INVALID_SOCKET)
		{
			Log(("!dataconn: PASV ret"));
			goto abort;
		}
	}

	/**/

	switch(type)
	{
		case TYPE_A:
		case TYPE_I:
		case TYPE_L:
		{
			FtpSetBreakable(this, FALSE);
			CurrentState = fcsProcessFile;

			if(fout.Handle && PluginAvailable(PLUGIN_NOTIFY))
				FTPNotify().Notify(&ni);

			DWORD b,e,bw;
			__int64 totalValue;
			int b_done;
			DWORD ind;
			int b_ost = Host.IOBuffSize, wsz = get_cluster_size(local)*2;

			if(!wsz || (wsz > b_ost && (wsz /= 2) > b_ost)) wsz = 512;

			ind = Min(1024*1024, Max(4*wsz, 256*1024));  // 256K - 1M
			setsockopt(din, SOL_SOCKET, SO_RCVBUF, (char*)&ind, sizeof(ind));
			b_done = ind = 0;
			totalValue = 0;
			bool unalign = false;
			GET_TIME(b);
			bw = b;

			while(true)
			{
				int c;

				if(wsz != 512 && b_done >= wsz)       // pseudo ansync io
				{
					DWORD off = 0, rdy = 0, ost = b_done % wsz, top = b_done - ost;

					while(ioctlsocket(din, FIONREAD, &rdy) && !rdy)
					{
						if(Fwrite(fout.Handle,IOBuff+off,wsz) != wsz) goto write_error;

						if((off += wsz) >= top) break;
					}

					if(off)
					{
						b_done -= off;

						if(b_done) memmove(IOBuff, IOBuff+off, b_done);

						b_ost = Host.IOBuffSize - b_done;
					}
				}

				//Recv
				c = nb_recv(&din, IOBuff+b_done, b_ost, 0);

				if(c <= 0)
				{
					if(b_done && Fwrite(fout.Handle,IOBuff,b_done) != b_done) goto write_error;

					if(c < 0)
					{
						Log(("gf(%d,%s)=%I64u: !read buff",code,GetSocketErrorSTR(),totalValue));
						code = RPL_TRANSFERERROR;
						goto NormExit;
					}

					Log(("gf(%d,%s)=%I64u: read zero",code,GetSocketErrorSTR(),totalValue));
					break;
				}

				totalValue += c;
				GET_TIME(e);

				if(!fout.Handle)
				{
					//Add readed to buffer
					Log(("AddOutput: +%d bytes", c));
					AddOutput((BYTE*)IOBuff,c);
				}
				else      //Write to file
				{
					b_done += c;
					b_ost -= c;

					if(b_ost < wsz || CMP_TIME(e,bw) >= 3.0)
					{
						DWORD ost = 0;

						if(wsz == 512 || b_done <= wsz)    // timeout or very small buffer
						{
							if(Fwrite(fout.Handle,IOBuff,b_done) != b_done) goto write_error;

							if(b_done < wsz) unalign = true;  // flag of timeout witing (optimize)
						}
						else
						{
							// scatter-gatter for RAID in win32 is very bad on large buffer
							// and when work without RAID synchronous write speed is independ
							// if buffer size is >= 2*cluster size
							int off = 0;

							if(unalign)    // was 'timeouted unaligned write'
							{
								unalign = false;
								off = (DWORD)(totalValue % wsz);

								if(off)
								{
									if(Fwrite(fout.Handle,IOBuff,off) != off) goto write_error;

									b_done -= off;

									if(b_done < wsz)
									{
										memmove(IOBuff, IOBuff+off, b_done);
										goto skip_sg;
									}
								}
							}

							ost = b_done % wsz;
							b_done -= ost;

							do
								if(Fwrite(fout.Handle,IOBuff+off,wsz) != wsz) goto write_error;

							while((off += wsz) < b_done);

							if(ost) memmove(IOBuff, IOBuff+off, ost);
						}

						b_done = ost;
skip_sg:
						b_ost = Host.IOBuffSize - b_done;
						GET_TIME(e);
						bw = e;
					}
				}

				ind += c;

				if(CMP_TIME(e,b) >= 0.5)
				{
					b = e;
					c = ind;
					ind = 0;

					//Call user CB
					if(IOCallback)
					{
						if(!TrafficInfo->Callback(c))
						{
							Log(("gf: canceled by CB"));
do_cancel:
							ErrorCode = ERROR_CANCELLED;

							if(b_done && Fwrite(fout.Handle,IOBuff,b_done) != b_done)
							{
write_error:
								SysError = TRUE;
								ErrorCode = GetLastError();

								if(ErrorCode == ERROR_SUCCESS)
									ErrorCode = ERROR_WRITE_FAULT;  // for non equal counter

								Log(("!write local"));
							}

							goto abort;
						}
					}
					else

						//Show Quite progressing
						if(Opt.ShowIdle && !remote)
						{
							char   digit[ 20 ];
							String str;
							str.printf("%s%s ", FP_GetMsg(MReaded), FCps(digit,(double)totalValue));
							SetLastError(ERROR_SUCCESS);
							IdleMessage(str.c_str(),Opt.ProcessColor);

							if(CheckForEsc(FALSE)) goto do_cancel;
						}
				}
			}

			if(IOCallback)
				TrafficInfo->Callback(0);

			break;
		}
	}

NormExit:
	FtpSetBreakable(this, oldBrk);
	ocode              = code;
	oecode             = ErrorCode;
	CurrentState       = oState;
	scClose(data_peer,-1);

	if(getreply(FALSE) == RPL_ERROR ||
	        oldtype && !SetType(oldtype))
	{
		lostpeer();
	}
	else
	{
		code      = ocode;
		ErrorCode = oecode;
	}

	if(fout.Handle && PluginAvailable(PLUGIN_NOTIFY))
	{
		ni.Starting = FALSE;
		ni.Success  = TRUE;
		FTPNotify().Notify(&ni);
	}

	return;
abort:
	FtpSetBreakable(this, oldBrk);

	if(!cpend)
	{
		Log(("!!!cpend"));
	}

	ocode        = code;
	oecode       = ErrorCode;
	CurrentState = oState;

	if(!SendAbort(din) ||
	        (oldtype && !SetType(oldtype)))
		lostpeer();
	else
	{
		code      = ocode;
		ErrorCode = oecode;
	}

	scClose(data_peer,-1);

	if(fout.Handle && PluginAvailable(PLUGIN_NOTIFY))
	{
		ni.Starting = FALSE;
		ni.Success  = FALSE;
		FTPNotify().Notify(&ni);
	}

	return;
}
예제 #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;
}
예제 #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;
}
예제 #9
0
파일: Queque.cpp 프로젝트: CyberShadow/FAR
void FTP::ExecuteQueueINT(QueueExecOptions* op)
{
	PROC(("ExecuteQueueINT","%d,%d",op->RestoreState,op->RemoveCompleted))
	FP_Screen       _scr;
	String          DefPath, LastPath, LastName;
	BOOL            rc;
	BOOL            needUpdate = FALSE;
	FTPUrl          *prev,*p,*tmp;
	FTPCopyInfo     ci;
	FAR_FIND_DATA   fd, ffd;
	//Copy info
	ci.asciiMode       = Host.AsciiMode;
	ci.ShowProcessList = FALSE;
	ci.AddToQueque     = FALSE;
	ci.MsgCode         = ocNone;
	ci.UploadLowCase   = Opt.UploadLowCase;
	//Check othe panel info
	PanelInfo pi;
	FP_Info->Control(INVALID_HANDLE_VALUE, FCTL_GETANOTHERPANELINFO, &pi);

	if(pi.PanelType != PTYPE_FILEPANEL ||
	        pi.Plugin)
		DefPath.Null();
	else
		DefPath = pi.CurDir;

	//DO full list
	prev        = NULL;
	p           = UrlsList;
	LastPath.Null();
	LastName.Null();

	while(p)
	{
//Check current host the same
		Log(("Queue: Check current host the same"));

		if(!hConnect ||
		        !Host.CmpConnected(&p->Host))
		{
			Host = p->Host;

			if(!FullConnect())
			{
				if(GetLastError() == ERROR_CANCELLED) break;

				p->Error.printf("%s: %s", FP_GetMsg(MQCanNotConnect), __WINError());
				goto Skip;
			}

			ResetCache=TRUE;
		}

//Apply other parameters
		Log(("Queue: Apply other parameters"));
		Host = p->Host;
		hConnect->InitData(&Host,-1);
		hConnect->InitIOBuff();
//Change local dir
		Log(("Queue: Change local dir"));

		do
		{
			char *m = p->Download ? p->DestPath.c_str() : p->SrcPath.c_str();

			if(!m[0]) m = DefPath.c_str();

			if(!m[0])
			{
				p->Error = FP_GetMsg(MQNotLocal);
				goto Skip;
			}

			if(SetCurrentDirectory(m)) break;

			if(DoCreateDirectory(m))
				if(SetCurrentDirectory(m)) break;

			p->Error.printf(FP_GetMsg(MQCanNotChangeLocal), m, __WINError());
			goto Skip;
		}
		while(0);

//Check local file
		Log(("Queue: Check local file"));

		if(!p->Download)
		{
			if(!FRealFile(p->FileName.cFileName, &fd))
			{
				p->Error.printf(FP_GetMsg(MQNotFoundSource), p->FileName.cFileName, __WINError());
				goto Skip;
			}
		}

//IO file
		Log(("Queue: IO file"));
		//Last used FTP path and name
		LastPath = p->Download ? p->SrcPath : p->DestPath;
		LastName = PointToName(p->FileName.cFileName);

		//DOWNLOAD ------------------------------------------------
		if(p->Download)
		{
			ci.Download  = TRUE;
			ci.SrcPath = p->SrcPath;
			AddEndSlash(ci.SrcPath, '/');
			ci.SrcPath.cat(p->FileName.cFileName);

			if(p->DestPath.Length())
			{
				FixFileNameChars(p->DestPath);
				ci.DestPath = p->DestPath;
			}
			else
				ci.DestPath = DefPath;

			AddEndSlash(ci.DestPath, '\\');
			ci.DestPath.cat(FixFileNameChars(p->FileName.cFileName,TRUE));
			__int64 fsz = FtpFileSize(hConnect, ci.SrcPath.c_str());
			hConnect->TrafficInfo->Init(hConnect, MStatusDownload, 0, NULL);
			hConnect->TrafficInfo->InitFile(fsz, ci.SrcPath.c_str(), ci.DestPath.c_str());

			if(FRealFile(ci.DestPath.c_str(),&fd))
			{
				if(fsz != -1)
				{
					ffd = fd;
					ffd.nFileSizeHigh = (DWORD)((fsz >> 32) & MAX_DWORD);
					ffd.nFileSizeLow  = (DWORD)(fsz & MAX_DWORD);
					ci.MsgCode  = AskOverwrite(MDownloadTitle, TRUE, &fd, &ffd, ci.MsgCode, FALSE);
				}
				else
					ci.MsgCode  = AskOverwrite(MDownloadTitle, TRUE, &fd, NULL, ci.MsgCode, FALSE);

				switch(ci.MsgCode)
				{
					case   ocOverAll:
					case      ocOver:
						break;
					case      ocSkip:
					case   ocSkipAll:
						goto Skip;
					case    ocResume:
					case ocResumeAll:
						break;
					case     ocNewer:
					case  ocNewerAll:
						goto Skip;
				}

				if(ci.MsgCode == ocCancel)
				{
					SetLastError(ERROR_CANCELLED);
					break;
				}
			}
예제 #10
0
파일: Queque.cpp 프로젝트: CyberShadow/FAR
void FTP::QuequeMenu(void)
{
	int              n,
	  num;
	int              Breaks[] = { VK_DELETE, VK_INSERT, VK_F4, VK_RETURN, 0 },
	                            BNumber;
	FarMenuItem     *mi = NULL;
	FTPUrl*          p,*p1;
	char             str1[MAX_PATH],
	   str2[MAX_PATH],
	   str3[MAX_PATH];
	QueueExecOptions exOp;
	SetupQOpt(&exOp);
	num = -1;

	do
	{
		mi = (FarMenuItem *)realloc(mi, (QuequeSize+1)*sizeof(FarMenuItem));
		memset(mi, 0, QuequeSize*sizeof(FarMenuItem));

		for(p = UrlsList,n = 0; p; p = p->Next, n++)
		{
			StrCpy(str1, p->SrcPath.c_str(),    20);
			StrCpy(str2, p->DestPath.c_str(),   20);
			StrCpy(str3, p->FileName.cFileName, 20);
			_snprintf(mi[n].Text, ARRAYSIZE(mi[n].Text),
			          "%c%c %-20s%c%-20s%c%-20s",
			          p->Download ? '-' : '<', p->Download ? '>' : '-',
			          str1, FAR_VERT_CHAR,
			          str2, FAR_VERT_CHAR,
			          str3);

			if(p->Error[0])
				mi[n].Checked = TRUE;
		}

		//Title
		char title[MAX_PATH];
		_snprintf(title, ARRAYSIZE(title), "%s: %d %s", FP_GetMsg(MQMenuTitle), n, FP_GetMsg(MQMenuItems));

		//Menu
		if(num != -1 && num < QuequeSize) mi[num].Selected = TRUE;

		n = FP_Info->Menu(FP_Info->ModuleNumber,-1,-1,0,FMENU_SHOWAMPERSAND,
		                  title,
		                  FP_GetMsg(MQMenuFooter),
		                  "FTPQueue", Breaks, &BNumber, mi, QuequeSize);

		//key ESC
		if(BNumber == -1 &&
		        n == -1)
			goto Done;

		//key Enter
		if(BNumber == -1)
		{
			//??
			goto Done;
		}

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

		num = n;

		//Process keys
		switch(BNumber)
		{
				/*DEL*/
			case 0:

				if(QuequeSize)
					switch(AskDeleteQueue())
					{
						case -1:
						case  2:
							break;
						case  0:
							p = UrlItem(n, &p1);
							DeleteUrlItem(p, p1);
							break;
						case  1:
							ClearQueue();
							break;
					}

				break;
				/*Ins*/
			case 1:
				InsertToQueue();
				break;
				/*F4*/
			case 2:
				p = UrlItem(n, NULL);

				if(p)
					EditUrlItem(p);

				break;
				/*Return*/
			case 3:

				if(QuequeSize &&
				        WarnExecuteQueue(&exOp))
				{
					ExecuteQueue(&exOp);

					if(!QuequeSize)
						goto Done;
				}

				break;
		}
	}
	while(true);

Done:
	free(mi);
}
예제 #11
0
파일: Cfg.cpp 프로젝트: CyberShadow/FAR
int WINAPI FP_GetColorDialog(int color,FLngColorDialog* p,LPCSTR Help)
{
	InitDialogItem InitItems[]=
	{
		{DI_DOUBLEBOX,3, 1,35,13,0,0,DIF_BOXCOLOR, 0,NULL},
		{DI_SINGLEBOX,5, 2,18, 7,0,0,DIF_BOXCOLOR|DIF_LEFTTEXT,0, NULL},
		{DI_RADIOBUTTON,6,3,0,0,0,0,DIF_GROUP|DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~0)&0x7, 0)),0,NULL},
		{DI_RADIOBUTTON,6,4,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~1)&0x7, 1)),0,NULL},
		{DI_RADIOBUTTON,6,5,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~2)&0x7, 2)),0,NULL},
		{DI_RADIOBUTTON,6,6,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~3)&0x7, 3)),0,NULL},
		{DI_RADIOBUTTON,9,3,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~4)&0x7, 4)),0,NULL},
		{DI_RADIOBUTTON,9,4,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~5)&0x7, 5)),0,NULL},
		{DI_RADIOBUTTON,9,5,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~6)&0x7, 6)),0,NULL},
		{DI_RADIOBUTTON,9,6,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~7)&0x7, 7)),0,NULL},
		{DI_RADIOBUTTON,12,3,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~8)&0x7, 8)),0,NULL},
		{DI_RADIOBUTTON,12,4,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~9)&0x7, 9)),0,NULL},
		{DI_RADIOBUTTON,12,5,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~10)&0x7,10)),0,NULL},
		{DI_RADIOBUTTON,12,6,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~11)&0x7,11)),0,NULL},
		{DI_RADIOBUTTON,15,3,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~12)&0x7,12)),0,NULL},
		{DI_RADIOBUTTON,15,4,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~13)&0x7,13)),0,NULL},
		{DI_RADIOBUTTON,15,5,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~14)&0x7,14)),0,NULL},
		{DI_RADIOBUTTON,15,6,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~15)&0x7,15)),0,NULL},
		{DI_SINGLEBOX,20, 2,33, 7,0,0,DIF_BOXCOLOR|DIF_LEFTTEXT, 0,NULL},
		{DI_RADIOBUTTON,21,3,0,0,0,0,DIF_GROUP|DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~0)&0x7, 0)),0,NULL},
		{DI_RADIOBUTTON,21,4,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~1)&0x7, 1)),0,NULL},
		{DI_RADIOBUTTON,21,5,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~2)&0x7, 2)),0,NULL},
		{DI_RADIOBUTTON,21,6,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~3)&0x7, 3)),0,NULL},
		{DI_RADIOBUTTON,24,3,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~4)&0x7, 4)),0,NULL},
		{DI_RADIOBUTTON,24,4,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~5)&0x7, 5)),0,NULL},
		{DI_RADIOBUTTON,24,5,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~6)&0x7, 6)),0,NULL},
		{DI_RADIOBUTTON,24,6,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~7)&0x7, 7)),0,NULL},
		{DI_RADIOBUTTON,27,3,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~8)&0x7, 8)),0,NULL},
		{DI_RADIOBUTTON,27,4,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~9)&0x7, 9)),0,NULL},
		{DI_RADIOBUTTON,27,5,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~10)&0x7,10)),0,NULL},
		{DI_RADIOBUTTON,27,6,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~11)&0x7,11)),0,NULL},
		{DI_RADIOBUTTON,30,3,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~12)&0x7,12)),0,NULL},
		{DI_RADIOBUTTON,30,4,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~13)&0x7,13)),0,NULL},
		{DI_RADIOBUTTON,30,5,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~14)&0x7,14)),0,NULL},
		{DI_RADIOBUTTON,30,6,0,0,0,0,DIF_MOVESELECT|DIF_SETCOLOR|(FAR_COLOR((~15)&0x7,15)),0,NULL},
		{DI_TEXT,5, 8,0,0,0,0,DIF_SETCOLOR|FAR_COLOR(fccYELLOW,fccGREEN), 0,NULL},
		{DI_TEXT,5, 9,0,0,0,0,DIF_SETCOLOR|FAR_COLOR(fccYELLOW,fccGREEN), 0,NULL},
		{DI_TEXT,5,10,0,0,0,0,DIF_SETCOLOR|FAR_COLOR(fccYELLOW,fccGREEN), 0,NULL},
		{DI_TEXT,3,11,3,11,0,0,DIF_BOXCOLOR|DIF_SEPARATOR,0,NULL },
		{DI_BUTTON,0,12,0,0,0,0,DIF_CENTERGROUP, 1, NULL},
		{DI_BUTTON,0,12,0,0,0,0,DIF_CENTERGROUP, 0,NULL},
	};
	FarDialogItem DialogItems[ARRAYSIZE(InitItems)];
	static FLngColorDialog base =
	{
		FMSG("Color"),
		FMSG("&Foreground"),
		FMSG("&Background"),
		FMSG("&Set"),
		FMSG("&Cancel"),
		FMSG("Text Text Text Text Text Text")
	};

	if(!p) p = &base;

	char str[FAR_MAX_CAPTION+50];
	int  n;
	InitDialogItems(InitItems,DialogItems,ARRAYSIZE(DialogItems));
	StrCpy(DialogItems[ 0].Data,         FP_GetMsg(p->MTitle?p->MTitle:base.MTitle),    FAR_MAX_CAPTION);
	StrCpy(DialogItems[ 1].Data,         FP_GetMsg(p->MFore?p->MFore:base.MFore),       FAR_MAX_CAPTION);
	StrCpy(DialogItems[18].Data,         FP_GetMsg(p->MBk?p->MBk:base.MBk),             FAR_MAX_CAPTION);
	StrCpy(DialogItems[39].Data,         FP_GetMsg(p->MSet?p->MSet:base.MSet),          FAR_MAX_CAPTION);
	StrCpy(DialogItems[40].Data,         FP_GetMsg(p->MCancel?p->MCancel:base.MCancel), FAR_MAX_CAPTION);
	StrCpy(DialogItems[cdlgTEXT].Data,   FP_GetMsg(p->MText?p->MText:base.MText),       FAR_MAX_CAPTION);
	strcpy(DialogItems[cdlgTEXT+1].Data, DialogItems[cdlgTEXT].Data);
	strcpy(DialogItems[cdlgTEXT+2].Data, DialogItems[cdlgTEXT].Data);
	ColorFore = FAR_COLOR_FORE(color);
	ColorBk   = FAR_COLOR_BK(color);

	for(n = 0; n < 16; n++)
	{
		DialogItems[cdlgFORE+n].Selected = FALSE;
		DialogItems[cdlgBK+n].Selected   = FALSE;
		DialogItems[cdlgFORE+n].Focus    = FALSE;
		DialogItems[cdlgBK+n].Focus      = FALSE;
	}

	DialogItems[ cdlgFORE+ColorFore ].Selected = TRUE;
	DialogItems[ cdlgFORE+ColorFore ].Focus = TRUE;
	DialogItems[ cdlgBK+ColorBk ].Selected     = TRUE;
	StrCpy(Title,DialogItems[0].Data,ARRAYSIZE(Title));
	sprintf(str,"(%3d 0x%02X %03o)",
	        FAR_COLOR(ColorFore,ColorBk),
	        FAR_COLOR(ColorFore,ColorBk),
	        FAR_COLOR(ColorFore,ColorBk));
	StrCat(DialogItems[0].Data,str,512);
	n = FP_Info->DialogEx(FP_Info->ModuleNumber,-1,-1,39,15,Help,DialogItems,ARRAYSIZE(DialogItems),0,0,CDLG_WndProc,0);

	if(n == cdlgOK)
		color = FAR_COLOR(ColorFore,ColorBk);

	StrCpy(DialogItems[0].Data,Title,FAR_MAX_CAPTION);
	return color;
}