Example #1
0
// ----------------
// Global routines
// ----------------
void EnlistFiles(const KString& Mask, KStrings& Files, bool bFullPaths, bool bClearFirst)
{
	if(bClearFirst)
		Files.Clear();

	KString FolderName = GetFilePath(Mask);

	_tfinddata_t FileInfo;
	
	int iHandle = _tfindfirst(Mask, &FileInfo);

	if(iHandle>=0)
	{
		for(;;)
		{
			if(!(FileInfo.attrib & _A_SUBDIR))
				*Files.AddLast() = bFullPaths ? FolderName + FileInfo.name : FileInfo.name;

			// To the next file
			if(_tfindnext(iHandle, &FileInfo)==-1)
				break;
		}
		
		_findclose(iHandle);
	}
}
Example #2
0
//
// readdir
//
// Return a pointer to a dirent structure filled with the information on the
// next entry in the directory.
//
struct dirent *readdir(DIR *dirp) {
    errno = 0;

    /* Check for valid DIR struct. */
    if(!dirp) {
        errno = EFAULT;
        return (struct dirent *)0;
    }

    if(dirp->dd_stat < 0) {
        /* We have already returned all files in the directory
         * (or the structure has an invalid dd_stat). */
        return (struct dirent *)0;
    }
    else if(dirp->dd_stat == 0) {
        /* We haven't started the search yet. */
        /* Start the search */
        dirp->dd_handle = _tfindfirst(dirp->dd_name, &(dirp->dd_dta));

        if(dirp->dd_handle == -1) {
            /* Whoops! Seems there are no files in that
             * directory. */
            dirp->dd_stat = -1;
        }
        else {
            dirp->dd_stat = 1;
        }
    }
    else {
        /* Get the next search entry. */
        if(_tfindnext(dirp->dd_handle, &(dirp->dd_dta))) {
            /* We are off the end or otherwise error.
               _findnext sets errno to ENOENT if no more file
               Undo this. */
            DWORD winerr = GetLastError();
            if(winerr == ERROR_NO_MORE_FILES) {
                errno = 0;
            }
            _findclose(dirp->dd_handle);
            dirp->dd_handle = -1;
            dirp->dd_stat = -1;
        }
        else {
            /* Update the status to indicate the correct
             * number. */
            dirp->dd_stat++;
        }
    }

    if(dirp->dd_stat > 0) {
        /* Successfully got an entry. Everything about the file is
         * already appropriately filled in except the length of the
         * file name. */
        dirp->dd_dir.d_namlen = _tcslen(dirp->dd_dta.name);
        _tcscpy(dirp->dd_dir.d_name, dirp->dd_dta.name);
        return &dirp->dd_dir;
    }

