summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2012-08-13 18:49:38 +0000
committeryexo <yexo@openttd.org>2012-08-13 18:49:38 +0000
commit483d878d5fbe549b2e8196c8e8176ad560734343 (patch)
treebd3b8f146f76dcb094c51a5204245675c7fa7d47 /src
parent93a135bc6a7b973d2fd6971fffd76962ff419a97 (diff)
downloadopenttd-483d878d5fbe549b2e8196c8e8176ad560734343.tar.xz
(svn r24466) -Codechange [FS#5236]: add general function for ContentType -> Subdirectory conversion (LordAro)
Diffstat (limited to 'src')
-rw-r--r--src/network/core/tcp_content.cpp26
-rw-r--r--src/network/core/tcp_content.h2
-rw-r--r--src/network/network_content.cpp53
3 files changed, 32 insertions, 49 deletions
diff --git a/src/network/core/tcp_content.cpp b/src/network/core/tcp_content.cpp
index 30284f2e7..131501a5c 100644
--- a/src/network/core/tcp_content.cpp
+++ b/src/network/core/tcp_content.cpp
@@ -163,4 +163,30 @@ bool NetworkContentSocketHandler::Receive_SERVER_INFO(Packet *p) { return this->
bool NetworkContentSocketHandler::Receive_CLIENT_CONTENT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CONTENT_CLIENT_CONTENT); }
bool NetworkContentSocketHandler::Receive_SERVER_CONTENT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CONTENT_SERVER_CONTENT); }
+/**
+ * Helper to get the subdirectory a #ContentInfo is located in.
+ * @param type The type of content.
+ * @return The subdirectory the content is located in.
+ */
+Subdirectory GetContentInfoSubDir(ContentType type)
+{
+ switch (type) {
+ default: return NO_DIRECTORY;
+ case CONTENT_TYPE_AI: return AI_DIR;
+ case CONTENT_TYPE_AI_LIBRARY: return AI_LIBRARY_DIR;
+ case CONTENT_TYPE_GAME: return GAME_DIR;
+ case CONTENT_TYPE_GAME_LIBRARY: return GAME_LIBRARY_DIR;
+ case CONTENT_TYPE_NEWGRF: return NEWGRF_DIR;
+
+ case CONTENT_TYPE_BASE_GRAPHICS:
+ case CONTENT_TYPE_BASE_SOUNDS:
+ case CONTENT_TYPE_BASE_MUSIC:
+ return BASESET_DIR;
+
+ case CONTENT_TYPE_SCENARIO:
+ case CONTENT_TYPE_HEIGHTMAP:
+ return SCENARIO_DIR;
+ }
+}
+
#endif /* ENABLE_NETWORK */
diff --git a/src/network/core/tcp_content.h b/src/network/core/tcp_content.h
index 12996a02d..8e06bedb0 100644
--- a/src/network/core/tcp_content.h
+++ b/src/network/core/tcp_content.h
@@ -206,6 +206,8 @@ public:
void ReceivePackets();
};
+Subdirectory GetContentInfoSubDir(ContentType type);
+
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CORE_TCP_CONTENT_H */
diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp
index 53672c5ec..afbca4a37 100644
--- a/src/network/network_content.cpp
+++ b/src/network/network_content.cpp
@@ -384,20 +384,8 @@ void ClientNetworkContentSocketHandler::DownloadSelectedContentFallback(const Co
*/
static char *GetFullFilename(const ContentInfo *ci, bool compressed)
{
- Subdirectory dir;
- switch (ci->type) {
- default: return NULL;
- case CONTENT_TYPE_BASE_GRAPHICS: dir = BASESET_DIR; break;
- case CONTENT_TYPE_BASE_MUSIC: dir = BASESET_DIR; break;
- case CONTENT_TYPE_BASE_SOUNDS: dir = BASESET_DIR; break;
- case CONTENT_TYPE_NEWGRF: dir = NEWGRF_DIR; break;
- case CONTENT_TYPE_AI: dir = AI_DIR; break;
- case CONTENT_TYPE_AI_LIBRARY: dir = AI_LIBRARY_DIR; break;
- case CONTENT_TYPE_SCENARIO: dir = SCENARIO_DIR; break;
- case CONTENT_TYPE_HEIGHTMAP: dir = HEIGHTMAP_DIR; break;
- case CONTENT_TYPE_GAME: dir = GAME_DIR; break;
- case CONTENT_TYPE_GAME_LIBRARY: dir = GAME_LIBRARY_DIR; break;
- }
+ Subdirectory dir = GetContentInfoSubDir(ci->type);
+ if (dir == NO_DIRECTORY) return NULL;
static char buf[MAX_PATH];
FioGetFullPath(buf, lengthof(buf), SP_AUTODOWNLOAD_DIR, dir, ci->filename);
@@ -544,41 +532,8 @@ void ClientNetworkContentSocketHandler::AfterDownload()
if (GunzipFile(this->curInfo)) {
unlink(GetFullFilename(this->curInfo, true));
- Subdirectory sd = NO_DIRECTORY;
- switch (this->curInfo->type) {
- case CONTENT_TYPE_AI:
- sd = AI_DIR;
- break;
-
- case CONTENT_TYPE_AI_LIBRARY:
- sd = AI_LIBRARY_DIR;
- break;
-
- case CONTENT_TYPE_GAME:
- sd = GAME_DIR;
- break;
-
- case CONTENT_TYPE_GAME_LIBRARY:
- sd = GAME_LIBRARY_DIR;
- break;
-
- case CONTENT_TYPE_BASE_GRAPHICS:
- case CONTENT_TYPE_BASE_SOUNDS:
- case CONTENT_TYPE_BASE_MUSIC:
- sd = BASESET_DIR;
- break;
-
- case CONTENT_TYPE_NEWGRF:
- sd = NEWGRF_DIR;
- break;
-
- case CONTENT_TYPE_SCENARIO:
- case CONTENT_TYPE_HEIGHTMAP:
- sd = SCENARIO_DIR;
- break;
-
- default: NOT_REACHED();
- }
+ Subdirectory sd = GetContentInfoSubDir(this->curInfo->type);
+ if (sd == NO_DIRECTORY) NOT_REACHED();
TarScanner ts;
ts.AddFile(sd, GetFullFilename(this->curInfo, false));