summaryrefslogtreecommitdiff
path: root/src/fileio.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-01-17 16:53:32 +0000
committerrubidium <rubidium@openttd.org>2009-01-17 16:53:32 +0000
commit3a13b75e37b5642de3c1e89cf6ab3bf860b76375 (patch)
tree76215ba6e27bc0b1f49919c01ff2608f276b8e3d /src/fileio.cpp
parent2850bf9e006ebdd40b5562cca5117bca027cfab5 (diff)
downloadopenttd-3a13b75e37b5642de3c1e89cf6ab3bf860b76375.tar.xz
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
Diffstat (limited to 'src/fileio.cpp')
-rw-r--r--src/fileio.cpp38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/fileio.cpp b/src/fileio.cpp
index 744da2e21..be6144160 100644
--- a/src/fileio.cpp
+++ b/src/fileio.cpp
@@ -518,7 +518,7 @@ static void SimplifyFileName(char *name)
#endif
}
-static bool TarListAddFile(const char *filename)
+bool TarListAddFile(const char *filename)
{
/* The TAR-header, repeated for every file */
typedef struct TarHeader {
@@ -951,6 +951,27 @@ void DeterminePaths(const char *exe)
free(save_dir);
free(autosave_dir);
+ /* If we have network we make a directory for the autodownloading of content */
+ _searchpaths[SP_AUTODOWNLOAD_DIR] = str_fmt("%s%s", _personal_dir, "content_download" PATHSEP);
+#ifdef ENABLE_NETWORK
+ FioCreateDirectory(_searchpaths[SP_AUTODOWNLOAD_DIR]);
+
+ /* Create the directory for each of the types of content */
+ const Subdirectory dirs[] = { SCENARIO_DIR, HEIGHTMAP_DIR, DATA_DIR, AI_DIR, AI_LIBRARY_DIR };
+ for (uint i = 0; i < lengthof(dirs); i++) {
+ char *tmp = str_fmt("%s%s", _searchpaths[SP_AUTODOWNLOAD_DIR], FioGetSubdirectory(dirs[i]));
+ FioCreateDirectory(tmp);
+ free(tmp);
+ }
+#else /* ENABLE_NETWORK */
+ /* If we don't have networking, we don't need to make the directory. But
+ * if it exists we keep it, otherwise remove it from the search paths. */
+ if (!FileExists(_searchpaths[SP_AUTODOWNLOAD_DIR])) {
+ free((void*)_searchpaths[SP_AUTODOWNLOAD_DIR]);
+ _searchpaths[SP_AUTODOWNLOAD_DIR] = NULL;
+ }
+#endif /* ENABLE_NETWORK */
+
ScanForTarFiles();
}
@@ -1097,3 +1118,18 @@ uint FileScanner::Scan(const char *extension, Subdirectory sd, bool tars)
return num;
}
+
+/**
+ * Scan for files with the given extention in the given search path.
+ * @param extension the extension of files to search for.
+ * @param directory the sub directory to search in.
+ * @return the number of found files, i.e. the number of times that
+ * AddFile returned true.
+ */
+uint FileScanner::Scan(const char *extension, const char *directory)
+{
+ char path[MAX_PATH];
+ strecpy(path, directory, lastof(path));
+ AppendPathSeparator(path, lengthof(path));
+ return ScanPath(this, extension, path, strlen(path));
+}