    return (struct dirent *)0;
}
Example #3
0
void EnlistFolders(const KString& Mask, KStrings& Folders, bool bFullPaths, bool bClearFirst)
{
	if(bClearFirst)
		Folders.Clear();

	KString FolderName = GetFilePath(Mask);

	_tfinddata_t FileInfo;
	
	int iHandle = _tfindfirst(Mask, &FileInfo);
	if(iHandle>=0)
	{
		for(;;)
		{
			if(	(FileInfo.attrib & _A_SUBDIR)		&&
				_tcscmp(FileInfo.name, TEXT("."))	&&
				_tcscmp(FileInfo.name, TEXT("..")))
			{
				*Folders.AddLast() = (bFullPaths ? FolderName + FileInfo.name : FileInfo.name) + TEXT("\\");
			}
			
			// To the next file
			if(_tfindnext(iHandle, &FileInfo)==-1)
				break;
		}
		
		_findclose(iHandle);
	}
}
Example #4
0
BOOL CGlobalObj::bOpenFunctioneditorfile(CString omStrNewCFileName)
{
    BOOL bFileFound = TRUE;

    CFunctionEditorDoc* pDoc = CFunctionEditorBase::pCreateNewDocument(m_eBus);
    // file-attribute information
    if (pDoc != nullptr)
    {
        CEditFrameWnd::sm_eBus = m_eBus;
        struct _tfinddata_t fileinfo;
        // Check if file exists
        if (_tfindfirst( omStrNewCFileName.GetBuffer(MAX_PATH), &fileinfo) == -1L)
        {
            bFileFound = pDoc->bCreateNewDocument(omStrNewCFileName);
        }
        if (bFileFound == TRUE)
        {
            //// Now open the selected file
            pDoc->OnOpenDocument(omStrNewCFileName);
            CMultiDocTemplate* pTemplate = m_pEditorDocTemplate;
            m_pEditFrameWnd = (CEditFrameWnd*)(pTemplate->CreateNewFrame(pDoc, nullptr));

            //If null is passed as parameter the m_pdoc->GetNextView(pos)  will
            // give null value
            if (m_pEditFrameWnd != nullptr)
            {
                ASSERT_KINDOF(CEditFrameWnd, m_pEditFrameWnd);
                pTemplate->InitialUpdateFrame(m_pEditFrameWnd, /*nullptr*/pDoc);
            }
        }
    }
    return bFileFound;
}
Example #5
0
int CAimProto::get_avatar_filename(HANDLE hContact, TCHAR* pszDest, size_t cbLen, const TCHAR *ext)
{
	size_t tPathLen;
	bool found = false;

	init_custom_folders();

	TCHAR* path = (TCHAR*)_malloca(cbLen * sizeof(TCHAR));
	if (hAvatarsFolder == NULL || FoldersGetCustomPathT(hAvatarsFolder, path, (int)cbLen, _T("")))
	{
		TCHAR *tmpPath = Utils_ReplaceVarsT(_T("%miranda_avatarcache%"));
		TCHAR *tszModuleName = mir_a2t(m_szModuleName);
		tPathLen = mir_sntprintf(pszDest, cbLen, _T("%s\\%s"), tmpPath, tszModuleName);
		mir_free(tszModuleName);
		mir_free(tmpPath);
	}
	else 
	{
		_tcscpy(pszDest, path);
		tPathLen = _tcslen(pszDest);
	}

	if (ext && _taccess(pszDest, 0))
		CallService(MS_UTILS_CREATEDIRTREET, 0, (LPARAM)pszDest);

	size_t tPathLen2 = tPathLen;
	
	DBVARIANT dbv;
	if (getTString(hContact, AIM_KEY_AH, &dbv)) return GAIR_NOAVATAR;
	tPathLen += mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%s"), dbv.ptszVal);
	DBFreeVariant(&dbv);

	if (ext == NULL)
	{
		mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T(".*"));

		_tfinddata_t c_file;
		long hFile = _tfindfirst(pszDest, &c_file);
		if (hFile > -1L)
		{
			do {
				if (_tcsrchr(c_file.name, '.'))
				{
					mir_sntprintf(pszDest + tPathLen2, cbLen - tPathLen2, _T("\\%s"), c_file.name);
					found = true;
				}
			} while (_tfindnext(hFile, &c_file) == 0);
			_findclose( hFile );
		}
		
		if (!found) pszDest[0] = 0;
	}
	else
	{
		mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, ext);
		found = _taccess(pszDest, 0) == 0;
	}

	return found ? GAIR_SUCCESS : GAIR_WAITFOR;
}
Example #6
0
bool SmileyPackCType::LoadSmileyDir(TCHAR* dir)
{
	bkstring dirs = dir;
	dirs += _T("\\*.*");

	_tfinddata_t c_file;
	INT_PTR hFile = _tfindfirst((TCHAR*)dirs.c_str(), &c_file);
	if (hFile > -1L)
	{
		do {
			if (c_file.name[0] != '.')
			{
				bkstring fullpath = dir;
				fullpath = fullpath + _T("\\") + c_file.name;
				TCHAR* div = _tcsrchr(c_file.name, '.');
				if (div)
				{
					*div = 0;
					SmileyCType *smlc = new SmileyCType(fullpath, c_file.name);
					if (smlc->GetTriggerText().empty())
						delete smlc;
					else
						m_SmileyList.insert(smlc);
				}
			}
		} while( _tfindnext( hFile, &c_file ) == 0 );
		_findclose( hFile );
		AddTriggersToSmileyLookup();
		return true;
	}
	return false;
}
Example #7
0
void CMsnProto::MSN_GetAvatarFileName(MCONTACT hContact, TCHAR* pszDest, size_t cbLen, const TCHAR *ext)
{
	size_t tPathLen = mir_sntprintf(pszDest, cbLen, _T("%s\\%S"), VARST(_T("%miranda_avatarcache%")), m_szModuleName);

	if (_taccess(pszDest, 0))
		CreateDirectoryTreeT(pszDest);

	size_t tPathLen2 = tPathLen;
	if (hContact != NULL) {
		DBVARIANT dbv;
		if (getString(hContact, "PictContext", &dbv) == 0) {
			char* szAvatarHash = MSN_GetAvatarHash(dbv.pszVal);
			if (szAvatarHash != NULL) {
				TCHAR *sztAvatarHash = mir_a2t(szAvatarHash);
				tPathLen += mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%s."), sztAvatarHash);
				mir_free(sztAvatarHash);
				mir_free(szAvatarHash);
			}
			else {
				delSetting(hContact, "PictContext");
				if (cbLen) pszDest[0] = 0;
			}
			db_free(&dbv);
		}
		else if (cbLen)
			pszDest[0] = 0;
	}
	else {
		TCHAR *sztModuleName = mir_a2t(m_szModuleName);
		tPathLen += mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%s avatar."), sztModuleName);
		mir_free(sztModuleName);
	}

	if (ext == NULL) {
		mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("*"));

		bool found = false;
		_tfinddata_t c_file;
		long hFile = _tfindfirst(pszDest, &c_file);
		if (hFile > -1L) {
			do {
				if (_tcsrchr(c_file.name, '.')) {
					mir_sntprintf(pszDest + tPathLen2, cbLen - tPathLen2, _T("\\%s"), c_file.name);
					found = true;
				}
			}
				while(_tfindnext(hFile, &c_file) == 0);
			_findclose( hFile );
		}

		if (!found) pszDest[0] = 0;
	}
	else {
		tPathLen--;
		mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, ext);
	}
}
Example #8
0
/**
 * \brief message handler for ID_FILE_NEW
 *
 * This is a message handler for ID_FILE_NEW
 * This function will be called when user selects
 * File -> Function Editor -> New  menu option.
 * Creates the MRU menu only once
 */
void CCANMonitorApp::OnFileNew()
{
    BOOL bOneChildWndOpen = FALSE;
    bOneChildWndOpen = m_pouFlags->nGetFlagStatus(FUNCEDITOR);

    if(bOneChildWndOpen != TRUE )
    {
        struct _tfinddata_t fileinfo;
        // Find if the current directory has some .c file already created.
        // Check if it has name "NewEdn" if yes, the new file name will be
        // NewEdx where value of x = n+1;
        char cBuffer[_MAX_PATH];
        CString omStrCFileName;
        CString strFilePath;
        _getcwd( cBuffer, _MAX_PATH );
        BOOL bStop = FALSE;
        UINT unCount = 0;

        while (bStop == FALSE)
        {
            omStrCFileName.Format("%s%d%s", "NewEd", ++unCount, ".c");

            // Search for the file name and if it is not present, set
            // the flag to TRUE to break the loop.
            if (_tfindfirst( omStrCFileName.GetBuffer(MAX_PATH), &fileinfo) == -1L)
            {
                strFilePath = cBuffer ;
                strFilePath += "\\"+ omStrCFileName ;
                bStop = TRUE;
            }
        }

        CMainFrame* pMainFrame = static_cast<CMainFrame*> (m_pMainWnd);
        if(pMainFrame != nullptr)
        {
            GetICANNodeSim()->FE_OpenFunctioneditorFile(strFilePath, pMainFrame->GetSafeHwnd(),
                    pMainFrame->m_sExFuncPtr[CAN]);
        }
        //CWinApp::OnFileNew();
        // Since creating of the document
        // loads another menu,
        // the menu created for the MRU
        // would have destroyed. So create
        // the same.
        // And this should be created only once.

        
    }
}
Example #9
0
bool GetSmileyFile(CMString& url, const CMString& packstr)
{
	_TPattern *urlsplit = _TPattern::compile(_T(".*/(.*)"));
	_TMatcher *m0 = urlsplit->createTMatcher(url);

	m0->findFirstMatch();

	CMString filename;
	filename.AppendFormat(_T("%s\\%s\\"), cachepath, packstr.c_str());
	int pathpos = filename.GetLength();
	filename += m0->getGroup(1);

	delete m0;
	delete urlsplit;

	bool needext = filename.Find('.') == -1;
	if (needext)
		filename += _T(".*");

	_tfinddata_t c_file;
	INT_PTR hFile = _tfindfirst((TCHAR*)filename.c_str(), &c_file);
	if (hFile > -1) {
		_findclose(hFile);
		filename.Truncate(pathpos);
		filename += c_file.name;
		url = filename;
		return false;
	}
	if (needext)
		filename.Truncate(filename.GetLength() - 1);

	WaitForSingleObject(g_hDlMutex, 3000);
	dlQueue.insert(new QueueElem(url, filename, needext));
	ReleaseMutex(g_hDlMutex);

	if (!threadRunning) {
		threadRunning = true;
		mir_forkthread(SmileyDownloadThread, NULL);
	}

	url = filename;
	return false;
}
Example #10
0
    bool GetFileList(const tstring& mask, std::set<tstring>& files)
    {
        struct _tfinddata_t file;
        intptr_t            hFile;
        tstring             dirPath = ExtractFilePath(mask);
        size_t              initialSize = files.size();

        if( (hFile = _tfindfirst( mask.c_str(), &file )) != -1L )
        {
            do 
            {
                tstring fileName = dirPath + _T("\\") + file.name;
                files.insert(fileName);
            } 
            while( _tfindnext( hFile, &file ) == 0 );
            _findclose( hFile );
        }
        return initialSize != files.size();
    }
