Skip to content
Open
23 changes: 14 additions & 9 deletions Basis/Packages/com.basis.bundlemanagement/BasisIOManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ public static string NormalizeCachePlatformName(string platformName)

public static string GetBeeCacheFilePath(string uniqueVersion, string downloadedPlatform = null)
{
return GenerateFilePath(BuildPlatformAwareCacheFileName(uniqueVersion, BasisBeeConstants.BasisEncryptedExtension, downloadedPlatform), BasisBeeConstants.AssetBundlesFolder);
return GenerateFilePath(BuildLegacyCacheFileName(uniqueVersion, BasisBeeConstants.BasisEncryptedExtension), GetPlatformCacheFolder(downloadedPlatform));
}

public static string GetConnectorCacheFilePath(string uniqueVersion, string downloadedPlatform = null)
{
return GenerateFilePath(BuildPlatformAwareCacheFileName(uniqueVersion, BasisBeeConstants.BasisConnectorExtension, downloadedPlatform), BasisBeeConstants.AssetBundlesFolder);
return GenerateFilePath(BuildLegacyCacheFileName(uniqueVersion, BasisBeeConstants.BasisConnectorExtension), GetPlatformCacheFolder(downloadedPlatform));
}

public static string GetMetaCacheFilePath(string uniqueVersion, string downloadedPlatform = null)
{
return GenerateFilePath(BuildPlatformAwareCacheFileName(uniqueVersion, BasisBeeConstants.BasisMetaExtension, downloadedPlatform), BasisBeeConstants.AssetBundlesFolder);
return GenerateFilePath(BuildLegacyCacheFileName(uniqueVersion, BasisBeeConstants.BasisMetaExtension), GetPlatformCacheFolder(downloadedPlatform));
}

public static string GetLegacyBeeCacheFilePath(string uniqueVersion)
Expand All @@ -66,21 +66,26 @@ public static string GetLegacyMetaCacheFilePath(string uniqueVersion)
return GenerateFilePath($"{uniqueVersion}{BasisBeeConstants.BasisMetaExtension}", BasisBeeConstants.AssetBundlesFolder);
}

private static string BuildPlatformAwareCacheFileName(string uniqueVersion, string extension, string downloadedPlatform)
private static string GetPlatformCacheFolder(string downloadedPlatform)
{
if (string.IsNullOrWhiteSpace(uniqueVersion))
throw new ArgumentException("Unique version is null or empty.", nameof(uniqueVersion));

string normalizedPlatform = string.IsNullOrWhiteSpace(downloadedPlatform)
? GetCurrentCachePlatform()
: NormalizeCachePlatformName(downloadedPlatform);

foreach (char invalidChar in Path.GetInvalidFileNameChars())
foreach (char invalidChar in Path.GetInvalidPathChars())
{
normalizedPlatform = normalizedPlatform.Replace(invalidChar, '_');
}

return $"{uniqueVersion}.{normalizedPlatform}{extension}";
return Path.Combine(BasisBeeConstants.AssetBundlesFolder, normalizedPlatform);
}

private static string BuildLegacyCacheFileName(string uniqueVersion, string extension)
{
if (string.IsNullOrWhiteSpace(uniqueVersion))
throw new ArgumentException("Unique version is null or empty.", nameof(uniqueVersion));

return $"{uniqueVersion}{extension}";
}

public sealed class BeeDownloadResult
Expand Down
Loading
Loading