Skip to content

Instantly share code, notes, and snippets.

@Amanieu
Created April 4, 2014 11:20
Show Gist options
  • Save Amanieu/9972572 to your computer and use it in GitHub Desktop.
Save Amanieu/9972572 to your computer and use it in GitHub Desktop.
diff --git a/src/engine/framework/FileSystem.cpp b/src/engine/framework/FileSystem.cpp
index 95287e0..361e27e 100644
--- a/src/engine/framework/FileSystem.cpp
+++ b/src/engine/framework/FileSystem.cpp
@@ -2397,21 +2397,42 @@ int FS_GetFileList(const char* path, const char* extension, char* listBuf, int b
if (!strcmp(path, "$modlist"))
return 0;
- int numFiles;
- char** list = FS_ListFiles(path, extension, &numFiles);
+ int numFiles = 0;
+ bool dirsOnly = extension && !strcmp(extension, "/");
- for (int i = 0; i < numFiles; i++) {
- int length = strlen(list[i]) + 1;
- if (bufSize < length) {
- FS_FreeFileList(list);
- return i;
+ try {
+ for (const std::string& x: FS::PakPath::ListFiles(path)) {
+ if (extension && !Str::IsSuffix(extension, x))
+ continue;
+ if (dirsOnly != (x.back() == '/'))
+ continue;
+ int length = x.size() + (x.back() != '/');
+ if (bufSize < length)
+ return numFiles;
+ memcpy(listBuf, x.c_str(), length);
+ listBuf[length - 1] = '\0';
+ listBuf += length;
+ bufSize -= length;
+ numFiles++;
}
- memcpy(listBuf, list[i], length);
- listBuf += length;
- bufSize -= length;
- }
+ } catch (std::system_error&) {}
+ try {
+ for (const std::string& x: FS::HomePath::ListFiles(FS::Path::Build("game", path))) {
+ if (extension && !Str::IsSuffix(extension, x))
+ continue;
+ if (dirsOnly != (x.back() == '/'))
+ continue;
+ int length = x.size() + (x.back() != '/');
+ if (bufSize < length)
+ return numFiles;
+ memcpy(listBuf, x.c_str(), length);
+ listBuf[length - 1] = '\0';
+ listBuf += length;
+ bufSize -= length;
+ numFiles++;
+ }
+ } catch (std::system_error&) {}
- FS_FreeFileList(list);
return numFiles;
}
diff --git a/src/engine/server/sv_ccmds.cpp b/src/engine/server/sv_ccmds.cpp
index c1f7b1a..1dc4f4c 100644
--- a/src/engine/server/sv_ccmds.cpp
+++ b/src/engine/server/sv_ccmds.cpp
@@ -85,7 +85,7 @@ class MapCmd: public Cmd::StaticCmd {
}
return out;
} else if (argNum > 1) {
- return FS::HomePath::CompleteFilename(prefix, "layouts/" + args.Argv(1), ".dat", false, true);
+ return FS::HomePath::CompleteFilename(prefix, "game/layouts/" + args.Argv(1), ".dat", false, true);
}
return {};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment