예제 #1
0
void File::copyFile(const tstring& source, const tstring& target)
{
	if (!::CopyFile(formatPath(source).c_str(), formatPath(target).c_str(), FALSE))
	{
		throw FileException(Util::translateError(GetLastError())); // 2012-05-03_22-05-14_LZE57W5HZ7NI3VC773UG4DNJ4QIKP7Q7AEBLWOA_AA236F48_crash-stack-r502-beta24-x64-build-9900.dmp
	}
}
예제 #2
0
void File::renameFile(const tstring& source, const tstring& target)
{
	if (!::MoveFile(formatPath(source).c_str(), formatPath(target).c_str()))
	{
		// Can't move, try copy/delete...
		copyFile(source, target);
		deleteFileT(source);
	}
}
예제 #3
0
int Directory::copyFiles(const QStringList &files, const QString &toPath, bool overWrite)
{
    int size = files.size();
    int count = 0;
	QString to_path(formatPath(toPath));
	QDir to_dir;
	QFile old_file;
	QFile new_file;
	QFileInfo old_file_info;
	QFileInfo new_file_info;

    for ( int i=0;i<size;i++ )
    {
		old_file.setFileName(files[i]);
		old_file_info.setFile(old_file);
        new_file.setFileName(to_path + QDir::separator()  + old_file_info.fileName());
		new_file_info.setFile(new_file);
		to_dir.setPath(new_file.fileName());
		to_dir.mkpath(new_file_info.path());

		if ((overWrite) || (!new_file.exists()))
        {
			old_file.copy(new_file.fileName());
            m_copyFileCount++;
			count++;
			Q_EMIT currentFile(m_copyFileCount, files[i]);
        }
    }
    return count;
}
예제 #4
0
StringList File::findFiles(const string& path, const string& pattern, bool p_append_path /*= true */)
{
	StringList ret;
	
	// [+] FlylinkDC
	auto appendToRet = [p_append_path, path](StringList & ret, const string & l_name, const char * extra) -> void
	{
		if (p_append_path) //[+]FlylinkDC++ Team TODO - проверить все места, где наружу не нужно отдавать путь
			ret.push_back(path + l_name + extra);
		else
			ret.push_back(l_name + extra);
	};
	// [~] FlylinkDC
	WIN32_FIND_DATA data;
	HANDLE hFind = FindFirstFile(formatPath(Text::toT(path + pattern)).c_str(), &data);
	if (hFind != INVALID_HANDLE_VALUE)
	{
		do
		{
			const char* extra = (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? "\\" : "";
			// [!] FlylinkDC
			const string l_name = Text::fromT(data.cFileName);
			appendToRet(ret, l_name, extra);
			// [~] FlylinkDC
		}
		while (FindNextFile(hFind, &data));
		FindClose(hFind);
	}
	return ret;
}
예제 #5
0
void Directory::doDirTree(const QString &fromPath, const QString &toPath,
                          const QStringList &nameFilters, bool overWrite,
                          QStringList &findFiles, bool isFind)
{
	QQueue<QString> from_all_dirs;
	QQueue<QString> to_all_dirs;
	QDir find_in_dir;
	QStringList file_list;
	QStringList dir_list;
	QString current_from_path;
	QString current_to_path;

	from_all_dirs.push_back(fromPath);
	to_all_dirs.push_back(toPath);

    while(from_all_dirs.size() > 0)
	{
		current_from_path = from_all_dirs.head();
		current_to_path = to_all_dirs.head();
		find_in_dir.setPath(current_from_path);
		file_list = find_in_dir.entryList(nameFilters, QDir::Files);

		for (int i = 0; i < file_list.size(); i++)
        {
			file_list[i] = formatPath(current_from_path) + file_list[i];
        }

		if (isFind)
        {
			findFiles += file_list;
        }else
        {
			copyFiles(file_list, current_to_path, overWrite);
        }
		dir_list = find_in_dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);

		for (int i = 0; i < dir_list.size(); i++)
		{
			from_all_dirs += formatPath(current_from_path) + dir_list[i];
			to_all_dirs += formatPath(current_to_path) + dir_list[i];
		}
		from_all_dirs.pop_front();
		to_all_dirs.pop_front();
	}
}
예제 #6
0
//[+] Greylink
int64_t File::getTimeStamp(const string& aFileName) throw(FileException)
{
	WIN32_FIND_DATA fd;
	HANDLE hFind = FindFirstFile(Text::toT(formatPath(aFileName)).c_str(), &fd);
	if (hFind == INVALID_HANDLE_VALUE)
		throw FileException(Util::translateError(GetLastError()) + ": " + aFileName);
	FindClose(hFind);
	return *(int64_t*)&fd.ftLastWriteTime;
}
예제 #7
0
void File::setTimeStamp(const string& aFileName, const uint64_t stamp) throw(FileException)
{
	HANDLE hCreate = CreateFile(formatPath(Text::toT(aFileName)).c_str(), FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
	if (hCreate == INVALID_HANDLE_VALUE)
		throw FileException(Util::translateError(GetLastError()) + ": " + aFileName);
	if (!SetFileTime(hCreate, NULL, NULL, (FILETIME*)&stamp))
	{
		CloseHandle(hCreate); //[+]PPA
		throw FileException(Util::translateError(GetLastError()) + ": " + aFileName);
	}
	CloseHandle(hCreate);
}
예제 #8
0
void copyFile(std::string srcFile, std::string destFile) {
	formatPath(srcFile);
	formatPath(destFile);

	DWORD attr = GetFileAttributes(srcFile.c_str());
	if (attr & FILE_ATTRIBUTE_DIRECTORY) {
		std::size_t pos = destFile.find_last_of('\\');
		destFile = destFile.substr(0, pos);
		deepCopyDirectory(destFile);
		SHFILEOPSTRUCT s = {0};
		s.hwnd = g_MainWin;
		s.wFunc = FO_COPY;
		s.pTo = destFile.c_str();
		s.pFrom = srcFile.c_str();
		s.fFlags = FOF_SILENT;
		SHFileOperation(&s);
	} else {
		std::size_t pos = destFile.find_last_of('\\');
		deepCopyDirectory(destFile.substr(0, pos));
		CopyFile(srcFile.c_str(), destFile.c_str(), false);
	}
}
예제 #9
0
void File::ensureDirectory(const tstring& aFile) noexcept
{
	dcassert(!aFile.empty());
	// Skip the first dir...
	tstring::size_type start = aFile.find_first_of(_T("\\/"));
	if (start == tstring::npos)
		return;
	start++;
	while ((start = aFile.find_first_of(_T("\\/"), start)) != tstring::npos)
	{
		::CreateDirectory((formatPath(aFile.substr(0, start + 1))).c_str(), NULL); //TODO Crash r501 sp1
		start++;
	}
}
 void getPaths(TreeNode* root, vector<int> path, vector<string> &ret) {
     path.push_back(root->val);
     if (root->left == NULL && root->right == NULL) {
         // new path
         ret.push_back(formatPath(path));
     } else {
         if (root->left) {
             getPaths(root->left, path, ret);
         }
         if (root->right) {
             getPaths(root->right, path, ret);
         }
     }
 }
예제 #11
0
void MainWindow::bRunClick() {
  if (splitStarted && splitterThread) {
    splitterThread->stop();
    return;
  }
  
  status("");
  
  int linesCount = ui->leLinesCount->text().toInt();
  QString inputFile = ui->lePath->text();
  
  QString outDir = ui->leOutDir->text();
  if (outDir.trimmed().length() == 0) {
    QString inDir = ui->lePath->text();
    QFileInfo info(inDir);
    outDir = info.absolutePath();
  }
  
  outDir = formatPath(outDir);
  outDir.replace(QRegExp("/$"), "");
  outDir += "/";
  createDirs(outDir);
  
  QString outFilename = ui->leOutFilename->text();
  if (outFilename.trimmed().length() == 0) {
    QFileInfo info(inputFile);
    outFilename = info.fileName();
  }
  string outputFile = outDir.toStdString() + outFilename.toStdString();
  
  splitterThread = new SplitterThread();
  splitterThread->setInputFile(inputFile.toStdString());
  splitterThread->setOutputFile(outputFile);
  splitterThread->setLinesCount(linesCount);
  
  connect( splitterThread, SIGNAL(finished()), this, SLOT(splitThreadFinished()) );
  
  splitterThread->start();
  
  splitStarted = true;
  ui->bRun->setText("Stop");
}
예제 #12
0
void File::init(const tstring& aFileName, int access, int mode, bool isAbsolutePath) // [!] IRainman fix.
{
	dcassert(access == WRITE || access == READ || access == (READ | WRITE));
	
	int m;
	if (mode & OPEN)
	{
		if (mode & CREATE)
		{
			m = (mode & TRUNCATE) ? CREATE_ALWAYS : OPEN_ALWAYS;
		}
		else
		{
			m = (mode & TRUNCATE) ? TRUNCATE_EXISTING : OPEN_EXISTING;
		}
	}
	else
	{
		if (mode & CREATE)
		{
			m = (mode & TRUNCATE) ? CREATE_ALWAYS : CREATE_NEW;
		}
		else
		{
			m = 0;
			dcassert(0);
		}
	}
	const DWORD shared = FILE_SHARE_READ | (mode & SHARED ? (FILE_SHARE_WRITE | FILE_SHARE_DELETE) : 0);
	
	const tstring outPath = isAbsolutePath ? formatPath(aFileName) : aFileName;
	
	h = ::CreateFile(outPath.c_str(), access, shared, nullptr, m, mode & NO_CACHE_HINT ? 0 : FILE_FLAG_SEQUENTIAL_SCAN, nullptr);
	
	if (h == INVALID_HANDLE_VALUE)
	{
//[!] Не включать - падаем на рекурсии
//        LogManager::getInstance()->message("File::File error = " + Util::toString(GetLastError()) + " File = " + aFileName);
		throw FileException(Util::translateError(GetLastError()));
	}
}
예제 #13
0
    bool listdir(StringArray & out, const std::wstring & path)
    {
        out.clear();

        std::wstring fname = path;
        formatPath(fname);
        fname += L'*';

        WIN32_FIND_DATA findData;
        HANDLE hFind = ::FindFirstFile(fname.c_str(), &findData);
        if(hFind == INVALID_HANDLE_VALUE) return false;

        do
        {
            const std::wstring & str = findData.cFileName;
            if(str != L"." && str != L"..")
            {
                out.push_back(str);
            }
        }while(::FindNextFile(hFind, &findData));

        ::FindClose(hFind);
        return true;
    }
예제 #14
0
bool File::isExist(const tstring& aFileName) noexcept // [+] IRainman
{
	const DWORD attr = GetFileAttributes(formatPath(aFileName).c_str());
	return (attr != INVALID_FILE_ATTRIBUTES);
}