| 1168 | //----------------------------------------------------------------------------- |
| 1169 | |
| 1170 | StringTableEntry ModuleManager::copyModule( ModuleDefinition* pSourceModuleDefinition, const char* pTargetModuleId, const char* pTargetPath, const bool useVersionPathing ) |
| 1171 | { |
| 1172 | // Sanity! |
| 1173 | AssertFatal( pSourceModuleDefinition != NULL, "Cannot copy module using a NULL source module definition." ); |
| 1174 | AssertFatal( pTargetModuleId != NULL, "Cannot copy module using a NULL target module Id." ); |
| 1175 | AssertFatal( pTargetPath != NULL, "Cannot copy module using a NULL target path." ); |
| 1176 | |
| 1177 | // Fetch the source module Id. |
| 1178 | StringTableEntry sourceModuleId = pSourceModuleDefinition->getModuleId(); |
| 1179 | |
| 1180 | // Is the source module definition registered with this module manager? |
| 1181 | if ( pSourceModuleDefinition->getModuleManager() != this ) |
| 1182 | { |
| 1183 | // No, so warn. |
| 1184 | Con::warnf("Module Manager: Cannot copy module Id '%s' as it is not registered with this module manager.", sourceModuleId ); |
| 1185 | return StringTable->EmptyString(); |
| 1186 | } |
| 1187 | |
| 1188 | // Fetch the target module Id. |
| 1189 | StringTableEntry targetModuleId = StringTable->insert( pTargetModuleId ); |
| 1190 | |
| 1191 | // Extend moduleId/VersionId pathing. |
| 1192 | char versionPathBuffer[1024]; |
| 1193 | |
| 1194 | // Are we using version pathing? |
| 1195 | if ( useVersionPathing ) |
| 1196 | { |
| 1197 | // Yes, so format it. |
| 1198 | dSprintf( versionPathBuffer, sizeof(versionPathBuffer), "%s/%s/%d", |
| 1199 | pTargetPath, targetModuleId, pSourceModuleDefinition->getVersionId() ); |
| 1200 | } |
| 1201 | else |
| 1202 | { |
| 1203 | // No, so a straight copy. |
| 1204 | dSprintf( versionPathBuffer, sizeof(versionPathBuffer), "%s", pTargetPath ); |
| 1205 | } |
| 1206 | |
| 1207 | // Expand the path. |
| 1208 | char targetPathBuffer[1024]; |
| 1209 | Con::expandPath( targetPathBuffer, sizeof(targetPathBuffer), versionPathBuffer ); |
| 1210 | pTargetPath = targetPathBuffer; |
| 1211 | |
| 1212 | // Info. |
| 1213 | if ( mEchoInfo ) |
| 1214 | { |
| 1215 | Con::printf( "Module Manager: Started copying module Id '%s' to target directory '%s'.", sourceModuleId, pTargetPath ); |
| 1216 | } |
| 1217 | |
| 1218 | // Is the target folder a directory? |
| 1219 | if ( !Platform::isDirectory( pTargetPath ) ) |
| 1220 | { |
| 1221 | // No, so we have to ensure that there is a trailing slash as that indicates a folder (not a file) when creating a path in the platform code. |
| 1222 | char createDirectoryBuffer[1024]; |
| 1223 | Con::expandPath( createDirectoryBuffer, sizeof(createDirectoryBuffer), pTargetPath, NULL, true ); |
| 1224 | |
| 1225 | // No, so can we create it? |
| 1226 | if ( !Platform::createPath( createDirectoryBuffer ) ) |
| 1227 | { |
no test coverage detected