mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-09-23 06:53:43 +00:00
Remove unused functions from tool shim, add int64 file ops
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#include "WindowsUnicodeToolShim.h"
|
||||
|
||||
#include <cstdio>
|
||||
@@ -97,3 +98,13 @@ void ScanDirectoryForExtension
|
||||
}
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
int fseek_int64(FILE *f, int64_t offset, int origin)
|
||||
{
|
||||
return fseeko(f, static_cast<off_t>(offset), origin);
|
||||
}
|
||||
|
||||
int64_t ftell_int64(FILE *f)
|
||||
{
|
||||
return static_cast<int64_t>(ftello(f));
|
||||
}
|
||||
|
@@ -123,57 +123,14 @@ void ScanDirectoryForExtension(std::vector<std::string> &outPaths, const char *p
|
||||
FindClose(h);
|
||||
}
|
||||
|
||||
struct DirectoryScanContext
|
||||
int fseek_int64(FILE *f, int64_t offset, int origin)
|
||||
{
|
||||
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();
|
||||
return _fseeki64(f, offset, origin);
|
||||
}
|
||||
|
||||
DirectoryScanContext *opendir_utf8(const char *name)
|
||||
int64_t ftell_int64(FILE *f)
|
||||
{
|
||||
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;
|
||||
return _ftelli64(f);
|
||||
}
|
||||
|
||||
int toolMain(int argc, const char **argv);
|
||||
|
@@ -1,28 +1,12 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <stdio.h>
|
||||
|
||||
FILE *fopen_utf8(const char *path, const char *options);
|
||||
int fseek_int64(FILE *f, int64_t offset, int origin);
|
||||
int64_t ftell_int64(FILE *f);
|
||||
int fputs_utf8(const char *str, FILE *f);
|
||||
int mkdir_utf8(const char *path);
|
||||
void TerminateDirectoryPath(std::string &path);
|
||||
void ScanDirectoryForExtension(std::vector<std::string>& outPaths, const char *path, const char *ending, bool recursive);
|
||||
|
||||
#ifdef _WIN32
|
||||
struct DirectoryScanContext;
|
||||
struct DirectoryScanEntry
|
||||
{
|
||||
const char *m_name;
|
||||
};
|
||||
|
||||
DirectoryScanContext *opendir_utf8(const char *name);
|
||||
DirectoryScanEntry *readdir_utf8(DirectoryScanContext *dir);
|
||||
void closedir_utf8(DirectoryScanContext *context);
|
||||
|
||||
#else
|
||||
|
||||
inline int _fseeki64(FILE *stream, long offset, int whence) {
|
||||
return fseek(stream, offset, whence);
|
||||
}
|
||||
inline long _ftelli64(FILE *stream) { return ftell(stream); };
|
||||
#endif
|
||||
|
@@ -70,22 +70,22 @@ size_t CFileReader::FileSize() const
|
||||
|
||||
bool CFileReader::SeekStart(FilePos_t pos)
|
||||
{
|
||||
return !_fseeki64(m_file, pos, SEEK_SET);
|
||||
return !fseek_int64(m_file, pos, SEEK_SET);
|
||||
}
|
||||
|
||||
bool CFileReader::SeekCurrent(FilePos_t pos)
|
||||
{
|
||||
return !_fseeki64(m_file, pos, SEEK_CUR);
|
||||
return !fseek_int64(m_file, pos, SEEK_CUR);
|
||||
}
|
||||
|
||||
bool CFileReader::SeekEnd(FilePos_t pos)
|
||||
{
|
||||
return !_fseeki64(m_file, pos, SEEK_END);
|
||||
return !fseek_int64(m_file, pos, SEEK_END);
|
||||
}
|
||||
|
||||
IFileReader::FilePos_t CFileReader::GetPosition() const
|
||||
{
|
||||
return _ftelli64(m_file);
|
||||
return ftell_int64(m_file);
|
||||
}
|
||||
|
||||
StuffItParser g_stuffItParser;
|
||||
|
Reference in New Issue
Block a user