Skip to content

Commit 7c8abe0

Browse files
authored
Merge pull request #1202 from scp-fs2open/revert-1187-fix/1182_2
Revert "Show error message when a data directory uses the wrong case"
2 parents 86cb91f + 07c86cd commit 7c8abe0

File tree

12 files changed

+30
-194
lines changed

12 files changed

+30
-194
lines changed

code/cfile/cfilesystem.cpp

Lines changed: 10 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,12 @@
1515
#include <errno.h>
1616
#include <sstream>
1717
#include <algorithm>
18-
#include <memory>
1918

2019
#ifdef _WIN32
2120
#include <io.h>
2221
#include <direct.h>
2322
#include <windows.h>
2423
#include <winbase.h> /* needed for memory mapping of file functions */
25-
#include <shlwapi.h>
26-
27-
struct dir_handle_deleter {
28-
typedef HANDLE pointer;
29-
30-
void operator()(HANDLE dirp) {
31-
if (dirp != INVALID_HANDLE_VALUE) {
32-
FindClose(dirp);
33-
}
34-
}
35-
};
36-
typedef std::unique_ptr<HANDLE, dir_handle_deleter> unique_dir_handle_ptr;
3724
#endif
3825

3926
#ifdef SCP_UNIX
@@ -43,14 +30,6 @@ typedef std::unique_ptr<HANDLE, dir_handle_deleter> unique_dir_handle_ptr;
4330
#include <fnmatch.h>
4431
#include <sys/stat.h>
4532
#include <unistd.h>
46-
#include <libgen.h>
47-
48-
struct dir_deleter {
49-
void operator()(DIR* dirp) {
50-
closedir(dirp);
51-
}
52-
};
53-
typedef std::unique_ptr<DIR, dir_deleter> unique_dir_ptr;
5433
#endif
5534

5635
#include "cfile/cfile.h"
@@ -59,7 +38,6 @@ typedef std::unique_ptr<DIR, dir_deleter> unique_dir_ptr;
5938
#include "globalincs/pstypes.h"
6039
#include "localization/localize.h"
6140
#include "osapi/osapi.h"
62-
#include "parse/parselo.h"
6341

6442
#define CF_ROOTTYPE_PATH 0
6543
#define CF_ROOTTYPE_PACK 1
@@ -574,62 +552,6 @@ void cf_search_root_path(int root_index)
574552
}
575553

576554
#if defined _WIN32
577-
{
578-
// Check if the case matches the case as specified in Pathtypes
579-
// Since Windows paths are case insensitive this wouldn't cause issues here but other
580-
// platforms would fail to find data paths in this case so we show a nice error if we detect that here
581-
582-
// Ignore the root since the case of that is allowed to differ (it's handled in the mod handling)
583-
if (i != CF_TYPE_ROOT) {
584-
// We use FindFirstFileNameW for this, it should hopefully work...
585-
// First, convert our path from ASCII/UTF-8 to wchar_t
586-
std::string search_string = search_path;
587-
// Remove any trailing directory separators
588-
if (search_string[search_string.size() - 1] == '\\') {
589-
search_string = search_string.substr(0, search_string.size() - 1);
590-
}
591-
592-
char parent_name[MAX_PATH];
593-
memset(parent_name, 0, sizeof(parent_name));
594-
strcpy_s(parent_name, search_string.c_str());
595-
596-
CHAR file_name[MAX_PATH];
597-
memset(file_name, 0, sizeof(file_name));
598-
strcpy_s(file_name, search_string.c_str());
599-
600-
PathStripPathA(file_name);
601-
if (PathRemoveFileSpecA(parent_name)) {
602-
strcat_s(parent_name, "\\*");
603-
604-
WIN32_FIND_DATAA find_data;
605-
auto handle = unique_dir_handle_ptr(FindFirstFileA(parent_name, &find_data));
606-
if (handle.get() != INVALID_HANDLE_VALUE) {
607-
do {
608-
if (stricmp(find_data.cFileName, file_name)) {
609-
// Not the same name, not even if we check case-insensitive
610-
continue;
611-
}
612-
613-
// Same name, might have case differences
614-
if (!strcmp(find_data.cFileName, file_name)) {
615-
// Case matches, everything is alright.
616-
continue;
617-
}
618-
619-
// We need to do some formatting on the parent_name in order to show a nice error message
620-
SCP_string parent_name_str = parent_name;
621-
parent_name_str = parent_name_str.substr(0, parent_name_str.size() - 1); // Remove trailing *
622-
parent_name_str += find_data.cFileName;
623-
624-
// If we are still here then the case didn't match which means that we have to show the error message
625-
Error(LOCATION, "Data directory '%s' for path type '%s' does not match the required case! "
626-
"All data directories must exactly match the case specified by the engine or your mod "
627-
"will not work on other platforms.", parent_name_str.c_str(), Pathtypes[i].path);
628-
} while (FindNextFileA(handle.get(), &find_data) != 0);
629-
}
630-
}
631-
}
632-
}
633555
strcat_s( search_path, "*.*" );
634556

635557
intptr_t find_handle;
@@ -666,65 +588,21 @@ void cf_search_root_path(int root_index)
666588
_findclose( find_handle );
667589
}
668590
#elif defined SCP_UNIX
669-
auto dirp = unique_dir_ptr(opendir(search_path));
670-
if (!dirp)
671-
{
672-
// If the directory does not exist then check if it might exist with a different case. If that's the case
673-
// we bail out with an error so inform the user that this is not valid.
674-
675-
// On Unix we can have a different case for the search paths so we also need to account for that
676-
// We do that by looking at the parent of search_path and enumerating all directories and then check if any of
677-
// them are a case-insensitive match
678-
char dirname_copy[CF_MAX_PATHNAME_LENGTH];
679-
memcpy(dirname_copy, search_path, sizeof(search_path));
680-
// According to the documentation of directory_name and basename, the return value does not need to be freed
681-
auto directory_name = dirname(dirname_copy);
682-
683-
char basename_copy[CF_MAX_PATHNAME_LENGTH];
684-
memcpy(basename_copy, search_path, sizeof(search_path));
685-
// According to the documentation of dirname and basename, the return value does not need to be freed
686-
auto search_name = basename(basename_copy);
687-
688-
auto parentDirP = unique_dir_ptr(opendir(directory_name));
689-
if (parentDirP) {
690-
struct dirent *dir = nullptr;
691-
while ((dir = readdir (parentDirP.get())) != nullptr) {
692-
693-
if (stricmp(search_name, dir->d_name)) {
694-
continue;
695-
}
696-
697-
SCP_string fn;
698-
sprintf(fn, "%s/%s", directory_name, dir->d_name);
699-
700-
struct stat buf;
701-
if (stat(fn.c_str(), &buf) == -1) {
702-
continue;
703-
}
591+
DIR *dirp;
592+
struct dirent *dir;
704593

705-
if (S_ISDIR(buf.st_mode)) {
706-
// Found a case insensitive match
707-
// If the name is not exactly the same as the one we are currently searching then it's an error
708-
if (strcmp(search_name, dir->d_name)) {
709-
Error(LOCATION, "Data directory '%s' for path type '%s' does not match the required case! "
710-
"All data directories must exactly match the case specified by the engine or your mod "
711-
"will not work on other platforms.", fn.c_str(), Pathtypes[i].path);
712-
}
713-
break;
714-
}
715-
}
716-
}
717-
} else {
718-
struct dirent *dir = nullptr;
719-
while ((dir = readdir (dirp.get())) != NULL)
594+
dirp = opendir (search_path);
595+
if ( dirp ) {
596+
while ((dir = readdir (dirp)) != NULL)
720597
{
721598
if (!fnmatch ("*.*", dir->d_name, 0))
722599
{
723-
SCP_string fn;
724-
sprintf(fn, "%s%s", search_path, dir->d_name);
600+
char fn[MAX_PATH];
601+
snprintf(fn, MAX_PATH-1, "%s%s", search_path, dir->d_name);
602+
fn[MAX_PATH-1] = 0;
725603

726604
struct stat buf;
727-
if (stat(fn.c_str(), &buf) == -1) {
605+
if (stat(fn, &buf) == -1) {
728606
continue;
729607
}
730608

@@ -754,6 +632,7 @@ void cf_search_root_path(int root_index)
754632
}
755633
}
756634
}
635+
closedir(dirp);
757636
}
758637
#endif
759638
}

test/src/cfile/cfile.cpp

Lines changed: 0 additions & 31 deletions
This file was deleted.

