// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.Text;
using UnityEngine;
namespace Google.Play.AssetDelivery.Internal
{
///
/// Wraps Play Core's AssetPackState which represents the current state of an AssetPack download.
///
internal class AssetPackState
{
///
/// The name of the asset pack being downloaded.
///
public string Name { get; private set; }
///
/// The number of bytes downloaded so far.
///
public long BytesDownloaded { get; private set; }
///
/// The total number of bytes that need to be downloaded.
///
public long TotalBytesToDownload { get; private set; }
///
/// The status of the associated download session (downloading, downloaded, installed, etc).
///
public int Status { get; private set; }
///
/// The error code indicating the reason the download session failed.
///
public int ErrorCode { get; private set; }
///
/// Creates an AssetPackState with all the fields of the underlying Java object, disposing the Java
/// object in the process.
///
public AssetPackState(AndroidJavaObject javaAssetPackState)
{
using (javaAssetPackState)
{
Name = javaAssetPackState.Call("name");
BytesDownloaded = javaAssetPackState.Call("bytesDownloaded");
TotalBytesToDownload = javaAssetPackState.Call("totalBytesToDownload");
Status = javaAssetPackState.Call("status");
ErrorCode = javaAssetPackState.Call("errorCode");
}
}
public override string ToString()
{
var stateDescription = new StringBuilder();
stateDescription.AppendFormat("name: {0}\n", Name);
stateDescription.AppendFormat("status: {0}\n", Status);
stateDescription.AppendFormat("error code: {0}\n", ErrorCode);
stateDescription.AppendFormat("bytes downloaded: {0}\n", BytesDownloaded);
stateDescription.AppendFormat("total downloaded: {0}\n", TotalBytesToDownload);
return stateDescription.ToString();
}
}
}