To use Smart Downloader SDK, service must be enabled on console and a registered service must be available. For more details, see Console Guide.
Smart Downloader SDK supports Unity engines.
Toast.SmartDownloader
namespace.<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
<application android:networkSecurityConfig="@xml/network_security_config"
... >
...
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">cdn.toastcloud.com</domain>
</domain-config>
</network-security-config>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>toastcdn.net</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
Select a service and download. By default, all uploaded resources are downloaded, but only some resources can be selected for a download.
Download setting can be modified by using DownloadConfig.
Default setting can be imported from DownloadConfig.Default
.
Parameter | Initial Value | Description |
---|---|---|
FixedDownloadThreadCount | -1 | Fix the number of threads for downloads (automatically set in SDK for 0 or below) |
DownloadConnectTimeout | 60 | Timeout for download connection (unit: second) |
DownloadReadTimeout | 20 | Timeout for download reading (unit: second) |
RetryDownloadCountPerFile | 3 | Number of retries when download fails |
UseStreamingAssets | false | Specify whether to compare with Streaming Assets resources |
PatchCompareFunction | PatchCompareType.INTERGRITY | Resource check option |
ClearUnusedResources | false | Remove unused resources (Remove resources downloaded before that are not available in the current CDN) |
Example
DownloadConfig config = DownloadConfig.Default;
config.DownloadConnectTimeout = TimeSpan.FromSeconds(60);
config.DownloadReadTimeout = TimeSpan.FromSeconds(20);
config.RetryDownloadCountPerFile = 3;
config.UseStreamingAssets = false;
config.PatchCompareFunction = PatchCompareType.INTERGRITY;
config.ClearUnusedResources = false;
It you set UseStreamingAssets to true, Smart Downloader SDK compares the paths of resources inside the Streaming Assets and the uploaded resources, and download the changed resources.
Caution
Split Application Binary
setting is activated, Streaming Assets are included in the OBB file, which is an APK expansion file. At this time, the OBB file is searched on the device automatically.
If there is no OBB file on the device, all uploaded resources are download. (See Unity Manual - Support for APK expansion files)The default option. During resource check, Smart Downloader SDK calculates the CRC of all downloaded resources and compare it with the uploaded resources.
Feature
When this option is used, Smart Downloader SDK saves the basic information of the downloaded resources on the device and compares it with the uploaded resources during the next check.
Feature
Vulnerability
When this option is used, Smart Downloader SDK saves the basic information of the downloaded resources on the device, compares it with the uploaded resource during the next check, and performs a simple check to see if the actual resources exist on the device.
Feature
Vulnerability
If a resource is not selected from download setting, all resources deployed for service are to be downloaded.
API
static void StartDownload(string appkey, string serviceName, string downPath, OnComplete callback)
static void StartDownload(string appkey, string serviceName, string downPath, DownloadConfig config, OnComplete callback)
delegate void OnComplete(DownloadResult result)
Example
SmartDl.StartDownload("Appkey", "ServiceName", "DownloadPath",
(result) =>
{
if (result.IsSuccessful)
{
// Write a success code
}
else
{
// Write a failure code
}
});
Select a resource to download from [Download Setting] so as to download such resource only. If a file is not found, error is returned (result code: ERROR_EMPTY_FILE_LIST)
For download API, see Download All Resources.
API
class DownloadConfig
{
void AddSpecifyPath(string path);
void RemoveSpecifyPath(string path);
void ClearSpecifyPath();
}
Example
// Download user-specified files.
// - All files below the Characters
// - all files below the Maps/M01
// - Data/CharacterInfo.txt file
var downloadConfig = DownloadConfig.Default;
downloadConfig.AddSpecifyPath(@"/Characters");
downloadConfig.AddSpecifyPath(@"/Maps/M01");
downloadConfig.AddSpecifyPath(@"/Data/CharacterInfo.txt");
SmartDl.StartDownload(Appkey, ServiceName, DownloadPath, downloadConfig,
(result) =>
{
if (result.IsSuccessful)
{
// Write a success code
}
else
{
// Write a failure code
}
});
Delivered to download result callbacks.
Parameter | Description |
---|---|
Code | Result code |
IsCompleted | If download is completed or not |
Message | Result message |
IsSuccessful | If download is successful or not |
Cancel downloads under progress. StartDownload callback is returned as failure. (Result Code : USER_CANCEL)
API
static void StopDownload()
Example
void StopDownload()
{
SmartDl.StopDownload();
}
Information of progressing download can be imported in the ProgressInfo type.
Parameter | Description |
---|---|
FileMap | Returns information of files which are currently downloaded by thread |
Percentage | Returns the total rate of progress |
Speed | Returns download speed from the start, up to now (unit: byte/second) (total download volume /current time from when download started) |
TotalReceivedBytes | Returns the number of bytes downloaded up to now |
TotalFileBytes | Returns the total number of bytes to download |
CompletedFileCount | Returns the number of files downloaded up to now |
TotalFileNumber | Returns the total number of files to download |
IsCompleted | Returns whether download is complete |
API
static ProgressInfo Progress;
Example
void StartDownload()
{
SmartDl.StartDownload(AppKey, ServiceName, DownloadPath, downloadConfig, OnCompleteCallback);
StartCoroutine(UpdateProgress());
}
IEnumerator UpdateProgress()
{
while (true)
{
var progress = SmartDl.Progress;
Debug.LogFormat("Percentage : {0} %", progress.Percentage);
var threadCount = progress.FileMap.Count;
ThreadProgressContainer.Instance.ThreadCount = threadCount;
for (int i = 0; i < threadCount; i++)
{
var file = progress.FileMap[i];
Debug.LogFormat("Thread[{0}] Percentage : {1} %", i, (file.DownloadedBytes / (float)file.TotalBytes) * 100.0f);
}
if (progress.IsCompleted)
yield break;
yield return null;
}
}
SmartDILogger type is provided for log outputs on internal SDK activities. Default log level is Error, and unless a log event is registered, no activities can be found.
API
static LogLevel CurrentLevel = LogLevel.Error;
static event Action<LogLevel, string> OnLog;
Example
void Initialize()
{
SmartDlLogger.CurrentLevel = SmartDlLogger.LogLevel.Trace;
SmartDlLogger.OnLog += (type, log) =>
{
switch (type)
{
case SmartDlLogger.LogLevel.Trace:
case SmartDlLogger.LogLevel.Developer:
case SmartDlLogger.LogLevel.Debug:
case SmartDlLogger.LogLevel.Info:
Debug.Log(log);
break;
case SmartDlLogger.LogLevel.Warn:
Debug.LogWarning(log);
break;
case SmartDlLogger.LogLevel.Error:
Debug.LogError(log);
break;
default:
Debug.Log(log);
break;
}
};
}
The APIs that are not supported by Smart Downloader SDK are deprecated. Deprecated APIs can be deleted without prior notice when the following conditions are met.
Minor version updates for 5 times or more
5 months or more have passed after deprecation.