Exemplo n.º 1
0
std::string FileUtils::getcwd()
{
    const boost::filesystem::path p = boost::filesystem::current_path();
    std::string path = p.string();
    path = addTrailingSlash(path);
    return path;
}
Exemplo n.º 2
0
std::string FileUtils::getDirectory(const std::string& path)
{
    const boost::filesystem::path dir = boost::filesystem::path(path).parent_path();
    std::string ret = dir.string();
    ret = addTrailingSlash(ret);
    return ret;
}
Exemplo n.º 3
0
void et::findSubfolders(const std::string& folder, bool recursive, StringList& list)
{
	StringList folderList;
	
	ET_STRING_TYPE normalizedFolder = ET_STRING_TO_PARAM_TYPE(addTrailingSlash(folder));
	ET_STRING_TYPE foldersSearchPath = normalizedFolder + allFilesMask;

	WIN32_FIND_DATA folders = { };
	HANDLE folderSearch = FindFirstFile(foldersSearchPath.c_str(), &folders);
	if (folderSearch != INVALID_HANDLE_VALUE)
	{
		do
		{
			ET_STRING_TYPE name(folders.cFileName);
			bool isFolder = (folders.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY;
			if (isFolder && (name != currentFolder) && (name != previousFolder))
			{
				folderList.push_back(ET_STRING_TO_OUTPUT_TYPE(normalizedFolder + 
					name + ET_STRING_FROM_CONST_CHAR("\\")));
			}
		}
		while (FindNextFile(folderSearch, &folders));
		FindClose(folderSearch);
	}

	if (recursive)
	{
		for (const std::string& i : folderList)
			findSubfolders(i, true, list);
	}

	list.insert(list.end(), folderList.begin(), folderList.end());
}
Exemplo n.º 4
0
void et::findSubfolders(const std::string& folder, bool recursive, StringList& list)
{
	std::string normalizedFolder = addTrailingSlash(folder);
	std::string foldersSearchPath = normalizedFolder + "*.*";
	StringList folderList;

	WIN32_FIND_DATA folders = { };
	HANDLE folderSearch = FindFirstFile(foldersSearchPath.c_str(), &folders);
	if (folderSearch != INVALID_HANDLE_VALUE)
	{
		do
		{
			if (strcmp(folders.cFileName, ".") && strcmp(folders.cFileName, "..") && 
				((folders.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY))
			{
				std::string folderName(folders.cFileName);
				folderList.push_back(normalizedFolder + folderName + "\\");
			}
		}
		while (FindNextFile(folderSearch, &folders));
		FindClose(folderSearch);
	}

	if (recursive)
	{
		for (const std::string& i : folderList)
			findSubfolders(i, true, list);
	}

	list.insert(list.end(), folderList.begin(), folderList.end());
}
Exemplo n.º 5
0
void et::findFiles(const std::string& folder, const std::string& mask, bool recursive, StringList& list)
{
	ET_STRING_TYPE normalizedFolder = ET_STRING_TO_PARAM_TYPE(addTrailingSlash(folder));
	ET_STRING_TYPE searchPath = normalizedFolder + ET_STRING_TO_PARAM_TYPE(mask);

	StringList folderList;
	if (recursive)
	{
		ET_STRING_TYPE foldersSearchPath = normalizedFolder + allFilesMask;

		WIN32_FIND_DATA folders = { };
		HANDLE folderSearch = FindFirstFile(foldersSearchPath.c_str(), &folders);
		if (folderSearch != INVALID_HANDLE_VALUE)
		{
			do
			{
				bool isFolder = (folders.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY;
				ET_STRING_TYPE name(folders.cFileName);
				if (isFolder && (name != currentFolder) && (name != previousFolder))
					folderList.push_back(ET_STRING_TO_OUTPUT_TYPE(normalizedFolder + name));

			}
			while (FindNextFile(folderSearch, &folders));
			FindClose(folderSearch);
		}
	}

	WIN32_FIND_DATA data = { };
	HANDLE search = FindFirstFile(searchPath.c_str(), &data);
	if (search != INVALID_HANDLE_VALUE)
	{
		do
		{
			bool isAcceptable = 
				((data.dwFileAttributes & FILE_ATTRIBUTE_NORMAL) == FILE_ATTRIBUTE_NORMAL) || 
				((data.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) == FILE_ATTRIBUTE_ARCHIVE) ||
				((data.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY);

			ET_STRING_TYPE name(data.cFileName);

			if (isAcceptable && (name != currentFolder) && (name != previousFolder))
				list.push_back(ET_STRING_TO_OUTPUT_TYPE(normalizedFolder + name));
		}
		while (FindNextFile(search, &data));
		FindClose(search);
	}

	if (recursive)
	{
		for (const std::string& i : folderList)
			findFiles(i, mask, recursive, list);
	}
}
Exemplo n.º 6
0
std::string et::libraryBaseFolder()
{
	wchar_t* path = nullptr;
	SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, nullptr, &path);

	if (path == nullptr) 
		return emptyString;

	std::string result = addTrailingSlash(unicodeToUtf8(path));
	CoTaskMemFree(path);
	return result;
}
Exemplo n.º 7
0
std::string et::documentsBaseFolder()
{
	wchar_t* path = nullptr;
	SHGetKnownFolderPath(FOLDERID_Documents, 0, nullptr, &path);

	if (path == nullptr) 
		return std::string();

	std::string result = addTrailingSlash(unicodeToUtf8(path));
	CoTaskMemFree(path);
	return result;
}
Exemplo n.º 8
0
void et::findFiles(const std::string& folder, const std::string& mask, bool recursive, StringList& list)
{
	std::string normalizedFolder = addTrailingSlash(folder);
	std::string searchPath = normalizedFolder + mask;

	StringList folderList;
	if (recursive)
	{
		std::string foldersSearchPath = normalizedFolder + "*.*";
		WIN32_FIND_DATA folders = { };
		HANDLE folderSearch = FindFirstFile(foldersSearchPath.c_str(), &folders);
		if (folderSearch != INVALID_HANDLE_VALUE)
		{
			do
			{
				if (strcmp(folders.cFileName, ".") && strcmp(folders.cFileName, "..") && 
					((folders.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY))
				{
					std::string folderName(folders.cFileName);
					folderList.push_back(normalizedFolder + folderName);
				}
			}
			while (FindNextFile(folderSearch, &folders));
			FindClose(folderSearch);
		}
	}

	WIN32_FIND_DATA data = { };
	HANDLE search = FindFirstFile(searchPath.c_str(), &data);

	if (search != INVALID_HANDLE_VALUE)
	{
		do
		{
			if (strcmp(data.cFileName, ".") && strcmp(data.cFileName, ".."))
			{
				std::string fileName(data.cFileName);
				list.push_back(normalizedFolder + fileName);
			}
		}
		while (FindNextFile(search, &data));
		FindClose(search);
	}

	if (recursive)
	{
		for (const std::string& i : folderList)
			findFiles(i, mask, recursive, list);
	}
}
Exemplo n.º 9
0
std::string et::applicationDataFolder()
{
	ET_CHAR_TYPE buffer[MAX_PATH] = { };
	GetCurrentDirectory(MAX_PATH, buffer);
	return addTrailingSlash(ET_STRING_TO_OUTPUT_TYPE(buffer));
}
Exemplo n.º 10
0
// Get the directory part of a filename.
string FileUtils::getDirectory(const string& path)
{
    const boost::filesystem::path dir =
         boost::filesystem::path(path).parent_path();
    return addTrailingSlash(dir.string());
}
Exemplo n.º 11
0
string FileUtils::getcwd()
{
    const boost::filesystem::path p = boost::filesystem::current_path();
    return addTrailingSlash(p.string());
}
Exemplo n.º 12
0
// Get the directory part of a filename.
string getDirectory(const string& path)
{
    const pdalboost::filesystem::path dir =
         pdalboost::filesystem::path(path).parent_path();
    return addTrailingSlash(dir.string());
}
Exemplo n.º 13
0
string getcwd()
{
    const pdalboost::filesystem::path p = pdalboost::filesystem::current_path();
    return addTrailingSlash(p.string());
}
Exemplo n.º 14
0
std::string et::applicationDataFolder()
{
	char buffer[MAX_PATH] = { };
	GetCurrentDirectory(MAX_PATH, buffer);
	return addTrailingSlash(std::string(buffer));
}
Exemplo n.º 15
0
void AutoCompletion::showPathCompletion()
{
    // Get current line (at most MAX_PATH characters "backwards" from current caret).
    generic_string currentLine;
    {
        const long bufSize = MAX_PATH;
        TCHAR buf[bufSize + 1];
        const int currentPos = _pEditView->execute(SCI_GETCURRENTPOS);
        const int startPos = max(0, currentPos - bufSize);
        _pEditView->getGenericText(buf, bufSize + 1, startPos, currentPos);
        currentLine = buf;
    }

    /* Try to figure out which path the user wants us to complete.
       We need to know the "raw path", which is what the user actually wrote.
       But we also need to know which directory to look in (pathToMatch), which might
       not be the same as what the user wrote. This happens when the user types an
       incomplete name.
       For instance: the user wants to autocomplete "C:\Wind", and assuming that no such directory
       exists, this means we should list all files and directories in C:.
    */
    generic_string rawPath, pathToMatch;
    if(! getPathsForPathCompletion(currentLine, rawPath, pathToMatch))
        return;

    // Get all files and directories in the path.
    generic_string autoCompleteEntries;
    {
        HANDLE hFind;
        WIN32_FIND_DATA data;
        generic_string pathToMatchPlusSlash = addTrailingSlash(pathToMatch);
        generic_string searchString = pathToMatchPlusSlash + TEXT("*.*");
        hFind = ::FindFirstFile(searchString.c_str(), &data);
        if(hFind != INVALID_HANDLE_VALUE)
        {
            // Maximum number of entries to show. Without this it appears to the user like N++ hangs when autocompleting
            // some really large directories (c:\windows\winxsys on my system for instance).
            const unsigned int maxEntries = 2000;
            unsigned int counter = 0;
            do
            {
                if(++counter > maxEntries)
                    break;

                if(generic_string(data.cFileName) == TEXT(".") || generic_string(data.cFileName) == TEXT(".."))
                    continue;

                if(! autoCompleteEntries.empty())
                    autoCompleteEntries += TEXT("\n");

                autoCompleteEntries += pathToMatchPlusSlash;
                autoCompleteEntries += data.cFileName;
                if(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) // If directory, add trailing slash.
                    autoCompleteEntries += TEXT("\\");

            } while(::FindNextFile(hFind, &data));
            ::FindClose(hFind);
        }
        else
        {
            return;
        }
    }

    // Show autocompletion box.
    _pEditView->execute(SCI_AUTOCSETSEPARATOR, WPARAM('\n'));
    _pEditView->execute(SCI_AUTOCSETIGNORECASE, true);
    _pEditView->showAutoComletion(rawPath.length(), autoCompleteEntries.c_str());
    _activeCompletion = CompletionPath;
    return;
}