Ejemplo n.º 1
0
void CFolder::process() {
    
    this->setStat(200);
    m_output = "<html><head><title>The list of directory" + m_path.getFileInfo().at(0) + "</title></head><body>";
    
    m_output += "<h1>The list of content in directory "+ m_path.getFileInfo().at(0) +"</h1>";
    m_output += "<ul>";
    
    for (string x : getFolderContent()) {
        
        m_output += "<li><a href=\"./"+ x +"\">"+ x +"</a></li>";
        
    }
    
    m_output += "</ul></body></html>";
    
}
Ejemplo n.º 2
0
	bool getFolderContent(shared_ptr<Path> folder)
	{
		WinDir dir(folder->path(), L"*");
		for (WinDir::iterator it = dir.begin(); it != dir.end(); ++it) {
			if (it.is_file()) {
				++Statistics::getInstance()->FoundFiles;
				Statistics::getInstance()->FoundFilesSize += it.size();
				if (SkipHidden && (it.attr() & FILE_ATTRIBUTE_HIDDEN)) {
					++Statistics::getInstance()->IgnoredHidden;
					{
						ConsoleColor col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
						logDebug(L"File ignored [hidden]: ");
					}
					logDebug(L"\"%s\"\n", it.name());
				} else if (SkipSystem && (it.attr() & FILE_ATTRIBUTE_SYSTEM)) {
					++Statistics::getInstance()->IgnoredSystem;
					{
						ConsoleColor col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
						logDebug(L"File ignored [system]: ");
					}
					logDebug(L"\"%s\"\n", it.name());
				} else if (it.size() == 0LL) {
					++Statistics::getInstance()->IgnoredZero;
					{
						ConsoleColor col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
						logDebug(L"File ignored [zero]: ");
					}
					logDebug(L"\"%s\"\n", it.name());
				} else if (!LinkSmall && (it.size() < MIN_FILE_SIZE)) {
					++Statistics::getInstance()->IgnoredSmall;
					{
						ConsoleColor col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
						logDebug(L"File ignored [small]: ");
					}
					logDebug(L"\"%s\"\n", it.name());
				} else {
					//logFile(info);
					data.push_back(shared_ptr < File > (new File(folder, it.name())));
				}
			} else {
				if (SkipJunct && it.is_link()) {
					++Statistics::getInstance()->IgnoredJunc;
					{
						ConsoleColor col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
						logDebug(L"Dir  ignored [junction]: ");
					}
					logDebug(L"\"%s\"\n", it.name());
				} else {
					if (it.is_link())
						++Statistics::getInstance()->FoundJuncs;
					else
						++Statistics::getInstance()->FoundDirs;
//					logFile(info);
					if (recursive) {
						bool Result = getFolderContent(shared_ptr < Path > (new Path(folder, it.name())));
						if (!Result)
							return false;
					}
				}
			}
		}

//		WIN32_FIND_DATAW	info;
//		HANDLE	hFind = ::FindFirstFileW(mask.c_str(), &info);
//		if (hFind == INVALID_HANDLE_VALUE) {
//			logError(::GetLastError(), L"Unable to read folder \"%s\" content.\n", path.c_str());
//		} else {
//			do {
//				if (is_valid_filename(info.cFileName)) {
//					if (!(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
//						uintmax_t	filesize = MyUI64(info.nFileSizeLow, info.nFileSizeHigh);
//						++Statistics::getInstance()->FoundFiles;
//						Statistics::getInstance()->FoundFilesSize += filesize;
//						if (SkipHidden && (info.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)) {
//							++Statistics::getInstance()->IgnoredHidden;
//							{
//								ConsoleColor	col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
//								logDebug(L"File ignored [hidden]: ");
//							}
//							logDebug(L"\"%s\"\n", info.cFileName);
//						} else if (SkipSystem && (info.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)) {
//							++Statistics::getInstance()->IgnoredSystem;
//							{
//								ConsoleColor	col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
//								logDebug(L"File ignored [system]: ");
//							}
//							logDebug(L"\"%s\"\n", info.cFileName);
//						} else if (filesize == 0LL) {
//							++Statistics::getInstance()->IgnoredZero;
//							{
//								ConsoleColor	col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
//								logDebug(L"File ignored [zero]: ");
//							}
//							logDebug(L"\"%s\"\n", info.cFileName);
//						} else if (!LinkSmall && (filesize < MIN_FILE_SIZE)) {
//							++Statistics::getInstance()->IgnoredSmall;
//							{
//								ConsoleColor	col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
//								logDebug(L"File ignored [small]: ");
//							}
//							logDebug(L"\"%s\"\n", info.cFileName);
//						} else {
//							logFile(info);
//							data.push_back(shared_ptr<File>(new File(folder, info.cFileName)));
//						}
//					} else {
//						if (SkipJunct && info.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
//							++Statistics::getInstance()->IgnoredJunc;
//							{
//								ConsoleColor	col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
//								logDebug(L"Dir  ignored [junction]: ");
//							}
//							logDebug(L"\"%s\"\n", info.cFileName);
//						} else {
//							if (info.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
//								++Statistics::getInstance()->FoundJuncs;
//							else
//								++Statistics::getInstance()->FoundDirs;
//							logFile(info);
//							if (recursive) {
//								bool	Result = getFolderContent(shared_ptr<Path>(new Path(folder, info.cFileName)));
//								if (!Result)
//									return	false;
//							}
//						}
//					}
//				}
//			} while (::FindNextFile(hFind, &info) != 0);
//			dwError = ::GetLastError();
//			::FindClose(hFind);
//			if (dwError != ERROR_NO_MORE_FILES) {
//				logError(dwError, L"FindNextFile error\n");
//				return	false;
//			}
//		}
		return true;
	}
