mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-09-23 06:53:43 +00:00
Bulk import script early version + StuffIt 5 fixes.
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
#include <string>
|
||||
|
||||
#include "GpUnicode.h"
|
||||
#include "WindowsUnicodeToolShim.h"
|
||||
|
||||
#include <Windows.h>
|
||||
#include <vector>
|
||||
#include <direct.h>
|
||||
|
||||
// This library provides front-ends and shims to make tools a bit more portable by handling all path strings as UTF-8,
|
||||
// and providing a "main" entry point that is also UTF-8.
|
||||
@@ -121,6 +123,58 @@ void ScanDirectoryForExtension(std::vector<std::string> &outPaths, const char *p
|
||||
FindClose(h);
|
||||
}
|
||||
|
||||
struct DirectoryScanContext
|
||||
{
|
||||
WIN32_FIND_DATAW m_findDataW;
|
||||
HANDLE m_handle;
|
||||
bool m_first;
|
||||
|
||||
std::string m_utf8Name;
|
||||
DirectoryScanEntry m_currentEntry;
|
||||
};
|
||||
|
||||
static void ParseDirEntry(DirectoryScanContext &context)
|
||||
{
|
||||
context.m_utf8Name = ConvertWStringToUTF8(context.m_findDataW.cFileName);
|
||||
context.m_currentEntry.m_name = context.m_utf8Name.c_str();
|
||||
}
|
||||
|
||||
DirectoryScanContext *opendir_utf8(const char *name)
|
||||
{
|
||||
DirectoryScanContext *context = new DirectoryScanContext();
|
||||
|
||||
std::wstring dirFilter = std::wstring(L"\\\\?\\") + ConvertUTF8ToWString(name) + L"\\*";
|
||||
|
||||
context->m_handle = FindFirstFileW(dirFilter.c_str(), &context->m_findDataW);
|
||||
if (context->m_handle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
delete context;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
context->m_first = true;
|
||||
return context;
|
||||
}
|
||||
|
||||
DirectoryScanEntry *readdir_utf8(DirectoryScanContext *dir)
|
||||
{
|
||||
if (dir->m_first)
|
||||
dir->m_first = false;
|
||||
else
|
||||
{
|
||||
if (!FindNextFileW(dir->m_handle, &dir->m_findDataW))
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ParseDirEntry(*dir);
|
||||
return &dir->m_currentEntry;
|
||||
}
|
||||
|
||||
void closedir_utf8(DirectoryScanContext *context)
|
||||
{
|
||||
FindClose(context->m_handle);
|
||||
delete context;
|
||||
}
|
||||
|
||||
int toolMain(int argc, const char **argv);
|
||||
|
||||
|
Reference in New Issue
Block a user