void AddInstrumentsJob::Run() {
        try {
            InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb();

            switch (Mode) {
                case NON_RECURSIVE:
                    Progress.SetTotalFileCount(GetFileCount());
                    db->AddInstrumentsNonrecursive(DbDir, FsDir, insDir, &Progress);
                    break;
                case RECURSIVE:
                    db->AddInstrumentsRecursive(DbDir, FsDir, false, insDir, &Progress);
                    break;
                case FLAT:
                    db->AddInstrumentsRecursive(DbDir, FsDir, true, insDir, &Progress);
                    break;
                default:
                    throw Exception("Unknown scan mode");
            }

            // Just to be sure that the frontends will be notified about the job completion
            if (Progress.GetTotalFileCount() != Progress.GetScannedFileCount()) {
                Progress.SetTotalFileCount(Progress.GetScannedFileCount());
            }
            if (Progress.GetStatus() != 100) Progress.SetStatus(100);
        } catch(Exception e) {
            Progress.SetErrorStatus(-1);
            throw e;
        }
    }
示例#2
0
int CIndex::GetFileNames(const char* VfsName, char** FileNames, int NumberToGet, int MaxPathLength)
{
	string Name = VfsName;
	transform(Name.begin(), Name.end(), Name.begin(), ::toupper);
	int Files = 0;
	int MaxCount = GetFileCount(Name.c_str());
	if(MaxCount == 0)
	{
		return 0;
	}
	if(NumberToGet > MaxCount)
	{
		NumberToGet = MaxCount;
	}
	for(vector<CVFSFile*>::iterator i = ListVFS->begin(); i != ListVFS->end(); ++i)
	{
		if(!strcmp((*i)->GetVFSName(), Name.c_str()))
		{
			int k = 0;
			for(vector<CVFSFile::File*>::iterator j = (*i)->Files->begin(); j != (*i)->Files->end(); ++j)
			{
				if(!(*j)->deleted)
				{
					strncpy(FileNames[k], (*j)->path, MaxPathLength - 1);
					FileNames[k][MaxPathLength - 1] = 0;
					Files++;
					k++;
				}
			}
		}
	}
	return Files;
}
示例#3
0
bool CDownloadQueue::RemoveSource(CUpDownClient* toremove, bool	WXUNUSED(updatewindow), bool bDoStatsUpdate)
{
	bool removed = false;
	toremove->DeleteAllFileRequests();
	
	for ( uint16 i = 0; i < GetFileCount(); i++ ) {
		CPartFile* cur_file = GetFileByIndex( i );
		
		// Remove from source-list
		if ( cur_file->DelSource( toremove ) ) {
			cur_file->RemoveDownloadingSource(toremove);
			removed = true;
			if ( bDoStatsUpdate ) {
				cur_file->UpdatePartsInfo();
			}
		}

		// Remove from A4AF-list
		cur_file->RemoveA4AFSource( toremove );
	}


	if ( !toremove->GetFileComment().IsEmpty() || toremove->GetFileRating()>0) {
		toremove->GetRequestFile()->UpdateFileRatingCommentAvail();
	}
	
	toremove->SetRequestFile( NULL );
	toremove->SetDownloadState(DS_NONE);

	// Remove from downloadlist widget
	Notify_DownloadCtrlRemoveSource(toremove, (CPartFile*)NULL);
	toremove->ResetFileStatusInfo();

	return removed;
}
示例#4
0
文件: GetDirs.c 项目: DMEW/SSH-ls
int GetDirs(char *currDir, fileobj **Files)
{
	DIR *dirp;
	int count=0;
	struct dirent *dirEntry;
	fileobj *f;
	//Open handle to directory path
	if((dirp = opendir(currDir)) != NULL)
	{
		//file count
		count = GetFileCount(dirp);
		f = malloc(count*sizeof(fileobj));
		int iFile=0;
		while((dirEntry=readdir(dirp))!=NULL)
		{
			//if file object is a directory, then set Color Red - Else Green
			if(dirEntry->d_type == DT_DIR)
				strcpy(f[iFile].color, RED);
			else
				strcpy(f[iFile].color, GREEN);
			strcpy(f[iFile].name,dirEntry->d_name);
			iFile=iFile+1;
		}          
		*Files=f;
		return count;
	}
	else
	{
		//Error
		return 0;
	}
}
示例#5
0
void CDownloadQueue::AddDownload(CPartFile* file, bool paused, uint8 category)
{
	wxCHECK_RET(!IsFileExisting(file->GetFileHash()), wxT("Adding duplicate part-file"));

	if (file->GetStatus(true) == PS_ALLOCATING) {
		file->PauseFile();
	} else if (paused && GetFileCount()) {
		file->StopFile();
	}

	{
		wxMutexLocker lock(m_mutex);
		m_filelist.push_back( file );
		DoSortByPriority();
	}

	NotifyObservers( EventType( EventType::INSERTED, file ) );
	if (category < theApp->glob_prefs->GetCatCount()) {
		file->SetCategory(category);
	} else {
		AddDebugLogLineN( logDownloadQueue, wxT("Tried to add download into invalid category.") );
	}
	Notify_DownloadCtrlAddFile( file );
	theApp->searchlist->UpdateSearchFileByHash(file->GetFileHash()); 	// Update file in the search dialog if it's still open
	AddLogLineC(CFormat(_("Downloading %s")) % file->GetFileName() );
}
示例#6
0
const wchar_t* CDirectoryUtil::GetFilePath(int index)
{
	assert(index >= 0 && index < GetFileCount());

	POSITION pos = m_files.FindIndex(index);

	return m_files.GetAt(pos);
}
示例#7
0
void CDownloadQueue::ResetCatParts(uint8 cat)
{
	for ( uint16 i = 0; i < GetFileCount(); i++ ) {
		CPartFile* file = GetFileByIndex( i );
		
		if ( file->GetCategory() == cat ) {
			// Reset the category
			file->SetCategory( 0 );
		} else if ( file->GetCategory() > cat ) {
			// Set to the new position of the original category
			file->SetCategory( file->GetCategory() - 1 );
		}
	}
}
void CAlbumFolder::Delete(BOOL bIfEmpty)
{
	if ( m_pParent == NULL ) return;

	if ( bIfEmpty )
	{
		if ( ! m_bAutoDelete ) return;
		if ( m_bCollSHA1 ) return;
		if ( GetFolderCount() ) return;
		if ( GetFileCount() ) return;
	}

	m_pParent->OnFolderDelete( this );
	delete this;
}
示例#9
0
void CDownloadQueue::SetCatPrio(uint8 cat, uint8 newprio)
{
	for ( uint16 i = 0; i < GetFileCount(); i++ ) {
		CPartFile* file = GetFileByIndex( i );
		
		if ( !cat || file->GetCategory() == cat ) {
			if ( newprio == PR_AUTO ) {
				file->SetAutoDownPriority(true);
			} else {
				file->SetAutoDownPriority(false);
				file->SetDownPriority(newprio);
			}
		}
	}
}
示例#10
0
void CCollectionFile::Render(CString& strBuffer) const
{
	strBuffer.Preallocate( GetFileCount() * 128 + 256 );

	strBuffer.Format( L"<html>\n<head>\n"
		L"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n"
		L"<title>%s</title>\n"
		L"<style type=\"text/css\">\n"
		L"body  { margin: 0px; padding: 0px; background-color: #ffffff; color: #000000; font-family: %s; font-size: %upx; }\n"
		L"h1    { text-align: left; color: #ffffff; height: 64px; margin: 0px; padding: 20px; font-size: 10pt; font-weight: bold; background-image: url(res://Envy.exe/312); }\n"
		L"table { font-size: 8pt; width: 100%%; }\n"
		L"td    { background-color: #e0e8f0; padding: 4px; }\n"
		L".num  { width: 40px; text-align: center; }\n"
		L".url  { text-align: left; cursor: hand; }\n"
		L".size { width: 100px; text-align: center; }\n"
		L"</style>\n</head>\n<body>\n<h1>%s</h1>\n<table>\n",
		(LPCTSTR)GetTitle(),
		(LPCTSTR)Settings.Fonts.DefaultFont, Settings.Fonts.DefaultSize,
		(LPCTSTR)GetTitle() );

	DWORD i = 1;
	for ( POSITION pos = GetFileIterator(); pos; ++i )
	{
		CCollectionFile::File* pFile = GetNextFile( pos );

		CString strURN;
		if ( pFile->m_oSHA1 )
			strURN = pFile->m_oSHA1.toUrn();
		else if ( pFile->m_oTiger )
			strURN = pFile->m_oTiger.toUrn();
		else if ( pFile->m_oED2K )
			strURN = pFile->m_oED2K.toUrn();
		else if ( pFile->m_oMD5 )
			strURN = pFile->m_oMD5.toUrn();
		else if ( pFile->m_oBTH )
			strURN = pFile->m_oBTH.toUrn();

		CString strTemp;
		strTemp.Format( L"<tr><td class=\"num\">%u</td>"
			L"<td class=\"url\" onclick=\"if ( ! window.external.open('%s') ) window.external.download('%s');\" onmouseover=\"window.external.hover('%s');\" onmouseout=\"window.external.hover('');\">%s</td>"
			L"<td class=\"size\">%s</td></tr>\n",
			i, (LPCTSTR)strURN, (LPCTSTR)strURN, (LPCTSTR)strURN, (LPCTSTR)pFile->m_sName,
			(LPCTSTR)Settings.SmartVolume( pFile->m_nSize ) );
		strBuffer += strTemp;
	}

	strBuffer += L"</table>\n</body>\n</html>";
}
示例#11
0
void CAlbumFolder::Serialize(CArchive& ar, int nVersion)
{
	POSITION pos;

	if ( ar.IsStoring() )
	{
		ar << m_sSchemaURI;

		ar.WriteCount( m_pXML != NULL ? 1 : 0 );
		if ( m_pXML ) m_pXML->Serialize( ar );

		ar << m_bCollSHA1;
		if ( m_bCollSHA1 ) ar.Write( &m_pCollSHA1, sizeof(SHA1) );

		ar << m_sName;
		ar << m_bExpanded;
		ar << m_bAutoDelete;
		ar << m_sBestView;

		ar.WriteCount( GetFolderCount() );

		for ( pos = GetFolderIterator() ; pos ; )
		{
			CAlbumFolder* pFolder = GetNextFolder( pos );
			pFolder->Serialize( ar, nVersion );
		}

		ar.WriteCount( GetFileCount() );

		for ( pos = GetFileIterator() ; pos ; )
		{
			CLibraryFile* pFile = GetNextFile( pos );
			ar << pFile->m_nIndex;
		}
	}
	else
	{
		CLibraryFile* pCollection = NULL;

		if ( m_pParent != NULL )
		{
			ar >> m_sSchemaURI;
			m_pSchema = SchemaCache.Get( m_sSchemaURI );
		}
		else
		{
示例#12
0
UINT64 CUnzipper::GetUnzipSize()
{
	if (muUncompressedSize == 0) {
		UINT64 nFile = GetFileCount();

		GotoFirstFile();

		while (nFile--)
		{
			UZ_FileInfo info;
			GetFileInfo(info);
			muUncompressedSize += info.dwUncompressedSize;
			if (!GotoNextFile())
				break;
		}
	}
	return muUncompressedSize;
}
示例#13
0
BOOL CUnzipper::GotoFile(int nFile)
{
	if (!m_uzFile)
		return FALSE;

	if (nFile < 0 || nFile >= GetFileCount())
		return FALSE;

	GotoFirstFile();

	while (nFile--)
	{
		if (!GotoNextFile())
			return FALSE;
	}

	return TRUE;
}
示例#14
0
// The purpose of this function is test is any of the files in
// the list point to a directory. If so, this function must
// return false. It must also return false on any kind of error
bool GtkToolkitFileChooser::VerifySaveFiles()
{
	for (int i=0; i<GetFileCount(); i++)
	{
		char* filename = g_filename_from_utf8(GetFileName(i), -1, 0, 0, 0);
		if (!filename)
			return false;
		struct stat s;
		int rc = stat(filename, &s);
		if (rc == -1)
		{
			if (errno == ENOENT)
				continue;
			return false;
		}
		if (S_ISDIR(s.st_mode))
			return false;
		g_free(filename);
	}

	return true;
}
示例#15
0
BOOL CUnzipper::UnzipTo(LPCTSTR szFolder, BOOL bIgnoreFilePath)
{
	if (!m_uzFile)
		return FALSE;

	if (!szFolder || !CreateFolder(szFolder))
		return FALSE;

	if (GetFileCount() == 0)
		return FALSE;

	if (!GotoFirstFile())
		return FALSE;

	// else
	do
	{
		if (!UnzipFile(szFolder, bIgnoreFilePath))
			return FALSE;
	}
	while (GotoNextFile());
	
	return TRUE;
}
示例#16
0
文件: vfs.cpp 项目: clbr/netradiant
 int getFileCount(const char *filename, int flags)
 {
   return GetFileCount(filename, flags);
 }
示例#17
0
void CDownloadQueue::LoadSourceSeeds()
{
	for ( uint16 i = 0; i < GetFileCount(); i++ ) {
		GetFileByIndex( i )->LoadSourceSeeds();
	}
}
示例#18
0
bool Panel::NeedUpdatePanel(const Panel *AnotherPanel) const
{
	/* Обновить, если обновление разрешено и пути совпадают */
	return (!Global->Opt->AutoUpdateLimit || static_cast<unsigned>(GetFileCount()) <= static_cast<unsigned>(Global->Opt->AutoUpdateLimit)) && equal_icase(AnotherPanel->m_CurDir, m_CurDir);
}
示例#19
0
void CDownloadQueue::LoadMetFiles(const CPath& path)
{
	AddLogLineNS(CFormat(_("Loading temp files from %s.")) % path.GetPrintable());
	
	std::vector<CPath> files;

	// Locate part-files to be loaded
	CDirIterator TempDir(path);
	CPath fileName = TempDir.GetFirstFile(CDirIterator::File, wxT("*.part.met"));
	while (fileName.IsOk()) {
		files.push_back(path.JoinPaths(fileName));

		fileName = TempDir.GetNextFile();
	}

	// Loading in order makes it easier to figure which
	// file is broken in case of crashes, or the like.
	std::sort(files.begin(), files.end());

	// Load part-files	
	for ( size_t i = 0; i < files.size(); i++ ) {
		AddLogLineNS(CFormat(_("Loading PartFile %u of %u")) % (i + 1) % files.size());
		fileName = files[i].GetFullName();
		CPartFile *toadd = new CPartFile();
		bool result = toadd->LoadPartFile(path, fileName) != 0;
		if (!result) {
			// Try from backup
			result = toadd->LoadPartFile(path, fileName, true) != 0;
		}
		if (result && !IsFileExisting(toadd->GetFileHash())) {
			{
				wxMutexLocker lock(m_mutex);
				m_filelist.push_back(toadd);
			}
			NotifyObservers(EventType(EventType::INSERTED, toadd));
			Notify_DownloadCtrlAddFile(toadd);
		} else {
			wxString msg;
			if (result) {
				msg << CFormat(wxT("WARNING: Duplicate partfile with hash '%s' found, skipping: %s"))
					% toadd->GetFileHash().Encode() % fileName;
			} else {
				// If result is false, then reading of both the primary and the backup .met failed
				AddLogLineN(_("ERROR: Failed to load backup file. Search http://forum.amule.org for .part.met recovery solutions."));
				msg << CFormat(wxT("ERROR: Failed to load PartFile '%s'")) % fileName;
			}
			AddLogLineCS(msg);

			// Delete the partfile object in the end.
			delete toadd;
		}
	}
	AddLogLineNS(_("All PartFiles Loaded."));
	
	if ( GetFileCount() == 0 ) {
		AddLogLineN(_("No part files found"));
	} else {
		AddLogLineN(CFormat(wxPLURAL("Found %u part file", "Found %u part files", GetFileCount())) % GetFileCount());

		DoSortByPriority();
		CheckDiskspace( path );
		Notify_ShowUpdateCatTabTitles();
	}
}
示例#20
0
bool 
GetFileCount(
	const LPCWSTR& in_lpszPathW, 
	DWORD& io_iCount,
	std::vector<std::wstring>& io_VecFiles,
	std::list<std::wstring>&   in_SkippedExtensions,
	const bool in_bDontRecurse = false)
{
	_ASSERT(in_lpszPathW);

	std::wstring strPathW(in_lpszPathW);
	
	_ASSERT( strPathW.length() );

	if(!PathIsDirectoryW(in_lpszPathW)) return false;

	if( strPathW.length())
	{
		if( strPathW[ strPathW.length() - 1 ] == L'\\' )
		{
			strPathW += L"*.*";
		}
		else
		{
			strPathW += L"\\*.*";
		}
	}
	
	TRACEW2(L"Doing a findfile on [%s] count is [%d]\n", strPathW.c_str(), io_iCount);

	WIN32_FIND_DATAW fileData={0};	
	
	//The first handle returns a valid file handle which is not the case with CFileFind::FindFile() 
	HANDLE hFind = FindFirstFileW(strPathW.c_str(), &fileData);

	if(hFind != INVALID_HANDLE_VALUE)
	{
		BOOL bWorking = true;
		std::wstring filePath = ExtractDirectoryW(strPathW);
		while(bWorking)
		{
			const std::wstring fileName(fileData.cFileName);

			if( ( (fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && IsDots(fileName) ) || (fileData.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT))
			{
				bWorking = FindNextFileW(hFind, &fileData);
				continue;
			}

			if(fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			{
				if(!in_bDontRecurse)
				{
					TRACEW2(L"Doing a recursive GetFileCount on [%s] count is [%d]\n", fileData.cFileName, io_iCount);
					GetFileCount( (filePath + fileName).c_str(), io_iCount, io_VecFiles, in_SkippedExtensions);
				}
				else
				{
					TRACE0("Not doing a recurse, in_bDontRecurse is true");
				}
			}
			else
			{
				if(in_SkippedExtensions.size())
				{
					// There's something in the list
					// Look for the current extension in the list, if it's there do not increment the counter

					const std::wstring extension (getExtensionW(fileName).c_str());

					TRACEW2(L"Gonna look for extension [%s] of file [%s] in the list of excluded extension\n", extension.c_str(), fileName.c_str());
					
					std::list<std::wstring>::const_iterator i = std::find(in_SkippedExtensions.begin(), in_SkippedExtensions.end(), extension);

					if(i == in_SkippedExtensions.end()) // extension not in list
					{
						io_VecFiles.push_back(filePath + fileName);
						++io_iCount;
					}
					else
					{
						TRACEW1(L"Skipped file [%s], it matched a skipped extension\n", fileName.c_str());
					}
				}
				else
				{
					io_VecFiles.push_back(filePath + fileName);
					++io_iCount;
				}
			}			
			bWorking = FindNextFileW(hFind,&fileData);
		}
		FindClose(hFind);
	}

	return true;
}
示例#21
0
/*
	instead of using just "test.exe" as the file name
	(LPSTR)getFileNameOnly(s).c_str()
	I use the whole path.

	Looks much better in Winrar and with the MS Cab viewer as one ca see the entier file paths

	Except that it doesn't always work....*sigh*. So you'll have to use the filename
	to determine what the full path was.

*/
bool 
MakeCab(const std::wstring& in_Where, 
		const std::string& in_Why, 
		DWORD& o_NumFilesInCab, 
		const std::wstring& in_StrThisFileOnly,
		const bool in_bDontRecurse = false) 
{
	g_CurrentDescription			= in_Why;
	ERF							erf = { 0 };
	CCAB			 cab_parameters = { 0 };	
	client_state				 cs = { 0 };

	set_cab_parameters(&cab_parameters);

	HFCI hfci = FCICreate(
		&erf,
		file_placed,
		mem_alloc,
		mem_free,
        fci_open,
        fci_read,
        fci_write,
        fci_close,
        fci_seek,
        fci_delete,
		get_temp_file,
        &cab_parameters,
        &cs
	);

	if (hfci == NULL)
	{
		printf("FCICreate() failed: code %d [%s]\n", erf.erfOper, return_fci_error_string( (FCIERROR)erf.erfOper));
		return false;
	}

	o_NumFilesInCab = 0;
	std::vector<std::wstring>	VecFiles;
	std::list<std::wstring>	    SkippedExtensions;

	if(in_StrThisFileOnly.empty())
	{
		if( GetFileCount(in_Where.c_str(), o_NumFilesInCab, VecFiles, SkippedExtensions, in_bDontRecurse) && o_NumFilesInCab)
		{
			wprintf(L"Ready to create a CAB using [%s] with [%d] files in it...\r\n", in_Where.c_str(),  o_NumFilesInCab);		
			printf("Destination CAB: [%s]\r\n", GetExeDir().c_str());
		}
		else
		{
			wprintf(L"Cannot perform under [%s]...Specify a valid, non-empty folder\r\n", in_Where.c_str());
			printf("Destination CAB: [%s]\r\n", GetExeDir().c_str());
			return false;
		}
	}
	else
	{
		++o_NumFilesInCab;
		VecFiles.push_back(in_StrThisFileOnly);
	}


	// For each file in 'in_Where' folder and subfolder, unless 'in_StrThisFileOnly' param was specified

	for each(std::wstring s in VecFiles)	
	{
		if (FALSE == FCIAddFile(
				hfci,
				(LPSTR)wide2Ansi(s).c_str(),		// file to add, can't be a folder, needs full path 
				(LPSTR)getFileNameOnly(s).c_str(),	// file name in cabinet file, and should not include any path information (e.g. “TEST.EXE”). 
				FALSE,						 //  specifies whether the file should be executed automatically when the cabinet is extracted 
				get_next_cabinet,
				progress,		// should point to a function which is called periodically by FCI so that the application may send a progress report to the user
				get_open_info,	// point to a function which opens a file and returns its datestamp, timestamp, and attributes
				COMPRESSION_TYPE))
			{
				printf("FCIAddFile(%s) failed: code %d [%s]\n", wide2Ansi(s).c_str(), erf.erfOper, return_fci_error_string( (FCIERROR)erf.erfOper));
				TRACE3("FCIAddFile(%s) failed: code %d [%s]\n", wide2Ansi(s).c_str(), erf.erfOper, return_fci_error_string( (FCIERROR)erf.erfOper));
				//FCIDestroy(hfci);
				//return false;
				// Try to keep a possible good file created so far...
				o_NumFilesInCab--;
			}
	}

	/*
	The FCIFlushCabinet API forces the current cabinet under construction to be completed immediately and written to disk.  
	Further calls to FCIAddFile will cause files to be added to another cabinet.  It is also possible that there exists pending 
	data in FCI’s internal buffers that will may require spillover into another cabinet, if the current cabinet has reached the 
	application-specified media size limit.
	*/

	if(o_NumFilesInCab > 0)
	{
		if (FALSE == FCIFlushCabinet(
			hfci,
			FALSE,				// The fGetNextCab flag determines whether the function pointed to by the supplied GetNextCab parameter, will be called.  
			get_next_cabinet,	// If fGetNextCab is TRUE, then GetNextCab will be called to obtain continuation information
			progress))
		{
			printf("FCIFlushCabinet() failed: code %d [%s]\n", erf.erfOper, return_fci_error_string( (FCIERROR)erf.erfOper));
			FCIDestroy(hfci);
			return false;
		}
	}

    if (FCIDestroy(hfci) != TRUE)
	{
		printf("FCIDestroy() failed: code %d [%s]\n", erf.erfOper, return_fci_error_string( (FCIERROR)erf.erfOper));
		return false;
	}

	return o_NumFilesInCab > 0;
}