Esempio n. 1
0
int FTPQueue::AddQueueOp(QueueOperation * op) {
	op->SetClient(m_wrapper);

	m_monitor->Enter();
		VQueue::iterator it;
		for(it = m_queue.begin(); it != m_queue.end(); ++it) {
			if (op->Equals(**it)) {
				OutMsg("[Queue] The operation was already added to the queue, ignoring");
				m_monitor->Exit();
				return 0;
			}
		}
	m_monitor->Exit();

	//Can safely inform queueWindow, Add is called by window thread
	op->SendNotification(QueueOperation::QueueEventAdd);

	m_monitor->Enter();
		m_queue.push_back(op);
		if (m_queue.size() == 1)
			m_monitor->Signal(ConditionQueueOps);
	m_monitor->Exit();

	return 0;
}
Esempio n. 2
0
int NppFTP::Start(NppData nppData, TCHAR * nppConfigStore, int id, FuncItem funcItem) {
	m_nppData = nppData;

	PF::Init();
	Encryption::Init();

	m_configStore = new TCHAR[MAX_PATH];
	lstrcpy(m_configStore, nppConfigStore);
	::PathAppend(m_configStore, TEXT("NppFTP"));
	int res = PU::CreateLocalDir(m_configStore);
	if (res == -1)
		return -1;

	_ConfigPath = new TCHAR[MAX_PATH];
	lstrcpy(_ConfigPath, nppConfigStore);
	::PathAppend(_ConfigPath, TEXT("NppFTP\\"));

	_HostsFile = new char[MAX_PATH];
	char * utf8Store = SU::TCharToCP(m_configStore, CP_ACP);
	strcpy(_HostsFile, utf8Store);
	::PathCombineA(_HostsFile, utf8Store, "known_hosts");
	SU::FreeChar(utf8Store);

	_MainOutputWindow = nppData._nppHandle;

	res = LoadSettings();
	if (res == -1)
		return -1;

	m_ftpWindow = new FTPWindow();
	m_ftpSession = new FTPSession();

	res = m_ftpWindow->Create(nppData._nppHandle, nppData._nppHandle, id, funcItem._cmdID);
	if (res == -1) {
		return -1;
	}

	res = m_ftpSession->Init(m_ftpWindow, m_ftpSettings);
	if (res == -1) {
		m_ftpWindow->Destroy();
		return -1;
	}

	res = m_ftpWindow->Init(m_ftpSession, &m_profiles, m_ftpSettings);
	if (res == -1) {
		m_ftpSession->Deinit();
		m_ftpWindow->Destroy();
		return -1;
	}

	res = m_ftpSession->SetCertificates(&m_certificates);
	m_controlChannel = new ControlChannel();
	m_controlChannel->Start(m_ftpWindow->m_ftpSession);
	OutMsg("[NppFTP] Everything initialized");

	return 0;
}
Esempio n. 3
0
int DropHelper::DragDropThread() {
	int result = 0;

	HRESULT res = OleInitialize(NULL);
	if (res != S_OK && res != S_FALSE) {
		OutErr("[DnD] Error initializing OLE (Thread): %d\n", res);
		return -1;
	}

	CDropSource * src = new CDropSource();
	if (!src) {
		return -1;
	}
	CDataObject * dat = new CDataObject(m_dataWindow);
	if (!dat) {
		src->Release();
		return -1;
	}

	DWORD resEffect = 0;
	OutMsg("[DnD] Begin DoDragDrop");
	res = DoDragDrop(dat, src, DROPEFFECT_COPY, &resEffect);
	OutMsg("[DnD] End DoDragDrop");

	src->Release();
	dat->Release();
	if (res == S_OK || res == DRAGDROP_S_DROP)
		result = TRUE;
	else
		result = FALSE;

	m_dataWindow->OnEndDnD();

	::OleUninitialize();
	m_hThread = NULL;

	return result;
}
Esempio n. 4
0
int FTPCache::ClearCurrentCache(bool permanent) {
	SHFILEOPSTRUCT shfop;
	TCHAR * dirPath = new TCHAR[MAX_PATH+1];

	ZeroMemory(&shfop, sizeof(shfop));
	shfop.hwnd = _MainOutputWindow;
	shfop.wFunc = FO_DELETE;
	shfop.pFrom = dirPath;
	shfop.pTo = NULL;
	shfop.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI | FOF_SILENT;// | FOF_WANTNUKEWARNING;
	if (!permanent) {
		shfop.fFlags |= FOF_ALLOWUNDO;	//use recycle bin
	}
	shfop.lpszProgressTitle = NULL;



	for(size_t i = 0; i < m_vCachePaths.size(); i++) {
		OutMsg("[Cache] Clearing cache in '%T'", m_vCachePaths[i].localpathExpanded);
		lstrcpy(dirPath, m_vCachePaths[i].localpathExpanded);
		int len = lstrlen(dirPath);
		dirPath[len+1] = 0;
		int res = SHFileOperation(&shfop);
		if (res != 0) {
			//Error may also be triggered if cache is empty, so stay silent
			//OutErr("Failure clearing cache: %d", res);
		}
	}

	delete [] dirPath;

	if (m_cacheParent)
		return m_cacheParent->ClearCurrentCache(permanent);

	return 0;
}
Esempio n. 5
0
int FTPWindow::OnEvent(QueueOperation * queueOp, int code, void * data, bool isStart) {
	int result = 0;
	void * queueData = queueOp->GetData();
	int queueResult = queueOp->GetResult();

	//Set busy parameter
	switch(queueOp->GetType()) {
		case QueueOperation::QueueTypeDownload:
		case QueueOperation::QueueTypeDownloadHandle:
		case QueueOperation::QueueTypeUpload: {
			m_busy = isStart;
			break; }
		case QueueOperation::QueueTypeConnect:
		case QueueOperation::QueueTypeDisconnect:
		case QueueOperation::QueueTypeDirectoryGet:
		case QueueOperation::QueueTypeDirectoryCreate:
		case QueueOperation::QueueTypeDirectoryRemove:
		case QueueOperation::QueueTypeFileCreate:
		case QueueOperation::QueueTypeFileDelete:
		case QueueOperation::QueueTypeFileRename:
		case QueueOperation::QueueTypeQuote:
		default: {
			//Other operations cannot be aborted
			break; }
	}

	//TODO: properly handle failures, like with getdir
	//Perform GUI operations
	switch(queueOp->GetType()) {
		case QueueOperation::QueueTypeConnect: {
			m_connecting = isStart;
			if (isStart) {
				SetInfo(TEXT("Connecting"));
				OutMsg("Connecting");
			} else {
				if (queueOp->GetResult() != -1) {
					OnConnect(code);
					OutMsg("Connected");
				} else {
					OutErr("Unable to connect");
					OnDisconnect(code);
					m_ftpSession->TerminateSession();
					result = 1;
				}
			}
			break; }
		case QueueOperation::QueueTypeDisconnect: {
			if (isStart) {
				break;
			}
			OutMsg("Disconnected");
			OnDisconnect(code);
			result = 1;
			break; }
		case QueueOperation::QueueTypeDirectoryGet: {
			QueueGetDir * dirop = (QueueGetDir*)queueOp;
			if (isStart) {
				break;
			}

            std::vector<FTPDir*> parentDirObjs = dirop->GetParentDirObjs();
            size_t i;

            for (i=0; i<parentDirObjs.size(); i++) {
                FTPDir* curFTPDir = parentDirObjs[i];

                FileObject* parent;
                parent = m_ftpSession->FindPathObject(curFTPDir->dirPath);
                if (parent)
                    OnDirectoryRefresh(parent, curFTPDir->files, curFTPDir->count);
            }

			if (queueResult == -1) {
				OutErr("Failure retrieving contents of directory %s", dirop->GetDirPath());
				//break commented: even if failed, update the treeview etc., count should result in 0 anyway
				//break;	//failure
			}
			FTPFile* files = (FTPFile*)queueData;
			int count = dirop->GetFileCount();
			FileObject* parent = m_ftpSession->FindPathObject(dirop->GetDirPath());
			if (parent)
				OnDirectoryRefresh(parent, files, count);
			break; }
		case QueueOperation::QueueTypeDownloadHandle:
		case QueueOperation::QueueTypeDownload: {
			QueueDownload * opdld = (QueueDownload*)queueOp;
			if (isStart)
				break;
			if (queueResult == -1) {
				OutErr("Download of %s failed", opdld->GetExternalPath());
				OnError(queueOp, code, data, isStart);
				break;	//failure
			}

			if (queueOp->GetType() == QueueOperation::QueueTypeDownload) {
				if (code == 0) {
					//Download to cache: Open file
					OutMsg("Download of %s succeeded, opening file.", opdld->GetExternalPath());
					::SendMessage(m_hNpp, NPPM_DOOPEN, (WPARAM)0, (LPARAM)opdld->GetLocalPath());
					::SendMessage(m_hNpp, NPPM_RELOADFILE, (WPARAM)0, (LPARAM)opdld->GetLocalPath());
				} else {
					//Download to other location: Ask
					int ret = ::MessageBox(m_hNpp, TEXT("The download is complete. Do you wish to open the file?"), TEXT("Download complete"), MB_YESNO);
					if (ret == IDYES) {
						::SendMessage(m_hNpp, NPPM_DOOPEN, (WPARAM)0, (LPARAM)opdld->GetLocalPath());
						::SendMessage(m_hNpp, NPPM_RELOADFILE, (WPARAM)0, (LPARAM)opdld->GetLocalPath());
					}
				}
			} else {
				OutMsg("Download of %s succeeded.", opdld->GetExternalPath());
			}
			break; }
		case QueueOperation::QueueTypeUpload: {
			QueueUpload * opuld = (QueueUpload*)queueOp;
			if (isStart)
				break;
			if (queueResult == -1) {
				OutErr("Upload of %S failed", opuld->GetLocalPath());
				OnError(queueOp, code, data, isStart);
				break;	//failure
			}

			OutMsg("Upload of %s succeeded.", opuld->GetExternalPath());

			char path[MAX_PATH];
			strcpy(path, opuld->GetExternalPath());
			char * name = (char*)PU::FindExternalFilename(path);
			if (!name)
				break;

			*name = 0;	//truncate path

			m_ftpSession->GetDirectory(path);
			break; }
		case QueueOperation::QueueTypeDirectoryCreate: {
			QueueCreateDir * opmkdir = (QueueCreateDir*)queueOp;
			if (isStart)
				break;
			if (queueResult == -1) {
				OutErr("Unable to create directory %s", opmkdir->GetDirPath());
				break;	//failure
			}
			OutMsg("Created directory %s", opmkdir->GetDirPath());
			break; }
		case QueueOperation::QueueTypeDirectoryRemove: {
			QueueRemoveDir * oprmdir = (QueueRemoveDir*)queueOp;
			if (isStart)
				break;
			if (queueResult == -1) {
				OutErr("Unable to remove directory %s", oprmdir->GetDirPath());
				break;	//failure
			}
			OutMsg("Removed directory %s", oprmdir->GetDirPath());
			break; }
		case QueueOperation::QueueTypeFileCreate: {
			QueueCreateFile * opmkfile = (QueueCreateFile*)queueOp;
			if (isStart)
				break;
			if (queueResult == -1) {
				OutErr("Unable to create file %s", opmkfile->GetFilePath());
				break;	//failure
			}
			OutMsg("Created file %s", opmkfile->GetFilePath());
			break; }
		case QueueOperation::QueueTypeFileDelete: {
			QueueDeleteFile * opdelfile = (QueueDeleteFile*)queueOp;
			if (isStart)
				break;
			if (queueResult == -1) {
				OutErr("Unable to delete file %s", opdelfile->GetFilePath());
				break;	//failure
			}
			OutMsg("Deleted file %s", opdelfile->GetFilePath());
			break; }
		case QueueOperation::QueueTypeFileRename: {
			QueueRenameFile * oprename = (QueueRenameFile*)queueOp;
			if (isStart)
				break;
			if (queueResult == -1) {
				OutErr("Unable to rename file %s", oprename->GetFilePath());
				break;	//failure
			}
			OutMsg("Renamed %s to %s", oprename->GetFilePath(), oprename->GetNewPath());
			break; }
		case QueueOperation::QueueTypeQuote: {
			QueueQuote * opquote = (QueueQuote*)queueOp;
			if (isStart)
				break;
			if (queueResult == -1) {
				OutErr("Unable to perform quote operation %s", opquote->GetQuote());
				break;	//failure
			}
			break; }
		default: {
			//Other operations do not require change in GUI atm (update tree for delete/rename/create later on)
			break; }
	}

	SetToolbarState();

	return result;
}