From 784d2f439987d7990c006224a06e9fd6f21ae7e9 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Sun, 3 Dec 2017 20:27:08 +1030 Subject: [PATCH 08/13] make GDir implementation private so we can eventually remove windows.h from gfile.h --- goo/gfile.cc | 71 +++++++++++++++++++++++++++++++++++++----------------------- goo/gfile.h | 16 +++----------- 2 files changed, 47 insertions(+), 40 deletions(-) diff --git a/goo/gfile.cc b/goo/gfile.cc index 3eb78ced..05ffed81 100644 --- a/goo/gfile.cc +++ b/goo/gfile.cc @@ -717,16 +717,33 @@ GDirEntry::~GDirEntry() { delete name; } +struct GDirPrivate { + GooString *path; // directory path + GBool doStat; // call stat() for each entry? +#if defined(_WIN32) + WIN32_FIND_DATAW ffd; + HANDLE hnd; +#elif defined(ACORN) +#elif defined(MACOS) +#else + DIR *dir; // the DIR structure from opendir() +#ifdef VMS + GBool needParent; // need to return an entry for [-] +#endif +#endif +}; + GDir::GDir(char *name, GBool doStatA) { - path = new GooString(name); - doStat = doStatA; + priv = new GDirPrivate; + priv->path = new GooString(name); + priv->doStat = doStatA; #if defined(_WIN32) GooString *tmp; - tmp = path->copy(); + tmp = priv->path->copy(); tmp->append("/*.*"); wchar_t *tmp_w = (wchar_t *)utf8ToUtf16(tmp->getCString()); - hnd = FindFirstFileW(tmp_w, &ffd); + priv->hnd = FindFirstFileW(tmp_w, &priv->ffd); gfree(tmp_w); delete tmp; #elif defined(ACORN) @@ -734,23 +751,23 @@ GDir::GDir(char *name, GBool doStatA) { #else dir = opendir(name); #ifdef VMS - needParent = strchr(name, '[') != NULL; + priv->needParent = strchr(name, '[') != NULL; #endif #endif } GDir::~GDir() { - delete path; + delete priv->path; #if defined(_WIN32) - if (hnd != INVALID_HANDLE_VALUE) { - FindClose(hnd); - hnd = INVALID_HANDLE_VALUE; + if (priv->hnd != INVALID_HANDLE_VALUE) { + FindClose(priv->hnd); + priv->hnd = INVALID_HANDLE_VALUE; } #elif defined(ACORN) #elif defined(MACOS) #else - if (dir) - closedir(dir); + if (priv->dir) + closedir(priv->dir); #endif } @@ -758,13 +775,13 @@ GDirEntry *GDir::getNextEntry() { GDirEntry *e = NULL; #if defined(_WIN32) - if (hnd != INVALID_HANDLE_VALUE) { - char *name = utf16ToUtf8((uint16_t *)ffd.cFileName); - e = new GDirEntry(path->getCString(), name, doStat); + if (priv->hnd != INVALID_HANDLE_VALUE) { + char *name = utf16ToUtf8((uint16_t *)priv->ffd.cFileName); + e = new GDirEntry(priv->path->getCString(), name, priv->doStat); gfree(name); - if (!FindNextFileW(hnd, &ffd)) { - FindClose(hnd); - hnd = INVALID_HANDLE_VALUE; + if (!FindNextFileW(priv->hnd, &priv->ffd)) { + FindClose(priv->hnd); + priv->hnd = INVALID_HANDLE_VALUE; } } #elif defined(ACORN) @@ -772,14 +789,14 @@ GDirEntry *GDir::getNextEntry() { #elif defined(VMS) struct dirent *ent; if (dir) { - if (needParent) { - e = new GDirEntry(path->getCString(), "-", doStat); - needParent = gFalse; + if (priv->needParent) { + e = new GDirEntry(path->getCString(), "-", priv->doStat); + priv->needParent = gFalse; return e; } ent = readdir(dir); if (ent) { - e = new GDirEntry(path->getCString(), ent->d_name, doStat); + e = new GDirEntry(path->getCString(), ent->d_name, priv->doStat); } } #else @@ -802,19 +819,19 @@ void GDir::rewind() { #ifdef _WIN32 GooString *tmp; - if (hnd != INVALID_HANDLE_VALUE) - FindClose(hnd); - tmp = path->copy(); + if (priv->hnd != INVALID_HANDLE_VALUE) + FindClose(priv->hnd); + tmp = priv->path->copy(); tmp->append("/*.*"); wchar_t *tmp_w = (wchar_t *)utf8ToUtf16(tmp->getCString()); - hnd = FindFirstFileW(tmp_w, &ffd); + priv->hnd = FindFirstFileW(tmp_w, &priv->ffd); gfree(tmp_w); delete tmp; #elif defined(ACORN) #elif defined(MACOS) #else - if (dir) - rewinddir(dir); + if (priv->dir) + rewinddir(priv->dir); #ifdef VMS needParent = strchr(path->getCString(), '[') != NULL; #endif diff --git a/goo/gfile.h b/goo/gfile.h index 8854b6c6..769527cb 100644 --- a/goo/gfile.h +++ b/goo/gfile.h @@ -180,6 +180,8 @@ private: GBool dir; // is it a directory? }; +struct GDirPrivate; + class GDir { public: @@ -192,19 +194,7 @@ private: GDir(const GDir &other); GDir& operator=(const GDir &other); - GooString *path; // directory path - GBool doStat; // call stat() for each entry? -#if defined(_WIN32) - WIN32_FIND_DATAW ffd; - HANDLE hnd; -#elif defined(ACORN) -#elif defined(MACOS) -#else - DIR *dir; // the DIR structure from opendir() -#ifdef VMS - GBool needParent; // need to return an entry for [-] -#endif -#endif + GDirPrivate *priv; }; #endif -- 2.11.0