From 8129afdd1f37d086daaf6b9a3446475e4f6671dd Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 3 Dec 2017 10:11:54 +0200 Subject: [PATCH 1/8] Fixed compilation of non-Windows targets These are quick hacks to be improved later --- src/resourcefiles/file_directory.cpp | 5 ++++- src/tmpfileplus.cpp | 6 ------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/resourcefiles/file_directory.cpp b/src/resourcefiles/file_directory.cpp index 02c70a21e..77e5d0141 100644 --- a/src/resourcefiles/file_directory.cpp +++ b/src/resourcefiles/file_directory.cpp @@ -209,7 +209,10 @@ int FDirectory::AddDirectory(const char *dirpath) FString fullFileName = scanDirectories[i] + file->d_name; - if(DirExists(fullFileName.GetChars())) + struct stat fileStat; + stat(fullFileName.GetChars(), &fileStat); + + if(S_ISDIR(fileStat.st_mode)) { scanDirectories.Push(scanDirectories[i] + file->d_name + "/"); continue; diff --git a/src/tmpfileplus.cpp b/src/tmpfileplus.cpp index bfe021dbb..2085e8be3 100644 --- a/src/tmpfileplus.cpp +++ b/src/tmpfileplus.cpp @@ -172,12 +172,6 @@ static FILE *mktempfile_internal(const char *tmpdir, const char *pfx, FString *t { /* Success, so return user a proper ANSI C file pointer */ fp = FDOPEN_(fd, "w+b"); errno = 0; - -#ifndef _WIN32 - /* [Unix only] And make sure the file will be deleted once closed */ - if (!keep) remove(tmpname); -#endif - } else { /* We failed */ From f25c7ef2d519f98f7acd64cfa01c03d3b7781384 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 3 Dec 2017 13:17:28 +0200 Subject: [PATCH 2/8] =?UTF-8?q?Unified=20implementation=20of=20=E2=80=99di?= =?UTF-8?q?rectory=20as=20resource=20file'=20for=20POSIX=20targets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/resourcefiles/file_directory.cpp | 75 ++++++++-------------------- 1 file changed, 20 insertions(+), 55 deletions(-) diff --git a/src/resourcefiles/file_directory.cpp b/src/resourcefiles/file_directory.cpp index 77e5d0141..2e5630169 100644 --- a/src/resourcefiles/file_directory.cpp +++ b/src/resourcefiles/file_directory.cpp @@ -35,27 +35,13 @@ #include -#include #ifdef _WIN32 #include -#define stat _stat #else -#include -#ifndef __sun #include #endif -#endif -#include -#include -#include -#include -#include -#include -#include "doomtype.h" -#include "tarray.h" #include "resourcefile.h" -#include "zstring.h" #include "cmdlib.h" #include "doomerrors.h" @@ -185,46 +171,6 @@ int FDirectory::AddDirectory(const char *dirpath) return count; } -#elif defined(__sun) || defined(__APPLE__) - -int FDirectory::AddDirectory(const char *dirpath) -{ - int count = 0; - TArray scanDirectories; - scanDirectories.Push(dirpath); - for(unsigned int i = 0;i < scanDirectories.Size();i++) - { - DIR* directory = opendir(scanDirectories[i].GetChars()); - if (directory == NULL) - { - Printf("Could not read directory: %s\n", strerror(errno)); - return 0; - } - - struct dirent *file; - while((file = readdir(directory)) != NULL) - { - if(file->d_name[0] == '.') //File is hidden or ./.. directory so ignore it. - continue; - - FString fullFileName = scanDirectories[i] + file->d_name; - - struct stat fileStat; - stat(fullFileName.GetChars(), &fileStat); - - if(S_ISDIR(fileStat.st_mode)) - { - scanDirectories.Push(scanDirectories[i] + file->d_name + "/"); - continue; - } - AddEntry(scanDirectories[i] + file->d_name, fileStat.st_size); - count++; - } - closedir(directory); - } - return count; -} - #else //========================================================================== @@ -249,6 +195,10 @@ int FDirectory::AddDirectory(const char *dirpath) Printf("Failed to start directory traversal: %s\n", strerror(errno)); return 0; } + + const size_t namepos = strlen(Filename); + FString pathfix; + while ((ent = fts_read(fts)) != NULL) { if (ent->fts_info == FTS_D && ent->fts_name[0] == '.') @@ -266,7 +216,22 @@ int FDirectory::AddDirectory(const char *dirpath) // We're only interested in remembering files. continue; } - AddEntry(ent->fts_path, ent->fts_statp->st_size); + + // Some implementations add an extra separator between + // root of the hierarchy and entity's path. + // It needs to be removed in order to resolve + // lumps' relative paths properly. + const char* path = ent->fts_path; + + if ('/' == path[namepos]) + { + pathfix = FString(path, namepos); + pathfix.AppendCStrPart(&path[namepos + 1], ent->fts_pathlen - namepos - 1); + + path = pathfix.GetChars(); + } + + AddEntry(path, ent->fts_statp->st_size); count++; } fts_close(fts); From 31d1018b9a30dfbc392f7da931ee6efb716d321e Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 3 Dec 2017 13:18:47 +0200 Subject: [PATCH 3/8] Fixed compilation warnings reported by GCC/Clang b_game.cpp:537:27: warning: more '%' conversions than data arguments [-Wformat] g_game.cpp:2982:40: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'long' [-Wsign-compare] --- src/b_game.cpp | 4 ++-- src/g_game.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/b_game.cpp b/src/b_game.cpp index 4300e0ada..661d09c6e 100644 --- a/src/b_game.cpp +++ b/src/b_game.cpp @@ -534,7 +534,7 @@ bool FCajunMaster::LoadBots () } if (!sc.OpenFile(tmp)) { - Printf("Unable to open %s. So no bots\n"); + Printf("Unable to open %s. So no bots\n", tmp.GetChars()); return false; } @@ -665,4 +665,4 @@ DEFINE_ACTION_FUNCTION(FLevelLocals, RemoveAllBots) PARAM_BOOL(fromlist); bglobal.RemoveAllBots(fromlist); return 0; -} \ No newline at end of file +} diff --git a/src/g_game.cpp b/src/g_game.cpp index f56bdac8e..0adfa2fc9 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -2978,7 +2978,7 @@ bool G_CheckDemoStatus (void) bool saved = false; if (fw != nullptr) { - auto size = long(demo_p - demobuffer); + const size_t size = demo_p - demobuffer; saved = fw->Write(demobuffer, size) == size; delete fw; if (!saved) remove(demoname); From 5f50d60eff3ef0d7a361ce7de3b6a576ce209c40 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 3 Dec 2017 13:23:43 +0200 Subject: [PATCH 4/8] Restored handling of tmpfileplus() keep argument for POSIX targets --- src/tmpfileplus.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/tmpfileplus.cpp b/src/tmpfileplus.cpp index 2085e8be3..2c14e1563 100644 --- a/src/tmpfileplus.cpp +++ b/src/tmpfileplus.cpp @@ -139,8 +139,8 @@ static FILE *mktempfile_internal(const char *tmpdir, const char *pfx, FString *t int oflag, pmode; /* In Windows, we use the _O_TEMPORARY flag with `open` to ensure the file is deleted when closed. - * In Unix, we use the unlink function after opening the file. (This does not work in Windows, - * which does not allow an open file to be unlinked.) + * In Unix, we use the remove function after opening the file. (This does not work in Windows, + * which does not allow an open file to be deleted.) */ #ifdef _WIN32 /* MSVC flags */ @@ -172,6 +172,12 @@ static FILE *mktempfile_internal(const char *tmpdir, const char *pfx, FString *t { /* Success, so return user a proper ANSI C file pointer */ fp = FDOPEN_(fd, "w+b"); errno = 0; + +#ifndef _WIN32 + /* [Unix only] And make sure the file will be deleted once closed */ + if (!keep) remove(tempname); +#endif + } else { /* We failed */ From 31b0fdc9fe1179bfa799e5c43d379933624661ae Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 3 Dec 2017 14:50:32 +0200 Subject: [PATCH 5/8] Fixed directory creation for POSIX targets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Warning was reported by GCC 7 only: cmdlib.cpp:550:13: warning: ‘info.stat::st_mode’ may be used uninitialized in this function [-Wmaybe-uninitialized] --- src/cmdlib.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/cmdlib.cpp b/src/cmdlib.cpp index bccb4afcd..e58b3569f 100644 --- a/src/cmdlib.cpp +++ b/src/cmdlib.cpp @@ -544,18 +544,13 @@ void CreatePath(const char *fn) { *p = '\0'; } - struct stat info; - if (DirEntryExists(copy)) + if (!DirEntryExists(copy) && mkdir(copy, 0755) == -1) { - if (info.st_mode & S_IFDIR) - goto exists; - } - if (mkdir(copy, 0755) == -1) - { // failed + // failed free(copy); return; } -exists: if (p != NULL) + if (p != NULL) { *p = '/'; } From 0fa74220c9fe56d106b983e5248ec7b254495b3d Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sun, 3 Dec 2017 12:39:24 -0500 Subject: [PATCH 6/8] - fixed: doublize sky float, in order to make it more smooth --- src/gl/scene/gl_scene.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 329ac6484..af03af86e 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -800,8 +800,8 @@ sector_t * GLSceneDrawer::RenderViewpoint (AActor * camera, GL_IRECT * bounds, f GLRenderer->mAngles.Roll.Degrees = r_viewpoint.Angles.Roll.Degrees; // Scroll the sky - GLRenderer->mSky1Pos = (double)fmod(screen->FrameTime * level.skyspeed1, 1024.f) * 90./256.; - GLRenderer->mSky2Pos = (double)fmod(screen->FrameTime * level.skyspeed2, 1024.f) * 90./256.; + GLRenderer->mSky1Pos = (double)fmod((double)screen->FrameTime * (double)level.skyspeed1, 1024.f) * 90./256.; + GLRenderer->mSky2Pos = (double)fmod((double)screen->FrameTime * (double)level.skyspeed2, 1024.f) * 90./256.; From cea89ba3ae0ec39a7d6ffbc65aa770567bd5699a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 3 Dec 2017 20:02:55 +0100 Subject: [PATCH 7/8] - fix backslashes in MD3 skin names. --- src/r_data/models/models_md3.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/r_data/models/models_md3.cpp b/src/r_data/models/models_md3.cpp index e504b252a..8a649f713 100644 --- a/src/r_data/models/models_md3.cpp +++ b/src/r_data/models/models_md3.cpp @@ -166,6 +166,8 @@ bool FMD3Model::Load(const char * path, int lumpnum, const char * buffer, int le for (int i = 0; i < s->numSkins; i++) { // [BB] According to the MD3 spec, Name is supposed to include the full path. + // ... and since some tools seem to output backslashes, these need to be replaced with forward slashes to work. + FixPathSeperator(shader[i].Name); s->skins[i] = LoadSkin("", shader[i].Name); // [BB] Fall back and check if Name is relative. if (!s->skins[i].isValid()) From a945418ba6c49704a4e9fbcbdda063e653d4c653 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 3 Dec 2017 21:03:44 +0100 Subject: [PATCH 8/8] - added M_GetDocumentsPath function. --- src/m_misc.h | 1 + src/posix/osx/i_specialpaths.mm | 21 +++++++++++++++++ src/posix/unix/i_specialpaths.cpp | 13 +++++++++++ src/win32/i_specialpaths.cpp | 38 +++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+) diff --git a/src/m_misc.h b/src/m_misc.h index 8f375b930..f3773659d 100644 --- a/src/m_misc.h +++ b/src/m_misc.h @@ -60,5 +60,6 @@ FString M_GetCajunPath(const char *filename); FString M_GetConfigPath(bool for_reading); FString M_GetScreenshotsPath(); FString M_GetSavegamesPath(); +FString M_GetDocumentsPath(); #endif diff --git a/src/posix/osx/i_specialpaths.mm b/src/posix/osx/i_specialpaths.mm index fbb32cec6..540aaf4b0 100644 --- a/src/posix/osx/i_specialpaths.mm +++ b/src/posix/osx/i_specialpaths.mm @@ -215,3 +215,24 @@ FString M_GetSavegamesPath() return path; } +//=========================================================================== +// +// M_GetDocumentsPath Unix +// +// Returns the path to the default documents directory. +// +//=========================================================================== + +FString M_GetDocumentsPath() +{ + FString path; + char cpath[PATH_MAX]; + FSRef folder; + + if (noErr == FSFindFolder(kUserDomain, kDocumentsFolderType, kCreateFolder, &folder) && + noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX)) + { + path << cpath << "/" GAME_DIR "/"; + } + return path; +} diff --git a/src/posix/unix/i_specialpaths.cpp b/src/posix/unix/i_specialpaths.cpp index 581fda5d5..01320548d 100644 --- a/src/posix/unix/i_specialpaths.cpp +++ b/src/posix/unix/i_specialpaths.cpp @@ -218,3 +218,16 @@ FString M_GetSavegamesPath() { return NicePath("~/" GAME_DIR); } + +//=========================================================================== +// +// M_GetDocumentsPath Unix +// +// Returns the path to the default documents directory. +// +//=========================================================================== + +FString M_GetDocumentsPath() +{ + return NicePath("~/" GAME_DIR); +} \ No newline at end of file diff --git a/src/win32/i_specialpaths.cpp b/src/win32/i_specialpaths.cpp index 4a790798f..375f301dd 100644 --- a/src/win32/i_specialpaths.cpp +++ b/src/win32/i_specialpaths.cpp @@ -380,3 +380,41 @@ FString M_GetSavegamesPath() } return path; } + +//=========================================================================== +// +// M_GetDocumentsPath Windows +// +// Returns the path to the default documents directory. +// +//=========================================================================== + +FString M_GetDocumentsPath() +{ + FString path; + + // A portable INI means that this storage location should also be portable. + path.Format("%s" GAMENAME "_portable.ini", progdir.GetChars()); + if (FileExists(path)) + { + return progdir; + } + + if (!UseKnownFolders()) + { + return progdir; + } + // Try defacto My Documents/My Games folder + else if (GetKnownFolder(CSIDL_PERSONAL, FOLDERID_Documents, true, path)) + { + // I assume since this isn't a standard folder, it doesn't have + // a localized name either. + path << "/My Games/" GAMENAME; + CreatePath(path); + } + else + { + path = progdir; + } + return path; +}