Exemple #1
0
FileObject* FTPSession::FindPathObject(const char * filepath) {
	if (!filepath)
		return NULL;

	char tempstr[MAX_PATH];
	strcpy(tempstr, filepath);

	FileObject * current = m_rootObject;

	char * curname = strtok (tempstr, "/");

	while(curname) {
		if (current->GetChildCount() == 0)	//search did not finish, but cannot find child
			return NULL;

		int i = 0;
		int count = current->GetChildCount();
		for(i = 0; i < count; i++) {
			if ( !strcmp( current->GetChild(i)->GetName(), curname ) ) {
				current = current->GetChild(i);
				curname = strtok (NULL, "/");
				break;
			}
		}

		if (i == count)	//none of the children match
			return NULL;
	}

	return current;
}
Exemple #2
0
int FTPWindow::OnConnect(int code) {
	if (code != 0)	//automated connect
		return 0;



	FileObject * root = m_ftpSession->GetRootObject();
	m_treeview.AddRoot(root);

	FileObject * last = root;
	while(last->GetChildCount() > 0) {
		last = last->GetChild(0);
	}

	m_treeview.EnsureObjectVisible(last);
	TreeView_Select(m_treeview.GetHWND(), last->GetData(), TVGN_CARET);
	m_ftpSession->GetDirectory(last->GetPath());

	TCHAR * info = SU::TSprintfNB(TEXT("Connected to %T"), m_ftpSession->GetCurrentProfile()->GetName());
	SetInfo(info);
	delete [] info;

	SetToolbarState();

	return 0;
}
Exemple #3
0
int FTPSession::GetDirectoryHierarchy(const char * inputDir) {
	if (!m_running)
		return -1;

    char *pathEntry;
    char* dir = SU::strdup(inputDir);

    // We will store the parent directory paths to be
    // examined in the below vector.
    std::vector<char*> parentDirs;

    int childCount;
    char currentPath[MAX_PATH];
    FileObject* currentFileObj = m_rootObject;

    strcpy( currentPath, "/" );

    // Split the entries based on '/' and append the
    // previous directory name to get the full path.
    pathEntry = strtok (dir,"/");
    while(pathEntry != NULL) {

        if (currentFileObj) {

            childCount = currentFileObj->GetChildCount();
            currentFileObj = currentFileObj->GetChildByName(pathEntry);

            if (currentFileObj) {

                HTREEITEM hti = (HTREEITEM)(currentFileObj->GetData());
                if (hti) {

                    sprintf(currentPath,"%s%s/", currentPath, pathEntry);
                    pathEntry = strtok (NULL,"/");

                    continue;
                }
            }

            // Cannot find the child. Check if it is because I have no
            // information about the child, or that I cannot find the child.
            if (!currentFileObj) {

                // If I have child data, but I cannot find the child, then
                // I will stop here and will not queue the operation.
                if (childCount)
                    return 1;
            }
        }

        if (!parentDirs.size()) {
            parentDirs.push_back(SU::strdup(currentPath));
        }

        sprintf(currentPath,"%s%s/", currentPath, pathEntry);

        parentDirs.push_back(SU::strdup(currentPath));
        pathEntry = strtok (NULL,"/");
    }

    // If there is some parent directories to be examined,
    // remove the last directory because this is same as
    // the input directory.
    if (parentDirs.size())
        parentDirs.pop_back();

	QueueGetDir * dirop = new QueueGetDir(m_hNotify, inputDir, parentDirs);

	m_mainQueue->AddQueueOp(dirop);

	return 0;
}