| 1110 | //----------------------------------------------------------------------------- |
| 1111 | |
| 1112 | StringTableEntry ModuleManager::copyModule( ModuleDefinition* pSourceModuleDefinition, const char* pTargetModuleId, const char* pTargetPath, const bool useVersionPathing ) |
| 1113 | { |
| 1114 | // Sanity! |
| 1115 | AssertFatal( pSourceModuleDefinition != NULL, "Cannot copy module using a NULL source module definition." ); |
| 1116 | AssertFatal( pTargetModuleId != NULL, "Cannot copy module using a NULL target module Id." ); |
| 1117 | AssertFatal( pTargetPath != NULL, "Cannot copy module using a NULL target path." ); |
| 1118 | |
| 1119 | // Fetch the source module Id. |
| 1120 | StringTableEntry sourceModuleId = pSourceModuleDefinition->getModuleId(); |
| 1121 | |
| 1122 | // Is the source module definition registered with this module manager? |
| 1123 | if ( pSourceModuleDefinition->getModuleManager() != this ) |
| 1124 | { |
| 1125 | // No, so warn. |
| 1126 | Con::warnf("Module Manager: Cannot copy module Id '%s' as it is not registered with this module manager.", sourceModuleId ); |
| 1127 | return StringTable->EmptyString; |
| 1128 | } |
| 1129 | |
| 1130 | // Fetch the target module Id. |
| 1131 | StringTableEntry targetModuleId = StringTable->insert( pTargetModuleId ); |
| 1132 | |
| 1133 | // Extend moduleId/VersionId pathing. |
| 1134 | char versionPathBuffer[1024]; |
| 1135 | |
| 1136 | // Are we using version pathing? |
| 1137 | if ( useVersionPathing ) |
| 1138 | { |
| 1139 | // Yes, so format it. |
| 1140 | dSprintf( versionPathBuffer, sizeof(versionPathBuffer), "%s/%s/%d", |
| 1141 | pTargetPath, targetModuleId, pSourceModuleDefinition->getVersionId() ); |
| 1142 | } |
| 1143 | else |
| 1144 | { |
| 1145 | // No, so a straight copy. |
| 1146 | dSprintf( versionPathBuffer, sizeof(versionPathBuffer), "%s", pTargetPath ); |
| 1147 | } |
| 1148 | |
| 1149 | // Expand the path. |
| 1150 | char targetPathBuffer[1024]; |
| 1151 | Con::expandPath( targetPathBuffer, sizeof(targetPathBuffer), versionPathBuffer ); |
| 1152 | pTargetPath = targetPathBuffer; |
| 1153 | |
| 1154 | // Info. |
| 1155 | if ( mEchoInfo ) |
| 1156 | { |
| 1157 | Con::printf( "Module Manager: Started copying module Id '%s' to target directory '%s'.", sourceModuleId, pTargetPath ); |
| 1158 | } |
| 1159 | |
| 1160 | // Is the target folder a directory? |
| 1161 | if ( !Platform::isDirectory( pTargetPath ) ) |
| 1162 | { |
| 1163 | // 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. |
| 1164 | char createDirectoryBuffer[1024]; |
| 1165 | Con::expandPath( createDirectoryBuffer, sizeof(createDirectoryBuffer), pTargetPath, NULL, true ); |
| 1166 | |
| 1167 | // No, so can we create it? |
| 1168 | if ( !Platform::createPath( createDirectoryBuffer ) ) |
| 1169 | { |
no test coverage detected