Ejemplo n.º 3
0
	void Process()
	{
		PathListIt it = paths.begin();
		while (it != paths.end()) {
			getFolderContent(*it);
			++it;
		}
		logInfo(L"Files to process:\t%8llu\n", data.size());

		logDebug(L"");
		std::sort(data.begin(), data.end(), CompareBySizeAndTime);
		std::pair<FilesListIt, FilesListIt> bounds;
		FilesListIt srch = data.begin();
		while (srch != data.end()) {
			logCounter(L"Files left:\t%8llu", std::distance(srch, data.end()));
			bounds = std::equal_range(srch, data.end(), *srch, CompareBySize);
			if (std::distance(bounds.first, bounds.second) == 1) {
				++Statistics::getInstance()->filesFoundUnique;
				data.erase(bounds.first);
			} else {
				while (srch != bounds.second) {
					FilesListIt it = srch;
					++it;
					shared_ptr<File>& f1 = *srch;
					while (it != bounds.second) {
						shared_ptr<File>& f2 = *it;
						AutoUTF buf1(f1->path());
						AutoUTF buf2(f2->path());
						{
							ConsoleColor col(FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_GREEN);
							logDebug(L"Comparing files [size = %I64u]:\n", f1->size());
						}
						logDebug(L"  %s\n", buf1.c_str());
						logDebug(L"  %s\n", buf2.c_str());
						++Statistics::getInstance()->fileCompares;
						f1->refresh();
						f2->refresh();
						if (AttrMustMatch && f1->attr() != f2->attr()) {
							{
								ConsoleColor col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
								logDebug(L"  Attributes of files do not match, skipping\n");
							}
							Statistics::getInstance()->fileMetaDataMismatch++;
							++it;
							break;
						}
						if (TimeMustMatch && f1->mtime() != f2->mtime()) {
							{
								ConsoleColor col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
								logDebug(L"  Modification timestamps of files do not match, skipping\n");
							}
							Statistics::getInstance()->fileMetaDataMismatch++;
							++it;
							break;
						}
						if (!isSameVolume(*f1, *f2)) {
							{
								ConsoleColor col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
								logDebug(L"  Files ignored - on different volumes\n");
							}
							++Statistics::getInstance()->filesOnDifferentVolumes;
							++it;
							break;
						}
						if (f1 == f2) {
							++Statistics::getInstance()->fileAlreadyLinked;
							{
								ConsoleColor col(FOREGROUND_INTENSITY | FOREGROUND_GREEN);
								logDebug(L"  Files ignored - already linked\n");
							}
							++it;
							break;
						}
						if (f1->size() > FirstBlock) {
							if (!f1->LoadHashMini()) {
								break;
							}
							if (!f2->LoadHashMini()) {
								it = data.erase(it);
								continue;
							}
						} else {
							if (!f1->LoadHashFull()) {
								break;
							}
							if (!f2->LoadHashFull()) {
								it = data.erase(it);
								continue;
							}
						}
						if (isIdentical(*f1, *f2)) {
							++Statistics::getInstance()->fileContentSame;
							if (logLevel == LOG_VERBOSE) {
								{
									ConsoleColor col(FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_GREEN);
									logVerbose(L"Comparing files [size = %I64u]:\n", f1->size());
								}
								logVerbose(L"  %s\n", buf1.c_str());
								logVerbose(L"  %s\n", buf2.c_str());
							}
							{
								ConsoleColor col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
								logVerbose(L"  Files are equal, hard link possible\n");
							}
							if (hardlink) {
								f1->hardlink(*f2);
							}
							Statistics::getInstance()->FreeSpaceIncrease += f1->size();
							it = data.erase(it);
						} else {
							{
								ConsoleColor col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
								logDebug(L"  Files differ in content (hash)\n");
							}
							Statistics::getInstance()->hashComparesHit1++;
							++it;
						}
					}
					srch = data.erase(srch);
				}
			}
			srch = bounds.second;
		}
		logCounter(L"                              ");
	}