diff --git a/mk/windoze/Glest.suo b/mk/windoze/Glest.suo index 374adcb4b..c374880a7 100755 Binary files a/mk/windoze/Glest.suo and b/mk/windoze/Glest.suo differ diff --git a/mk/windoze/shared_lib.vcproj b/mk/windoze/shared_lib.vcproj index 5c275e0a4..53e3973d0 100755 --- a/mk/windoze/shared_lib.vcproj +++ b/mk/windoze/shared_lib.vcproj @@ -416,6 +416,10 @@ RelativePath="..\..\source\shared_lib\sources\platform\win32\factory_repository.cpp" > + + @@ -730,6 +734,10 @@ + + diff --git a/source/shared_lib/include/platform/win32/glob.h b/source/shared_lib/include/platform/win32/glob.h new file mode 100644 index 000000000..8d6c56d6c --- /dev/null +++ b/source/shared_lib/include/platform/win32/glob.h @@ -0,0 +1,166 @@ +/* ///////////////////////////////////////////////////////////////////////// + * File: glob.h + * + * Purpose: Declaration of the glob() API functions and types for the + * Win32 platform. + * + * Created: 13th November 2002 + * Updated: 5th February 2010 + * + * Home: http://synesis.com.au/software/ + * + * Copyright (c) 2002-2010, Matthew Wilson and Synesis Software + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the names of Matthew Wilson and Synesis Software nor the names of + * any contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * ////////////////////////////////////////////////////////////////////// */ + + +/** \file glob.h + * + * Contains the declarations for the glob() API. + */ + +#ifndef SYNSOFT_UNIXEM_INCL_H_GLOB +#define SYNSOFT_UNIXEM_INCL_H_GLOB + +/* ////////////////////////////////////////////////////////////////////// */ + +/** \weakgroup unixem Synesis Software UNIX Emulation for Win32 + * \brief The UNIX emulation library + */ + +/** \weakgroup unixem_glob glob() API + * \ingroup UNIXem unixem + * \brief This API provides facilities for enumerating the file-system contents + * @{ + */ + +/* ////////////////////////////////////////////////////////////////////// */ + +#ifndef _WIN32 +# error This file is only currently defined for compilation on Win32 systems +#endif /* _WIN32 */ + +/* ///////////////////////////////////////////////////////////////////////// + * Constants and definitions + */ + +/* Error codes */ +#define GLOB_NOSPACE (1) /*!< \brief (Error result code:) An attempt to allocate memory failed, or if errno was 0 GLOB_LIMIT was specified in the flags and ARG_MAX patterns were matched. */ +#define GLOB_ABORTED (2) /*!< \brief (Error result code:) The scan was stopped because an error was encountered and either GLOB_ERR was set or (*errfunc)() returned non-zero. */ +#define GLOB_NOMATCH (3) /*!< \brief (Error result code:) The pattern does not match any existing pathname, and GLOB_NOCHECK was not set int flags. */ +#define GLOB_NOSYS (4) /*!< \brief (Error result code:) . */ +#define GLOB_ABEND GLOB_ABORTED /*!< \brief (Error result code:) . */ + +/* Flags */ +#define GLOB_ERR 0x00000001 /*!< \brief Return on read errors. */ +#define GLOB_MARK 0x00000002 /*!< \brief Append a slash to each name. */ +#define GLOB_NOSORT 0x00000004 /*!< \brief Don't sort the names. */ +#define GLOB_DOOFFS 0x00000008 /*!< \brief Insert PGLOB->gl_offs NULLs. Supported from version 1.6 of UNIXem. */ +#define GLOB_NOCHECK 0x00000010 /*!< \brief If nothing matches, return the pattern. Supported from version 1.6 of UNIXem. */ +#define GLOB_APPEND 0x00000020 /*!< \brief Append to results of a previous call. Not currently supported in this implementation. */ +#define GLOB_NOESCAPE 0x00000040 /*!< \brief Backslashes don't quote metacharacters. Has no effect in this implementation, since escaping is not supported. */ + +#define GLOB_PERIOD 0x00000080 /*!< \brief Leading `.' can be matched by metachars. Supported from version 1.6 of UNIXem. */ +#define GLOB_MAGCHAR 0x00000100 /*!< \brief Set in gl_flags if any metachars seen. Supported from version 1.6 of UNIXem. */ +/* #define GLOB_ALTDIRFUNC 0x00000200 */ /*!< \brief Use gl_opendir et al functions. Not currently supported in this implementation. */ +/* #define GLOB_BRACE 0x00000400 */ /*!< \brief Expand "{a,b}" to "a" "b". Not currently supported in this implementation. */ +#define GLOB_NOMAGIC 0x00000800 /*!< \brief If no magic chars, return the pattern. Supported from version 1.6 of UNIXem. */ +#define GLOB_TILDE 0x00001000 /*!< \brief Expand ~user and ~ to home directories. Partially supported from version 1.6 of UNIXem: leading ~ is expanded to %HOMEDRIVE%%HOMEPATH%. */ +#define GLOB_ONLYDIR 0x00002000 /*!< \brief Match only directories. This implementation guarantees to only return directories when this flag is specified. */ +#define GLOB_TILDE_CHECK 0x00004000 /*!< \brief Like GLOB_TILDE but return an GLOB_NOMATCH even if GLOB_NOCHECK specified. Supported from version 1.6 of UNIXem. */ +#define GLOB_ONLYFILE 0x00008000 /*!< \brief Match only files. Supported from version 1.6 of UNIXem. */ +#define GLOB_NODOTSDIRS 0x00010000 /*!< \brief Elide "." and ".." directories from wildcard searches. Supported from version 1.6 of UNIXem. */ +#define GLOB_LIMIT 0x00020000 /*!< \brief Limits the search to the number specified by the caller in gl_matchc. Supported from version 1.6 of UNIXem. */ + +/* ///////////////////////////////////////////////////////////////////////// + * Typedefs + */ + +/** \brief Result structure for glob() + * + * This structure is used by glob() to return the results of the search. + */ +typedef struct +{ + int gl_pathc; /*!< count of total paths so far */ + int gl_matchc; /*!< count of paths matching pattern */ + int gl_offs; /*!< reserved at beginning of gl_pathv */ + int gl_flags; /*!< returned flags */ + char **gl_pathv; /*!< list of paths matching pattern */ +} glob_t; + +/* ///////////////////////////////////////////////////////////////////////// + * API functions + */ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** \brief Generates pathnames matching a pattern + * + * This function is a pathname generator that implements the rules for + * file name pattern matching used by the UNIX shell. + * + * \param pattern The pattern controlling the search + * \param flags A combination of the GLOB_* flags + * \param errfunc A function that is called each time part of the search processing fails + * \param pglob Pointer to a glob_t structure to receive the search results + * \return 0 on success, otherwise one of the GLOB_* error codes + */ +int glob( char const *pattern + , int flags +#if defined(__COMO__) + , int (*errfunc)(char const *, int) +#else /* ? compiler */ + , const int (*errfunc)(char const *, int) +#endif /* compiler */ + , glob_t *pglob); + +/** \brief Frees the results of a call to glob + * + * This function releases any memory allocated in a call to glob. It must + * always be called for a successful call to glob. + * + * \param pglob Pointer to a glob_t structure to receive the search results + */ +void globfree(glob_t *pglob); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/* ////////////////////////////////////////////////////////////////////// */ + +/** @} // end of group unixem_glob */ + +/* ////////////////////////////////////////////////////////////////////// */ + +#endif /* SYNSOFT_UNIXEM_INCL_H_GLOB */ + +/* ///////////////////////////// end of file //////////////////////////// */ diff --git a/source/shared_lib/sources/platform/win32/glob.c b/source/shared_lib/sources/platform/win32/glob.c new file mode 100644 index 000000000..c50467e01 --- /dev/null +++ b/source/shared_lib/sources/platform/win32/glob.c @@ -0,0 +1,455 @@ +/* ///////////////////////////////////////////////////////////////////////// + * File: glob.c + * + * Purpose: Definition of the glob() API functions for the Win32 platform. + * + * Created: 13th November 2002 + * Updated: 6th February 2010 + * + * Home: http://synesis.com.au/software/ + * + * Copyright (c) 2002-2010, Matthew Wilson and Synesis Software + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the names of Matthew Wilson and Synesis Software nor the names of + * any contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * ////////////////////////////////////////////////////////////////////// */ + +/* ///////////////////////////////////////////////////////////////////////// + * Includes + */ + +#include +#include +#include +#include +#include + +#define NUM_ELEMENTS(ar) (sizeof(ar) / sizeof(ar[0])) + +/* ///////////////////////////////////////////////////////////////////////// + * Helper functions + */ + +static char const *strrpbrk(char const *string, char const *strCharSet) +{ + char *part = NULL; + char const *pch; + + for(pch = strCharSet; *pch; ++pch) + { + char *p = strrchr(string, *pch); + + if(NULL != p) + { + if(NULL == part) + { + part = p; + } + else + { + if(part < p) + { + part = p; + } + } + } + } + + return part; +} + +/* ///////////////////////////////////////////////////////////////////////// + * API functions + */ + +/* It gives you back the matched contents of your pattern, so for Win32, the + * directories must be included + */ + +int glob( char const *pattern + , int flags +#if defined(__COMO__) + , int (*errfunc)(char const *, int) +#else /* ? compiler */ + , const int (*errfunc)(char const *, int) +#endif /* compiler */ + , glob_t *pglob) +{ + int result; + char szRelative[1 + _MAX_PATH]; + char const *file_part; + WIN32_FIND_DATAA find_data; + HANDLE hFind; + char *buffer; + char szPattern2[1 + _MAX_PATH]; + char szPattern3[1 + _MAX_PATH]; + char const *effectivePattern = pattern; + char const *leafMost; + const int bMagic = (NULL != strpbrk(pattern, "?*")); + int bNoMagic = 0; + int bMagic0; + size_t maxMatches = ~(size_t)(0); + + assert(NULL != pglob); + + if(flags & GLOB_NOMAGIC) + { + bNoMagic = !bMagic; + } + + if(flags & GLOB_LIMIT) + { + maxMatches = (size_t)pglob->gl_matchc; + } + + if(flags & GLOB_TILDE) + { + /* Check that begins with "~/" */ + if( '~' == pattern[0] && + ( '\0' == pattern[1] || + '/' == pattern[1] || + '\\' == pattern[1])) + { + DWORD dw; + + (void)lstrcpyA(&szPattern2[0], "%HOMEDRIVE%%HOMEPATH%"); + + dw = ExpandEnvironmentStringsA(&szPattern2[0], &szPattern3[0], NUM_ELEMENTS(szPattern3) - 1); + + if(0 != dw) + { + (void)lstrcpynA(&szPattern3[0] + dw - 1, &pattern[1], (int)(NUM_ELEMENTS(szPattern3) - dw)); + szPattern3[NUM_ELEMENTS(szPattern3) - 1] = '\0'; + + effectivePattern = szPattern3; + } + } + } + + file_part = strrpbrk(effectivePattern, "\\/"); + + if(NULL != file_part) + { + leafMost = ++file_part; + + (void)lstrcpyA(szRelative, effectivePattern); + szRelative[file_part - effectivePattern] = '\0'; + } + else + { + szRelative[0] = '\0'; + leafMost = effectivePattern; + } + + bMagic0 = (leafMost == strpbrk(leafMost, "?*")); + + hFind = FindFirstFileA(effectivePattern, &find_data); + buffer = NULL; + + pglob->gl_pathc = 0; + pglob->gl_pathv = NULL; + + if(0 == (flags & GLOB_DOOFFS)) + { + pglob->gl_offs = 0; + } + + if(hFind == INVALID_HANDLE_VALUE) + { + /* If this was a pattern search, and the + * directory exists, then we return 0 + * matches, rather than GLOB_NOMATCH + */ + if( bMagic && + NULL != file_part) + { + result = 0; + } + else + { + if(NULL != errfunc) + { + (void)errfunc(effectivePattern, (int)GetLastError()); + } + + result = GLOB_NOMATCH; + } + } + else + { + int cbCurr = 0; + size_t cbAlloc = 0; + size_t cMatches = 0; + + result = 0; + + do + { + int cch; + size_t new_cbAlloc; + + if( bMagic0 && + 0 == (flags & GLOB_PERIOD)) + { + if('.' == find_data.cFileName[0]) + { + continue; + } + } + + if(find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + { +#ifdef GLOB_ONLYFILE + if(flags & GLOB_ONLYFILE) + { + continue; + } +#endif /* GLOB_ONLYFILE */ + + if( bMagic0 && + GLOB_NODOTSDIRS == (flags & GLOB_NODOTSDIRS)) + { + /* Pattern must begin with '.' to match either dots directory */ + if( 0 == lstrcmpA(".", find_data.cFileName) || + 0 == lstrcmpA("..", find_data.cFileName)) + { + continue; + } + } + + if(flags & GLOB_MARK) + { +#if 0 + if(find_data.cFileName[0] >= 'A' && find_data.cFileName[0] <= 'M') +#endif /* 0 */ + (void)lstrcatA(find_data.cFileName, "/"); + } + } + else + { + if(flags & GLOB_ONLYDIR) + { + /* Skip all further actions, and get the next entry */ +#if 0 + if(find_data.cFileName[0] >= 'A' && find_data.cFileName[0] <= 'M') +#endif /* 0 */ + continue; + } + } + + cch = lstrlenA(find_data.cFileName); + if(NULL != file_part) + { + cch += (int)(file_part - effectivePattern); + } + + new_cbAlloc = (size_t)cbCurr + cch + 1; + if(new_cbAlloc > cbAlloc) + { + char *new_buffer; + + new_cbAlloc *= 2; + + new_cbAlloc = (new_cbAlloc + 31) & ~(31); + + new_buffer = (char*)realloc(buffer, new_cbAlloc); + + if(new_buffer == NULL) + { + result = GLOB_NOSPACE; + free(buffer); + buffer = NULL; + break; + } + + buffer = new_buffer; + cbAlloc = new_cbAlloc; + } + + (void)lstrcpynA(buffer + cbCurr, szRelative, 1 + (int)(file_part - effectivePattern)); + (void)lstrcatA(buffer + cbCurr, find_data.cFileName); + cbCurr += cch + 1; + + ++cMatches; + } + while(FindNextFile(hFind, &find_data) && cMatches != maxMatches); + + (void)FindClose(hFind); + + if(result == 0) + { + /* Now expand the buffer, to fit in all the pointers. */ + size_t cbPointers = (1 + cMatches + pglob->gl_offs) * sizeof(char*); + char *new_buffer = (char*)realloc(buffer, cbAlloc + cbPointers); + + if(new_buffer == NULL) + { + result = GLOB_NOSPACE; + free(buffer); + } + else + { + char **pp; + char **begin; + char **end; + char *next_str; + + buffer = new_buffer; + + (void)memmove(new_buffer + cbPointers, new_buffer, cbAlloc); + + /* Handle the offsets. */ + begin = (char**)new_buffer; + end = begin + pglob->gl_offs; + + for(; begin != end; ++begin) + { + *begin = NULL; + } + + /* Sort, or no sort. */ + pp = (char**)new_buffer + pglob->gl_offs; + begin = pp; + end = begin + cMatches; + + if(flags & GLOB_NOSORT) + { + /* The way we need in order to test the removal of dots in the findfile_sequence. */ + *end = NULL; + for(begin = pp, next_str = buffer + cbPointers; begin != end; --end) + { + *(end - 1) = next_str; + + /* Find the next string. */ + next_str += 1 + lstrlenA(next_str); + } + } + else + { + /* The normal way. */ + for(begin = pp, next_str = buffer + cbPointers; begin != end; ++begin) + { + *begin = next_str; + + /* Find the next string. */ + next_str += 1 + lstrlenA(next_str); + } + *begin = NULL; + } + + /* Return results to caller. */ + pglob->gl_pathc = (int)cMatches; + pglob->gl_matchc= (int)cMatches; + pglob->gl_flags = 0; + if(bMagic) + { + pglob->gl_flags |= GLOB_MAGCHAR; + } + pglob->gl_pathv = (char**)new_buffer; + } + } + + if(0 == cMatches) + { + result = GLOB_NOMATCH; + } + } + + if(GLOB_NOMATCH == result) + { + if( (flags & GLOB_TILDE_CHECK) && + effectivePattern == szPattern3) + { + result = GLOB_NOMATCH; + } + else if(bNoMagic || + (flags & GLOB_NOCHECK)) + { + const size_t effPattLen = strlen(effectivePattern); + const size_t cbNeeded = ((2 + pglob->gl_offs) * sizeof(char*)) + (1 + effPattLen); + char **pp = (char**)realloc(buffer, cbNeeded); + + if(NULL == pp) + { + result = GLOB_NOSPACE; + free(buffer); + } + else + { + /* Handle the offsets. */ + char** begin = pp; + char** end = pp + pglob->gl_offs; + char* dest = (char*)(pp + 2 + pglob->gl_offs); + + for(; begin != end; ++begin) + { + *begin = NULL; + } + + /* Synthesise the pattern result. */ +#ifdef UNIXEM_USING_SAFE_STR_FUNCTIONS + pp[0 + pglob->gl_offs] = (strcpy_s(dest, effPattLen + 1, effectivePattern), dest); +#else /* ? UNIXEM_USING_SAFE_STR_FUNCTIONS */ + pp[0 + pglob->gl_offs] = strcpy(dest, effectivePattern); +#endif /* UNIXEM_USING_SAFE_STR_FUNCTIONS */ + pp[1 + pglob->gl_offs] = NULL; + + /* Return results to caller. */ + pglob->gl_pathc = 1; + pglob->gl_matchc= 1; + pglob->gl_flags = 0; + if(bMagic) + { + pglob->gl_flags |= GLOB_MAGCHAR; + } + pglob->gl_pathv = pp; + + result = 0; + } + } + } + else if(0 == result) + { + if((size_t)pglob->gl_matchc == maxMatches) + { + result = GLOB_NOSPACE; + } + } + + return result; +} + +void globfree(glob_t *pglob) +{ + if(pglob != NULL) + { + free(pglob->gl_pathv); + pglob->gl_pathc = 0; + pglob->gl_pathv = NULL; + } +} + +/* ///////////////////////////// end of file //////////////////////////// */ diff --git a/source/shared_lib/sources/platform/win32/platform_util.cpp b/source/shared_lib/sources/platform/win32/platform_util.cpp index cc1d38368..b88687768 100644 --- a/source/shared_lib/sources/platform/win32/platform_util.cpp +++ b/source/shared_lib/sources/platform/win32/platform_util.cpp @@ -29,6 +29,8 @@ #include "sdl_private.h" #include "window.h" #include "noimpl.h" +#include +#include #include "leak_dumper.h" @@ -214,8 +216,8 @@ void Tokenize(const string& str,vector& tokens,const string& delimiters) void findDirs(const vector &paths, vector &results, bool errorOnNotFound) { results.clear(); - int pathCount = paths.size(); - for(int idx = 0; idx < pathCount; idx++) { + size_t pathCount = paths.size(); + for(unsigned int idx = 0; idx < pathCount; idx++) { string path = paths[idx] + "/*."; vector current_results; findAll(path, current_results, false, errorOnNotFound); @@ -237,8 +239,8 @@ void findDirs(const vector &paths, vector &results, bool errorOn void findAll(const vector &paths, const string &fileFilter, vector &results, bool cutExtension, bool errorOnNotFound) { results.clear(); - int pathCount = paths.size(); - for(int idx = 0; idx < pathCount; idx++) { + size_t pathCount = paths.size(); + for(unsigned int idx = 0; idx < pathCount; idx++) { string path = paths[idx] + "/" + fileFilter; vector current_results; findAll(path, current_results, cutExtension, errorOnNotFound); @@ -332,8 +334,8 @@ bool EndsWith(const string &str, const string& key) //finds all filenames like path and gets their checksum of all files combined int32 getFolderTreeContentsCheckSumRecursively(vector paths, string pathSearchString, const string filterFileExt, Checksum *recursiveChecksum) { Checksum checksum = (recursiveChecksum == NULL ? Checksum() : *recursiveChecksum); - int count = paths.size(); - for(int idx = 0; idx < count; ++idx) { + size_t count = paths.size(); + for(unsigned int idx = 0; idx < count; ++idx) { string path = paths[idx] + pathSearchString; getFolderTreeContentsCheckSumRecursively(path, filterFileExt, &checksum); } @@ -348,93 +350,98 @@ int32 getFolderTreeContentsCheckSumRecursively(vector paths, string path //finds all filenames like path and gets their checksum of all files combined int32 getFolderTreeContentsCheckSumRecursively(const string &path, const string &filterFileExt, Checksum *recursiveChecksum) { - Checksum checksum = (recursiveChecksum == NULL ? Checksum() : *recursiveChecksum); - -/* MV - PORT THIS to win32 - - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning [%s]\n",__FILE__,__FUNCTION__,path.c_str()); - - std::string mypath = path; - // Stupid win32 is searching for all files without extension when *. is specified as wildcard - if(mypath.compare(mypath.size() - 2, 2, "*.") == 0) { - mypath = mypath.substr(0, mypath.size() - 2); - mypath += "*"; - } - - glob_t globbuf; - - int res = glob(mypath.c_str(), 0, 0, &globbuf); - if(res < 0) { - std::stringstream msg; - msg << "Couldn't scan directory '" << mypath << "': " << strerror(errno); - throw runtime_error(msg.str()); - } - - for(size_t i = 0; i < globbuf.gl_pathc; ++i) { - const char* p = globbuf.gl_pathv[i]; - // - //const char* begin = p; - //for( ; *p != 0; ++p) { - // // strip the path component - // if(*p == '/') - // begin = p+1; - //} - - - if(isdir(p) == false) - { - bool addFile = true; - if(filterFileExt != "") - { - addFile = EndsWith(p, filterFileExt); - } - - if(addFile) - { - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] adding file [%s]\n",__FILE__,__FUNCTION__,p); - - checksum.addFile(p); - } - } - } - - globfree(&globbuf); - - // Look recursively for sub-folders - res = glob(mypath.c_str(), GLOB_ONLYDIR, 0, &globbuf); - if(res < 0) { - std::stringstream msg; - msg << "Couldn't scan directory '" << mypath << "': " << strerror(errno); - throw runtime_error(msg.str()); - } - - for(size_t i = 0; i < globbuf.gl_pathc; ++i) { - const char* p = globbuf.gl_pathv[i]; - // - //const char* begin = p; - //for( ; *p != 0; ++p) { - // strip the path component - // if(*p == '/') - // begin = p+1; - //} - - getFolderTreeContentsCheckSumRecursively(string(p) + "/*", filterFileExt, &checksum); - } - - globfree(&globbuf); -*/ - - if(recursiveChecksum != NULL) { - *recursiveChecksum = checksum; - } - - return checksum.getSum(); + + Checksum checksum = (recursiveChecksum == NULL ? Checksum() : *recursiveChecksum); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning [%s] starting checksum = %d\n",__FILE__,__FUNCTION__,path.c_str(),checksum.getSum()); + + std::string mypath = path; + /** Stupid win32 is searching for all files without extension when *. is + * specified as wildcard + */ + if(mypath.compare(mypath.size() - 2, 2, "*.") == 0) { + mypath = mypath.substr(0, mypath.size() - 2); + mypath += "*"; + } + + glob_t globbuf; + + int res = glob(mypath.c_str(), 0, 0, &globbuf); + if(res < 0) { + std::stringstream msg; + msg << "Couldn't scan directory '" << mypath << "': " << strerror(errno); + throw runtime_error(msg.str()); + } + + for(size_t i = 0; i < globbuf.gl_pathc; ++i) { + const char* p = globbuf.gl_pathv[i]; + /* + const char* begin = p; + for( ; *p != 0; ++p) { + // strip the path component + if(*p == '/') + begin = p+1; + } + */ + + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] examining file [%s]\n",__FILE__,__FUNCTION__,p); + + if(isdir(p) == false) + { + bool addFile = true; + if(filterFileExt != "") + { + addFile = EndsWith(p, filterFileExt); + } + + if(addFile) + { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] adding file [%s]\n",__FILE__,__FUNCTION__,p); + + checksum.addFile(p); + } + } + } + + globfree(&globbuf); + + // Look recursively for sub-folders + res = glob(mypath.c_str(), GLOB_ONLYDIR, 0, &globbuf); + if(res < 0) { + std::stringstream msg; + msg << "Couldn't scan directory '" << mypath << "': " << strerror(errno); + throw runtime_error(msg.str()); + } + + for(size_t i = 0; i < globbuf.gl_pathc; ++i) { + const char* p = globbuf.gl_pathv[i]; + /* + const char* begin = p; + for( ; *p != 0; ++p) { + // strip the path component + if(*p == '/') + begin = p+1; + } + */ + + getFolderTreeContentsCheckSumRecursively(string(p) + "/*", filterFileExt, &checksum); + } + + globfree(&globbuf); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning [%s] ending checksum = %d\n",__FILE__,__FUNCTION__,path.c_str(),checksum.getSum()); + + if(recursiveChecksum != NULL) { + *recursiveChecksum = checksum; + } + + return checksum.getSum(); } vector > getFolderTreeContentsCheckSumListRecursively(vector paths, string pathSearchString, string filterFileExt, vector > *recursiveMap) { vector > checksumFiles = (recursiveMap == NULL ? vector >() : *recursiveMap); - int count = paths.size(); - for(int idx = 0; idx < count; ++idx) { + size_t count = paths.size(); + for(unsigned int idx = 0; idx < count; ++idx) { string path = paths[idx] + pathSearchString; getFolderTreeContentsCheckSumListRecursively(path, filterFileExt, &checksumFiles); } @@ -444,85 +451,88 @@ vector > getFolderTreeContentsCheckSumListRecursively(ve //finds all filenames like path and gets the checksum of each file vector > getFolderTreeContentsCheckSumListRecursively(const string &path, const string &filterFileExt, vector > *recursiveMap) { - vector > checksumFiles = (recursiveMap == NULL ? vector >() : *recursiveMap); - -/* MV - PORT THIS to win32 - - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning [%s]\n",__FILE__,__FUNCTION__,path.c_str()); - - std::string mypath = path; - // Stupid win32 is searching for all files without extension when *. is specified as wildcard - if(mypath.compare(mypath.size() - 2, 2, "*.") == 0) { - mypath = mypath.substr(0, mypath.size() - 2); - mypath += "*"; - } - - glob_t globbuf; - - int res = glob(mypath.c_str(), 0, 0, &globbuf); - if(res < 0) { - std::stringstream msg; - msg << "Couldn't scan directory '" << mypath << "': " << strerror(errno); - throw runtime_error(msg.str()); - } - - for(size_t i = 0; i < globbuf.gl_pathc; ++i) { - const char* p = globbuf.gl_pathv[i]; - // - //const char* begin = p; - //for( ; *p != 0; ++p) { - // strip the path component - // if(*p == '/') - // begin = p+1; - //} - - - if(isdir(p) == false) - { - bool addFile = true; - if(filterFileExt != "") - { - addFile = EndsWith(p, filterFileExt); - } - - if(addFile) - { - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] adding file [%s]\n",__FILE__,__FUNCTION__,p); - - Checksum checksum; - checksum.addFile(p); - - checksumFiles.push_back(std::pair(p,checksum.getSum())); - } - } - } - - globfree(&globbuf); - - // Look recursively for sub-folders - res = glob(mypath.c_str(), GLOB_ONLYDIR, 0, &globbuf); - if(res < 0) { - std::stringstream msg; - msg << "Couldn't scan directory '" << mypath << "': " << strerror(errno); - throw runtime_error(msg.str()); - } - - for(size_t i = 0; i < globbuf.gl_pathc; ++i) { - const char* p = globbuf.gl_pathv[i]; - // - //const char* begin = p; - //for( ; *p != 0; ++p) { - // strip the path component - // if(*p == '/') - // begin = p+1; - //} - - checksumFiles = getFolderTreeContentsCheckSumListRecursively(string(p) + "/*", filterFileExt, &checksumFiles); - } - - globfree(&globbuf); -*/ - return checksumFiles; + vector > checksumFiles = (recursiveMap == NULL ? vector >() : *recursiveMap); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning [%s]\n",__FILE__,__FUNCTION__,path.c_str()); + + std::string mypath = path; + /** Stupid win32 is searching for all files without extension when *. is + * specified as wildcard + */ + if(mypath.compare(mypath.size() - 2, 2, "*.") == 0) { + mypath = mypath.substr(0, mypath.size() - 2); + mypath += "*"; + } + + glob_t globbuf; + + int res = glob(mypath.c_str(), 0, 0, &globbuf); + if(res < 0) { + std::stringstream msg; + msg << "Couldn't scan directory '" << mypath << "': " << strerror(errno); + throw runtime_error(msg.str()); + } + + for(size_t i = 0; i < globbuf.gl_pathc; ++i) { + const char* p = globbuf.gl_pathv[i]; + /* + const char* begin = p; + for( ; *p != 0; ++p) { + // strip the path component + if(*p == '/') + begin = p+1; + } + */ + + if(isdir(p) == false) + { + bool addFile = true; + if(filterFileExt != "") + { + addFile = EndsWith(p, filterFileExt); + } + + if(addFile) + { + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] adding file [%s]\n",__FILE__,__FUNCTION__,p); + + Checksum checksum; + checksum.addFile(p); + + checksumFiles.push_back(std::pair(p,checksum.getSum())); + } + } + } + + globfree(&globbuf); + + // Look recursively for sub-folders + res = glob(mypath.c_str(), GLOB_ONLYDIR, 0, &globbuf); + if(res < 0) { + std::stringstream msg; + msg << "Couldn't scan directory '" << mypath << "': " << strerror(errno); + throw runtime_error(msg.str()); + } + + for(size_t i = 0; i < globbuf.gl_pathc; ++i) { + const char* p = globbuf.gl_pathv[i]; + /* + const char* begin = p; + for( ; *p != 0; ++p) { + // strip the path component + if(*p == '/') + begin = p+1; + } + */ + + checksumFiles = getFolderTreeContentsCheckSumListRecursively(string(p) + "/*", filterFileExt, &checksumFiles); + } + + globfree(&globbuf); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning [%s]\n",__FILE__,__FUNCTION__,path.c_str()); + + return checksumFiles; } string extractDirectoryPathFromFile(string filename) @@ -700,7 +710,7 @@ void getFullscreenVideoModes(list *modeinfos) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SDL_PixelFormat format; - SDL_Rect **modes; + //SDL_Rect **modes; int loops(0); int bpp(0); std::map uniqueResList;