-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
105 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
139 changes: 71 additions & 68 deletions
139
...-bundle-converter/Assets/AssetBundleConverter/LODsConverter/Utils/AmazonS3FileProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,96 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading.Tasks; | ||
using Amazon; | ||
using Amazon.S3; | ||
using Amazon.S3.Model; | ||
using UnityEngine; | ||
using JetBrains.Annotations; | ||
|
||
public class AmazonS3FileProvider | ||
namespace AssetBundleConverter.LODsConverter.Utils | ||
{ | ||
private readonly string bucketName = "your-bucket-name"; | ||
private readonly string directoryPath = "your-directory-path/"; // Ensure it ends with a '/' | ||
private readonly string outputPath = "your-output-path"; | ||
private static readonly RegionEndpoint bucketRegion = RegionEndpoint.USEast1; // Update to your bucket's region | ||
private readonly IAmazonS3 s3Client; | ||
|
||
public AmazonS3FileProvider(string bucketName, string bucketDirectory, string outputPath) | ||
public class AmazonS3FileProvider : IFileDownloader | ||
{ | ||
var config = new AmazonS3Config(); | ||
config.RegionEndpoint = bucketRegion; | ||
config.ServiceURL = "http://localhost:4566"; // Ensure to use the correct endpoint | ||
s3Client = new AmazonS3Client(config); | ||
this.bucketName = bucketName; | ||
directoryPath = bucketDirectory; | ||
this.outputPath = outputPath; | ||
} | ||
private readonly string bucketName = "your-bucket-name"; | ||
private readonly string directoryPath = "your-directory-path/"; // Ensure it ends with a '/' | ||
private readonly string outputPath = "your-output-path"; | ||
private static readonly RegionEndpoint bucketRegion = RegionEndpoint.USEast1; // Update to your bucket's region | ||
private readonly IAmazonS3 s3Client; | ||
|
||
public async Task DownloadFilesAsync() | ||
{ | ||
try | ||
public AmazonS3FileProvider(string bucketName, string bucketDirectory, string outputPath) | ||
{ | ||
var request = new ListObjectsV2Request | ||
{ | ||
BucketName = bucketName, Prefix = directoryPath | ||
}; | ||
var config = new AmazonS3Config(); | ||
config.RegionEndpoint = bucketRegion; | ||
config.ServiceURL = "http://localhost:4566"; // Ensure to use the correct endpoint | ||
s3Client = new AmazonS3Client(config); | ||
this.bucketName = bucketName; | ||
directoryPath = bucketDirectory; | ||
this.outputPath = outputPath; | ||
} | ||
|
||
ListObjectsV2Response response; | ||
do | ||
[CanBeNull] | ||
public async Task<string[]> Download() | ||
{ | ||
try | ||
{ | ||
response = await s3Client.ListObjectsV2Async(request); | ||
foreach (var entry in response.S3Objects) | ||
var request = new ListObjectsV2Request | ||
{ | ||
Console.WriteLine($"Downloading {entry.Key}..."); | ||
await DownloadFileAsync(entry.Key); | ||
} | ||
BucketName = bucketName, Prefix = directoryPath | ||
}; | ||
|
||
request.ContinuationToken = response.NextContinuationToken; | ||
} while (response.IsTruncated); | ||
} | ||
catch (AmazonS3Exception e) | ||
{ | ||
Console.WriteLine($"Error encountered on server. Message:'{e.Message}' when listing objects"); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine($"Unknown encountered on server. Message:'{e.Message}' when listing objects"); | ||
} | ||
} | ||
ListObjectsV2Response response; | ||
do | ||
{ | ||
response = await s3Client.ListObjectsV2Async(request); | ||
foreach (var entry in response.S3Objects) | ||
{ | ||
Console.WriteLine($"Downloading {entry.Key}..."); | ||
await DownloadFileAsync(entry.Key); | ||
} | ||
|
||
private async Task DownloadFileAsync(string keyName) | ||
{ | ||
string filePath = Path.Combine(outputPath, keyName.Replace("/", "\\")); | ||
// Ensure the directory exists | ||
Directory.CreateDirectory(Path.GetDirectoryName(filePath)); | ||
request.ContinuationToken = response.NextContinuationToken; | ||
} while (response.IsTruncated); | ||
} | ||
catch (AmazonS3Exception e) | ||
{ | ||
Console.WriteLine($"Error encountered on server. Message:'{e.Message}' when listing objects"); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine($"Unknown encountered on server. Message:'{e.Message}' when listing objects"); | ||
} | ||
|
||
return Array.Empty<string>(); | ||
} | ||
|
||
try | ||
private async Task DownloadFileAsync(string keyName) | ||
{ | ||
var request = new GetObjectRequest | ||
string filePath = Path.Combine(outputPath, keyName.Replace("/", "\\")); | ||
// Ensure the directory exists | ||
Directory.CreateDirectory(Path.GetDirectoryName(filePath)); | ||
|
||
try | ||
{ | ||
BucketName = bucketName, Key = keyName | ||
}; | ||
var request = new GetObjectRequest | ||
{ | ||
BucketName = bucketName, Key = keyName | ||
}; | ||
|
||
using (var response = await s3Client.GetObjectAsync(request)) | ||
using (var responseStream = response.ResponseStream) | ||
using (var fileStream = File.Create(filePath)) | ||
using (var response = await s3Client.GetObjectAsync(request)) | ||
using (var responseStream = response.ResponseStream) | ||
using (var fileStream = File.Create(filePath)) | ||
{ | ||
await responseStream.CopyToAsync(fileStream); | ||
Console.WriteLine($"{keyName} has been downloaded to {filePath}"); | ||
} | ||
} | ||
catch (AmazonS3Exception e) | ||
{ | ||
await responseStream.CopyToAsync(fileStream); | ||
Console.WriteLine($"{keyName} has been downloaded to {filePath}"); | ||
Console.WriteLine($"Error encountered on server. Message:'{e.Message}' when downloading an object"); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine($"Unknown encountered on server. Message:'{e.Message}' when downloading an object"); | ||
} | ||
} | ||
catch (AmazonS3Exception e) | ||
{ | ||
Console.WriteLine($"Error encountered on server. Message:'{e.Message}' when downloading an object"); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine($"Unknown encountered on server. Message:'{e.Message}' when downloading an object"); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
asset-bundle-converter/Assets/AssetBundleConverter/LODsConverter/Utils/IFileDownloader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace AssetBundleConverter.LODsConverter.Utils | ||
{ | ||
public interface IFileDownloader | ||
{ | ||
Task<string[]> Download(); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...-bundle-converter/Assets/AssetBundleConverter/LODsConverter/Utils/IFileDownloader.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"C:\Program Files\Unity\Hub\Editor\2022.3.12f1\Editor\Unity.exe" -projectPath "asset-bundle-converter" -batchmode -executeMethod DCL.ABConverter.LODClient.ExportURLLODsToAssetBundles -lods "https://lods-bucket-ed4300a.s3.amazonaws.com/-17,-21/LOD/Sources/1707776785658/bafkreidnwpjkv3yoxsz6iiqh3fahuec7lfsqtmkyz3yf6dgps454ngldnu_0.fbx;https://lods-bucket-ed4300a.s3.amazonaws.com/-17,-21/LOD/Sources/1707776785658/bafkreidnwpjkv3yoxsz6iiqh3fahuec7lfsqtmkyz3yf6dgps454ngldnu_1.fbx;https://lods-bucket-ed4300a.s3.amazonaws.com/-17,-21/LOD/Sources/1707776785658/bafkreidnwpjkv3yoxsz6iiqh3fahuec7lfsqtmkyz3yf6dgps454ngldnu_2.fbx" -output "C:/Users/juani/Documents/Decentraland/asset-bundle-converter - Copy/AssetBundles" -logFile ./tmp/log.txt |