test/src/menuui/test_intel_parse.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class IntelParseTest : public test::FSTestFixture {
99
public:
10-
IntelParseTest() : test::FSTestFixture(INIT_CFILE) {
10+
IntelParseTest() : test::FSTestFixture(0) {
1111
pushModDir("menuui");
1212
pushModDir("intel_parse");
1313
}

test/src/parse/test_parselo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class ParseloTest : public test::FSTestFixture {
99
public:
10-
ParseloTest() : test::FSTestFixture(INIT_CFILE) {
10+
ParseloTest() : test::FSTestFixture(0) {
1111
pushModDir("parselo");
1212
}
1313

@@ -162,4 +162,4 @@ TEST(ParseloUtilTest, drop_whitespace) {
162162
test_str = " ";
163163
drop_white_space(test_str);
164164
ASSERT_EQ(test_str, "");
165-
}
165+
}

test/src/scripting/ScriptingTestFixture.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extern "C" {
1111
namespace test {
1212
namespace scripting {
1313

14-
ScriptingTestFixture::ScriptingTestFixture(uint64_t init_flags) : FSTestFixture(init_flags | INIT_CFILE) {
14+
ScriptingTestFixture::ScriptingTestFixture(uint64_t init_flags) : FSTestFixture(init_flags) {
1515
pushModDir("scripting");
1616
}
1717
void ScriptingTestFixture::SetUp() {

test/src/scripting/api/base.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class ScriptingBaseTest : public test::scripting::ScriptingTestFixture {
55
public:
6-
ScriptingBaseTest() : test::scripting::ScriptingTestFixture(INIT_NONE) {
6+
ScriptingBaseTest() : test::scripting::ScriptingTestFixture(0) {
77
pushModDir("base");
88
}
99
};

test/src/scripting/api/bitops.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class BitOpsTest : public test::scripting::ScriptingTestFixture {
55
public:
6-
BitOpsTest() : test::scripting::ScriptingTestFixture(INIT_NONE) {
6+
BitOpsTest() : test::scripting::ScriptingTestFixture(0) {
77
pushModDir("bitops");
88
}
99
};
@@ -30,4 +30,4 @@ TEST_F(BitOpsTest, checkBit) {
3030

3131
TEST_F(BitOpsTest, addBit) {
3232
this->EvalTestScript();
33-
}
33+
}

test/src/scripting/api/enums.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class EnumsTest : public test::scripting::ScriptingTestFixture {
55
public:
6-
EnumsTest() : test::scripting::ScriptingTestFixture(INIT_NONE) {
6+
EnumsTest() : test::scripting::ScriptingTestFixture(0) {
77
pushModDir("enums");
88
}
99
};

test/src/source_groups.cmake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ add_file_folder(root ""
1212
test_stubs.cpp
1313
)
1414

15-
add_file_folder(cfile "cfile"
16-
cfile/cfile.cpp
17-
)
18-
1915
add_file_folder(graphics "Globalincs"
2016
globalincs/test_flagset.cpp
2117
globalincs/test_safe_strings.cpp

test/src/util/FSTestFixture.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ void test::FSTestFixture::SetUp() {
3030

3131
os_init("Test", "Test");
3232

33-
if (!(_initFlags & INIT_CFILE)) {
34-
return;
35-
}
36-
37-
// The rest depends on cfile initialization
3833
SCP_string cfile_dir(TEST_DATA_PATH);
3934
cfile_dir += DIR_SEPARATOR_CHAR;
4035
cfile_dir += "test"; // Cfile expects something after the path
@@ -57,22 +52,20 @@ void test::FSTestFixture::SetUp() {
5752
}
5853
}
5954
void test::FSTestFixture::TearDown() {
60-
if (_initFlags & INIT_CFILE) {
61-
if (_initFlags & INIT_SHIPS) {
62-
ship_close();
63-
}
64-
65-
if (_initFlags & INIT_GRAPHICS) {
66-
io::mouse::CursorManager::shutdown();
55+
if (_initFlags & INIT_SHIPS) {
56+
ship_close();
57+
}
6758

68-
bm_unload_all();
59+
if (_initFlags & INIT_GRAPHICS) {
60+
io::mouse::CursorManager::shutdown();
6961

70-
gr_close();
71-
}
62+
bm_unload_all();
7263

73-
cfile_close();
64+
gr_close();
7465
}
7566

67+
cfile_close();
68+
7669
timer_close();
7770

7871
lcl_close();

0 commit comments

Comments
 (0)