Example #11
0
//This function tests whether we have read access to the
//contents of a directory.  Note:  This function counts on the
//fact that the path is a *directory* path, terminated in backslash.
//
bool
CanReadFromDir(const wchar_t *kpFile)
{
#ifdef _WIN32
    //Try to use _tfindfirst() to get a handle.
    //If we have read access to the directory, this
    //is always guaranteed to succeed because "."
    //will be present even if it's an empty directory
    wchar_t szPath[_MAX_PATH],
          szDrive[_MAX_DRIVE],
          szDir[_MAX_DIR],
          szFname[_MAX_FNAME],
          szExt[_MAX_EXT];
    _tsplitpath(kpFile, szDrive, szDir, szFname, szExt);
    assert(_tcslen(szFname) == 0);
    assert(_tcslen(szExt) == 0);
    _tmakepath(
        szPath,
        szDrive,
        szDir,
        L"*", //NOXLATE
        L"");//NOXLATE
    _wfinddata_t info;
    intptr_t lHandle = _tfindfirst(szPath, &info);
    if (-1 == lHandle)
    {
        //Nope, no read access.
        return false;
    }

    //Looks like we have read access!
    _findclose(lHandle);
#else
    //
    // Used MgFileUtil methods instead.
    //
#endif
    return true;
}
Example #12
0
/******************************************************************************
Function Name    :  OnOK
Input(s)         :
Output           :
Functionality    :  Called when the user presses OK button.
                    Validation of the fileds.

Member of        :  CNodeDetailsDlg
Friend of        :      -
Author(s)        :
Date Created     :
Modification     :
*****************************************************************************/
void CNodeDetailsDlg::OnOK()
{
    BOOL bDuplicateFound = FALSE;
    BOOL bRetVal = TRUE;

    UpdateData(TRUE);
    if (m_omStrNodeName.IsEmpty())
    {
        AfxMessageBox( "Node Name cannot be empty!", MB_OK|MB_ICONINFORMATION );

        GetDlgItem( IDC_EDIT_ANODE_NAME )->SetWindowText(m_psNodeStuctPtr->m_omStrNodeName);
        GetDlgItem( IDC_EDIT_ANODE_NAME )->SetFocus();
        bRetVal = FALSE;
    }
    else
    {
        CSimSysNodeInfo* pSimSysNodeInfo =
            CSimSysManager::ouGetSimSysManager(m_eBus).pomGetSimSysNodeInfo();
        //Check for duplicate node name if the name is changed
        if ( m_psNodeStuctPtr->m_omStrNodeName != m_omStrNodeName)
        {
            if (pSimSysNodeInfo->bIsDuplicateNode( m_omStrNodeName ))
            {
                AfxMessageBox( "Duplicate Node Name found!", MB_OK|MB_ICONINFORMATION );
                GetDlgItem(IDC_EDIT_ANODE_NAME)->SetFocus();
                bRetVal = FALSE;
            }
        }
        if (m_eBus == J1939)
        {
            if (bRetVal == TRUE)
            {
                //Check for duplicate ECU NAME if the current if J1939
                UINT64 unEcuName = (UINT64)m_omEcuName.lGetValue();
                if ( m_psNodeStuctPtr->m_unEcuName != unEcuName)
                {
                    if (pSimSysNodeInfo->bIsDuplicateEcuName(unEcuName))
                    {
                        AfxMessageBox( "Duplicate ECU NAME found!", MB_OK|MB_ICONINFORMATION );
                        GetDlgItem(IDC_EDIT_ECU_NAME)->SetFocus();
                        bRetVal = FALSE;
                    }
                }
            }
            if (bRetVal == TRUE)
            {
                //Check for duplicate Preffered Address
                BYTE byPrefAdres = (BYTE)m_omPreferedAddress.lGetValue();
                if ( m_psNodeStuctPtr->m_byPrefAddress != byPrefAdres)
                {
                    if (pSimSysNodeInfo->bIsDuplicateAddress(byPrefAdres))
                    {
                        INT nChoice = AfxMessageBox( "Another node is configured to claim the same address.\nDo you want to proceed?",
                                                     MB_YESNO|MB_ICONWARNING );
                        if (nChoice == IDNO)
                        {
                            GetDlgItem(IDC_EDIT_ADDRESS)->SetFocus();
                            bRetVal = FALSE;
                        }
                    }
                }
            }
        }
        //Check for duplicate dll
        if( (!m_omStrDllPath.IsEmpty()) &&
                (m_psNodeStuctPtr->m_omStrDllName != m_omStrDllPath))
        {
            if (pSimSysNodeInfo->bIsDuplicateDllName( m_omStrDllPath ))
            {
                AfxMessageBox( "Duplicate Dll found!", MB_OK|MB_ICONINFORMATION );
                GetDlgItem(IDC_EDIT_DLL_PATH)->SetFocus();
                bRetVal = FALSE;
            }
        }
    }
    if ( bRetVal == TRUE )
    {
        //If name is changed
        if (m_psNodeStuctPtr->m_omStrNodeName != m_omStrNodeName)
        {
            m_bIsNodeModified = TRUE;
            m_psNodeStuctPtr->m_omStrNodeName = m_omStrNodeName;
        }
        if (m_psNodeStuctPtr->m_omStrDllName  != m_omStrDllPath)
        {
            //If dll is changed
            m_bIsNodeModified = TRUE;
            //If no error then update the node details and close the dialog box
            m_psNodeStuctPtr->m_omStrDllName  = m_omStrDllPath;
            // Now search for respective *.c file and change it
            CString omStrFilename = m_psNodeStuctPtr->m_omStrDllName;
            omStrFilename.Replace(defDOT_DLL ,defDOT_SMALL_C);
            // file-attribute information
            struct _tfinddata_t fileinfo;
            // Check if file exists
            if (_tfindfirst( omStrFilename.GetBuffer(MAX_PATH), &fileinfo) != -1L)
            {
                m_psNodeStuctPtr->m_omStrFileName = omStrFilename;
            }
        }
        if (m_psNodeStuctPtr->m_byPrefAddress !=
                (BYTE)(m_omPreferedAddress.lGetValue()))
        {
            m_bIsNodeModified = TRUE;
            m_psNodeStuctPtr->m_byPrefAddress = (BYTE)(m_omPreferedAddress.lGetValue());
        }
        if (m_psNodeStuctPtr->m_unEcuName !=
                (UINT64)(m_omEcuName.lGetValue()))
        {
            m_bIsNodeModified = TRUE;
            m_psNodeStuctPtr->m_unEcuName = (UINT64)(m_omEcuName.lGetValue());
        }
        CDialog::OnOK();
    }
}
Example #13
0
// -------------------------------------------------------------
void Actions::ParseDirectory( LPCTSTR rootPath, LPCTSTR extentionPath  )
{
  // make sure that we do not have too many actions
  // this is a sign that something is broken
  // or that we are reading the root directory
  {
    myodd::threads::Lock guard(_mutexActions);
    if (_actions.size() > static_cast<size_t>(::myodd::config::Get(L"paths\\maxcommand", 2048)))
    {
      ASSERT(0); // you have reached the limit!
                   // it is pointless to try and add more command.
      return;
    }
  }

  // make sure that the path that we have is valid.
  ASSERT( _tcslen( rootPath ) > 0 );
  if( _tcslen( rootPath ) == 0 )
  {
    return;
  }

  //  the end path
  std::wstring directory = rootPath;  

  // make sure it has a trailing back slash.
  myodd::files::AddTrailingBackSlash( directory );

  // add the extension
  directory += extentionPath;

  //  add a trailing back slash
  myodd::files::AddTrailingBackSlash( directory );

  //
  //  we could refine the search to
  //  *.bat, *.exe, *.pl
  //  but I am not sure we really need to restrict anything
  // it is up to the user to ensure that they have 
  auto sPath = directory + L"*.*";

  LPTSTR fullPath = NULL;
  if( !myodd::files::ExpandEnvironment( sPath.c_str(), fullPath ) )
  {
    return;
  }
  
  _tfinddata_t fdata;
  const auto ffhandle = _tfindfirst( fullPath, &fdata );
  if( ffhandle != -1 )
  {
    do
    {
      if( _tcscmp(fdata.name, L"." ) == 0 || _tcscmp(fdata.name, L"..") == 0)
      {
        continue;
      }

      //  .svn directories are hidden so we might as well ignore all hidden file.
      if( (fdata.attrib & _A_HIDDEN) == _A_HIDDEN )
      {
        continue;
      }

      if( (fdata.attrib & _A_SUBDIR) == _A_SUBDIR )
      {
        if( IsReservedDir( fdata.name ) )
        {
          continue;
        }
        
        std::wstring subPath( extentionPath );
        subPath += fdata.name;
        myodd::files::AddTrailingBackSlash( subPath );

        ParseDirectory( rootPath, subPath.c_str() );
        continue;
      }

      //  ok add this command
      auto szFullPath( directory);
      szFullPath += fdata.name;

      std::wstring szName( fdata.name);
      szName = myodd::strings::lower(szName );
      
      //  if we don't want to show the extension then strip it.
      if( ::myodd::config::Get( L"commands\\show.extentions", 0 ) == false )
      {
        myodd::files::StripExtension( szName );
      }        

      Add( new Action( _application ,szName, szFullPath));
    }while( _tfindnext( ffhandle, &fdata ) == 0 );

    _findclose( ffhandle );
  }

  delete [] fullPath;
}
Example #14
0
void CFolderListCtrl::RefreshFileList()
{
	std::vector<CFLCItemData *>arrListCache(m_nItemCount);
	int i;
	for (i=0;i<m_nItemCount;i++)
	{
		arrListCache[i] = reinterpret_cast<CFLCItemData *>(GetItemData(i));
		arrListCache[i]->m_bFoundOnRefresh = false;
	}

	SCStringVector::iterator itExt = m_Properties.m_vsExt.begin();
	CSCADString sPath;

	struct _tfinddata_t fd;

	int nLargeIconInd = 0;
	int nSmallIconInd = 0;
	int nItemCount = m_nItemCount;

	for( ; itExt != m_Properties.m_vsExt.end(); ++itExt )
	{
		sPath = m_sFolderPath + _T("\\") + *itExt;

		intptr_t hFindHandle = _tfindfirst( sPath, &fd );

		if( hFindHandle == -1 )
			continue;
		AddFileTypeIcons(fd, nLargeIconInd, nSmallIconInd);
		do
		{
			bool bFileFound = false;
			CSCADString sFileName;
			
			if( m_sFolderPath.GetLength() && 
				( m_sFolderPath[m_sFolderPath.GetLength()-1] == _T('\\') ||
				m_sFolderPath[m_sFolderPath.GetLength()-1] == _T('/') ) )
				sFileName = m_sFolderPath+ fd.name;
			else
				sFileName = m_sFolderPath + (  _T("\\") ) + fd.name;
			for (int k=0; k<nItemCount;k++)
			{
				if (arrListCache[k]->m_sFilePath == sFileName)
				{
					bFileFound = true;
					arrListCache[k]->m_bFoundOnRefresh = true;
					if (fd.time_write != arrListCache[k]->m_tModified)
					{
						arrListCache[k]->m_bProcessed = false;
						if (m_strSelectedPath.CompareNoCase(arrListCache[k]->m_sFilePath)==0)
						{
							CSCAD3DMdlSettings::Get3DS()->SetViewFilePath( arrListCache[k]->m_sFilePath, arrListCache[k]->m_sExt );
						}
						break;
					}
				}
			}
			if (!bFileFound)
			{
				AddFileItem(fd, nLargeIconInd, nSmallIconInd,*itExt);
			}
		} while( _tfindnext( hFindHandle, &fd ) != -1 );
		_findclose( hFindHandle );
	}
	m_nImageBalance = 0;
	for (i=0;i<m_nItemCount;i++)
	{
		CFLCItemData *pData = reinterpret_cast<CFLCItemData *>(GetItemData(i));
		if (!pData->m_bFoundOnRefresh)
		{
			delete pData;
			CListCtrl::DeleteItem(i);
			m_nItemCount--;
		}
		else
		{
			if (!pData->m_bProcessed)
				m_nImageBalance++;
		}

	}

	SortItems( m_flciColumns[m_nCurColumn].m_fnCmp, m_bSortAscending );

	ASSERT(m_nItemCount == GetItemCount());
	UpdateFileCount();
	SetRedrawItemPos( 0, true );

}
Example #15
0
BOOL CFolderListCtrl::SetCurFolder( const CSCADString& sFolderPath, bool bForce)
{
	if( !bForce && !m_sFolderPath.CompareNoCase( sFolderPath ) )
		return TRUE;
	Timer.Start();
	m_DirChangeListener.SetDir(sFolderPath, m_hWnd);
/*
	SCDefProjInfo proj_info;

	SCADDefProj::GetInfo( m_Properties.m_DefProj, proj_info );
	SCMdl3DSetCameraPos( proj_info.m_ptViewDir, proj_info.m_ptUpOrient );
*/
	// ReSharper disable once CppEntityAssignedButNoRead
	extern SCDefProjType ThumbProjection;
	ThumbProjection = m_Properties.m_DefProj;
	if(CSCAD3DMdlSettings::Get3DS())
	{
		CSCAD3DMdlSettings::Get3DS()->CancelDraw();
		CSCAD3DMdlSettings::Get3DS()->SetStartDrawPos( 0 );
	}

	CreateImageList();
	DeleteAllItemsData();
	DeleteAllItems();
	m_sFolderPath = sFolderPath;
	m_nItemCount = 0;
	m_nImageBalance = 0;
	m_nSelectedItem = -1;
	SetSelectionMark( 0 );
	
	int i;

	for( i = m_imlLargeIcons.GetImageCount() - 1; i >= 0; i-- )
		m_imlLargeIcons.Remove( i );
	for( i = m_imlSmallIcons.GetImageCount() - 1; i >= 0; i-- )
		m_imlSmallIcons.Remove( i );

	if( _taccess( sFolderPath, 0 ) == -1 )
		return TRUE;

	SCStringVector::iterator itExt = m_Properties.m_vsExt.begin();
	CSCADString sPath;

	struct _tfinddata_t fd;

	int nLargeIconInd = 0;
	int nSmallIconInd = 0;

	for( ; itExt != m_Properties.m_vsExt.end(); ++itExt )
	{
		sPath = m_sFolderPath + _T("\\") + *itExt;

		intptr_t hFindHandle = _tfindfirst( sPath, &fd );

		if( hFindHandle == -1 )
			continue;

		AddFileTypeIcons(fd, nLargeIconInd, nSmallIconInd);

		do
		{
			AddFileItem(fd, nLargeIconInd, nSmallIconInd, *itExt);
		} while( _tfindnext( hFindHandle, &fd ) != -1 );
		_findclose( hFindHandle );
	}
	SortItems( m_flciColumns[m_nCurColumn].m_fnCmp, m_bSortAscending );
	m_nImageBalance = m_nItemCount;
	SetRedrawItemPos( 0, true );
	if( AfxGetMainWnd() )
	{
		CSCADViewerStatBar &theStatusBar = static_cast<CScadViewerFrame*>(AfxGetMainWnd())->GetStatusBar();
		theStatusBar.SetFileCount( m_nItemCount );
	}
	UpdateFileCount();		

	return TRUE;
}
Example #16
0
/* gets the list of mechanisms */
int _sasl_load_plugins(const add_plugin_list_t *entrypoints,
		       const sasl_callback_t *getpath_cb,
		       const sasl_callback_t *verifyfile_cb)
{
    int result;
    TCHAR cur_dir[PATH_MAX], full_name[PATH_MAX+2], prefix[PATH_MAX+2];
				/* 1 for '\\' 1 for trailing '\0' */
    TCHAR * pattern;
    TCHAR c;
    int pos;
    int retCode = SASL_OK;
    char *utf8path = NULL;
    TCHAR *path=NULL;
    int position;
    const add_plugin_list_t *cur_ep;
    struct _stat statbuf;		/* filesystem entry information */
    intptr_t fhandle;			/* file handle for _findnext function */
    struct _tfinddata_t finddata;	/* data returned by _findnext() */
    size_t prefix_len;
    
    /* for static plugins */
    add_plugin_t *add_plugin;
    _sasl_plug_type type;
    _sasl_plug_rec *p;

    if (! entrypoints
	|| ! getpath_cb
	|| getpath_cb->id != SASL_CB_GETPATH
	|| ! getpath_cb->proc
	|| ! verifyfile_cb
	|| verifyfile_cb->id != SASL_CB_VERIFYFILE
	|| ! verifyfile_cb->proc)
	return SASL_BADPARAM;

    /* do all the static plugins first */

    for (cur_ep = entrypoints; cur_ep->entryname; cur_ep++) {

        /* What type of plugin are we looking for? */
        if (!strcmp(cur_ep->entryname, "sasl_server_plug_init")) {
            type = SERVER;
            add_plugin = (add_plugin_t *)sasl_server_add_plugin;
        }
        else if (!strcmp(cur_ep->entryname, "sasl_client_plug_init")) {
            type = CLIENT;
            add_plugin = (add_plugin_t *)sasl_client_add_plugin;
        }
        else if (!strcmp(cur_ep->entryname, "sasl_auxprop_plug_init")) {
            type = AUXPROP;
            add_plugin = (add_plugin_t *)sasl_auxprop_add_plugin;
        }
        else if (!strcmp(cur_ep->entryname, "sasl_canonuser_init")) {
            type = CANONUSER;
            add_plugin = (add_plugin_t *)sasl_canonuser_add_plugin;
        }
        else {
            /* What are we looking for then? */
            return SASL_FAIL;
        }
        for (p = _sasl_static_plugins; p->type; p++) {
            if (type == p->type)
                result = add_plugin(p->name, p->plug);
        }
    }

    /* get the path to the plugins */
    result = ((sasl_getpath_t *)(getpath_cb->proc))(getpath_cb->context,
						    &utf8path);
    if (result != SASL_OK) return result;
    if (!utf8path) return SASL_FAIL;

    if (sizeof(TCHAR) == sizeof(char)) {
        path = (TCHAR*)utf8path;
    }
    else {
        path = _sasl_utf8_to_wchar(utf8path);
        if (!path) return SASL_FAIL;
    }

    if (_tcslen(path) >= PATH_MAX) { /* no you can't buffer overrun */
	    retCode = SASL_FAIL;
        goto cleanup;
    }

    position=0;
    do {
	pos=0;
	do {
	    c=path[position];
	    position++;
	    cur_dir[pos]=c;
	    pos++;
	} while ((c!=PATHS_DELIMITER) && (c!=0));
	cur_dir[pos-1]='\0';


/* : check to make sure that a valid directory name was passed in */
	if (_tstat (cur_dir, &statbuf) < 0) {
	    continue;
	}
	if ((statbuf.st_mode & S_IFDIR) == 0) {
	    continue;
	}

    _tcscpy(prefix, cur_dir);
	prefix_len = _tcslen (prefix);

/* : Don't append trailing \ unless required */
	if (prefix[prefix_len-1] != '\\') {
        _tcscat(prefix,_T("\\"));
	    prefix_len++;
	}

	pattern = prefix;

/* : Check that we have enough space for "*.dll" */
	if ((prefix_len + DLL_MASK_LEN) > (sizeof(prefix) / sizeof(TCHAR) - 1)) {
	    _sasl_log(NULL, SASL_LOG_WARN, "plugin search mask is too big");
            continue;
	}

	_tcscat (prefix + prefix_len, _T("*") DLL_SUFFIX);

        fhandle = _tfindfirst (pattern, &finddata);
        if (fhandle == -1) {	/* no matching files */
            continue;
        }

/* : Truncate "*.dll" */
	prefix[prefix_len] = '\0';

	do {
	    size_t length;
	    void *library;
	    char *c;
	    char plugname[PATH_MAX];
	    int entries;

	    length = _tcslen(finddata.name);
	    if (length < 5) { /* At least <Ch>.dll */
		continue; /* can not possibly be what we're looking for */
	    }

/* : Check for overflow */
	    if (length + prefix_len >= PATH_MAX) continue; /* too big */

	    if (_tcscmp(finddata.name + (length - _tcslen(DLL_SUFFIX)), DLL_SUFFIX) != 0) {
		continue;
	    }

/* : Check that it is not a directory */
	    if ((finddata.attrib & _A_SUBDIR) == _A_SUBDIR) {
		continue;
	    }

/* : Construct full name from prefix and name */

        _tcscpy (full_name, prefix);
        _tcscat (full_name, finddata.name);
		
/* cut off .dll suffix -- this only need be approximate */
        if (sizeof(TCHAR) != sizeof(char)) {
            if (WideCharToMultiByte(CP_UTF8, 0, finddata.name, -1, plugname, sizeof(plugname), NULL, NULL) == 0) { // in case of unicode use utf8
                continue;
            }
        }
        else {
            _tcscpy((TCHAR*)plugname, finddata.name); // w/o unicode local enconding is fine
        }
	    c = strchr(plugname, '.');
	    if (c != NULL) *c = '\0';

	    result = _tsasl_get_plugin (full_name, verifyfile_cb, &library);

	    if (result != SASL_OK) {
		continue;
	    }

	    entries = 0;
	    for (cur_ep = entrypoints; cur_ep->entryname; cur_ep++) {
		result = _sasl_plugin_load(plugname,
					   library,
					   cur_ep->entryname,
					   cur_ep->add_plugin);
		if (result == SASL_OK) {
		    ++entries;
		}
		/* If this fails, it's not the end of the world */
	    }
	    if (entries == 0) {
		_sasl_remove_last_plugin();
	    }

	} while (_tfindnext (fhandle, &finddata) == 0);
	
	_findclose (fhandle);

    } while ((c!='=') && (c!=0));

cleanup:
    if (sizeof(TCHAR) != sizeof(char)) {
        sasl_FREE(path); /* It's always allocated in coversion to wchar */
    }
    return retCode;
}